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