ns-allinone-2.35/ns-2.35/diffserv/dsPolicy.cc
int SRTCMPolicy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet* pkt) {

  hdr_cmn* hdr = hdr_cmn::access(pkt);
  double size = (double) hdr->size();
  
  if ((policy->cBucket - size) >= 0) {
    policy->cBucket -= size;
    return(policer->initialCodePt);
  } else {
    if ((policy->eBucket - size) >= 0) {
      policy->eBucket -= size;
      return(policer->downgrade1);
    } else
      return(policer->downgrade2);
  }
}
/*-----------------------------------------------------------------------------
int SRTCMPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, Packet* pkt)
Pre: policy points to a policyTableEntry that is using the srTCM policer and
  whose state variables (cBucket and eBucket) are up to date.  pkt points to a
  newly-arrived packet.
Post: If policy's cBucket is at least as large as pkt's size, cBucket is
  decremented by that size and the initial code point is retained.  Otherwise,
  if eBucket is at least as large as the packet, eBucket is decremented and the
  yellow code point is returned.  Otherwise, the red code point is returned.
Returns: A code point to apply to the current packet.
Uses: Method downgradeOne() and downgradeTwo().
Note: See the Internet Draft, "A Single Rate Three Color Marker" (Heinanen et
  al; May, 1999) for a description of the srTCM.
-----------------------------------------------------------------------------*/
int SRTCMPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, Packet* pkt)
Pre: policy points to a policyTableEntry that is using the srTCM policer and
whose state variables (cBucket and eBucket) are up to date.  pkt points to a
newly-arrived packet.
Post: If policy's cBucket is at least as large as pkt's size, cBucket is
decremented by that size and the initial code point is retained.  Otherwise,
if eBucket is at least as large as the packet, eBucket is decremented and the
yellow code point is returned.  Otherwise, the red code point is returned.
Returns: A code point to apply to the current packet.
Uses: Method downgradeOne() and downgradeTwo().
Note: See the Internet Draft, "A Single Rate Three Color Marker" (Heinanen et
al; May, 1999) for a description of the srTCM.
int SRTCMPolicy :: applyPolicer ( policyTableEntry * policy int initialCodePt Packet * pkt ) Pre : policy points to a policyTableEntry that is using the srTCM policer and whose state variables ( cBucket and eBucket ) are up to date . pkt points to a newly - arrived packet . Post : If policy ' s cBucket is at least as large as pkt ' s size cBucket is decremented by that size and the initial code point is retained . Otherwise if eBucket is at least as large as the packet eBucket is decremented and the yellow code point is returned . Otherwise the red code point is returned . Returns : A code point to apply to the current packet . Uses : Method downgradeOne () and downgradeTwo () . Note : See the Internet Draft " A Single Rate Three Color Marker " ( Heinanen et al ; May 1999 ) for a description of the srTCM .
int SRTCMPolicy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet* pkt) {
  hdr_cmn* hdr = hdr_cmn::access(pkt);
  double size = (double) hdr->size();
  if ((policy->cBucket - size) >= 0) {
    policy->cBucket -= size;
    return(policer->initialCodePt);
  } else {
    if ((policy->eBucket - size) >= 0) {
      policy->eBucket -= size;
      return(policer->downgrade1);
    } else
      return(policer->downgrade2);
  }
}
int SRTCMPolicy :: applyPolicer ( policyTableEntry * policy , policerTableEntry * policer , Packet * pkt ) { hdr_cmn * hdr = hdr_cmn :: access ( pkt ) ; double size = ( double ) hdr -> size ( ) ; if ( ( policy -> cBucket - size ) >= 0 ) { policy -> cBucket -= size ; return ( policer -> initialCodePt ) ; } else { if ( ( policy -> eBucket - size ) >= 0 ) { policy -> eBucket -= size ; return ( policer -> downgrade1 ) ; } else return ( policer -> downgrade2 ) ; } }
int SRTCMPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, Packet* pkt)
Pre: policy points to a policyTableEntry that is using the srTCM policer and
whose state variables (cBucket and eBucket) are up to date.
int SRTCMPolicy :: applyPolicer ( policyTableEntry * policy int initialCodePt Packet * pkt ) Pre : policy points to a policyTableEntry that is using the srTCM policer and whose state variables ( cBucket and eBucket ) are up to date .