58
Marco Di Felice NS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering University of Bologna. Italy [email protected]

Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Embed Size (px)

Citation preview

Page 1: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Marco Di Felice

Network Modeling and Simulation with Network Simulator 2 (ns2)

Department of Computer Science and Engineering

University of Bologna. Italy

[email protected]

Page 2: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Outline

NS2: Architecture and Design

NS2: Use Cases and Features

NS2: Building simple network models

NS2: Demo & Analysis

Page 3: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: An Overview

NS2: A (discrete event) network simulator tool. NS2: A (discrete event) network simulator tool.

Generally speaking, a network simulator is a dedicated software that allows to:

Model the behaviour of network protocols/applications (e.g. TCP protocol).

Reproduce the behaviour of a computer network as a whole (e.g. a wireless LAN).

Quantify the network performance, through well-defined network metrics (e.g. system throughput).

Page 4: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: WHAT

Q. When may I use a network simulator? Q. When may I use a network simulator?

Case 1: Network planningCase 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?

Page 5: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: WHAT

Q. When may I use a network simulator? Q. When may I use a network simulator?

Case 2: Network EvaluationCase 2: Network Evaluation

Need to evaluate the performance of a (possibly large-scale) network infrastructure or network application.

Use an existing testbed BUT …

Q2. Are the experiments easily reproducible?

Q1. What is the cost of setting up the experiments?

An example: Early Collision Detection Systems In VANETs

Page 6: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: WHAT

Q. When may I use a network simulator? Q. When may I use a network simulator?

Case 3: Research on Networking SystemsCase 3: Research on Networking Systems

Need to evaluate the performance of a new network protocol, architecture, or application.

2. Analytical models might be too complex to model all the components of the scenario under study.

1. A real deployment might not be feasible, or might be too costly.

An example: Proposing a new TCP variant for wireless LANs.

Page 7: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: WHAT

Network simulators might be used to model several kinds of networking systems (wired,

wireless, optical, etc).

In practice, simulation constitutes the main evaluation technique for wireless systems.

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.

Page 8: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

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 Analytical Model

Compare Simulation vs Real Measurements

SIM.THROUGPUT

ANALYTICALEXPERIMENTS

Page 9: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: WHAT

NS2: A network simulation tool

Discrete Event simulator (details later …)

NS2: A network simulation tool

Discrete Event simulator (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)…

Page 10: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

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: [email protected]

documentation:

Reference manual and Tutorials on the website

Other tutorials on the Web

Page 11: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

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 !

Page 12: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: WHY

NS2: A network simulation tool

Discrete Event simulator (details later …)

NS2: A network simulation tool

Discrete Event simulator (details later …)

OMNET++ OPNET JiST NS3 GLOMOSIM …

OTHER SIMULATION TOOLS

Q. WHY should I use NS2 for my research?Q. WHY should I use NS2 for my research?

Page 13: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: WHY

MAC LayerMAC Layer

Network LayerNetwork Layer

Transport LayerTransport Layer

Application LayerApplication Layer

Ethernet, 802.11 (WIFI), 802.15.4, Bluetooth, 802.16 (WIMAX), …

Wired routing (RIP), Ad Hoc Routing (AODV, OLSR, DSR), …

UDP, TCP (Reno, NewReno, Vegas, SACK), …

FTP, Telnet, HTTP, Multimedia, Exponential traffic, …

Link Models:Wired Links,Wireless Links,Satellite Links, …

Link Models:Wired Links,Wireless Links,Satellite Links, …

NS2 includes a vast model library of network components. NS2 includes a vast model library of network components.

Page 14: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: WHY

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, …

NS2 is distributed with GNU General Public Licence (GPL) NS2 is distributed with GNU General Public Licence (GPL)

Page 15: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: WHY

MOBIHOC Conference: Statistics on tools used to produce a simulation study within the papers submitted at the ACM MOBIHOC conference (2000-2006).MOBIHOC Conference: Statistics on tools used to produce a simulation study within the papers submitted at the ACM MOBIHOC conference (2000-2006).

Number of Users: 10KNumber of Users: 10K

Institutes: 1KInstitutes: 1K

% Papers: 44.4%% Papers: 44.4%

NS2 is a popular tool, widely adopted by researchers working on the field of computer networks.

NS2 is a popular tool, widely adopted by researchers working on the field of computer networks.

Page 16: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: WHY

Q. WHY NOT to use NS2 for my research?Q. WHY NOT to use NS2 for my research?

Performance issues Monolithic (basic) scheduler,

scalability constitutes a big issue.

Architectural issues Not really a modular architecture,

difficult to share the code of network models.

Evaluation issues No support for the trace analysis.

#nodes

CP

U t

ime

?

NS2NS2TRACE

Page 17: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

NS2: HOW

OTCL for simulation setup and execution Quickly define the simulation environment

C++ for model deployment Implement the behaviour of a network component

Two programming languages: C++ and OTCL. Two programming languages: C++ and OTCL.

Page 18: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

NS2: HOW

The core of the NS2 simulator is the Scheduler The core of the NS2 simulator is the Scheduler

Discrete-event scheduler.

Basic implementation, few optimization.

Event in NS2 IDID TYPETYPE TIMETIME HANDLERHANDLER

TimerEvents

PacketEvents

NS2 Object+ function name

that should be invoked once the

event is fired.

Simulation time of the event

Packet sent

Packet received

Packet dropped

Page 19: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

NS2: HOW

The Scheduler manages the simulation event list. 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 E6SIMULATION

TIME: t

At each simulation step:

1.The head element of the list is removed2.The simulation time is set to E1.time3.The event handler (E1.handler) is executed.

11 TYPETYPE TIMETIME HANDLERHANDLER

SIMULATION TIME: E1.time

Page 20: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

NS2: HOW

The Scheduler manages the simulation event list. 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 E7SIMULATION

TIME: t

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)

SIMULATION TIME: E1.time

E1.HANDLERE1.HANDLER

Page 21: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

NS2: HOW

Let’s make an example on a network scenario … Let’s make an example on a network scenario …

NODE A NODE B

APPLICATIONAPPLICATION

MACMAC

APPLICATIONAPPLICATION

MACMACETHERNETLINK

SIMULATION TIME: 0

EVENT LIST

At t=0, the Application module of node A is invoked

Page 22: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

NS2: HOW

Let’s make an example on a network scenario … Let’s make an example on a network scenario …

NODE A NODE B

APPLICATIONAPPLICATION

MACMAC

APPLICATIONAPPLICATION

MACMACETHERNETLINK

SIMULATION TIME: 0

EVENT LIST

A timer event is scheduled at time 4 by node A

11 SendSend 44 A.APPLICATIONA.APPLICATION

E1

Page 23: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

NS2: HOW

Let’s make an example on a network scenario … Let’s make an example on a network scenario …

NODE A NODE B

APPLICATIONAPPLICATION

MACMAC

APPLICATIONAPPLICATION

MACMACETHERNETLINK

SIMULATION TIME: 4

EVENT LIST

22 RecvRecv 4.54.5 A.MACA.MAC

E2 E3

33 SendSend 88 A.APPLICATIONA.APPLICATION

Page 24: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

NS2: HOW

Let’s make an example on a network scenario … Let’s make an example on a network scenario …

NODE A NODE B

APPLICATIONAPPLICATION

MACMAC

APPLICATIONAPPLICATION

MACMACETHERNETLINK

SIMULATION TIME: 4.5

EVENT LIST

44 RecvRecv 5.05.0 B.MACB.MAC

E4 E3

33 SendSend 88 A.APPLICATIONA.APPLICATION

Page 25: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

NS2: HOW

Let’s make an example on a network scenario … Let’s make an example on a network scenario …

NODE A NODE B

APPLICATIONAPPLICATION

