# # 04/02/2004 # DiffServ Policies patch for ns2.1b9a (gcc3.2) # by Vincenzo Falletta, Giovanni Neglia @ TTI lab - Palermo # {vincenzo.falletta,giovanni.neglia}@tti.unipa.it # # This patch updates the network simulator ns2.1b9a (gcc3.2) introducing a new # DiffServ policy (WBE2) which implements the last version of our Packet Marking Algorithm # (see "An Analytical Model of a new Packet Marking Algorithm for TCP flows: # preliminary insights", Neglia, G., Bianchi, G., Falletta, V. - ISCCSP 2004, # 21-24 March 2004, Hammamet, Tunisia - for details about how it works), but it also defines previous # experimental policies such as PS, WBE, WBE3, MELLIA, MERGE. # To apply the patch, uncompress the archive ns-allinone-2.1b9a-gcc32.tar.gz with the command # # tar -xvzf ns-allinone-2.1b9a-gcc32.tar.gz # # obtaining the directory 'ns-allinone-2.1b9a'; now from the point where this # folder has been created simply type # # $patch -b -z .original -p0 < DiffServ_patch.txt # # # This patch modifies the following files: # ns-allinone-2.1b9a/ns-2.1b9a/diffserv/dsPolicy.cc # ns-allinone-2.1b9a/ns-2.1b9a/diffserv/dsPolicy.h # ns-allinone-2.1b9a/ns-2.1b9a/diffserv/dsred.cc # ns-allinone-2.1b9a/ns-2.1b9a/diffserv/dsred.h # ns-allinone-2.1b9a/ns-2.1b9a/diffserv/dsredq.cc # ns-allinone-2.1b9a/ns-2.1b9a/diffserv/dsredq.h # ns-allinone-2.1b9a/ns-2.1b9a/tcl/lib/ns-default.tcl # ns-allinone-2.1b9a/ns-2.1b9a/tcp/tcp.cc # ns-allinone-2.1b9a/ns-2.1b9a/tcp/tcp.h # ns-allinone-2.1b9a/ns-2.1b9a/tcp/tcp-sink.cc # ns-allinone-2.1b9a/ns-2.1b9a/tcp/tcp-sink.h # # That's all, enjoy ;-) # diff -Naurb ns-allinone-2.1b9a/ns-2.1b9a/diffserv/dsPolicy.cc ns-allinone-2.1b9a_modif/ns-2.1b9a/diffserv/dsPolicy.cc --- ns-allinone-2.1b9a/ns-2.1b9a/diffserv/dsPolicy.cc 2002-08-22 01:55:22.000000000 +0200 +++ ns-allinone-2.1b9a_modif/ns-2.1b9a/diffserv/dsPolicy.cc 2004-02-03 16:55:24.000000000 +0100 @@ -86,6 +86,12 @@ TokenBucket InitialCodePoint CIR CBS srTCM InitialCodePoint CIR CBS EBS trTCM InitialCodePoint CIR CBS PIR PBS +PS InitialCodePoint AVGSPACING //TTI_LAB +WBE InitialCodePoint //TTI_LAB +WBE2 InitialCodePoint //TTI_LAB +WBE3 InitialCodePoint //TTI_LAB +MELLIA InitialCodePoint //TTI_LAB +MERGE InitialCodePoint //TTI_LAB No error-checking is performed on the parameters. CIR and PIR should be specified in bits per second; CBS, EBS, and PBS should be specified in bytes. @@ -185,6 +191,70 @@ policyTable[policyTableSize].policy_index = EWP; policyTable[policyTableSize].policer = EWPolicer; policyTable[policyTableSize].meter = ewTagger; + /*TTI_LAB else-if sequence*/ + } else if (strcmp(argv[4], "PS") == 0) { + if(!policy_pool[PS]) + policy_pool[PS] = new PSPolicy; + policyTable[policyTableSize].policy_index = PS; + policyTable[policyTableSize].policer = PSPolicer; + policyTable[policyTableSize].meter = PSMeter; + + policyTable[policyTableSize].avgSpacing = + policyTable[policyTableSize].actSpacing = (double) atof(argv[6]); + } else if (strcmp(argv[4], "WBE") == 0) { + if(!policy_pool[WBE]) + policy_pool[WBE] = new WBEPolicy; + policyTable[policyTableSize].policy_index = WBE; + policyTable[policyTableSize].policer = WBEPolicer; + policyTable[policyTableSize].meter = WBEMeter; + + policyTable[policyTableSize].avgSpacing = 7; + policyTable[policyTableSize].actSpacing = 0; + policyTable[policyTableSize].seqno = -1; + } else if (strcmp(argv[4], "WBE2") == 0) { + if(!policy_pool[WBE2]) + policy_pool[WBE2] = new WBE2Policy; + policyTable[policyTableSize].policy_index = WBE2; + policyTable[policyTableSize].policer = WBE2Policer; + policyTable[policyTableSize].meter = WBE2Meter; + + policyTable[policyTableSize].avgSpacing = 7; + policyTable[policyTableSize].actSpacing = 0; + policyTable[policyTableSize].inCounter = 0; + policyTable[policyTableSize].seqno = -1; + } else if (strcmp(argv[4], "WBE3") == 0) { + if(!policy_pool[WBE3]) + policy_pool[WBE3] = new WBE3Policy; + policyTable[policyTableSize].policy_index = WBE3; + policyTable[policyTableSize].policer = WBE3Policer; + policyTable[policyTableSize].meter = WBE3Meter; + + policyTable[policyTableSize].avgSpacing = 7; + policyTable[policyTableSize].actSpacing = 0; + policyTable[policyTableSize].inCounter = 0; + policyTable[policyTableSize].seqno = -1; + } else if (strcmp(argv[4], "MELLIA") == 0) { + if(!policy_pool[MELLIA]) + policy_pool[MELLIA] = new MELLIAPolicy; + policyTable[policyTableSize].policy_index = MELLIA; + policyTable[policyTableSize].policer = MELLIAPolicer; + policyTable[policyTableSize].meter = MELLIAMeter; + + policyTable[policyTableSize].n_s = 6; + policyTable[policyTableSize].n_a = 0; + policyTable[policyTableSize].seqno = -1; + } else if (strcmp(argv[4], "MERGE") == 0) { + if(!policy_pool[MERGE]) + policy_pool[MERGE] = new MERGEPolicy; + policyTable[policyTableSize].policy_index = MERGE; + policyTable[policyTableSize].policer = MERGEPolicer; + policyTable[policyTableSize].meter = MERGEMeter; + + policyTable[policyTableSize].avgSpacing = 7; + policyTable[policyTableSize].actSpacing = 0; + policyTable[policyTableSize].seqno = -1; + policyTable[policyTableSize].n_s = 6; + policyTable[policyTableSize].n_a = 0; } else { printf("No applicable policy specified, exit!!!\n"); exit(-1); @@ -273,6 +343,37 @@ policy_pool[EWP] = new EWPolicy; policerTable[policerTableSize].policer = EWPolicer; policerTable[policerTableSize].policy_index = EWP; + /*TTI_LAB else-if sequence*/ + } else if (strcmp(argv[2], "PS") == 0) { + if(!policy_pool[PS]) + policy_pool[PS] = new PSPolicy; + policerTable[policerTableSize].policer = PSPolicer; + policerTable[policerTableSize].policy_index = PS; + } else if (strcmp(argv[2], "WBE") == 0) { + if(!policy_pool[WBE]) + policy_pool[WBE] = new WBEPolicy; + policerTable[policerTableSize].policer = WBEPolicer; + policerTable[policerTableSize].policy_index = WBE; + } else if (strcmp(argv[2], "WBE2") == 0) { + if(!policy_pool[WBE2]) + policy_pool[WBE2] = new WBE2Policy; + policerTable[policerTableSize].policer = WBE2Policer; + policerTable[policerTableSize].policy_index = WBE2; + } else if (strcmp(argv[2], "WBE3") == 0) { + if(!policy_pool[WBE3]) + policy_pool[WBE3] = new WBE3Policy; + policerTable[policerTableSize].policer = WBE3Policer; + policerTable[policerTableSize].policy_index = WBE3; + } else if (strcmp(argv[2], "MELLIA") == 0) { + if(!policy_pool[MELLIA]) + policy_pool[MELLIA] = new MELLIAPolicy; + policerTable[policerTableSize].policer = MELLIAPolicer; + policerTable[policerTableSize].policy_index = MELLIA; + } else if (strcmp(argv[2], "MERGE") == 0) { + if(!policy_pool[MERGE]) + policy_pool[MERGE] = new MERGEPolicy; + policerTable[policerTableSize].policer = MERGEPolicer; + policerTable[policerTableSize].policy_index = MERGE; } else { printf("No applicable policer specified, exit!!!\n"); exit(-1); @@ -436,6 +537,44 @@ policyTable[i].sourceNode,policyTable[i].destNode); printf("initial code point %d.\n", policyTable[i].codePt); break; + /*TTI_LAB cases*/ + case PSPolicer: + printf("Flow (%d to %d): Packet Spacing policer, ", + policyTable[i].sourceNode,policyTable[i].destNode); + printf("initial code point %d, average spacing %.1f.\n", + policyTable[i].codePt, policyTable[i].avgSpacing); + break; + case WBEPolicer: + printf("Flow (%d to %d): WBE policer, ", + policyTable[i].sourceNode,policyTable[i].destNode); + printf("initial code point %d. \n", + policyTable[i].codePt); + break; + case WBE2Policer: + printf("Flow (%d to %d): WBE2 policer, ", + policyTable[i].sourceNode,policyTable[i].destNode); + printf("initial code point %d. \n", + policyTable[i].codePt); + break; + case WBE3Policer: + printf("Flow (%d to %d): WBE3 policer, ", + policyTable[i].sourceNode,policyTable[i].destNode); + printf("initial code point %d. \n", + policyTable[i].codePt); + break; + case MELLIAPolicer: + printf("Flow (%d to %d): MELLIA policer, ", + policyTable[i].sourceNode,policyTable[i].destNode); + printf("initial code point %d. \n", + policyTable[i].codePt); + break; + case MERGEPolicer: + printf("Flow (%d to %d): MERGE policer, ", + policyTable[i].sourceNode,policyTable[i].destNode); + printf("initial code point %d. \n", + policyTable[i].codePt); + break; + default: printf("ERROR: Unknown policer type in Policy Table.\n"); } @@ -479,6 +618,22 @@ case EWPolicer: printf("EW "); break; + /*TTI_LAB cases*/ + case PSPolicer: + printf("Packet Spacing "); + break; + case WBEPolicer: + printf("WBE "); + break; + case WBE2Policer: + printf("WBE2 "); + break; + case MELLIAPolicer: + printf("MELLIA "); + break; + case MERGEPolicer: + printf("MERGE "); + break; default: printf("ERROR: Unknown policer type in Policer Table."); } @@ -974,3 +1129,368 @@ printf("\n"); } // End of SFD + +/*TTI_LAB policies*/ + + // Beginning of PS + + /*----------------------------------------------------------------------------- + void PSPolicy::applyMeter(policyTableEntry *policy, Packet *pkt) + + Do nothing + -----------------------------------------------------------------------------*/ + void PSPolicy::applyMeter(policyTableEntry *policy, Packet *pkt) { + + + } + /*---------------------------------------------------------------------------- + int PSPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, + Packet* pkt) + when the control congestion windown is less than 4 mark with in. + mark packet in dependent of avgSpacing and actSpacing count each packet o part of packet marked IN, actSpacing reduces every packet marked out + Returns: A code point to apply to the current packet. + Uses: Method downgradeOne(). + -----------------------------------------------------------------------------*/ + int PSPolicy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet* pkt) { + + hdr_cmn* cmn=hdr_cmn::access(pkt); + hdr_ip* ip=hdr_ip::access(pkt); + hdr_tcp* tcp = hdr_tcp::access(pkt); + + if ((cmn->ptype_)==5) { + return(policer->initialCodePt); //cmq gli ACK vanno protetti + } + + if((cmn->ptype_)!=1){ //se il pkt e' TCP protegge + if ((tcp->mywind_ < 4.0)||(tcp->reason_!=0)) { //per finesta < 4 o ritrasm. + //if (tcp->reason_!=0) { //per ritrasm. + //if (tcp->mywind_ < 4.0) { //per finesta < 4 + return(policer->initialCodePt); + } else { + if ((policy->actSpacing) <= 1){ //distanzia i pkt + policy->actSpacing += policy->avgSpacing; + return(policer->initialCodePt); + } else { + --(policy->actSpacing); + return(policer->downgrade1); + } + } + }else{ //per pkt no TCP degrada + return (policer->downgrade1); + } + } + // End of Packet Spacing. + + /*----------------------------------------------------------------------------- + void WBEPolicy::applyMeter(policyTableEntry *policy, Packet *pkt) + + Do nothing + -----------------------------------------------------------------------------*/ + void WBEPolicy::applyMeter(policyTableEntry *policy, Packet *pkt) { + + + } + /*---------------------------------------------------------------------------- + int WBEPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, + Packet* pkt) + Returns: A code point to apply to the current packet. + Uses: Method downgradeOne(). + -----------------------------------------------------------------------------*/ + int WBEPolicy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet* pkt) { + + hdr_cmn* cmn=hdr_cmn::access(pkt); + hdr_tcp* tcp = hdr_tcp::access(pkt); + + if (((cmn->ptype_)!=5) && (cmn->size()==40)) { +// printf ("ho trovato il syn"); + (policy->avgSpacing) = 7; + (policy->actSpacing) = 0; + (policy->seqno) = -1; + } + + + if ((cmn->ptype_)==5) { + return(policer->initialCodePt); //cmq gli ACK vanno protetti + } + + if (tcp->seqno_ <= policy->seqno) { + policy->avgSpacing = 0.5 * (policy->avgSpacing) + 0.5 * (policy->actSpacing); + (policy->actSpacing) = 0; + // (policy->seqno) = tcp->seqno_; + return(policer->initialCodePt); + } else { + (policy->seqno) = tcp->seqno_; + (policy->actSpacing)++; + if (policy->actSpacing > policy->avgSpacing) { + (policy->actSpacing) = 0; + (policy->avgSpacing) = 2*(policy->avgSpacing+1); + return(policer->downgrade1); + } else return(policer->initialCodePt); + } + } + + // End of WBE. + + + /*----------------------------------------------------------------------------- + void WBE2Policy::applyMeter(policyTableEntry *policy, Packet *pkt) + + Do nothing + -----------------------------------------------------------------------------*/ + void WBE2Policy::applyMeter(policyTableEntry *policy, Packet *pkt) { + + + } + /*---------------------------------------------------------------------------- + int WBE2Policy::applyPolicer(policyTableEntry *policy, int initialCodePt, + Packet* pkt) + Returns: A code point to apply to the current packet. + Uses: Method downgradeOne(). + -----------------------------------------------------------------------------*/ + int WBE2Policy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet* pkt) { + + hdr_cmn* cmn=hdr_cmn::access(pkt); + hdr_tcp* tcp = hdr_tcp::access(pkt); + double now; + + if (((cmn->ptype_)!=5) && (cmn->size()==40)) { +// printf ("ho trovato il syn"); + (policy->avgSpacing) = 7; + (policy->actSpacing) = 0; + (policy->inCounter) = 0; + (policy->seqno) = -1; + } + + + if ((cmn->ptype_)==5) { + return(policer->initialCodePt); //cmq gli ACK vanno protetti + } + + now = Scheduler::instance().clock(); + + if (tcp->seqno_ <= policy->seqno) { + policy->avgSpacing = 0.5 * (policy->avgSpacing) + 0.5 * (policy->actSpacing); + //printf("%f SEQ %4d %4d DATA %x %f %10.6f IN-RTX \n", now, tcp->seqno(), policy->seqno, policy, policy->actSpacing, policy->avgSpacing); + (policy->actSpacing) = 0; + (policy->inCounter)++; + // (policy->seqno) = tcp->seqno_; + return(policer->initialCodePt); + } else { + (policy->seqno) = tcp->seqno_; + (policy->actSpacing)++; +// if (policy->inCounter > ((policy->avgSpacing)-1)) { +// A=N-1 + if (policy->inCounter > (policy->avgSpacing)) { + //printf("%f SEQ %4d %4d DATA %x %f %10.6f OUT \n", now, tcp->seqno(), policy->seqno, policy, policy->actSpacing, policy->avgSpacing); + (policy->inCounter) = 0; + // (policy->avgSpacing) = 2*(policy->avgSpacing+1); + (policy->avgSpacing)++; + return(policer->downgrade1); + } else { + (policy->inCounter)++; + //printf("%f SEQ %4d %4d DATA %x %f %10.6f IN-NEW \n", now, tcp->seqno(), policy->seqno, policy, policy->actSpacing, policy->avgSpacing); + return(policer->initialCodePt); + } + } + } + + // End of WBE2. + + + + /*----------------------------------------------------------------------------- + void WBE3Policy::applyMeter(policyTableEntry *policy, Packet *pkt) + + Do nothing + -----------------------------------------------------------------------------*/ + void WBE3Policy::applyMeter(policyTableEntry *policy, Packet *pkt) { + + + } + /*---------------------------------------------------------------------------- + int WBE3Policy::applyPolicer(policyTableEntry *policy, int initialCodePt, + Packet* pkt) + Returns: A code point to apply to the current packet. + Uses: Method downgradeOne(). + -----------------------------------------------------------------------------*/ + int WBE3Policy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet* pkt) { + + hdr_cmn* cmn=hdr_cmn::access(pkt); + hdr_tcp* tcp = hdr_tcp::access(pkt); + + + if (((cmn->ptype_)!=5) && (cmn->size()==40)) { + // printf ("ho trovato il syn"); + (policy->avgSpacing) = 7; + (policy->actSpacing) = 0; + (policy->inCounter) = 0; + (policy->seqno) = -1; + } + + + if ((cmn->ptype_)==5) { + return(policer->initialCodePt); //cmq gli ACK vanno protetti + } + + if (tcp->seqno_ <= policy->seqno) { + // double xxx = 0.5 * policy->actSpacing + 0.5 * policy->avgSpacing; + policy->avgSpacing = (policy->actSpacing > policy->avgSpacing) ? policy->avgSpacing : policy->actSpacing; + //printf("SEQ %4d %4d DATA %x %f %10.6f IN-RTX \n", tcp->seqno(), policy->seqno, policy, policy->actSpacing, policy->avgSpacing); + // printf("%d %x %f IN-RTX\n", tcp->seqno(), policy, policy->avgSpacing); + (policy->actSpacing) = 0; + (policy->inCounter)++; + // (policy->seqno) = tcp->seqno_; + return(policer->initialCodePt); + } else { + (policy->seqno) = tcp->seqno_; + (policy->actSpacing)++; + if (policy->inCounter > (policy->avgSpacing)) { + //printf("SEQ %4d %4d DATA %x %f %10.6f OUT \n", tcp->seqno(), policy->seqno, policy, policy->actSpacing, policy->avgSpacing); + // printf("%d %x %f OUT\n", tcp->seqno(), policy, policy->avgSpacing); + (policy->inCounter) = 0; + policy->avgSpacing+=1; + return(policer->downgrade1); + } else { + (policy->inCounter)++; + //printf("SEQ %4d %4d DATA %x %f %10.6f NEW \n", tcp->seqno(), policy->seqno, policy, policy->actSpacing, policy->avgSpacing); + // printf("%d %x %f NEW\n", tcp->seqno(), policy, policy->avgSpacing); + return(policer->initialCodePt); + } + } + +/* OLD MODEL + if (tcp->seqno_ <= policy->seqno) { + policy->avgSpacing = 0.5 * (policy->avgSpacing) + 0.5 * (policy->actSpacing); + printf("SEQ %4d %4d DATA %x %f %10.6f IN-RTX \n", tcp->seqno(), policy->seqno, policy, policy->actSpacing, policy->avgSpacing); + (policy->actSpacing) = 0; + (policy->inCounter)++; + // (policy->seqno) = tcp->seqno_; + return(policer->initialCodePt); + } else { + (policy->seqno) = tcp->seqno_; + (policy->actSpacing)++; + if (policy->inCounter > (policy->avgSpacing)) { + printf("SEQ %4d %4d DATA %x %f %10.6f OUT \n", tcp->seqno(), policy->seqno, policy, policy->actSpacing, policy->avgSpacing); + (policy->inCounter) = 0; + // (policy->avgSpacing) = 2*(policy->avgSpacing+1); + return(policer->downgrade1); + } else { + (policy->inCounter)++; + printf("SEQ %4d %4d DATA %x %f %10.6f IN-NEW \n", tcp->seqno(), policy->seqno, policy, policy->actSpacing, policy->avgSpacing); + return(policer->initialCodePt); + } + } +*/ + } + + // End of WBE3. + + + + /*----------------------------------------------------------------------------- + void MELLIAPolicy::applyMeter(policyTableEntry *policy, Packet *pkt) + + Do nothing + -----------------------------------------------------------------------------*/ + void MELLIAPolicy::applyMeter(policyTableEntry *policy, Packet *pkt) { + + + } + /*---------------------------------------------------------------------------- + int MELLIAPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, + Packet* pkt) + Returns: A code point to apply to the current packet. + Uses: Method downgradeOne(). + -----------------------------------------------------------------------------*/ + int MELLIAPolicy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet* pkt) { + + hdr_cmn* cmn=hdr_cmn::access(pkt); + hdr_tcp* tcp = hdr_tcp::access(pkt); + + if (((cmn->ptype_)!=5) && (cmn->size()==40)) { +// printf ("ho trovato il syn"); + (policy->n_s) = 6; + (policy->n_a) = 0; + (policy->seqno) = -1; + } + + if (tcp->seqno_ <= policy->seqno) { + if ((policy->n_a)==0) (policy->n_a) = 5; + } else { + (policy->seqno) = tcp->seqno_; +// (policy->n_a) = 0; if a new sequence number means everything is OK + } + + if ((policy->n_s) > 0) { + (policy->n_s)--; + return(policer->initialCodePt); + } else if ((policy->n_a) > 0) { + (policy->n_a)--; + return(policer->initialCodePt); + } else return(policer->downgrade1); + } + + // End of MELLIA. + + /*----------------------------------------------------------------------------- + void MERGEPolicy::applyMeter(policyTableEntry *policy, Packet *pkt) + + Do nothing + -----------------------------------------------------------------------------*/ + void MERGEPolicy::applyMeter(policyTableEntry *policy, Packet *pkt) { + + + } + /*---------------------------------------------------------------------------- + int MERGEPolicy::applyPolicer(policyTableEntry *policy, int initialCodePt, + Packet* pkt) + Returns: A code point to apply to the current packet. + Uses: Method downgradeOne(). + -----------------------------------------------------------------------------*/ + int MERGEPolicy::applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet* pkt) { + + hdr_cmn* cmn=hdr_cmn::access(pkt); + hdr_tcp* tcp = hdr_tcp::access(pkt); + + if (((cmn->ptype_)!=5) && (cmn->size()==40)) { +// printf ("ho trovato il syn"); + (policy->avgSpacing) = 7; + (policy->actSpacing) = 0; + (policy->n_s) = 6; + (policy->n_a) = 0; + (policy->seqno) = -1; + } + + if ((cmn->ptype_)==5) { + return(policer->downgrade1); //cmq gli ACK vanno protetti + } + + + if (tcp->seqno_ <= policy->seqno) { + if ((policy->n_a)==0) (policy->n_a) = 5; + policy->avgSpacing = 0.5 * (policy->avgSpacing) + 0.5 * (policy->actSpacing); + (policy->actSpacing) = 0; + // (policy->seqno) = tcp->seqno_; + // return(policer->downgrade1); + } else { + (policy->seqno) = tcp->seqno_; + (policy->actSpacing)++; + } + + if ((policy->n_s) > 0) { + (policy->n_s)--; + return(policer->initialCodePt); + } else if ((policy->n_a) > 0) { + (policy->n_a)--; + return(policer->initialCodePt); + } else if (policy->actSpacing > policy->avgSpacing) { + (policy->actSpacing) = 0; + (policy->avgSpacing) = 2*(policy->avgSpacing+1); + return(policer->downgrade2); + } else return(policer->downgrade1); + + } + + // End of MERGE. + + diff -Naurb ns-allinone-2.1b9a/ns-2.1b9a/diffserv/dsPolicy.h ns-allinone-2.1b9a_modif/ns-2.1b9a/diffserv/dsPolicy.h --- ns-allinone-2.1b9a/ns-2.1b9a/diffserv/dsPolicy.h 2002-08-22 01:55:23.000000000 +0200 +++ ns-allinone-2.1b9a_modif/ns-2.1b9a/diffserv/dsPolicy.h 2004-01-29 12:32:43.000000000 +0100 @@ -40,7 +40,8 @@ #define ANY_HOST -1 // Add to enable point to multipoint policy #define FLOW_TIME_OUT 5.0 // The flow does not exist already. -#define MAX_POLICIES 20 // Max. size of Policy Table. +//#define MAX_POLICIES 20 // Max. size of Policy Table. +#define MAX_POLICIES 1000 // TTI_LAB #define DUMB 0 #define TSW2CM 1 @@ -50,10 +51,16 @@ #define TRTCM 5 #define SFD 6 #define EWP 7 +#define PS 8 //TTI_LAB +#define WBE 9 //TTI_LAB +#define MELLIA 10 //TTI_LAB +#define MERGE 11 //TTI_LAB +#define WBE2 12 //TTI_LAB +#define WBE3 13 //TTI_LAB -enum policerType {dumbPolicer, TSW2CMPolicer, TSW3CMPolicer, tokenBucketPolicer, srTCMPolicer, trTCMPolicer, SFDPolicer, EWPolicer}; +enum policerType {dumbPolicer, TSW2CMPolicer, TSW3CMPolicer, tokenBucketPolicer, srTCMPolicer, trTCMPolicer, SFDPolicer, EWPolicer, PSPolicer, WBEPolicer, WBE2Policer, WBE3Policer, MELLIAPolicer, MERGEPolicer};//TTI_LAB -enum meterType {dumbMeter, tswTagger, tokenBucketMeter, srTCMMeter, trTCMMeter, sfdTagger, ewTagger}; +enum meterType {dumbMeter, tswTagger, tokenBucketMeter, srTCMMeter, trTCMMeter, sfdTagger, ewTagger, PSMeter, WBEMeter, WBE2Meter, WBE3Meter, MELLIAMeter, MERGEMeter}; class Policy; class TBPolicy; @@ -75,6 +82,11 @@ double pBucket; // Current size of peak bucket (bytes) double arrivalTime; // Arrival time of last packet in TSW metering double avgRate, winLen; // Used for TSW metering + double avgSpacing; // Used for PS, WBE, WBE2, MERGE (TTI_LAB) + double actSpacing; // Used for PS, WBE, WBE2, MERGE (TTI_LAB) + int inCounter; // Used for WBE2 (TTI_LAB) + int seqno; // Last sequence number, used for WBE, WBE2, MELLIA, MERGE (TTI_LAB) + int n_s, n_a; // IN packet number at the flow begin and after a out-of-sequence (TTI_LAB) }; @@ -219,4 +231,67 @@ struct flow_list flow_table; }; +/*TTI_LAB classes*/ +class PSPolicy : public Policy { + public: + PSPolicy() : Policy(){}; + + // Metering and policing methods: + void applyMeter(policyTableEntry *policy, Packet *pkt); + int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt); + + }; + + class WBEPolicy : public Policy { + public: + WBEPolicy() : Policy(){}; + + // Metering and policing methods: + void applyMeter(policyTableEntry *policy, Packet *pkt); + int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt); + + }; + + + class WBE2Policy : public Policy { + public: + WBE2Policy() : Policy(){}; + + // Metering and policing methods: + void applyMeter(policyTableEntry *policy, Packet *pkt); + int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt); + + }; + + class WBE3Policy : public Policy { + public: + WBE3Policy() : Policy(){}; + + // Metering and policing methods: + void applyMeter(policyTableEntry *policy, Packet *pkt); + int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt); + + }; + + + class MELLIAPolicy : public Policy { + public: + MELLIAPolicy() : Policy(){}; + + // Metering and policing methods: + void applyMeter(policyTableEntry *policy, Packet *pkt); + int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt); + + }; + + class MERGEPolicy : public Policy { + public: + MERGEPolicy() : Policy(){}; + + // Metering and policing methods: + void applyMeter(policyTableEntry *policy, Packet *pkt); + int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt); + + }; + #endif diff -Naurb ns-allinone-2.1b9a/ns-2.1b9a/diffserv/dsred.cc ns-allinone-2.1b9a_modif/ns-2.1b9a/diffserv/dsred.cc --- ns-allinone-2.1b9a/ns-2.1b9a/diffserv/dsred.cc 2001-12-19 21:53:32.000000000 +0100 +++ ns-allinone-2.1b9a_modif/ns-2.1b9a/diffserv/dsred.cc 2004-01-30 11:43:42.000000000 +0100 @@ -67,6 +67,7 @@ dsREDQueue::dsREDQueue() : de_drop_(NULL), link_(NULL) { bind("numQueues_", &numQueues_); bind_bool("ecn_", &ecn_); + bind_bool("traccia", &traccia); //TTI_LAB int i; numPrec = MAX_PREC; @@ -174,13 +175,44 @@ void dsREDQueue::enque(Packet* pkt) { int codePt, eq_id, prec; hdr_ip* iph = hdr_ip::access(pkt); + hdr_tcp* tcph = hdr_tcp::access(pkt); //TTI_LAB //extracting the marking done by the edge router codePt = iph->prio(); int ecn = 0; + int pippor=0; //TTI_LAB + double pippoa=0; //TTI_LAB + double pippow=0; //TTI_LAB + int flussoid= iph->fid_; //TTI_LAB + double now = Scheduler::instance().clock(); //TTI_LAB + FILE* traccia_file; //TTI_LAB + int i=0; //TTI_LAB + //looking up queue and prec numbers for that codept lookupPHBTable(codePt, &eq_id, &prec); + +// Tracciamento delle informazioni che hanno permesso di selezionare la coda da deque (TTI_LAB) + if (traccia){ + pippow = tcph->mywind(); + // if (redq_[eq_id].mredMode == rio_c) { +pippor=redq_[eq_id].getRealLength_v(0)+redq_[eq_id].getRealLength_v(1); + pippoa = redq_[eq_id].getWeightedLength_v(prec); + traccia_file = fopen("trace.tr","at"); + fprintf(traccia_file,"t: %.6f q: %d p: 0 RL: %d WL: %.6f Win: %.6f Fid: %d\n",now,eq_id,pippor,pippoa,pippow,flussoid); + if (prec==1) { + pippor=0; + pippoa=0; + for (i=0;iaccess(off_flags_)); // Changed for the latest version instead of 2.1b6 @@ -471,15 +503,16 @@ An output method that may be altered to assist debugging. ------------------------------------------------------------------------------*/ void dsREDQueue::printStats() { - printf("\nPackets Statistics\n"); - printf("=======================================\n"); - printf(" CP TotPkts TxPkts ldrops edrops\n"); - printf(" -- ------- ------ ------ ------\n"); - printf("All %8ld %8ld %8ld %8ld\n",stats.pkts,stats.pkts-stats.drops-stats.edrops,stats.drops,stats.edrops); + //printf("\nPackets Statistics\n"); //TTI_LAB + //printf("=======================================\n"); //TTI_LAB + //printf(" CP TotPkts TxPkts ldrops edrops\n"); //TTI_LAB + //printf(" -- ------- ------ ------ ------\n"); //TTI_LAB + double now = Scheduler::instance().clock(); //TTI_LAB + printf("%.3f All %8ld %8ld %8ld %8ld ",now,stats.pkts,stats.pkts-stats.drops-stats.edrops,stats.drops,stats.edrops); for (int i = 0; i < MAX_CP; i++) if (stats.pkts_CP[i] != 0) - printf("%3d %8ld %8ld %8ld %8ld\n",i,stats.pkts_CP[i],stats.pkts_CP[i]-stats.drops_CP[i]-stats.edrops_CP[i],stats.drops_CP[i],stats.edrops_CP[i]); - + printf("%3d %8ld %8ld %8ld %8ld ",i,stats.pkts_CP[i],stats.pkts_CP[i]-stats.drops_CP[i]-stats.edrops_CP[i],stats.drops_CP[i],stats.edrops_CP[i]); + printf("\n"); } diff -Naurb ns-allinone-2.1b9a/ns-2.1b9a/diffserv/dsred.h ns-allinone-2.1b9a_modif/ns-2.1b9a/diffserv/dsred.h --- ns-allinone-2.1b9a/ns-2.1b9a/diffserv/dsred.h 2001-10-19 09:59:51.000000000 +0200 +++ ns-allinone-2.1b9a_modif/ns-2.1b9a/diffserv/dsred.h 2004-01-09 11:39:51.000000000 +0100 @@ -142,6 +142,7 @@ int wirrTemp[MAX_QUEUES]; unsigned char wirrqDone[MAX_QUEUES]; int queuesDone; + int traccia; // Inserito per il tracciamento (TTI_LAB) void reset(); void edrop(Packet* p); // used so flowmonitor can monitor early drops diff -Naurb ns-allinone-2.1b9a/ns-2.1b9a/diffserv/dsredq.h ns-allinone-2.1b9a_modif/ns-2.1b9a/diffserv/dsredq.h --- ns-allinone-2.1b9a/ns-2.1b9a/diffserv/dsredq.h 2001-12-19 21:53:32.000000000 +0100 +++ ns-allinone-2.1b9a_modif/ns-2.1b9a/diffserv/dsredq.h 2004-02-04 22:56:29.000000000 +0100 @@ -37,6 +37,7 @@ #ifndef dsredq_h #define dsredq_h +#include "trace.h"// (TTI_LAB) //#include "dsred.h" // maximum number of virtual RED queues in one physical queue #define MAX_PREC 3 diff -Naurb ns-allinone-2.1b9a/ns-2.1b9a/tcl/lib/ns-default.tcl ns-allinone-2.1b9a_modif/ns-2.1b9a/tcl/lib/ns-default.tcl --- ns-allinone-2.1b9a/ns-2.1b9a/tcl/lib/ns-default.tcl 2002-10-20 00:41:36.000000000 +0200 +++ ns-allinone-2.1b9a_modif/ns-2.1b9a/tcl/lib/ns-default.tcl 2004-02-04 09:42:27.000000000 +0100 @@ -107,6 +107,9 @@ Queue/dsRED set numQueues_ 4 Queue/dsRED set ecn_ 0 +#by TTI_LAB +Queue/dsRED set traccia false + Queue/RED set bytes_ false Queue/RED set queue_in_bytes_ false # Queue/RED set thresh_ 5 @@ -201,13 +204,14 @@ Queue/PI set prob_ 0 Queue/PI set curq_ 0 -# Queue/Vq set queue_in_bytes_ false + +#Queue/Vq set queue_in_bytes_ false Queue/Vq set queue_in_bytes_ true -# Default for queue_in_bytes_ changed to true on 4/28/2002. +## Default for queue_in_bytes_ changed to true on 4/28/2002. Queue/Vq set markpkts_ false Queue/Vq set ecnlim_ 0.8 Queue/Vq set buflim_ 1.0 -# Queue/Vq set gamma_ 0.895 +#Queue/Vq set gamma_ 0.895 Queue/Vq set gamma_ 0.98 # Default for gamma_ changed to 0.98 on 4/28/2002. Queue/Vq set mean_pktsize_ 1000 @@ -756,10 +760,12 @@ Agent/TCP set useHeaders_ true ; # default changed on 2001/11/28. # These are all variables for experimental high-speed TCP. -# Agent/TCP set low_window_ 31 + +#Agent/TCP set low_window_ 31 Agent/TCP set low_window_ 38 # low_window_ was changed on 2002/8/12 from 31 to 38, for low_p_ of 0.001. # This should be an undetectable change in performance. + Agent/TCP set high_window_ 83000 Agent/TCP set high_p_ 0.0000001 Agent/TCP set high_decrease_ 0.1 @@ -804,6 +810,11 @@ Agent/TCPSink set ts_echo_bugfix_ false Agent/TCPSink set generateDSacks_ false Agent/TCPSink set RFC2581_immediate_ack_ true +Agent/TCPSink set bytes_rcv 0; #TTI_LAB + +Agent/TCPSink set tstamp_ 0; #TTI_LAB +Agent/TCPSink set tstampsquare_ 0; #TTI_LAB +Agent/TCPSink set npktrecv_ 0;#TTI_LAB Agent/TCPSink/DelAck set interval_ 100ms catch { @@ -998,6 +1009,10 @@ Agent/LossMonitor set bytes_ 0 Agent/LossMonitor set lastPktTime_ 0 Agent/LossMonitor set expected_ 0 +#Agent/LossMonitor set expected_ -1 + +Agent/LossMonitor set latenzaMedia_ 0 ; #TTI_LAB +Agent/LossMonitor set tempoStamps_ 0 ; #TTI_LAB # RAP Agent/RAP set packetSize_ 512 diff -Naurb ns-allinone-2.1b9a/ns-2.1b9a/tcp/tcp-sink.cc ns-allinone-2.1b9a_modif/ns-2.1b9a/tcp/tcp-sink.cc --- ns-allinone-2.1b9a/ns-2.1b9a/tcp/tcp-sink.cc 2002-08-20 05:13:33.000000000 +0200 +++ ns-allinone-2.1b9a_modif/ns-2.1b9a/tcp/tcp-sink.cc 2004-02-04 23:04:57.000000000 +0100 @@ -83,6 +83,7 @@ return; } + void Acker::update_ts(int seqno, double ts) { if (ts >= ts_to_echo_ && seqno <= next_) @@ -99,6 +100,7 @@ if (numBytes <= 0) printf("Error, received TCP packet size <= 0\n"); int numToDeliver = 0; + while(seq + 1 - next_ >= wndmask_) { // next_ is next packet expected; wndmask_ is the maximum // window size minus 1; if somehow the seqno of the @@ -181,6 +183,8 @@ #else /* ! TCP_DELAY_BIND_ALL */ bind("maxSackBlocks_", &max_sack_blocks_); // used only by sack #endif /* TCP_DELAY_BIND_ALL */ + bind("bytes_rcv", &bytes_rcv); //TTI_LAB + trace_flag = false; //TTI_LAB } void @@ -190,6 +194,11 @@ delay_bind_init_one("ts_echo_bugfix_"); delay_bind_init_one("generateDSacks_"); // used only by sack delay_bind_init_one("RFC2581_immediate_ack_"); + + delay_bind_init_one("tstamp_");// (TTI_LAB) + delay_bind_init_one("tstampsquare_");// (TTI_LAB) + delay_bind_init_one("npktrecv_");// (TTI_LAB) + #if defined(TCP_DELAY_BIND_ALL) && 0 delay_bind_init_one("maxSackBlocks_"); #endif /* TCP_DELAY_BIND_ALL */ @@ -204,6 +213,12 @@ if (delay_bind_bool(varName, localName, "ts_echo_bugfix_", &ts_echo_bugfix_, tracer)) return TCL_OK; if (delay_bind_bool(varName, localName, "generateDSacks_", &generate_dsacks_, tracer)) return TCL_OK; if (delay_bind_bool(varName, localName, "RFC2581_immediate_ack_", &RFC2581_immediate_ack_, tracer)) return TCL_OK; + + if (delay_bind(varName, localName, "tstamp_", &tstamp_, tracer)) return TCL_OK;// (TTI_LAB) + if (delay_bind(varName, localName, "tstampsquare_", &tstampsquare_, tracer)) return TCL_OK;// (TTI_LAB) + if (delay_bind(varName, localName, "npktrecv_", &npktrecv_, tracer)) return TCL_OK;// (TTI_LAB) + + #if defined(TCP_DELAY_BIND_ALL) && 0 if (delay_bind(varName, localName, "maxSackBlocks_", &max_sack_blocks_, tracer)) return TCL_OK; #endif /* TCP_DELAY_BIND_ALL */ @@ -227,12 +242,23 @@ reset(); return (TCL_OK); } + if ((strcmp(argv[1], "clear") == 0 ) && trace_flag) {//TTI_LAB + fclose(trace_file); //TTI_LAB + }//TTI_LAB if (strcmp(argv[1], "resize_buffers") == 0) { // no need for this as seen buffer set dynamically fprintf(stderr,"DEPRECIATED: resize_buffers\n"); - return (TCL_OK); + } } + if (argc == 3) { //TTI_LAB + if (strcmp(argv[1], "start_trace") == 0) { //TTI_LAB + trace_file = fopen(argv[2], "at"); //TTI_LAB + trace_flag = true; //TTI_LAB + return (TCL_OK); //TTI_LAB + } //TTI_LAB + } //TTI_LAB + return (Agent::command(argc, argv)); } @@ -316,13 +342,36 @@ int numToDeliver; int numBytes = hdr_cmn::access(pkt)->size(); // number of bytes in the packet just received + + + double tempoconsegna;// (TTI_LAB) + double now = Scheduler::instance().clock();// (TTI_LAB) + + bytes_rcv += numBytes;//TTI_LAB + // number of bytes in the packet just received hdr_tcp *th = hdr_tcp::access(pkt); /* W.N. Check if packet is from previous incarnation */ + + ++npktrecv_;// (TTI_LAB) + tempoconsegna=now-(th->ts_);// (TTI_LAB) + tstamp_+=tempoconsegna;// (TTI_LAB) + tstampsquare_+=tempoconsegna*tempoconsegna;// (TTI_LAB) + if (th->ts() < lastreset_) { // Remove packet and do nothing Packet::free(pkt); return; } + + //TTI_LAB begin + // Print timestamp + if (trace_flag) { + double triptime_; + double time = Scheduler::instance().clock(); + triptime_ = (time - th->ts()); + fprintf(trace_file, "%g\t Seqno: %i\t Triptime: %g\n", time, th->seqno(), triptime_); + } + //TTI_LAB end acker_->update_ts(th->seqno(),th->ts()); // update the timestamp to echo diff -Naurb ns-allinone-2.1b9a/ns-2.1b9a/tcp/tcp-sink.h ns-allinone-2.1b9a_modif/ns-2.1b9a/tcp/tcp-sink.h --- ns-allinone-2.1b9a/ns-2.1b9a/tcp/tcp-sink.h 2002-08-20 05:13:33.000000000 +0200 +++ ns-allinone-2.1b9a_modif/ns-2.1b9a/tcp/tcp-sink.h 2004-02-04 23:05:48.000000000 +0100 @@ -41,7 +41,10 @@ /* max window size */ #define MWS 64 +//#define MWS 1024 + #define MWM (MWS-1) + /* For Tahoe TCP, the "window" parameter, representing the receiver's * advertised window, should be less than MWM. For Reno TCP, the * "window" parameter should be less than MWM/2. @@ -98,6 +101,11 @@ void reset(); int command(int argc, const char*const* argv); TracedInt& maxsackblocks() { return max_sack_blocks_; } + + double tstamp_; // (TTI_LAB) + double tstampsquare_; // (TTI_LAB) + int npktrecv_; // (TTI_LAB) + protected: void ack(Packet*); @@ -118,6 +126,9 @@ // for RFC2581-compliant gap-filling. double lastreset_; /* W.N. used for detecting packets */ /* from previous incarnations */ + int bytes_rcv; //TTI_LAB + bool trace_flag; //TTI_LAB + FILE* trace_file; //TTI_LAB }; class DelAckSink; diff -Naurb ns-allinone-2.1b9a/ns-2.1b9a/tcp/tcp.cc ns-allinone-2.1b9a_modif/ns-2.1b9a/tcp/tcp.cc --- ns-allinone-2.1b9a/ns-2.1b9a/tcp/tcp.cc 2002-10-20 00:41:37.000000000 +0200 +++ ns-allinone-2.1b9a_modif/ns-2.1b9a/tcp/tcp.cc 2004-02-04 22:59:16.000000000 +0100 @@ -579,6 +579,7 @@ hdr_tcp *tcph = hdr_tcp::access(p); hdr_flags* hf = hdr_flags::access(p); int databytes = hdr_cmn::access(p)->size(); + tcph->mywind()=windowd();// (TTI_LAB) tcph->seqno() = seqno; tcph->ts() = Scheduler::instance().clock(); tcph->ts_echo() = ts_peer_; @@ -889,7 +890,6 @@ } cwnd_ += increment; break; - case 2: /* These are window increase algorithms * for experimental purposes only. */ @@ -954,6 +954,7 @@ // The decrease factor ranges from 0.5 to high_decrease // as the window ranges from low_window to high_window, // as the log of the window. + // For an efficient implementation, this would just be looked up // in a table, with the increase and decrease being a function of the // congestion window. @@ -1004,6 +1005,9 @@ // we are in slowstart for sure if cwnd < ssthresh if (cwnd_ < ssthresh_) slowstart = 1; + // we are in slow start - need to trace this event (TTI_LAB) + trace_event("SLOW_START"); //TTI_LAB + if (precision_reduce_) { halfwin = windowd() / 2; if (wnd_option_ == 6) { diff -Naurb ns-allinone-2.1b9a/ns-2.1b9a/tcp/tcp.h ns-allinone-2.1b9a_modif/ns-2.1b9a/tcp/tcp.h --- ns-allinone-2.1b9a/ns-2.1b9a/tcp/tcp.h 2002-10-20 00:41:37.000000000 +0200 +++ ns-allinone-2.1b9a_modif/ns-2.1b9a/tcp/tcp.h 2004-02-04 23:02:18.000000000 +0100 @@ -56,6 +56,7 @@ int tcp_flags_; /* TCP flags for FullTcp */ int last_rtt_; /* more recent RTT measurement in ms, */ /* for statistics only */ + double mywind_;// (TTI_LAB) static int offset_; // offset for this header inline static int& offset() { return offset_; } @@ -75,6 +76,7 @@ int& ackno() { return (ackno_); } int& flags() { return (tcp_flags_); } int& last_rtt() { return (last_rtt_); } + double& mywind(){ return (mywind_); }// (TTI_LAB) }; /* these are used to mark packets as to why we xmitted them */ @@ -158,6 +160,8 @@ void trace(TracedVar* v); virtual void advanceby(int delta); + double wnd() {return (double)cwnd_;} // (TTI_LAB) + protected: virtual int window(); virtual double windowd();