Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 ns-2 Tutorial, part 2 Dave Anderson, Xiaowei Yang (Modified from Polly Huang’s slides)

Similar presentations


Presentation on theme: "1 ns-2 Tutorial, part 2 Dave Anderson, Xiaowei Yang (Modified from Polly Huang’s slides)"— Presentation transcript:

1 1 ns-2 Tutorial, part 2 Dave Anderson, Xiaowei Yang (Modified from Polly Huang’s slides)

2 2 Outline Ns-2 internals –script -> internal structure How to Extend ns

3 3 Script Code # Create a topology Set ns [new Simulator] set n0 [$ns node] set n1 [$ns node] $ns duplex-link $n0 $n1 1Mb 10ms DropTail # Add Transport agents set tcp [new Agent/TCP] $ns attach-agent $n0 $tcp set tcpsink [new Agent/TCPSink] $ns attach-agent $n1 $tcpsink $tcp connect $tcpsink # Add application set ftp [new Application/FTP] $ftp attach-agent $tcp # Create a schedule $ns at 0.5 "$ftp start" $ns at 4.5 "$ftp stop" #Run the simulation $ns run n0n1 1Mb 10ms FTP TCP FTP TCP

4 4 Discrete Event-Driven Simulator time_, uid_, next_, handler_ head_ -> handler_ -> handle() time_, uid_, next_, handler_ insert $ns at 0.5 “$ftp start” $ns at 4.5 “$ftp stop” $ns run

5 5 Ns Node n0n1 Addr Classifier Port Classifier classifier_ dmux_ entry_ 0 1 Addr Classifier Port Classifier classifier_ dmux_ entry_ 1 0 set n0 [$ns node] set n1 [$ns node]

6 6 Network Topology - Link n0n1 enqT_queue_deqT_ drophead_drpT_ link_ttl_ n1 entry_ head_ $ns duplex-link $n0 $n1 1Mb 10ms DropTail

7 7 Routing n0n1 Addr Classifier Port Classifier classifier_ dmux_ entry_ 0 1 Addr Classifier Port Classifier classifier_ dmux_ entry_ 1 0 Link n0-n1 Link n1-n0

8 8 0 1 Transport n0n1 Addr Classifier Port Classifier classifier_ dmux_ entry_ 0 Agent/TCP agents_ Addr Classifier Port Classifier classifier_ dmux_ entry_ 1 0 Link n0-n1 Link n1-n0 0 Agent/TCPSink agents_ dst_=1.0 dst_=0.0 set tcp [new Agent/TCP] $ns attach-agent $n0 $tcp

9 9 Application 0 1 n0n1 Addr Classifier Port Classifier classifier_ dmux_ entry_ 0 Agent/TCP agents_ Addr Classifier Port Classifier classifier_ dmux_ entry_ 1 0 Link n0-n1 Link n1-n0 0 Agent/TCPSink agents_ dst_=1.0 dst_=0.0 Application/FTP set ftp [new Application/FTP] $tcp attach-agent $ftp

10 10 Packet Flow 0 1 n0n1 Addr Classifier Port Classifier entry_ 0 Agent/TCP Addr Classifier Port Classifier entry_ 1 0 Link n0-n1 Link n1-n0 0 Agent/TCPSink dst_=1.0 dst_=0.0 Application/FTP

11 11 Packet Format header data ip header tcp header rtp header trace header cmn header... ts_ ptype_ uid_ size_ iface_

12 12 Extending ns-2 Simulator

13 13 otcl and C++: The Duality C++ for data –per packet action otcl for control –periodic or triggered action C++ otcl

14 14 Adding New Classes C++ otcl New Class variablesprocedures New Class command() bind() TclClass() proceduresvariables

15 15 TclClass TclObject Agent Agent/Echo TclObject Agent EchoAgent NsObject ?? OTclC++ mirroring Static class TcpClass : public TclClass { public: TcpClass() : TclClass(“Agent/Echo”) {} TclObject* create(int, const char*const*) { return (new EchoAgent()); } } class_echo; Static class TcpClass : public TclClass { public: TcpClass() : TclClass(“Agent/Echo”) {} TclObject* create(int, const char*const*) { return (new EchoAgent()); } } class_echo;

16 16 TclObject: bind() C++ EchoAgent::TcpAgent() { bind(“msglen_”, &len_); … } otcl Agent/Echo set msglen_ 50

17 17 TclObject: command() C++ Int EchoAgent::command(int argc, const char*const* argv) { if (argc == 2) { if (strcmp(argv[1], “send”) == 0) { send(); return(TCL_OK); } else if (strcmp(argv[1], “recv”) == 0) { send(); return(TCL_OK); } return (Agent::command(argc, argv); } otcl set echo [new Agent/Echo] $echo send


Download ppt "1 ns-2 Tutorial, part 2 Dave Anderson, Xiaowei Yang (Modified from Polly Huang’s slides)"

Similar presentations


Ads by Google