Calculate throughput in NS2 using AWK

starrr picture starrr · Jul 2, 2012 · Viewed 9.4k times · Source

enter image description here My senario in NS 2.29 has 5 nodes which each node has 2 interfaces to expect node 0 and node 4 and node 0 wants to send packet to node 4. The protocol I've used is AODV and type of nodes is wireless

I want to calculate

receive packet / send packet

and also throughput in different simulation time and I want to do all with AWK language.

I dont know how to share output file to undrestand what I said.

output file :

s -t 0.100000000 -Hs 0 -Hd -2 -Ni 0 -Nx 0.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 4.0 -It cbr -Il 1000 -If 1 -Ii 0 -Iv 32 -Pn cbr -Pi 0 -Pf 0 -Po 0 

r -t 0.100000000 -Hs 0 -Hd -2 -Ni 0 -Nx 0.00 -Ny 500.00 -Nz 0.00 -Ne -1.000000 -Nl RTR -Nw --- -Ma 0 -Md 0 -Ms 0 -Mt 0 -Is 0.0 -Id 4.0 -It cbr -Il 1000 -If 1 -Ii 0 -Iv 32 -Pn cbr -Pi 0 -Pf 0 -Po 0 

s 0.100000000 _0_ RTR  --- 0 AODV 48 [0 0 0 0] ------- [0:255 -1:255 30 0] [0x2 1 1 [4 0] [0 4]] (REQUEST)

s -t 0.100295000 -Hs 0 -Hd -2 -Ni 0 -Nx 0.00 -Ny 500.00 -Nz 0.00 -Ne -1.000000 -Nl MAC -Nw --- -Ma 0 -Md ffffffff -Ms 0 -Mt 800 -Is 0.255 -Id -1.255 -It AODV -Il 100 -If 0 -Ii 0 -Iv 30 -P aodv -Pt 0x2 -Ph 1 -Pb 1 -Pd 4 -Pds 0 -Ps 0 -Pss 4 -Pc REQUEST 

r -t 0.101095133 -Hs 1 -Hd -2 -Ni 1 -Nx 40.00 -Ny 500.00 -Nz 0.00 -Ne -1.000000 -Nl MAC -Nw --- -Ma 0 -Md ffffffff -Ms 0 -Mt 800 -Is 0.255 -Id -1.255 -It AODV -Il 48 -If 0 -Ii 0 -Iv 30 -P aodv -Pt 0x2 -Ph 1 -Pb 1 -Pd 4 -Pds 0 -Ps 0 -Pss 4 -Pc REQUEST 

r -t 0.101120133 -Hs 1 -Hd -2 -Ni 1 -Nx 40.00 -Ny 500.00 -Nz 0.00 -Ne -1.000000 -Nl RTR -Nw --- -Ma 0 -Md ffffffff -Ms 0 -Mt 800 -Is 0.255 -Id -1.255 -It AODV -Il 48 -If 0 -Ii 0 -Iv 30 -P aodv -Pt 0x2 -Ph 1 -Pb 1 -Pd 4 -Pds 0 -Ps 0 -Pss 4 -Pc REQUEST 

s 0.102001360 _1_ RTR  --- 0 AODV 48 [0 ffffffff 0 800] ------- [1:255 -1:255 29 0] [0x2 2 1 [4 0] [0 4]] (REQUEST)

s -t 0.102476360 -Hs 1 -Hd -2 -Ni 1 -Nx 40.00 -Ny 500.00 -Nz 0.00 -Ne -1.000000 -Nl MAC -Nw --- -Ma 0 -Md ffffffff -Ms 1 -Mt 800 -Is 1.255 -Id -1.255 -It AODV -Il 100 -If 0 -Ii 0 -Iv 29 -P aodv -Pt 0x2 -Ph 2 -Pb 1 -Pd 4 -Pds 0 -Ps 0 -Pss 4 -Pc REQUEST 

r -t 0.103276493 -Hs 0 -Hd -2 -Ni 0 -Nx 0.00 -Ny 500.00 -Nz 0.00 -Ne -1.000000 -Nl MAC -Nw --- -Ma 0 -Md ffffffff -Ms 1 -Mt 800 -Is 1.255 -Id -1.255 -It AODV -Il 48 -If 0 -Ii 0 -Iv 29 -P aodv -Pt 0x2 -Ph 2 -Pb 1 -Pd 4 -Pds 0 -Ps 0 -Pss 4 -Pc REQUEST 

