• No results found

Network Simulator: ns-2

N/A
N/A
Protected

Academic year: 2021

Share "Network Simulator: ns-2"

Copied!
39
0
0

Loading.... (view fulltext now)

Full text

(1)

Network Simulator: ns-2

Antonio Cianfrani

Dipartimento DIET

Università “Sapienza” di Roma

(2)

Introduction

• Network simulator provides a powerful support to research in networking area

– Design of new protocols, traffic characterization, etc – Comparison among different protocol versions

• It is an open source software

– The code is shared among users and can be modified so that to support new features, models, etc..

– In this way software reliability is improved

• It is the unique simulator implementing the whole TCP/IP stack

(3)

Features of ns-2

• Wired networks

– Routing DV, LS, PIM-SM – Trasport: TCP, UDP, SCTP

– Traffic generator: web, ftp, telnet, cbr, stocastiche

– Queuing scheduling policies :drop-tail, RED, FQ, SFQ, DRR – QoS: IntServ and Diffserv

• Wireless networks

– Ad hoc routing and mobile IP – Directed diffusion, sensor-MAC – Satellitar networks

(4)

ns-2 components

• ns, the simulator

• Nam, the network animator tool

• Pre-processing:

– Traffic and topology generators

• Post-processing:

(5)

Discrete event simulator

• NS-2 discrete event simulator used to study packet based networks

• Two programming languages are used – C++ : simulation engine

– OTcl (Object-oriented tool commande language): to manage the user/simulator interface

OTcl Interpreter

C++ NS simulator:

- Event scheduler - Network components

(6)

The C++ simulator

• The C++ simulator is the engine of ns-2; it implements the supported protocols:

– Network protocols (MAC, routing, transport) – Traffic generators(CBR, FTP, On/Off, … ) – Queue scheduling policies (FIFO, RED, …) – Wireless protocols

(7)

The OTcl Interpreter

• Used by the user to describe the simulation scenario, to configure the network topology and to schedule the events

(8)

User role

• The user must describe the simulation scenario by means of an OTcl script; then results evaluation can

(9)
(10)

The OTcl language

• The OTcl language is an extension of Tcl scripting language: it is an Object Oriented language

• Il Tcl language makes use of the Tk (Tool Kit) library, that allows the creation of symple graphical interfaces • Information about OTcl available at

(11)

OTcl commands (1/4)

• The command to assign a value to a variable is set: set a 5

• The variable is not declared before. All variables are of string type: if needed the interpreter performs numerical convertion • The value of a variabile is identified with the symbol $:

set b $a

• The command to perform a arithmetic operation is expr : set c [ expr $a * $b /2] (c=a*b/2)

(12)

OTcl commands (2/4)

• To send an output to the screesn the puts command is used:

puts $a puts “ Ciao”

• To write into a file:

– opening: set file [ open “filename” w ]

– writing: puts $file $a

(13)

OTcl commands (3/4)

FOR

for {set i 0} {$i < 100} {incr i} { ”istruzioni” }WHILE while {$i < 100} { ”istruzioni” incr i }IF if {$i < 10} { “istruzioni“ }

(14)

OTcl commands (4/4)

• A procedure is a function that can be called within the script. The proc command is used:

proc positivo { numero } { if {$numero < 0} { return $numero } return 0

}

• The command to call the procedure is: set valore [ positivo num ]

(15)

How to create a simulation

scenario

(16)

The OTcl script

• The first step is the OTcl script:

• - to describe the network topology; • - to schedule the events list.

• NS-2 provides classes.

• The most used classes are: – Simulator

NodeLinkAgent

(17)

The OTcl classes

• Network scenario: – SimulatorNodeLinkAgentApplication • Results collecting: − TraceMonitor

(18)

Simulator

• It is the basic NS-2 class

• Must be defined at the beginning of every script

set ns [ new Simulator ]

• Within the simulator (ns) it will be possible to:

– create a network scenario

– monitor the simulation evolution (trace)

– manage the events scheduler

• At the end of a script the following command must be inserted: $ns run

(19)

Simulator class: the

scheduler

• The scheduler allows to introduce events in specific time instants.

• Commands:

at t : at instant t

after p : after p seconds • Example

set ns [ new Simulator ]

$ns at 2,5 “generate an IP packet” $ns after 3 “exit 0”

(20)

The Node class

• It represents an IP node, implementing all network layer functionalities:

– Addressing – Routing

• To create a node:

set n1 [ $ns node]

• To create N different nodes:

for {set i 0} {$i < N} {incr i} { set n($i) [$ns node] }

(21)

The Link class (1/2)

• It represent the IP link among two nodes. • Set of parameters:

– Link type

– Interconnected nodes

– Features: delay, bandwidth – Queing policy $ns duplex-link $n0 $n1 1Mb 10ms DropTail Bi-directional link Nodes Link Capacity Propagation delay Queuing policy

(22)

The Link class (2/2)

• A link is implemented by means of an ingress

queue

• If the link is bidirectional there will be two different

buffers

• It is possible to set the maximum queue size

$ns queue-limit $n1 $n2 queue-limit

(23)

The Agent class (1/3)

• It represents the transport layer of an IP node:

Nodo1

Nodo2

(24)

The Agent class (2/3)

• The transport protocol must be specified: TCP or

UDP.

• The Agent role:

– transmitter

set agent_tcp [new Agent/TCP] set agent_udp [new Agent/UDP] – receiver

set null [new Agent/Null] (drop)

set tcpsink [new Agent/TCPSink] (reply with ack) set sink0 [new Agent/LossMonitor] (collect statistics)

