Documente Academic
Documente Profesional
Documente Cultură
Presented by,
Amritha Sampath
Department of Computer Science
RSET
NS2 Workshop
5.
6.
7.
-: disable
1st = E: ECN (Explicit Congestion Notification) echo
is enabled.
2nd = P: the priority in the IP header is enabled.
3rd: Not in use
4th = A: Congestion action
5th = E: Congestion has occurred.
6th = F: The TCP fast start is used.
7th = N: Explicit Congestion Notification (ECN) is on.
Flow ID
Source Address :the format of these two fields is
a.b, where a isthe address and b is the port.
10. Destination Address
11. Sequence Number
12. Packet Unique ID
8.
9.
NS2 Workshop
AWK file
Language that scans through a file line by
line
Data driven
Access any column in the current line by
using special variables $1, $2, $3, etc.
BEGIN { print "START" }
{ print
}
END { print "STOP" }
4
NS2 Workshop
Eg. 1
NS2 Workshop
For TCP
#!/usr/bin/awk -f
BEGIN{
data=0
}
{
if ( $1=="r" && $4=="5" && $5=="tcp" )
{
data += $6
print $2,data*8.0/$2/1000000
}
}
END{
#print "Completed"
}
NS2 Workshop
For UDP
#!/usr/bin/awk -f
BEGIN{
data=0
}
{
if ( $1=="r" && $4=="4" && $5=="cbr" )
{
data += $6
print $2,data*8.0/$2/1000000
}
}
END{
#print "Completed"
}
NS2 Workshop
<output_file>
NS2 Workshop
Xgraph
Plotting purposes.
Comes together with NS2 installation
package.
Running Xgraph
xgraph <inputfile1>...<inputfilen > -bg
NS2 Workshop
10
NS2 Workshop
Wireless Networks
Adhoc Networks
Ad-hoc networks are wireless networks
12
NS2 Workshop
Basic setup
Create simulator instance
NS2 Workshop
Create topography :
Director):
create-god <number_of_nodes>
Eg: create-god $val(nn)
14
NS2 Workshop
Simulation of Adhoc
Networks
Specify components of the mobile node:
set val(chan)
Channel/WirelessChannel
set val(prop)
Propagation/TwoRayGround
propagation model
set val(ant)
Antenna/OmniAntenna
set val(ll)
LL
set val(ifq)
Queue/DropTail/PriQueue
type
set val(ifqlen)
50
ifq
set val(netif)
Phy/WirelessPhy
interface type
set val(mac)
Mac/802_11
set val(rp)
DSDV
protocol
set val(nn)
2
mobilenodes
15
NS2 Workshop
;# channel type
;# radio;# Antenna type
;# Link layer type
;# Interface queue
;# max packet in
;# network
;# MAC type
;# ad-hoc routing
;# number of
Configuration of the
mobile nodes
$<simulator_name> node-config
<option_1> <value_1> \
<option_2>
<value_2> \
...
...
...
<option_n>
<value_n>
16
NS2 Workshop
Eg:
$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 \
-channel $chan \
-agentTrace ON\
-routerTrace ON\
-macTrace ON\
-movementTrace ON
17
NS2 Workshop
Finish Procedure
proc <proc_name> { }
{
global <vaiable_list>
<file_list>
$<simulator_name>
flush-trace
close $<file_name>
exit 0
}
18
NS2 Workshop
Eg:
proc finish {} {
global nt nm ns
$ns flush-trace
close $nt
close $nm
exit 0
}
are created
set <node_name> [$<simulator_name> node]
Eg: set n0 [$ns node ]
Enable/disable random motion
NS2 Workshop
$<simulator_name> initial_node_pos
$<node_name> <size>
Eg: $ns initial_node_pos $n0 10
Setting initial position
NS2 Workshop
$<simulator_name> at <time>
"$<node_name> setdest
<X_destination> <Y_destination>
<speed>"
Eg: $ns at 0.0 $n1 setdest 195.0 195.0
200.0
21
NS2 Workshop
Eg. 1
Create a scenario with 4 nodes with
random motion
Set up TCP flow from node 0 to node 3
Set up UDP flow from node 1 to node 3
22
NS2 Workshop
val(chan1) Channel/WirelessChannel
val(prop1) Propagation/TwoRayGround
val(netif)
Phy/WirelessPhy
val(mac)
Mac/802_11
val(ifq)
Queue/DropTail/PriQueue
val(ll)
LL
val(ant)
Antenna/OmniAntenna
val(ifqlen)
50
val(nn)
4
val(rp)
DSDV
NS2 Workshop
24
NS2 Workshop
25
NS2 Workshop
STEP 4: Create
Topography
set topo [new Topography]
$topo load_flatgrid 300 300
26
NS2 Workshop
27
NS2 Workshop
28
NS2 Workshop
NS2 Workshop
NS2 Workshop
10
10
10
10
March 13, 2016
NS2 Workshop
32
NS2 Workshop
Eg. 2
33
NS2 Workshop
Node
Time
Position
Node0
05 05
Node1
195 195
Node2
195 05
Node1
40
30 30
Node1
80
195 195
Node2
90
175 50
Procedure
Define all mobile node modules
Create simulator object
Setup Trace File
Create Topography of size 200x200.
Create Object God
Configure nodes
Write a finish procedure to close the trace and
animator files
Create nodes and configure Initial Position as the
positions in Node Movement Table at time 0.
Setup traffic flow between n0 and n2.
Create Movement as defined in Node Movement
Table.
Set Stop Time and Start Simulation.
34
NS2 Workshop
NS2 Workshop
Node movement
$ns at 0.0 "$n0 setdest 5.0 295.0 200.0"
$ns at 0.0 "$n1 setdest 5.0 5.0 200.0"
$ns at 0.0 "$n2 setdest 150.0 150.0 200.0"
$ns at 0.0 "$n3 setdest 295.0 150.0 200.0"
$ns at 1.0 "$ftp0 start"
$ns at 1.0 "$cbr1 start"
$ns at 40.0 "$n2 setdest 150.0 5.0 15.0"
$ns at 80.0 "$n2 setdest 150.0 295.0 15.0"
$ns at 120.0 "$n2 setdest 150.0 150.0 15.0"
$ns at 170.0 "$n0 reset"
$ns at 170.0 "$n1 reset"
$ns at 170.0 "$n2 reset"
$ns at 170.0 "$n3 reset"
$ns at 175.0 "$ftp0 stop"
$ns at 175.0 "$cbr1 stop"
$ns at 180.1 "finish"
36
NS2 Workshop
1.
1.
2.
3.
4.
2.
3.
4.
1.
2.
3.
4.
5.
6.
37
s - sent
r - received
D - dropped
f - forwarded
AGT - application
RTR - routing
LL - link layer
IFQ - outgoing packet queue (between link and
mac layer)
MAC - mac
PHY - physical
NS2 Workshop
flags:
SEQNO: the sequence number of the packet
TYPE: the packet type
5.
6.
7.
1.
2.
3.
4.
8.
9.
1.
2.
3.
4.
38
NS2 Workshop
10. flags:
11. [......]: [
1. source node ip : port_number
2. destination node ip (-1 means
broadcast) : port_number
3. ip header ttl
4. ip of next hop (0 means node 0 or
broadcast) ]
39
NS2 Workshop
Eg. 3
Node
Node0
Node1
Node2
Node3
Node2
Node2
Node2
40
NS2 Workshop
Time
0
0
0
0
40
80
120
Position
05 295
05 05
150 150
295 150
150 05
150 295
150 150
41
NS2 Workshop
Xgraph
42
NS2 Workshop
Conclusion
Discussed Trace file formats for wired and
wireless networks
Discussed AWK files and Xgraph
Generated graph for throughput calculation
for wired networks
TCL script for wireless networks
Generated graph for throughput calculation
for wired networks
43
NS2 Workshop
44
NS2 Workshop