ns-allinone-2.35/ns-2.35/diffserv/dsPolicy.cc
int TRTCMPolicy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet* pkt) {
  hdr_cmn* hdr = hdr_cmn::access(pkt);
  double size = (double) hdr->size();
  
  if ((policy->pBucket - size) < 0)
    return(policer->downgrade2);
  else {
    if ((policy->cBucket - size) < 0) {
      policy->pBucket -= size;
      return(policer->downgrade1);
    } else {
      policy->cBucket -= size;
      policy->pBucket -= size;
      return(policer->initialCodePt);
    }
  }
}
/*----------------------------------------------------------------------------
int TRTCMPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, Packet* pkt)
Pre: policy points to a policyTableEntry that is using the trTCM policer and
  whose state variables (cBucket and pBucket) are up to date.  pkt points to a
  newly-arrived packet.
Post: If policy's pBucket is smaller than pkt's size, the red code point is
  retained.  Otherwise, if cBucket is smaller than the packet size, the yellow
  code point is returned and pBucket is decremented.  Otherwise, the packet
  remains green and both buckets are decremented.
Returns: A code point to apply to the current packet.
Uses: Method downgradeOne() and downgradeTwo().
Note: See the Internet Draft, "A Two Rate Three Color Marker" (Heinanen et al;
  May, 1999) for a description of the srTCM.
-----------------------------------------------------------------------------*/
int TRTCMPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, Packet* pkt)
Pre: policy points to a policyTableEntry that is using the trTCM policer and
whose state variables (cBucket and pBucket) are up to date.  pkt points to a
newly-arrived packet.
Post: If policy's pBucket is smaller than pkt's size, the red code point is
retained.  Otherwise, if cBucket is smaller than the packet size, the yellow
code point is returned and pBucket is decremented.  Otherwise, the packet
remains green and both buckets are decremented.
Returns: A code point to apply to the current packet.
Uses: Method downgradeOne() and downgradeTwo().
Note: See the Internet Draft, "A Two Rate Three Color Marker" (Heinanen et al;
May, 1999) for a description of the srTCM.
int TRTCMPolicy :: applyPolicer ( policyTableEntry * policy int initialCodePt Packet * pkt ) Pre : policy points to a policyTableEntry that is using the trTCM policer and whose state variables ( cBucket and pBucket ) are up to date . pkt points to a newly - arrived packet . Post : If policy ' s pBucket is smaller than pkt ' s size the red code point is retained . Otherwise if cBucket is smaller than the packet size the yellow code point is returned and pBucket is decremented . Otherwise the packet remains green and both buckets are decremented . Returns : A code point to apply to the current packet . Uses : Method downgradeOne () and downgradeTwo () . Note : See the Internet Draft " A Two Rate Three Color Marker " ( Heinanen et al ; May 1999 ) for a description of the srTCM .
int TRTCMPolicy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet* pkt) {
  hdr_cmn* hdr = hdr_cmn::access(pkt);
  double size = (double) hdr->size();
  if ((policy->pBucket - size) < 0)
    return(policer->downgrade2);
  else {
    if ((policy->cBucket - size) < 0) {
      policy->pBucket -= size;
      return(policer->downgrade1);
    } else {
      policy->cBucket -= size;
      policy->pBucket -= size;
      return(policer->initialCodePt);
    }
  }
}
int TRTCMPolicy :: applyPolicer ( policyTableEntry * policy , policerTableEntry * policer , Packet * pkt ) { hdr_cmn * hdr = hdr_cmn :: access ( pkt ) ; double size = ( double ) hdr -> size ( ) ; if ( ( policy -> pBucket - size ) < 0 ) return ( policer -> downgrade2 ) ; else { if ( ( policy -> cBucket - size ) < 0 ) { policy -> pBucket -= size ; return ( policer -> downgrade1 ) ; } else { policy -> cBucket -= size ; policy -> pBucket -= size ; return ( policer -> initialCodePt ) ; } } }
int TRTCMPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, Packet* pkt)
Pre: policy points to a policyTableEntry that is using the trTCM policer and
whose state variables (cBucket and pBucket) are up to date.
int TRTCMPolicy :: applyPolicer ( policyTableEntry * policy int initialCodePt Packet * pkt ) Pre : policy points to a policyTableEntry that is using the trTCM policer and whose state variables ( cBucket and pBucket ) are up to date .