qdisc_cbq.c revision 1.5
11.5Sitojun/* $NetBSD: qdisc_cbq.c,v 1.5 2002/03/05 04:11:52 itojun Exp $ */ 21.5Sitojun/* $KAME: qdisc_cbq.c,v 1.5 2001/11/07 04:56:08 kjc Exp $ */ 31.1Sthorpej/* 41.1Sthorpej * Copyright (C) 1999-2000 51.1Sthorpej * Sony Computer Science Laboratories, Inc. All rights reserved. 61.1Sthorpej * 71.1Sthorpej * Redistribution and use in source and binary forms, with or without 81.1Sthorpej * modification, are permitted provided that the following conditions 91.1Sthorpej * are met: 101.1Sthorpej * 1. Redistributions of source code must retain the above copyright 111.1Sthorpej * notice, this list of conditions and the following disclaimer. 121.1Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 131.1Sthorpej * notice, this list of conditions and the following disclaimer in the 141.1Sthorpej * documentation and/or other materials provided with the distribution. 151.1Sthorpej * 161.1Sthorpej * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND 171.1Sthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 181.1Sthorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 191.1Sthorpej * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE 201.1Sthorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 211.1Sthorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 221.1Sthorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 231.1Sthorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 241.1Sthorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 251.1Sthorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 261.1Sthorpej * SUCH DAMAGE. 271.1Sthorpej */ 281.1Sthorpej 291.1Sthorpej#include <sys/param.h> 301.1Sthorpej#include <sys/ioctl.h> 311.1Sthorpej#include <sys/time.h> 321.1Sthorpej#include <sys/socket.h> 331.1Sthorpej#include <net/if.h> 341.1Sthorpej#include <netinet/in.h> 351.1Sthorpej#include <altq/altq.h> 361.1Sthorpej#include <altq/altq_cbq.h> 371.1Sthorpej 381.1Sthorpej#include <stdio.h> 391.1Sthorpej#include <stdlib.h> 401.1Sthorpej#include <unistd.h> 411.1Sthorpej#include <string.h> 421.1Sthorpej#include <math.h> 431.1Sthorpej#include <errno.h> 441.1Sthorpej#include <err.h> 451.1Sthorpej 461.1Sthorpej#include "quip_client.h" 471.1Sthorpej#include "altqstat.h" 481.1Sthorpej 491.1Sthorpej#define NCLASSES 64 501.1Sthorpej 511.1Sthorpej#ifndef RM_FILTER_GAIN 521.1Sthorpej#define RM_FILTER_GAIN 5 /* log2 of gain, e.g., 5 => 31/32 */ 531.1Sthorpej#endif 541.1Sthorpej#ifndef RM_POWER 551.1Sthorpej#define RM_POWER (1 << RM_FILTER_GAIN) 561.1Sthorpej#endif 571.1Sthorpej 581.1Sthorpejvoid 591.1Sthorpejcbq_stat_loop(int fd, const char *ifname, int count, int interval) 601.1Sthorpej{ 611.1Sthorpej class_stats_t stats1[NCLASSES], stats2[NCLASSES]; 621.1Sthorpej char clnames[NCLASSES][128]; 631.1Sthorpej u_long clhandles[NCLASSES]; 641.1Sthorpej struct cbq_getstats get_stats; 651.1Sthorpej class_stats_t *sp, *lp, *new, *last, *tmp; 661.1Sthorpej struct timeval cur_time, last_time; 671.1Sthorpej int i; 681.1Sthorpej double flow_bps, sec; 691.1Sthorpej int cnt = count; 701.1Sthorpej 711.3Sitojun strlcpy(get_stats.iface.cbq_ifacename, ifname, 721.3Sitojun sizeof(get_stats.iface.cbq_ifacename)); 731.1Sthorpej new = &stats1[0]; 741.1Sthorpej last = &stats2[0]; 751.1Sthorpej 761.1Sthorpej for (i = 0; i < NCLASSES; i++) 771.1Sthorpej clhandles[i] = NULL_CLASS_HANDLE; 781.1Sthorpej 791.1Sthorpej while (count == 0 || cnt-- > 0) { 801.1Sthorpej get_stats.nclasses = NCLASSES; 811.1Sthorpej get_stats.stats = new; 821.1Sthorpej if (ioctl(fd, CBQ_GETSTATS, &get_stats) < 0) 831.1Sthorpej err(1, "ioctl CBQ_GETSTATS"); 841.1Sthorpej 851.1Sthorpej gettimeofday(&cur_time, NULL); 861.1Sthorpej sec = calc_interval(&cur_time, &last_time); 871.1Sthorpej 881.1Sthorpej for (i=0; i<get_stats.nclasses; i++) { 891.1Sthorpej sp = &new[i]; 901.1Sthorpej lp = &last[i]; 911.1Sthorpej 921.1Sthorpej if (sp->handle != clhandles[i]) { 931.1Sthorpej quip_chandle2name(ifname, sp->handle, 941.3Sitojun clnames[i], sizeof(clnames[0])); 951.1Sthorpej clhandles[i] = sp->handle; 961.1Sthorpej continue; 971.1Sthorpej } 981.1Sthorpej 991.1Sthorpej switch (sp->handle) { 1001.1Sthorpej case ROOT_CLASS_HANDLE: 1011.1Sthorpej printf("Root Class for Interface %s: %s\n", 1021.1Sthorpej ifname, clnames[i]); 1031.1Sthorpej break; 1041.1Sthorpej case DEFAULT_CLASS_HANDLE: 1051.1Sthorpej printf("Default Class for Interface %s: %s\n", 1061.1Sthorpej ifname, clnames[i]); 1071.1Sthorpej break; 1081.1Sthorpej case CTL_CLASS_HANDLE: 1091.1Sthorpej printf("Ctl Class for Interface %s: %s\n", 1101.1Sthorpej ifname, clnames[i]); 1111.1Sthorpej break; 1121.1Sthorpej default: 1131.1Sthorpej printf("Class %d on Interface %s: %s\n", 1141.1Sthorpej sp->handle, ifname, clnames[i]); 1151.1Sthorpej break; 1161.1Sthorpej } 1171.1Sthorpej 1181.1Sthorpej flow_bps = 8.0 / (double)sp->ns_per_byte 1191.1Sthorpej * 1000*1000*1000; 1201.1Sthorpej 1211.1Sthorpej printf("\tpriority: %d depth: %d", 1221.1Sthorpej sp->priority, sp->depth); 1231.1Sthorpej printf(" offtime: %d [us] wrr_allot: %d bytes\n", 1241.1Sthorpej sp->offtime, sp->wrr_allot); 1251.1Sthorpej printf("\tnsPerByte: %d", sp->ns_per_byte); 1261.2Sthorpej printf("\t(%sbps),", rate2str(flow_bps)); 1271.2Sthorpej printf("\tMeasured: %s [bps]\n", 1281.1Sthorpej rate2str(calc_rate(sp->xmit_cnt.bytes, 1291.1Sthorpej lp->xmit_cnt.bytes, sec))); 1301.1Sthorpej printf("\tpkts: %llu,\tbytes: %llu\n", 1311.1Sthorpej (ull)sp->xmit_cnt.packets, 1321.1Sthorpej (ull)sp->xmit_cnt.bytes); 1331.1Sthorpej printf("\tovers: %u,\toveractions: %u\n", 1341.1Sthorpej sp->over, sp->overactions); 1351.1Sthorpej printf("\tborrows: %u,\tdelays: %u\n", 1361.1Sthorpej sp->borrows, sp->delays); 1371.1Sthorpej printf("\tdrops: %llu,\tdrop_bytes: %llu\n", 1381.5Sitojun (ull)sp->drop_cnt.packets, 1391.1Sthorpej (ull)sp->drop_cnt.bytes); 1401.1Sthorpej if (sp->qtype == Q_RED) 1411.1Sthorpej print_redstats(sp->red); 1421.1Sthorpej else if (sp->qtype == Q_RIO) 1431.1Sthorpej print_riostats(sp->red); 1441.1Sthorpej 1451.1Sthorpej printf("\tQCount: %d,\t(qmax: %d)\n", 1461.1Sthorpej sp->qcnt, sp->qmax); 1471.1Sthorpej printf("\tAvgIdle: %d [us],\t(maxidle: %d minidle: %d [us])\n", 1481.1Sthorpej sp->avgidle >> RM_FILTER_GAIN, 1491.1Sthorpej sp->maxidle >> RM_FILTER_GAIN, 1501.1Sthorpej sp->minidle / RM_POWER); 1511.1Sthorpej } 1521.1Sthorpej 1531.1Sthorpej /* swap the buffer pointers */ 1541.1Sthorpej tmp = last; 1551.1Sthorpej last = new; 1561.1Sthorpej new = tmp; 1571.1Sthorpej 1581.1Sthorpej last_time = cur_time; 1591.1Sthorpej sleep(interval); 1601.1Sthorpej } 1611.1Sthorpej} 162