Sie sind auf Seite 1von 20

m 



T S PRADEEP KUMAR
url : http://www.pradeepkumar.org
Email: tspembedded@gmail.com
Social : http://www.facebook.com/tspradeep
  

´ Installation of NS2
´ Introduction to OTCL/C++

´ Recompiling NS2
« Modification

« Adding a new module


m
m
´ Linux
« Use of Linux is recommended
² Fedora (10, 12)
¹ If DVD Version- no need of additional package installation
¹ Install all the packages (if default installation selected, then additional packages
have to be installed)
² Ubuntu (9.04, 9.10, 10.04, 10.10)
¹ Additional packages to be installed, there may be GCC Issues, xgraph and NAM
issues
² Red Hat Enterprise Linux 5 (RHEL5)
¹ Cent OS is the alternative for RHEL
« Basic commands (ls, chmod, tar, rpm, make, gedit, vi, pwd,
passwd, echo, cd, etc)
« Directory structure and shell prompt
« Path variables setting, Installation of packages and dependencies
m mm
´ Download from http://isi.edu/nsnam/ns/ns-
build.html#allinone
´ Copy the file under /home/pradeep (if your
username is ´abcdefµ then home folder will be
/home/abcdef)
´ Extract it using ´„  

  „ µ
´ ´˜ 

  µ
´ ´ „

´ (if any errors, please correct it)


´ Setting of paths in ´  
 or ´ ˜
   
 m
| 

 m
   
´ OTCL
« Interpreted Hierarchy
« Faster to interpret, slow to run
« Preferable for beginners
´ C++
« Used when dealing with a packet, agent or a protocol
« Compiled Hierarchy
« Slow to compile, faster to execute
´ The interface between OTCL and C++ is TclCL
(available as a folder in ~ns-allinone-2.34/tclcl-xxx)
 

´ TCLCL Consists of Six main classes


« Tcl(Methods to access the interpreted hierarchy)
« InstVar (binds member variable in both hierarchies
together
« TclObject (base class of all simulation objects)

« TclClass (maps class of IH to class of CH)

« TclCommand (global access to CH from IH)

« EmbeddedTcl (translates OTCL Script to C++ Code)


 

´ Each class have various member functions that


are used to get compiled
´ As a case study, lets start how to create a
simple agent.
    m
class TSPAgent : public Agent {
public:
TSPAgent();
protected:
int command(int argc, const char*const* argv);
private:
int tsp_var1;
double tsp_var2;
void TSPPrivFunc(void);
};
    m
static class TSPAgentClass : public TclClass {
public:
TSPAgentClass() : TclClass("Agent/TSPAgentOtcl") {}
TclObject* create(int, const char*const*) {
return(new TSPAgent());
}
} class_tsp_agent;

TSPAgent::TSPAgent() : Agent(PT_UDP) {
bind("tsp_var1_otcl", &tsp_var1);
bind("tsp_var2_otcl", &tsp_var2);
}
    m
int TSPAgent::command(int argc, const char*const*
argv) {
if(argc == 2) {
if(strcmp(argv[1], "call-tsp-priv-func") == 0) {
TSPPrivFunc();
return(TCL_OK);
}
}
return(Agent::command(argc, argv));
}
    m

void TSPAgent::TSPPrivFunc(void) {
Tcl& tcl = Tcl::instance();
tcl.eval("puts \"Message From TSPPrivFunc\"");
tcl.evalf("puts \" tsp_var1 = %d\"", tsp_var1);
tcl.evalf("puts \" tsp_var2 = %f\"", tsp_var2);
}
    m 
#name it as .tcl file
# Create TSPAgent
set myagent [new Agent/TSPAgentOtcl]

# Set configurable parameters of TSPAgent


$myagent set tsp_var1_otcl 2
$myagent set tsp_var2_otcl 3.14

# Give a command to TSPAgent


$myagent call-tsp-priv-fun
  
| 
 |  

|
´ to build a multimedia application that runs over
a UDP connection,
´ five rate media scaling

´ by changing encoding and transmission policy


pairs associated with scale parameter values.
  
| 
 |  

|
´ Based on 5 rate
«0 0.3mb
«1 0.6mb
«2 0.9mb
«3 1.2mb
«4 1.5mb
« Packetsize 1000
« Random false
  
| 
 |  

|
´ Mhen connection established, Sender/receiver
agree on 5 different sets of encoding and
transmission policy pairs.
´ Sender sends with scale 0 but changes the
transmission rates according to the value that the
receiver notifies.
´ The receiver is responsible for monitoring the
network congestion and determine the scale
factor. If congestion, then the receiver reduces the
scale factor.
   |

´ ~ns-2.34 is the folder where all the cc modules


are located
Topic Mhere to modify
Routing Protocol ~ns-2.34/aodv/aodv.cc, aodv_rtable.cc,
(AODV, DSDV, DSR) etc
Mobile Node (Energy, Propagation, ~ns-2.34/mobile/*.cc and *.h
Antenna)
TCP (Vegas, Reno, New Reno, etc) ~ns-2.34/tcp/ *.cc
New packet, agent to be added ~ns-2.34/common/packet.h, agent.h
Mireless Physical layer or MAC ~ns-2.34/mac/*.cc
Layer modification
   |
Topic Mhere to modify
MPLS ~ns-2.34/mpls
Adding a new Queue ~ns-2.34/queue/*.cc and *.h
Adding a new application ~ns-2.34/apps/app.h
Sensors ~ns-2.34/sensor-net (still to be developed)
Examples (more than 100) ~ns-2.34/tcl/ex/
Mhat not lot more in NS2
 m