Network Simulator ns-2. 2 Agenda Introduction Interface Tcl and OTcl TclCL Simulator Wired network Wireless network Program Assignment.

Slides:



Advertisements
Similar presentations
Wireless Communication : LAB 3
Advertisements

1 ns-2 Tutorial, part 2 Dave Anderson, Xiaowei Yang (Modified from Polly Huang’s slides)
1 NS Fundamentals (contd..) Padma Haldar USC/ISI.
Network Simulation One tool to simulation network protocols for the Internet is the network simulator (NS) The simulation environment needs to be set-
An Introduction to NS-2 * Gayatri Swamynathan CS 276 TA *some slides are from a presentation by Haobo Yu & Nader Salehi, USC/ISI.
NS-2 Shahin Shayandeh December 2004 Session 2. Ns programming  Create the event scheduler  Turn on tracing  Create network  Setup routing  Insert.
Brief Intro to ns2: The most widely used Network Simulator COMP5416 Advanced Network Technologies Based on: Marc Greis's
Ns-2 Tutorial Exercise (1) Multimedia Networking Group, The Department of Computer Science, UVA Jianping Wang Adopted from Nicolas’s slides Jianping Wang,
Ns-2 tutorial Karthik Sadasivam Banuprasad Samudrala CSCI 5931 Network Security Instructor : Dr. T. Andrew Yang.
Network Simulator (NS) Prof. Nelson L. S. da Fonseca State University of Campinas, Brazil.
How to Add a New Protocol in NS2 Xu Leiming CSCW Lab. at CS Dept., Tsinghua Univ. June 1, 2001.
5-Jul-141 S.Pushpalatha, Associate Professor, PSNACET.
Introduction to NS. Information Main website Documentation, mailing list archive, tutorial Location of Source codes –C++ files.
Introduction to Wireless simulations Shao-Cheng Wang.
Simulation of GPRS MS-BS Interface Using ns-Network Simulator Dual Degree Presentation by Richa Jain (96D07007) Department of Electrical Engineering, Indian.
15-744: Computer Networking ns-2 Tutorial Based on slides from John Heidemann, Polly Huang, and Amit Manjhi.
Network Simulator 2 Tejas Vasavada.
1 Network Simulator (NS-2). 2 講義 Network Simulator (NS2) Part 1: 下載 Part 2: 安裝與測試 Part 3: 劇本 Part 4: 數據.
Katz, Stoica F04 EECS 122 Introduction to Computer Networks (Fall 2003) Network simulator 2 (ns-2) Department of Electrical Engineering and Computer Sciences.
CprE 543x – ns-2 Tutorial Zak Abichar, Dept of Electrical and Computer Engineering Iowa State University Ames,
Day 3 Outline Multicast example (from Day 2) Wireless Misc. utilities
15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich.
Jump to first page NS Tutorial: mobile and wireless network simulation Ya Xu USC/ISI September 10th, 1999.
1 Network Simulator (NS-2) Tutorial These slides can be downloaded from:
EECS122 - UCB1 Measurements and Modeling Table of Contents 1. Measurements Measurements 2. Modeling and its Shortcomings Modeling and its Shortcomings.
Introduction to Network Simulator NS-2 Part II
NS2 Tutorial Aga Zhang Dependable Computing Lab. Outline Introduction Fundamental Skills - Tcl and OTcl Network Simulator - ns-2 Study Project - Mobile.
Network Simulator 2(NS2) Yingyue Xu 8/25/2015. Overview: The Network simulator (NS): discrete event simulator for networks. supports wired, wireless,
Network Simulator (NS2) 1 Tutorial on Network Simulator (NS2) Hemant Kumar Rath Infonet Lab, Dept of Electrical Engineering IIT Bombay, Mumbai
Wireless Networking and Systems CSE 590 ns2 tutorial.
Introduction to ns-2 Noun Choi Oct. 11, Outline Background ns-2 Internals Short demo Troubleshooting Reference links Q & A.
Introduction to NS2 -Network Simulator- -Prepared by Changyong Jung.
1 Introduction to Ns-2 Zhibin WU WINLAB, ECE Dept. Rutgers U.
1 / 10 Mobile Networking in ns Speaker : Mark Yang
NS2 Tutorial for CS740 Jianming Wu *modified from Aga Zhang.
Introduction to Mobility & Network Simulator 2 (NS-2)
NS2 - Wireless Network Ming-Feng Yang. 2 2 Outline Basic wireless model Extensions wireless model Example - Ad hoc network Example – WLAN Example – Mobile.
Define options(1/2) #channel type set val(chan) Channel/WirelessChannel # radio-propagation model set val(prop) Propagation/TwoRayGround # network interface.
MOBILE IP SOMULATION IN NS2 Presenter: 吳寶緣. Outlines  Overview  Hierarchical Address Format  Hierarchical Address Format-ex  MoblieIP Demo  Additional.
NS2 - Appendix Ming-Feng Yang. 2 2 Outline NS2 Models NS2 Directory Structure Extending NS2 in OTcl Extending NS2 in C++ NS2 related links.
JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY Network Simulator – NS-2 1.
Network Simulator-2 Sandeep singla 1998A2A7540. NS-2 A discrete event simulator Focused on modeling network protocols –Wired, wireless –TCP,UDP,unicast,multicast.
1 Network Simulator Tutorial. 2 Network Simulation * Motivation: Learn fundamentals of evaluating network performance via simulation Overview: fundamentals.
Internet Computing KUT Youn-Hee Han
NS-2 Tutorial. Motivation What’s NS-2 Network simulator –Discrete event simulator It covers multiple layers –Application layer, transport layer, network.
Quality evaluation of MPEG4 video transmission over GPRS networks.. Presented by: Abdullah M. Rana Multimedia Communication.
1 Network Simulation and Testing Polly Huang EE NTU
1 NS Fundamentals. USC INFORMATION SCIENCES INSTITUTE 2 OTcl and C++: The Duality C++ OTcl Pure C++ objects Pure OTcl objects C++/OTcl split objects ns.
Ns-2 Tutorial (1) Multimedia Networking Group, The Department of Computer Science, UVA Jianping Wang Jianping Wang, 2002 cs757 1.
1 Introduction to NS-2 r Tutorial overview of NS m Create basic NS simulation r Walk-through a simple example m Model specification m Execution and trace.
1 ns-2 Tutorial Polly Huang AT&T Labs Research 11 August, 1999.
Lab 2, Network Simulator ns2 Shiv Kalyanaraman Yong Xia (TA) Satish Raghunath Sept 4,
Network Simulator Tutorial Wireless Networks. Acknowledgements Material is taken from the presentations by Jim Kurose, University of Massachusetts, Amherst.
CDA6530: Performance Models of Computers and Networks Chapter 10: Introduction to Network Simulator (NS2) TexPoint fonts used in EMF. Read the TexPoint.
1 Part II: ns Internals. USC INFORMATION SCIENCES INSTITUTE 2 Outline Fundamental concept Split object: C++/OTcl linkage Plumbing Wired Wireless Scaling.
The Creation of NS2 Simulated Environment ( 1 ) LI Chengbo
TNK092: Network Simulation - Nätverkssimulering Lecture #1: Course basics and a first taste of NS2 Vangelis Angelakis Ph.D.
NS-2 Shahin Shayandeh December 2004 Session 1. Ns-2, the Network Simulator  A discrete event simulator Simple model  Focused on modeling network protocols.
Lab 2, Network Simulator ns2
1 NS-2: the network simulator 15 September 2005 Network Lab., SNU Changjee Joo.
DMET 602: Networks and Media Lab Amr El Mougy Yasmeen EssamAlaa Tarek.
Ch7: Link and Buffer Management. 2 Portrait of A Mobile Node Node ARP Propagation and antenna models MobileNode LL MAC PHY LL CHANNEL LL MAC PHY Classifier:
NS-2 Simulator 최 종 훈 Contents  About NS  Installation  Based on Linux  Based on Windows  Architecture  Using NS-2  Example  References.
ECE 6610 Sandeep Kakumanu GNAN research Lab
DMET 602: Networks and Media Lab
(Modified from Polly Huang’s and last year’s original)
Introduction to ns-2: “The” Network Simulator
Karthik Sadasivam Banuprasad Samudrala
Introduction to ns-2 Noun Choi Oct. 11, 2007.
TexPoint fonts used in EMF.
Presentation transcript:

