ns-allinone-2.35/ns-2.35/diffserv/dsPolicy.cc
int TSW3CMPolicy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *) {
  double rand = policy->avgRate * (1.0 - Random::uniform(0.0, 1.0));
  
  if (rand > policy->pir)
    return (policer->downgrade2);
  else if (rand > policy->cir)
    return(policer->downgrade1);
  else
    return(policer->initialCodePt);
}
/*-----------------------------------------------------------------------------
int TSW3CMPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, Packet *pkt)
Pre: policy points to a policytableEntry that is using the TSW3CM policer and
  whose state variables (avgRate, cir, and pir) are up to date.
Post: Sets code points with the following probabilities when rate > PIR:

          red:    (rate - PIR) / rate
          yellow: (PIR - CIR) / rate
          green:  CIR / rate

and with the following code points when CIR < rate <= PIR:

          red:    0
          yellow: (rate - CIR) / rate
          green:  CIR / rate

    When rate is under CIR, a packet is always marked green.
Returns: A code point to apply to the current packet.
Uses: Methods downgradeOne() and downgradeTwo().
-----------------------------------------------------------------------------*/
int TSW3CMPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, Packet *pkt)
Pre: policy points to a policytableEntry that is using the TSW3CM policer and
whose state variables (avgRate, cir, and pir) are up to date.
Post: Sets code points with the following probabilities when rate > PIR.



and with the following code points when CIR < rate <= PIR.



When rate is under CIR, a packet is always marked green.
Returns: A code point to apply to the current packet.
Uses: Methods downgradeOne() and downgradeTwo().
int TSW3CMPolicy :: applyPolicer ( policyTableEntry * policy int initialCodePt Packet * pkt ) Pre : policy points to a policytableEntry that is using the TSW3CM policer and whose state variables ( avgRate cir and pir ) are up to date . Post : Sets code points with the following probabilities when rate > PIR . and with the following code points when CIR < rate < = PIR . When rate is under CIR a packet is always marked green . Returns : A code point to apply to the current packet . Uses : Methods downgradeOne () and downgradeTwo () .
int TSW3CMPolicy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *) {
  double rand = policy->avgRate * (1.0 - Random::uniform(0.0, 1.0));
  if (rand > policy->pir)
    return (policer->downgrade2);
  else if (rand > policy->cir)
    return(policer->downgrade1);
  else
    return(policer->initialCodePt);
}
int TSW3CMPolicy :: applyPolicer ( policyTableEntry * policy , policerTableEntry * policer , Packet * ) { double rand = policy -> avgRate * ( 1.0 - Random :: uniform ( 0.0 , 1.0 ) ) ; if ( rand > policy -> pir ) return ( policer -> downgrade2 ) ; else if ( rand > policy -> cir ) return ( policer -> downgrade1 ) ; else return ( policer -> initialCodePt ) ; }
int TSW3CMPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, Packet *pkt)
Pre: policy points to a policytableEntry that is using the TSW3CM policer and
whose state variables (avgRate, cir, and pir) are up to date.
int TSW3CMPolicy :: applyPolicer ( policyTableEntry * policy int initialCodePt Packet * pkt ) Pre : policy points to a policytableEntry that is using the TSW3CM policer and whose state variables ( avgRate cir and pir ) are up to date .