1 /* $NetBSD: qdisc_cdnr.c,v 1.5 2006/10/28 11:43:02 peter Exp $ */
2 /* $KAME: qdisc_cdnr.c,v 1.6 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_cdnr.h>
46 #include "quip_client.h"
50 #define MAX_PROB (128*1024)
52 static const char *element_names
[] = { "none", "top", "element", "tbmeter", "trtcm",
54 static const char *tbmprof_names
[] = { "in: ", "out: " };
55 static const char *tcmprof_names
[] = { "green: ", "yellow:", "red: " };
58 cdnr_stat_loop(int fd
, const char *ifname
, int count
, int interval
)
60 struct tce_stats stats1
[NELEMENTS
], stats2
[NELEMENTS
];
61 char cdnrnames
[NELEMENTS
][128];
62 struct cdnr_get_stats get_stats
;
63 struct tce_stats
*sp
, *lp
, *new, *last
, *tmp
;
64 struct timeval cur_time
, last_time
;
66 const char **profile_names
;
74 snprintf(_ifname
, sizeof(_ifname
), "_%s", ifname
);
76 strlcpy(get_stats
.iface
.cdnr_ifname
, ifname
,
77 sizeof(get_stats
.iface
.cdnr_ifname
));
81 for (i
= 0; i
< NELEMENTS
; i
++)
82 stats1
[i
].tce_handle
= stats2
[i
].tce_handle
= CDNR_NULL_HANDLE
;
86 get_stats
.nelements
= NELEMENTS
;
87 get_stats
.tce_stats
= new;
89 if (ioctl(fd
, CDNR_GETSTATS
, &get_stats
) < 0)
90 err(1, "ioctl CDNR_GETSTATS");
92 gettimeofday(&cur_time
, NULL
);
93 sec
= calc_interval(&cur_time
, &last_time
);
96 printf(" pass:%llu drop:%llu mark:%llu next:%llu return:%llu none:%llu\n",
97 (ull
)get_stats
.cnts
[TCACODE_PASS
].packets
,
98 (ull
)get_stats
.cnts
[TCACODE_DROP
].packets
,
99 (ull
)get_stats
.cnts
[TCACODE_MARK
].packets
,
100 (ull
)get_stats
.cnts
[TCACODE_NEXT
].packets
,
101 (ull
)get_stats
.cnts
[TCACODE_RETURN
].packets
,
102 (ull
)get_stats
.cnts
[TCACODE_NONE
].packets
);
104 for (i
= 0; i
< get_stats
.nelements
; i
++) {
108 if (sp
->tce_handle
!= lp
->tce_handle
) {
109 quip_chandle2name(_ifname
, sp
->tce_handle
,
110 cdnrnames
[i
], sizeof(cdnrnames
[0]));
113 switch (sp
->tce_type
) {
114 case TCETYPE_TBMETER
:
116 profile_names
= tbmprof_names
;
121 profile_names
= tcmprof_names
;
124 profile_names
= tbmprof_names
; /* silence cc */
131 printf("[%s: %s] handle:%#lx\n",
132 element_names
[sp
->tce_type
], cdnrnames
[i
],
134 for (j
= 0; j
< nprofile
; j
++) {
135 printf(" %s %10llu pkts %16llu bytes",
137 (ull
)sp
->tce_cnts
[j
].packets
,
138 (ull
)sp
->tce_cnts
[j
].bytes
);
139 if (lp
->tce_handle
!= CDNR_NULL_HANDLE
) {
142 sp
->tce_cnts
[j
].bytes
,
143 lp
->tce_cnts
[j
].bytes
, sec
)));
151 /* swap the buffer pointers */
156 last_time
= cur_time
;
158 if (count
!= 0 && --cnt
== 0)
161 /* wait for alarm signal */
162 if (sigprocmask(SIG_BLOCK
, NULL
, &omask
) == 0)