Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

dsPolicy.h

Go to the documentation of this file.
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 DUMB 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 EWP 7
00053 
00054 enum policerType {dumbPolicer, TSW2CMPolicer, TSW3CMPolicer, tokenBucketPolicer, srTCMPolicer, trTCMPolicer, SFDPolicer, EWPolicer};
00055 
00056 enum meterType {dumbMeter, tswTagger, tokenBucketMeter, srTCMMeter, trTCMMeter, sfdTagger, ewTagger};
00057 
00058 class Policy;
00059 class TBPolicy;
00060 
00061 //struct policyTableEntry
00062 struct policyTableEntry {
00063   nsaddr_t sourceNode, destNode;        // Source-destination pair
00064   int policy_index;                     // Index to the policy table.
00065   policerType policer;
00066   meterType meter;
00067   int codePt;                // In-profile code point
00068   double cir;                // Committed information rate (bytes per s) 
00069   double cbs;                // Committed burst size (bytes)                   
00070   double cBucket;            // Current size of committed bucket (bytes)     
00071   double ebs;                // Excess burst size (bytes)                      
00072   double eBucket;            // Current size of excess bucket (bytes)   
00073   double pir;                // Peak information rate (bytes per s)
00074   double pbs;                // Peak burst size (bytes)                 
00075   double pBucket;            // Current size of peak bucket (bytes)            
00076   double arrivalTime;        // Arrival time of last packet in TSW metering
00077   double avgRate, winLen;    // Used for TSW metering
00078 };
00079         
00080 
00081 // This struct specifies the elements of a policer table entry.
00082 struct policerTableEntry {
00083   policerType policer;
00084   int initialCodePt;
00085   int downgrade1;
00086   int downgrade2;
00087   int policy_index;
00088 };
00089 
00090 // Class PolicyClassifier: keep the policy and polier tables.
00091 class PolicyClassifier : public TclObject {
00092  public:
00093   PolicyClassifier();
00094   void addPolicyEntry(int argc, const char*const* argv);
00095   void addPolicerEntry(int argc, const char*const* argv);
00096   void updatePolicyRTT(int argc, const char*const* argv);
00097   double getCBucket(const char*const* argv);
00098   int mark(Packet *pkt);
00099 
00100   // prints the policy tables
00101   void printPolicyTable();              
00102   void printPolicerTable();
00103   
00104   // The table keeps pointers to the real policy
00105   // Added to support multiple policy per interface.
00106   Policy *policy_pool[MAX_POLICIES];
00107 
00108 protected:
00109   // policy table and its pointer
00110   policyTableEntry policyTable[MAX_POLICIES];
00111   int policyTableSize;
00112   // policer table and its pointer
00113   policerTableEntry policerTable[MAX_CP];
00114   int policerTableSize; 
00115 
00116   policyTableEntry* getPolicyTableEntry(nsaddr_t source, nsaddr_t dest);
00117   policerTableEntry* getPolicerTableEntry(int policy_index, int oldCodePt);
00118 };
00119 
00120 // Below are actual policy classes.
00121 // Supper class Policy can't do anything useful.
00122 class Policy : public TclObject {
00123  public:
00124   Policy(){};
00125 
00126   // Metering and policing methods:
00127   // Have to initialize all the pointers before actually do anything with them!
00128   // If not, ok with gcc but not cc!!! Nov 29, xuanc
00129   virtual void applyMeter(policyTableEntry *policy, Packet *pkt) = 0;
00130   virtual int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt) = 0;
00131 };
00132 
00133 // DumbPolicy will do nothing, but is a good example to show how to add 
00134 // new policy.
00135 class DumbPolicy : public Policy {
00136  public:
00137   DumbPolicy() : Policy(){};
00138 
00139   // Metering and policing methods:
00140   void applyMeter(policyTableEntry *policy, Packet *pkt);
00141   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
00142 };
00143 
00144 class TSW2CMPolicy : public Policy {
00145  public:
00146   TSW2CMPolicy() : Policy(){};
00147 
00148   // protected:
00149   // Metering and policing methods:
00150   void applyMeter(policyTableEntry *policy, Packet *pkt);
00151   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
00152 };
00153 
00154 class TSW3CMPolicy : public Policy {
00155  public:
00156   TSW3CMPolicy() : Policy(){};
00157 
00158   // Metering and policing methods:
00159   void applyMeter(policyTableEntry *policy, Packet *pkt);
00160   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
00161 };
00162 
00163 class TBPolicy : public Policy {
00164  public:
00165   TBPolicy() : Policy(){};
00166 
00167   // protected:
00168   // Metering and policing methods:
00169   void applyMeter(policyTableEntry *policy, Packet *pkt);
00170   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
00171 };
00172 
00173 class SRTCMPolicy : public Policy {
00174  public:
00175   SRTCMPolicy() : Policy(){};
00176 
00177   // Metering and policing methods:
00178   void applyMeter(policyTableEntry *policy, Packet *pkt);
00179   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
00180 };
00181 
00182 class TRTCMPolicy : public Policy {
00183  public:
00184   TRTCMPolicy() : Policy(){};
00185 
00186   // Metering and policing methods:
00187   void applyMeter(policyTableEntry *policy, Packet *pkt);
00188   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
00189 };
00190 
00191 struct flow_entry {
00192   int fid;
00193   int src_id;
00194   int dst_id;
00195   double last_update;
00196   int bytes_sent;
00197   int count;
00198   struct flow_entry *next;
00199 };
00200 
00201 struct flow_list {
00202   struct flow_entry *head;
00203   struct flow_entry *tail;
00204 };
00205 
00206 class SFDPolicy : public Policy {
00207 public:
00208 SFDPolicy();
00209 ~SFDPolicy();
00210 
00211 // Metering and policing methods:
00212 void applyMeter(policyTableEntry *policy, Packet *pkt);
00213 int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
00214 
00215 void printFlowTable();
00216 
00217  protected:
00218   // The table to keep the flow states.
00219   struct flow_list flow_table;
00220 };
00221 
00222 #endif

Generated on Tue Apr 20 12:14:14 2004 for NS2.26SourcesOriginal by doxygen 1.3.3