MACMAC

APPLICATIONAPPLICATION

MACMACETHERNETLINK

SIMULATION TIME: 5

EVENT LIST

55 RecvRecv 5.25.2 B.APPLICATIONB.APPLICATION

E5 E3

33 SendSend 88 A.APPLICATIONA.APPLICATION

Page 26: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

NS2: HOW

Let’s make an example on a network scenario … Let’s make an example on a network scenario …

NODE A NODE B

APPLICATIONAPPLICATION

MACMAC

APPLICATIONAPPLICATION

MACMACETHERNETLINK

SIMULATION TIME: 5.2

EVENT LIST

E3

33 SendSend 88 A.APPLICATIONA.APPLICATION

The message is processed by Node B at time 5.2

Page 27: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

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.

QUITE EASY

NOT EASY

Page 28: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

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

Page 29: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

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 OverviewOTCL Overview

Page 30: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

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

Page 31: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

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.

Page 32: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

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

Page 33: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: Building the network (WIRED)

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

CASE 1. Modeling a wired network.CASE 1. Modeling a wired network.

Page 34: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: Building the network (WIRED)

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.

CASE 1. Modeling a wired network.CASE 1. Modeling a wired network.

Page 35: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: Building the network (WIRED)

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

CASE 1. Modeling a wireless network.CASE 1. Modeling a wireless network.

Set node 0 at position <300,400,0>

Set simulation areato 400mx400m

Page 36: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: Building the network (WIRED)

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”

CASE 1. Modeling a wireless network.CASE 1. Modeling a wireless network.

At time 10.5, node 0 will move towardposition (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)

Page 37: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: Building the network (WIRED)

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”

CASE 1. Modeling a wireless network.CASE 1. Modeling a wireless network.

Any mobility simulator can be used for trace generation.

MOB.TRACE

MOBILITYSIMULATOR

MOBILITYSIMULATOR

OTCLSCRIPT

NS2NS2

e.g. SUMO SOURCE

Page 38: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

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

Page 39: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

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 TahoeTCP RenoTCP NewRenoTCP VegasTCP SACK…

Page 40: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

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]

Page 41: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

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

Page 42: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: HOW

A wireless 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_

PHY LAYERPHY LAYER

ANTENNA PROPAGATION

MAC LAYERMAC LAYER

NET LAYERNET LAYER

QUEUEQUEUE

LL LAYERLL LAYER

Page 43: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: HOW

A wireless 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_

PHY LAYERPHY LAYER

ANTENNA PROPAGATION

MAC LAYERMAC LAYER

NET LAYERNET LAYER

QUEUEQUEUE

LL LAYERLL LAYER

Page 44: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: HOW

Configuring the PHY Layer

set val(netif) Phy/WirelessPhy[Ext]

Some parameters to be tuned:

Phy/WirelessPhy set Pt 2.07983391e-01Phy/WirelessPhy set RXThresh 2.591168e-08Phy/WirelessPhy set CSThresh 3.497734e-09

Functionalities offered by the PHY Layers

Signal capture Modulation & Bit-rate setting Modeling of collision/transmission errors …

Page 45: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: HOW

A wireless 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_

PHY LAYERPHY LAYER

ANTENNA PROPAGATION

MAC LAYERMAC LAYER

NET LAYERNET LAYER

QUEUEQUEUE

LL LAYERLL LAYER

Page 46: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: HOW

Configuring the Propagation model

set val(prop) Propagation/TwoRayGroundset val(prop) Propagation/FreeSpace

FREE SPACE

TWORAY

SENDER RECEIVER

Configuring the Antenna model

set val(antType) Antenna/OmniAntennaset val(antType) Antenna/Directional

DIRECTIONAL OMNIDIRECTIONAL

Page 47: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

A wireless 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

Ns2: HOW

PHY LAYERPHY LAYER

ANTENNA PROPAGATION

MAC LAYERMAC LAYER

NET LAYERNET LAYER

