Hello ns-users
I'm currently digging into the source code of ns2. As far as I know, the 
Distance Vector (DV) route agent has 2 related source files:  - 
ns-2.35/routing/rtProtoDV.h
 - ns-2.35/routing/rtProtoDV.ccHowever, code logic in files above is rather 
simple. code in rtProtoDV.h is as shown below:00 #ifndef ns_rtprotodv_h
01 #define ns_rtprotodv_h
02 
03 #include "packet.h"
04 #include "ip.h"
05 
06 struct hdr_DV {
07 u_int32_t mv_;
08
09 static int offset_;
10 inline static int& offset() { return offset_; }
11 inline static hdr_DV* access(const Packet* p) {
12 return (hdr_DV*) p->access(offset_);
13 }
14 
15 u_int32_t& metricsVar() { return mv_; }
16 };
17 
18 class rtProtoDV : public Agent {
19 public:
20 rtProtoDV() : Agent(PT_RTPROTO_DV) {}
21 int command(int argc, const char*const* argv);
22 void sendpkt(ns_addr_t dst, u_int32_t z, u_int32_t mtvar);
23 void recv(Packet* p, Handler*);
24 };
25 
26 #endifAnd here comes the code in rtProtoDV.cc:01 #ifndef lint
02 static const char rcsid[] =
03 @(#) $Header: /cvsroot/nsnam/ns-2/routing/rtProtoDV.cc,v 1.9 2005/08/25 
18:58:12 johnh Exp $ (USC/ISI);
04 #endif
05
06 #include "agent.h"
07 #include "rtProtoDV.h"
08
09 int hdr_DV::offset_;
10              
11 static class rtDVHeaderClass : public PacketHeaderClass {
12 public:
13 rtDVHeaderClass() : PacketHeaderClass("PacketHeader/rtProtoDV",
14 sizeof(hdr_DV)) {
15 bind_offset(&hdr_DV::offset_);
16 }
17 } class_rtProtoDV_hdr;
18
19 static class rtProtoDVclass : public TclClass {
20 public:
21 rtProtoDVclass() : TclClass("Agent/rtProto/DV") {}
22 TclObject* create(int, const char*const*) {
23 return (new rtProtoDV);
24 }
25 } class_rtProtoDV;
26              
27              
28 int rtProtoDV::command(int argc, const char*const* argv)
29 {
30 if (strcmp(argv[1], ""send-update"") == 0) {
31 ns_addr_t dst;
32 dst.addr_ = atoi(argv[2]);
33 dst.port_ = atoi(argv[3]);
34 u_int32_t mtvar = atoi(argv[4]);
35 u_int32_t size = atoi(argv[5]);
36 sendpkt(dst, mtvar, size);
37 return TCL_OK;
38 }
39 return Agent::command(argc, argv);"
40 }
41              
42 void rtProtoDV::sendpkt(ns_addr_t dst, u_int32_t mtvar, u_int32_t size)
43 {
44 daddr() = dst.addr_;
45 dport() = dst.port_;
46 size_ = size;
47                      
48 Packet* p = Agent::allocpkt();
49 hdr_DV *rh = hdr_DV::access(p);
50 rh->metricsVar() = mtvar;
51              
52 target_->recv(p);
53 }
54
55 void rtProtoDV::recv(Packet* p, Handler*)
56 {
57 hdr_DV* rh = hdr_DV::access(p);
58 hdr_ip* ih = hdr_ip::access(p);
59 Tcl::instance().evalf("%s recv-update %d %d", name(),
60 ih->saddr(), rh->metricsVar());
61 Packet::free(p);
62 }I didn't see any logic maintaining the route table, and I don't know how to 
print the route table. My question is, what is the fastest way to implement 
(modify, or just use) a dv-based route protocol like RIP, then create a simple 
network scenario, and finally print the route table of each agent in a tcl 
script?Is it necessary to make a copy of some more complex prototols, e.g., 
DSDV or AODV, and change it into a simple RIP protocol?Eagerly waiting for the 
reply
Thank you

Reply via email to