You are on page 1of 44

Traces, AWK and Xgraph

Presented by,
Amritha Sampath
Department of Computer Science
RSET

Trace Files for Wired


Networks
1. Type Identifier: Type of Event

+: a packet enqueue event


-: a packet dequeue event
r: a packet reception event
d: a packet drop event
c: a packet collision at the MAC level

2. Time: at which the packet tracing string is created.


3. Source Node : denote the IDs of the source node of

the tracing object.


4. Destination Node : denote the IDs of the
destination
2

NS2 Workshop

March 13, 2016

Packet Name: Name of the packet type


Packet Size: Size of the packet in bytes.
Flags: A 7-digit flag string

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

March 13, 2016

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

March 13, 2016

Eg. 1

NS2 Workshop

March 13, 2016

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

March 13, 2016

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

March 13, 2016

To run awk script


awk -f <filename.awk> <input_file> >

<output_file>

NS2 Workshop

March 13, 2016

Xgraph
Plotting purposes.
Comes together with NS2 installation

package.
Running Xgraph
xgraph <inputfile1>...<inputfilen > -bg

<color> -t <graph_title> -x <xtitle> -y


<ytitle>

NS2 Workshop

March 13, 2016

10

NS2 Workshop

March 13, 2016

Wireless Networks

Adhoc Networks
Ad-hoc networks are wireless networks

where nodes communicate with each other


using multi-hop links.
No stationary infrastructure or base station
for communication.
Each node itself acts as a router for
forwarding and receiving packets to/from
other nodes.

12

NS2 Workshop

March 13, 2016

Basic setup
Create simulator instance

Eg: set ns [new Simulator]


Open trace file and activate it

Eg: set nt [open 3nodes.tr w]


$ns trace-all $nt
Open namtrace file and activate it
$<simulator_name> namtrace-all-wireless $<namfile_name> <size_X> <size_Y>

Eg: set nm [open 3nodes.nam w]


$ns namtrace-all-wireless $nm 200 200
13

NS2 Workshop

March 13, 2016

Create topography :

set <topography_name> [new Topography]


$<topography_name> load_flatgrid <size_x>
<size_y>
Eg: set topo [new Topography]
$topo load_flatgrid 200 200
Create the GOD object (General Operations

Director):

create-god <number_of_nodes>
Eg: create-god $val(nn)
14

NS2 Workshop

March 13, 2016

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

March 13, 2016

Configuration of the
mobile nodes
$<simulator_name> node-config
<option_1> <value_1> \
<option_2>
<value_2> \
...
...
...
<option_n>
<value_n>
16

NS2 Workshop

March 13, 2016

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

March 13, 2016

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
}

March 13, 2016

Creating the nodes


After setting the configuration options, the nodes

are created
set <node_name> [$<simulator_name> node]
Eg: set n0 [$ns node ]
Enable/disable random motion

$<node_name> random-motion <value>


Value=0 to disable random motion
=1 to enable random motion
Eg: $n0 random-motion 0
19

NS2 Workshop

March 13, 2016

Setting node size

$<simulator_name> initial_node_pos
$<node_name> <size>
Eg: $ns initial_node_pos $n0 10
Setting initial position

$<node_name> set X_ <x_location>


$<node_name> set Y_ <y_location>
$<node_name> set Z_ 0
Eg: $n0 set X_ 0.0
$n0 set Y_ 0.0
$n0 set Z_ 0.0
20

NS2 Workshop

March 13, 2016

Setting node positions

$<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

March 13, 2016

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

March 13, 2016

STEP 1: Define all mobile


node modules
set
set
set
set
set
set
set
set
set
set
23

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

March 13, 2016

STEP 2: Create simulator


object
set ns [new Simulator]

24

NS2 Workshop

March 13, 2016

STEP 3: Setup Trace File


set nt [open throughput.tr w]
$ns trace-all $nt
set nm [open throughput.nam w]
$ns namtrace-all-wireless $nm 300 300