Network Simulator ns-2

2 Agenda Introduction Interface Tcl and OTcl TclCL Simulator Wired network Wireless network Program Assignment

3 Introduction NS-2: network simulator version 2 Discrete event simulator Packet level simulation Features Open source Scheduling, routing and congestion control Wired networks: P2P links, LAN Wireless networks: terrestrial (ad-hoc, cellular; GPRS, UMTS, WLAN, Bluetooth), satellite Emulation and trace

4 NS-2: Paradigm Object-oriented programming Protocol layering Modularity and extensibility Large scale simulation Maintenance and reusability Split-language programming Scripting language (Tcl) System programming language (C)

5 NS-2: Split Languages Tcl scripts (Tcl/OTcl) Interpreted (interactive) Setup and configuration C codes (C/C++) Compiled (efficient) Algorithms and protocols TclCL (OTcl/C++) Link Tcl/OTcl scripts and C/C++ codes Provide a layer of C++ glue over OTcl

6 NS-2: Split Objects OTcl C++ Pure OTcl objects Pure C++ objects OTcl/C++ split objects NS-2 TclCL linkage

7 NS-2: A Tcl Script Example /home>ns abc.tcl /home>abc.tcl #!/home/hsieh/ns-allinone-2.27/bin/ns set ns [new Simulator] set nf [open out.tr w] $ns trace-all $nf for {set i 0} {$i<2} {incr i} {;# create the nodes set n($i) [$ns node] } $ns duplex-link $n(0) $n(1) 1Mb 10ms DropTail # Create a UDP agent set udp(src) [new Agent/UDP] $udp(src) set packetSize_ 500 $ns attach-agent $n(0) $udp(src) proc finish {} { global ns nf $ns flush-trace; close $nf } $ns at 5.0 "finish" $ns run

