49
Network Simulator 2(NS2) Yingyue Xu 06/09/22

Network Simulator 2(NS2)

  • Upload
    fern

  • View
    208

  • Download
    0

Embed Size (px)

DESCRIPTION

Network Simulator 2(NS2). Yingyue Xu 8/10/2014. Overview:. The Network simulator (NS): discrete event simulator for networks. supports wired, wireless, and satellite networks. various routing and multicast protocols. written in C++ and object-oriented tool command language (OTcl). - PowerPoint PPT Presentation

Citation preview

Page 1: Network Simulator 2(NS2)

Network Simulator 2(NS2)

Yingyue Xu04/22/23

Page 2: Network Simulator 2(NS2)

Overview:The Network simulator (NS): discrete event simulator for networks. supports wired, wireless, and satellite networks. various routing and multicast protocols. written in C++ and object-oriented tool command

language (OTcl). NS output is a file(s) which contains all packet

information. It can be viewed using network animator (NAM), xgraph, or processed with custom scripts (Perl, Tcl or Awk ).

Page 3: Network Simulator 2(NS2)

User view of NS:

Page 4: Network Simulator 2(NS2)

Why two languages:C++

Fast in running. Slow and hard to modify (need

to recompile the whole NS ). Used to implement detailed

protocols and algorithms, to manipulate bytes since it can run over large number of data

OTcl Slow in running Can be quickly changed (no

need to recompile). Used to implement the

simulation configuration like # of nodes, simulation topology and the dimensions of test area.

That’s why NS object called split object!

NS via Tclcl (Tcl with classes) provides glue to make objects and variables appear on both languages.

Page 5: Network Simulator 2(NS2)

Ns functionalities Wired world

Routing DV, LS, PIM-SM Transportation: TCP and UDP Traffic sources:web, ftp, telnet, cbr, stochastic Queuing disciplines:drop-tail, RED, FQ, SFQ, DRR QoS: IntServ and Diffserv Emulation

Wireless Ad hoc routing and mobile IP Directed diffusion, sensor-MAC

Tracing, visualization, various utilities

Page 6: Network Simulator 2(NS2)

Ns Models Traffic models and applications:

Web, FTP, telnet, constant-bit rate, real audio Transport protocols:

unicast: TCP (Reno, Vegas, etc.), UDP Multicast: SRM

Routing and queueing: Wired routing, ad hoc rtg and directed diffusion queueing protocols: RED, drop-tail, etc

Physical media: Wired (point-to-point, LANs), wireless (multiple propagation

models), satellite

Page 7: Network Simulator 2(NS2)

NS installation: NS can work on most UNIX platforms, and

also on windows platform.Detailed info for downloading and building NS: http://www.isi.edu/nsnam/ns/ns-build.html Easier way to download all in one package

and build NS (this will not work on Windows), this package contains Tcl, Tclcl, OTcl, Tk, and NS source codes.

You need to run install from UNIX shell (Bash or C shell).

Page 8: Network Simulator 2(NS2)

Basic Tclvariables:set x 10puts “x is $x”

functions and expressions:set y [pow x 2]set y [expr x*x]

control flow:if {$x > 0} { return $x } else {

return [expr -$x] }while { $x > 0 } {

puts $xincr x –1

}

procedures:proc pow {x n} {

if {$n == 1} { return $x }set part [pow x [expr $n-1]]return [expr $x*$part]

}

Also lists, associative arrays, etc.

=> can use a real programming language to build network topologies, traffic models, etc.

Page 9: Network Simulator 2(NS2)

Basic otclClass Person# constructor:Person instproc init {age} {

$self instvar age_set age_ $age

}# method:Person instproc greet {} {

$self instvar age_puts “$age_ years old: How are you doing?”

}

# subclass:Class Kid -superclass PersonKid instproc greet {} {

$self instvar age_puts “$age_ years old kid: What’s up, dude?”

}

set a [new Person 45]set b [new Kid 15]$a greet$b greet

=> can easily make variations of existing things (TCP, TCP/Reno)

Page 10: Network Simulator 2(NS2)

Ns programming Create the event scheduler Turn on tracing Create network Setup routing Insert errors Create transport connection Create traffic Transmit application-level data

Page 11: Network Simulator 2(NS2)

Creating Event Scheduler Create event scheduler

set ns [new Simulator] Schedule events

$ns at <time> <event> <event>: any legitimate ns/tcl commands

$ns at 5.0 “finish” Start scheduler

$ns run

Page 12: Network Simulator 2(NS2)

Ns programming Create the event scheduler Turn on tracing Create network Setup routing Insert errors Create transport connection Create traffic Transmit application-level data

Page 13: Network Simulator 2(NS2)

Tracing and Monitoring Packet tracing:

On all links: $ns trace-all [open out.tr w] On one specific link: $ns trace-queue $n0

$n1$tr<Event> <time> <from> <to> <pkt> <size> -- <fid> <src> <dst>

<seq> <attr>

+ 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0- 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0r 1.00234 0 2 cbr 210 ------- 0 0.0 3.1 0 0

Page 14: Network Simulator 2(NS2)

Ns programming Create the event scheduler Turn on tracing Create network Setup routing Insert errors Create transport connection Create traffic Transmit application-level data

Page 15: Network Simulator 2(NS2)

Creating Network Nodes

set n0 [$ns node]set n1 [$ns node]

Links and queuing$ns <link_type> $n0 $n1 <bandwidth> <delay>

<queue_type> <link_type>: duplex-link, simplex-link <queue_type>: DropTail, RED, CBQ, FQ, SFQ,

DRR, diffserv RED queues

Page 16: Network Simulator 2(NS2)

Creating Network: LAN$ns make-lan <node_list> <bandwidth>

<delay> <ll_type> <ifq_type> <mac_type> <channel_type>

<ll_type>: LL<ifq_type>: Queue/DropTail,<mac_type>: MAC/802_3<channel_type>: Channel

Page 17: Network Simulator 2(NS2)

Ns programming Create the event scheduler Turn on tracing Create network Setup routing Insert errors Create transport connection Create traffic Transmit application-level data

Page 18: Network Simulator 2(NS2)

Setup Routing Unicast

$ns rtproto <type><type>: Static, Session, DV, cost, multi-path

Multicast$ns multicast (right after [new Simulator])$ns mrtproto <type><type>: CtrMcast, DM, ST, BST

Other types of routing supported: source routing, hierarchical routing

Page 19: Network Simulator 2(NS2)

Ns programming Create the event scheduler Turn on tracing Create network Setup routing Insert errors Create transport connection Create traffic Transmit application-level data

Page 20: Network Simulator 2(NS2)

Inserting Errors Creating Error Module

set loss_module [new ErrorModel]$loss_module set rate_ 0.01$loss_module unit pkt$loss_module ranvar [new RandomVariable/Uniform]$loss_module drop-target [new Agent/Null]

Inserting Error Module$ns lossmodel $loss_module $n0 $n1

Page 21: Network Simulator 2(NS2)

Ns programming Create the event scheduler Turn on tracing Create network Setup routing Insert errors Create transport connection Create traffic

Page 22: Network Simulator 2(NS2)

Creating Connection and Traffic UDPset udp [new Agent/UDP]set null [new Agent/Null]$ns attach-agent $n0

$udp$ns attach-agent $n1

$null$ns connect $udp $null

CBRset src [new

Application/Traffic/CBR]

Page 23: Network Simulator 2(NS2)

Creating Connection and Traffic II TCPset tcp [new Agent/TCP]set tcpsink [new

Agent/TCPSink]$ns attach-agent $n0 $tcp$ns attach-agent $n1

$tcpsink$ns connect $tcp $tcpsink

FTPset ftp [new Application/FTP]$ftp attach-agent $tcp Telnetset telnet [new

Application/Telnet]$telnet attach-agent $tcp

Page 24: Network Simulator 2(NS2)

Summary: Generic Script Structure

set ns [new Simulator]set ns [new Simulator]# [Turn on tracing]# [Turn on tracing]# Create topology# Create topology# Setup packet loss, link dynamics# Setup packet loss, link dynamics# Create routing agents# Create routing agents# Create: # Create: # - multicast groups# - multicast groups# - protocol agents# - protocol agents# - application and/or setup traffic sources# - application and/or setup traffic sources# Post-processing procs# Post-processing procs# Start simulation# Start simulation

Page 25: Network Simulator 2(NS2)

Plumbing: Packet Flow

01

n0 n1

Addr Classifier

Port Classifier

entry_

0 Agent/TCP Addr Classifier

Port Classifier

entry_

10

Link n0-n1

Link n1-n0

0 Agent/TCPSinkdst_=1.0 dst_=0.0

Application/FTP

Page 26: Network Simulator 2(NS2)

Getting started with nam Turn on nam tracing in your Tcl script

As easy as turning on normal tracing$ns namtrace $file

Specify link orientation (or node position for wireless)$ns duplex-link-op $node1 $node2 orient left

Execute namexec nam $filename

Page 27: Network Simulator 2(NS2)

Advanced nam capabilities Node options — color, shape, label

$node color red$node shape hexagon$node label “my text”$node label-color blue$node label-at up

Link options$ns duplex-link-op $n1 $n2 color green$ns duplex-link-op queuePos right$ns duplex-link-op $n1 $n2 label “my text”$ns duplex-link-op $n1 $n2 label-color blue$ns duplex-link-op $n1 $n2 label-at down

Page 28: Network Simulator 2(NS2)

Advanced nam capabilities Packet colors

$ns color $n blue$agent set fid_ $n

Annotation$ns at $time “$ns trace-annotate $text”

Control playback$ns set-animation-rate 3ms

Page 29: Network Simulator 2(NS2)

The nam user interface

Page 30: Network Simulator 2(NS2)

The nam editor Create simple scenarios graphically Good for those who don’t want to learn

Tcl, but only a limited subset of ns is available

Page 31: Network Simulator 2(NS2)

The nam editor

Page 32: Network Simulator 2(NS2)

Wireless model Mobilenode at core of mobility model Mobilenodes can move in a given topology,

receive/transmit signals from/to wireless channels Wireless network stack consists of LL, ARP,

MAC, IFQ etc Allows simulations of multi-hop ad hoc networks,

wireless LANs, sensor networks etc

Page 33: Network Simulator 2(NS2)

An Example – Step 1# Define Global Variables# create simulatorset ns [new Simulator]

# create a flat topology in a 670m x 670m areaset topo [new Topography] $topo load_flatgrid 670 670

Page 34: Network Simulator 2(NS2)

An Example – Step 2# Define standard ns/nam trace

# ns trace

set tracefd [open demo.tr w]

$ns trace-all $tracefd

# nam trace

set namtrace [open demo.nam w]

$ns namtrace-all-wireless $namtrace 670 670

Page 35: Network Simulator 2(NS2)

GOD (General Operations Director) Stores smallest number of hops from one

node to another Optimal case to compare routing protocol

performance Automatically generated by scenario file set god [create-god <no of mnodes>] $god set-dist <from> <to> <#hops>

Page 36: Network Simulator 2(NS2)

Example –Step 3 Create God

set god [create-god 3]$ns at 900.00 “$god setdist 2 3 1”

Page 37: Network Simulator 2(NS2)

An Example – Step 4# Define how a mobile node is configured$ns node-config \

-adhocRouting DSDV \-llType LL \-macType Mac/802_11 \-ifqLen 50 \-ifqType Queue/DropTail/PriQueue \-antType Antenna/OmniAntenna \-propType Propagation/TwoRayGround \-phyType Phy/WirelessPhy \-channelType Channel/WirelessChannel \-topoInstance $topo-agentTrace ON \-routerTrace OFF \-macTrace OFF

Page 38: Network Simulator 2(NS2)

An Example – Step 5# Next create a mobile node, attach it to the channel set node(0) [$ns node]# disable random motion $node(0) random-motion 0

