NS-3 With Ndnsim Patch - Tutorial
NS-3 With Ndnsim Patch - Tutorial
After following a set of installation steps given in following Link, NS-3 resides in
/home/<user-name>/ndnSim/ns-3 folder.
https://sites.google.com/view/maazrehan/simulators?authuser=0
In terminal, to run a simulation script pwd (present working Directory) must be /home/<user-
name>/ndnSim/ns-3 (For Reference see Fig-2)
Folder location and containing folders can also be seen in following Figure.
Folders Hierarchy with Details (which folders are for what purpose)
As in Fig-1 couple of folders can be seen, but “examples, scratch and src” are the mostly used folders.
Examples folder contains all the example simulation script with mixed usage of all the network
features like routing contains routing related simulations while wireless contains wired and
wireless mixed simulations.
Scratch folder is used to run customized simulations, just place new simulation in scratch folder
and run it from terminal.
Src folder contains all the definition of each module like aodv, olsr, wave, application, antenna,
etc. All the protocols and frameworks are briefly defined in ‘model’ folder, while sample usage
of protocols in simulation scripts is placed in ‘example’ folder. ‘Helper’ folder contains the
helper classes of protocols and frameworks which are further called in simulation scripts to call
their functionality.
As discussed in previous section, example scripts with usage of protocols and frameworks are placed
in examples folder of each, like aodv --> examples --> aodv.cc <<or>> wave --> examples -->
vanet-routing-compare.cc
As discussed earlier each protocol contains different folders but mainly we will focus on model,
examples and helper folder. A protocol is defined in model and called through helpers defined in
Helper Folder. Each protocol’s working and utilization could be learnt through understanding lines of
code given in simulation scripts placed in example folders.
For AODV, sending and receiving functions for specific Packets (Hello, RouteReq, RouteReply) are
declared, defined and called in aodv-routing-protocol.h and aodv-routing-protocol.cc which are
located in /home/vr/ndnSim/ns-3/src/aodv/model.
aodv-packet.h & aodv-packet.cc >>> to declare and define new member in an existing packet or
completely building a new packet.
aodv-routing-protocol.h & aodv-routing-protocol.cc >>> to declare and define a send/ receive
function to build or extract information from packet.
Step-2:- Change the value of packet size according to new addition e.g. if added new ‘uint32_t’ then
total bytes are ‘4’, if existing size is ‘10’ new will be ‘14’. This size change will be provided
in GetSerializedSize( ) method of packet’s Class in file aodv-packet.cc
Step-3:- For sending a Packet, in each packet class there is a method(Function) to write the packet
content on buffer named as Serialize(Buffer::Iterator i), member variable will be written
on buffer e.g. i.WriteHtonU32(m_lifetime) *** will be done in aodv-packet.cc
Step-5:- In send function of a Packet, value of new member will be passed through constructor of the
class object in file aodv-routing-protocol.cc
Step-6:- On receiving Packet, information could be extracted by putting some line of codes to get the
member values, same will be done in receive function of packet in aodv-routing-
protocol.cc
If received a Packet, then following lines will be used;
- Create an object of concerned packet class
RrepHeader rrepheader;
- Remove Packet information from Packet P into packet class object
p->RemoveHeader (rrepheader);
- Now use the member variable for further actions
- std::cout << “Received a Hello Packet from ” << rrepheader.senderID;
While following steps should be followed to add a new packet in AODV-Protocol;
Step-1:- Each packet must include functions marked in red rectangle in following figure, while rest is
the packet formation. (In aodv-packet.h)
Step-2:- Declare and initialize an identification message type for packet. (In aodv-packet.h)
Step-3:- Message type and corresponding action will be defined. (In aodv-packet.cc)
Step-4:- Then functions declared previously in aodv-packet.h to define a size of packet, writing
packet on buffer and on receiving reading from buffer will be defined. (In aodv-packet.cc)
Step-5:- After creation of packet, we will declare send and receive functions to get required
information to publish in network. (In aodv-routing-protocol.h)
Step-6:- Again, a definition will be done against each routine in aodv-routing-protocol.cc -- receive
routine against custom packet is shown in the following figure.
Step-7:- After all this send and receive function, last thing is to register this receive routine against
aodv packet. Means, in network whenever an aodv related packet is received over a node, it
decide which function is to be executed. Receiving routine for new Packet will be placed in
RecvAodv (Ptr<Socket> socket) in aodv-routing-protocol.cc
Sample Function (your own sample code examples involving different functions)
--------------------------------------------------------
--------------------------------------------------------
Re-Compiling NS-3 (re-compiling ns-3)
Every time when we enter “./waf --run=<script-name>”, python will find any changes in files
present in src folder of ns-3 and on change found in files compiler will re-compile ns-3.
--------------------------------------------------------
--------------------------------------------------------