Monday, November 14, 2011

NS2: How add/implement a new protocol into ns2 network simulator

I have tried adding new protocol called "MyPing" using existing code of "ping" protocol. I have followed following procedure :

1. copy the ping.h & ping.cc to ns2-xx/apps and renamed it myping.h & myping.cc respectively.

2. Define MyPing Packet type in packet.h as:


a)       // insert new packet types here
          static const packet_t PT_MYPING = 62;
          static packet_t       PT_NTYPE = 63; // This MUST be the LAST one

b)         class p_info {  .........
              static bool data_packet(packet_t type) {
              ..................................
              (type) == PT_MYPING\
             -----------------------------
           static void initName()
           ------------------------------
           name_[PT_MYPING]="MyPing";
     //------------------------------------
           name_[PT_NTYPE]= "undefined";
          .....................................................


c)      #define DATA_PACKET(type) ( (type) == PT_TCP || \
            ...........................................
             (type) == PT_MYPING \
             ...........................................


3)  Define default value of MyPing agent in ns-default.tcl
    Agent/MyPing packet_size 64


4) Edit Makefile inside ns2-xx dir and add "apps/myping.o"  next to "apps/ping.o" 


5) make clean and then make


You may follow these links for more information related to implementation:
http://www.isi.edu/nsnam/ns/tutorial/nsnew.html
http://nile.wpi.edu/NS/

Thanks
--

53 comments:

Anonymous said...

can we store database in ns2

Santosh said...

Not sure..never uses database with ns2 but I have feeling that there should be some way to use it.

stylesp said...

when i modify the packet.h file and type make clean and make then following error occurs

./common/packet.h:46:18: fatal error: list.h: No such file or directory compilation terminated.

can you please help me on this?

Santosh said...

@stylesp ./common/packet.h:46 has #include "lib/bsd-list.h" not list.h. So, before coming to any conclusion, I would like to know what you trying to do? I mean are you adding new protocol or just trying same example what I have mentioned in this blog? Also, if you could tell me, are you able to compile successfully without modifying anything and using same procedure?

stylesp said...

NO sir i tried to modify packet.h for different purpose. I found the code of segmentation and reassembly and modify packet.h and when i compile then i got error as above.

i'm new user to ns2 and i want to piggyback two packets at a time and then send those packets in the multicast networks. I want to try whether that segmentation/reassembly will work or not. So i tried that one.

snehal shendware said...

Sir,After adding MyPing as describe above
I get following error.

