/* * Copyright (c) 1992 by Fore Systems, Inc. */ #ifndef lint static char _atm_server_aal4_c_[] = "@(#)$Id: atm_server_aal4.c,v 1.3 1994/06/28 20:18:39 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, mtu, qlen, conn_id; u_int switchid, portid; Atm_info info; Atm_endpoint calling; Atm_qos qos; Atm_sap ssap; Aal_type aal; Atm_dataflow dataflow = simplex; char *device_name; char *tbuf, *rbuf; extern char *malloc(); if (argc < 2) { fprintf(stderr, "Usage: %s device [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); /* * Bind to a well known sap and set pending * connect request queue length. */ ssap = (argc == 3) ? atoi(argv[2]) : SERVER_SAP; qlen = 1; if (atm_bind(fd, ssap, &ssap, qlen) < 0) { atm_error("atm_bind"); exit(1); } printf("SAP assigned=%d\n", ssap); /* * Wait for a connection request. */ if (atm_listen(fd, &conn_id, &calling, &qos, &aal) < 0) { atm_error("atm_connect"); exit(1); } /* * Extract the switch id and port id from the NSAP. */ GET_SWITCH(switchid, calling.nsap); GET_PORT(portid, calling.nsap); printf("calling switch=%d, port=%d, sap=%d, aal=%d\n", switchid, portid, calling.asap, aal); printf("qos target peak=%d, mean=%d, burst=%d\n", qos.peak_bandwidth.target, qos.mean_bandwidth.target, qos.mean_burst.target); printf("qos minimum peak=%d, mean=%d, burst=%d\n", qos.peak_bandwidth.minimum, qos.mean_bandwidth.minimum, qos.mean_burst.minimum); printf("connect conn_id=%d\n", conn_id); /* * 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 */ /* * Accept the connection request. */ if (atm_accept(fd, fd, conn_id, &qos, dataflow) < 0) { atm_error("atm_accept"); exit(1); } for (i = 1; i <= mtu; i++) { if (atm_recv(fd, rbuf, i) < 0) { atm_error("atm_recv"); break; } switch (dataflow) { case simplex: if ((i % PROGRESS) == 0) printf("%d packets received\n", i); break; case duplex: if (atm_send(fd, tbuf, i) < 0) { atm_error("atm_send"); break; } if ((i % PROGRESS) == 0) printf("%d packets received and sent\n", i); break; } } printf("%d packets sent and/or received\n", i); sleep(1); return(0); }