Top Banner

Click here to load reader

Network Simulator 2 Network 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

ReportDownload

Documents

others

  • 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

  • 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

  • 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

  • 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

  • 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

  • September 8, 2011 11

    How does NS2 work?

    September 8, 2011 12

  • 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

  • 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

  • First example

    September 8, 2011 17

    n1 n2

    Bandwidth:1Mbps Latency: 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

    }

  • 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

  • September 8, 2011 21

    Adding traffic

    n1 n2 1Mbps,10ms

    udp null

    cbr

    Packet Size: 500 bytes rate: 800Kbps

    cbr traffic

    0.0 0.5

    5.0 4.5 time

    node agent

    source

    link

    First example (cont)

    September 8, 2011 22

    #create a udp agent and attach it to node n0 set 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

  • 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

    �References September 8, 2011 24

  • 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

    }

  • 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

  • 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

  • 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_]"

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.