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

marker.cc

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2000-2002, by the Rector and Board of Visitors of the 
00003  * University of Virginia.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, 
00007  * with or without modification, are permitted provided 
00008  * that the following conditions are met:
00009  *
00010  * Redistributions of source code must retain the above 
00011  * copyright notice, this list of conditions and the following 
00012  * disclaimer. 
00013  *
00014  * Redistributions in binary form must reproduce the above 
00015  * copyright notice, this list of conditions and the following 
00016  * disclaimer in the documentation and/or other materials provided 
00017  * with the distribution. 
00018  *
00019  * Neither the name of the University of Virginia nor the names 
00020  * of its contributors may be used to endorse or promote products 
00021  * derived from this software without specific prior written 
00022  * permission. 
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
00025  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
00026  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00027  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00028  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 
00029  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
00030  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00031  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
00032  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 
00033  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00034  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
00035  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
00036  * THE POSSIBILITY OF SUCH DAMAGE.
00037  */
00038 /*
00039  *                                                                     
00040  * Marker module for JoBS (and WTP).
00041  *                                                                     
00042  * Authors: Constantinos Dovrolis <dovrolis@mail.eecis.udel.edu>, 
00043  *          Nicolas Christin <nicolas@cs.virginia.edu>, 2000-2002       
00044  *                                                                    
00045  * $Id: marker.cc,v 1.1 2003/02/02 22:18:22 xuanc Exp $
00046  */
00047 
00048 #include <string.h>
00049 #include <queue.h>
00050 #include "random.h"
00051 #include "marker.h"
00052 
00053 static class MarkerClass : public TclClass {
00054  public:
00055         MarkerClass() : TclClass("Queue/Marker") {}
00056         TclObject* create(int, const char*const*) {
00057                 return (new Marker);
00058         }
00059 } class_marker;
00060 
00061 
00062 
00063 Marker::Marker() {
00064         q_ = new PacketQueue; 
00065         for (int i=0; i<=NO_CLASSES; i++) marker_arrvs_[i]=0;
00066         // How can we bind arrays between cc and tcl????
00067         if (NO_CLASSES!=4) {
00068                 printf("Change Marker's code!!!\n\n");
00069                 abort();
00070         } 
00071         bind("marker_arrvs1_",  &(marker_arrvs_[1]));
00072         bind("marker_arrvs2_",  &(marker_arrvs_[2]));
00073         bind("marker_arrvs3_",  &(marker_arrvs_[3]));
00074         bind("marker_arrvs4_",  &(marker_arrvs_[4]));
00075         
00076         // Some initial values for the random marking fractions
00077         marker_frc_[0]=0.0; // class-0 is not used
00078         marker_frc_[1]=0.4; 
00079         marker_frc_[2]=0.7;
00080         marker_frc_[3]=0.9; 
00081         marker_frc_[4]=1.0;
00082 }
00083 
00084 
00085 
00086 int Marker::command(int argc, const char*const* argv) {
00087         if (argc == 3) {
00088                 if (!strcmp(argv[1], "marker_type")) {
00089                         marker_type_ = atoi(argv[2]);   
00090                         if ((marker_type_ != DETERM) && (marker_type_ != STATIS)) {
00091                                 printf("Wrong Marker Type\n");
00092                                 abort();
00093                         }
00094                         return (TCL_OK);
00095                 }
00096                 if (!strcmp(argv[1], "marker_class")) {
00097                         marker_class_ = atoi(argv[2]);  
00098                         if (marker_class_<1 || marker_class_>NO_CLASSES) {
00099                                 printf("Wrong Marker Class:%d\n", marker_class_);
00100                                 abort();
00101                         }
00102                         return (TCL_OK);
00103                 }
00104                 if (!strcmp(argv[1], "init-seed")) {
00105                         rn_seed_ = atoi(argv[2]);       
00106                         Random::seed(rn_seed_);
00107                         srand48((long)(rn_seed_));
00108                         return (TCL_OK);
00109                 }
00110         }
00111         if (argc == NO_CLASSES+2) {
00112                 if (!strcmp(argv[1], "marker_frc")) {
00113                         double sum = 0.0;
00114                         for (int i=1; i<=NO_CLASSES; i++) {
00115                                 marker_frc_[i] = sum + atof(argv[1+i]); 
00116                                 sum = marker_frc_[i];
00117                                 // printf("Fraction of class-%d traffic: %.3f\n", 
00118                                 //      i, marker_frc_[i]-marker_frc_[i-1]);
00119                         }
00120                         if (sum >  1.0) {
00121                            printf("Class marking thresholds should add to 1.0 \n");
00122                            abort();
00123                         } 
00124                         return (TCL_OK);
00125                 }
00126         }
00127         return Queue::command(argc, argv);
00128 }
00129 
00130 
00131 
00132 void Marker::enque(Packet* p) {
00133         hdr_ip*   iph = hdr_ip::access(p);
00134         hdr_cmn* cm_h = hdr_cmn::access(p);
00135         
00136         // Timestamp the packet's arrival in a header field
00137         // used for measuring the e2e delay of the packet
00138         // (for monitoring purposes)
00139         double  cur_time  = Scheduler::instance().clock();
00140         cm_h->ts_arr_ = cur_time;
00141 
00142         if (marker_type_ == DETERM) {
00143                 // Mark with fixed class 
00144                 iph->prio_ = marker_class_; 
00145         } else { 
00146                 // (marker_type_ == STATIS) 
00147                 // Determine probabilistically the class of this packet
00148                 double rn = drand48(); 
00149                 int i=0;
00150                 do i++; while (rn >= marker_frc_[i]);
00151                 iph->prio_ = i; 
00152         }
00153 
00154 
00155         // Count the packets arrived in this class
00156         marker_arrvs_[iph->prio_] += 1.;
00157 
00158         q_->enque(p);
00159         if (q_->length() >= qlim_) {
00160                 q_->remove(p);
00161                 drop(p);
00162                 printf("Packet drops in Marker of type:%d\n", marker_type_);
00163         }
00164 }
00165 
00166 // Nothing interesting here
00167 Packet* Marker::deque() {
00168         return q_->deque();
00169 }

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