Sei sulla pagina 1di 2

Steps for Creating a New Agent in NS2.

35
1. Create folder named as newagent under the following directory: /ns-2.35 named as /newagent 2. Create files under the newly created directory /newagent: Files: newagent.h, newagent.cc, newagent_packet.h. The files may increase based on the agent being added. If a routing agent is added then some few more files are added such as those for routing table and queue used by the agent. a. newagent/h provides the header file. It consists of declaration of the functions to be used. b. newagent.cc provides the definition of the functions that are used by the agent and those which are declared in the above header file. c. newagent_packet.h provides the packet definition that is used by this agent. 3. Modify following files: a. Makefile.in b. packet.h c. ns-lib.tcl d. ns-agent.tcl e. ns-packet.tcl 4. Modify the Makefile.in file present under the root directory ns-2.35. Makefile.in file acts as initialization file for NS2 that has the object files for all the agents and protocols that are available in NS2. We have to create object file for newly defined agent. Create it as follows: a. newagent/newagent.o \ at Line Number 270 5. Modify the file named packet.h present under /ns2.35/common directory as follows: a. Whenever we add new agent or new protocol this newly created agent has to be the second last in the file; the last being PT_NTYPE. Line Number 200
//NEWAGENT packet static const packet_t PT_NEWAGENT = 72; // insert new packet types here static packet_t PT_NTYPE = 73; // This MUST be the LAST one

b. Add following line at Line Number 269


(type) == PT_NEWAGENT

c. Name the agent in the packet.h file at Line Number 351 as below:

name_ [PT_NEWAGENT] = NEWAGENT;

6. Modify ns-lib.tcl file under the /tcl/lib directory as below: a. As we have added new agent the procedure for this protocol agent has to be coded in this file. Line Number 633
NEWAGENT { set ragent [$self create-newagent-agent $node] }

b. Add the code for this agent at Line Number 865


Simulator instproc create-newagent-agent { node } { # Create NEWAGENT routing agent set ragent [new Agent/NEWAGENT [$node node-addr]] $self at 0.0 "$ragent start" $node set ragent_ $ragent return $ragent }

When nodes use this agent then they are initialized here so that they follow this agents definit ion at the beginning of the simulation. 7. Modify ns-agent.tcl file present under /tcl/lib directory. a. Set the port numbers for the agent as source port and destination port at Line Number 201. This should be the last agent in the file.
Agent/NEWAGENT instproc init args { $self next $args } Agent/NEWAGENT set sport_ 0 Agent/NEWAGENT set dport_ 0

8. Modify ns-packet.tcl file present under the /tcl/lib directory: a. Add the name of the agent at Line Number 184. Here we have considered that the new agent is for wireless network so it is added at Line Number 184. The line number may change depending upon the type of protocol or agent that has been created. For example if agent/protocol is based on wireless ad-hoc networks then it will be added at Line Number 184. If it is a transport protocol/agent then it will be added at Line Number 162 and so on.
# NEWAGENT patch NEWAGENT

Potrebbero piacerti anche