Presentation is loading. Please wait.

Presentation is loading. Please wait.

Network Simulator 2 Tejas Vasavada.

Similar presentations


Presentation on theme: "Network Simulator 2 Tejas Vasavada."— Presentation transcript:

1 Network Simulator 2 Tejas Vasavada

2 Contents Simulation of wired networks Simulation of wireless networks
Traffic and movement-pattern files Trace files Analyzing trace files using 'awk' script 'gnuplot' – utility to plot graphs

3 Contents (contd.) DSR – A protocol for MANETs
Source code of DSR in NS2 How to change DSR (with examples) Printing packet header Configuring nodes to drop packets Adding a new function in DSR Calling previous function from Tcl Passing arguments from Tcl to DSR Use of timers

4 Contents How to add new package in NS
Simulation of Wired-cum-Wireless Networks

5 Introduction Simulation comes before implementation.
A newly designed protocol is simulated first to test the performance.

6 Simulation Tools OmNet++, NS2, Qualnet, Opnet, GlomoSim etc.
NS2 - an open source tool, widely used in academics for research purpose.

7 How to use NS2 Front end – Tcl (Tool Command Langauage) Back end – C++
Today we will learn Tcl.

8 Wired Network

9 Tcl script set ns [new Simulator]
creates an instance of ‘Simulator’ class. Output is stored in .nam files (Network AniMator) set nf [open out.nam w] $ns namtrace-all $nf

10 Tcl script (contd.) proc finish {} { global ns nf $ns flush-trace
close $nf exec nam out.nam & exit 0 } ‘finish’ will be called at the end of simulation.

11 Tcl Script (contd.) $ns at 5.0 "finish“
finish() is called at 5th second. $ns run Starts simulation.

12 Tcl script (contd.) set n0 [$ns node] set n1 [$ns node]
Creates two nodes - n0 and n1. $ns duplex-link $n0 $n1 1Mb 10ms DropTail Connects both the nodes.

13 Tcl script (contd.) #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

14 Tcl script (contd.) set null0 [new Agent/Null]
$ns attach-agent $n1 $null0 Creates a null agent and attaches it to n1. $ns connect $udp0 $null0 Two agents are connected togother.

15 Tcl script (contd.) $ns at 0.5 "$cbr0 start" $ns at 4.5 "$cbr0 stop“
Node n0 will start sending packets at time 0.5 sec and will stop at 4.5 sec.

16 Exercise 1 Read example1.tcl provided to you.
Run it using following command ns example1.tcl Read & Run Example2.tcl

17 Example2.tcl $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 Creates star shape topology.

18 Example2.tcl (contd.)

19 Example2.tcl (contd.) Nodes n0 and n1 connect to n3 via n2.
Bandwidth n2-n3 < (bandwidth n0-n2 + bandwidth n1-n2) Node n2 drops packets.

20 Example2.tcl To see what is happening at n2, different flows should be coloured differently. $udp0 set class_ 1 $udp1 set class_ 2 $ns color 1 Blue $ns color 2 Red

21 Example2.tcl (contd.)

