dsEdge.cc

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 /*
00038  * Integrated into ns by Xuan Chen (xuanc@isi.edu) 
00039  * Add instance of policyClassifier.
00040  */
00041 
00042 #include "dsEdge.h"
00043 #include "ew.h"
00044 #include "dewp.h"
00045 #include "packet.h"
00046 #include "tcp.h"
00047 #include "random.h"
00048 
00049 
00050 /*------------------------------------------------------------------------------
00051 class edgeClass 
00052 ------------------------------------------------------------------------------*/
00053 static class edgeClass : public TclClass {
00054 public:
00055     edgeClass() : TclClass("Queue/dsRED/edge") {}
00056     TclObject* create(int, const char*const*) {
00057         return (new edgeQueue);
00058     }
00059 } class_edge;
00060 
00061 
00062 /*------------------------------------------------------------------------------
00063 edgeQueue() Constructor.
00064 ------------------------------------------------------------------------------*/
00065 edgeQueue::edgeQueue() {
00066   //  policy = NULL;
00067 }
00068 
00069 
00070 /*------------------------------------------------------------------------------
00071 void enque(Packet* pkt) 
00072 Post: The incoming packet pointed to by pkt is marked with an appropriate code
00073   point (as handled by the marking method) and enqueued in the physical and 
00074   virtual queue corresponding to that code point (as specified in the PHB 
00075   Table).
00076 Uses: Methods Policy::mark(), lookupPHBTable(), and redQueue::enque(). 
00077 ------------------------------------------------------------------------------*/
00078 void edgeQueue::enque(Packet* pkt) {
00079     int codePt;
00080 
00081     // Mark the packet with the specified priority:
00082     //printf("before ,mark\n");
00083     codePt = policy.mark(pkt);
00084     //  printf("after ,mark\n");
00085     dsREDQueue::enque(pkt);
00086 }
00087 
00088 
00089 /*------------------------------------------------------------------------------
00090 int command(int argc, const char*const* argv) 
00091     Commands from the ns file are interpreted through this interface.
00092 ------------------------------------------------------------------------------*/
00093 int edgeQueue::command(int argc, const char*const* argv) {
00094   if (strcmp(argv[1], "addPolicyEntry") == 0) {
00095     // Note: the definition of policy has changed.
00096     policy.addPolicyEntry(argc, argv);
00097     return(TCL_OK);
00098   };
00099 
00100   if (strcmp(argv[1], "addPolicerEntry") == 0) {
00101     // Note: the definition of policy has changed.
00102     policy.addPolicerEntry(argc, argv);
00103     return(TCL_OK);
00104   };
00105 
00106   if (strcmp(argv[1], "couple") == 0) {
00107   /*
00108     printf("%d ", argc);
00109     for (int i = 1; i < argc; i++) 
00110       printf("%d(%s) ", i, argv[i]);
00111     printf("\n");   
00112   */
00113 
00114     DEWPPolicy *ewp = (DEWPPolicy *)(policy.policy_pool[DEWP]);
00115 
00116     // Get the pointer to the queue to be coupled (in c++)
00117     //Tcl& tcl = Tcl::instance();
00118     edgeQueue *cq = (edgeQueue*) TclObject::lookup(argv[2]);
00119     DEWPPolicy *ewpc = (DEWPPolicy *)((cq->policy).policy_pool[DEWP]);
00120 
00121     ewp->couple(ewpc); 
00122 
00123     return(TCL_OK);
00124   };
00125 
00126   // couple the EW on request and response links
00127   if (strcmp(argv[1], "coupleEW") == 0) {
00128     //printf("%d ", argc);
00129     //for (int i = 1; i < argc; i++) 
00130     //printf("%d(%s) ", i, argv[i]);
00131     //printf("\n");   
00132 
00133     EWPolicy *ewp = (EWPolicy *)(policy.policy_pool[EW]);
00134 
00135     // Get the pointer to the queue to be coupled (in c++)
00136     //Tcl& tcl = Tcl::instance();
00137     edgeQueue *cq = (edgeQueue*) TclObject::lookup(argv[2]);
00138     EWPolicy *ewpc = (EWPolicy *)((cq->policy).policy_pool[EW]);
00139 
00140     // couple the EW detector 
00141     if (argc > 3)
00142       ewp->coupleEW(ewpc, atof(argv[3])); 
00143     else
00144       ewp->coupleEW(ewpc); 
00145 
00146     return(TCL_OK);
00147   };
00148 
00149   // Set a rate limitor
00150   if (strcmp(argv[1], "limit") == 0) {
00151     //printf("%d ", argc);
00152     //for (int i = 1; i < argc; i++) 
00153     //  printf("%d(%s) ", i, argv[i]);
00154     //printf("\n");
00155 
00156     EWPolicy *ewp = (EWPolicy *)(policy.policy_pool[EW]);
00157     
00158     // Packet rate limitor
00159     if (strcmp(argv[2], "P") == 0) {
00160       ewp->limitPr(atoi(argv[3]));
00161       return(TCL_OK);
00162     } 
00163 
00164     // bits rate limitor
00165     if (strcmp(argv[2], "B") == 0) {
00166       ewp->limitBr(atoi(argv[3]));
00167       return(TCL_OK);
00168     }
00169   };
00170 
00171   // Setup an EW detector on a link
00172   if (strcmp(argv[1], "detect") == 0) {
00173     //printf("%d ", argc);
00174     //for (int i = 1; i < argc; i++) 
00175     //  printf("%d(%s) ", i, argv[i]);
00176     //printf("\n");
00177 
00178     EWPolicy *ewp = (EWPolicy *)(policy.policy_pool[EW]);
00179     
00180     if (strcmp(argv[2], "P") == 0) {
00181       if (argc > 4)
00182     ewp->detectPr(atoi(argv[3]), atoi(argv[4]));
00183       else if (argc > 3)
00184     ewp->detectPr(atoi(argv[3]));
00185       else
00186     ewp->detectPr();
00187 
00188       return(TCL_OK);
00189     } 
00190 
00191     if (strcmp(argv[2], "B") == 0) {
00192       if (argc > 4)
00193     ewp->detectBr(atoi(argv[3]), atoi(argv[4]));
00194       else if (argc > 3)
00195     ewp->detectBr(atoi(argv[3]));
00196       else
00197     ewp->detectBr();
00198 
00199       return(TCL_OK);
00200     }
00201   };
00202 
00203   if (strcmp(argv[1], "getCBucket") == 0) {
00204     Tcl& tcl = Tcl::instance();
00205     tcl.resultf("%f", policy.getCBucket(argv));
00206     return(TCL_OK);
00207   }
00208   if (strcmp(argv[1], "printPolicyTable") == 0) {
00209     policy.printPolicyTable();
00210     return(TCL_OK);
00211   }
00212   if (strcmp(argv[1], "printPolicerTable") == 0) {
00213     policy.printPolicerTable();
00214     return(TCL_OK);
00215   }
00216   
00217   return(dsREDQueue::command(argc, argv));
00218 };

Generated on Tue Mar 6 16:47:44 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6