dsPolicy.h
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:7k
源码类别:

通讯编程

开发平台:

Visual C++

  1. /*
  2.  * Copyright (c) 2000 Nortel Networks
  3.  * All rights reserved.
  4.  * 
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *      This product includes software developed by Nortel Networks.
  16.  * 4. The name of the Nortel Networks may not be used
  17.  *    to endorse or promote products derived from this software without
  18.  *    specific prior written permission.
  19.  * 
  20.  * THIS SOFTWARE IS PROVIDED BY NORTEL AND CONTRIBUTORS ``AS IS'' AND
  21.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23.  * ARE DISCLAIMED.  IN NO EVENT SHALL NORTEL OR CONTRIBUTORS BE LIABLE
  24.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30.  * SUCH DAMAGE.
  31.  *
  32.  * Developed by: Farhan Shallwani, Jeremy Ethridge
  33.  *               Peter Pieda, and Mandeep Baines
  34.  * Maintainer: Peter Pieda <ppieda@nortelnetworks.com>
  35.  */
  36. #ifndef DS_POLICY_H
  37. #define DS_POLICY_H
  38. #include "dsred.h"
  39. #define ANY_HOST -1 // Add to enable point to multipoint policy
  40. #define FLOW_TIME_OUT 5.0      // The flow does not exist already.
  41. #define MAX_POLICIES 20 // Max. size of Policy Table.
  42. #define Null 0
  43. #define TSW2CM 1
  44. #define TSW3CM 2
  45. #define TB 3
  46. #define SRTCM 4
  47. #define TRTCM 5
  48. #define SFD 6
  49. #define EW 7
  50. #define DEWP 8
  51. enum policerType {nullPolicer, TSW2CMPolicer, TSW3CMPolicer, tokenBucketPolicer, srTCMPolicer, trTCMPolicer, SFDPolicer, EWPolicer, DEWPPolicer};
  52. enum meterType {nullMeter, tswTagger, tokenBucketMeter, srTCMMeter, trTCMMeter, sfdTagger, ewTagger, dewpTagger};
  53. class Policy;
  54. class TBPolicy;
  55. //struct policyTableEntry
  56. struct policyTableEntry {
  57.   nsaddr_t sourceNode, destNode; // Source-destination pair
  58.   int policy_index;                     // Index to the policy table.
  59.   policerType policer;
  60.   meterType meter;
  61.   int codePt;      // In-profile code point
  62.   double cir;      // Committed information rate (bytes per s) 
  63.   double cbs;      // Committed burst size (bytes)        
  64.   double cBucket;      // Current size of committed bucket (bytes)     
  65.   double ebs;      // Excess burst size (bytes)        
  66.   double eBucket;      // Current size of excess bucket (bytes)
  67.   double pir;      // Peak information rate (bytes per s)
  68.   double pbs;      // Peak burst size (bytes)
  69.   double pBucket;      // Current size of peak bucket (bytes)        
  70.   double arrivalTime;      // Arrival time of last packet in TSW metering
  71.   double avgRate, winLen;    // Used for TSW metering
  72. };
  73. // This struct specifies the elements of a policer table entry.
  74. struct policerTableEntry {
  75.   policerType policer;
  76.   int initialCodePt;
  77.   int downgrade1;
  78.   int downgrade2;
  79.   int policy_index;
  80. };
  81. // Class PolicyClassifier: keep the policy and polier tables.
  82. class PolicyClassifier : public TclObject {
  83.  public:
  84.   PolicyClassifier();
  85.   void addPolicyEntry(int argc, const char*const* argv);
  86.   void addPolicerEntry(int argc, const char*const* argv);
  87.   void updatePolicyRTT(int argc, const char*const* argv);
  88.   double getCBucket(const char*const* argv);
  89.   int mark(Packet *pkt);
  90.   // prints the policy tables
  91.   void printPolicyTable();
  92.   void printPolicerTable();
  93.   
  94.   // The table keeps pointers to the real policy
  95.   // Added to support multiple policy per interface.
  96.   Policy *policy_pool[MAX_POLICIES];
  97. protected:
  98.   // policy table and its pointer
  99.   policyTableEntry policyTable[MAX_POLICIES];
  100.   int policyTableSize;
  101.   // policer table and its pointer
  102.   policerTableEntry policerTable[MAX_CP];
  103.   int policerTableSize;
  104.   policyTableEntry* getPolicyTableEntry(nsaddr_t source, nsaddr_t dest);
  105.   policerTableEntry* getPolicerTableEntry(int policy_index, int oldCodePt);
  106. };
  107. // Below are actual policy classes.
  108. // Supper class Policy can't do anything useful.
  109. class Policy : public TclObject {
  110.  public:
  111.   Policy(){};
  112.   // Metering and policing methods:
  113.   // Have to initialize all the pointers before actually do anything with them!
  114.   // If not, ok with gcc but not cc!!! Nov 29, xuanc
  115.   virtual void applyMeter(policyTableEntry *policy, Packet *pkt) = 0;
  116.   virtual int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt) = 0;
  117. };
  118. // NullPolicy will do nothing. But it is also a good example to show 
  119. // how to add a new policy.
  120. class NullPolicy : public Policy {
  121.  public:
  122.   NullPolicy() : Policy(){};
  123.   // Metering and policing methods:
  124.   void applyMeter(policyTableEntry *policy, Packet *pkt);
  125.   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
  126. };
  127. class TSW2CMPolicy : public Policy {
  128.  public:
  129.   TSW2CMPolicy() : Policy(){};
  130.   // protected:
  131.   // Metering and policing methods:
  132.   void applyMeter(policyTableEntry *policy, Packet *pkt);
  133.   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
  134. };
  135. class TSW3CMPolicy : public Policy {
  136.  public:
  137.   TSW3CMPolicy() : Policy(){};
  138.   // Metering and policing methods:
  139.   void applyMeter(policyTableEntry *policy, Packet *pkt);
  140.   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
  141. };
  142. class TBPolicy : public Policy {
  143.  public:
  144.   TBPolicy() : Policy(){};
  145.   // protected:
  146.   // Metering and policing methods:
  147.   void applyMeter(policyTableEntry *policy, Packet *pkt);
  148.   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
  149. };
  150. class SRTCMPolicy : public Policy {
  151.  public:
  152.   SRTCMPolicy() : Policy(){};
  153.   // Metering and policing methods:
  154.   void applyMeter(policyTableEntry *policy, Packet *pkt);
  155.   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
  156. };
  157. class TRTCMPolicy : public Policy {
  158.  public:
  159.   TRTCMPolicy() : Policy(){};
  160.   // Metering and policing methods:
  161.   void applyMeter(policyTableEntry *policy, Packet *pkt);
  162.   int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
  163. };
  164. struct flow_entry {
  165.   int fid;
  166.   int src_id;
  167.   int dst_id;
  168.   double last_update;
  169.   int bytes_sent;
  170.   int count;
  171.   struct flow_entry *next;
  172. };
  173. struct flow_list {
  174.   struct flow_entry *head;
  175.   struct flow_entry *tail;
  176. };
  177. class SFDPolicy : public Policy {
  178. public:
  179. SFDPolicy();
  180. ~SFDPolicy();
  181. // Metering and policing methods:
  182. void applyMeter(policyTableEntry *policy, Packet *pkt);
  183. int applyPolicer(policyTableEntry *policy, policerTableEntry *policer, Packet *pkt);
  184. void printFlowTable();
  185.  protected:
  186.   // The table to keep the flow states.
  187.   struct flow_list flow_table;
  188. };
  189. #endif