📄 dspolicy.cc.svn-base
字号:
policerTable[policerTableSize].downgrade1 = (int)strtod(argv[4], NULL); if (argc == 6) policerTable[policerTableSize].downgrade2 = (int)strtod(argv[5], NULL); policerTableSize++;}// Return the entry of Policer table with policerType and initCodePoint matchedpolicerTableEntry* PolicyClassifier::getPolicerTableEntry(int policy_index, int oldCodePt) { for (int i = 0; i < policerTableSize; i++) if ((policerTable[i].policy_index == policy_index) && (policerTable[i].initialCodePt == oldCodePt)) return(&policerTable[i]); printf("ERROR: No Policer Table entry found for initial code point %d.\n", oldCodePt); //printPolicerTable(); return(NULL);}/*-----------------------------------------------------------------------------int mark(Packet *pkt)Pre: The source-destination pair taken from pkt matches a valid entry in policyTable.Post: pkt is marked with an appropriate code point.-----------------------------------------------------------------------------*/int PolicyClassifier::mark(Packet *pkt) { policyTableEntry *policy; policerTableEntry *policer; int policy_index; int codePt; hdr_ip* iph; int fid; iph = hdr_ip::access(pkt); fid = iph->flowid(); policy = getPolicyTableEntry(iph->prio()); codePt = policy->codePt; policy_index = policy->policy_index; policer = getPolicerTableEntry(policy_index, codePt); if (policy_pool[policy_index]) { policy_pool[policy_index]->applyMeter(policy, pkt); codePt = policy_pool[policy_index]->applyPolicer(policy, policer, pkt); } else { printf("The policy object doesn't exist, ERROR!!!\n"); exit(-1); } iph->prio_ = codePt; return(codePt);} // Prints the policyTable, one entry per line.void PolicyClassifier::printPolicyTable() { printf("Policy Table(%d):\n",policyTableSize); for (int i = 0; i < policyTableSize; i++) { switch (policyTable[i].policer) { case dumbPolicer: printf("Traffic marked with DSCP %2d : DUMB policer\n", policyTable[i].codePt); break; case TSW2CMPolicer: printf("Traffic marked with DSCP %2d : TSW2CM policer, ", policyTable[i].codePt); printf("CIR %.1f bps.\n", policyTable[i].cir * 8); break; case TSW3CMPolicer: printf("Traffic marked with DSCP %2d : TSW3CM policer, ", policyTable[i].codePt); printf("CIR %.1f bps, PIR %.1f bytes.\n", policyTable[i].cir * 8, policyTable[i].pir * 8); break; case tokenBucketPolicer: printf("Traffic marked with DSCP %2d : Token Bucket policer, ", policyTable[i].codePt); printf("CIR %.1f bps, CBS %.1f bytes.\n", policyTable[i].cir * 8, policyTable[i].cbs); break; case srTCMPolicer: printf("Traffic marked with DSCP %2d : srTCM policer,", policyTable[i].codePt); printf("CIR %.1f bps, CBS %.1f bytes, EBS %.1f bytes.\n", policyTable[i].cir * 8, policyTable[i].cbs, policyTable[i].ebs); break; case trTCMPolicer: printf("Traffic marked with DSCP %2d : trTCM policer, ", policyTable[i].codePt); printf("CIR %.1f bps, CBS %.1f bytes, PIR %.1f bps, ", policyTable[i].cir * 8, policyTable[i].cbs, policyTable[i].pir * 8); printf("PBS %.1f bytes.\n", policyTable[i].pbs); break; case FWPolicer: printf("Traffic marked with DSCP %2d : FW policer, ", policyTable[i].codePt); printf("TH %d bytes.\n",(int)policyTable[i].cir); break; default: printf("ERROR: Unknown policer type in Policy Table.\n"); } } printf("\n");}// Prints the policerTable, one entry per line.void PolicyClassifier::printPolicerTable() { bool threeColor, dumb; printf("Policer Table:\n"); for (int i = 0; i < policerTableSize; i++) { threeColor = false; dumb=false; switch (policerTable[i].policer) { case dumbPolicer: printf("Dumb "); dumb=true; break; case TSW2CMPolicer: printf("TSW2CM "); break; case TSW3CMPolicer: printf("TSW3CM "); threeColor = true; break; case tokenBucketPolicer: printf("Token Bucket "); break; case srTCMPolicer: printf("srTCM "); threeColor = true; break; case trTCMPolicer: printf("trTCM "); threeColor = true; break; case FWPolicer: printf("FW "); //printFlowTable(); break; default: printf("ERROR: Unknown policer type in Policer Table."); } if (dumb) printf("policer: DSCP %2d is not policed\n", policerTable[i].initialCodePt); else if (threeColor) { printf("policer: DSCP %2d is policed to yellow ", policerTable[i].initialCodePt); printf("DSCP %2d and red DSCP %2d.\n", policerTable[i].downgrade1, policerTable[i].downgrade2); } else printf("policer: DSCP %2d is policed to DSCP %2d.\n", policerTable[i].initialCodePt, policerTable[i].downgrade1); } printf("\n");}// The beginning of the definition of DumbPolicy// DumbPolicy will do nothing, but is a good example to show how to add // new policy./*-----------------------------------------------------------------------------void DumbPolicy::applyMeter(policyTableEntry *policy, Packet *pkt)Do nothing-----------------------------------------------------------------------------*/void DumbPolicy::applyMeter(policyTableEntry *policy, Packet *pkt) { policy->arrivalTime = Scheduler::instance().clock(); }/*-----------------------------------------------------------------------------int DumbPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, Packet *pkt)Always return the initial codepoint.-----------------------------------------------------------------------------*/int DumbPolicy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt) { return(policer->initialCodePt);}// The end of DumbPolicy// The beginning of the definition of TSW2CM/*-----------------------------------------------------------------------------void TSW2CMPolicy::applyMeter(policyTableEntry *policy, Packet *pkt)Pre: policy's variables avgRate, arrivalTime, and winLen hold valid values; and pkt points to a newly-arrived packet.Post: Adjusts policy's TSW state variables avgRate and arrivalTime (also called tFront) according to the specified packet.Note: See the paper "Explicit Allocation of Best effor Delivery Service" (David Clark and Wenjia Fang), Section 3.3, for a description of the TSW Tagger.-----------------------------------------------------------------------------*/void TSW2CMPolicy::applyMeter(policyTableEntry *policy, Packet *pkt) { double now, bytesInTSW, newBytes; hdr_cmn* hdr = hdr_cmn::access(pkt); bytesInTSW = policy->avgRate * policy->winLen; newBytes = bytesInTSW + (double) hdr->size(); now = Scheduler::instance().clock(); policy->avgRate = newBytes / (now - policy->arrivalTime + policy->winLen); policy->arrivalTime = now;}/*-----------------------------------------------------------------------------int TSW2CMPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, Packet *pkt)Pre: policy points to a policytableEntry that is using the TSW2CM policer and whose state variables (avgRate and cir) are up to date.Post: If policy's avgRate exceeds its CIR, this method returns an out-of-profile code point with a probability of ((rate - CIR) / rate). If it does not downgrade the code point, this method simply returns the initial code point.Returns: A code point to apply to the current packet.Uses: Method downgradeOne().-----------------------------------------------------------------------------*/int TSW2CMPolicy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt) { if ((policy->avgRate > policy->cir) && (Random::uniform(0.0, 1.0) <= (1-(policy->cir/policy->avgRate)))) { return(policer->downgrade1); } else { return(policer->initialCodePt); }}// The end of TSW2CM// The Beginning of TSW3CM/*-----------------------------------------------------------------------------void TSW3CMPolicy::applyMeter(policyTableEntry *policy, Packet *pkt)Pre: policy's variables avgRate, arrivalTime, and winLen hold valid values; and pkt points to a newly-arrived packet.Post: Adjusts policy's TSW state variables avgRate and arrivalTime (also called tFront) according to the specified packet.Note: See the paper "Explicit Allocation of Best effor Delivery Service" (David Clark and Wenjia Fang), Section 3.3, for a description of the TSW Tagger.-----------------------------------------------------------------------------*/void TSW3CMPolicy::applyMeter(policyTableEntry *policy, Packet *pkt) { double now, bytesInTSW, newBytes; hdr_cmn* hdr = hdr_cmn::access(pkt); bytesInTSW = policy->avgRate * policy->winLen; newBytes = bytesInTSW + (double) hdr->size(); now = Scheduler::instance().clock(); policy->avgRate = newBytes / (now - policy->arrivalTime + policy->winLen); policy->arrivalTime = now;}/*-----------------------------------------------------------------------------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 / rateand 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, policerTableEntry *policer, Packet *pkt) { 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);} // End of TSW3CM// 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 *pkt) { 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;}/*----------------------------------------------------------------------------int TBPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, Packet* pkt)Pre: policy points to a policytableEntry that is using the Token Bucket policerand whose state variable (cBucket) is up to date. pkt points to anewly-arrived packet.Post: If policy's cBucket is at least as large as pkt's size, cBucket isdecremented by that size and the initial code point is retained. Otherwise,the code point is downgraded.Returns: A code point to apply to the current packet.Uses: Method downgradeOne().
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -