/* * 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 #include #include #include #define SERVER_SAP 4096 #define PROGRESS 1024 /* report progress every n packets */ main(argc, argv) 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); }