1*ba31dc0cSpeter /* $NetBSD: qdisc_blue.c,v 1.4 2006/10/28 11:43:02 peter Exp $ */
28b8734d2Sitojun /* $KAME: qdisc_blue.c,v 1.3 2001/08/15 12:51:58 kjc Exp $ */
38726857eSthorpej /*
48726857eSthorpej * Copyright (C) 1999-2000
58726857eSthorpej * Sony Computer Science Laboratories, Inc. All rights reserved.
68726857eSthorpej *
78726857eSthorpej * Redistribution and use in source and binary forms, with or without
88726857eSthorpej * modification, are permitted provided that the following conditions
98726857eSthorpej * are met:
108726857eSthorpej * 1. Redistributions of source code must retain the above copyright
118726857eSthorpej * notice, this list of conditions and the following disclaimer.
128726857eSthorpej * 2. Redistributions in binary form must reproduce the above copyright
138726857eSthorpej * notice, this list of conditions and the following disclaimer in the
148726857eSthorpej * documentation and/or other materials provided with the distribution.
158726857eSthorpej *
168726857eSthorpej * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
178726857eSthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
188726857eSthorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
198726857eSthorpej * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
208726857eSthorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
218726857eSthorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
228726857eSthorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
238726857eSthorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
248726857eSthorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
258726857eSthorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
268726857eSthorpej * SUCH DAMAGE.
278726857eSthorpej */
288726857eSthorpej
298726857eSthorpej #include <sys/param.h>
308726857eSthorpej #include <sys/ioctl.h>
318726857eSthorpej #include <sys/time.h>
328726857eSthorpej #include <sys/socket.h>
338726857eSthorpej #include <net/if.h>
348726857eSthorpej #include <netinet/in.h>
358726857eSthorpej #include <altq/altq.h>
368726857eSthorpej #include <altq/altq_blue.h>
378726857eSthorpej
388726857eSthorpej #include <stdio.h>
398726857eSthorpej #include <stdlib.h>
408726857eSthorpej #include <unistd.h>
418726857eSthorpej #include <string.h>
428726857eSthorpej #include <math.h>
438726857eSthorpej #include <errno.h>
448726857eSthorpej #include <err.h>
458726857eSthorpej
468726857eSthorpej #include "altqstat.h"
478726857eSthorpej
488726857eSthorpej void
blue_stat_loop(int fd,const char * ifname,int count,int interval)498726857eSthorpej blue_stat_loop(int fd, const char *ifname, int count, int interval)
508726857eSthorpej {
518726857eSthorpej struct blue_stats blue_stats;
528726857eSthorpej struct timeval cur_time, last_time;
538726857eSthorpej u_int64_t last_bytes;
548726857eSthorpej double sec;
558726857eSthorpej int cnt = count;
568726857eSthorpej
578b8734d2Sitojun strlcpy(blue_stats.iface.blue_ifname, ifname,
588b8734d2Sitojun sizeof(blue_stats.iface.blue_ifname));
598726857eSthorpej
608726857eSthorpej gettimeofday(&last_time, NULL);
618726857eSthorpej last_time.tv_sec -= interval;
628726857eSthorpej last_bytes = 0;
638726857eSthorpej
64*ba31dc0cSpeter for (;;) {
658726857eSthorpej if (ioctl(fd, BLUE_GETSTATS, &blue_stats) < 0)
668726857eSthorpej err(1, "ioctl BLUE_GETSTATS");
678726857eSthorpej
688726857eSthorpej gettimeofday(&cur_time, NULL);
698726857eSthorpej sec = calc_interval(&cur_time, &last_time);
708726857eSthorpej
718726857eSthorpej printf(" q_len:%d , q_limit:%d, q_pmark: %d\n",
728726857eSthorpej blue_stats.q_len, blue_stats.q_limit,
738726857eSthorpej blue_stats.q_pmark);
748726857eSthorpej printf(" xmit: %llu pkts, drop: %llu pkts (forced: %llu, early: %llu)\n",
758726857eSthorpej (ull)blue_stats.xmit_packets,
768726857eSthorpej (ull)blue_stats.drop_packets,
778726857eSthorpej (ull)blue_stats.drop_forced,
788726857eSthorpej (ull)blue_stats.drop_unforced);
798726857eSthorpej if (blue_stats.marked_packets != 0)
808726857eSthorpej printf(" marked: %llu\n",
818726857eSthorpej (ull)blue_stats.marked_packets);
828726857eSthorpej printf(" throughput: %sbps\n",
838726857eSthorpej rate2str(calc_rate(blue_stats.xmit_bytes,
848726857eSthorpej last_bytes, sec)));
858726857eSthorpej
868726857eSthorpej last_bytes = blue_stats.xmit_bytes;
878726857eSthorpej last_time = cur_time;
88*ba31dc0cSpeter
89*ba31dc0cSpeter if (count != 0 && --cnt == 0)
90*ba31dc0cSpeter break;
91*ba31dc0cSpeter
928726857eSthorpej sleep(interval);
938726857eSthorpej }
948726857eSthorpej }
95