apps/myping.o:(.bss+0x0): multiple definition of `hdr_ping::offset_'
apps/ping.o:(.bss+0x0): first defined here
apps/myping.o: In function `PingAgent::PingAgent()':
myping.cc:(.text+0x84): multiple definition of `PingAgent::PingAgent()'
apps/ping.o:ping.cc:(.text+0x84): first defined here
apps/myping.o: In function `PingAgent::PingAgent()':
myping.cc:(.text+0x0): multiple definition of `PingAgent::PingAgent()'
apps/ping.o:ping.cc:(.text+0x0): first defined here
apps/myping.o: In function `PingAgent::command(int, char const* const*)':
myping.cc:(.text+0x108): multiple definition of `PingAgent::command(int, char const* const*)'
apps/ping.o:ping.cc:(.text+0x108): first defined here
apps/myping.o: In function `PingAgent::recv(Packet*, Handler*)':
myping.cc:(.text+0x28a): multiple definition of `PingAgent::recv(Packet*, Handler*)'
apps/ping.o:ping.cc:(.text+0x28a): first defined here
collect2: ld returned 1 exit status
make: *** [ns] Error 1

Please reply.

eashwar said...

@all:hi guys im doing my final year project in ns2 and we are going to develop DSR in unicast mode and compare it with the original DSR which is a broadcast module......so can any one please explain me or giv gud suggestion to do DSR in a unicast mode......i find it diffcult to understand the original DSR code which is in c++ in ns2 ......so can any one help me to identify the broadcast module in that code and help me to change it into unicast module......

Please reply ASAP.....very urgent!!!!!!

jahnavi said...

could you please tell the code for execution of TORA routing protocol in ns-2 under linux operating system(fedora-12)

Santosh said...

@snehal Please download the following files and see the difference and also this was done for ns2.34. So please make sure that you are modifying packet format in right way. Because older might have different packet format.

https://docs.google.com/open?id=0B9hgZqVJNhpjSTc4eXhmSDhTZWEteHZfQ2NFbmlCQQ
https://docs.google.com/open?id=0B9hgZqVJNhpjMzM2eFdKTVRTbmVCYXlYYWlhb3ROdw
https://docs.google.com/open?id=0B9hgZqVJNhpjbVVmbWdUTXFTN3k1UHBGNzVIbEhCUQ
https://docs.google.com/open?id=0B9hgZqVJNhpjOXRnTnlJeHpRV3Fma2kzR20xT3AzZw

Others: Guys I am sorry for delay..i am going little busy...so not getting much time to look your problem.

@jahnvi : please check this link..it may be useful for your problem : http://www-sop.inria.fr/members/Eitan.Altman/ns.htm

Sathya said...

I am doing my final year project in ns2.34 about Target tracking in wireless sensor networks .Any help regarding how can i track the mobile node and report to the base station.Please reply

Anonymous said...

hi frndz...do any one know how to simulate sensor nodes in ns2???

Jyoti Rungta said...

Hi Everyone this is Jyoti from TechnoZonk.

We can develop any kind of simulation based on NS2.

NS2 Project Developers and NS2 Training In India. Having 14+ years experience in Networking, Linux and Network Simulator over 7+ years. First time Professional Ns2 Reserch projects development done by us and delivered more than 300 projects around India . Also trained more than 2000 students in ns2. Having strong knowledge to bring new domain and create strong professionals for the same.

Contact us :9920118169
for more info or email us on rungtajyoti@yahoo.co.in

vidya said...

Hi all,
I am doing my final year project in ns2.34.Our project is Remaining energy based routing protocol for wireless sensor network.We are using C++. Can anybody tell how to broadcast packet in WSN.There is flood-agent file in ns2.34. so should we include that file and how?
plz reply

Anonymous said...

i have followed the steps you have said to the last word and put the renamed files into a directory named ns-allinone-2.35/ns2-2.35/eammh/

the files are eammh.cc and eammh.h
after doing make clean,make depend,make
the eammh.o file is being created successfully.
but even then i get the following error whenever i try to include Agent/Eammh in a tcl file.

error:

invalid command name "Agent/Eammh"
while executing
"Agent/Eammh instproc recv {from rtt} {
$self instvar node_
puts "node [$node_ id] received ping answer from \
$from with round-trip-ti..."
(file "eammh.tcl" line 32)

what is the problem?

Unknown said...

Hi I was trying to simulate in ns2 using your example. I have done the same changes as per your post.. When I try to create a tcl script like this

set ns [new Simulator]

set nf [open out.nam w]
$ns namtrace-all $nf

#Create three nodes
set n0 [$ns node]
set n1 [$ns node]

#Connect the nodes with one link
$ns duplex-link $n0 $n1 1Mb 10ms DropTail

#Create two ping agents and attach them to the nodes n0 and n1
set p0 [new Agent/MyPing]
$ns attach-agent $n0 $p0
set p1 [new Agent/MyPing]
$ns attach-agent $n1 $p1

#Connect the two agents
$ns connect $p0 $p1

#Schedule events
$ns at 0.2 "$p0 send"
$ns at 0.4 "$p1 send"
$ns at 0.6 "$p0 send"
$ns at 0.6 "$p1 send"
$ns at 1.0 "finish"

#Run the simulation
$ns run


I get an err[code omitted because of length]
: invalid command name "Agent/MyPing"
while executing
"Agent/MyPing packet_Size 64"
or stating


Please post your comments on this issue

T S Pradeep Kumar said...

Try this for writing your own agent.
http://www.nsnam.com/2011/12/creating-new-agent-in-network-simulator.html
also refer
http://www.pradeepkumar.org

Santosh said...

Hi guys,

Sorry for late reply..I was kind of occupied. I have uploaded the files and shring with you. anyone who has problem please refer the files. Here is Links:

https://docs.google.com/open?id=0B9hgZqVJNhpjQUlNdjJub2RvNlE
https://docs.google.com/open?id=0B9hgZqVJNhpjY1RtUGV4ZW1NdkE
https://docs.google.com/open?id=0B9hgZqVJNhpjeU9KS2FDbWR5Q0k
https://docs.google.com/open?id=0B9hgZqVJNhpjV3J4YTNuZmR1UEE
https://docs.google.com/open?id=0B9hgZqVJNhpjNHJqSXYzTkpHOFU

--
santosh

Anonymous said...

Hey.....can you tell me where exactly are the ns2 related files located in Ubuntu....??

Meenakshi Bhrugubanda said...

sir iam doing my project on smac protocol . i have to create star topology,ring topology and grid topology for wireless networks . plz tell me how to write the tcl scripts for the above mentioned topologies

VMK said...

hii,
How can we find node energy in Tora protocol.

Unknown said...

i made some changes in aodv protocol in ns2 2.35 version and complied the ns2 folder using the commands make clean
./configure
make install
make..
but am getting errors like cant remove gen/version.o gen/ptypes.cc -permission denied..
can anyone provide a solution for this??

Unknown said...

can you help me....i try to make multipath dsr procol..what should i do..?

Anonymous said...

Hello sir,
I have to submit an assignment on ns2. I have to implement any protocol in ns2 and run the nam file and trace file. Can you suggest me material to do this?
Thank you in advance.

dhaval_dr said...

Hello friends ,
I want to implement[Simulate] ,
SPIN[Sensor protocol for information via negotiation] and LEACH[low energy adaptive clustering hierarchy] protocol for wireless sensor network in NS2.............

can any one help me.......i have just started to work on NS2 ....so,please suggest me , how can i simulate this protocol in NS2 ?????

inform me at "dhaval_dr@hotmail.com"

Thank you

Unknown said...

Hello friends,
I want to implement an energy aware AODV by adding a field minEnergy on RREQ.When a node before broadcasting it compares its current energy & the minEnergy on the RREQ packets and reassign the minimum of them on minEnergy of RREQ packet.Then rebroadcast it. My question is how can I obtain current energy of each node? I tried to obtain using this: currEnergy = iNode->energy_model()->energy(); But It does not work.
Can any one provide some hint on it?

Thank you in advance!!

Yohannes

prashant said...

Hello friends ,
I want to implement[Simulate] ,
SPIN[Sensor protocol for information via negotiation] and LEACH[low energy adaptive clustering hierarchy] protocol for wireless sensor network in NS2.............

can any one help me.......i have just started to work on NS2 ....so,please suggest me , how can i simulate this protocol in NS2 ?????
my email id is pmmishraprashant@gmail.com

Unknown said...

hi..
i want to do a BFS on a tree topology in ns2. Can anyone please tell me how to do that. Is there any method to find the neighbour of a node in ns2

sreekanth vakati said...

I am Sreekanth Vakati doing my M.Tech in Andhra Pradesh. I am doing a project on MANET routing protocols.I have got some results like Packet delivery Ratio ,Routing Overhead,and Avg End-to-End Delay.I have got these results from Trace file run in the java parsetrace file.In my base paper the author calculated the Node Throughput.I dont have any idea to calculate throughput.Somebody told me that some awk files will be available in the net and run them in terminal,i have downloaded awk file and i don't know how to run it in Linux, if anybody know how to calculate the node throughput kindly give me the reply.

Unknown said...

Sir I am doing final year project in NS 2.34 in ubunto platform. And i want to add Cluster Based Routing Protocol (CBRP) in NS2. I have all source code and .tcl code the only thing where I stuck up is how to add new protocol in NS2. can u please help me?

spandan spandy said...

Hello sir,
i am working on project energy efficient bee routing algorithm in ns2....i am not getting where to include this routing algoirthm ..can u help me...plz

sony said...

Hello sir,
I am doing my final year M.Tech project in NS2.34. I would like to get printed, the neighbor node list for each node in the network and when a node receives a route request, it has to set a "1" corresponding to he neighbor from which it has obtained the Route request packet. Has anyone got an idea how to implement this in AODV protocol? It was really urgent for my project.
Thanks in advance..

Santosh said...

hi everyone, sorry for delay in replying. I would love to help you gus but I am kind of busy and also its quite sometime since last time I developed NS2 module. But I would like to suggest you please use ns2 mailing list, it is very helpful. Wishing you best with your work.

--
santosh

pencari said...

hi, i'm evi. i'm doing my project in ns-2. i think i wanna discuss something with u mam. I hope u want to reply me by email. evi.hartati.26@gmail.com




pencari said...

i'm sorry. I meant, Sir

Dr. Md. Amir Khusru Akhtar said...

Dear All
Please guide me the institution name and address for the NS-2 training.

Unknown said...

hello sir,
Can u please guide me with the code of end to end delay and route discovery latency in ns2?

Admin said...

did any one do SPIN i am stuck on that :/ help

Unknown said...

sir i need code for implementation of tcp new reno for NS version 2.35.
would be greatful if anybody could help.
email id:-saharsh28smit@gmail.com

Unknown said...

When I implemented this , and run the TCL script I got the error ""warning: ns Scheduler::schedule: scheduling event
with negative delay (-13743.895344) at time 0.200000.
ns: scheduler going backwards in time from 0.200000 to -13743.695344."" anyone pls help....

Unknown said...

how to calculate network lifetime of sensor nodes.......... pls help me friends.............

Unknown said...

Hi Sir,
I am trying to implement a new protocol in NS2 named WFRP protocol.
I got this error..
trace/cmu-trace.o: In function `hdr_wfrp::access(Packet const*)':
cmu-trace.cc:(.text._ZN8hdr_wfrp6accessEPK6Packet[hdr_wfrp::access(Packet const*)]+0x7): undefined reference to `hdr_wfrp::offset_'
collect2: ld returned 1 exit status
make: *** [ns] Error 1
Ns make failed!

Can u say the solution for this....
Mail ID : prajan090@gmail.com

abhi said...

Sir,
how can i patch CBRP protocol with NS2.34 simulator???
pls reply fast

Unknown said...
This comment has been removed by the author.
Unknown said...

Hello, I have implemented LEACH protocol in ns2.34 in centos.I want to improve the leach protocol by applying k-means algo on it. I have found kmeans.tcl file. I dont know how to apply it on LEACH protocol. If any one know then please reply me?

Unknown said...

id : rab.2107@gmail.com

Unknown said...

Can any one tel me how to control acknowledgement transmission in smac. I want to send only one ack frame after receiving all the data frame.

Unknown said...

There are three types of cache at DSR. Mobicache, link cache and simplecache. Mobicache is the cache that is used by default in the DSR. I want to change from mobicache to to link cache. How can I do that using NS2.

Unknown said...

any body send multipath routing in aodv tcl code please send my mail id vdharmanv@gmail.com

Unknown said...

Sir,
I need patch of CBRP,if anyone please share with me.

pls reply fast
My mail-ID:- swetaramani648@gmail.com

BLOSSOM RENITA said...

I am working in evalvid tool i want to send the packet to multihop network.Can anyone help.

reply to blossomrenita@gmail.com

Unknown said...

hello all. I want to implement Modified AODV routing protocol. I want to make changes in HELLO and RREQ packets. I want to add delay time in hello packet and then calculate the Route stability factor. This factor will be included in RREQ packets which will be send to all nodes and then to Destination. Please suggest where the modifications are to be done? please help

romy said...

I have a protocol in a folder that is not currently implemented in ns2. the folder has 4 '.cc' files, 4 '.h' files and 5 '.o' files. It also has 1 '.cc~' and 1 '.h~' files. How do I make my ns-2 use this folder? What steps am i suppose to follow? Anyone?

Unknown said...

invalid command name "Agent/myping"
while executing
"Agent/myping instproc recv {from rtt mess originmess hash} {
$self instvar node_
puts "node [$node_ id] received packet from \
$from with..."
(file "myping.tcl" line 49)

Post a Comment