QUEUEQUEUE

LL LAYERLL LAYER

Page 48: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: HOW

Configuring the LL layer

set val(ll) LL

Configuring the MAC model

set val(mac) Mac/802_11

Include ARP protocol

Select a MAC protocol:802.11 (Wifi)802.15.4 (Sensors)CSMA/CA… Configuring the Queue Layer

set val(ifq) Queue/DropTail/PrimaryQueueset val(ifqlen) 50

Define the queue policy:PrimaryQueueRED Queue…

Set the queue length

Page 49: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: HOW

A wireless 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

PHY LAYERPHY LAYER

ANTENNA PROPAGATION

MAC LAYERMAC LAYER

NET LAYERNET LAYER

QUEUEQUEUE

LL LAYERLL LAYER

Page 50: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: HOW

Configuring the routing protocol

set val(adhocrouting) AODV

Select a routing protocol for multi-hop networks:AODV, DSDV, DSR, TORA, ….

SOURCE

DESTINATIONROUTING PATH

Page 51: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

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.

QUITE EASY

NOT EASY

Page 52: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: HOW

In C++, each model extends the class NSObject.

Each NSObject has a correspective in OTCL.

Page 53: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: HOW

When creating a new model in C++:

Extend the NSObject class

Create the corresponding OTCL class

Implement these methods

recv(Packet* p, Handler* h) Callback once a packet is received from the upper layer.

command(int argc, const char*const* argv) Binding between C++ and OTCL for the parameter passing from the TCL script.

Page 54: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: Simulation Output (TRACE)

The output of the simulation is a trace file, containing the description of the events occurred during the simulation.

s 10.00000 0 MAC --- 0 RTS 44 [253e 1 0 0]r 10.00041 1 MAC --- 0 RTS 44 [253e 1 0 0]s 10.00042 1 MAC --- 0 CTS 38 [2404 0 0 0]r 10.00075 0 MAC --- 0 CTS 38 [2404 0 0 0]s 10.00076 0 MAC --- 100 cbr 1112 [13a 1 0 800]r 10.00982 1 MAC --- 100 cbr 1112 [13a 1 0 800]

Simulation Time

Event Type

NodePacket

ID

Traffictype

Packetsize

MAC Header

Page 55: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: Simulation Output (TRACE)

Depending on the length of the simulation, the trace file might occupy lots of bytes on the disk.

$ns_ node-config –agentTrace ON/OFF -routerTrace ON/OFF

-macTrace ON/OFF -mobilityTrace ON/OFF

Configure the granularity of the tracing process …

s 10.00078 1 AGT --- 100 cbr 1112 [13a 1 0 800]s 10.00078 1 MAC --- 100 cbr 1112 [13a 1 0 800]r 10.00078 0 MAC --- 100 cbr 1112 [13a 1 0 800]r 10.00078 0 AGT --- 100 cbr 1112 [13a 1 0 800]

Page 56: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: Simulation Output (NAM)

The output of the simulation can be visualized by using the Network Animator (NAM) tool.

Page 57: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: Analysis of Simulation Results

NS2 does NOT provide any specific support for the data analysis/validation and for the computation of performance metrics (e.g. throughput, delay).

Run multiple simulations with different seeds

Remove the transient phase from the trace file

Extract the performance metrics from the trace file

Compute the average and confidence intervals

Plot the results

External data processing tools must be used.

AWK, PERL, …GNUPLOT

Page 58: Marco Di FeliceNS2: An Overview Marco Di Felice Network Modeling and Simulation with Network Simulator 2 (ns2) Department of Computer Science and Engineering

Marco Di Felice NS2: An Overview

Ns2: Analysis of Simulation Results

Example: Computing the system throughput in AWK.

BEGIN {recvByte=sim_time=transient=0.0

}

($1==‘r’) && ($4==‘AGT’) && ($2>transient) {

recvByte+=$8sim_time=$2

}

END {print recvByte/(sime_time-transient)

}