qdisc_red.c revision 1.1 1 /* $KAME: qdisc_red.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
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <unistd.h>
40 #include <string.h>
41 #include <math.h>
42 #include <errno.h>
43 #include <err.h>
44
45 #include "altqstat.h"
46
47 static int avg_scale = 4096; /* default fixed-point scale */
48
49 void
50 red_stat_loop(int fd, const char *ifname, int count, int interval)
51 {
52 struct red_stats red_stats;
53 struct timeval cur_time, last_time;
54 u_int64_t last_bytes;
55 double sec;
56 int cnt = count;
57
58 strcpy(red_stats.iface.red_ifname, ifname);
59
60 gettimeofday(&last_time, NULL);
61 last_time.tv_sec -= interval;
62 last_bytes = 0;
63
64 while (count == 0 || cnt-- > 0) {
65
66 if (ioctl(fd, RED_GETSTATS, &red_stats) < 0)
67 err(1, "ioctl RED_GETSTATS");
68
69 gettimeofday(&cur_time, NULL);
70 sec = calc_interval(&cur_time, &last_time);
71
72 printf(" weight:%d inv_pmax:%d qthresh:(%d,%d)\n",
73 red_stats.weight, red_stats.inv_pmax,
74 red_stats.th_min, red_stats.th_max);
75 printf(" q_len:%d (avg: %.2f), q_limit:%d\n",
76 red_stats.q_len,
77 ((double)red_stats.q_avg)/(double)avg_scale,
78 red_stats.q_limit);
79 printf(" xmit:%llu pkts, drop:%llu pkts (forced: %u, early: %u)\n",
80 (ull)red_stats.xmit_cnt.packets,
81 (ull)red_stats.drop_cnt.packets,
82 red_stats.drop_forced, red_stats.drop_unforced);
83 if (red_stats.marked_packets != 0)
84 printf(" marked: %u\n", red_stats.marked_packets);
85 printf(" throughput: %sbps\n",
86 rate2str(calc_rate(red_stats.xmit_cnt.bytes,
87 last_bytes, sec)));
88 if (red_stats.fv_alloc > 0) {
89 printf(" flowvalve: alloc:%u flows:%u\n",
90 red_stats.fv_alloc, red_stats.fv_flows);
91 printf(" predrop:%u pass:%u escape:%u\n",
92 red_stats.fv_predrop, red_stats.fv_pass,
93 red_stats.fv_escape);
94 }
95 printf("\n");
96
97 last_bytes = red_stats.xmit_cnt.bytes;
98 last_time = cur_time;
99 sleep(interval);
100 }
101 }
102
103 int
104 print_redstats(struct redstats *rp)
105 {
106 printf(" RED q_avg:%.2f xmit:%llu (forced:%u early:%u marked:%u)\n",
107 ((double)rp->q_avg)/(double)avg_scale,
108 (ull)rp->xmit_cnt.packets,
109 rp->drop_forced,
110 rp->drop_unforced,
111 rp->marked_packets);
112 return 0;
113 }
114