LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-07-2014, 08:55 AM   #1
Nindu
LQ Newbie
 
Registered: Oct 2014
Location: INDIA
Posts: 26

Rep: Reputation: Disabled
Error when using AWK script


hello everyone
I m working on ns2.35 ubuntu 12.04
when i try to use awk script for genthroughput, instant jitter, e2e delay using command
awk -f filename.awk ns.trc >aodv.xg
then it always show that
awk: cannot open genthroughput.awk(No such file or directory)
bt it works fine for pdf (pdf and other scripts are in the same folder)
plz help me as soon as possible thanx
this z my 2nd post (nobody give reply to my first post )
 
Old 10-07-2014, 10:14 AM   #2
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Not sure you will get any usable Xgraph file.xg with
$ awk -f genthroughput.awk ns.trc > aodv.xg
* Please remember <space> :
$ awk -f genthroughput.awk ns.trc >[space]aodv.xg

File not found : Not easy to guess.
But you don't have to type any file names.
* Please take advantage of "bash completion" :
$ awk -f gen<TAB>
* And please remember : There can be no spaces in file names.

Examples, xgraph file creating, post #195 here :
http://www.linuxquestions.org/questi...26/page13.html



P.S. : Your other posts were answered ..... some time ago.


-

Last edited by knudfl; 10-07-2014 at 10:16 AM.
 
1 members found this post helpful.
Old 10-07-2014, 02:37 PM   #3
Nindu
LQ Newbie
 
Registered: Oct 2014
Location: INDIA
Posts: 26

Original Poster
Rep: Reputation: Disabled
thanx sir, command works and shows

Average Throughput[kbps] = -0.00
StartTime=400.00
StopTime=0.00

what changes i need to do ?

i read somewhere that packet size which is used in tcl script same is used in genthroughput.awk, it doesnt work
 
Old 10-07-2014, 03:08 PM   #4
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
← #3 .

Well, then please try out some of the other *th*.awk,
and perl scripts from "awk_scripts-06.2014.tar.bz2".
Download link https://drive.google.com/file/d/0B7S...ew?usp=sharing
→ →
avg_throughput.awk
avg_throughput-zigbee.awk
chainThroughput.pl
flow-thr.awk
genthroughput.awk
instantThroughput.awk
instantThroughputStll.awk
thpt.awk
thr_drop_delay.awk
thr-one.pl
Throughput2007.awk
throughput-8.pl
throughput-9.pl
throughput_newtrace.awk
thruput.awk
updown-link-thr.pl
wireless-thr.awk
 
1 members found this post helpful.
Old 10-08-2014, 05:10 AM   #5
Nindu
LQ Newbie
 
Registered: Oct 2014
Location: INDIA
Posts: 26

Original Poster
Rep: Reputation: Disabled
HELLO Knudfl
i tried all scripts some works and others show the error no such file or directory
when i use

genthroughput.awk it gives
Code:
 
Average Throughput[kbps] = -0.00  StartTime=400.00	StopTime=0.00
instantjitter.awk
Code:
 # flow   flowType   src   dst      time          jitter1          jitter2          jitter3          jitter4
NRL_ot.awk
Code:
 awk: NRL_ot.awk:22: (FILENAME=ns.trc FNR=1885840)fatal: division by zero attempted

e2edelay.awk
Code:
 
awk: e2e delay.awk:91: (FILENAME=aodv.xg FNR=4)  fatal: division by zero attempted
plz help me

Last edited by Nindu; 10-14-2014 at 08:23 AM. Reason: i forgot to write exact error
 
Old 10-08-2014, 05:47 AM   #6
Nindu
LQ Newbie
 
Registered: Oct 2014
Location: INDIA
Posts: 26

Original Poster
Rep: Reputation: Disabled
I m using following awk scripts

genthroughput.awk
Code:
BEGIN {

       recvdSize = 0

       startTime = 400

       stopTime = 0

  }

   

  {

             event = $1

             time = $2

             node_id = $3

             pkt_size = $8

             level = $4

   

  # Store start time

  if (level == "AGT" && event == "s" && 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 {

       printf("Average Throughput[kbps] = %.2f\t\t StartTime=%.2f\tStopTime=%.2f\n",(recvdSize/(stopTime-startTime))*(8/1000),startTime,stopTime)

  }


instantjitter.awk
Code:
BEGIN {
	num_recv = 0
	printf("# %10s %10s %5s %5s %15s %16s %16s %16s %16s\n\n", \
	       "flow","flowType","src","dst","time","jitter1","jitter2","jitter3","jitter4")
}

{
	# Trace line format: normal
	if ($2 != "-t") {
		event = $1
		time = $2
		if (event == "+" || event == "-") node_id = $3
		if (event == "r" || event == "d") node_id = $4
		flow_id = $8
		pkt_id = $12
		pkt_size = $6
		flow_t = $5
		level = "AGT"
	}
	# 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 packets send time
	if (level == "AGT" && flow_id == flow && node_id == src &&
	    sendTime[pkt_id] == 0 && (event == "+" || event == "s") && pkt_size >= pkt) {
		sendTime[pkt_id] = time
	}

	# Store packets arrival time
	if (level == "AGT" && flow_id == flow && node_id == dst &&
	    event == "r" && pkt_size >= pkt) {
		recvTime[pkt_id] = time
		num_recv ++
	}
}

END {
	# Compute average jitter
	jitter1 = jitter2 = jitter3 = jitter4 = tmp_recv = 0
	prev_time = delay = prev_delay = processed = currTime = 0
	prev_delay = -1
	for (i=0; processed<num_recv; i++) {
		if(recvTime[i] != 0) {
		        tmp_recv++
			if(prev_time != 0) {
				delay = recvTime[i] - prev_time
				e2eDelay = recvTime[i] - sendTime[i]
				if(delay < 0) delay = 0
				if(prev_delay != -1) {
					jitter1 += abs(e2eDelay - prev_e2eDelay)
					jitter2 += abs(delay-prev_delay)
					jitter3 += (abs(e2eDelay-prev_e2eDelay) - jitter3) / 16
					jitter4 += (abs(delay-prev_delay) - jitter4) / 16
				}
				# This 'if' is introduce to obtain clearer
				# plots from the output of this script
				if(delay >= tic*10) {
					printf("  %10g %10s %5d %5d %15g %18g\n", \
						flow,flow_t,src,dst,(prev_time+1.0),0)
					printf("  %10g %10s %5d %5d %15g %18g\n", \
						flow,flow_t,src,dst,(recvTime[i]-1.0),0)
				}
				currTime += delay
				if (currTime >= tic) {
					printf("  %10g %10s %5d %5d %15g %16g %16g %16g %16g\n", \
						flow,flow_t,src,dst,recvTime[i],jitter1*1000/tmp_recv, \
						jitter2*1000/tmp_recv,jitter3*1000,jitter4*1000)
					jitter1 = jitter2 = jitter3 = jitter4 = 0
					currTime = 0
					tmp_recv = 0
				}
				prev_delay = delay
				prev_e2eDelay = e2eDelay
			}
			prev_time = recvTime[i]
			processed++
		}
	}
}

END {
	printf("\n\n")
}

function abs(value) {
	if (value < 0) value = 0-value
	return value
}


NRL_ot.awk
Code:
BEGIN{

recvd = 0;#################### to calculate total number of data packets received

rt_pkts = 0;################## to calculate total number of routing packets received

}



{

##### Check if it is a data packet

if (( $1 == "r") && ( $7 == "cbr" || $7 =="tcp" ) && ( $4=="AGT" )) recvd++;



##### Check if it is a routing packet

if (($1 == "s" || $1 == "f") && $4 == "RTR" && ($7 =="AODV" || $7 =="message" || $7 =="DSR" || $7 =="OLSR")) rt_pkts++;

}



END{

printf("##################################################################################\n");

printf("\n");

printf("Normalized Routing Load = %.3f\n", rt_pkts/recvd);

printf("\n");

printf("##################################################################################\n");

}



e2edelay.awk
Code:
BEGIN {



    seqno = -1;    



#    droppedPackets = 0; 



#    receivedPackets = 0; 



    count = 0;



}



{



    if($4 == "AGT" && $1 == "s" && seqno < $6) {



          seqno = $6;



    } 

#	else if(($4 == "AGT") && ($1 == "r")) {



#            receivedPackets++;



#    } else if ($1 == "D" && $7 == "tcp" && $8 > 512){



#            droppedPackets++;            



#  } 



    #end-to-end delay



    if($4 == "AGT" && $1 == "s") {



          start_time[$6] = $2;



    } else if(($7 == "tcp") && ($1 == "r")) {



        end_time[$6] = $2;



    } else if($1 == "D" && $7 == "tcp") {



          end_time[$6] = -1;



    } 



}



 

END {        

  

    for(i=0; i<=seqno; i++) {



          if(end_time[i] > 0) {



              delay[i] = end_time[i] - start_time[i];



                  count++;



        }



            else



            {



                  delay[i] = -1;



            }



    }



    for(i=0; i<=seqno; i++) {



          if(delay[i] > 0) {



              n_to_n_delay = n_to_n_delay + delay[i];



        }         



    }



   n_to_n_delay = n_to_n_delay/count;



 



    print "\n";



#    print "GeneratedPackets            = " seqno+1;



#    print "ReceivedPackets             = " receivedPackets;



#    print "Packet Delivery Ratio      = " receivedPackets/(seqno+1)*100

#"%";



#    print "Total Dropped Packets = " droppedPackets;



    print "Average End-to-End Delay    = " n_to_n_delay * 1000 " ms";



    print "\n";



}

Last edited by Nindu; 10-08-2014 at 02:45 PM.
 
Old 10-08-2014, 05:54 AM   #7
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
← #6 .

The code in post #6 must be in code tags.
http://www.linuxquestions.org/questi....php?do=bbcode
http://www.linuxquestions.org/questi...gs-4175464257/
... Please edit post #6 : The 'Edit' button.

* Has the file got a name ? ?

-
 
1 members found this post helpful.
Old 10-08-2014, 12:42 PM   #8
Nindu
LQ Newbie
 
Registered: Oct 2014
Location: INDIA
Posts: 26

Original Poster
Rep: Reputation: Disabled
i edited the post no 6
plz reply as soon as possible thanx
 
Old 10-08-2014, 01:18 PM   #9
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
See post #7.

Please add some file names.
Must be unique names, if they are new files.
NRL isn't a name. "nrl-nindu.awk" or any choice will do.
And no uppercase, please.
Then it looks like you have processed the files with Windows©.
.. And that files should possibly be repaired with $ dos2unix *

-
 
1 members found this post helpful.
Old 10-08-2014, 02:52 PM   #10
Nindu
LQ Newbie
 
Registered: Oct 2014
Location: INDIA
Posts: 26

Original Poster
Rep: Reputation: Disabled
NRL is in uppercase bcoz m using awk file which is NRL_ot.awk
when m using nrl_ot.awk
it show
awk: fatal: can't open source file `nrl_ot.awk' for reading (No such file or directory)
 
Old 10-08-2014, 03:01 PM   #11
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Please spell out your words and do not use text-speak. You will get more replies to a better written and properly spelled question.

From what I can make out, you are in the wrong directory. Please read your documentation and follow the steps more closely, you will find out that you have forgotten or missed a cd command.

Last edited by szboardstretcher; 10-08-2014 at 03:02 PM.
 
Old 10-08-2014, 03:54 PM   #12
Nindu
LQ Newbie
 
Registered: Oct 2014
Location: INDIA
Posts: 26

Original Poster
Rep: Reputation: Disabled
thnx for reply sir
according to me i havn't missed cd command anywhere

Code:
root@ubuntu:/home/nona19# cd ns-allinone-2.35
root@ubuntu:/home/nona19/ns-allinone-2.35# cd ns-2.35
root@ubuntu:/home/nona19/ns-allinone-2.35/ns-2.35# cd tcl
root@ubuntu:/home/nona19/ns-allinone-2.35/ns-2.35/tcl# cd ex
root@ubuntu:/home/nona19/ns-allinone-2.35/ns-2.35/tcl/ex# gedit aodv.tcl
root@ubuntu:/home/nona19/ns-allinone-2.35/ns-2.35/tcl/ex# ns aodv.tcl
num_nodes is set 10
INITIALIZE THE LIST xListHead
10 simulation seconds
20 simulation seconds
30 simulation seconds
40 simulation seconds
|
|
|
|
2040 simulation seconds
2050 simulation seconds
root@ubuntu:/home/nona19/ns-allinone-2.35/ns-2.35/tcl/ex# gedit ns.trc
root@ubuntu:/home/nona19/ns-allinone-2.35/ns-2.35/tcl/ex# awk -f pdf.awk ns.trc > aodv.xg
root@ubuntu:/home/nona19/ns-allinone-2.35/ns-2.35/tcl/ex# gedit aodv.xg
root@ubuntu:/home/nona19/ns-allinone-2.35/ns-2.35/tcl/ex# awk -f e2edelay.awk ns.trc > aodv.xg
awk: fatal: can't open source file `e2edelay.awk' for reading (No such file or directory)
root@ubuntu:/home/nona19/ns-allinone-2.35/ns-2.35/tcl/ex# awk -f e2e\ delay.awk ns.trc > aodv.xg
awk: e2e delay.awk:91: (FILENAME=ns.trc FNR=1885840) fatal: division by zero attempted

Last edited by Nindu; 10-08-2014 at 03:55 PM.
 
Old 10-08-2014, 03:56 PM   #13
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Try this:

Code:
cd /home/nona19/ns-allinone-2.35/ns-2.35
find . -name e2edelay.awk
What is the output of those commands?
 
Old 10-08-2014, 04:17 PM   #14
Nindu
LQ Newbie
 
Registered: Oct 2014
Location: INDIA
Posts: 26

Original Poster
Rep: Reputation: Disabled
are u saying like this?

Code:
nona19@ubuntu:~$ cd /home/nona19/ns-allinone-2.35/ns-2.35
nona19@ubuntu:~/ns-allinone-2.35/ns-2.35$ cd tcl
nona19@ubuntu:~/ns-allinone-2.35/ns-2.35/tcl$ cd ex
nona19@ubuntu:~/ns-allinone-2.35/ns-2.35/tcl/ex$ gedit aodv.tcl
nona19@ubuntu:~/ns-allinone-2.35/ns-2.35/tcl/ex$ ns aodv.tcl
num_nodes is set 10
couldn't open "ns.trc": permission denied
    while executing
"open ns.trc w"
    invoked from within
"set nsTrc [open ns.trc w]"
    (file "aodv.tcl" line 209)
 
Old 10-08-2014, 05:12 PM   #15
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Ref. post #12, etc.

Ubuntu 12.04 : Must be a very strange setup you have,
when lower case file names cannot be found / picked up.
→ Strange setup, or a totally wrecked OS.


Quote:
root@ubuntu:/home/nona19/ns-allinone-2.35/ns-2.35
You are not supposed to work as root with any user application.
Root is for administrative tasks only.
The only ns2 commands that will require a root prompt are :
# make install ,,, and # cp ns-<protocol-name> /usr/local/bin/.


About using awk scripts and trace files : Some (most?) files.tr
will make many of the awk scripts choke, and return :
"division by zero attempted".

About using a default awk or perl script to create a file(.xg),
that Xgraph can use : Is not going to work.
* How to create files.tr that Xgraph can plot, see post #2,
.... ~5 examples are attached : xgraph_ns2-files-tcl.2014.tar.gz
* A new link to the "Joe Naoum-Sawaya tcl"
http://www.360doc.com/content/12/122...56135064.shtml
→ "Measure the throughput, packet drop rate,end-to-end delay for UDP-based application".
-
Attached Files
File Type: txt xgraph_ns2-files-tcl.2014.tar.gz.txt (7.3 KB, 95 views)

Last edited by knudfl; 10-08-2014 at 05:31 PM.
 
  


Reply

Tags
awk-ns2, ns2



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
Please help me NS2 Programming : AWK script error ns-2_learning Linux - Newbie 2 02-17-2014 09:59 AM
AWK script error - driving me crazy Solox Programming 7 05-28-2013 12:24 PM
Error on awk script sebelk Programming 6 10-16-2009 07:44 AM
awk shell script error ApacheRoseXbones Linux - Newbie 5 07-18-2008 12:06 PM
bash script read error and awk ouptut error whited Programming 4 10-16-2007 07:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:48 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
Open Source Consulting | Domain Registration