The following code will count all the received application packets in a network such that we can calculated the network throughput. If a throughput of a specific node has to be calculated, then we can simply add the node_id in the if condition.
The code simply prints the observed throughput during the time_interval through out the simulation time. We can change the time_interval variable according to our requirements.
In the following code:
- packet_size * recv * 8.0 gives the total number of bits received. Packet size is the size of packed used in Application layer.
- diving the value by 1000 gives us the throughput in kbps.
#============================= throughput.awk ========================
BEGIN {
recv=0;
gotime = 1;
time = 0;
packet_size = 50;
time_interval=2;
}
#body
{
event = $1
time = $2
node_id = $3
level = $4
pktType = $7
if(time>gotime) {
print gotime, (packet_size * recv * 8.0)/1000; #packet size * ... gives results in kbps
gotime+= time_interval;
recv=0;
}
#============= CALCULATE throughput=================
if (( event == "r") && ( pktType == "cbr" ) && ( level=="AGT" ))
{
recv++;
}
} #body
END {
;
}
#============================= Ends ============================
Graph generated by above awk script. |
P.S: feel free to contact me for any help.
hi sir
ReplyDeletewhere I need to put this code after which step in my scenario ? and the result will be in the trace file??
rroaa86@yahoo.com
Good day sir, please how can i convert my trace file to matlab format, as i am trying to get my input into NN toolbox for training
ReplyDeleteregards
leye
How to calculate the end -to -end throughput for wired network from source-destination??
ReplyDeletelet t1 be the send time of first packet by source
Deletelet t2 be the send time of last packet by source
let n by the number of packets sent
let s be the size of a packet
Now, throughput =
8*n*s
------------ (in Kbits/s)
(t2-t1)*1000
This comment has been removed by the author.
ReplyDeleteThanks for the reply. I have two groups of nodes. group1 has a flowID=1 and group2 has a flowID= 2. I have a dumbbell topology:
ReplyDeletegroup1
---Node 1------------Node 2----------- Node 3 (receiver)
group 2
I want to calculate the the throughput for group 1 and group 2 ,,,,, I would appreciate your reply.
Dear
Deletejust filter your result through Flow Id , use $7....
nice blog for researcher and for all IT student.
ReplyDeleteHello sir,
ReplyDeleteIf I have the throughput value from the awk script, then after that how should I plot a graph throughput vs time. what will be the next step.
Plz help.
Thanks
u may use any graph plotting software such as ms excel, origin, sigma plot etc. as your wish...
DeleteTry using gnuplot if you are using linux.
Deletehere is link for tutorials
http://www.youtube.com/watch?v=9k-l_ol9jok
Otherwise excel can be fine for beginners.
Hello sir,
ReplyDeleteAfter plotting the graph, how can i conclude that. I can't understand the conclusion for this results.
The graph shows throughput w.r.t time. Increase in throughput means decrease in packet loss whereas, decrease in throughput means increase in packet loss may be due to collision or errrors..
ReplyDeleteHi sir,
ReplyDeleteI am grateful to you for the code above to generate a graph file from the ns2 tracefile, however, there are few things to note about your code above,
The code above calculates a fixed packetsize of 50 bytes, not based on user defined on the simulation file, so I modified your code, the calculation to be almost same as this in his tcl code
puts $f0 "$now [expr $bw0/$time*8/1000000]" # in MB
from
http://www.isi.edu/nsnam/ns/tutorial/ns.html, and compared the initial results, most of the data are the same although some of them are not by about 1-5 offsets I think.
where
$bw0 = bytes received
$time = interval
where I modified the calculation part is
print gotime, ((packetsize * recv)/ interval * 8/1000) #for KB
where the packetsize on above calculations are taken from ns2 tracefile records
Currently I am working on modifying this to accommodate the new tracefile format
Thank you so much for this code.
-asraf
sir can u provide me all the awk script for ns2... plz sir sir help me
ReplyDeleteregards
davenda
devsa.devra@gmail.com
Sir i want to implement 802.15.4 in NS2 ....can you please help me....?
ReplyDeleteI just want to measure performance parameters.....
ok I will try to make new blog on IEEE 802.15.4 soon. I hope it will be helpful for others also....
DeleteSir what is the maximum value of throughput in a network ..
ReplyDeletethroughput = number of bits received / time to receive those bits
Deletehowever, the number of bits received should be the pure data bits excluding control packets. If you continuously transmit data for 1 sec and measure the throughput for that 1 sec then the throughput is exactly equal to data rate. But in practice, throughput is always less than data rate. The maximum theoretical value of throughput can be close to employed data rate.
Hi sir,
ReplyDeleteI'm sorry in going for off-topic a little bit, do you know how to use AODV-UU properly for simulation scripts?
-asraf
hello Sir,
ReplyDeleteI am working with simulation of wired cum wireless topology in ns2. Please tell how to set the bandwidth of the link from the base station to the terminal is
1Mbps, and the delay is 0.01ms.
Hi sir!!
ReplyDeletehow do i get a graph for throughput? can you please tell me the format for calling a graph
you can use any graph plotting tool such as excel or you can also use xgraph command
Deletelink for xgraph is http://www.xgraph.org/
hi sir ! I'm student from indonesia.
ReplyDeletesir what a difference Old and New trace files ? i have some trouble when i calculate awk from trace files
this is an error : " awk : awk_throuhput.awk:312:(FILENAME:wpanc.tr FNR:52523) fatal:division by zero attemped "
may i get your sugestion ?
try to check the value of divisor..the error is because you are trying to divide by zero..
ReplyDeleteHi Pranesh
ReplyDeleteplease tell how to make the graph after getting throughput fro different time duration
thanks
u may use any graph plotting software such as ms excel, origin, sigma plot etc. as your wish...
Deleteit means start time is always 0 for values given in graph in research papers
ReplyDeletebecause as time increases throughput increases
means for time duration 20-30
start time 0 stop time 20
start time 0 stop time 30
After parsing the trace file I am getting -nan in the output. how to fix this ?
ReplyDeleteHi,
ReplyDeleteI am trying to calculate throughput ,delay and packet loss for a wired cum wireless network. Please, can you help me in this because the trace file is mixed between the wired and wireless format.
Hi,
ReplyDeleteI am trying to calculate throughput ,delay and packet loss for a wired cum wireless network. Please, can you help me in this because the trace file is mixed between the wired and wireless format.
hi,
ReplyDeleteI tried this code and I get throughput= -0.0 and start time =400 , end time =0
What should I do to get the actual throughput?
Did you supply trace file name??
Deleteeg. throughput.awk trace.tr
Sir,
ReplyDeleteI had a doubt in the formula you used in calculating throughput. Aren't the total number of bit supposed to be divided by the time interval, which is two in this case?
Thank You
i want correct formula for calculating throughput for TCP protocol for wired Network.. pls help me
ReplyDeletehello sir,
ReplyDeletei do not understand how the coding was done, please can you explain it line by line.
hello sir,
ReplyDeletei do not understand how the coding was done, please can you explain it line by line.
hello,
ReplyDeletecould you help me to calculate throughput and e2edelay for wire networking
kind regareds
Hi Sir,
ReplyDeleteI am new to NS2. I want to plot graph using xgraph tool. I have a simple tcl code of two nodes that send packets to each other. I have an awk script to extract the time and packet size. When i run the awk script i get only a single row from which i cannot plot the graph. Please help me in this code.
trace file format:
+ 0.51 0 1 cbr 100 ------- 0 0.0 1.0 2 4
- 0.51 0 1 cbr 100 ------- 0 0.0 1.0 2 4
+ 0.51 1 0 cbr 100 ------- 0 1.1 0.1 2 5
- 0.51 1 0 cbr 100 ------- 0 1.1 0.1 2 5
r 0.5108 0 1 cbr 100 ------- 0 0.0 1.0 0 0
....
.....
AWK script:
BEGIN {
recvdSize = 0
startTime = 0
stopTime = 500
}
{
event = $1
time = $2
node_id = $3
node_id = $4
pkt_size = $6
level = $5
# Store start time
if ($1 == "r" && $5 == "cbr" && pkt_size = 100) {
if (time < startTime) {
startTime = time
}
}
# Update total received packets' size and store packets arrival time
if ($1 == "r" && $5 == "cbr" && pkt_size = 100) {
if (time < stopTime) {
stopTime = time
}
# Rip off the header
#hdr_size = pkt_size % 512
#pkt_size -= hdr_size
# Store received packet's size
recvdSize += pkt_size
}
#printf("Value of the number of packets",recvdSize)
}
END {
printf("%10s %10g",event, time)
printf("Value of the number of packets %d",recvdSize)
printf("Average Throughput[kbps] = %.2f\t\t StartTime=%.2f\tStopTime=%.2f\n",(recvdSize/(stopTime-startTime))*(8/1000),startTime,stopTime)
}
Ouput after running the AWK script:
r 4.5108 Value of the number of packets 160200 Average Throughput[kbps] = 2509.01 StartTime=0.00 StopTime=0.51
Please help me understanding the code and how to plot the graph.
Thanks & Regards
kindly help me in understanding where to put the code and how ro observe the results sir
ReplyDeletekindly help me in understanding where to put the code and how ro observe the results sir
ReplyDeleteits a awk file so please read about awk in linux. thanks
ReplyDeletehello sir
ReplyDeletecan you please provide me awk script for wired network thanks in advance!!!!!!!!!!!!!!!!!!
gawk -f
ReplyDeletehello sir.. i want to know how to execute this throughput code. where to place this code in tcl file?
ReplyDeleteHello sir,
ReplyDeleteI want to find out packet loss for AODV and also want to plot graph for that,Please guide me .
hello,
ReplyDeletehow to calculate throughput for each and every node in wireless networks.so that plotting of graph with numerous values will be accurate
Hello sir?
ReplyDeleteI have seen some of your blogs.Please guide me regarding how to integrate packet loss differentiation algorithms for any scenario taken on NS2?
Thank you sir
hello sir,
ReplyDeletecan u help us in the ollowing matter.
1)using this awk file in our program can we plot xgraph???
and if yes what is the command for that
You can use bash script for that. Create a bash script, call awk script from bash file and then dump the result into a temp file using '>' operation and then call xgraph.
DeleteYou bash file would look like as follows
e.g.
ns xyz.tcl
awk -f throghput.awk xyz.tr > th.txt
xgraph th.txt
Hi
ReplyDeleteDo you have scripts for new trace format?
Sir: How we can change the packet size and time interval between packets in running time. pleas help me Sir!
ReplyDeleteSir Awk file not run in ns2
ReplyDeleteerror -f command not found how?
Sir, can you please explain how to calculate throughput for wireless network using trace and awk files.
ReplyDelete