NAME

     atm_server_aal4 - example server ATM program using AAL 3/4


EXAMPLE

     /*
      * 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 <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, 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);
     }


SEE ALSO

     atm_intro(4N)