qdisc_cbq.c revision 1.3
1/* $KAME: qdisc_cbq.c,v 1.4 2001/08/15 12:51:58 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_cbq.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#ifndef RM_FILTER_GAIN 51#define RM_FILTER_GAIN 5 /* log2 of gain, e.g., 5 => 31/32 */ 52#endif 53#ifndef RM_POWER 54#define RM_POWER (1 << RM_FILTER_GAIN) 55#endif 56 57void 58cbq_stat_loop(int fd, const char *ifname, int count, int interval) 59{ 60 class_stats_t stats1[NCLASSES], stats2[NCLASSES]; 61 char clnames[NCLASSES][128]; 62 u_long clhandles[NCLASSES]; 63 struct cbq_getstats get_stats; 64 class_stats_t *sp, *lp, *new, *last, *tmp; 65 struct timeval cur_time, last_time; 66 int i; 67 double flow_bps, sec; 68 int cnt = count; 69 70 strlcpy(get_stats.iface.cbq_ifacename, ifname, 71 sizeof(get_stats.iface.cbq_ifacename)); 72 new = &stats1[0]; 73 last = &stats2[0]; 74 75 for (i = 0; i < NCLASSES; i++) 76 clhandles[i] = NULL_CLASS_HANDLE; 77 78 while (count == 0 || cnt-- > 0) { 79 get_stats.nclasses = NCLASSES; 80 get_stats.stats = new; 81 if (ioctl(fd, CBQ_GETSTATS, &get_stats) < 0) 82 err(1, "ioctl CBQ_GETSTATS"); 83 84 gettimeofday(&cur_time, NULL); 85 sec = calc_interval(&cur_time, &last_time); 86 87 for (i=0; i<get_stats.nclasses; i++) { 88 sp = &new[i]; 89 lp = &last[i]; 90 91 if (sp->handle != clhandles[i]) { 92 quip_chandle2name(ifname, sp->handle, 93 clnames[i], sizeof(clnames[0])); 94 clhandles[i] = sp->handle; 95 continue; 96 } 97 98 switch (sp->handle) { 99 case ROOT_CLASS_HANDLE: 100 printf("Root Class for Interface %s: %s\n", 101 ifname, clnames[i]); 102 break; 103 case DEFAULT_CLASS_HANDLE: 104 printf("Default Class for Interface %s: %s\n", 105 ifname, clnames[i]); 106 break; 107 case CTL_CLASS_HANDLE: 108 printf("Ctl Class for Interface %s: %s\n", 109 ifname, clnames[i]); 110 break; 111 default: 112 printf("Class %d on Interface %s: %s\n", 113 sp->handle, ifname, clnames[i]); 114 break; 115 } 116 117 flow_bps = 8.0 / (double)sp->ns_per_byte 118 * 1000*1000*1000; 119 120 printf("\tpriority: %d depth: %d", 121 sp->priority, sp->depth); 122 printf(" offtime: %d [us] wrr_allot: %d bytes\n", 123 sp->offtime, sp->wrr_allot); 124 printf("\tnsPerByte: %d", sp->ns_per_byte); 125 printf("\t(%sbps),", rate2str(flow_bps)); 126 printf("\tMeasured: %s [bps]\n", 127 rate2str(calc_rate(sp->xmit_cnt.bytes, 128 lp->xmit_cnt.bytes, sec))); 129 printf("\tpkts: %llu,\tbytes: %llu\n", 130 (ull)sp->xmit_cnt.packets, 131 (ull)sp->xmit_cnt.bytes); 132 printf("\tovers: %u,\toveractions: %u\n", 133 sp->over, sp->overactions); 134 printf("\tborrows: %u,\tdelays: %u\n", 135 sp->borrows, sp->delays); 136 printf("\tdrops: %llu,\tdrop_bytes: %llu\n", 137 (ull)sp->drop_cnt.bytes, 138 (ull)sp->drop_cnt.bytes); 139 if (sp->qtype == Q_RED) 140 print_redstats(sp->red); 141 else if (sp->qtype == Q_RIO) 142 print_riostats(sp->red); 143 144 printf("\tQCount: %d,\t(qmax: %d)\n", 145 sp->qcnt, sp->qmax); 146 printf("\tAvgIdle: %d [us],\t(maxidle: %d minidle: %d [us])\n", 147 sp->avgidle >> RM_FILTER_GAIN, 148 sp->maxidle >> RM_FILTER_GAIN, 149 sp->minidle / RM_POWER); 150 } 151 152 /* swap the buffer pointers */ 153 tmp = last; 154 last = new; 155 new = tmp; 156 157 last_time = cur_time; 158 sleep(interval); 159 } 160} 161