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