⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dspolicy.cc.svn-base

📁 diff serve for ns-2, work for version 2.29
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
/* Copyright (C) 2001-2006  Sergio Andreozzi * * This file is part of DiffServ4NS, a set of improvements to * the Network Simulator 2 for DiffServ simulations. * * Project Homepage: http://diffserv4ns.sourceforge.net/ *  * DiffServ4NS is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * DiffServ4NS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with DiffServ4NS; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA * GNU License: http://www.gnu.org/licenses/gpl.txt *  * The above copyright applies to the following changes and additions to the official * NS2 (http://nsnam.cvs.sourceforge.net/nsnam/ns-2/): * *  - marking: possibility to define mark rules based on source node,  *             destination node, transport protocol type and application type *  - new schedulers: WFQ, WF2Q+, SCFQ, SFQ, LLQ *  - new policy: possibility to define a DSCP based rate limiter *  - new monitoring possibilities: *     - For UDP-based traffic *        + Average, instantaneous, minimum and frequency distributed OWD *        + Average, instantaneous, minimum and frequency distributed IPDV *     - For TCP-based traffic *        + TCP Goodput on a DSCP basis *        + TCP Round-Trip Time on a DSCP basis, both instantaneous value  *          and frequency distribution *        + TCP Window Size on a DSCP basis, both instantaneous value  *          and frequency distribution *     - per-hop parameters: *        + Instantaneous and average queue length on a queue basis  *          or on a queue and drop precedence level basis *        + Maximum burstiness for queue 0 *        + Departure rate on a queue basis or on a queue and drop level  *          precedence basis *        + Received packets, transmitted packets, dropped packets due to droppers  *          and dropped packets due to buffer overflow,  *          all on a DSCP basis and for both absolute and percentage values * ***************************************************************************************  *//* * Copyright (c) 2000 Nortel Networks * All rights reserved. *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *      This product includes software developed by Nortel Networks. * 4. The name of the Nortel Networks may not be used *    to endorse or promote products derived from this software without *    specific prior written permission. *  * THIS SOFTWARE IS PROVIDED BY NORTEL AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL NORTEL OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * Developed by: Farhan Shallwani, Jeremy Ethridge *               Peter Pieda, and Mandeep Baines * Maintainer: Peter Pieda <ppieda@nortelnetworks.com> *//*  *  Integrated into ns main distribution and reorganized by  *  Xuan Chen (xuanc@isi.edu). The main changes are: * *  1. Defined two seperated classes, PolicyClassifier and Policy, to handle  *     the work done by class Policy before. *     Class PolicyClassifier now only keeps states for each flow and pointers *     to certain policies.  *     The policies perform the diffserv related jobs as described *     below. (eg, traffic metering and packet marking.) *     class Policy functions like the class Classifer. * *  2. Created a general supper class Policy so that new policy can be added *     by just creating a subclass of Policy. Examples are given (eg,  *     DumbPolicy) to help people trying to add their own new policies. * *  TODO: *  1. implement the multiple policy support by applying the idea of  *     multi-policy. * */#include "dsPolicy.h"#include "packet.h"#include "tcp.h"#include "random.h"// The definition of class PolicyClassifier.//Constructor.PolicyClassifier::PolicyClassifier() {  int i;  policyTableSize = 0;  policerTableSize = 0;  for (i = 0; i < MAX_POLICIES; i++)     policy_pool[i] = NULL;}/*-----------------------------------------------------------------------------void addPolicyEntry()    Adds an entry to policyTable according to the arguments in argv.  A sourceand destination node ID must be specified in argv, followed by a policy typeand policy-specific parameters.  Supported policies and their parametersare:TSW2CM        InitialCodePoint  CIRTSW3CM        InitialCodePoint  CIR  PIRTokenBucket   InitialCodePoint  CIR  CBSsrTCM         InitialCodePoint  CIR  CBS  EBStrTCM         InitialCodePoint  CIR  CBS  PIR  PBS    No error-checking is performed on the parameters.  CIR and PIR should bespecified in bits per second; CBS, EBS, and PBS should be specified in bytes.    If the Policy Table is full, this method prints an error message.-----------------------------------------------------------------------------*/void PolicyClassifier::addPolicyEntry(int argc, const char*const* argv) {  if (policyTableSize == MAX_POLICIES)    printf("ERROR: Policy Table size limit exceeded.\n");  else {    policyTable[policyTableSize].codePt = (int)strtod(argv[2],NULL);    policyTable[policyTableSize].arrivalTime = 0;    policyTable[policyTableSize].winLen = 1.0;        if (strcmp(argv[3], "Dumb") == 0) {      if(!policy_pool[DUMB])	policy_pool[DUMB] = new DumbPolicy;      policyTable[policyTableSize].policy_index = DUMB;         policyTable[policyTableSize].policer = dumbPolicer;      policyTable[policyTableSize].meter = dumbMeter;    } else if (strcmp(argv[3], "TSW2CM") == 0) {      if(!policy_pool[TSW2CM])	policy_pool[TSW2CM] = new TSW2CMPolicy;      policyTable[policyTableSize].policy_index = TSW2CM;         policyTable[policyTableSize].policer = TSW2CMPolicer;      policyTable[policyTableSize].meter = tswTagger;      policyTable[policyTableSize].cir =	policyTable[policyTableSize].avgRate = (double) atof(argv[4]) / 8.0;      if (argc == 8) policyTable[policyTableSize].winLen = (double) atof(argv[5]);/* mb */    } else if (strcmp(argv[3], "TSW3CM") == 0) {      if(!policy_pool[TSW3CM])	policy_pool[TSW3CM] = new TSW3CMPolicy;      policyTable[policyTableSize].policy_index = TSW3CM;         policyTable[policyTableSize].policer = TSW3CMPolicer;      policyTable[policyTableSize].meter = tswTagger;      policyTable[policyTableSize].cir =	policyTable[policyTableSize].avgRate = (double) atof(argv[4]) / 8.0;      policyTable[policyTableSize].pir = (double) atof(argv[5]) / 8.0;    } else if (strcmp(argv[3], "TokenBucket") == 0) {      if(!policy_pool[TB])	policy_pool[TB] = (Policy *) new TBPolicy;      policyTable[policyTableSize].policy_index = TB;         policyTable[policyTableSize].policer = tokenBucketPolicer;      policyTable[policyTableSize].meter = tokenBucketMeter;            policyTable[policyTableSize].cir =	policyTable[policyTableSize].avgRate = (double) atof(argv[4])/8.0;      policyTable[policyTableSize].cbs =	policyTable[policyTableSize].cBucket = (double) atof(argv[5]);    } else if (strcmp(argv[3], "srTCM") == 0) {      if(!policy_pool[SRTCM])	policy_pool[SRTCM] = new SRTCMPolicy;      policyTable[policyTableSize].policy_index = SRTCM;         policyTable[policyTableSize].policer = srTCMPolicer;      policyTable[policyTableSize].meter = srTCMMeter;            policyTable[policyTableSize].cir =	policyTable[policyTableSize].avgRate = (double) atof(argv[4]) / 8.0;      policyTable[policyTableSize].cbs =	policyTable[policyTableSize].cBucket = (double) atof(argv[5]);      policyTable[policyTableSize].ebs =	policyTable[policyTableSize].eBucket = (double) atof(argv[6]);    } else if (strcmp(argv[3], "trTCM") == 0) {      if(!policy_pool[TRTCM])	policy_pool[TRTCM] = new TRTCMPolicy;      policyTable[policyTableSize].policy_index = TRTCM;        policyTable[policyTableSize].policer = trTCMPolicer;      policyTable[policyTableSize].meter = trTCMMeter;            policyTable[policyTableSize].cir =	policyTable[policyTableSize].avgRate = (double) atof(argv[4]) / 8.0;      policyTable[policyTableSize].cbs =	policyTable[policyTableSize].cBucket = (double) atof(argv[5]);      policyTable[policyTableSize].pir = (double) atof(argv[6]) / 8.0;      policyTable[policyTableSize].pbs =	policyTable[policyTableSize].pBucket = (double) atof(argv[7]);    } else if (strcmp(argv[3], "FW") == 0) {      if(!policy_pool[FW])	policy_pool[FW] = new FWPolicy;      policyTable[policyTableSize].policy_index = FW;      policyTable[policyTableSize].policer = FWPolicer;      policyTable[policyTableSize].meter = fwTagger;      // Use cir as the transmission size threshold for the moment.      policyTable[policyTableSize].cir = (int)strtod(argv[4], NULL);    } else {      printf("No applicable policy specified, exit!!!\n");      exit(-1);    }    policyTableSize++;  }}/*-----------------------------------------------------------------------------policyTableEntry* PolicyClassifier::getPolicyTableEntry(long source, long dest)Pre: policyTable holds exactly one entry for the specified source-dest pair.Post: Finds the policyTable array that matches the specified source-dest pair.Returns: On success, returns a pointer to the corresponding policyTableEntry;  on failure, returns NULL.Note: the source-destination pair could be one-any or any-any (xuanc)-----------------------------------------------------------------------------*/policyTableEntry* PolicyClassifier::getPolicyTableEntry(int codePt) {  for (int i = 0; i <= policyTableSize; i++) {    if (policyTable[i].codePt==codePt)	return(&policyTable[i]);    }  printf("ERROR: No Policy Table entry found for DSCP %d\n", codePt);  printPolicyTable();  return(NULL);}/*-----------------------------------------------------------------------------void addPolicerEntry(int argc, const char*const* argv)Pre: argv contains a valid command line for adding a policer entry.Post: Adds an entry to policerTable according to the arguments in argv.  No  error-checking is done on the arguments.  A policer type should be specified,  consisting of one of the names {TSW2CM, TSW3CM, TokenBucket,  srTCM, trTCM}, followed by an initial code point.  Next should be an  out-of-profile code point for policers with two-rate markers; or a yellow and  a red code point for policers with three drop precedences.      If policerTable is full, an error message is printed.-----------------------------------------------------------------------------*/void PolicyClassifier::addPolicerEntry(int argc, const char*const* argv) {  //int cur_policy;  if (policerTableSize == MAX_CP)    printf("ERROR: Policer Table size limit exceeded.\n");  else {    if (strcmp(argv[2], "Dumb") == 0) {      if(!policy_pool[DUMB])	policy_pool[DUMB] = new DumbPolicy;      policerTable[policerTableSize].policer = dumbPolicer;            policerTable[policerTableSize].policy_index = DUMB;          } else if (strcmp(argv[2], "TSW2CM") == 0) {      if(!policy_pool[TSW2CM])	policy_pool[TSW2CM] = new TSW2CMPolicy;      policerTable[policerTableSize].policer = TSW2CMPolicer;      policerTable[policerTableSize].policy_index = TSW2CM;          } else if (strcmp(argv[2], "TSW3CM") == 0) {      if(!policy_pool[TSW3CM])	policy_pool[TSW3CM] = new TSW3CMPolicy;      policerTable[policerTableSize].policer = TSW3CMPolicer;      policerTable[policerTableSize].policy_index = TSW3CM;          } else if (strcmp(argv[2], "TokenBucket") == 0) {      if(!policy_pool[TB])	policy_pool[TB] = new TBPolicy;      policerTable[policerTableSize].policer = tokenBucketPolicer;      policerTable[policerTableSize].policy_index = TB;          } else if (strcmp(argv[2], "srTCM") == 0) {      if(!policy_pool[SRTCM])	policy_pool[SRTCM] = new SRTCMPolicy;      policerTable[policerTableSize].policer = srTCMPolicer;      policerTable[policerTableSize].policy_index = SRTCM;          } else if (strcmp(argv[2], "trTCM") == 0){      if(!policy_pool[TRTCM])	policy_pool[TRTCM] = new TRTCMPolicy;      policerTable[policerTableSize].policer = trTCMPolicer;      policerTable[policerTableSize].policy_index = TRTCM;          } else if (strcmp(argv[2], "FW") == 0) {      if(!policy_pool[FW])	policy_pool[FW] = new FWPolicy;      policerTable[policerTableSize].policer = FWPolicer;      policerTable[policerTableSize].policy_index = FW;          } else {      printf("No applicable policer specified, exit!!!\n");      exit(-1);    }  };   policerTable[policerTableSize].initialCodePt = (int)strtod(argv[3], NULL);  //printf("Policer: %s %s \n", argv[2], argv[3]);  if (argc == 5)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -