qdisc_hfsc.c revision 1.2 1 /* $KAME: qdisc_hfsc.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_hfsc.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 "quip_client.h"
46 #include "altqstat.h"
47
48 #define NCLASSES 64
49
50 void
51 hfsc_stat_loop(int fd, const char *ifname, int count, int interval)
52 {
53 struct class_stats stats1[NCLASSES], stats2[NCLASSES];
54 char clnames[NCLASSES][128];
55 struct hfsc_class_stats get_stats;
56 struct class_stats *sp, *lp, *new, *last, *tmp;
57 struct timeval cur_time, last_time;
58 int i;
59 double sec;
60 int cnt = count;
61
62 strlcpy(get_stats.iface.hfsc_ifname, ifname,
63 sizeof(get_stats.iface.hfsc_ifname));
64 new = &stats1[0];
65 last = &stats2[0];
66
67 /* invalidate class ids */
68 for (i=0; i<NCLASSES; i++)
69 last[i].class_id = 999999; /* XXX */
70
71 while (count == 0 || cnt-- > 0) {
72 get_stats.nskip = 0;
73 get_stats.nclasses = NCLASSES;
74 get_stats.stats = new;
75
76 if (ioctl(fd, HFSC_GETSTATS, &get_stats) < 0)
77 err(1, "ioctl HFSC_GETSTATS");
78
79 gettimeofday(&cur_time, NULL);
80 sec = calc_interval(&cur_time, &last_time);
81
82 printf("\ncur_time:%#llx %u classes %u packets in the tree\n",
83 (ull)get_stats.cur_time,
84 get_stats.hif_classes, get_stats.hif_packets);
85
86 for (i=0; i<get_stats.nclasses; i++) {
87 sp = &new[i];
88 lp = &last[i];
89
90 if (sp->class_id != lp->class_id) {
91 quip_chandle2name(ifname, sp->class_handle,
92 clnames[i], sizeof(clnames[0]));
93 continue;
94 }
95
96 printf("[%2d %s] handle:%#lx [rt %s %ums %s][ls %s %ums %s]\n",
97 sp->class_id, clnames[i], sp->class_handle,
98 rate2str((double)sp->rsc.m1), sp->rsc.d,
99 rate2str((double)sp->rsc.m2),
100 rate2str((double)sp->fsc.m1), sp->fsc.d,
101 rate2str((double)sp->fsc.m2));
102 printf(" measured: %sbps [rt:%s ls:%s] qlen:%2d period:%u\n",
103 rate2str(calc_rate(sp->total, lp->total, sec)),
104 rate2str(calc_rate(sp->cumul, lp->cumul, sec)),
105 rate2str(calc_rate(sp->total - sp->cumul,
106 lp->total - lp->cumul, sec)),
107 sp->qlength, sp->period);
108 printf(" packets:%llu (%llu bytes) drops:%llu\n",
109 (ull)sp->xmit_cnt.packets,
110 (ull)sp->xmit_cnt.bytes,
111 (ull)sp->drop_cnt.packets);
112 printf(" cumul:%#llx total:%#llx\n",
113 (ull)sp->cumul, (ull)sp->total);
114 printf(" vt:%#llx d:%#llx e:%#llx\n",
115 (ull)sp->vt, (ull)sp->d, (ull)sp->e);
116 if (sp->qtype == Q_RED)
117 print_redstats(sp->red);
118 else if (sp->qtype == Q_RIO)
119 print_riostats(sp->red);
120 }
121
122 /* swap the buffer pointers */
123 tmp = last;
124 last = new;
125 new = tmp;
126
127 last_time = cur_time;
128 sleep(interval);
129 }
130 }
131