qdisc_rio.c revision 1.2 1 /* $KAME: qdisc_rio.c,v 1.4 2001/08/15 12:51:59 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 strlcpy(rio_stats.iface.rio_ifname, ifname,
61 sizeof(rio_stats.iface.rio_ifname));
62
63 gettimeofday(&last_time, NULL);
64 last_time.tv_sec -= interval;
65
66 while (count == 0 || cnt-- > 0) {
67
68 if (ioctl(fd, RIO_GETSTATS, &rio_stats) < 0)
69 err(1, "ioctl RIO_GETSTATS");
70
71 gettimeofday(&cur_time, NULL);
72 sec = calc_interval(&cur_time, &last_time);
73
74 printf("weight:%d q_limit:%d\n",
75 rio_stats.weight, rio_stats.q_limit);
76
77 printf("\t\t\tLOW DP\t\tMEDIUM DP\t\tHIGH DP\n");
78
79 printf("thresh (prob):\t\t[%d,%d](1/%d)\t[%d,%d](1/%d)\t\t[%d,%d](%d)\n",
80 rio_stats.q_params[0].th_min,
81 rio_stats.q_params[0].th_max,
82 rio_stats.q_params[0].inv_pmax,
83 rio_stats.q_params[1].th_min,
84 rio_stats.q_params[1].th_max,
85 rio_stats.q_params[1].inv_pmax,
86 rio_stats.q_params[2].th_min,
87 rio_stats.q_params[2].th_max,
88 rio_stats.q_params[2].inv_pmax);
89 printf("qlen (avg):\t\t%d (%.2f)\t%d (%.2f)\t\t%d (%.2f)\n",
90 rio_stats.q_len[0],
91 ((double)rio_stats.q_stats[0].q_avg)/(double)avg_scale,
92 rio_stats.q_len[1],
93 ((double)rio_stats.q_stats[1].q_avg)/(double)avg_scale,
94 rio_stats.q_len[2],
95 ((double)rio_stats.q_stats[2].q_avg)/(double)avg_scale);
96 printf("xmit (drop) pkts:\t%llu (%llu)\t\t%llu (%llu)\t\t\t%llu (%llu)\n",
97 (ull)rio_stats.q_stats[0].xmit_cnt.packets,
98 (ull)rio_stats.q_stats[0].drop_cnt.packets,
99 (ull)rio_stats.q_stats[1].xmit_cnt.packets,
100 (ull)rio_stats.q_stats[1].drop_cnt.packets,
101 (ull)rio_stats.q_stats[2].xmit_cnt.packets,
102 (ull)rio_stats.q_stats[2].drop_cnt.packets);
103 printf("(forced:early):\t\t(%u:%u)\t\t(%u:%u)\t\t\t(%u:%u)\n",
104 rio_stats.q_stats[0].drop_forced,
105 rio_stats.q_stats[0].drop_unforced,
106 rio_stats.q_stats[1].drop_forced,
107 rio_stats.q_stats[1].drop_unforced,
108 rio_stats.q_stats[2].drop_forced,
109 rio_stats.q_stats[2].drop_unforced);
110 if (rio_stats.q_stats[0].marked_packets != 0
111 || rio_stats.q_stats[1].marked_packets != 0
112 || rio_stats.q_stats[2].marked_packets != 0)
113 printf("marked:\t\t\t%u\t\t%u\t\t\t%u\n",
114 rio_stats.q_stats[0].marked_packets,
115 rio_stats.q_stats[1].marked_packets,
116 rio_stats.q_stats[2].marked_packets);
117 printf("throughput:\t\t%sbps\t%sbps\t\t%sbps\n\n",
118 rate2str(calc_rate(rio_stats.q_stats[0].xmit_cnt.bytes,
119 last_bytes[0], sec)),
120 rate2str(calc_rate(rio_stats.q_stats[1].xmit_cnt.bytes,
121 last_bytes[1], sec)),
122 rate2str(calc_rate(rio_stats.q_stats[2].xmit_cnt.bytes,
123 last_bytes[2], sec)));
124
125 last_bytes[0] = rio_stats.q_stats[0].xmit_cnt.bytes;
126 last_bytes[1] = rio_stats.q_stats[1].xmit_cnt.bytes;
127 last_bytes[2] = rio_stats.q_stats[2].xmit_cnt.bytes;
128 last_time = cur_time;
129 sleep(interval);
130 }
131 }
132
133 int
134 print_riostats(struct redstats *rp)
135 {
136 int dp;
137
138 for (dp = 0; dp < RIO_NDROPPREC; dp++)
139 printf(" RIO[%d] q_avg:%.2f xmit:%llu (forced: %u early:%u marked:%u)\n",
140 dp,
141 ((double)rp[dp].q_avg)/(double)avg_scale,
142 (ull)rp[dp].xmit_cnt.packets,
143 rp[dp].drop_forced,
144 rp[dp].drop_unforced,
145 rp[dp].marked_packets);
146 return 0;
147 }
148