Feb 25, 2007

Tips : How to scale your simulation to more nodes eg. > 500 nodes and increase the simulation speed


One of the biggest problem for the implementation of the Packet data structure of NS2 is that it does not math the realities. The packet in ns2 simulation keeps all packet headers for any protocols implemented in NS2. For example, a DSR routing packet may keep DSDV, AODV, or even a PING application header. For this reason, till today, a packet used in ns2 simulation, would have a header size around 40~64KB. And NO packet would be deleted to release the memory it holds until the end of the simulation.

So for a typical simulation with 100 nodes in ns2 around 1M packets exchanged (of course, you may reuse the packets already being freed through Packet::free(Packet*). To learn the implementation of it, please check file common/packet{.h,.cc} ), you may hold 10% of it, 100K packets, and you may use a memory at least 100K*64KB -> 6.4GB, which definitely would crash your computer even server computers.

SO what is the best way to scale the simulation and increase the simulation speed. Fortunately there are two ways :

1. Suggested by ns2 manual, putting the below codes in your tcl script
remove-all-packet-headers
add-packet-header DSR ARP LL MAC CBR IP

to simulation a CBR application on UDP with DSR as routing protocol in a wireless ad hoc network (OOPS!, UDP is not a header. This method is effective, but it requires you to understand most packets header you need.

2. Another way is my way, changing the tcl library for the packet headers. You may find the tcl library file for packet headers in ns2/tcl/lib/ns-packet.tcl, you may find a procedure starting as foreach prot . You can comment out all the headers you don't recognize, like all the Routing protocols you dont know, all Routers, all Multicast, all Transport Protocols except you need, all application layer protocols, some of the Wireless, some of the Mobility, Ad-Hoc Networks, Sensor Nets and all the Other. Finally, you may just have all the below left

foreach prot {
# Common:
Common
Flags
IP
# Transport Protocols
TCP
# Wireless
ARP
LL
Mac
# Mobility
AODV
} {
add-packet-header $prot
}

Here is a sample of the skeleton of the script for you to put your code for your own packet header.

Typically, after this way, you may just have a packet size as 256B. So even you have 500 nodes, and 10M packets need to be exchanged during the simulation. You just need 256MB (if 10% packets held) for it, which is lower than any common configuration of current PCs.

tags: , , , , , , ,

2 comments:

Anonymous said...

hi, i want to simulate a manet using ns2.can anyone tel me how to change the beacon formats and how to send and receive it. Is it possible to do beaconing along with routing protocol? if so tel me how.if not wher it has to be handled mac layer na? how?

Anonymous said...

hi, can anyone tel me how to add the trans patch to ns2. i have fed up with lot of errors. is it necessary to instal sumo to add that patch?