# Use “for” loop to create 3 nodes:

for {set i < 0} {$i < 3} {incr i} {set node($i) [$ns node]$node($i) random-motion 0}

Page 39: Network Simulator 2(NS2)

Mobilenode Movement Node position defined in a 3-D model However z axis not used

$node set X_ <x1>$node set Y_ <y1>$node set Z_ <z1>$node at $time setdest <x2> <y2>

<speed> Node movement may be logged

Page 40: Network Simulator 2(NS2)

Scenario Generator: Movement

Mobile Movement Generatorsetdest -n <num_of_nodes> -p pausetime -setdest -n <num_of_nodes> -p pausetime -

s <maxspeed> -t <simtime> -x <maxx> -y s <maxspeed> -t <simtime> -x <maxx> -y <maxy><maxy>

Source: ns-2/indep-utils/cmu-scen-gen/setdest/ns-2/indep-utils/cmu-scen-gen/setdest/

Random movement $node random-motion 1 $node start$node start

Page 41: Network Simulator 2(NS2)

A Movement File$node_(2) set Z_ 0.000000000000$node_(2) set Y_ 199.373306816804$node_(2) set X_ 591.256560093833$node_(1) set Z_ 0.000000000000$node_(1) set Y_ 345.357731779204$node_(1) set X_ 257.046298323157$node_(0) set Z_ 0.000000000000$node_(0) set Y_ 239.438009831261$node_(0) set X_ 83.364418416244$ns_ at 50.000000000000 "$node_(2) setdest 369.463244915743 170.519203111152 3.371785899154"$ns_ at 51.000000000000 "$node_(1) setdest 221.826585497093 80.855495003839 14.909259208114"$ns_ at 33.000000000000 "$node_(0) setdest 89.663708107313 283.494644426442 19.153832288917"

Page 42: Network Simulator 2(NS2)

Scenario Generator: Traffic Generating traffic pattern files

CBR trafficns cbrgen.tcl [-type cbr|tcp] [-nn ns cbrgen.tcl [-type cbr|tcp] [-nn nodes] [-seed seed] [-mc connections] nodes] [-seed seed] [-mc connections] [-rate rate][-rate rate]

TCP trafficns tcpgen.tcl [-nn nodes] [-seed seed]ns tcpgen.tcl [-nn nodes] [-seed seed]

Source: ns-2/indep-utils/cmu-scen-ns-2/indep-utils/cmu-scen-gen/gen/

Page 43: Network Simulator 2(NS2)

A Traffic Scenarioset udp_(0) [new Agent/UDP]$ns_ attach-agent $node_(0) $udp_(0)set null_(0) [new Agent/Null]$ns_ attach-agent $node_(2) $null_(0)set cbr_(0) [new Application/Traffic/CBR]$cbr_(0) set packetSize_ 512$cbr_(0) set interval_ 4.0$cbr_(0) set random_ 1$cbr_(0) set maxpkts_ 10000$cbr_(0) attach-agent $udp_(0)$ns_ connect $udp_(0) $null_(0)$ns_ at 127.93667922166023 "$cbr_(0) start"…….

Page 44: Network Simulator 2(NS2)

An Example – Step 6# Define node movement model source <movement-scenario-files>

# Define traffic modelsource <traffic-scenario-files>

Page 45: Network Simulator 2(NS2)

An Example – Step 7

# Tell ns/nam the simulation stop time $ns at 200.0 “$ns nam-end-wireless 200.0”$ns at 200.0 “$ns halt”

# Start your simulation $ns run

Page 46: Network Simulator 2(NS2)

nam Visualization Replace

$ns namtrace-all $fd$ns namtrace-all $fd

with$ns namtrace-all-wireless $fd$ns namtrace-all-wireless $fd

At the end of simulation, do$ns nam-end-wireless [$ns now]$ns nam-end-wireless [$ns now]

Page 47: Network Simulator 2(NS2)

Wireless Trace Support Original cmu trace format A separate wireless trace format developed

later at ISI Current ongoing effort to have ONE format

to combine all wired and wireless formats