📄 dspolicy.cc.svn-base
字号:
---------------------------------------------------------------------------*/int TBPolicy::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{ return(policer->downgrade1); }}// End of Tocken Bucket.// Begining of SRTCM/*-----------------------------------------------------------------------------void SRTCMPolicy::applyMeter(policyTableEntry *policy)Pre: policy's variables cBucket, eBucket, cir, cbs, ebs, and arrivalTime hold valid values.Post: Increments policy's srTCM state variables cBucket and eBucket 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. When cBucket is full (equal to CBS), eBucket is filled at a rate equal to CIR, capped at an upper bound of EBS. This method also sets arrivalTime equal to the current simulator time.Note: See the Internet Draft, "A Single Rate Three Color Marker" (Heinanen et al; May, 1999) for a description of the srTCM.-----------------------------------------------------------------------------*/void SRTCMPolicy::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 { tokenBytes = tokenBytes - (policy->cbs - policy->cBucket); policy->cBucket = policy->cbs; if (policy->eBucket + tokenBytes <= policy->ebs) policy->eBucket += tokenBytes; else policy->eBucket = policy->ebs; } policy->arrivalTime = now;}/*-----------------------------------------------------------------------------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); }}// End of SRTCM// Beginning of TRTCM/*----------------------------------------------------------------------------void TRTCMPolicy::applyMeter(policyTableEntry *policy, Packet *pkt)Pre: policy's variables cBucket, pBucket, cir, pir, cbs, pbs, and arrivalTime hold valid values.Post: Increments policy's trTCM state variables cBucket and pBucket 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. pBucket is filled at a rate equal to PIR, capped at an upper bound of PBS. This method also sets arrivalTime equal to the current simulator time.Note: See the Internet Draft, "A Two Rate Three Color Marker" (Heinanen et al; May, 1999) for a description of the srTCM.---------------------------------------------------------------------------*/void TRTCMPolicy::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; tokenBytes = (double) policy->pir * (now - policy->arrivalTime); if (policy->pBucket + tokenBytes <= policy->pbs) policy->pBucket += tokenBytes; else policy->pBucket = policy->pbs; policy->arrivalTime = now;}/*----------------------------------------------------------------------------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); } }}// End of TRTCM// Beginning of FW//Constructor.FWPolicy::FWPolicy() : Policy() { flow_table.head = NULL; flow_table.tail = NULL;}//Deconstructor.FWPolicy::~FWPolicy(){ struct flow_entry *p, *q; p = q = flow_table.head; while (p) { printf("free flow: %d\n", p->fid); q = p; p = p->next; free(q); } p = q = NULL; flow_table.head = flow_table.tail = NULL;}/*----------------------------------------------------------------------------- void FWPolicy::applyMeter(policyTableEntry *policy, Packet *pkt) Flow states are kept in a linked list. Record how many bytes has been sent per flow and check if there is any flow timeout.-----------------------------------------------------------------------------*/void FWPolicy::applyMeter(policyTableEntry *policy, Packet *pkt) { int fid; struct flow_entry *p, *q, *new_entry; double now = Scheduler::instance().clock(); hdr_cmn* hdr = hdr_cmn::access(pkt); hdr_ip* iph = hdr_ip::access(pkt); fid = iph->flowid(); // printf("enter applyMeter\n"); p = q = flow_table.head; while (p) { // Check if the flow has been recorded before. if (p->fid == fid) { p->last_update = now; p->bytes_sent += hdr->size(); return; } else if (p->last_update + FLOW_TIME_OUT < now){ // The coresponding flow is dead. if (p == flow_table.head){ if (p == flow_table.tail) { flow_table.head = flow_table.tail = NULL; free(p); p = q = NULL; } else { flow_table.head = p->next; free(p); p = q = flow_table.head; } } else { q->next = p->next; if (p == flow_table.tail) flow_table.tail = q; free(p); p = q->next; } } else { q = p; p = q->next; } } // This is the firt time the flow shown up if (!p) { new_entry = new flow_entry; new_entry->fid = fid; new_entry->last_update = now; new_entry->bytes_sent = hdr->size(); new_entry->count = 0; new_entry->next = NULL; // always insert the new entry to the tail. if (flow_table.tail) flow_table.tail->next = new_entry; else flow_table.head = new_entry; flow_table.tail = new_entry; } // printf("leave applyMeter\n"); return;}/*-----------------------------------------------------------------------------void FWPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, Packet *pkt) Prints the policyTable, one entry per line.-----------------------------------------------------------------------------*/int FWPolicy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt) { struct flow_entry *p; hdr_ip* iph = hdr_ip::access(pkt); // printf("enter applyPolicer\n"); // printFlowTable(); p = flow_table.head; while (p) { // Check if the flow has been recorded before. if (p->fid == iph->flowid()) { if (p->bytes_sent > policy->cir) { // Use downgrade2 code to judge how to penalize out-profile packets. if (policer->downgrade2 == 0) { // Penalize every packet beyond th. //printf("leave applyPolicer %d, every downgrade\n", p->fid); return(policer->downgrade1); } else if (policer->downgrade2 == 1) { // Randomized penalization. if (Random::uniform(0.0, 1.0) > (1 - (policy->cir/p->bytes_sent))) { //printf("leave applyPolicer %d, random initial.\n", p->fid); return(policer->initialCodePt); } else { //printf("leave applyPolicer %d, random, downgrade\n", p->fid); return(policer->downgrade1); } } else { // Simple scheduling on penalization. if (p->count == 5) { // Penalize 4 out of every 5 packets. p->count = 0; //printf("leave applyPolicer %d, initial, %d\n", p->fid, p->count); return(policer->initialCodePt); } else { p->count++; //printf("leave applyPolicer %d, downgrade, %d\n", p->fid, p->count); return(policer->downgrade1); } } } else { // printf("leave applyPolicer, initial\n"); return(policer->initialCodePt); } } p = p->next; } // Can't find the record for this flow. if (!p) { printf ("MISS: no flow %d in the table\n", iph->flowid()); printFlowTable();}; // printf("leave applyPolicer, init but problem...\n"); return(policer->initialCodePt);}// Prints the flowTable, one entry per line.void FWPolicy::printFlowTable() { struct flow_entry *p; printf("Flow table:\n"); p = flow_table.head; while (p) { printf("flow id: %d, bytesSent: %d, last_update: %f\n", p->fid, p->bytes_sent, p->last_update); p = p-> next; } p = NULL; printf("\n");}// End of FW
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -