qdisc_hfsc.c revision 1.3 1 /* $NetBSD: qdisc_hfsc.c,v 1.3 2001/08/16 07:48:11 itojun Exp $ */
2 /* $KAME: qdisc_hfsc.c,v 1.4 2001/08/15 12:51:59 kjc Exp $ */
3 /*
4 * Copyright (C) 1999-2000
5 * Sony Computer Science Laboratories, Inc. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #include <sys/param.h>
30 #include <sys/ioctl.h>
31 #include <sys/time.h>
32 #include <sys/socket.h>
33 #include <net/if.h>
34 #include <netinet/in.h>
35 #include <altq/altq.h>
36 #include <altq/altq_hfsc.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 "quip_client.h"
47 #include "altqstat.h"
48
49 #define NCLASSES 64
50
51 void
52 hfsc_stat_loop(int fd, const char *ifname, int count, int interval)
53 {
54 struct class_stats stats1[NCLASSES], stats2[NCLASSES];
55 char clnames[NCLASSES][128];
56 struct hfsc_class_stats get_stats;
57 struct class_stats *sp, *lp, *new, *last, *tmp;
58 struct timeval cur_time, last_time;
59 int i;
60 double sec;
61 int cnt = count;
62
63 strlcpy(get_stats.iface.hfsc_ifname, ifname,
64 sizeof(get_stats.iface.hfsc_ifname));
65 new = &stats1[0];
66 last = &stats2[0];
67
68 /* invalidate class ids */
69 for (i=0; i<NCLASSES; i++)
70 last[i].class_id = 999999; /* XXX */
71
72 while (count == 0 || cnt-- > 0) {
73 get_stats.nskip = 0;
74 get_stats.nclasses = NCLASSES;
75 get_stats.stats = new;
76
77 if (ioctl(fd, HFSC_GETSTATS, &get_stats) < 0)
78 err(1, "ioctl HFSC_GETSTATS");
79
80 gettimeofday(&cur_time, NULL);
81 sec = calc_interval(&cur_time, &last_time);
82
83 printf("\ncur_time:%#llx %u classes %u packets in the tree\n",
84 (ull)get_stats.cur_time,
85 get_stats.hif_classes, get_stats.hif_packets);
86
87 for (i=0; i<get_stats.nclasses; i++) {
88 sp = &new[i];
89 lp = &last[i];
90
91 if (sp->class_id != lp->class_id) {
92 quip_chandle2name(ifname, sp->class_handle,
93 clnames[i], sizeof(clnames[0]));
94 continue;
95 }
96
97 printf("[%2d %s] handle:%#lx [rt %s %ums %s][ls %s %ums %s]\n",
98 sp->class_id, clnames[i], sp->class_handle,
99 rate2str((double)sp->rsc.m1), sp->rsc.d,
100 rate2str((double)sp->rsc.m2),
101 rate2str((double)sp->fsc.m1), sp->fsc.d,
102 rate2str((double)sp->fsc.m2));
103 printf(" measured: %sbps [rt:%s ls:%s] qlen:%2d period:%u\n",
104 rate2str(calc_rate(sp->total, lp->total, sec)),
105 rate2str(calc_rate(sp->cumul, lp->cumul, sec)),
106 rate2str(calc_rate(sp->total - sp->cumul,
107 lp->total - lp->cumul, sec)),
108 sp->qlength, sp->period);
109 printf(" packets:%llu (%llu bytes) drops:%llu\n",
110 (ull)sp->xmit_cnt.packets,
111 (ull)sp->xmit_cnt.bytes,
112 (ull)sp->drop_cnt.packets);
113 printf(" cumul:%#llx total:%#llx\n",
114 (ull)sp->cumul, (ull)sp->total);
115 printf(" vt:%#llx d:%#llx e:%#llx\n",
116 (ull)sp->vt, (ull)sp->d, (ull)sp->e);
117 if (sp->qtype == Q_RED)
118 print_redstats(sp->red);
119 else if (sp->qtype == Q_RIO)
120 print_riostats(sp->red);
121 }
122
123 /* swap the buffer pointers */
124 tmp = last;
125 last = new;
126 new = tmp;
127
128 last_time = cur_time;
129 sleep(interval);
130 }
131 }
132