25

NS2 Workshop

March 13, 2016

STEP 4: Create
Topography
set topo [new Topography]
$topo load_flatgrid 300 300

26

NS2 Workshop

March 13, 2016

STEP 5: Create Object God


create-god $val(nn)

27

NS2 Workshop

March 13, 2016

STEP 6: 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(prop1)\
-phyType $val(netif)\
-channelType $val(chan1)\
-topoInstance $topo\
-agentTrace ON\
-routerTrace ON\
-macTrace ON\
-movementTrace ON

28

NS2 Workshop

March 13, 2016

STEP 7: Write a finish


procedure
proc finish {} {
global nt nm ns
$ns flush-trace
close $nt
close $nm
exec nam throughput.nam
exit 0
}
29

NS2 Workshop

March 13, 2016

STEP 8: Create nodes and start


random motion
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$n0 random-motion 1
$n1 random-motion 1
$n2 random-motion 1
$n3 random-motion 1
$n0 start
$n1 start
$n2 start
$n3 start
$ns initial_node_pos $n0
$ns initial_node_pos $n1
$ns initial_node_pos $n2
$ns initial_node_pos $n3
30

NS2 Workshop

10
10
10
10
March 13, 2016

STEP 9: Setup traffic flow


set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n3 $sink1
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns connect $tcp0 $sink1
set udp1 [new Agent/UDP]
$ns attach-agent $n1 $udp1
set sink2 [new Agent/Null]
$ns attach-agent $n3 $sink2
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$ns connect $udp1 $sink2
31

NS2 Workshop

March 13, 2016

STEP 10: Set Stop Time and


Start Simulation
$ns
$ns
$ns
$ns
$ns
$ns

32

at 1.0 "$ftp0 start"


at 1.0 "$cbr1 start"
at 175.0 "$ftp0 stop"
at 175.0 "$cbr1 stop"
at 180.1 "finish"
run

NS2 Workshop

March 13, 2016

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

March 13, 2016

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

March 13, 2016

Configure Initial Position


$n0 set X_ 5.0
$n0 set Y_ 5.0
$n0 set Z_ 0.0

$n1 set X_ 195.0


$n1 set Y_ 195.0
$n1 set Z_ 0.0

$n2 set X_ 195.0


$n2 set Y_ 5.0
$n2 set Z_ 0.0
35

NS2 Workshop

March 13, 2016

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

March 13, 2016

Trace file for Wireless


Networks
ACTION: [s|r|D|f]:

1.

1.
2.
3.
4.

WHEN: the time when the action happened


WHERE: the node where the action happened
LAYER:

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

March 13, 2016

flags:
SEQNO: the sequence number of the packet
TYPE: the packet type

5.
6.
7.
1.
2.
3.
4.

SIZE: the size of packet


[a b c d]:

8.
9.
1.
2.
3.
4.
38

cbr -- CBR data stream packet


DSR -- DSR routing packet (control packet
generated by routing)
RTS -- RTS packet generated by MAC 802.11
ARP -- link layer ARP(Address Resolution
Protocol) packet

a -- the packet duration in mac layer header


b -- the mac address of destination
c -- the mac address of source
d -- the mac type of the packet body

NS2 Workshop

March 13, 2016

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

March 13, 2016

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

March 13, 2016

Awk script for Throughput


Calculation
#!/usr/bin/awk -f
BEGIN{
#print "Throughput calculation"
data=0
}

{
if ( $1=="r" && $3=="_3_" && $7=="tcp" && $4=="MAC")
{
data += $8
print $2,data*8.0/$2/1000000
}
}

END{
#print "Completed"
}

41

NS2 Workshop

March 13, 2016

Xgraph

42

NS2 Workshop

March 13, 2016

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

March 13, 2016

44

NS2 Workshop

March 13, 2016

You might also like