1 /* $NetBSD: qdisc_wfq.c,v 1.4 2006/10/12 19:59:13 peter Exp $ */
2 /* $KAME: qdisc_wfq.c,v 1.5 2002/11/08 06:36:18 kjc Exp $ */
4 * Copyright (C) 1999-2000
5 * Sony Computer Science Laboratories, Inc. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
29 #include <sys/param.h>
30 #include <sys/ioctl.h>
32 #include <sys/socket.h>
34 #include <netinet/in.h>
35 #include <altq/altq.h>
36 #include <altq/altq_wfq.h>
59 static int ntop
= NTOP
;
62 wfq_stat_loop(int fd
, const char *ifname
, int count
, int interval
)
64 struct wfq_getstats wfq_stats
;
65 struct timeval cur_time
, last_time
;
68 struct wfqinfo
*qinfo
, **top
;
72 strlcpy(wfq_stats
.iface
.wfq_ifacename
, ifname
,
73 sizeof(wfq_stats
.iface
.wfq_ifacename
));
76 * first, find out how many queues are available
78 for (i
= 0; i
< MAX_QSIZE
; i
++) {
80 if (ioctl(fd
, WFQ_GET_STATS
, &wfq_stats
) < 0)
84 printf("wfq on %s: %d queues are used\n", ifname
, nqueues
);
86 if ((qinfo
= malloc(nqueues
* sizeof(struct wfqinfo
))) == NULL
)
87 err(1, "malloc failed!");
88 if ((top
= malloc(ntop
* sizeof(struct wfqinfo
*))) == NULL
)
89 err(1, "malloc failed!");
92 sleep(2); /* wait a bit before clearing the screen */
97 gettimeofday(&last_time
, NULL
);
98 last_time
.tv_sec
-= interval
;
101 for (j
= 0; j
< ntop
; j
++)
104 for (i
= 0; i
< nqueues
; i
++) {
106 if (ioctl(fd
, WFQ_GET_STATS
, &wfq_stats
) < 0)
107 err(1, "ioctl WFQ_GET_STATS");
110 qinfo
[i
].stats
= wfq_stats
.stats
;
113 gettimeofday(&cur_time
, NULL
);
114 sec
= calc_interval(&cur_time
, &last_time
);
117 * calculate the throughput of each queue
119 for (i
= 0; i
< nqueues
; i
++) {
120 qinfo
[i
].bps
= calc_rate(qinfo
[i
].stats
.xmit_cnt
.bytes
,
121 qinfo
[i
].last_bytes
, sec
);
122 qinfo
[i
].last_bytes
= qinfo
[i
].stats
.xmit_cnt
.bytes
;
124 for (j
= 0; j
< ntop
; j
++) {
125 if (top
[j
] == NULL
) {
129 if (top
[j
]->bps
< qinfo
[i
].bps
||
130 (top
[j
]->bps
== qinfo
[i
].bps
&&
131 top
[j
]->stats
.xmit_cnt
.packets
<
132 qinfo
[i
].stats
.xmit_cnt
.packets
)) {
133 for (k
= ntop
-1; k
> j
; k
--)
144 printf("[QID] WEIGHT QSIZE(KB) SENT(pkts) (KB) DROP(pkts) (KB) bps\n\r");
146 for (j
= 0; j
< ntop
; j
++) {
148 printf("[%4d] %4d %4d %10llu %14llu %10llu %14llu %9s\n\r",
150 top
[j
]->stats
.weight
,
151 top
[j
]->stats
.bytes
/ 1024,
152 (ull
)top
[j
]->stats
.xmit_cnt
.packets
,
153 (ull
)top
[j
]->stats
.xmit_cnt
.bytes
/1024,
154 (ull
)top
[j
]->stats
.drop_cnt
.packets
,
155 (ull
)top
[j
]->stats
.drop_cnt
.bytes
/1024,
156 rate2str(top
[j
]->bps
));
162 mvcur(ntop
+1, 0, 0, 0);
165 last_time
= cur_time
;
167 if (count
!= 0 && --cnt
== 0)
170 /* wait for alarm signal */
171 if (sigprocmask(SIG_BLOCK
, NULL
, &omask
) == 0)