8 NS-2: A C++ Code Example static class UdpAgentClass : public TclClass { public: UdpAgentClass() : TclClass("Agent/UDP") {} TclObject* create(int, const char*const*) { return (new UdpAgent()); } } class_udp_agent; UdpAgent::UdpAgent() : Agent(PT_UDP), seqno_(-1) { bind("packetSize_", &size_); } void UdpAgent::sendmsg(int nbytes, AppData* data, const char* flags) { Packet *p; p = allocpkt(); hdr_cmn::access(p)->size() = size_; hdr_rtp::access(p)->seqno() = ++seqno_; p->setdata(data); target_->recv(p); }

9 TclCL: Class TclObject Base class in NS-2 for split objects Mirrored in both C++ (TclObject) and OTcl (SplitObject) Usage Instantiation, bind and command Example set tcp [new Agent/TCP] $tcp set window_ 30 $tcp advanceby 5000

10 Class TclObject: Hierarchy SplitObject Agent Agent/TCP OTcl object _o123 Agent/TCP C++ object *tcp TclObject Agent TcpAgent OTcl class hierarchy C++ class hierarchy Connector

11 Class TclObject: Binding Bi-directional variable bindings Link C++ member variables (compiled) to OTcl instance variables (interpreted) Initialization through the closest OTcl class variable Agent/TCP set window_ 50 Do all initialization of bound variables in ~ns/tcl/lib/ns-default.tcl Otherwise a warning will be issued when the shadow compiled object is created

12 Class TclObject: Binding C++ TcpAgent::TcpAgent() { bind(“window_”, &wnd_); … } bind(), bind_time(), bind_bool(), bind_bw() OTcl Agent/TCP set window_ 50 set tcp [new Agent/TCP] $tcp set window_ 100

