demarker.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: demarker.cc,v 1.1 2003/02/02 22:18:22 xuanc Exp $
00046  */
00047 
00048 #include <string.h>
00049 #include <queue.h>
00050 #include "demarker.h"
00051 #include "tcp.h"
00052 
00053 static class DemarkerClass : public TclClass {
00054 public:
00055     DemarkerClass() : TclClass("Queue/Demarker") {}
00056     TclObject* create(int, const char*const*) {
00057         return (new Demarker);
00058     }
00059 } class_demarker;
00060 
00061 Demarker::Demarker() {
00062     q_ = new PacketQueue; 
00063   
00064     last_monitor_update_=0.0;
00065     monitoring_window_ = 0.1;
00066     
00067     for (int i=0; i<=NO_CLASSES; i++) {
00068         demarker_arrvs_[i]=0;
00069         arrived_Bits_[i] = 0;
00070     }
00071   // Binding arrays between cc and tcl still not supported by tclcl...
00072   if (NO_CLASSES != 4) {
00073     printf("Change Demarker's code!!!\n\n");
00074     abort();
00075   }
00076   bind("demarker_arrvs1_",    &(demarker_arrvs_[1]));
00077   bind("demarker_arrvs2_",    &(demarker_arrvs_[2]));
00078   bind("demarker_arrvs3_",    &(demarker_arrvs_[3]));
00079   bind("demarker_arrvs4_",    &(demarker_arrvs_[4]));
00080 }
00081 
00082 
00083 
00084 int Demarker::command(int argc, const char*const* argv) {
00085     if (argc == 3) {
00086         if (strcmp(argv[1], "trace-file") == 0) {
00087             file_name_ = new(char[500]);
00088             strcpy(file_name_,argv[2]);
00089             if (strcmp(file_name_,"null") != 0) {
00090                 demarker_type_ = VERBOSE;
00091                 for (int i=1; i<=NO_CLASSES; i++) {
00092                     char filename[500]; 
00093                     sprintf(filename,"%s.%d", file_name_,i);
00094                     if ((delay_tr_[i] = fopen(filename,"w"))==NULL) {
00095                         printf("Problem with opening the trace files\n");
00096                         abort();
00097                     }
00098                 }
00099             } else {
00100                 demarker_type_ = QUIET;
00101             }
00102             return (TCL_OK);
00103         } else if (strcmp(argv[1], "id") == 0) {
00104             link_id_ = (int)atof(argv[2]);
00105             return (TCL_OK);
00106         } 
00107     }
00108     return Queue::command(argc, argv);
00109 }
00110 
00111 
00112 
00113 void Demarker::enque(Packet* p) {
00114     q_->enque(p);
00115     if (q_->length() >= qlim_) {
00116         q_->remove(p);
00117         drop(p);
00118         printf("Packet drops in Demarker of type:%d\n", demarker_type_);
00119     }
00120 }
00121 
00122 
00123 
00124 Packet* Demarker::deque() {
00125   Packet* p= q_->deque();
00126   if (p==NULL) return p;
00127   
00128   hdr_ip*  iph = hdr_ip::access(p);
00129   hdr_cmn* cm_h = hdr_cmn::access(p);
00130   double  cur_time  = Scheduler::instance().clock();
00131 
00132   int cls = iph->prio_;
00133   if ((cls<1) || (cls>NO_CLASSES)) {
00134     printf("Wrong class type in Demarker-deque (S=%d, D=%d, FID=%d, Class=%d)\n",
00135        (int)(iph->src().addr_), (int)(iph->dst().addr_),
00136        iph->fid_, iph->prio_);
00137     
00138     fflush(stdout);
00139     abort();
00140   }
00141   demarker_arrvs_[cls] += 1.;
00142 
00143  
00144   if (demarker_type_ == VERBOSE) {
00145     // Write end-to-end delay of packet in per class trace file
00146     if (cur_time > START_STATISTICS) {
00147       double pack_del = cur_time - cm_h->ts_arr_;
00148       cm_h->ts_arr_=0;    // This stupid thing is required..
00149       // print arrival time and delay
00150       fprintf(delay_tr_[cls], "%.5f %.5f\n", 
00151           cur_time, pack_del);
00152     }    
00153  
00154     return p;
00155   }
00156   
00157   return p;
00158 }

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