NAME
atm_client_aal4 - example client ATM program using AAL 3/4
EXAMPLE
/*
* Copyright (c) 1992 by Fore Systems, Inc.
*/
#ifndef lint
static char -atm-client-aal4-c-[] = "@(#)$Id: atm-client-aal4.c,v 1.3 1994/06/28 20:18:37 jshirron Exp $ FSI";
#endif /* lint */
#include <stdio.h>
#include <sys/file.h>
#include <sys/fcntl.h>
#include <fore-atm/fore-atm-user.h>
#define SERVER-SAP 4096
#define PROGRESS 1024 /* report progress every n packets */
main(argc, argv) main
int argc;
char *argv[];
{
int fd, i, j, mtu, qlen;
Atm-info info;
Atm-endpoint dst;
Atm-qos qos;
Atm-qos-sel qos-selected;
Atm-sap ssap;
Aal-type aal = aal-type-4;
Atm-dataflow dataflow = simplex;
char *device-name;
char *tbuf, *rbuf;
extern char *malloc();
if (argc < 3) {
fprintf(stderr, "Usage: %s device server-hostname [server-sap]\n",
argv[0]);
exit(1);
}
device-name = malloc(strlen("/dev/") + strlen(argv[1]) + 1);
sprintf(device-name, "/dev/%s", argv[1]);
if ((fd = atm-open(device-name, O-RDWR, &info)) < 0) {
perror("atm-open");
exit(1);
}
mtu = info.mtu; /* Max packet size */
tbuf = malloc(mtu);
rbuf = malloc(mtu);
/*
* Let ATM driver assign a source SAP by specifying
* sap of zero. Set incoming connect request length to
* zero since we're the client. Servers set queue length
* to non zero.
*/
ssap = 0;
qlen = 0;
if (atm-bind(fd, ssap, &ssap, qlen) < 0) {
atm-error("atm-bind");
exit(1);
}
printf("SAP assigned=%d\n", ssap);
/*
* Initialize the server's data link address.
*/
if (atm-gethostbyname(argv[2], &dst.nsap) < 0) {
fprintf(stderr, "atm-gethostbyname failed\n");
exit(1);
}
dst.asap = (argc == 4) ? atoi(argv[3]) : SERVER-SAP;
/*
* Request some quality of service.
*/
qos.peak-bandwidth.target = 0; /* kbit/sec */
qos.peak-bandwidth.minimum = 0; /* kbit/sec */
qos.mean-bandwidth.target = 128; /* kbit/sec */
qos.mean-bandwidth.minimum = 64; /* kbit/sec */
qos.mean-burst.target = 2; /* 2 kbit packet length */
qos.mean-burst.minimum = 1; /* 1 kbit packet length */
if (atm-connect(fd, &dst, &qos, &qos-selected, aal, dataflow) < 0) {
atm-error("atm-connect");
exit(1);
}
printf("selected qos peak=%d, mean=%d, burst=%d\n",
qos-selected.peak-bandwidth,
qos-selected.mean-bandwidth,
qos-selected.mean-burst);
for (i = 1; i <= mtu; i++) {
if (atm-send(fd, tbuf, i) < 0) {
atm-error("atm-send");
exit(1);
}
switch (dataflow) {
case simplex:
if ((i % PROGRESS) == 0)
printf("%d packets sent\n", i);
for (j = 0; j < i * 3; j++)
;
break;
case duplex:
if (atm-recv(fd, rbuf, i) < 0) {
atm-error("atm-recv");
exit(1);
}
if ((i % PROGRESS) == 0)
printf("%d packets sent and received\n", i);
break;
}
}
sleep(1);
return(0);
}
SEE ALSO
atm_intro(4N)