legolas07
legolas07

Reputation: 79

How to modify the behavior of a node in ns2 simulator?

I want to modify the behavior of a node in ns2 simulator. In particular, I have to modify a routing of a node inside a simulation of the dsr protocol. I know that dsragent.cc is the class that manages the routing of this protocol. But if I have a tcl script with 10 nodes, called $node1,$node2...node$10, how to modify the behavior of $node5 in the dsr protocol? How to find the single behavior of that node?

Upvotes: 0

Views: 436

Answers (1)

Mohannad_
Mohannad_

Reputation: 89

i had worked with other routing protocol but i will mention some points ..may it be useful.

in order to access specific node object in c++ you need to know its address in tcl. then you may need to make modification in forward or recv function.. you can extract all information you need form common,IP,DSR headers

DSRAgent::recv(Packet* packet, Handler*)
  /* handle packets with a MAC destination address of this host, or
     the MAC broadcast addr */
{
       hdr_sr *srh =  hdr_sr::access(packet);
      hdr_ip *iph =  hdr_ip::access(packet);
      hdr_cmn *cmh =  hdr_cmn::access(packet);
      p.dest = ID((Address::instance().get_nodeaddr(iph->daddr())),::IP);
      p.src = ID((Address::instance().get_nodeaddr(iph->saddr())),::IP);

the following means.. if current node is the generator of the packet

 if (p.src == net_id) {code}

to select specific node object

 if (net_id==ID("put the node address here", ::IP))     \\ notice net_id is a struct 
     {
       your code here
     }

you can assign node address from tcl and this address will be passed to c++ by command function

DSRAgent::command(int argc, const char*const* argv)
.
.
 if (strcasecmp(argv[1], "addr") == 0) 
    {
      int temp;
      temp = Address::instance().str2addr(argv[2]);
     net_id = ID(temp, ::IP);
     flow_table.setNetAddr(net_id.addr);
.
}

regards

Upvotes: 1

Related Questions