00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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
00047
00048
00049
00050
00051 class Replicator : public Classifier {
00052 public:
00053 Replicator();
00054 void recv(Packet*, Handler* h = 0);
00055 virtual int classify(Packet*) { 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
00089
00090
00091 if(direction_){
00092 if( HDR_CMN(p)->direction() == hdr_cmn::DOWN){
00093 ch->direction() = hdr_cmn::UP;
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
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
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