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 /* 00038 * dsred.h 00039 * 00040 * The Positions of dsREDQueue, edgeQueue, and coreQueue in the Object Hierarchy. 00041 * 00042 * This class, i.e. "dsREDQueue", is positioned in the class hierarchy as follows: 00043 * 00044 * Queue 00045 * | 00046 * dsREDQueue 00047 * 00048 * 00049 * This class stands for "Differentiated Services RED Queue". Since the 00050 * original RED does not support multiple parameters, and other functionality 00051 * needed by a RED gateway in a Diffserv architecture, this class was created to 00052 * support the desired functionality. This class is then inherited by two more 00053 * classes, moulding the old hierarchy as follows: 00054 * 00055 * 00056 * Queue 00057 * | 00058 * dsREDQueue 00059 * | | 00060 * edgeQueue coreQueue 00061 * 00062 * 00063 * These child classes correspond to the "edge" and "core" routers in a Diffserv 00064 * architecture. 00065 * 00066 */ 00067 00068 00069 #ifndef dsred_h 00070 #define dsred_h 00071 00072 #include "red.h" // need RED class specs (edp definition, for example) 00073 #include "queue.h" // need Queue class specs 00074 #include "dsredq.h" 00075 00076 00077 /* The dsRED class supports the creation of up to MAX_QUEUES physical queues at 00078 each network device, with up to MAX_PREC virtual queues in each queue. */ 00079 #define MAX_QUEUES 8// maximum number of physical RED queues 00080 #define MAX_PREC 3 // maximum number of virtual RED queues in one physical queue 00081 #define MAX_CP 40 // maximum number of code points in a simulation 00082 #define MEAN_PKT_SIZE 1000 // default mean packet size, in bytes, needed for RED calculations 00083 00084 enum schedModeType {schedModeRR, schedModeWRR, schedModeWIRR, schedModePRI}; 00085 00086 #define PKT_MARKED 3 00087 #define PKT_EDROPPED 2 00088 #define PKT_ENQUEUED 1 00089 #define PKT_DROPPED 0 00090 00091 00092 /*------------------------------------------------------------------------------ 00093 struct phbParam 00094 This struct is used to maintain entries for the PHB parameter table, used 00095 to map a code point to a physical queue-virtual queue pair. 00096 ------------------------------------------------------------------------------*/ 00097 struct phbParam { 00098 int codePt_; 00099 int queue_; // physical queue 00100 int prec_; // virtual queue (drop precedence) 00101 }; 00102 00103 struct statType { 00104 long drops; // per queue stats 00105 long edrops; 00106 long pkts; 00107 long valid_CP[MAX_CP]; // per CP stats 00108 long drops_CP[MAX_CP]; 00109 long edrops_CP[MAX_CP]; 00110 long pkts_CP[MAX_CP]; 00111 }; 00112 00113 00114 /*----------------------------------------------------------------------------- 00115 class dsREDQueue 00116 This class specifies the characteristics for a Diffserv RED router. 00117 -----------------------------------------------------------------------------*/ 00118 class dsREDQueue : public Queue { 00119 public: 00120 dsREDQueue(); 00121 int command(int argc, const char*const* argv); // interface to ns scripts 00122 00123 protected: 00124 redQueue redq_[MAX_QUEUES]; // the physical queues at the router 00125 NsObject* de_drop_; // drop_early target 00126 statType stats; // used for statistics gatherings 00127 int qToDq; // current queue to be dequeued in a round robin manner 00128 int numQueues_; // the number of physical queues at the router 00129 int numPrec; // the number of virtual queues in each physical queue 00130 phbParam phb_[MAX_CP]; // PHB table 00131 int phbEntries; // the current number of entries in the PHB table 00132 int ecn_; // used for ECN (Explicit Congestion Notification) 00133 LinkDelay* link_; // outgoing link 00134 int schedMode; // the Queue Scheduling mode 00135 00136 int queueWeight[MAX_QUEUES]; // A queue weight per queue 00137 double queueMaxRate[MAX_QUEUES]; // Maximum Rate for Priority Queueing 00138 double queueAvgRate[MAX_QUEUES]; // Average Rate for Priority Queueing 00139 double queueArrTime[MAX_QUEUES]; // Arrival Time for Priority Queueing 00140 int slicecount[MAX_QUEUES]; 00141 int pktcount[MAX_QUEUES]; 00142 int wirrTemp[MAX_QUEUES]; 00143 unsigned char wirrqDone[MAX_QUEUES]; 00144 int queuesDone; 00145 00146 void reset(); 00147 void edrop(Packet* p); // used so flowmonitor can monitor early drops 00148 void enque(Packet *pkt); // enques a packet 00149 Packet *deque(void); // deques a packet 00150 int getCodePt(Packet *p); // given a packet, extract the code point marking from its header field 00151 int selectQueueToDeque(); // round robin scheduling dequing algorithm 00152 void lookupPHBTable(int codePt, int* queue, int* prec); // looks up queue and prec numbers corresponding to a code point 00153 void addPHBEntry(int codePt, int queue, int prec); // edits phb entry in the table 00154 void setNumPrec(int curPrec); 00155 void setMREDMode(const char* mode, const char* queue); 00156 void printStats(); // print various stats 00157 double getStat(int argc, const char*const* argv); 00158 void printPHBTable(); // print the PHB table 00159 void setSchedularMode(const char* schedtype); // Sets the schedular mode 00160 00161 // Add a weigth to a WRR or WIRR queue 00162 void addQueueWeights(int queueNum, int weight); 00163 // Add a maxRate to a PRI queue 00164 void addQueueRate(int queueNum, int rate); 00165 00166 void printWRRcount(); // print various stats 00167 00168 // apply meter to calculate average rate of a PRI queue 00169 // Modified by xuanc(xuanc@isi.edu) Oct 18, 2001, 00170 // referring to the patch contributed by 00171 // Sergio Andreozzi <sergio.andreozzi@lut.fi> 00172 void applyTSWMeter(int q_id, int pkt_size); 00173 }; 00174 00175 #endif