Home | History | Annotate | Line # | Download | only in altqstat
qdisc_rio.c revision 1.1
      1 /*	$KAME: qdisc_rio.c,v 1.2 2000/10/18 09:15:17 kjc Exp $	*/
      2 /*
      3  * Copyright (C) 1999-2000
      4  *	Sony Computer Science Laboratories, Inc.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
     16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18  * ARE DISCLAIMED.  IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
     19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  * SUCH DAMAGE.
     26  */
     27 
     28 #include <sys/param.h>
     29 #include <sys/ioctl.h>
     30 #include <sys/time.h>
     31 #include <sys/socket.h>
     32 #include <net/if.h>
     33 #include <netinet/in.h>
     34 #include <altq/altq.h>
     35 #include <altq/altq_red.h>
     36 #include <altq/altq_rio.h>
     37 
     38 #include <stdio.h>
     39 #include <stdlib.h>
     40 #include <unistd.h>
     41 #include <string.h>
     42 #include <math.h>
     43 #include <errno.h>
     44 #include <err.h>
     45 
     46 #include "altqstat.h"
     47 
     48 static int avg_scale = 4096;	/* default fixed-point scale */
     49 
     50 void
     51 rio_stat_loop(int fd, const char *ifname, int count, int interval)
     52 {
     53 	struct rio_stats rio_stats;
     54 	struct timeval cur_time, last_time;
     55 	u_int64_t last_bytes[3];
     56 	double sec;
     57 	int cnt = count;
     58 
     59 	bzero(&rio_stats, sizeof(rio_stats));
     60 	strcpy(rio_stats.iface.rio_ifname, ifname);
     61 
     62 	gettimeofday(&last_time, NULL);
     63 	last_time.tv_sec -= interval;
     64 
     65 	while (count == 0 || cnt-- > 0) {
     66 
     67 		if (ioctl(fd, RIO_GETSTATS, &rio_stats) < 0)
     68 			err(1, "ioctl RIO_GETSTATS");
     69 
     70 		gettimeofday(&cur_time, NULL);
     71 		sec = calc_interval(&cur_time, &last_time);
     72 
     73 		printf("weight:%d q_limit:%d\n",
     74 		       rio_stats.weight, rio_stats.q_limit);
     75 
     76 		printf("\t\t\tLOW DP\t\tMEDIUM DP\t\tHIGH DP\n");
     77 
     78 		printf("thresh (prob):\t\t[%d,%d](1/%d)\t[%d,%d](1/%d)\t\t[%d,%d](%d)\n",
     79 		       rio_stats.q_params[0].th_min,
     80 		       rio_stats.q_params[0].th_max,
     81 		       rio_stats.q_params[0].inv_pmax,
     82 		       rio_stats.q_params[1].th_min,
     83 		       rio_stats.q_params[1].th_max,
     84 		       rio_stats.q_params[1].inv_pmax,
     85 		       rio_stats.q_params[2].th_min,
     86 		       rio_stats.q_params[2].th_max,
     87 		       rio_stats.q_params[2].inv_pmax);
     88 		printf("qlen (avg):\t\t%d (%.2f)\t%d (%.2f)\t\t%d (%.2f)\n",
     89 		       rio_stats.q_len[0],
     90 		       ((double)rio_stats.q_stats[0].q_avg)/(double)avg_scale,
     91 		       rio_stats.q_len[1],
     92 		       ((double)rio_stats.q_stats[1].q_avg)/(double)avg_scale,
     93 		       rio_stats.q_len[2],
     94 		       ((double)rio_stats.q_stats[2].q_avg)/(double)avg_scale);
     95 		printf("xmit (drop) pkts:\t%llu (%llu)\t\t%llu (%llu)\t\t\t%llu (%llu)\n",
     96 		       (ull)rio_stats.q_stats[0].xmit_cnt.packets,
     97 		       (ull)rio_stats.q_stats[0].drop_cnt.packets,
     98 		       (ull)rio_stats.q_stats[1].xmit_cnt.packets,
     99 		       (ull)rio_stats.q_stats[1].drop_cnt.packets,
    100 		       (ull)rio_stats.q_stats[2].xmit_cnt.packets,
    101 		       (ull)rio_stats.q_stats[2].drop_cnt.packets);
    102 		printf("(forced:early):\t\t(%u:%u)\t\t(%u:%u)\t\t\t(%u:%u)\n",
    103 		       rio_stats.q_stats[0].drop_forced,
    104 		       rio_stats.q_stats[0].drop_unforced,
    105 		       rio_stats.q_stats[1].drop_forced,
    106 		       rio_stats.q_stats[1].drop_unforced,
    107 		       rio_stats.q_stats[2].drop_forced,
    108 		       rio_stats.q_stats[2].drop_unforced);
    109 		if (rio_stats.q_stats[0].marked_packets != 0
    110 		    || rio_stats.q_stats[1].marked_packets != 0
    111 		    || rio_stats.q_stats[2].marked_packets != 0)
    112 			printf("marked:\t\t\t%u\t\t%u\t\t\t%u\n",
    113 			       rio_stats.q_stats[0].marked_packets,
    114 			       rio_stats.q_stats[1].marked_packets,
    115 			       rio_stats.q_stats[2].marked_packets);
    116 		printf("throughput:\t\t%sbps\t%sbps\t\t%sbps\n\n",
    117 		       rate2str(calc_rate(rio_stats.q_stats[0].xmit_cnt.bytes,
    118 					  last_bytes[0], sec)),
    119 		       rate2str(calc_rate(rio_stats.q_stats[1].xmit_cnt.bytes,
    120 					  last_bytes[1], sec)),
    121 		       rate2str(calc_rate(rio_stats.q_stats[2].xmit_cnt.bytes,
    122 					  last_bytes[2], sec)));
    123 
    124 		last_bytes[0] = rio_stats.q_stats[0].xmit_cnt.bytes;
    125 		last_bytes[1] = rio_stats.q_stats[1].xmit_cnt.bytes;
    126 		last_bytes[2] = rio_stats.q_stats[3].xmit_cnt.bytes;
    127 		last_time = cur_time;
    128 		sleep(interval);
    129 	}
    130 }
    131 
    132 int
    133 print_riostats(struct redstats *rp)
    134 {
    135 	int dp;
    136 
    137 	for (dp = 0; dp < RIO_NDROPPREC; dp++)
    138 		printf("     RIO[%d] q_avg:%.2f xmit:%llu (forced: %u early:%u marked:%u)\n",
    139 		       dp,
    140 		       ((double)rp[dp].q_avg)/(double)avg_scale,
    141 		       (ull)rp[dp].xmit_cnt.packets,
    142 		       rp[dp].drop_forced,
    143 		       rp[dp].drop_unforced,
    144 		       rp[dp].marked_packets);
    145 	return 0;
    146 }
    147