diff -Naur ns.orig/ns-allinone-2.31/ns-2.31/common/packet.cc ns-allinone-2.31/ns-2.31/common/packet.cc --- ns.orig/ns-allinone-2.31/ns-2.31/common/packet.cc 2005-10-20 06:45:22.000000000 +0200 +++ ns-allinone-2.31/ns-2.31/common/packet.cc 2006-11-28 16:17:39.000000000 +0100 @@ -41,7 +41,21 @@ #include "flags.h" p_info packet_info; -char* p_info::name_[PT_NTYPE+1]; +char** p_info::name_; +unsigned int p_info::nPkt_ = 0; +PacketClassifier *p_info::pc_ = 0; + +int p_info::addPacket(char *name) +{ + if(!nPkt_) + initName(); + + int newID = nPkt_-1; + PT_NTYPE = nPkt_; + initName(); + name_[newID] = name; + return newID; +} int Packet::hdrlen_ = 0; // size of a packet's header Packet* Packet::free_; // free list diff -Naur ns.orig/ns-allinone-2.31/ns-2.31/common/packet.h ns-allinone-2.31/ns-2.31/common/packet.h --- ns.orig/ns-allinone-2.31/ns-2.31/common/packet.h 2006-02-22 14:32:23.000000000 +0100 +++ ns-allinone-2.31/ns-2.31/common/packet.h 2007-04-17 18:46:54.000000000 +0200 @@ -31,7 +31,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#) $Header: /cvsroot/nsnam/ns-2/common/packet.h,v 1.100 2006/02/22 13:32:23 mahrenho Exp $ (LBL) + * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/common/packet.h,v 1.98 2005/09/18 23:33:31 tomh Exp $ (LBL) */ #ifndef ns_packet_h @@ -72,111 +72,191 @@ /* --------------------------------------------------------------------*/ -enum packet_t { - PT_TCP, - PT_UDP, - PT_CBR, - PT_AUDIO, - PT_VIDEO, - PT_ACK, - PT_START, - PT_STOP, - PT_PRUNE, - PT_GRAFT, - PT_GRAFTACK, - PT_JOIN, - PT_ASSERT, - PT_MESSAGE, - PT_RTCP, - PT_RTP, - PT_RTPROTO_DV, - PT_CtrMcast_Encap, - PT_CtrMcast_Decap, - PT_SRM, +/* +Fede's modify 31/4/2006: I want to make the system more flexile +*/ +typedef unsigned int packet_t; + + +static const packet_t PT_TCP = 0; +static const packet_t PT_UDP = 1; +static const packet_t PT_CBR = 2; +static const packet_t PT_AUDIO = 3; +static const packet_t PT_VIDEO = 4; +static const packet_t PT_ACK = 5; +static const packet_t PT_START = 6; +static const packet_t PT_STOP = 7; +static const packet_t PT_PRUNE = 8; +static const packet_t PT_GRAFT = 9; +static const packet_t PT_GRAFTACK = 10; +static const packet_t PT_JOIN = 11; +static const packet_t PT_ASSERT = 12; +static const packet_t PT_MESSAGE = 13; +static const packet_t PT_RTCP = 14; +static const packet_t PT_RTP = 15; +static const packet_t PT_RTPROTO_DV = 16; +static const packet_t PT_CtrMcast_Encap = 17; +static const packet_t PT_CtrMcast_Decap = 18; +static const packet_t PT_SRM = 19; /* simple signalling messages */ - PT_REQUEST, - PT_ACCEPT, - PT_CONFIRM, - PT_TEARDOWN, - PT_LIVE, // packet from live network - PT_REJECT, - - PT_TELNET, // not needed: telnet use TCP - PT_FTP, - PT_PARETO, - PT_EXP, - PT_INVAL, - PT_HTTP, +static const packet_t PT_REQUEST = 20; +static const packet_t PT_ACCEPT = 21; +static const packet_t PT_CONFIRM = 22; +static const packet_t PT_TEARDOWN = 23; +static const packet_t PT_LIVE = 24; // packet from live network +static const packet_t PT_REJECT = 25; + +static const packet_t PT_TELNET = 26; // not needed: telnet use TCP +static const packet_t PT_FTP = 27; +static const packet_t PT_PARETO = 28; +static const packet_t PT_EXP = 29; +static const packet_t PT_INVAL = 30; +static const packet_t PT_HTTP = 31; /* new encapsulator */ - PT_ENCAPSULATED, - PT_MFTP, +static const packet_t PT_ENCAPSULATED = 32; +static const packet_t PT_MFTP = 33; /* CMU/Monarch's extnsions */ - PT_ARP, - PT_MAC, - PT_TORA, - PT_DSR, - PT_AODV, - PT_IMEP, +static const packet_t PT_ARP = 34; +static const packet_t PT_MAC = 35; +static const packet_t PT_TORA = 36; +static const packet_t PT_DSR = 37; +static const packet_t PT_AODV = 38; +static const packet_t PT_IMEP = 39; // RAP packets - PT_RAP_DATA, - PT_RAP_ACK, +static const packet_t PT_RAP_DATA = 40; +static const packet_t PT_RAP_ACK = 41; - PT_TFRC, - PT_TFRC_ACK, - PT_PING, +static const packet_t PT_TFRC = 42; +static const packet_t PT_TFRC_ACK = 43; +static const packet_t PT_PING = 44; // Diffusion packets - Chalermek - PT_DIFF, +static const packet_t PT_DIFF = 45; // LinkState routing update packets - PT_RTPROTO_LS, +static const packet_t PT_RTPROTO_LS = 46; // MPLS LDP header - PT_LDP, +static const packet_t PT_LDP = 47; // GAF packet - PT_GAF, +static const packet_t PT_GAF = 48; // ReadAudio traffic - PT_REALAUDIO, +static const packet_t PT_REALAUDIO = 49; // Pushback Messages - PT_PUSHBACK, +static const packet_t PT_PUSHBACK = 50; #ifdef HAVE_STL // Pragmatic General Multicast - PT_PGM, +static const packet_t PT_PGM = 51; #endif //STL // LMS packets - PT_LMS, - PT_LMS_SETUP, +static const packet_t PT_LMS = 52; +static const packet_t PT_LMS_SETUP = 53; - PT_SCTP, - PT_SCTP_APP1, +static const packet_t PT_SCTP = 54; +static const packet_t PT_SCTP_APP1 = 55; // SMAC packet - PT_SMAC, - +static const packet_t PT_SMAC = 56; // XCP packet - PT_XCP, +static const packet_t PT_XCP = 57; // HDLC packet - PT_HDLC, +static const packet_t PT_HDLC = 58; // Bell Labs Traffic Trace Type (PackMime OL) - PT_BLTRACE, +static const packet_t PT_BLTRACE = 59; // insert new packet types here - PT_NTYPE // This MUST be the LAST one +static packet_t PT_NTYPE = 60;// This MUST be the LAST one + +enum packetClass +{ + UNCLASSIFIED, + ROUTING, + DATApkt +}; + +class PacketClassifier +{ + public: + PacketClassifier(): next_(0){} + virtual ~PacketClassifier() {} + void setNext(PacketClassifier *next){next_ = next;} + PacketClassifier *getNext(){return next_;} + packetClass classify(packet_t type) + { + packetClass c = getClass(type); + if(c == UNCLASSIFIED && next_) + c = next_->classify(type); + return c; + } + + protected: + virtual packetClass getClass(packet_t type) = 0; //return 0 if the packet is unknown + PacketClassifier *next_; }; + class p_info { public: - p_info() { + p_info() + { + initName(); + } + const char* name(packet_t p) const { + if ( p <= p_info::nPkt_ ) return name_[p]; + return 0; + } + static bool data_packet(packet_t type) { + return ( (type) == PT_TCP || \ + (type) == PT_TELNET || \ + (type) == PT_CBR || \ + (type) == PT_AUDIO || \ + (type) == PT_VIDEO || \ + (type) == PT_ACK || \ + (type) == PT_SCTP || \ + (type) == PT_SCTP_APP1 || \ + (type) == PT_HDLC \ + ); + } + static packetClass classify(packet_t type) { + if (type == PT_DSR || type == PT_MESSAGE || type == PT_TORA || type == PT_AODV) + return ROUTING; + if (type == PT_TCP || type == PT_TELNET || type == PT_CBR || type == PT_AUDIO || type == PT_VIDEO || type == PT_ACK || type == PT_SCTP || type == PT_SCTP_APP1 || type == PT_HDLC) + return DATApkt; + if (pc_) + return pc_->classify(type); + return UNCLASSIFIED; + } + static void addPacketClassifier(PacketClassifier *pc) + { + if(!pc) + return; + pc->setNext(pc_); + pc_ = pc; + } + static void initName() + { + if(nPkt_ >= PT_NTYPE+1) + return; + char **nameNew = new char*[PT_NTYPE+1]; + for(unsigned int i = (unsigned int)PT_SMAC+1; i < nPkt_; i++) + { + nameNew[i] = name_[i]; + } + if(!nPkt_) + delete [] name_; + name_ = nameNew; + nPkt_ = PT_NTYPE+1; + name_[PT_TCP]= "tcp"; name_[PT_UDP]= "udp"; name_[PT_CBR]= "cbr"; @@ -197,14 +277,14 @@ name_[PT_CtrMcast_Encap]= "CtrMcast_Encap"; name_[PT_CtrMcast_Decap]= "CtrMcast_Decap"; name_[PT_SRM]= "SRM"; - + name_[PT_REQUEST]= "sa_req"; name_[PT_ACCEPT]= "sa_accept"; name_[PT_CONFIRM]= "sa_conf"; name_[PT_TEARDOWN]= "sa_teardown"; name_[PT_LIVE]= "live"; name_[PT_REJECT]= "sa_reject"; - + name_[PT_TELNET]= "telnet"; name_[PT_FTP]= "ftp"; name_[PT_PARETO]= "pareto"; @@ -219,77 +299,78 @@ name_[PT_DSR]= "DSR"; name_[PT_AODV]= "AODV"; name_[PT_IMEP]= "IMEP"; - + name_[PT_RAP_DATA] = "rap_data"; name_[PT_RAP_ACK] = "rap_ack"; - - name_[PT_TFRC]= "tcpFriend"; + + name_[PT_TFRC]= "tcpFriend"; name_[PT_TFRC_ACK]= "tcpFriendCtl"; name_[PT_PING]="ping"; - - /* For diffusion : Chalermek */ - name_[PT_DIFF] = "diffusion"; - + + /* For diffusion : Chalermek */ + name_[PT_DIFF] = "diffusion"; + // Link state routing updates name_[PT_RTPROTO_LS] = "rtProtoLS"; - + // MPLS LDP packets name_[PT_LDP] = "LDP"; - + // for GAF - name_[PT_GAF] = "gaf"; - + name_[PT_GAF] = "gaf"; + // RealAudio packets name_[PT_REALAUDIO] = "ra"; - + //pushback name_[PT_PUSHBACK] = "pushback"; - + #ifdef HAVE_STL // for PGM name_[PT_PGM] = "PGM"; #endif //STL - + // LMS entries name_[PT_LMS]="LMS"; name_[PT_LMS_SETUP]="LMS_SETUP"; - + name_[PT_SCTP]= "sctp"; - name_[PT_SCTP_APP1] = "sctp_app1"; + name_[PT_SCTP_APP1] = "sctp_app1"; // smac name_[PT_SMAC]="smac"; - + // HDLC name_[PT_HDLC]="HDLC"; // XCP name_[PT_XCP]="xcp"; - + // Bell Labs (PackMime OL) name_[PT_BLTRACE]="BellLabsTrace"; - + name_[PT_NTYPE]= "undefined"; } - const char* name(packet_t p) const { - if ( p <= PT_NTYPE ) return name_[p]; - return 0; - } - static bool data_packet(packet_t type) { - return ( (type) == PT_TCP || \ - (type) == PT_TELNET || \ - (type) == PT_CBR || \ - (type) == PT_AUDIO || \ - (type) == PT_VIDEO || \ - (type) == PT_ACK || \ - (type) == PT_SCTP || \ - (type) == PT_SCTP_APP1 || \ - (type) == PT_HDLC \ - ); + static int addPacket(char *name); + static packet_t getType(const char *name) + { + for(unsigned int i = 0; i < nPkt_; i++) + { + if(strcmp(name, name_[i]) == 0) + return i; + } + return PT_NTYPE; } private: - static char* name_[PT_NTYPE+1]; + static char** name_; + static unsigned int nPkt_; + static PacketClassifier *pc_; }; + +/* +End Fede +*/ + extern p_info packet_info; /* map PT_* to string name */ //extern char* p_info::name_[]; diff -Naur ns.orig/ns-allinone-2.31/ns-2.31/common/ptypes2tcl.cc ns-allinone-2.31/ns-2.31/common/ptypes2tcl.cc --- ns.orig/ns-allinone-2.31/ns-2.31/common/ptypes2tcl.cc 1999-09-28 05:46:32.000000000 +0200 +++ ns-allinone-2.31/ns-2.31/common/ptypes2tcl.cc 2007-04-17 19:34:03.000000000 +0200 @@ -10,7 +10,20 @@ #define TCL2C_INT #endif -char* p_info::name_[PT_NTYPE+1]; +char** p_info::name_; +unsigned int p_info::nPkt_ = 0; +PacketClassifier *p_info::pc_ = 0; +int p_info::addPacket(char *name) +{ + if(!nPkt_) + initName(); + + int newID = nPkt_-1; + PT_NTYPE = nPkt_; + initName(); + name_[newID] = name; + return newID; +} void printLine(char *s) { @@ -48,7 +61,7 @@ printLine("set ptype(error) -1"); printLine("set pvals(-1) error"); char strbuf[512]; - for (int i = 0; i < PT_NTYPE; i++) { + for (unsigned int i = 0; i < PT_NTYPE; i++) { sprintf(strbuf, "set ptype(%s) %d", lcase(pinfo.name(packet_t(i))), i); printLine(strbuf); sprintf(strbuf, "set pvals(%d) %s", i, pinfo.name(packet_t(i))); diff -Naur ns.orig/ns-allinone-2.31/ns-2.31/trace/cmu-trace.cc ns-allinone-2.31/ns-2.31/trace/cmu-trace.cc --- ns.orig/ns-allinone-2.31/ns-2.31/trace/cmu-trace.cc 2006-03-21 23:31:32.000000000 +0100 +++ ns-allinone-2.31/ns-2.31/trace/cmu-trace.cc 2007-04-17 19:01:21.000000000 +0200 @@ -34,7 +34,7 @@ * Ported from CMU/Monarch's code, appropriate copyright applies. * nov'98 -Padma. * - * $Header: /cvsroot/nsnam/ns-2/trace/cmu-trace.cc,v 1.89 2006/03/21 22:31:32 liyuan Exp $ + * $Header: /nfs/jade/vint/CVSROOT/ns-2/trace/cmu-trace.cc,v 1.88 2005/10/08 19:16:16 tomh Exp $ */ #include @@ -62,6 +62,40 @@ #include "diffusion/diff_header.h" // DIFFUSION -- Chalermek +/* +Added by Fede 03/04/2006 - For shared library compatibility +*/ +PacketTracer::PacketTracer() : next_(0) +{ +} +void PacketTracer::setNext(PacketTracer *next) +{ + next_ = next; +} + +PacketTracer *PacketTracer::getNext() +{ + return next_; +} + +int PacketTracer::format_unknow(Packet *p, int offset, BaseTrace *pt, int newtrace) +{ + return (format(p, offset, pt, newtrace) || (next_ && next_->format_unknow(p, offset, pt, newtrace))); +} + +PacketTracer *CMUTrace::pktTrc_ = 0; + +void CMUTrace::addPacketTracer(PacketTracer *pt) +{ + if(!pt) + return; + pt->setNext(pktTrc_); + pktTrc_ = pt; +} + +/* +End Fede +*/ //#define LOG_POSITION @@ -545,7 +579,7 @@ } /* Armando L. Caro Jr. 6/5/2002 - * (with help from Florina Almenrez ) + * (with help from Florina Almenárez ) */ void CMUTrace::format_sctp(Packet* p,int offset) @@ -1181,6 +1215,14 @@ case PT_PING: break; default: +/* +Added by Fede 03/04/2006 - For shared library compatibility +*/ + if(pktTrc_ && pktTrc_->format_unknow(p, offset, pt_, newtrace_)) + break; +/* +End fede +*/ /* fprintf(stderr, "%s - invalid packet type (%s).\n", __PRETTY_FUNCTION__, packet_info.name(ch->ptype())); diff -Naur ns.orig/ns-allinone-2.31/ns-2.31/trace/cmu-trace.h ns-allinone-2.31/ns-2.31/trace/cmu-trace.h --- ns.orig/ns-allinone-2.31/ns-2.31/trace/cmu-trace.h 2005-10-20 06:45:25.000000000 +0200 +++ ns-allinone-2.31/ns-2.31/trace/cmu-trace.h 2006-11-28 16:17:39.000000000 +0100 @@ -91,11 +91,36 @@ #define MAX_ID_LEN 3 #define MAX_NODE 4096 +/* +Added by Fede 03/04/2006 - For shared library compatibility +*/ +class PacketTracer +{ + public: + PacketTracer(); + void setNext(PacketTracer *next); + PacketTracer *getNext(); + int format_unknow(Packet *p, int offset, BaseTrace *pt_, int newtrace); + protected: + virtual int format(Packet *p, int offset, BaseTrace *pt_, int newtrace) = 0; //return 0 if the packet is unknown + PacketTracer *next_; +}; +/* +End Fede +*/ + class CMUTrace : public Trace { public: CMUTrace(const char *s, char t); void recv(Packet *p, Handler *h); void recv(Packet *p, const char* why); +/* +Added by Fede 03/04/2006 - For shared library compatibility +*/ + static void addPacketTracer(PacketTracer *pt); +/* +End Fede +*/ private: char tracename[MAX_ID_LEN + 1]; @@ -133,6 +158,13 @@ void format_tora(Packet *p, int offset); void format_imep(Packet *p, int offset); void format_aodv(Packet *p, int offset); +/* +Added by Fede 03/04/2006 - For shared library compatibility +*/ + static PacketTracer *pktTrc_; +/* +End Fede +*/ }; #endif /* __cmu_trace__ */ diff -Naur ns.orig/ns-allinone-2.31/ns-2.31/tcl/lib/ns-default.tcl ns-allinone-2.31/ns-2.31/tcl/lib/ns-default.tcl --- ns.orig/ns-allinone-2.31/ns-2.31/tcl/lib/ns-default.tcl 2006-10-23 07:33:16.000000000 +0200 +++ ns-allinone-2.31/ns-2.31/tcl/lib/ns-default.tcl 2007-04-17 19:06:57.000000000 +0200 @@ -610,6 +610,14 @@ # use tagged traces or positional traces? Simulator set TaggedTrace_ OFF +# +# Added by Fede 04/04/2006 - In order to give more flexibility and developing plugin +# +Simulator set rtAgentFunction_ "" +# +# End Fede +# + SessionHelper set rc_ 0 ;# just to eliminate warnings SessionHelper set debug_ false diff -Naur ns.orig/ns-allinone-2.31/ns-2.31/tcl/lib/ns-lib.tcl ns-allinone-2.31/ns-2.31/tcl/lib/ns-lib.tcl --- ns.orig/ns-allinone-2.31/ns-2.31/tcl/lib/ns-lib.tcl 2007-01-30 06:00:51.000000000 +0100 +++ ns-allinone-2.31/ns-2.31/tcl/lib/ns-lib.tcl 2007-04-17 19:14:45.000000000 +0200 @@ -375,6 +375,13 @@ Simulator instproc satNodeType {val} {$self set satNodeType_ $val} Simulator instproc downlinkBW {val} {$self set downlinkBW_ $val} Simulator instproc stopTime {val} {$self set stopTime_ $val} +# +# Added by Fede 04/04/2006 - In order to give more flexibility and developing plugin +# +Simulator instproc rtAgentFunction {val} {$self set rtAgentFunction_ $val} +# +# End Fede +# # change wrt Mike's code Simulator instproc eotTrace {val} { $self set eotTrace_ $val } @@ -594,7 +601,7 @@ macType_ ifqType_ ifqlen_ phyType_ chan antType_ \ energyModel_ initialEnergy_ txPower_ rxPower_ \ idlePower_ sleepPower_ sleepTime_ transitionPower_ transitionTime_ \ - topoInstance_ level1_ level2_ inerrProc_ outerrProc_ FECProc_ + topoInstance_ level1_ level2_ inerrProc_ outerrProc_ FECProc_ rtAgentFunction_ Simulator set IMEPFlag_ OFF @@ -605,51 +612,55 @@ if { [info exist wiredRouting_] && $wiredRouting_ == "ON" } { $node base-station [AddrParams addr2id [$node node-addr]] } - switch -exact $routingAgent_ { - DSDV { - set ragent [$self create-dsdv-agent $node] - } - DSR { - $self at 0.0 "$node start-dsr" - } - AODV { - set ragent [$self create-aodv-agent $node] - } - TORA { - Simulator set IMEPFlag_ ON - set ragent [$self create-tora-agent $node] - } - DIFFUSION/RATE { - eval $node addr $args - set ragent [$self create-diffusion-rate-agent $node] - } - DIFFUSION/PROB { - eval $node addr $args - set ragent [$self create-diffusion-probability-agent $node] - } - Directed_Diffusion { - eval $node addr $args - set ragent [$self create-core-diffusion-rtg-agent $node] - } - FLOODING { - eval $node addr $args - set ragent [$self create-flooding-agent $node] - } - OMNIMCAST { - eval $node addr $args - set ragent [$self create-omnimcast-agent $node] - } - DumbAgent { - set ragent [$self create-dumb-agent $node] - } - ManualRtg { - set ragent [$self create-manual-rtg-agent $node] - } - default { - eval $node addr $args - puts "Wrong node routing agent!" - exit - } + if {$rtAgentFunction_ != ""} { + set ragent [$self $rtAgentFunction_ $node] + } else { + switch -exact $routingAgent_ { + DSDV { + set ragent [$self create-dsdv-agent $node] + } + DSR { + $self at 0.0 "$node start-dsr" + } + AODV { + set ragent [$self create-aodv-agent $node] + } + TORA { + Simulator set IMEPFlag_ ON + set ragent [$self create-tora-agent $node] + } + DIFFUSION/RATE { + eval $node addr $args + set ragent [$self create-diffusion-rate-agent $node] + } + DIFFUSION/PROB { + eval $node addr $args + set ragent [$self create-diffusion-probability-agent $node] + } + Directed_Diffusion { + eval $node addr $args + set ragent [$self create-core-diffusion-rtg-agent $node] + } + FLOODING { + eval $node addr $args + set ragent [$self create-flooding-agent $node] + } + OMNIMCAST { + eval $node addr $args + set ragent [$self create-omnimcast-agent $node] + } + DumbAgent { + set ragent [$self create-dumb-agent $node] + } + ManualRtg { + set ragent [$self create-manual-rtg-agent $node] + } + default { + eval $node addr $args + puts "Wrong node routing agent!" + exit + } + } } # errProc_ and FECProc_ are an option unlike other diff -Naur ns.orig/ns-allinone-2.31/ns-2.31/Makefile.in ns-allinone-2.31/ns-2.31/Makefile.in --- ns.orig/ns-allinone-2.31/ns-2.31/Makefile.in 2007-03-11 00:49:57.000000000 +0100 +++ ns-allinone-2.31/ns-2.31/Makefile.in 2007-04-17 19:15:48.000000000 +0200 @@ -55,7 +55,7 @@ CCOPT = @V_CCOPT@ STATIC = @V_STATIC@ #LDFLAGS = $(STATIC) -LDFLAGS = @LDFLAGS@ +LDFLAGS = @LDFLAGS@ -export-dynamic LDOUT = -o $(BLANK) DEFINE = -DTCP_DELAY_BIND_ALL -DNO_TK @V_DEFINE@ @V_DEFINES@ @DEFS@ -DNS_DIFFUSION -DSMAC_NO_SYNC -DCPP_NAMESPACE=@CPP_NAMESPACE@ -DUSE_SINGLE_ADDRESS_SPACE -Drng_test