0% found this document useful (0 votes)
52 views28 pages

Introduction To NS-2: Part 5. Wireless Network

This document provides an introduction to simulating wireless networks using the NS-2 network simulator. It outlines the key components of a wireless network that can be modeled in NS-2 including the layers, nodes, traffic generation, and an example OTcl script. The script simulates a simple wireless network with 3 nodes, one generating CBR traffic. The document also describes the trace formats produced by NS-2, including the new simplified format, and provides examples of how to analyze the trace files to extract metrics like packet loss ratio.

Uploaded by

Muhammad Hamidi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views28 pages

Introduction To NS-2: Part 5. Wireless Network

This document provides an introduction to simulating wireless networks using the NS-2 network simulator. It outlines the key components of a wireless network that can be modeled in NS-2 including the layers, nodes, traffic generation, and an example OTcl script. The script simulates a simple wireless network with 3 nodes, one generating CBR traffic. The document also describes the trace formats produced by NS-2, including the new simplified format, and provides examples of how to analyze the trace files to extract metrics like packet loss ratio.

Uploaded by

Muhammad Hamidi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Introduction to NS-2

Part 5. Wireless Network


Min Chen
School of Computer Science and Engineering
Seoul National University

Outline

Introduction to Wireless Network


An Example of Wireless Simulation
Trace Format for Wireless Network
Analysis Examples

Wireless Network

Telecommunications by radio wave


Mobile Supported!!
The Way to Ubiquitous Life
A Variety of Wireless Networks

Wi-Fi

Cellular Network

WiMax

Wireless Sensor Networks

Wireless Mesh Networks

...

Wireless Network Layers in ns-2


Application
ApplicationLayer
Layer

Agent
AgentLayer
Layer

Transport
TransportLayer
Layer

Router
RouterLayer
Layer

Network
NetworkLayer
Layer

MAC
MACLayer
Layer

PHY
PHYLayer
Layer

Wireless Simulation in ns-2


cbr

udp

null
(500,900)

(350,500)

(500,500)

(500,100)

2
(650,500)

OTcl file for the Example (1)


#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy
;# network interface type
set val(mac) Mac/802_11
;# MAC type
set val(ifq)
Queue/DropTail/PriQueue ;# interface queue type
set val(ll)
LL
;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50
;# max packet in ifq
set val(nn)
3
;# number of mobilenodes
set val(rp)
AODV
;# routing protocol
set val(x)
1000
;# X dimension of topography
set val(y)
1000
;# Y dimension of topography
set val(stop) 10.0
;# time of simulation end

OTcl file for the Example (2)


#===================================
#
Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#Open the NS trace file
set tracefile [open out.tr w]
$ns trace-all $tracefile
#Open the NAM trace file
set namfile [open out.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];
#Create wireless channel
#Setup topography object
set topo
[new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

OTcl file for the Example (3)


#===================================
# Mobile node parameter setup
#===================================
$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) \
-channel
$chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace
ON \
-movementTrace ON

OTcl file for the Example (4)


#===================================
#
Nodes Definition
#===================================
#Create 3 nodes
set n0 [$ns node]
$n0 set X_ 350
$n0 set Y_ 500
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 500
$n1 set Y_ 500
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 650
$n2 set Y_ 500
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20

OTcl file for the Example (5)


#===================================
# Nodes Movement
#===================================
$ns at 2.0 "$n1 setdest 500.0 900.0 100.0"
$ns at 5.0 "$n1 setdest 500.0 100.0 100.0"

OTcl file for the Example (6)


#===================================
#
Agents Definition
#===================================
#Setup a UDP connection
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null1 [new Agent/Null]
$ns attach-agent $n2 $null1
$ns connect $udp0 $null1
$udp0 set packetSize_ 1500
#===================================
#
Applications Definition
#===================================
#Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 1.0Mb
$cbr0 set random_ null
$ns at 1.0 "$cbr0 start"
$ns at 9.0 "$cbr0 stop"

OTcl file for the Example (7)


#===================================
#
Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

Result

Trace Format for Wireless


...
s 1.022873047 _0_ MAC --- 2 cbr 1078 [13a 1 0 800] ------- [0:0 2:0 30 1] [2] 0 0
s 1.024000000 _0_ AGT --- 3 cbr 1000 [0 0 0 0] ------- [0:0 2:0 32 0] [3] 0 0
r 1.024000000 _0_ RTR --- 3 cbr 1000 [0 0 0 0] ------- [0:0 2:0 32 0] [3] 0 0
s 1.024000000 _0_ RTR --- 3 cbr 1020 [0 0 0 0] ------- [0:0 2:0 30 1] [3] 0 0
r 1.031497547 _1_ MAC --- 2 cbr 1020 [13a 1 0 800] ------- [0:0 2:0 30 1] [2] 1 0
s 1.031507547 _1_ MAC --- 0 ACK 38 [0 0 0 0]
r 1.031522547 _1_ RTR --- 2 cbr 1020 [13a 1 0 800] ------- [0:0 2:0 30 1] [2] 1 0
f 1.031522547 _1_ RTR --- 2 cbr 1020 [13a 1 0 800] ------- [0:0 2:0 29 2] [2] 1 0
r 1.031812047 _0_ MAC --- 0 ACK 38 [0 0 0 0]
s 1.032000000 _0_ AGT --- 4 cbr 1000 [0 0 0 0] ------- [0:0 2:0 32 0] [4] 0 0
r 1.032000000 _0_ RTR --- 4 cbr 1000 [0 0 0 0] ------- [0:0 2:0 32 0] [4] 0 0
s 1.032000000 _0_ RTR --- 4 cbr 1020 [0 0 0 0] ------- [0:0 2:0 30 1] [4] 0 0
s 1.032221547 _1_ MAC --- 0 RTS 44 [242e 2 1 0]
s 1.032222047 _0_ MAC --- 0 RTS 44 [242e 1 0 0]
r 1.032574047 _2_ MAC --- 0 RTS 44 [242e 2 1 0]
s 1.033168547 _1_ MAC --- 0 RTS 44 [242e 2 1 0]
r 1.033521047 _2_ MAC --- 0 RTS 44 [242e 2 1 0]
s 1.033531047 _2_ MAC --- 0 CTS 38 [22f4 1 0 0]
r 1.033835547 _1_ MAC --- 0 CTS 38 [22f4 1 0 0]
...

Trace Format for Wireless


s 1.032000000 _0_ RTR --- 4 cbr 1020 [0 0 0 0] ------- [0:0 2:0 30 1] [4] 0 0

1Event
2Time
3NodeID
4Layer
7PacketType
8Packetsize
14Sourceaddress
15Destinationaddress

s:send
r:receive
d:drop
f:forward
RTR:RouterTrace
AGT:AgentTrace
MAC:MACTrace
src_node:port
dest_node:port

The New Trace Format

ns-2 now provide new trace format

Easier to understand

Easier to perform analysis

To use the new trace format

Add one statement in the OTcl script

$ns use-newtrace

The New Trace Format


s -t 1.000000000 -Hs 0 -Hd -2 -Ni 0 -Nx 350.00 -Ny 500.00 -Nz 0.00 -Ne
-1.000000 -Nl AGT -Nw --- -Ma 0 -Md 0 -Ms 0 -Mt 0 -Is 0.0 -Id 2.0 -It cbr
-Il 1000 -If 0 -Ii 0 -Iv 32 -Pn cbr -Pi 0 -Pf 0 -Po 0
7parts:
1Event
s
2Time
t1.000000000
3NextHop
Hs0Hd2
4NodeProperty
Ni0Nx350.00Ny500.00Nz0.00Ne1.000000
NlAGTNw
5PacketInformationatMACLayer
Ma0Md0Ms0Mt0
6PacketInformationatIPLayer
Is0.0Id2.0ItcbrIl1000If0Ii0Iv32
7PacketInformationatApplicationLayer
PncbrPi0Pf0Po0

The New Trace Files Details (1)

Event

s : send

r : receive

d : drop

f : forward

Time

-t : The time for the event

The New Trace Files Details (2)

Next Hop Information

-Hs : id for this node

-Hd : id the next hop towards the destination

Node property tyep tag

-Ni : node id

-Nx -Ny -Nz : node's x/y/z coordinate

-Ne: node energy level

-Nl : trace level (AGT, RTR, MAC)

-Nw : reason for the event

The New Trace Files Details (3)

Packet Information at MAC Layer

-Ma : duration

-Md : destination's ethernet address

-Ms : source's ethernet address

-Mt : ethernet type

The New Trace Files Details (4)

Packet Information at IP Layer


-Is : source address.source port number
-Id : destination address. Destination port
number
-It : packet type
-Il : packet length (packet size)
-If : flow id
-Ii : unique id
-Iv : ttl value

Analysis : Packet Loss Ratio

AWK:

BEGIN{
receive=0;
send=0;
}
{
if(($1=="s")&&($3=="_0_")&&($4=="AGT"))
send++;
if(($1=="r")&&($3=="_2_")&&($4=="AGT"))
receive++;
}
END{
printf("Send: %d, Receive: %d, Loss: %d, Loss Ratio: %f%
%\n",send,receive,send-receive,(send-receive)/send*100);
}

Example : Data Rate and Packet Loss

Study the relationship between data rate and


packet loss
A set of scenarios

The data rate increases from 0.1Mb to 1 Mb

Calculate the pakeckt loss for each scenario

Plot the figure

Modification on OTcl

Add the variable control from command line

#========================================
# Parameters: Queue Length and Event Rate
#========================================
set Data_Rate [lindex $argv 0]

Set the data rate as our variable

$cbr0 set rate_ [expr $Data_Rate*1.0]Mb

Disable the Animatior

# exec nam out.nam &

The Batch File


echo "0.1 \c" > loss.txt
ns data-rate.tcl 0.1
awk -f loss.awk out.tr >> loss.txt
echo "0.2 \c" > loss.txt
ns data-rate.tcl 0.2
awk -f loss.awk out.tr >> loss.txt
...
echo "1 \c" > loss.txt
ns data-rate.tcl 1
awk -f loss.awk out.tr >> loss.txt
gnuplot data-rate.gpl

The GPL File


set title "Impact of Data Rate on the Packet Loss Ratio"
set xlabel "Data Rate (Mb)"
set ylabel "Loss Ratio (%)"
set terminal png
set output "data_rate.png"
plot "loss.txt" with lines

Result

Questions?

Thank you !

You might also like