(25)

The Agent class (3/3)

• The agent must be associated to a node

$ns attach-agent $node $agent

• The transmitter and the receiver agents must be

connected:

$ns connect $agent1 $agent2

• The first command must be always executed

before the second one.

(26)

The Application class

• It represents an application : FTP, Telnet, HTTP, traffic generator, ..

set application1 [new Application / TYPE]

• The application must be associated to an Agent

$application1 attach-agent $agent1

Nodo1

Nodo2

Agent1

Agent2

(27)

Traffic generator (1/4)

• Traffic generator definition:

set traffic [new Application / Traffic / “Type”]

EXPOO_Traffic: Exponential On/Off distribution. Packets

are sent at a fixed rate during on periods, and no packets are sent during off periods. On and off periods are taken from an exponential distribution. Packets are constant size.

packetSize_ the constant size of the packets generated – burst_time_ the average “on” time for the generator

idle_time_ the average “off” time for the generator – rate_ the sending rate during “on” times

(28)

Traffic generator (2/4)

POO_Traffic: generates traffic according to a Pareto

On/Off distribution. This is identical to the exponential

On/Off distribution, except the on and off periods are taken from a Pareto distribution.

packetSize_ the constant size of the packets generated – burst_time_ the average "on" time for the generator

idle_time_ the average "off" time for the generator – rate_ the sending rate during "on" times

shape_ the "shape" parameter used by the pareto distribution

(29)

Traffic generator (3/4)

CBR_Traffic: generates traffic according to a deterministic

rate. Packets are constant size. – rate_ the sending rate

interval_ (Optional) interval between packets

packetSize_ the constant size of the packets generated – random_ flag indicating whether or not to introduce

random “noise” in the scheduled departure times (default is off)

maxpkts_ the maximum number of packets to send (default is 228)

(30)

Traffic generator (4/4)

TrafficTrace: generates traffic according to a trace file.

Each record in the trace file consists of 2 fields. The first contains the inter-arrival time (in microseconds), the second contains the length (in bytes).

set tfile [new Tracefile]

(31)

CBR Traffic

• CBR definition: parameters

set cbr [new Application / Traffic / CBR] $cbr set packetSize_ 500 (byte)

$cbr set interval_ 0.005 (seconds)

($cbr set rate_ 800kb ) $cbr attach-agent $agent

• Traffic scheduling

$ns at 0.5 "$cbr start" $ns at 4.5 "$cbr stop"

(32)

The ERROR MODEL Class

• It is possible to introduce network failures in the simulation

• Inserting/removing a link:

$ns rtmodel-at <time> up|down $n0 $n1

• Example:

$ns rtmodel-at 1.0 down $n(1) $n(2) $ns rtmodel-at 2.0 up $n(1) $n(2)

(33)

The Trace class

• The Trace class generates a report (trace) with the whole events list.

• The report can also be related to a single link (queue). • A trace must be always associated to a file (to be

opened when starting the simulation).

(34)

The Trace class: commands

set traccia [ open traccia.tr w]

$ns trace-all $traccia

($ns trace-queue $S1 $S2 $traccia)

………

close $traccia

(35)

The Trace class: how to

monitor a queue

• To focus on a single link (from n1 to n2):

$ns trace-queue $n1 $n2 $traccia

• Also specific events can be selected

$ns create-trace type fileID $n1 $n2

• where type field can be:

EnqueueDequeueDrops

(36)
(37)

The Monitor class (1/2)

• The Monitor class is able to monitor specific

simulation variables.

• The QueueMonitor element

set coda1_2 [ $ns monitor-queue $n1 $n2 [

$ns get-ns-traceall]]

(38)

The Monitor class (2/2)

• QueueMonitor fields:

size_ queue length (bytes) at t

pkts_ number of packets in queue at tparrivals_ total number of received packets  barrivals_ total number of received bytes  pdepartures_ total number of sended packets  bdepartures_ total number of sended bytes

pdrops_ total number of dropped packets  bdrops_ total number of dropped bytes

• A specific procedure (record) can be used to exploits QueueMonitor features.

(39)

The

record

procedure

proc record { } {

global ns f1 f2 coda1_2 set ns [Simulator instance] set time 0.1

set lung_coda [$coda1_2 set pkts_ ] set drops [$coda1_2 set pdrops_ ] set now [$ns now]

puts $f1 "$now $lung_coda" puts $f2 "$now $drops"

$ns at [expr $now + $time] "record“ }

References

Related documents

Treatment retention and follow-up outcomes in the drug abuse treatment outcome

This conclusion is further supported by the following observations: (i) constitutive expression of stdE and stdF in a Dam + background represses SPI-1 expression (Figure 5); (ii)

Making sacramental wine requires special attention and care, starting with qvevri washing and marani hygiene and ending with fermentation, aging and storage. During

4.1 The Select Committee is asked to consider the proposed development of the Customer Service Function, the recommended service delivery option and the investment required8. It

Project Management, Configuration Services, Deployment Services, Asset Tagging, Apple One-to-One Services Solution, Remote Consulting, and Full-Time Resources are custom

Minors who do not have a valid driver’s license which allows them to operate a motorized vehicle in the state in which they reside will not be permitted to operate a motorized

(2008) used a variety of fractal patterns to drive their visual metronome, and thus were better positioned to examine motor control flexibility, we elected to focus on

Bayes rule, Dempster-Shafer rule and Full Bayes Updating rule imply consequentialism but do not imply dynamic consistency if the capacity is not necessarily additive.. CKL