r -t 0.103301493 -Hs 0 -Hd -2 -Ni 0 -Nx 0.00 -Ny 500.00 -Nz 0.00 -Ne -1.000000 -Nl RTR -Nw --- -Ma 0 -Md ffffffff -Ms 1 -Mt 800 -Is 1.255 -Id -1.255 -It AODV -Il 48 -If 0 -Ii 0 -Iv 29 -P aodv -Pt 0x2 -Ph 2 -Pb 1 -Pd 4 -Pds 0 -Ps 0 -Pss 4 -Pc REQUEST 

s 0.105531867 _1_ RTR  --- 0 AODV 48 [0 ffffffff 0 800] ------- [1:255 -1:255 29 0] [0x2 2 1 [4 0] [0 4]] (REQUEST)

s -t 0.105786867 -Hs 1 -Hd -2 -Ni 1 -Nx 40.00 -Ny 500.00 -Nz 0.00 -Ne -1.000000 -Nl MAC -Nw --- -Ma 0 -Md ffffffff -Ms 2 -Mt 800 -Is 1.255 -Id -1.255 -It AODV -Il 100 -If 0 -Ii 0 -Iv 29 -P aodv -Pt 0x2 -Ph 2 -Pb 1 -Pd 4 -Pds 0 -Ps 0 -Pss 4 -Pc REQUEST 

r -t 0.106587000 -Hs 2 -Hd -2 -Ni 2 -Nx 80.00 -Ny 500.00 -Nz 0.00 -Ne -1.000000 -Nl MAC -Nw --- -Ma 0 -Md ffffffff -Ms 2 -Mt 800 -Is 1.255 -Id -1.255 -It AODV -Il 48 -If 0 -Ii 0 -Iv 29 -P aodv -Pt 0x2 -Ph 2 -Pb 1 -Pd 4 -Pds 0 -Ps 0 -Pss 4 -Pc REQUEST 

r -t 0.106612000 -Hs 2 -Hd -2 -Ni 2 -Nx 80.00 -Ny 500.00 -Nz 0.00 -Ne -1.000000 -Nl RTR -Nw --- -Ma 0 -Md ffffffff -Ms 2 -Mt 800 -Is 1.255 -Id -1.255 -It AODV -Il 48 -If 0 -Ii 0 -Iv 29 -P aodv -Pt 0x2 -Ph 2 -Pb 1 -Pd 4 -Pds 0 -Ps 0 -Pss 4 -Pc REQUEST 

s 0.109702791 _2_ RTR  --- 0 AODV 48 [0 ffffffff 2 800] ------- [2:255 -1:255 28 0] [0x2 3 1 [4 0] [0 4]] (REQUEST)

s -t 0.110077791 -Hs 2 -Hd -2 -Ni 2 -Nx 80.00 -Ny 500.00 -Nz 0.00 -Ne -1.000000 -Nl MAC -Nw --- -Ma 0 -Md ffffffff -Ms 4 -Mt 800 -Is 2.255 -Id -1.255 -It AODV -Il 100 -If 0 -Ii 0 -Iv 28 -P aodv -Pt 0x2 -Ph 3 -Pb 1 -Pd 4 -Pds 0 -Ps 0 -Pss 4 -Pc REQUEST 

....

to be continue

Can anybody explain how can I do this? Any answer will be very helpfull. Thanks

Answer

Dennis Williamson picture Dennis Williamson · Jul 2, 2012

Let's say you have the following two data lines which consist of a timestamp and a number of bytes sent during the time interval ending with that timestamp:

s 1341227109 10010
r 1341227111 19115
s 1341227118 12345
r 1341227122 16773

This snippet would calculate the throughput during the time interval between the two events:

awk '! sprev && $1 == "s" {sprev = $2; next} $1 == "s" {sinterval = $2 - sprev; sthroughput = $2 / sinterval; print sthroughput, "sent bytes/second"}' inputfile

add similar blocks for received data. You can use arrays to track node to node communication separately if needed.

Issues to be addressed:

  • Do you want to output throughput for each interval? Probably not. Is it good enough to use the first and last event only? Do you want to do some sort of moving calculation taking some number of events or larger segements of time?
  • Are there different types of events that need to be accounted separately?
  • Is there data to be ignored or used in setup?

It looks to me that the more natural choice for processing NS2 data might be TCL since it appears to be used within the package and there may be APIs that you can take advantage of. However, AWK is perfectly suited for processing tabular data.