tokenmt.c revision 1a5e258f5471356ca102c7176637cdce45bac147
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/sysmacros.h>
#include <netinet/in_systm.h>
/*
* Module : Single or Two Rate Metering module - tokenmt
* Description
* This module implements the metering part of RFC 2698 & 2697. It accepts the
* committed rate, peak rate (optional), committed burst and peak burst for a
* flow and determines if the flow is within the cfgd. rates and assigns
* next action appropriately..
* If the peak rate is provided this acts as a two rate meter (RFC 2698), else
* a single rate meter (RFC 2697). If this is a two rate meter, then
* the outcome is either green, red or yellow. Else if this a single rate
* meter and the peak burst size is not provided, the outcome is either
* green or red.
* Internally, it maintains 2 token buckets, Tc & Tp, each filled with
* tokens equal to committed burst & peak burst respectively initially.
* When a packet arrives, tokens in Tc or Tp are updated at the committed
* or the peak rate up to a maximum of the committed or peak burst size.
* If there are enough tokens in Tc, the packet is Green, else if there are
* enough tokens in Tp, the packet is Yellow, else the packet is Red. In case
*/
int tokenmt_debug = 0;
/* Updating tokens */
/*
* Given a packet and the tokenmt_data it belongs to, this routine meters the
* ToS or DSCP for IPv4 and IPv6 resp. with the values configured for
* the tokenmt_data.
*/
int
{
enum meter_colour colour;
tokenmt0dbg(("tokenmt_process: null mp!\n"));
return (EINVAL);
}
} else {
tokenmt0dbg(("tokenmt_process: no data\n"));
return (EINVAL);
}
}
tokenmt0dbg(("tokenmt_process: pullup error\n"));
return (EINVAL);
}
}
/* discard last 2 unused bits */
} else {
/* discard ECN bits */
}
/* Convert into bits */
pkt_len <<= 3;
/* Update the token counts */
/*
* Figure out the drop preced. for the pkt. Need to be careful here
* because if the mode is set to COLOUR_AWARE, then the dscp value
* is used regardless of whether it was explicitly set or not.
* If the value is defaulted to 000 (drop precd.) then the pkt
* will always be coloured RED.
*/
if (!cfg_parms->colour_aware) {
/*
* Can't do this if yellow_action is not
* configured.
*/
} else {
}
} else {
if ((colour == TOKENMT_GREEN) &&
} else if (((colour == TOKENMT_GREEN) ||
(colour == TOKENMT_YELLOW)) &&
/*
* Can't do this if yellow_action is not
* configured.
*/
} else {
}
}
} else {
if (!cfg_parms->colour_aware) {
/*
* Can't do this if yellow_action is not
* configured.
*/
} else {
}
} else {
if ((colour == TOKENMT_RED) ||
} else if ((colour == TOKENMT_YELLOW) ||
/*
* Can't do this if yellow_action is not
* configured.
*/
} else {
}
}
}
/* Update Stats */
} else {
}
return (0);
}
void
{
switch (cfg_parms->tokenmt_type) {
case SRTCL_TOKENMT:
/*
* Add tokens at the committed rate to
* committed_tokens. If they are in excess of
* the committed burst, add the excess to
* peak_tokens, capped to peak_burst.
*/
+ tokens -
tokens);
} else {
}
break;
case TRTCL_TOKENMT:
/* Fill at the committed rate */
/* Fill at the peak rate */
break;
}
}