17

Click here to load reader

Recompiling network simulator 2

Embed Size (px)

Citation preview

Page 1: Recompiling network simulator 2

RECOMPILING NETWORK SIMULATOR 2

Page 2: Recompiling network simulator 2

Recompilation waysModifying Existing code A magic word “make”. Correct the errors if any No need for changing

the Makefile.in

Adding a New Module Create a folder for the

project Specify the folder name

along with the object file to Makefile.in Execute “make” command

Page 3: Recompiling network simulator 2

Recompilation ways¤ For UG and PG Projects,

existing code modification is advisable as the time frame is just 4 to 8 months

¤ For research scholars, a new protocol, packet, agent, application can be created.

Page 4: Recompiling network simulator 2

Modifying the existing code

Important: Always start with the basic. Learn how existing algorithm works and how the parameters can be changed for wired, wireless and satellite networks.

Should have the knowledge of C++ and its object oriented concepts and the strong use of pointers

Understanding the existing protocol is must Do some basic simulations based on the existing code. (examples may be taken from NS2 library) Dedicate the 50 to 70% of the work for existing code and rest will be the modification code.

Page 5: Recompiling network simulator 2

Recompilation¤ Must have the basics of the C++

classes of NS2 and linkages between the OTCL and C++.

¤ For implementing a new protocol, the following should be designed ■ Packet header ■ Agent (use the existing agent) ■ Application (use the existing app) ■ Routing, etc.

Page 6: Recompiling network simulator 2

Example- Modifying the existing code

Finding the Node Position, speed and Velocity of a Node while using AODV Files to be modified ¤ ~ns-2.34/aodv/aodv.h ¤ ~ns-2.34/aodv/aodv.cc ¤ Please look at the corresponding File

Page 7: Recompiling network simulator 2

Example..Step 1: Open

~ns-2.34/aodv/aodv.h include the following header

line in aodv.h #include<mobilenode.h>

Step2: In protected scope declare the variables you would be using to store the node parameters.

double xpos; double ypos; double zpos; double iEnergy; int node_speed; MobileNode *iNode; FILE *fp;

Page 8: Recompiling network simulator 2

Example..Step 3: In aodv.cc initialize the declared variables in the constructor xpos = 0.0; ypos = 0.0; zpos = 0.0; node_speed = 0; iEnergy=0.0; fp=fopen("pradeep.csv","w"); MobileNode *iNode;

Page 9: Recompiling network simulator 2

ExamplePaste the following lines in the AODV::forward() function

//Code by pradeepkumar /***This code retrieves node position*****/ fprintf(fp,"Position is, X, Y, Z, Velocity is, X, Y, Z, Velocity, Node Speed,

Energy \n"); iNode = (MobileNode*) (Node::get_node_by_address(index)); ((MobileNode *) iNode)->getLoc(&xpos,&ypos,&zpos); //Position of %d , X, Y, Z fprintf(fp,"%d,%f,%f,%f,", index, xpos, ypos, zpos);

Page 10: Recompiling network simulator 2

Example/***This code retrieves the nodes velocity*****/ iNode = (MobileNode*) (Node::get_node_by_address(index)); ((MobileNode *) iNode)->getVelo(&xpos, &ypos, &zpos); //Velocity of %d , X, Y, Z fprintf(fp,"%d,%f,%f,%f,", index, xpos, ypos, zpos);

Page 11: Recompiling network simulator 2

Example /***This code retrieves the nodes speed*****/ iNode = (MobileNode*) (Node::get_node_by_address(index)); node_speed = ((MobileNode *) iNode)->speed(); iEnergy=iNode->energy_model()->energy(); //Velocity of %d , Node Speed in m/s Energy in joules fprintf(fp,"%d,%d,%f,", index, node_speed,iEnergy);

Page 12: Recompiling network simulator 2

Example 2: RecompilationThere are totally 6 steps Step1: Create a folder mytcp in ~ns-2.34/ Copy all .cc and .h files in the ~ns-2.34/mytcp

Page 13: Recompiling network simulator 2

Example 2: RecompilationStep 2. make an entry in the ~ns-2.34/Makefile.in in OBJ_CC mytcp/tcp-westwood.o mytcp/tcp-westwood-nr.o \ Step 3. Using Shell, go to ~ns-2.34/

Page 14: Recompiling network simulator 2

Example 2: RecompilationStep 4 - Run the commands ./configure make 5. Copy the following lines in the ~ns-2.34/tcl/lib/ns-default.tcl

Page 15: Recompiling network simulator 2

Example2# Added for TCP WestwoodNR

Agent/TCP/WestwoodNR set current_bwe_ 0 Agent/TCP/WestwoodNR set last_bwe_sample_ 0

Agent/TCP/WestwoodNR set unaccounted_ 0 Agent/TCP/WestwoodNR set fr_a_ 1 Agent/TCP/WestwoodNR set min_rtt_estimate 10000

Agent/TCP/WestwoodNR set myseqno_ 1 Agent/TCP/WestwoodNR set lastackno_ 0

Agent/TCP/WestwoodNR set lastackrx_ 0 Agent/TCP/WestwoodNR set fr_alpha_ 0.9 Agent/TCP/WestwoodNR set filter_type_ 3

Agent/TCP/WestwoodNR set tau_ 1.0

# setting this to 1 implements some changes to reno # proposed by Janey Hoe (other than fixing reno's # unnecessary retransmit timeouts) Agent/TCP/WestwoodNR set newreno_changes_ 0 # setting this to 1 allows the retransmit timer to expire for # a window with many packet drops Agent/TCP/WestwoodNR set newreno_changes1_ 0 Agent/TCP/WestwoodNR set partial_window_deflation_ 0 Agent/TCP/WestwoodNR set exit_recovery_fix_ 0

Page 16: Recompiling network simulator 2

Example2# Added for TCP Westwood Agent/TCP/Westwood set current_bwe_ 0 Agent/TCP/Westwood set last_bwe_sample_ 0 Agent/TCP/Westwood set unaccounted_ 0 Agent/TCP/Westwood set fr_a_ 1 Agent/TCP/Westwood set min_rtt_estimate 10000 Agent/TCP/Westwood set myseqno_ 1 Agent/TCP/Westwood set lastackno_ 0 Agent/TCP/Westwood set lastackrx_ 0 Agent/TCP/Westwood set fr_alpha_ 0.9 Agent/TCP/Westwood set filter_type_ 3 Agent/TCP/Westwood set tau_ 1.0

Page 17: Recompiling network simulator 2

Example2Step 6. Run the file test-1-simple.tcl