Solstice X.25 9.2 Developer's Guide

Chapter 5 Getting Statistics

This chapter contains an example of a program for gathering statistics. By using the ioctls described in Chapter 7, Network Layer ioctls, you can write programs that specify more precisely what kind of statistics you want to gather and whether they should apply to a particular link or virtual circuit.

5.1 Sample Program


Note -

There is a copy of this code sample in the /opt/SUNWconn/x25/samples.stats directory.


The steps for writing this kind of program are:

  1. Include the streams and X.25 header files.

  2. Specify the location of the X.25 devices file descriptor.

  3. Define a structure for containing the statistics.

    In the example these are per-link X.25 statistics.

  4. Open the X.25 driver.

  5. Define the fields required by the ioctl(s) you are using.

    In the example, this is N_getlinkstats, which retrieves per link X.25 statistics.

  6. Specify where you want to gather statistics from.

    For example, N_getlinkstats requires you to give a link number.

  7. Gather the statistics.

    How you do this depends on which ioctls you are using.

  8. Display, or otherwise make use of, the statistics that have been gathered.

     /************************************************************
      * Copyright 20 Apr 1995 Sun Microsystems, Inc. All Rights Reserved
      *
      * This example shows how to open X25 driver,
      * get X25 per_link statistics,
      * and display (as an example) the number of transmit and
      * received CALL packets.
      *
      * Many more information are available for X25 through this ioctl.
      * Many other ioctls permit to get :
      * - Global stats for : IXE, X25 packet layer protocol, LAPB, LLC2, and MLP
      * - Per-link stats for : X25, LAPB, LLC2 and MLP
      * - Per-VC stats
      * Some other ioctls permit to reset those statistics.
      *
      ************************************************************/
    
     /*
      * General includes for streams
      */
     #include <fcntl.h>
     #include <stdio.h>
     #include <sys/types.h>
     #include <sys/stat.h>
     #include <sys/stropts.h>
     #include <sys/stream.h>
    
     /*
      * the following includes are specific to X25
      */
     #include <netx25/uint.h>
     #include <netx25/x25_proto.h>
     #include <netx25/x25_control.h>
    
     /*
      * location of x25 device file descriptor
      */
     #define X25_DEV "/dev/x25"
    
     /* used to open X25 device */
     int x25_fd;
    
     /*
      * io control structure used for all stream ioctl
      * see STREAM programmer's guide for more information about this structure.
      */
     struct strioctl      ioc;
    
     /*
      * this structure to be used to collect X25 per-link stats
      */
     struct perlinkstats  x25_s;
    
     main()
     {
     	/*
     	 * open x25 driver
     	 */
     	x25_fd = open(X25_DEV, O_RDONLY);
     	if (x25_fd == -1)
             {
     			perror("Failed to access X25 driver.\n");
     			exit(1);
     	}
    
     	/*
     	 * set the general info for ioctl
     	 */
     	ioc.ic_cmd = N_getlinkstats;
     	ioc.ic_len = sizeof(x25_s);
     	ioc.ic_dp = (char *) &x25_s;
    
     	/*
     	 * Set the link id.
     	 * Specify the link number where to gather statistics.
     	 * (2 in that particular case)
     	 */
     	x25_s.linkid = 2;
    
     	/*
     	 * perform the STREAMS ioctl
     	 */
     	if (ioctl(x25_fd, I_STR, &ioc) < 0)
     			{
     			perror("Failed to gather X25 per-link statistics");
     			exit(2);
     	}
    
     	/*
     	 * display some statistics
     	 */
     	printf("X25 statistics for link number 2\n");
     	printf("Number of CALL transmitted %10ld\n",
     			x25_s.mon_array[cll_out_s]);
     	printf("Number of CALL received %10ld   \n",
     			x25_s.mon_array[cll_in_s]);
     }