LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-25-2015, 07:05 AM   #1
newinubuntu
Member
 
Registered: Jan 2015
Location: India
Distribution: Ubuntu, RHEL
Posts: 37

Rep: Reputation: Disabled
problem in executing AWk script


I have one ns2 trace file. I am attaching it.

XXX.tr
Code:
+ 0.01 0 1 tcp 40 ------- 0 167772161.180 167772417.179 0 0
- 0.01 0 1 tcp 40 ------- 0 167772161.180 167772417.179 0 0
+ 0.01 1 0 tcp 40 ------- 0 167772417.180 167772161.179 0 1
- 0.01 1 0 tcp 40 ------- 0 167772417.180 167772161.179 0 1
r 0.01132 0 1 tcp 40 ------- 0 167772161.180 167772417.179 0 0
+ 0.01132 1 0 ack 40 ------- 0 167772417.179 167772161.180 0 2
- 0.01132 1 0 ack 40 ------- 0 167772417.179 167772161.180 0 2
r 0.01132 1 0 tcp 40 ------- 0 167772417.180 167772161.179 0 1
+ 0.01132 0 1 ack 40 ------- 0 167772161.179 167772417.180 0 3
- 0.01132 0 1 ack 40 ------- 0 167772161.179 167772417.180 0 3
r 0.01264 1 0 ack 40 ------- 0 167772417.179 167772161.180 0 2
+ 0.01264 0 1 tcp 40 ------- 0 167772161.180 167772417.179 1 4
- 0.01264 0 1 tcp 40 ------- 0 167772161.180 167772417.179 1 4
+ 0.01264 0 1 tcp 40 ------- 0 167772161.180 167772417.179 1 5
r 0.01264 0 1 ack 40 ------- 0 167772161.179 167772417.180 0 3
+ 0.01264 1 0 tcp 40 ------- 0 167772417.180 167772161.179 1 6
- 0.01264 1 0 tcp 40 ------- 0 167772417.180 167772161.179 1 6
+ 0.01264 1 0 tcp 40 ------- 0 167772417.180 167772161.179 1 7
- 0.01296 0 1 tcp 40 ------- 0 167772161.180 167772417.179 1 5
- 0.01296 1 0 tcp 40 ------- 0 167772417.180 167772161.179 1 7
r 0.01396 0 1 tcp 40 ------- 0 167772161.180 167772417.179 1 4
+ 0.01396 1 0 tcp 69 ------- 0 167772417.180 167772161.179 1 8
- 0.01396 1 0 tcp 69 ------- 0 167772417.180 167772161.179 1 8
r 0.01396 1 0 tcp 40 ------- 0 167772417.180 167772161.179 1 6
+ 0.01396 0 1 tcp 69 ------- 0 167772161.180 167772417.179 1 9
- 0.01396 0 1 tcp 69 ------- 0 167772161.180 167772417.179 1 9
r 0.01428 0 1 tcp 40 ------- 0 167772161.180 167772417.179 1 5
r 0.01428 1 0 tcp 40 ------- 0 167772417.180 167772161.179 1 7
r 0.015512 1 0 tcp 69 ------- 0 167772417.180 167772161.179 1 8
r 0.015512 0 1 tcp 69 ------- 0 167772161.180 167772417.179 1 9
+ 0.1 1 0 ack 40 ------- 0 167772417.179 167772161.180 1 10
- 0.1 1 0 ack 40 ------- 0 167772417.179 167772161.180 1 10
+ 0.1 0 1 ack 40 ------- 0 167772161.179 167772417.180 1 11
- 0.1 0 1 ack 40 ------- 0 167772161.179 167772417.180 1 11
r 0.10132 1 0 ack 40 ------- 0 167772417.179 167772161.180 1 10
+ 0.10132 0 1 tcp 59 ------- 0 167772161.180 167772417.179 30 12
- 0.10132 0 1 tcp 59 ------- 0 167772161.180 167772417.179 30 12
r 0.10132 0 1 ack 40 ------- 0 167772161.179 167772417.180 1 11
+ 0.10132 1 0 tcp 59 ------- 0 167772417.180 167772161.179 30 13
- 0.10132 1 0 tcp 59 ------- 0 167772417.180 167772161.179 30 13
r 0.102792 0 1 tcp 59 ------- 0 167772161.180 167772417.179 30 12
r 0.102792 1 0 tcp 59 ------- 0 167772417.180 167772161.179 30 13
+ 0.2 1 0 ack 40 ------- 0 167772417.179 167772161.180 1 14
- 0.2 1 0 ack 40 ------- 0 167772417.179 167772161.180 1 14
+ 0.2 0 1 ack 40 ------- 0 167772161.179 167772417.180 1 15
- 0.2 0 1 ack 40 ------- 0 167772161.179 167772417.180 1 15
r 0.20132 1 0 ack 40 ------- 0 167772417.179 167772161.180 1 14
r 0.20132 0 1 ack 40 ------- 0 167772161.179 167772417.180 1 15
+ 1 0 1 tcp 92 ---A--- 0 167772161.180 167772417.179 49 16
- 1 0 1 tcp 92 ---A--- 0 167772161.180 167772417.179 49 16
r 1.001736 0 1 tcp 92 ---A--- 0 167772161.180 167772417.179 49 16
+ 1.1 1 0 ack 40 ------- 0 167772417.179 167772161.180 1 17
- 1.1 1 0 ack 40 ------- 0 167772417.179 167772161.180 1 17
r 1.10132 1 0 ack 40 ------- 0 167772417.179 167772161.180 1 17
+ 2 1 0 tcp 92 ---A--- 0 167772417.180 167772161.179 49 18
- 2 1 0 tcp 92 ---A--- 0 167772417.180 167772161.179 49 18
r 2.001736 1 0 tcp 92 ---A--- 0 167772417.180 167772161.179 49 18
+ 2.1 0 1 ack 40 ------- 0 167772161.179 167772417.180 1 19
- 2.1 0 1 ack 40 ------- 0 167772161.179 167772417.180 1 19
r 2.10132 0 1 ack 40 ------- 0 167772161.179 167772417.180 1 19
+ 28 0 1 tcp 92 ---A--- 0 167772161.180 167772417.179 101 20
- 28 0 1 tcp 92 ---A--- 0 167772161.180 167772417.179 101 20
r 28.001736 0 1 tcp 92 ---A--- 0 167772161.180 167772417.179 101 20
+ 28.1 1 0 ack 40 ------- 0 167772417.179 167772161.180 1 21
- 28.1 1 0 ack 40 ------- 0 167772417.179 167772161.180 1 21
r 28.10132 1 0 ack 40 ------- 0 167772417.179 167772161.180 1 21
+ 28.10132 0 1 tcp 92 ------- 0 167772161.180 167772417.179 153 22
- 28.10132 0 1 tcp 92 ------- 0 167772161.180 167772417.179 153 22
r 28.103056 0 1 tcp 92 ------- 0 167772161.180 167772417.179 153 22
+ 28.2 1 0 ack 40 ------- 0 167772417.179 167772161.180 1 23
- 28.2 1 0 ack 40 ------- 0 167772417.179 167772161.180 1 23
r 28.20132 1 0 ack 40 ------- 0 167772417.179 167772161.180 1 23
+ 29 1 0 tcp 92 ---A--- 0 167772417.180 167772161.179 101 24
- 29 1 0 tcp 92 ---A--- 0 167772417.180 167772161.179 101 24
r 29.001736 1 0 tcp 92 ---A--- 0 167772417.180 167772161.179 101 24
+ 29.1 0 1 ack 40 ------- 0 167772161.179 167772417.180 1 25
- 29.1 0 1 ack 40 ------- 0 167772161.179 167772417.180 1 25
r 29.10132 0 1 ack 40 ------- 0 167772161.179 167772417.180 1 25
Now i want to calculate the throughput from this trace file using awk script.
throughput.awk
Code:
BEGIN {
       recvdSize = 0
       startTime = 1.0
       stopTime = 1000.0
  }
   
  {
       
       # Trace line format: new
       if ($2 == "-t") {
             event = $1
             time = $3
             node_id = $5
             flow_id = $39
             pkt_id = $41
             pkt_size = $37
             flow_t = $45
             level = $19
       }
   
  # Store start time
  if (level == "AGT" && (event == "+" || event == "r") && pkt_size >= 512) {
    if (time < startTime) {
             startTime = time
             }
       }
   
  # Update total received packets' size and store packets arrival time
  if (level == "AGT" && event == "r" && pkt_size >= 512) {
       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
       }
  }
   
  END {
       if(startTime)printf("Average Throughput[kbps] = %.2f\t\t StartTime=%.2f\tStopTime=%.2f\n",(recvdSize/(stopTime-startTime))*(8/1000),startTime,stopTime)
  }
OUTPUT:
Code:
Average Throughput[kbps] = 0.00		 StartTime=1.00	StopTime=1000.00
I am new to this awk script. Please help me out..
 
Old 05-25-2015, 07:50 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 & 7
Posts: 3,025

Rep: Reputation: 806Reputation: 806Reputation: 806Reputation: 806Reputation: 806Reputation: 806Reputation: 806
This rule is never true in the data you provided:

Code:
if ($2 == "-t")
 
Old 05-31-2015, 01:06 PM   #3
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2018 CentOS6.10 CentOS7.5 + 50+ other Linux OS, for test only.
Posts: 17,105

Rep: Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489
The script "throughput.awk" is just one of the many scripts for ns2 throughput.

* Some of the others are ....
avg_throughput.awk
avg_throughput-zigbee.awk
avg_thr_wirelss.awk
chainThroughput.pl
e2ethroughput.awk
flow-thr.awk
genthroughput.awk
instantThroughput.awk
instantThroughputStll.awk
Lianghui-throughput.pl
myflowcalcall_throu.awk
thpt.awk
thr_drop_delay.awk
thr-one.pl
Throughput2007.awk
throughput-8.pl
throughput-9.pl
throughput_newtrace.awk
throughput.pl
thruput.awk
updown-link-thr.pl
uu-cope_throughput.pl
wireless-thr.awk

... See "awk-and-perl_scripts_12.2014.tar.gz"
https://drive.google.com/file/d/0B7S...ew?usp=sharing


-

Last edited by knudfl; 06-01-2015 at 07:56 AM.
 
Old 06-04-2015, 01:26 PM   #4
amal79
LQ Newbie
 
Registered: Jun 2015
Posts: 9
Blog Entries: 3

Rep: Reputation: Disabled
Thumbs up New NS2 trace file format

Hello,
Do you have the throughout. awk that we could used it with new trace format for wireless network
 
  


Reply

Tags
ns2


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in executing script through crontab azheruddin Linux - Newbie 19 10-30-2015 01:46 PM
[SOLVED] Problem executing commandline from script via cron battles Linux - Newbie 3 09-04-2014 11:14 AM
Executing a awk command inside perl script -- Alkass Linux - Newbie 1 07-30-2011 11:33 AM
[SOLVED] Executing awk script without file name vinaytp Linux - Newbie 5 07-15-2010 09:19 PM
Problem in executing a shell script ursvmg Linux - Newbie 1 05-19-2009 10:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration