ns-allinone-2.35/ns-2.35/diffserv/dsPolicy.cc
void TBPolicy::applyMeter(policyTableEntry *policy, Packet *) {
  double now = Scheduler::instance().clock();
  double tokenBytes;

  tokenBytes = (double) policy->cir * (now - policy->arrivalTime);
  if (policy->cBucket + tokenBytes <= policy->cbs)
   policy->cBucket += tokenBytes;
  else
   policy->cBucket = policy->cbs;
  policy->arrivalTime = now;
}
// Begin of Token Bucket.
/*-----------------------------------------------------------------------------
void TBPolicy::applyMeter(policyTableEntry *policy, Packet *pkt)
Pre: policy's variables cBucket, cir, cbs, and arrivalTime hold valid values.
Post: Increments policy's Token Bucket state variable cBucket according to the
  elapsed time since the last packet arrival.  cBucket is filled at a rate equal  to CIR, capped at an upper bound of CBS.
  This method also sets arrivalTime equal to the current simulator time.
-----------------------------------------------------------------------------*/
Begin of Token Bucket.
void TBPolicy::applyMeter(policyTableEntry *policy, Packet *pkt)
Pre: policy's variables cBucket, cir, cbs, and arrivalTime hold valid values.
Post: Increments policy's Token Bucket state variable cBucket according to the
elapsed time since the last packet arrival.  cBucket is filled at a rate equal  to CIR, capped at an upper bound of CBS.
This method also sets arrivalTime equal to the current simulator time.
Begin of Token Bucket . void TBPolicy :: applyMeter ( policyTableEntry * policy Packet * pkt ) Pre : policy ' s variables cBucket cir cbs and arrivalTime hold valid values . Post : Increments policy ' s Token Bucket state variable cBucket according to the elapsed time since the last packet arrival . cBucket is filled at a rate equal to CIR capped at an upper bound of CBS . This method also sets arrivalTime equal to the current simulator time .
void TBPolicy::applyMeter(policyTableEntry *policy, Packet *) {
  double now = Scheduler::instance().clock();
  double tokenBytes;
  tokenBytes = (double) policy->cir * (now - policy->arrivalTime);
  if (policy->cBucket + tokenBytes <= policy->cbs)
   policy->cBucket += tokenBytes;
  else
   policy->cBucket = policy->cbs;
  policy->arrivalTime = now;
}
void TBPolicy :: applyMeter ( policyTableEntry * policy , Packet * ) { double now = Scheduler :: instance ( ) . clock ( ) ; double tokenBytes ; tokenBytes = ( double ) policy -> cir * ( now - policy -> arrivalTime ) ; if ( policy -> cBucket + tokenBytes <= policy -> cbs ) policy -> cBucket += tokenBytes ; else policy -> cBucket = policy -> cbs ; policy -> arrivalTime = now ; }
Begin of Token Bucket.
Begin of Token Bucket .