Top Banner
21

Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

Mar 15, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

Network Simulator 2

Advanced Computer Network (CS5229)

Saeid Montazeri

September 8, 2011

Outline

�Overview of Simulation

�Overview of NS2

�Steps for network simulation

�How to make a scenario

�How to change the implementation of NS2

�References

September 8, 2011 2

Page 2: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

What is simulation?

September 8, 2011 3

system under study

(has deterministic rules

governing its behavior)

exogenous inputs

to system

(the environment)

system boundary

observer

�real� life

computer program

simulates deterministic

rules governing behavior

psuedo random inputs

to system

(models environment)

program boundary

observer

�simulated� life

Why Simulation?

�Real-system not available, is complex/costly or dangerous (eg: space simulations, flight simulations)

�Quickly evaluate design alternatives (eg: different system configurations)

�Evaluate complex functions for which closed form formulas or numerical techniques are not available

September 8, 2011 4

Page 3: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

Programming a simulation

� What is in a simulation program?

� Simulated time

� Internal variable that keeps the time

� System state

� Variables maintained by simulation program

� Number of packet in the queue, transmission time value

� Events

� occurs at an instant in time and marks a change of system state

� Arrival packet to a queue, departure of packet from a queue

September 8, 2011 5

Simulator Structure

�Simulation program maintains and updates list of

future events: event listevent list

�Requirements:

�well defined set of events

� for each event: simulated system action,

updating of event list

September 8, 2011 6

Page 4: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

Simulator Block Diagram

September 8, 2011 7

initialize event list

get next (nearest future)event from event list

time = event time

update statistics

done?n

process event(change state values, add/delete

future events from event list)

Outline

�Overview of Simulation

�Overview of NS2

�Steps for network simulation

�How to make a scenario

�How to change the implementation of NS2

�References

September 8, 2011 8

Page 5: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

What is NS2?

�Stands for Network Simulator version 2

�Discrete event simulator for networking research

�Work at packet level

�Provide substantial support to simulate bunch of

protocols like TCP, UDP, FTP and HTTP

�Simulate wired and wireless network.

�Primarily Unix based

September 8, 2011 9

Otcl and C++

�C++ for data

� Per packet action

�Otcl for control

� Periodic and triggered action

September 8, 2011 10

Page 6: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

September 8, 2011 11

How does NS2 work?

September 8, 2011 12

Page 7: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

Installation

Ubuntu 11:� http://narnicles.wordpress.com/2011/05/10/installing-ns2-in-ubuntu-11-04/

Ubuntu 10:

� Go the below link and choose the second procedure� http://www.scribd.com/doc/46784839/Install-NS2-34-in-Ubuntu10-10

Windows:

� For example:� http://paulson.in/?p=49

September 8, 2011 13

Outline

�Overview of Simulation

�Overview of NS2

�Steps for network simulation

�How to make a scenario

�How to change the implementation of NS2

�References

September 8, 2011 14

Page 8: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

Steps for network simulation

1. Implement the protocol models

2. Setup simulation scenario

3. Run the simulation

4. Analyze the simulation output

September 8, 2011 15

Simulation scenario

�Write scenario in Otcl

Create topology

Nodes, links, protocol parameters

Traffic

CBR, VBR, Exponential On/Off

�NS2 interprets script file and pass required parameters

to model

September 8, 2011 16

Page 9: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

First example

September 8, 2011 17

n1 n2

Bandwidth:1MbpsLatency: 10ms

First example (cont)

September 8, 2011 18

#create a new simulator object

set ns_ [new Simulator]

#open the nam trace file

set nf [open out.nam w]

$ns_ namtrace-all $nf

#define a 'finish' procedure

proc finish {} {

global ns_ nf

$ns_ flush-trace

#close the trace file

close $nf

#execute nam on the trace file

exec nam out.nam &

exit 0

}

Page 10: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

First example (cont)

September 8, 2011 19

#create two nodes

set n0 [$ns_ node]

set n1 [$ns_ node]

#create a duplex link between the nodes

$ns_ duplex-link $n0 $n1 1Mb 10ms DropTail

#call the finish procedure after 5 secs of

simulated time

$ns_ at 5.0 "finish�

#run the simulation

$ns_ run

Demo

September 8, 2011 20

Page 11: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

September 8, 2011 21

Adding traffic

n1 n21Mbps,10ms

udpnull

cbr

Packet Size: 500 bytesrate: 800Kbps

cbr traffic

0.00.5

5.04.5 time

node agent

source

link

First example (cont)

September 8, 2011 22

#create a udp agent and attach it to node n0set udp0 [new Agent/UDP]

$ns_ attach-agent $n0 $udp0

#Create a CBR traffic source and attach it to udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 500

$cbr0 set interval_ 0.005

$cbr0 attach-agent $udp0

#create a Null agent(a traffic sink) and attach it

to node n1

set null0 [new Agent/Null]

$ns_ attach-agent $n1 $null0

#Connect the traffic source to the sink

$ns_ connect $udp0 $null0

#Schedule events for CBR traffic

$ns_ at 0.5 "$cbr0 start"

$ns_ at 4.5 "$cbr0 stop�

Page 12: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

Demo

September 8, 2011 23

Outline�Overview of Simulation

�Overview of NS2

�Steps for network simulation

�How to make a scenario

� First simple example

� Second example� Post processing

�How to change the implementation of NS2

�ReferencesSeptember 8, 2011 24

Page 13: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

Second Scenario (NS by Example)

September 8, 2011 25

