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

delay.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1996-1997 The Regents of the University of California.
00004  * All rights reserved.
00005  * 
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *      This product includes software developed by the Network Research
00017  *      Group at Lawrence Berkeley National Laboratory.
00018  * 4. Neither the name of the University nor of the Laboratory may be used
00019  *    to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  * 
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  */
00034 
00035 #ifndef lint
00036 static const char rcsid[] =
00037     "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/link/delay.cc,v 1.26 1999/09/09 03:22:36 salehi Exp $ (LBL)";
00038 #endif
00039 
00040 #include "delay.h"
00041 #include "mcast_ctrl.h"
00042 #include "ctrMcast.h"
00043 
00044 static class LinkDelayClass : public TclClass {
00045 public:
00046         LinkDelayClass() : TclClass("DelayLink") {}
00047         TclObject* create(int /* argc */, const char*const* /* argv */) {
00048                 return (new LinkDelay);
00049         }
00050 } class_delay_link;
00051 
00052 LinkDelay::LinkDelay() : dynamic_(0), itq_(0)
00053 {
00054         bind_bw("bandwidth_", &bandwidth_);
00055         bind_time("delay_", &delay_);
00056 }
00057 
00058 int LinkDelay::command(int argc, const char*const* argv)
00059 {
00060         if (argc == 2) {
00061                 if (strcmp(argv[1], "isDynamic") == 0) {
00062                         dynamic_ = 1;
00063                         itq_ = new PacketQueue();
00064                         return TCL_OK;
00065                 }
00066         } else if (argc == 6) {
00067                 if (strcmp(argv[1], "pktintran") == 0) {
00068                         int src = atoi(argv[2]);
00069                         int grp = atoi(argv[3]);
00070                         int from = atoi(argv[4]);
00071                         int to = atoi(argv[5]);
00072                         pktintran (src, grp);
00073                         Tcl::instance().evalf("%s puttrace %d %d %d %d %d %d %d %d", name(), total_[0], total_[1], total_[2], total_[3], src, grp, from, to);
00074                         return TCL_OK;
00075                 }
00076         }
00077 
00078         return Connector::command(argc, argv);
00079 }
00080 
00081 void LinkDelay::recv(Packet* p, Handler* h)
00082 {
00083         double txt = txtime(p);
00084         Scheduler& s = Scheduler::instance();
00085         if (dynamic_) {
00086                 Event* e = (Event*)p;
00087                 e->time_= txt + delay_;
00088                 itq_->enque(p); // for convinience, use a queue to store packets in transit
00089                 s.schedule(this, p, txt + delay_);
00090         } else {
00091                 s.schedule(target_, p, txt + delay_);
00092         }
00093         s.schedule(h, &intr_, txt);
00094 }
00095 
00096 void LinkDelay::send(Packet* p, Handler*)
00097 {
00098         target_->recv(p, (Handler*) NULL);
00099 }
00100 
00101 void LinkDelay::reset()
00102 {
00103         Scheduler& s= Scheduler::instance();
00104 
00105         if (itq_ && itq_->length()) {
00106                 Packet *np;
00107                 // walk through packets currently in transit and kill 'em
00108                 while ((np = itq_->deque()) != 0) {
00109                         s.cancel(np);
00110                         drop(np);
00111                 }
00112         }
00113 }
00114 
00115 void LinkDelay::handle(Event* e)
00116 {
00117         Packet *p = itq_->deque();
00118         assert(p->time_ == e->time_);
00119         send(p, (Handler*) NULL);
00120 }
00121 
00122 void LinkDelay::pktintran(int src, int group)
00123 {
00124         int reg = 1;
00125         int prune = 30;
00126         int graft = 31;
00127         int data = 0;
00128         for (int i=0; i<4; i++) {
00129                 total_[i] = 0;
00130         }
00131 
00132         if (! dynamic_)
00133                 return;
00134 
00135         int len = itq_->length();
00136         while (len) {
00137                 len--;
00138                 Packet* p = itq_->lookup(len);
00139                 hdr_ip* iph = hdr_ip::access(p);
00140                 if (iph->flowid() == prune) {
00141                         if (iph->saddr() == src && iph->daddr() == group) {
00142                                 total_[0]++;
00143                         }
00144                 } else if (iph->flowid() == graft) {
00145                         if (iph->saddr() == src && iph->daddr() == group) {
00146                                 total_[1]++;
00147                         }
00148                 } else if (iph->flowid() == reg) {
00149                         hdr_CtrMcast* ch = hdr_CtrMcast::access(p);
00150                         if (ch->src() == src+1 && ch->group() == group) {
00151                                 total_[2]++;
00152                         }
00153                 } else if (iph->flowid() == data) {
00154                         if (iph->saddr() == src+1 && iph->daddr() == group) {
00155                                 total_[3]++;
00156                         }
00157                 }
00158         }
00159         //printf ("%f %d %d %d %d\n", Scheduler::instance().clock(), total_[0], total_[1], total_[2],total_[3]);
00160 }

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