1 / 58

Marco Di Felice

Network Modeling and Simulation with Network Simulator 2 ( ns2 ). Marco Di Felice. Department of Computer Science and Engineering University of Bologna. Italy difelice@cs.unibo.it. NS2 : Architecture and Design. NS2 : Use Cases and Features. NS2 : Building simple network models.

kuper
Download Presentation

Marco Di Felice

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Network Modeling and Simulation with Network Simulator 2 (ns2) Marco Di Felice Department of Computer Science and Engineering University of Bologna. Italy difelice@cs.unibo.it

  2. NS2: Architecture and Design NS2: Use Cases and Features NS2: Building simple network models NS2: Demo & Analysis Outline

  3. Ns2: An Overview NS2: A (discrete event) networksimulatortool. Generallyspeaking, a network simulator is a dedicated softwarethatallows to: • Modelthe behaviour of network protocols/applications(e.g. TCP protocol). • Reproducethe behaviour of a computer networkas a whole(e.g. a wireless LAN). • Quantifythe network performance, throughwell-definednetwork metrics(e.g. systemthroughput).

  4. Ns2: WHAT Q.Whenmay I use a network simulator? Case 1: Network planning • Need to build a network infrastructure, with coverage and Quality of Service (QoS) issues. Q1. Where to place the network gateways? Q2. How many gateways do I really need?

  5. Ns2: WHAT Q.Whenmay I use a network simulator? Case 2: Network Evaluation An example: Early Collision Detection Systems In VANETs • Need to evaluate the performance of a (possibly large-scale) network infrastructure or network application. • Use an existing testbed  BUT … Q1. What is the cost of setting up the experiments? Q2. Are the experiments easily reproducible?

  6. Ns2: WHAT Q.Whenmay I use a network simulator? Case 3: Researchon NetworkingSystems • Need to evaluate the performance of a new network protocol, architecture, or application. An example: Proposing a new TCP variant for wireless LANs. 1. A real deployment might not be feasible, or might be too costly. 2. Analytical models might be too complex to model all the components of the scenario under study.

  7. Ns2: WHAT • Network simulators might be used to model several kinds of networkingsystems (wired, wireless, optical, etc). • In practice, simulationconstitutes the main evaluation technique for wirelesssystems. • Possibility to build reproducible experiments (hard to guarantee with wireless testbeds). • Possibility to reproduce wireless propagation phenomena in an accurate way through probabilistic models (e.g. fading) • Possibility to model large-scale wireless networks composed by several interacting nodes.

  8. Ns2: WHAT • Simulation is a meaningful evaluation approach only when it produces “trustable” results. • Validation is needed to certify that the simulation models reproduce correctly the characteristics and dynamics of the system under study. • HOW to VALIDATE a NETWORK MODEL? • Compare Simulation vs AnalyticalModel • Compare Simulation vs RealMeasurements SIM. THROUGPUT EXPERIMENTS ANALYTICAL

  9. Ns2: WHAT • NS2: A network simulation tool • Discrete Eventsimulator(details later …) • NS2 allows to model and evaluate several IP networking systems(LAN/WAN). It includes: • Network protocols model(e.g. MAC, routing, …) • Network applications model (e.g. CBR, FTP, …) • Queue management algorithms (e.g. FIFO, RED, …) • Network link models (e.g. lossy link) • …

  10. Ns2: WHERE • http://www.isi.edu/nsnam/ns • http://sourceforge.net/projects/nsnam • download ns-allinone • includes several tools (ns2, nam, awk, otcl, …) • mailing list: ns-users@isi.edu • documentation: • Referencemanual and Tutorials on the website • Other tutorials on the Web

  11. Ns2: WHEN • The project started from REAL project in 1989 • ns-1 by Floyd and McCanne at Lawrance Berkeley National Laboratory (LBNL). • ns-2 by Steve McCanne, within the VINT project involving a consortium of US universities (LBL, PARC,USC, ...) • currently maintained at USC/ISI (University of Southern California), but several forks available. • NS3 relased in 2008 (now NS3.15) • Deployed by a team lead by Tom Henderson and Sally Floyd (University of Washington) • A completely new tool, not a mere extension of Ns2 !

  12. Ns2: WHY • NS2: A network simulation tool • Discrete Eventsimulator(details later …) OTHER SIMULATION TOOLS • OMNET++ • OPNET • JiST • NS3 • GLOMOSIM • … Q. WHY should I use NS2 for my research?

  13. Ns2: WHY • NS2 includes a vast modellibraryof network components. • Link Models: • Wired Links, • Wireless Links, • Satellite Links, … ApplicationLayer FTP, Telnet, HTTP, Multimedia, Exponential traffic, … TransportLayer UDP, TCP (Reno, NewReno, Vegas, SACK), … NetworkLayer Wired routing (RIP), Ad Hoc Routing (AODV, OLSR, DSR), … MACLayer Ethernet, 802.11 (WIFI), 802.15.4, Bluetooth, 802.16 (WIMAX), …

  14. Ns2: WHY • NS2 is distributed with GNU General Public Licence (GPL) • Collaborative deployment environment • possibility to freely modify the existing NS2 code based on each user’s needs. • possibility to share network models for research/education purposes (e.g. a new implementation of TCP). • possibility to compare his/her own model with models implemented by other research teams. • Multi-platform support • GNU/Linux, MAC OSX, Solaris, Windows, …

  15. Ns2: WHY • NS2 is a popular tool, widely adopted by researchers working on the field of computer networks. NumberofUsers: 10K Institutes: 1K % Papers: 44.4% MOBIHOC Conference: Statistics on toolsused to produce a simulationstudywithin the paperssubmittedat the ACM MOBIHOC conference (2000-2006).

  16. Ns2: WHY Q. WHYNOT to use NS2 for my research? • Performanceissues • Monolithic (basic) scheduler, scalability constitutes a big issue. • Architecturalissues • Not really a modular architecture, difficult to share the code of network models. • Evaluationissues • No support for the trace analysis. CPU time ? #nodes NS2 TRACE

  17. NS2: HOW • Two programming languages: C++ and OTCL. • OTCL for simulation setup and execution • Quickly define the simulation environment • C++ for model deployment • Implement the behaviour of a network component

  18. NS2: HOW • The core of the NS2 simulator is the Scheduler • Discrete-event scheduler. • Basic implementation, few optimization. Event in NS2 ID TYPE TIME HANDLER Packet sent NS2 Object + function name that should be invoked once the event is fired. Packet Events Timer Events Packet received Packet dropped Simulation time of the event

  19. NS2: HOW • The Scheduler manages the simulation event list. • The elements are the events of the simulation. • The list is ordered on the basis of the time field. E1 E2 E3 E4 E5 E6 SIMULATION TIME: t SIMULATION TIME: E1.time • At each simulation step: • The head element of the list is removed • The simulation time is set to E1.time • The eventhandler (E1.handler) is executed. 1 TYPE TIME HANDLER

  20. NS2: HOW • The Scheduler manages the simulation event list. • The elements are the events of the simulation. • The list is ordered on the basis of the time field. E2 E3 E4 E5 E6 E7 SIMULATION TIME: t SIMULATION TIME: E1.time • At each simulation step: • E1.handler is executed, and it might generate new events (e.g. E7), that are inserted into the event list (at a position denoted by E7.time) E1.HANDLER

  21. NS2: HOW • Let’s make an example on a network scenario … NODE A NODE B APPLICATION APPLICATION MAC MAC ETHERNET LINK SIMULATION TIME: 0 EVENT LIST • At t=0, the Application module of node A is invoked

  22. NS2: HOW • Let’s make an example on a network scenario … NODE A NODE B APPLICATION APPLICATION MAC MAC ETHERNET LINK SIMULATION TIME: 0 E1 EVENT LIST 1 Send 4 A.APPLICATION • A timer event is scheduled at time 4 by node A

  23. NS2: HOW • Let’s make an example on a network scenario … NODE A NODE B APPLICATION APPLICATION MAC MAC ETHERNET LINK SIMULATION TIME: 4 E2 E3 EVENT LIST 2 Recv 4.5 A.MAC 3 Send 8 A.APPLICATION

  24. NS2: HOW • Let’s make an example on a network scenario … NODE A NODE B APPLICATION APPLICATION MAC MAC ETHERNET LINK SIMULATION TIME: 4.5 E4 E3 EVENT LIST 4 Recv 5.0 B.MAC 3 Send 8 A.APPLICATION

  25. NS2: HOW • Let’s make an example on a network scenario … NODE A NODE B APPLICATION APPLICATION MAC MAC ETHERNET LINK SIMULATION TIME: 5 E5 E3 EVENT LIST 5 Recv 5.2 B.APPLICATION 3 Send 8 A.APPLICATION

  26. NS2: HOW • Let’s make an example on a network scenario … NODE A NODE B APPLICATION APPLICATION MAC MAC ETHERNET LINK SIMULATION TIME: 5.2 E3 EVENT LIST 3 Send 8 A.APPLICATION • The message is processed by Node B at time 5.2

  27. Ns2: HOW • Two ways of interactions: • Modify/Create a new network model • Network models: network protocols, applications, queue policies, network architecture models, etc. • Coding in C++ • Recompile at the end. • Configure/Run a network simulation • Coding in OTCL • Executed by an interpreter, no need to recompile. NOT EASY QUITE EASY

  28. Ns2: HOW • Running an OTCL script: • ns script-file.tcl [parameters] • Initialize the scheduler • Define the simulation parameters (e.g. start time) • Build the network topology • Generate the traffic load • Define the protocol stack used by each node • OTCL scripting language, OO-extension of TCL 

  29. Ns2: OTCL inside • Assign a value to a variable • set x 0 • Keyword $ returns the value of a variable • set y $x • Selection Statements if (if < expr > ... else ...) • if {$x == $y } { puts “Hello world” } • Iterative Statements • for {set i 0; $i < $x ; incr i}{puts “Hello world” } • Function Declaration • proc name_FUNCTION {par1, ...parn} {... return $x} OTCL Overview

  30. Ns2: HOW • Running an OTCL script: • ns script-file.tcl [parameters] • Initialize the scheduler • Define the simulation parameters (e.g. start time) • Build the network topology • Generate the traffic load • Define the protocol stack used by each node • OTCL scripting language, OO-extension of TCL 

  31. Ns2: Initialize the Scheduler • Creating the Event Scheduler • set ns [new Simulator] • Starting the simulation • $ns run • Initializing the random number generator • $ns-random SEED • Scheduling the events • $ns at <time> <event> • Stopping the simulation at time 300 • $ns at 300 "finish“ SEED=0  current timestamp All the random variable used by the current simulation are initialized with this SEED.

  32. Ns2: HOW • Running an OTCL script: • ns script-file.tcl [parameters] • Initialize the scheduler • Define the simulation parameters (e.g. start time) • Build the network topology • Generate the traffic load • Define the protocol stack used by each node • OTCL scripting language, OO-extension of TCL 

  33. Ns2: Building the network (WIRED) CASE 1. Modeling a wired network. • Define the nodes of the network • set n0 [$ns node] • set n1 [$ns node] • Define the Links among nodes • #Nodes connected with an Ethernet cable, 10 Mb/s • $ns duplex-link $n0 $n1 10Mb 100ms DropTail Specifies bandwidth, delay, and queue policy: DropTail, RED, CBQ, FQ, SFQ, DRR

  34. Ns2: Building the network (WIRED) CASE 1. Modeling a wired network. • Define the error model on wired links • set loss_module [new ErrorModel] • $loss_module set rate_ 0.1 • $loss_module ranvar [new RandomVariable/Uniform] • $loss_module drop-target [new Agent/Null] • $ns lossmodel $loss_module $n0 $n1 Lossy link between node 0 and node 1, with error rate equal to 0.1. Packets with errors are sent to Agent/Null, i.e. they are discarded.

  35. Ns2: Building the network (WIRED) CASE 1. Modeling a wireless network. • Define the nodes of the network • set n0 [$ns node] • set n1 [$ns node] • Define the position • set topograpy [new Topography] • $topography load_flatgrid 400 400 • Define the position • $n0 set X_ 300 • $n0 set Y_ 400 • $n0 set Z_ 0 Set simulation area to 400mx400m Set node 0 at position <300,400,0>

  36. Ns2: Building the network (WIRED) CASE 1. Modeling a wireless network. • Define the mobility of wireless nodes • NS_OBJ at TIME “NODE setdest X_COOR Y_COOR SPEED” • $ns at 10.5 “$node(0) setdest 100 100 5.0” At time 10.5, node 0 will move toward position (100,100) with speed equal to 5 m/s (constant speed) • Utilize the General Object Director (GOD) • set $god [new God] Object that stores global information about the state of the environment (e.g. the matrix of connectivity among nodes)

  37. Ns2: Building the network (WIRED) CASE 1. Modeling a wireless network. • The mobility traces of wireless nodes can be pre-generated by using the setdest tool (random waypoint model) • ./setdest [-n num_of_nodes] [-p pausetime] [-maxspeed] • [-t simtime] [-x][-y] > [fileOutput] • In the TCL script: source “fileOutput” • Any mobility simulator can be used for trace generation. MOBILITY SIMULATOR MOB. TRACE OTCL SCRIPT NS2 e.g. SUMO SOURCE

  38. Ns2: HOW • Running an OTCL script: • ns script-file.tcl [parameters] • Initialize the scheduler • Define the simulation parameters (e.g. start time) • Build the network topology • Generate the traffic load • Define the protocol stack used by each node • OTCL scripting language, OO-extension of TCL 

  39. Ns2: Creating connections (UDP/TCP) • Define the end-points of the communication • TCP Connections: • set src [new Agent/TCP] • set dst [new Agent/TCPSink] • UDP Connections: • set src [new Agent/UDP] • set dst [new Agent/Null] • Connect sender and receiver • $ns attach-agent $n0 $src • $ns attach-agent $n1 $dst • $ns connect $src $dst • Several TCP variants: • TCP Tahoe • TCP Reno • TCP NewReno • TCP Vegas • TCP SACK • …

  40. Ns2: Attaching Applications • Define the application and attach it to the sender • FTP Agent • set ftp [new Application/FTP] • $ftp attach-agent $src • $ns at TIME “$ftp start” • CBR Agent • set cbr [new Application/Traffic/CBR] • $cbr attach-agent $src • $ns at TIME “$cbr start” • Exponential Traffic Generator • set exp [new Application/Traffic/Exponential]

  41. Ns2: HOW • Running an OTCL script: • ns script-file.tcl [parameters] • Initialize the scheduler • Define the simulation parameters (e.g. start time) • Build the network topology • Generate the traffic load • Define the protocol stack used by each node • OTCL scripting language, OO-extension of TCL 

  42. Ns2: HOW • Awireless environment can be modeled by configuring the protocol stack of each node. • $ns_ node-config –phyType $val(netif) • -propType $val(prop) • -antType $val(type) • -llType $val(ll) • -macType $val(mac) • -ifqType $val(ifq) • -ifqLen $val(ifqlen) • -adhocRouting $val(rp) • -topoInstance $topo • -channel $chan_ NET LAYER QUEUE LL LAYER MAC LAYER ANTENNA PROPAGATION PHY LAYER

  43. Ns2: HOW • Awireless environment can be modeled by configuring the protocol stack of each node. • $ns_ node-config –phyType $val(netif) • -propType $val(prop) • -antType $val(type) • -llType $val(ll) • -macType $val(mac) • -ifqType $val(ifq) • -ifqLen $val(ifqlen) • -adhocRouting $val(rp) • -topoInstance $topo • -channel $chan_ NET LAYER QUEUE LL LAYER MAC LAYER ANTENNA PROPAGATION PHY LAYER

  44. Ns2: HOW • Configuring the PHY Layer • set val(netif) Phy/WirelessPhy[Ext] • Some parameters to be tuned: • Phy/WirelessPhy set Pt 2.07983391e-01 • Phy/WirelessPhy set RXThresh 2.591168e-08 • Phy/WirelessPhy set CSThresh 3.497734e-09 • Functionalities offered by the PHY Layers • Signal capture • Modulation & Bit-rate setting • Modeling of collision/transmission errors • …

  45. Ns2: HOW • Awireless environment can be modeled by configuring the protocol stack of each node. • $ns_ node-config –phyType $val(netif) • -propType $val(prop) • -antType $val(type) • -llType $val(ll) • -macType $val(mac) • -ifqType $val(ifq) • -ifqLen $val(ifqlen) • -adhocRouting $val(rp) • -topoInstance $topo • -channel $chan_ NET LAYER QUEUE LL LAYER MAC LAYER ANTENNA PROPAGATION PHY LAYER

  46. Ns2: HOW • Configuring the Propagation model • set val(prop) Propagation/TwoRayGround • set val(prop) Propagation/FreeSpace FREE SPACE TWORAY RECEIVER SENDER • Configuring the Antenna model • set val(antType) Antenna/OmniAntenna • set val(antType) Antenna/Directional OMNIDIRECTIONAL DIRECTIONAL

  47. Ns2: HOW • Awireless environment can be modeled by configuring the protocol stack of each node. • $ns_ node-config –phyType $val(netif) • -propType $val(prop) • -antType $val(type) • -llType $val(ll) • -macType $val(mac) • -ifqType $val(ifq) • -ifqLen $val(ifqlen) • -adhocRouting $val(rp) • -topoInstance $topo • -channel $chan NET LAYER QUEUE LL LAYER MAC LAYER ANTENNA PROPAGATION PHY LAYER

  48. Ns2: HOW • Configuring the LL layer • set val(ll) LL Include ARP protocol • Configuring the MAC model • set val(mac) Mac/802_11 • Select a MAC protocol: • 802.11 (Wifi) • 802.15.4 (Sensors) • CSMA/CA • … • Configuring the Queue Layer • set val(ifq) Queue/DropTail/PrimaryQueue • set val(ifqlen) 50 • Define the queue policy: • PrimaryQueue • RED Queue • … Set the queue length

  49. Ns2: HOW • Awireless environment can be modeled by configuring the protocol stack of each node. • $ns_ node-config –phyType $val(netif) • -propType $val(prop) • -antType $val(type) • -llType $val(ll) • -macType $val(mac) • -ifqType $val(ifq) • -ifqLen $val(ifqlen) • -adhocRouting $val(rp) • -topoInstance $topo • -channel $chan NET LAYER QUEUE LL LAYER MAC LAYER ANTENNA PROPAGATION PHY LAYER

  50. Ns2: HOW • Configuring the routing protocol • set val(adhocrouting) AODV • Select a routing protocol for multi-hop networks: • AODV, DSDV, DSR, TORA, …. SOURCE ROUTING PATH DESTINATION

More Related