Second Scenario (cont)

September 8, 2011 26

#Create a simulator object

set ns_ [new Simulator]

#Define different colors for data flows (for NAM)

$ns_ color 1 Blue

$ns_ color 2 Red

#Open the NAM trace file

set nf [open out.nam w]

$ns_ namtrace-all $nf

#Define a 'finish' procedure

proc finish {} {

global ns_ nf

$ns flush-trace

#Close the NAM trace file

close $nf

#Execute NAM on the trace file

exec nam out.nam &

exit 0

}

Page 14: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

Second Scenario (cont)

September 8, 2011 27

#Create four nodes

set n0 [$ns_ node]

set n1 [$ns_ node]

set n2 [$ns_ node]

set n3 [$ns_ node]

#Create links between the nodes

$ns_ duplex-link $n0 $n2 2Mb 10ms DropTail

$ns_ duplex-link $n1 $n2 2Mb 10ms DropTail

$ns_ duplex-link $n2 $n3 1.7Mb 20ms DropTail

#Set Queue Size of link (n2-n3) to 10

$ns_ queue-limit $n2 $n3 10

Second Scenario (cont)

September 8, 2011 28

#Give node position (for NAM)

$ns_ duplex-link-op $n0 $n2 orient right-down

$ns_ duplex-link-op $n1 $n2 orient right-up

$ns_ duplex-link-op $n2 $n3 orient right

#Monitor the queue for link (n2-n3). (for NAM)

$ns_ duplex-link-op $n2 $n3 queuePos 0.5

Page 15: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

Second Scenario (cont)

September 8, 2011 29

#Setup a TCP connection

set tcp [new Agent/TCP]

$ns_ attach-agent $n0 $tcp

set sink [new Agent/TCPSink]

$ns_ attach-agent $n3 $sink

$ns_ connect $tcp $sink

$tcp set fid_ 1

#Setup a FTP over TCP connection

set ftp [new Application/FTP]

$ftp attach-agent $tcp

$ftp set type_ FTP

Second Scenario (cont)

September 8, 2011 30

#Setup a UDP connection

set udp [new Agent/UDP]

$ns_ attach-agent $n1 $udp

set null [new Agent/Null]

$ns_ attach-agent $n3 $null

$ns_ connect $udp $null

$udp set fid_ 2

#Setup a CBR over UDP connection

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp

$cbr set type_ CBR

$cbr set packet_size_ 1000

$cbr set rate_ 1mb

$cbr set random_ false

Page 16: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

Second Scenario (cont)

September 8, 2011 31

#Schedule events for the CBR and FTP agents

$ns_ at 0.1 "$cbr start"

$ns_ at 1.0 "$ftp start"

$ns_ at 4.0 "$ftp stop"

$ns_ at 4.5 "$cbr stop"

#Call the finish procedure after 5 seconds of simulation

time

$ns_ at 5.0 "finish"

#Print CBR packet size and interval

puts "CBR packet size = [$cbr set packet_size_]"

puts "CBR interval = [$cbr set interval_]"

#Run the simulation

$ns_ run

Demo

September 8, 2011 32

Page 17: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

How does NS2 work?

September 8, 2011 33

How to get trace file?#Create a simulator object

set ns_ [new Simulator]

#Define different colors for data flows (for NAM)

$ns_ color 1 Blue

$ns_ color 2 Red

#Open the NAM trace file

set nf [open out.nam w]

$ns_ namtrace-all $nf

#Open the traffic trace file to record all events

set nd [open out.tr w]

$ns_ trace-all $nd

#Define a 'finish' procedure

proc finish {} {

global ns_ nf nd

$ns flush-trace

#Close the NAM trace file

close $nf

close $nd

#Execute NAM on the trace file

#exec nam out.nam &

exit 0

Page 18: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

Directory + Demo

September 8, 2011 35

Page 19: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

Demo

Write script to measure packet loss

September 8, 2011 37

Outline

�Overview of Simulation

�Overview of NS2

�Steps for network simulation

�How to make a scenario

�How to change the implementation of NS2

�References

September 8, 2011 38

Page 20: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

Second Scenario (changed)

September 8, 2011 39

#Create four nodes

set n0 [$ns_ node]

set n1 [$ns_ node]

set n2 [$ns_ node]

set n3 [$ns_ node]

#Create links between the nodes

Queue/RED set thresh_ 2

Queue/RED set maxthresh_ 6

Queue/RED set queue_in_bytes_ false

Queue/RED set gentle_ false

$ns_ duplex-link $n0 $n2 2Mb 10ms DropTail

$ns_ duplex-link $n1 $n2 2Mb 10ms DropTail

$ns_ duplex-link $n2 $n3 1.7Mb 20ms RED

How to change NS implementation

September 8, 2011 40

1.Save your changes in cc file

2.Go to ns-allinone-2.34/ns-2.34 in command

prompt

3.switch to root user

4.Type �make clean�

5.Type �make�

6.Type �make install�

Page 21: Network Simulator 2Network Simulator 2 Advanced Computer Network (CS5229) Saeid Montazeri September 8, 2011 Outline Overview of Simulation Overview of NS2 Steps for network simulation

Demo

September 8, 2011 41

Reference

Marc Greis tutorial

� http://www.isi.edu/nsnam/ns/tutorial/nsscript2.html

NS2 by example

� http://perform.wpi.edu/NS/

NS2

� http://www.isi.edu/nsnam/ns

Simulation Overview (Jim Kurose, University of Massachusets, Amhers)

September 8, 2011 42