replicator.cc

Go to the documentation of this file.
00001 
00002 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00003 /*
00004  * Copyright (c) 1996 Regents of the University of California.
00005  * All rights reserved.
00006  * 
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  * 3. All advertising materials mentioning features or use of this software
00016  *    must display the following acknowledgement:
00017  *  This product includes software developed by the MASH Research
00018  *  Group at the University of California Berkeley.
00019  * 4. Neither the name of the University nor of the Research Group may be
00020  *    used to endorse or promote products derived from this software without
00021  *    specific prior written permission.
00022  * 
00023  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00024  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00027  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00028  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00029  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00032  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00033  * SUCH DAMAGE.
00034  */
00035 
00036 #ifndef lint
00037 static const char rcsid[] =
00038     "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/mcast/replicator.cc,v 1.21 2000/12/20 10:12:48 alefiyah Exp $";
00039 #endif
00040 
00041 #include "classifier.h"
00042 #include "packet.h"
00043 #include "ip.h"
00044 
00045 /*
00046  * A replicator is not really a packet classifier but
00047  * we simply find convenience in leveraging its slot table.
00048  * (this object used to implement fan-out on a multicast
00049  * router as well as broadcast LANs)
00050  */
00051 class Replicator : public Classifier {
00052 public:
00053     Replicator();
00054     void recv(Packet*, Handler* h = 0);
00055     virtual int classify(Packet*) {/*NOTREACHED*/ return -1;};
00056 protected:
00057     virtual int command(int argc, const char*const* argv);
00058     int ignore_;
00059     int direction_;
00060 };
00061 
00062 static class ReplicatorClass : public TclClass {
00063 public:
00064     ReplicatorClass() : TclClass("Classifier/Replicator") {}
00065     TclObject* create(int, const char*const*) {
00066         return (new Replicator());
00067     }
00068 } class_replicator;
00069 
00070 Replicator::Replicator() : ignore_(0),direction_(0)
00071 {
00072     bind("ignore_", &ignore_);
00073     bind_bool("direction_",&direction_);
00074 }
00075 
00076 void Replicator::recv(Packet* p, Handler*)
00077 {
00078     hdr_ip* iph = hdr_ip::access(p);
00079     hdr_cmn* ch = hdr_cmn::access(p);
00080     if (maxslot_ < 0) {
00081         if (!ignore_) 
00082             Tcl::instance().evalf("%s drop %ld %ld %d", name(), 
00083                 iph->saddr(), iph->daddr(), ch->iface());
00084         Packet::free(p);
00085         return;
00086     }
00087     
00088     //If the direction of the packet is DOWN, 
00089     // now that is has reached the end of the stack 
00090     // change the direction to UP
00091     if(direction_){
00092         if( HDR_CMN(p)->direction() == hdr_cmn::DOWN){
00093             ch->direction() = hdr_cmn::UP; // Up the stack 
00094         }
00095     }
00096     for (int i = 0; i < maxslot_; ++i) {
00097         NsObject* o = slot_[i];
00098         if (o != 0)
00099             o->recv(p->copy());
00100     }
00101     /* we know that maxslot is non-null */
00102     slot_[maxslot_]->recv(p);
00103 }
00104 
00105 int Replicator::command(int argc, const char*const* argv)
00106 {
00107     Tcl& tcl = Tcl::instance();
00108     if (argc == 2) {
00109         /*
00110          * $replicator slot
00111          */
00112         if (strcmp(argv[1], "slots") == 0) {
00113             if (maxslot_ < 0) {
00114                 tcl.result("");
00115                 return (TCL_OK);
00116             }
00117             for (int i = 0; i <= maxslot_; i++) {
00118                 if (slot_[i] == 0) 
00119                     continue;
00120                 tcl.resultf("%s %s", tcl.result(),
00121                         slot_[i]->name());
00122             }
00123             return (TCL_OK);
00124         }
00125         
00126     }
00127     return Classifier::command(argc, argv);
00128 }
00129 
00130 
00131 
00132 
00133 

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