1130365Smlaier/* $KAME: altq_cdnr.h,v 1.9 2003/07/10 12:07:48 kjc Exp $ */ 2130365Smlaier 3130365Smlaier/* 4130365Smlaier * Copyright (C) 1999-2002 5130365Smlaier * Sony Computer Science Laboratories Inc. All rights reserved. 6130365Smlaier * 7130365Smlaier * Redistribution and use in source and binary forms, with or without 8130365Smlaier * modification, are permitted provided that the following conditions 9130365Smlaier * are met: 10130365Smlaier * 1. Redistributions of source code must retain the above copyright 11130365Smlaier * notice, this list of conditions and the following disclaimer. 12130365Smlaier * 2. Redistributions in binary form must reproduce the above copyright 13130365Smlaier * notice, this list of conditions and the following disclaimer in the 14130365Smlaier * documentation and/or other materials provided with the distribution. 15130365Smlaier * 16130365Smlaier * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND 17130365Smlaier * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18130365Smlaier * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19130365Smlaier * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE 20130365Smlaier * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21130365Smlaier * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22130365Smlaier * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23130365Smlaier * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24130365Smlaier * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25130365Smlaier * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26130365Smlaier * SUCH DAMAGE. 27130365Smlaier */ 28130365Smlaier 29130365Smlaier#ifndef _ALTQ_ALTQ_CDNR_H_ 30130365Smlaier#define _ALTQ_ALTQ_CDNR_H_ 31130365Smlaier 32130365Smlaier#include <altq/altq.h> 33130365Smlaier 34130365Smlaier/* 35130365Smlaier * traffic conditioner element types 36130365Smlaier */ 37130365Smlaier#define TCETYPE_NONE 0 38130365Smlaier#define TCETYPE_TOP 1 /* top level conditioner */ 39130365Smlaier#define TCETYPE_ELEMENT 2 /* a simple tc element */ 40130365Smlaier#define TCETYPE_TBMETER 3 /* token bucket meter */ 41130365Smlaier#define TCETYPE_TRTCM 4 /* (two-rate) three color marker */ 42130365Smlaier#define TCETYPE_TSWTCM 5 /* time sliding window 3-color maker */ 43130365Smlaier 44130365Smlaier/* 45130365Smlaier * traffic conditioner action 46130365Smlaier */ 47130365Smlaierstruct cdnr_block; 48130365Smlaier 49130365Smlaierstruct tc_action { 50130365Smlaier int tca_code; /* e.g., TCACODE_PASS */ 51130365Smlaier /* tca_code dependent variable */ 52130365Smlaier union { 53130365Smlaier u_long un_value; /* template */ 54130365Smlaier u_int8_t un_dscp; /* diffserv code point */ 55130365Smlaier u_long un_handle; /* tc action handle */ 56130365Smlaier struct cdnr_block *un_next; /* next tc element block */ 57130365Smlaier } tca_un; 58130365Smlaier}; 59130365Smlaier#define tca_value tca_un.un_value 60130365Smlaier#define tca_dscp tca_un.un_dscp 61130365Smlaier#define tca_handle tca_un.un_handle 62130365Smlaier#define tca_next tca_un.un_next 63130365Smlaier 64130365Smlaier#define TCACODE_NONE 0 /* action is not set */ 65130365Smlaier#define TCACODE_PASS 1 /* pass this packet */ 66130365Smlaier#define TCACODE_DROP 2 /* discard this packet */ 67130365Smlaier#define TCACODE_RETURN 3 /* do not process this packet */ 68130365Smlaier#define TCACODE_MARK 4 /* mark dscp */ 69130365Smlaier#define TCACODE_HANDLE 5 /* take action specified by handle */ 70130365Smlaier#define TCACODE_NEXT 6 /* take action in the next tc element */ 71130365Smlaier#define TCACODE_MAX 6 72130365Smlaier 73130365Smlaier#define CDNR_NULL_HANDLE 0 74130365Smlaier 75130365Smlaierstruct cdnr_interface { 76130365Smlaier char cdnr_ifname[IFNAMSIZ]; /* interface name (e.g., fxp0) */ 77130365Smlaier}; 78130365Smlaier 79130365Smlaier/* simple element operations */ 80130365Smlaierstruct cdnr_add_element { 81130365Smlaier struct cdnr_interface iface; 82130365Smlaier struct tc_action action; 83130365Smlaier 84130365Smlaier u_long cdnr_handle; /* return value */ 85130365Smlaier}; 86130365Smlaier 87130365Smlaierstruct cdnr_delete_element { 88130365Smlaier struct cdnr_interface iface; 89130365Smlaier u_long cdnr_handle; 90130365Smlaier}; 91130365Smlaier 92130365Smlaier/* token-bucket meter operations */ 93130365Smlaierstruct cdnr_add_tbmeter { 94130365Smlaier struct cdnr_interface iface; 95130365Smlaier struct tb_profile profile; 96130365Smlaier struct tc_action in_action; 97130365Smlaier struct tc_action out_action; 98130365Smlaier 99130365Smlaier u_long cdnr_handle; /* return value */ 100130365Smlaier}; 101130365Smlaier 102130365Smlaierstruct cdnr_modify_tbmeter { 103130365Smlaier struct cdnr_interface iface; 104130365Smlaier u_long cdnr_handle; 105130365Smlaier struct tb_profile profile; 106130365Smlaier}; 107130365Smlaier 108130365Smlaierstruct cdnr_tbmeter_stats { 109130365Smlaier struct cdnr_interface iface; 110130365Smlaier u_long cdnr_handle; 111130365Smlaier struct pktcntr in_cnt; 112130365Smlaier struct pktcntr out_cnt; 113130365Smlaier}; 114130365Smlaier 115130365Smlaier/* two-rate three-color marker operations */ 116130365Smlaierstruct cdnr_add_trtcm { 117130365Smlaier struct cdnr_interface iface; 118130365Smlaier struct tb_profile cmtd_profile; /* profile for committed tb */ 119130365Smlaier struct tb_profile peak_profile; /* profile for peak tb */ 120130365Smlaier struct tc_action green_action; /* action for green packets */ 121130365Smlaier struct tc_action yellow_action; /* action for yellow packets */ 122130365Smlaier struct tc_action red_action; /* action for red packets */ 123130365Smlaier int coloraware; /* color-aware/color-blind */ 124130365Smlaier 125130365Smlaier u_long cdnr_handle; /* return value */ 126130365Smlaier}; 127130365Smlaier 128130365Smlaierstruct cdnr_modify_trtcm { 129130365Smlaier struct cdnr_interface iface; 130130365Smlaier u_long cdnr_handle; 131130365Smlaier struct tb_profile cmtd_profile; /* profile for committed tb */ 132130365Smlaier struct tb_profile peak_profile; /* profile for peak tb */ 133130365Smlaier int coloraware; /* color-aware/color-blind */ 134130365Smlaier}; 135130365Smlaier 136130365Smlaierstruct cdnr_tcm_stats { 137130365Smlaier struct cdnr_interface iface; 138130365Smlaier u_long cdnr_handle; 139130365Smlaier struct pktcntr green_cnt; 140130365Smlaier struct pktcntr yellow_cnt; 141130365Smlaier struct pktcntr red_cnt; 142130365Smlaier}; 143130365Smlaier 144130365Smlaier/* time sliding window three-color marker operations */ 145130365Smlaierstruct cdnr_add_tswtcm { 146130365Smlaier struct cdnr_interface iface; 147130365Smlaier u_int32_t cmtd_rate; /* committed rate (bits/sec) */ 148130365Smlaier u_int32_t peak_rate; /* peak rate (bits/sec) */ 149130365Smlaier u_int32_t avg_interval; /* averaging interval (msec) */ 150130365Smlaier struct tc_action green_action; /* action for green packets */ 151130365Smlaier struct tc_action yellow_action; /* action for yellow packets */ 152130365Smlaier struct tc_action red_action; /* action for red packets */ 153130365Smlaier 154130365Smlaier u_long cdnr_handle; /* return value */ 155130365Smlaier}; 156130365Smlaier 157130365Smlaierstruct cdnr_modify_tswtcm { 158130365Smlaier struct cdnr_interface iface; 159130365Smlaier u_long cdnr_handle; 160130365Smlaier u_int32_t cmtd_rate; /* committed rate (bits/sec) */ 161130365Smlaier u_int32_t peak_rate; /* peak rate (bits/sec) */ 162130365Smlaier u_int32_t avg_interval; /* averaging interval (msec) */ 163130365Smlaier}; 164130365Smlaier 165130365Smlaierstruct cdnr_add_filter { 166130365Smlaier struct cdnr_interface iface; 167130365Smlaier u_long cdnr_handle; 168130365Smlaier#ifdef ALTQ3_CLFIER_COMPAT 169130365Smlaier struct flow_filter filter; 170130365Smlaier#endif 171130365Smlaier u_long filter_handle; /* return value */ 172130365Smlaier}; 173130365Smlaier 174130365Smlaierstruct cdnr_delete_filter { 175130365Smlaier struct cdnr_interface iface; 176130365Smlaier u_long filter_handle; 177130365Smlaier}; 178130365Smlaier 179130365Smlaierstruct tce_stats { 180130365Smlaier u_long tce_handle; /* tc element handle */ 181130365Smlaier int tce_type; /* e.g., TCETYPE_ELEMENT */ 182130365Smlaier struct pktcntr tce_cnts[3]; /* tcm returns 3 counters */ 183130365Smlaier}; 184130365Smlaier 185130365Smlaierstruct cdnr_get_stats { 186130365Smlaier struct cdnr_interface iface; 187130365Smlaier struct pktcntr cnts[TCACODE_MAX+1]; 188130365Smlaier 189130365Smlaier /* element stats */ 190130365Smlaier int nskip; /* skip # of elements */ 191130365Smlaier int nelements; /* # of element stats (WR) */ 192130365Smlaier struct tce_stats *tce_stats; /* pointer to stats array */ 193130365Smlaier}; 194130365Smlaier 195130365Smlaier#define CDNR_IF_ATTACH _IOW('Q', 1, struct cdnr_interface) 196130365Smlaier#define CDNR_IF_DETACH _IOW('Q', 2, struct cdnr_interface) 197130365Smlaier#define CDNR_ENABLE _IOW('Q', 3, struct cdnr_interface) 198130365Smlaier#define CDNR_DISABLE _IOW('Q', 4, struct cdnr_interface) 199130365Smlaier#define CDNR_ADD_FILTER _IOWR('Q', 10, struct cdnr_add_filter) 200130365Smlaier#define CDNR_DEL_FILTER _IOW('Q', 11, struct cdnr_delete_filter) 201130365Smlaier#define CDNR_GETSTATS _IOWR('Q', 12, struct cdnr_get_stats) 202130365Smlaier#define CDNR_ADD_ELEM _IOWR('Q', 30, struct cdnr_add_element) 203130365Smlaier#define CDNR_DEL_ELEM _IOW('Q', 31, struct cdnr_delete_element) 204130365Smlaier#define CDNR_ADD_TBM _IOWR('Q', 32, struct cdnr_add_tbmeter) 205130365Smlaier#define CDNR_MOD_TBM _IOW('Q', 33, struct cdnr_modify_tbmeter) 206130365Smlaier#define CDNR_TBM_STATS _IOWR('Q', 34, struct cdnr_tbmeter_stats) 207130365Smlaier#define CDNR_ADD_TCM _IOWR('Q', 35, struct cdnr_add_trtcm) 208130365Smlaier#define CDNR_MOD_TCM _IOWR('Q', 36, struct cdnr_modify_trtcm) 209130365Smlaier#define CDNR_TCM_STATS _IOWR('Q', 37, struct cdnr_tcm_stats) 210130365Smlaier#define CDNR_ADD_TSW _IOWR('Q', 38, struct cdnr_add_tswtcm) 211130365Smlaier#define CDNR_MOD_TSW _IOWR('Q', 39, struct cdnr_modify_tswtcm) 212130365Smlaier 213130365Smlaier#ifndef DSCP_EF 214130365Smlaier/* diffserve code points */ 215130365Smlaier#define DSCP_MASK 0xfc 216130365Smlaier#define DSCP_CUMASK 0x03 217130365Smlaier#define DSCP_EF 0xb8 218130365Smlaier#define DSCP_AF11 0x28 219130365Smlaier#define DSCP_AF12 0x30 220130365Smlaier#define DSCP_AF13 0x38 221130365Smlaier#define DSCP_AF21 0x48 222130365Smlaier#define DSCP_AF22 0x50 223130365Smlaier#define DSCP_AF23 0x58 224130365Smlaier#define DSCP_AF31 0x68 225130365Smlaier#define DSCP_AF32 0x70 226130365Smlaier#define DSCP_AF33 0x78 227130365Smlaier#define DSCP_AF41 0x88 228130365Smlaier#define DSCP_AF42 0x90 229130365Smlaier#define DSCP_AF43 0x98 230130365Smlaier#define AF_CLASSMASK 0xe0 231130365Smlaier#define AF_DROPPRECMASK 0x18 232130365Smlaier#endif 233130365Smlaier 234130365Smlaier#ifdef _KERNEL 235130365Smlaier 236130365Smlaier/* 237130365Smlaier * packet information passed to the input function of tc elements 238130365Smlaier */ 239130365Smlaierstruct cdnr_pktinfo { 240130365Smlaier int pkt_len; /* packet length */ 241130365Smlaier u_int8_t pkt_dscp; /* diffserv code point */ 242130365Smlaier}; 243130365Smlaier 244130365Smlaier/* 245130365Smlaier * traffic conditioner control block common to all types of tc elements 246130365Smlaier */ 247130365Smlaierstruct cdnr_block { 248130365Smlaier LIST_ENTRY(cdnr_block) cb_next; 249130365Smlaier int cb_len; /* size of this tc element */ 250130365Smlaier int cb_type; /* cdnr block type */ 251130365Smlaier int cb_ref; /* reference count of this element */ 252130365Smlaier u_long cb_handle; /* handle of this tc element */ 253130365Smlaier struct top_cdnr *cb_top; /* back pointer to top */ 254130365Smlaier struct tc_action cb_action; /* top level action for this tcb */ 255130365Smlaier struct tc_action *(*cb_input)(struct cdnr_block *, 256130365Smlaier struct cdnr_pktinfo *); 257130365Smlaier}; 258130365Smlaier 259130365Smlaier/* 260130365Smlaier * top level traffic conditioner structure for an interface 261130365Smlaier */ 262130365Smlaierstruct top_cdnr { 263130365Smlaier struct cdnr_block tc_block; 264130365Smlaier 265130365Smlaier LIST_ENTRY(top_cdnr) tc_next; 266130365Smlaier struct ifaltq *tc_ifq; 267130365Smlaier 268130365Smlaier LIST_HEAD(, cdnr_block) tc_elements; 269130365Smlaier#ifdef ALTQ3_CLFIER_COMPAT 270130365Smlaier struct acc_classifier tc_classifier; 271130365Smlaier#endif 272130365Smlaier struct pktcntr tc_cnts[TCACODE_MAX+1]; 273130365Smlaier}; 274130365Smlaier 275130365Smlaier/* token bucket element */ 276130365Smlaierstruct tbe { 277130365Smlaier u_int64_t rate; 278130365Smlaier u_int64_t depth; 279130365Smlaier 280130365Smlaier u_int64_t token; 281130365Smlaier u_int64_t filluptime; 282130365Smlaier u_int64_t last; 283130365Smlaier}; 284130365Smlaier 285130365Smlaier/* token bucket meter structure */ 286130365Smlaierstruct tbmeter { 287130365Smlaier struct cdnr_block cdnrblk; /* conditioner block */ 288130365Smlaier struct tbe tb; /* token bucket */ 289130365Smlaier struct tc_action in_action; /* actions for IN/OUT */ 290130365Smlaier struct tc_action out_action; /* actions for IN/OUT */ 291130365Smlaier struct pktcntr in_cnt; /* statistics for IN/OUT */ 292130365Smlaier struct pktcntr out_cnt; /* statistics for IN/OUT */ 293130365Smlaier}; 294130365Smlaier 295130365Smlaier/* two-rate three-color marker structure */ 296130365Smlaierstruct trtcm { 297130365Smlaier struct cdnr_block cdnrblk; /* conditioner block */ 298130365Smlaier struct tbe cmtd_tb; /* committed tb profile */ 299130365Smlaier struct tbe peak_tb; /* peak tb profile */ 300130365Smlaier struct tc_action green_action; 301130365Smlaier struct tc_action yellow_action; 302130365Smlaier struct tc_action red_action; 303130365Smlaier int coloraware; 304130365Smlaier u_int8_t green_dscp; 305130365Smlaier u_int8_t yellow_dscp; 306130365Smlaier u_int8_t red_dscp; 307130365Smlaier struct pktcntr green_cnt; 308130365Smlaier struct pktcntr yellow_cnt; 309130365Smlaier struct pktcntr red_cnt; 310130365Smlaier}; 311130365Smlaier 312130365Smlaier/* time sliding window three-color marker structure */ 313130365Smlaierstruct tswtcm { 314130365Smlaier struct cdnr_block cdnrblk; /* conditioner block */ 315130365Smlaier 316130365Smlaier u_int32_t avg_rate; /* average rate (bytes/sec) */ 317130365Smlaier u_int64_t t_front; /* timestamp of last update */ 318130365Smlaier 319130365Smlaier u_int64_t timewin; /* average interval */ 320130365Smlaier u_int32_t cmtd_rate; /* committed target rate */ 321130365Smlaier u_int32_t peak_rate; /* peak target rate */ 322130365Smlaier struct tc_action green_action; 323130365Smlaier struct tc_action yellow_action; 324130365Smlaier struct tc_action red_action; 325130365Smlaier u_int8_t green_dscp; 326130365Smlaier u_int8_t yellow_dscp; 327130365Smlaier u_int8_t red_dscp; 328130365Smlaier struct pktcntr green_cnt; 329130365Smlaier struct pktcntr yellow_cnt; 330130365Smlaier struct pktcntr red_cnt; 331130365Smlaier}; 332130365Smlaier 333130365Smlaier#endif /* _KERNEL */ 334130365Smlaier 335130365Smlaier#endif /* _ALTQ_ALTQ_CDNR_H_ */ 336