13 Class TclObject: Command Invoke C++ compiled functions through OTcl interpreted methods A way of implementing OTcl methods in C++ Hook point Tcl method unknown{} OTcl method cmd{} Send all arguments after cmd{} call to TclObject::command() Use Tcl::resultf() in C++ to pass back results

14 Class TclObject: Command $tcp cmd send match “send”? Invoke parent: return Agent::command() process and return Yes No OTcl space C++ space no such procedure SplitObject::unknown{} $tcp send TcpAgent::command()

15 Class TclObject: Command OTcl set tcp [new Agent/TCP] $tcp advance 100 C++ int TcpAgent::command(int argc, const char*const* argv) { if (argc == 3) { if (strcmp(argv[1], “advance”) == 0) { int newseq = atoi(argv[2]); …… return TCL_OK; } return (Agent::command(argc, argv); }

16 TclCL: Summary Class TclObject Unified interpreted (OTcl) and compiled (C++) class hierarchies Seamless access (procedure call and variable access) between OTcl and C++ Class TclClass Mechanism that makes TclObject work Class Tcl Primitives to access OTcl interpreter

17 NS-2: Directory Structure TK8OTclTclCLTcl8ns-2nam-1 tcl extest lib... examples validation tests C++ code OTcl code ns-allinone mcast... (ftp://ftp.isi.edu/nsnam/ns-allinone-2.30.tar.gz)

Network Simulator ns-2 Part II: Wired Network

19 Class Hierarchy TclObject NsObject ConnectorClassifier Delay PortClassifier Agent AddrClassifier QueueTrace DropTailREDTCPEnqDeqDrop RenoSACK Vegas Process Application Node FTP target_ recv() Scheduler

20 Simulation Elements Create the event scheduler (simulator) [Setup tracing] Create network topology [Setup routing] [Insert error modules/network dynamics] Create connection (transport) Create traffic (application) Start the scheduler Post-process data

21 Event Scheduler Create event scheduler set ns [new Simulator] Schedule events (OTcl) OTcl: $ns at C++: Scheduler::schedule(h,e, delay) Obtain simulation time OTcl: $ns now C++: Scheduler::clock() Start scheduler $ns run The last line of your OTcl script

22 Trace Trace packets on all links $ns trace-all [open nstr.out w] cbr cbr cbr cbr r cbr r cbr $ns namtrace-all [open namtr.out w] Turn on tracing on specific links $ns trace-queue $n0 $n1 $ns namtrace-queue $n0 $n1 Output trace to /dev/null if not desired

23 Network Topology Nodes set n0 [$ns node] set n1 [$ns node] Links and queues $ns duplex-link $n0 $n1 \ queue : DropTail, RED, CBQ, FQ, … Link delay = f ( bandwidth, delay ) = packet transmission time + propagation delay

24 Network Topology: Node n0n1 Addr Classifier Port Classifier classifier_ dmux_ entry_ Node entry Unicast Node Multicast Node Multicast Classifier classifier_ dmux_ entry_ Node entry multiclassifier_

25 Network Topology: Link n0n1 enqT_queue_deqT_ drophead_ drpT_ link_ttl_ n1 entry_ head_ tracing simplex link duplex link

26 Routing Unicast routing $ns rtproto type : Static (default), Session, DV, LS, Manual nodes : default entire topology Default static routing Dijkstra’s all-pairs shortest path first algorithm Route calculation is done before simulation starts Link cost $ns cost $n0 $n1 default link cost = 1

27 Routing n0n1 Addr Classifier Port Classifier classifier_ dmux_ entry_ Node entry 0 1 enqT_queue_deqT_ drophead_ drpT_ link_ttl_ n1 entry_ head_

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

29 Transport: TCP TCP set tcp [new Agent/TCP] set tcpsink [new Agent/TCPSink] $ns attach-agent $n0 $tcp $ns attach-agent $n1 $tcpsink $ns connect $tcp $tcpsink Use create-connection{} Customization $agent set fid $agent set packetSize_

30 Transport 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

31 Application FTP set ftp [new Application/FTP] $ftp attach-agent $tcp $tcp attach-app FTP CBR set cbr [new Application/Traffic/CBR] $cbr set packetSize_ 1000 $cbr set rate_ Start traffic generation $ns at “$app start”

32 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

33 Packet Packets are events Can be scheduled to “arrive” Packets contain header section and data Header section is a cascade of all in-use headers Each packet contains a common header packet size (used to compute transmission time) packet type timestamp, uid, … All in-use headers are included when simulation starts Change packet size to reflect header cascading

34 Packet Header header data ip header tcp header rtp header trace header cmn header... ts_ ptype_ uid_ size_ iface_ Example: Get the pointer to the common header: p->access(hdr_cmn::offset_) or, HDR_CMN(p)

35 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

36 Recap NsObject: generic receive method recv() for packet reception Connector: one neighbor target_ Node: collection of classifiers and agents Link: encapsulation of queue and delay Classifier: packet demultiplexer (routing) Agent: protocol endpoint or implementation of routing protocol Application: traffic generation

Network Simulator ns-2 Part III: Wireless Network

38 Wireless Network Wireless network Nodes can move No explicit “links” used to connect nodes Wireless network extension Mobile node Wireless channel and propagation model Packet headers Topology and movement Routing and forwarding

39 Class Hierarchy TclObject NsObject Connector Channel WirelessChannel Node BiConnector Phy MobileNode WirelessPhy MAC Delay LL Propagation TwoRayGround uptarget_ downtarget_

40 Mobile Node: Portrait Node Propagation and antenna models MobileNode LL MAC PHY LL CHANNEL LL MAC PHY Classifier: Forwarding Node Entry Agent: Protocol entity LL: Link layer object IFQ: Interface queue MAC: MAC object PHY: Network interface protocol agent routing agent addr classifier port classifier 255 IFQ defaulttarget_ ARP

41 Example: Ad Hoc Network Scenario 3 mobile nodes Move within a 670m*670m flat topology DSR ad hoc routing protocol Random waypoint mobility model UDP and CBR traffic

42 An Example – Step 1 # Create simulator set ns [new Simulator] # Create a topology in a 670m x 670m area set topo [new Topography] $topo load_flatgrid # ns trace and nam trace $ns trace-all [open ns.tr w] $ns namtrace-all-wireless [open ns.nam w]

43 An Example – Step 2 # Create God set god [create-god 3] God: General Operations Director Keep the number of nodes in the network Called by MAC to keep a sequence number cache of all nodes Store an array of the smallest number of hops required to reach one node to another Used for setdest operation $ns at “$god set-dist 2 3 1”

44 An Example – Step 3 # Define how to create a mobile node $ns node-config \ -adhocRouting DSR \ -llType LL \ -macType Mac/802_11 \ -ifqLen 50 \ -ifqType Queue/DropTail/PriQueue \ -phyType Phy/WirelessPhy \ -antType Antenna/OmniAntenna \ -propType Propagation/TwoRayGround \ -channel [new Channel/WirelessChannel] \ -topoInstance $topo -agentTrace ON \ -routerTrace OFF \ -macTrace OFF \ -movementTrace OFF

45 Energy Parameters $ns node-config \ –energyModel EnergyModel \ -initialEnergy100.0 \ -txPower0.6 \ -rxPower0.2 Node is energy-aware Node status: on / off / sleep Pt_ and Pt_consume_

46 An Example – Step 4 # Create mobile nodes for {set i 0} {$i<3} {incr i} { set node($i) [$ns node] # disable random motion for static network $node($i) random-motion 0 } # Define movement model (if applicable) source movement-scenario-files # Define traffic model (if applicable) source traffic-scenario-files

47 Scenario: Movement Mobile movement generator ~ns/indep-utils/cmu-scen-gen/setdest/setdest setdest -n setdest -n -p -s -p -s -t -x -y -t -x -y Random movement $node random-motion 1 $node start Change POSITION_UPDATE_INTERVAL and MAX_SPEED internally

48 A Movement File $node_(0) set X_ 83.4 $node_(0) set Y_ $node_(0) set Z_ 0.0 $node_(1) set X_ $node_(1) set Y_ $node_(1) set Z_ 0.0 $node_(2) set X_ $node_(2) set Y_ $node_(2) set Z_ 0.0 $ns_ at 33.0 "$node_(0) setdest “ $ns_ at 51.0 "$node_(1) setdest " $ns_ at 50.0 "$node_(2) setdest "

49 Scenario: Traffic Traffic pattern generator CBR (UDP) or FTP (TCP) traffic ~ns/indep-utils/cmu-scen-gen/cbrgen.tcl ns cbrgen.tcl [-type cbr|tcp] [-nn nodes] [-seed seed] [-mc connections] [-rate rate] Specify in the OTcl script Same as the wired network scenario

50 A Traffic Scenario set udp_(0) [new Agent/UDP] $ns_ attach-agent $node_(0) $udp_(0) set null_(0) [new Agent/Null] $ns_ attach-agent $node_(2) $null_(0) set cbr_(0) [new Application/Traffic/CBR] $cbr_(0) set packetSize_ 1000 $cbr_(0) set interval_ 4.0 $cbr_(0) set random_ 1 $cbr_(0) set maxpkts_ $cbr_(0) attach-agent $udp_(0) $ns_ connect $udp_(0) $null_(0) $ns_ at 20.0 "$cbr_(0) start"

51 An Example – Step 5 # Define node initial position in nam for {set i 0} {$i < 3} {incr i} { $ns initial_node_position $node($i) 20 } # Tell ns/nam the simulation stop time $ns at “$ns nam-end-wireless 100.0” $ns at “$ns halt” # Start your simulation $ns run

52 Summary NS-2 is an open source, discrete event, and packet level network simulator NS-2 is written in C++ with OTcl interpreter as a front end TclCL provides linkage for class hierarchy, object instantiation, variable binding and command dispatching NS-2 provides abundant implementations of protocols used in wired and wireless networks

53 Random Variable Test the following script Change pareto to exponential distribution.

54 M/M/1 Queueing System Arrival: Poisson arrival with rate Service: Packet size is exponential distribution (average tx duration is  )  = /  Average number of packet in the queue is  /(1-  ). Compare the theoretical value and simulation results.

55 Many TCP Many TCP (Agent/TCP/Newreno) sessions sharing a bottleneck link and single destination (D) Draw queue size of node BN every 0.1s. Draw throughput of each TCP sessions every 0.1s. S S S BND 1Mbps TCP

56 TCP over DSDV 3 node ad-hoc simulation Channel: wireless channel Propagation: Tworayground Mac: Queue: priority queue Routing protocol: DSDV Topology: 400mx500m Position of nodes: n0(5,5), n1(490,285), n2(150,240) TCP sender at n0 and receiver at n2 Draw TCP window size

57 NS2 Installation Guidelines Downloading NS2 is available from Download the ns-allinone package, ns-allinone-2.30.tar.gzns-allinone-2.30.tar.gz Installing NS2 Go to directory of downloaded ns-allinone.tar.gz Unpack the file using: tar -xzvf ns-allinone-2.30.tar.gz Go to the ns-allinone directory: cd ns-allinone-2.30 Install it with the command./install How to run ns2 Type./ns [filename].tcl

58 NS2 Useful Links Network Simulator NS-2 NS-2 Homepage ( NS-2 Manual ( documentation.html) Getting started with NS-2 Marc Greis's tutorial ( NS by example ( NS2 for beginners ( ) OTcl (ftp://ftp.tns.lcs.mit.edu/pub/otcl/doc/tutorial.html)

59 References The ns Manual, January 2002 IEC ns workshop slides, June 2000 First ns workshop slides, September 1997 Wetherall and Lindblad, “Extending Tcl for Dynamic Object-Oriented Programming,” Proceedings of the Tcl/Tk Workshop, 1995 Welch, “Practical Programming in Tcl and Tk”, Prentice-Hall, 1995 Ousterhout, “Tcl and the Tk Toolkit,” Addison-Wesley, 1994