When you add a new module or modify a existing source code, then ns2 needs to be recompiled. How to recompile and where to do the modifications are mentioned in this slide
2. Recompilation ways
Modifying 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
3. 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.
4. 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.
5. 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.
6. 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
7. 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;
8. 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;
9. Example
Paste 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);
10. 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);
11. 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);
12. Example 2: Recompilation
There 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
13. Example 2: Recompilation
Step 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/
14. Example 2: Recompilation
Step 4 - Run the commands
./configure
make
5. Copy the following lines in the ~ns-2.34/tcl/lib/ns-
default.tcl
15. 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
16. 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