22 Example3.tcl for {set i 0} {$i < 7} {incr i} { set n($i) [$ns node]
Creates 7 nodes. $ns duplex-link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms DropTail

23 Example3.tcl (contd.)

24 Example3.tcl (contd.) Node n0 is connected to n3. Packets will pass through n1 and n2 (shortest path). Break n1-n2 link using following commands. $ns rtmodel-at 1.0 down $n(1) $n(2) $ns rtmodel-at 2.0 up $n(1) $n(2)

25 Example3.tcl (contd.)

26 Example3.tcl (contd.) Use following command to use alternate path.
$ns rtproto DV

27 Example3.tcl (contd.)

28 Wireless Network

29 Simple-wireless.tcl Components of a mobile node… Link Layer,
Interface Queue between LL and Network Layer, MAC Layer Routing Layer Parameters of a mobile node Type of antenna, Radio propagation model

30 Simple-wireless.tcl (contd.)
set val(chan) Channel/WirelessChannel ;# channel type set val(prop) Propagation/TwoRayGround ;# radio-propagation model set val(ant) Antenna/OmniAntenna ;# Antenna type set val(ll) LL ;# Link layer type set val(ifq) Queue/DropTail/PriQueue ;# Interface queue type set val(ifqlen) 50 ;# max packet in ifq set val(netif) Phy/WirelessPhy ;# network interface type set val(mac) Mac/802_11 ;# MAC type set val(rp) DSDV ;# ad-hoc routing protocol set val(nn) 2 ;# number of mobilenodes

31 Simple-wireless.tcl (contd.)
set ns_ [new Simulator] Creates new instance of ‘Simulator’. set tracefd [open simple.tr w] $ns_ trace-all $tracefd Creates new instance of trace file.

32 Simple-wireless.tcl (contd.)
set topo [new Topography] Creates new topology. $topo load_flatgrid Sets resolution of topology to 500 x 500.

33 Simple-wireless.tcl (contd.)
# Configure nodes $ns_ node-config -adhocRouting $val(rp) -llType $val(ll) \ -macType $val(mac) ifqType $val(ifq) \ -ifqLen $val(ifqlen) -antType $val(ant) \ -propType $val(prop) –phyType $val(netif) \ -topoInstance $topo \ -channelType $val(chan) \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace OFF

34 Simple-wireless.tcl (contd.)
for {set i 0} {$i < $val(nn) } {incr i} { set node_($i) [$ns_ node ] $node_($i) random-motion 0 } Random motion is disabled. We will provide initial position and movement parameters.

35 Simple-wireless.tcl (contd.)
$node_(0) set X_ 5.0 $node_(0) set Y_ 2.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 390.0 $node_(1) set Y_ 385.0 $node_(1) set Z_ 0.0

36 Simple-wireless.tcl (contd.)
# Node_(1) starts to move towards node_(0) $ns_ at 50.0 "$node_(1) setdest " $ns_ at 10.0 "$node_(0) setdest “ # Node_(1) then starts to move away from node_(0) $ns_ at "$node_(1) setdest "

37 Simple-wireless.tcl (contd.)
# TCP connections between node_(0) and node_(1) set tcp [new Agent/TCP] $tcp set class_ 2 set sink [new Agent/TCPSink] $ns_ attach-agent $node_(0) $tcp $ns_ attach-agent $node_(1) $sink $ns_ connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp $ns_ at 10.0 "$ftp start"

38 Simple-wireless.tcl (contd.)
# Tell nodes when the simulation ends for {set i 0} {$i < $val(nn) } {incr i} { $ns_ at "$node_($i) reset"; } $ns_ at "stop" $ns_ at "puts \"NS EXITING...\" ; $ns_ halt" proc stop {} { global ns_ tracefd close $tracefd

39 Simple-wireless.tcl (contd.)
puts "Starting Simulation..." $ns_ run Prints the message and starts simulation.

40 Traffic-pattern file and movement-pattern file

41 Wireless-1.tcl set val(cp) “/root/cbr-3-test"
set val(sc) “/root/scen-3-test“ cbr-3-test is connection-pattern file. scen-3-test is movement-pattern file.

42 Wireless-1.tcl (contd.) set val(x) 670 set val(y) 670
set namtrace [open wireless1-out.nam w] $ns_ namtrace-all-wireless $namtrace $val(x) $val(y)

43 Wireless-1.tcl (contd.) puts "Loading connection pattern..."
source $val(cp) Loads connection-pattern file. puts "Loading scenario file..." source $val(sc) Loads movement-pattern(scenario) file.

44 Wireless-1.tcl (contd.) for {set i 0} {$i < $val(nn)} {incr i} {
$ns_ initial_node_pos $node_($i) 20 } Defines size of node in nam

45 Traffic pattern file ns cbrgen.tcl [-type cbr|tcp] [-nn nodes] [-seed seed] [-mc connections] [-rate rate] > [filenm] Generates a traffic pattern. It is saved in file ‘filenm’. -type : type of connection cbr or tcp -nn : no. of nodes -seed : seed value used by random number generator -mc : no. of connections -rate : rate at with packets are sent

46 Traffic pattern file (contd.)
ns cbrgen.tcl -type cbr -nn 10 -seed 1.0 -mc 8 -rate 4.0 > cbr-10-test Generates traffic-pattern and saves in file cbr-10-test. Create traffice-pattern file for tcp traffic and check how it differs from cbr-10-test

47 Movement-pattern file
‘setdest’ utility available at: ns-x.xx/indep-utils/cmu-scen-gen/setdest /setdest –v 1 –n <nodes> -p <pause time> -M <max speed> -t <sim time> -x <maxx> -y <maxy>

48 Movement-pattern file (contd.)
./setdest –v 2 –n <nodes> -s <speed type> -m <min speed> -M <max speed> -t <sim time> -P <pause type> -p <pause time> -x <maxx> -y <maxy> Speed type: 1 - uniform speed 2 - normal speed

49 Pause type: 1 - constant 2 – uniform [ 0, 2 x pause ] For e.g. ./setdest –v 2 -n 50 -s 1 -m 1 -M 20 -t 200 -P 1 -p 0 -x 200 -y 200 > /root/Desktop/scen-3-test

50 Trace file format

51 Trace files Output of simulation is in trace format.
Trace file has two formats: old and new To use new format add following line in tcl script before calling trace-all . $ns use-newtrace

52 Trace file format Event type s send d drop r receive f forward Time -t

53 Trace file format (contd.)
Node property tag -Ni Node id -Nx Node’s x-coordinate -Ny Node’s y-coordinate -Nz Node’s z-coordinate -Ne Node’s energy level -Nl Trace level (AGT, RTR, MAC)

54 Trace file format (contd.)
-Is source address.source port number -Id dest address.dest port number -It packet type -Il packet size -If flow id -Ii unique id -Iv ttl value

55 Trace file format (contd.)
Next hop information -Hs id for this node -Hd id of next node towards destination

56 Awk script

57 Awk script ‘Awk’ is a scripting language used to process text files.
Processes the file row by row. Columns are identified like $1,$2 etc. awk –f <.awk file> <.tr> file. Use the awk file provided to calculate throughput from tracefile.

58 Sample Script - dr.awk BEGIN { sent=0 recd=0 }

59 dr.awk event=$1 level=$19 if(event == “s” && level == “AGT”) sent++
if(event == “r” && level == “AGT”) recd++ }

60 dr.awk END { printf("sent %g, recd %g, fwd %g, del. %g\n",sent,recd,fwd,recd/sent); }

61 GnuPlot

62 'gnuplot' Syntax: gnuplot <file.gnu> Read dr.gnu file to understand use of 'gnuplot' to plot graphs.

63 Adding new Files in NS Find ns2_ricean_dist folder available with this presentation. Follow the procedure in “README” file.


Download ppt "Network Simulator 2 Tejas Vasavada."

Similar presentations


Ads by Google