• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/diffserv/dsPolicy.h

00001 /*
00002  * Copyright (c) 2000 Nortel Networks
00003  * All rights reserved.
00004  * 
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. All advertising materials mentioning features or use of this software
00014  *    must display the following acknowledgement:
00015  *      This product includes software developed by Nortel Networks.
00016  * 4. The name of the Nortel Networks may not be used
00017  *    to endorse or promote products derived from this software without
00018  *    specific prior written permission.
00019  * 
00020  * THIS SOFTWARE IS PROVIDED BY NORTEL AND CONTRIBUTORS ``AS IS'' AND
00021  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00023  * ARE DISCLAIMED.  IN NO EVENT SHALL NORTEL OR CONTRIBUTORS BE LIABLE
00024  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00025  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00026  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00027  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00028  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00029  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00030  * SUCH DAMAGE.
00031  *
00032  * Developed by: Farhan Shallwani, Jeremy Ethridge
00033  *               Peter Pieda, and Mandeep Baines
00034  * Maintainer: Peter Pieda <ppieda@nortelnetworks.com>
00035  */
00036 
00037 #ifndef DS_POLICY_H
00038 #define DS_POLICY_H
00039 #include "dsred.h"
00040 
00041 #define ANY_HOST -1             // Add to enable point to multipoint policy
00042 #define FLOW_TIME_OUT 5.0      // The flow does not exist already.
00043 #define MAX_POLICIES 20         // Max. size of Policy Table.
00044 
00045 #define Null 0
00046 #define TSW2CM 1
00047 #define TSW3CM 2
00048 #define TB 3
00049 #define SRTCM 4
00050 #define TRTCM 5
00051 #define SFD 6
00052 #define EW 7
00053 #define DEWP 8
00054 
00055 enum policerType {nullPolicer, TSW2CMPolicer, TSW3CMPolicer, tokenBucketPolicer, srTCMPolicer, trTCMPolicer, SFDPolicer, EWPolicer, DEWPPolicer};
00056 
00057 enum meterType {nullMeter, tswTagger, tokenBucketMeter, srTCMMeter, trTCMMeter, sfdTagger, ewTagger, dewpTagger};
00058 
00059 class Policy;
00060 class TBPolicy;
00061 
00062 //struct policyTableEntry
00063 struct policyTableEntry {
00064   nsaddr_t sourceNode, destNode;        // Source-destination pair
00065   int policy_index;                     // Index to the policy table.
00066   policerType policer;
00067   meterType meter;
00068   int codePt;                // In-profile code point
00069   double cir;                // Committed information rate (bytes per s) 
00070   double cbs;                // Committed burst size (bytes)                   
00071   double cBucket;            // Current size of committed bucket (bytes)     
00072   double ebs;                // Excess burst size (bytes)                      
00073   double eBucket;            // Current size of excess bucket (bytes)   
00074   double pir;                // Peak information rate (bytes per s)
00075   double pbs;                // Peak burst size (bytes)                 
00076   double pBucket;            // Current size of peak bucket (bytes)            
00077   double arrivalTime;        // Arrival time of last packet in TSW metering
00078   double avgRate, winLen;    // Used for TSW metering
00079 };
00080         
00081 
00082 // This struct specifies the elements of a policer table entry.
00083 struct policerTableEntry {
00084   policerType policer;
00085   int initialCodePt;
00086   int downgrade1;
00087   int downgrade2;
00088   int policy_index;
00089 };
00090 
00091 // Class PolicyClassifier: keep the policy and polier tables.
00092 class PolicyClassifier : public TclObject {
00093  public:
00094   PolicyClassifier();
00095   void addPolicyEntry(int argc, const char*const* argv);
00096   void addPolicerEntry(int argc, const char*const* argv);
00097   void updatePolicyRTT(int argc, const char*const* argv);
00098   double getCBucket(const char*const* argv);
00099   int mark(Packet *pkt);
00100 
00101   // prints the policy tables
00102   void printPolicyTable();              
00103   void printPolicerTable();
00104   
00105   // The table keeps pointers to the real policy
00106   // Added to support multiple policy per interface.
00107   Policy *policy_pool[MAX_POLICIES];
00108 
00109 protected:
00110   // policy table and its pointer
00111   policyTableEntry policyTable[MAX_POLICIES];
00112   int policyTableSize;
00113   // policer table and its pointer
00114   policerTableEntry policerTable[MAX_CP];
00115   int policerTableSize; 
00116 
00117   policyTableEntry* getPolicyTableEntry(nsaddr_t source, nsaddr_t dest);
00118   policerTableEntry* getPolicerTableEntry(int policy_index, int oldCodePt);
00119 };
00120 
00121 // Below are actual policy classes.
00122 // Supper class Policy can't do anything useful.
00123 class Policy : public TclObject {
00124  public:
00125   Policy(){};
00126 
00127   // Metering and policing methods:
00128   // Have to initialize all the pointers before actually do anything with them!
00129   // If not, ok with gcc but not cc!!! Nov 29, xuanc
00130   virtual void applyMeter(policyTableEntry *policy, Packet *pkt) = 0;
00131   virtual int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt) = 0;
00132 };
00133 
00134 // NullPolicy will do nothing. But it is also a good example to show 
00135 // how to add a new policy.
00136 class NullPolicy : public Policy {
00137  public:
00138   NullPolicy() : Policy(){};
00139 
00140   // Metering and policing methods:
00141   void applyMeter(policyTableEntry *policy, Packet *pkt);
00142   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
00143 };
00144 
00145 class TSW2CMPolicy : public Policy {
00146  public:
00147   TSW2CMPolicy() : Policy(){};
00148 
00149   // protected:
00150   // Metering and policing methods:
00151   void applyMeter(policyTableEntry *policy, Packet *pkt);
00152   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
00153 };
00154 
00155 class TSW3CMPolicy : public Policy {
00156  public:
00157   TSW3CMPolicy() : Policy(){};
00158 
00159   // Metering and policing methods:
00160   void applyMeter(policyTableEntry *policy, Packet *pkt);
00161   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
00162 };
00163 
00164 class TBPolicy : public Policy {
00165  public:
00166   TBPolicy() : Policy(){};
00167 
00168   // protected:
00169   // Metering and policing methods:
00170   void applyMeter(policyTableEntry *policy, Packet *pkt);
00171   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
00172 };
00173 
00174 class SRTCMPolicy : public Policy {
00175  public:
00176   SRTCMPolicy() : Policy(){};
00177 
00178   // Metering and policing methods:
00179   void applyMeter(policyTableEntry *policy, Packet *pkt);
00180   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
00181 };
00182 
00183 class TRTCMPolicy : public Policy {
00184  public:
00185   TRTCMPolicy() : Policy(){};
00186 
00187   // Metering and policing methods:
00188   void applyMeter(policyTableEntry *policy, Packet *pkt);
00189   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
00190 };
00191 
00192 struct flow_entry {
00193   int fid;
00194   int src_id;
00195   int dst_id;
00196   double last_update;
00197   int bytes_sent;
00198   int count;
00199   struct flow_entry *next;
00200 };
00201 
00202 struct flow_list {
00203   struct flow_entry *head;
00204   struct flow_entry *tail;
00205 };
00206 
00207 class SFDPolicy : public Policy {
00208 public:
00209 SFDPolicy();
00210 ~SFDPolicy();
00211 
00212 // Metering and policing methods:
00213 void applyMeter(policyTableEntry *policy, Packet *pkt);
00214 int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
00215 
00216 void printFlowTable();
00217 
00218  protected:
00219   // The table to keep the flow states.
00220   struct flow_list flow_table;
00221 };
00222 
00223 #endif

Generated on Tue Aug 10 2010 16:16:06 for ns-2.33 by  doxygen 1.7.1