LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-17-2011, 12:04 AM   #1
aicaicai
Member
 
Registered: Aug 2011
Posts: 40

Rep: Reputation: Disabled
something wrong when extracting TR file by awk


my TR files are as fellows:
r 0.000000000 _1_ RTR --- 0 cbr 70 [0 0 0 0] ------- [1:0 0:0 32 0] [0] 0 0
v 0 eval {set sim_annotation {(at 0.0) cbr traffic from node 1 to node 0}}
s 0.000000000 _1_ RTR --- 0 AODV 48 [0 0 0 0] ------- [1:255 -1:255 30 0] [0x2 1 1 [0 0] [1 4]] (REQUEST)
r 0.005202035 _2_ RTR --- 0 AODV 48 [0 ffffffff 1 800] ------- [1:255 -1:255 30 0] [0x2 1 1 [0 0] [1 4]] (REQUEST)
r 0.005202046 _0_ RTR --- 0 AODV 48 [0 ffffffff 1 800] ------- [1:255 -1:255 30 0] [0x2 1 1 [0 0] [1 4]] (REQUEST)
s 0.005202046 _0_ RTR --- 0 AODV 44 [0 0 0 0] ------- [0:255 1:255 30 1] [0x4 1 [0 4] 10.000000] (REPLY)
s 0.013366795 _2_ RTR --- 0 AODV 48 [0 ffffffff 1 800] ------- [2:255 -1:255 29 0] [0x2 2 1 [0 0] [1 4]] (REQUEST)
r 0.015898183 _1_ RTR --- 0 AODV 44 [0 1 0 800] ------- [0:255 1:255 30 1] [0x4 1 [0 4] 10.000000] (REPLY)
s 0.015898183 _1_ RTR --- 0 cbr 90 [0 0 0 0] ------- [1:0 0:0 30 0] [0] 0 0
r 0.018568830 _1_ RTR --- 0 AODV 48 [0 ffffffff 2 800] ------- [2:255 -1:255 29 0] [0x2 2 1 [0 0] [1 4]] (REQUEST)
r 0.200000000 _1_ RTR --- 1 cbr 70 [0 0 0 0] ------- [1:0 0:0 32 0] [1] 0 0
s 0.200000000 _1_ RTR --- 1 cbr 90 [0 0 0 0] ------- [1:0 0:0 30 0] [1] 0 0
r 0.300000000 _2_ RTR --- 2 cbr 70 [0 0 0 0] ------- [2:0 1:1 32 0] [0] 0 0
v 0.29999999999999999 eval {set sim_annotation {(at 0.3) cbr traffic from node 2 to node 1}}
s 0.300000000 _2_ RTR --- 2 cbr 90 [0 0 0 0] ------- [2:0 1:1 30 1] [0] 0 0
r 0.400000000 _1_ RTR --- 3 cbr 70 [0 0 0 0] ------- [1:0 0:0 32 0] [2] 0 0
s 0.400000000 _1_ RTR --- 3 cbr 90 [0 0 0 0] ------- [1:0 0:0 30 0] [2] 0 0
r 0.500000000 _2_ RTR --- 4 cbr 70 [0 0 0 0] ------- [2:0 1:1 32 0] [1] 0 0
s 0.500000000 _2_ RTR --- 4 cbr 90 [0 0 0 0] ------- [2:0 1:1 30 1] [1] 0 0
r 0.600000000 _1_ RTR --- 5 cbr 70 [0 0 0 0] ------- [1:0 0:0 32 0] [3] 0 0
s 0.600000000 _1_ RTR --- 5 cbr 90 [0 0 0 0] ------- [1:0 0:0 30 0] [3] 0 0
r 0.700000000 _0_ RTR --- 6 cbr 70 [0 0 0 0] ------- [0:1 2:1 32 0] [0] 0 0

and my awk script language are as fellows:
# 使用的是无线trace的旧格式
BEGIN {
highest_packet_id = 0;
delaysum=0;
i=0;
}
{
action = $1;
time = $2;
packet_id = $6;
type = $7;

# 不考虑路由包,可以保证序号为0的cbr被统计到
if ( type == "cbr" ) {

if ( packet_id > highest_packet_id )
highest_packet_id = packet_id;

#记录封包的传送时间
if ( start_time[packet_id] == 0 )
start_time[packet_id] = time;

#记录CBR 的接收时间
if ( action != "d" ) {
if ( action == "r" ) {
end_time[packet_id] = time;
}
} else {
#把不符合条件的数据包的时间设为-1
end_time[packet_id] = -1;
}
}
}


END {
#当资料列全部读取完后,开始计算有效封包的端点到端点延迟时间
for ( packet_id = 0; packet_id <= highest_packet_id; packet_id++ ) {
start = start_time[packet_id];
end = end_time[packet_id];
packet_duration = end - start;

#只把接收时间大于传送时间的记录列出来
if ( start < end ) {
delaysum+=packet_duration;
i++;
}
}
printf "delay:%f\n",(delaysum/i);
}
when I executed awk -f /usr/local/ns2/ns-allinone-2.34/ns-2.34/delay.awk>/usr/local/ns2/ns-allinone-2.34/ns-2.34/cbr_delay
there is nothing in cbr_delay.
But when i executed it on Cygwin on XP,There is an error:awk:delay.awk:49filename=wpan_demo1.tr fnr=260) fault division by zero attemped
Please help me!Thank you very much.
 
Old 09-17-2011, 11:58 PM   #2
kakaka
Member
 
Registered: Sep 2003
Posts: 382

Rep: Reputation: 87
I created a test version of the program you provided, added extra output so we can follow what the program is doing. I ran the program using the sample data you provided. It appears that in the sample data, the "r" record occurs first for each packet ID. Both the start time and the end time for each packet ID, are being set to the same time for each packet. When later records come along for the same packet_id, start_time is already set, so isn't changed. As a result, there are no differences between start and end. If the division by i is not conditionalized, you are trying to divide by zero.

Should the setting of start_time be conditionalized as well?

Code:
# 使用的是无线trace的旧格式
# Using the old wireless trace format
BEGIN {
        highest_packet_id = 0 ;
        delaysum=0 ;
        i=0 ;
      }

{
    action = $1 ;
    time = $2 ;
    packet_id = $6 ;
    type = $7 ;

    # 不考虑路由包,可以保证序号为0的cbr被统计到
    if ( type == "cbr" )
    {
    
        print "\n\ncbr LINE:  " $0 ;

        if (  packet_id  >  highest_packet_id  )
            highest_packet_id = packet_id ;

        # 记录封包的传送时间
        if (  start_time[ packet_id ]  ==  0  )
        {
            print "Setting start_time for packet_id:  "  packet_id ;
            start_time[ packet_id ] = time ;
        }

        # 记录CBR 的接收时间
        if ( action != "d" )
        {
            if ( action == "r" )
            {
                print "Setting end_time for packet_id:  "  packet_id ;
                end_time[ packet_id ] = time ;
            }
        }
        else
        {
            # 把不符合条件的数据包的时间设为-1
            print "Defaulting end_time for packet_id:  "  packet_id ;
            end_time [packet_id ] = -1 ;
        }
    }
}


END {
        # 当资料列全部读取完后,开始计算有效封包的端点到端点延迟时间
        print "\n\nScanning range of packet ID's..."

        for (  packet_id = 0 ;  packet_id <= highest_packet_id ;  packet_id++  )
        {
            print "\npacket ID: "  packet_id ;
            start = start_time[ packet_id ] ;
            end = end_time [ packet_id ] ;
            packet_duration = end - start ;

            # 只把接收时间大于传送时间的记录列出来
            if ( start < end )
            {
                delaysum+=packet_duration;
                i++ ;
            }
        }

        if (  i  >  0  )
            printf  "\ndelay:%f\n" ,  (delaysum/i) ;
        else
            print "\n'start' never less than 'end'.\n" ;
    }
Quote:
cbr LINE: r 0.000000000 _1_ RTR --- 0 cbr 70 [0 0 0 0] ------- [1:0 0:0 32 0] [0] 0 0
Setting start_time for packet_id: 0
Setting end_time for packet_id: 0


cbr LINE: s 0.015898183 _1_ RTR --- 0 cbr 90 [0 0 0 0] ------- [1:0 0:0 30 0] [0] 0 0
Setting start_time for packet_id: 0


cbr LINE: r 0.200000000 _1_ RTR --- 1 cbr 70 [0 0 0 0] ------- [1:0 0:0 32 0] [1] 0 0
Setting start_time for packet_id: 1
Setting end_time for packet_id: 1


cbr LINE: s 0.200000000 _1_ RTR --- 1 cbr 90 [0 0 0 0] ------- [1:0 0:0 30 0] [1] 0 0


cbr LINE: r 0.300000000 _2_ RTR --- 2 cbr 70 [0 0 0 0] ------- [2:0 1:1 32 0] [0] 0 0
Setting start_time for packet_id: 2
Setting end_time for packet_id: 2


cbr LINE: s 0.300000000 _2_ RTR --- 2 cbr 90 [0 0 0 0] ------- [2:0 1:1 30 1] [0] 0 0


cbr LINE: r 0.400000000 _1_ RTR --- 3 cbr 70 [0 0 0 0] ------- [1:0 0:0 32 0] [2] 0 0
Setting start_time for packet_id: 3
Setting end_time for packet_id: 3


cbr LINE: s 0.400000000 _1_ RTR --- 3 cbr 90 [0 0 0 0] ------- [1:0 0:0 30 0] [2] 0 0


cbr LINE: r 0.500000000 _2_ RTR --- 4 cbr 70 [0 0 0 0] ------- [2:0 1:1 32 0] [1] 0 0
Setting start_time for packet_id: 4
Setting end_time for packet_id: 4


cbr LINE: s 0.500000000 _2_ RTR --- 4 cbr 90 [0 0 0 0] ------- [2:0 1:1 30 1] [1] 0 0


cbr LINE: r 0.600000000 _1_ RTR --- 5 cbr 70 [0 0 0 0] ------- [1:0 0:0 32 0] [3] 0 0
Setting start_time for packet_id: 5
Setting end_time for packet_id: 5


cbr LINE: s 0.600000000 _1_ RTR --- 5 cbr 90 [0 0 0 0] ------- [1:0 0:0 30 0] [3] 0 0


cbr LINE: r 0.700000000 _0_ RTR --- 6 cbr 70 [0 0 0 0] ------- [0:1 2:1 32 0] [0] 0 0
Setting start_time for packet_id: 6
Setting end_time for packet_id: 6


Scanning range of packet ID's...

packet ID: 0

packet ID: 1

packet ID: 2

packet ID: 3

packet ID: 4

packet ID: 5

packet ID: 6

'start' never less than 'end'.
Hope this helps.
 
Old 09-18-2011, 01:33 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
I agree with the above. Except for packet_id = 0, all start times are equal to the times for 'r' values and all end times are equal to time for 'r' values.
The 0 packet_id is no better off however as the 's' time value is greater than the 'r' value for the end time so the 'if' in the END section is always false:
Code:
#只把接收时间大于传送时间的记录列出来
if ( start < end ) {
    delaysum+=packet_duration;
    i++;
}
The above is never true so neither delaysum not i are ever set or increased.
 
Old 09-19-2011, 02:42 AM   #4
aicaicai
Member
 
Registered: Aug 2011
Posts: 40

Original Poster
Rep: Reputation: Disabled
I am sorry,i don't understand.I am a beginner. When i use the awk script you given ,there is an error:
awk:1:unexpected character 0xff

r 0.000000000 _1_ RTR --- 0 cbr 70 [0 0 0 0] ------- [1:0 0:0 32 0] [0] 0 0
v 0 eval {set sim_annotation {(at 0.0) cbr traffic from node 1 to node 0}}
s 0.015898183 _1_ RTR --- 0 cbr 90 [0 0 0 0] ------- [1:0 0:0 30 0] [0] 0 0
r 0.200000000 _1_ RTR --- 1 cbr 70 [0 0 0 0] ------- [1:0 0:0 32 0] [1] 0 0
s 0.200000000 _1_ RTR --- 1 cbr 90 [0 0 0 0] ------- [1:0 0:0 30 0] [1] 0 0
r 0.300000000 _2_ RTR --- 2 cbr 70 [0 0 0 0] ------- [2:0 1:1 32 0] [0] 0 0

there is a packet_id change about cbr 70 [0 0 0 0] from 1 to 2
 
Old 09-19-2011, 07:06 AM   #5
kakaka
Member
 
Registered: Sep 2003
Posts: 382

Rep: Reputation: 87
Hi aicaicai,

You are using Linux, yes? I ask because the version of the program I sent works fine for me on Linux.

If you are using Linux, then line 1 should be the first line in the awk program, the comment. If you're talking about the version of the program I sent you, you should have received the comment exactly as you sent it. The error message sounds like some problem with the character set, or the characters used in the first line. You can try this command to create a new awk program file, without the comments:

Code:
fgrep -v '#' < cbr_delay > test.awk
I didn't see what your data file was called in your original post. But if you had put your data in a file called data, you should be able to run the test.awk program like this:

awk -f test.awk < data

and there should be no errors. Please let us know what happens when you try that.
 
Old 09-19-2011, 07:19 AM   #6
aicaicai
Member
 
Registered: Aug 2011
Posts: 40

Original Poster
Rep: Reputation: Disabled
Today in the afternoon i try again,i receive a number by using the awk script i sent.
delay:0.014008
But I don't konw if it's right.Can you help me to analize it?

I will do as you said .And I will let you know what happens when i try it
 
Old 09-19-2011, 12:09 PM   #7
kakaka
Member
 
Registered: Sep 2003
Posts: 382

Rep: Reputation: 87
Hi aicaicai,

If you'd like help analyzing the result, please post, as attachments, the data file you were using, and the exact awk program you were using, when you got the result.

Thanks.
 
Old 09-19-2011, 09:24 PM   #8
aicaicai
Member
 
Registered: Aug 2011
Posts: 40

Original Poster
Rep: Reputation: Disabled
s 0.000000000 _19_ AGT --- 0 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [0] 0 0
v 0 eval {set sim_annotation {(at 0.0) cbr traffic from node 19 to node 6}}
r 0.104565974 _6_ AGT --- 0 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [0] 4 0
s 0.200000000 _19_ AGT --- 1 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [1] 0 0
r 0.223240154 _6_ AGT --- 1 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [1] 4 0
s 0.300000000 _10_ AGT --- 2 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [0] 0 0
v 0.29999999999999999 eval {set sim_annotation {(at 0.3) cbr traffic from node 10 to node 4}}
r 0.379308277 _4_ AGT --- 2 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [0] 3 0
s 0.400000000 _19_ AGT --- 3 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [2] 0 0
r 0.423240154 _6_ AGT --- 3 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [2] 4 0
s 0.500000000 _10_ AGT --- 4 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [1] 0 0
r 0.517750110 _4_ AGT --- 4 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [1] 3 0
s 0.600000000 _19_ AGT --- 5 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [3] 0 0
r 0.622280154 _6_ AGT --- 5 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [3] 4 0
s 0.700000000 _3_ AGT --- 6 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [0] 0 0
v 0.69999999999999996 eval {set sim_annotation {(at 0.7) cbr traffic from node 3 to node 2}}
s 0.700000000 _10_ AGT --- 7 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [2] 0 0
r 0.717110110 _4_ AGT --- 7 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [2] 3 0
s 0.800000000 _19_ AGT --- 8 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [4] 0 0
r 0.823880154 _6_ AGT --- 8 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [4] 4 0
s 0.900000000 _3_ AGT --- 9 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [1] 0 0
s 0.900000000 _10_ AGT --- 10 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [3] 0 0
r 0.918710110 _4_ AGT --- 10 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [3] 3 0
s 1.000000000 _19_ AGT --- 11 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [5] 0 0
r 1.023240154 _6_ AGT --- 11 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [5] 4 0
s 1.100000000 _3_ AGT --- 12 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [2] 0 0
s 1.100000000 _10_ AGT --- 13 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [4] 0 0
r 1.119670110 _4_ AGT --- 13 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [4] 3 0
s 1.200000000 _19_ AGT --- 14 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [6] 0 0
r 1.226120154 _6_ AGT --- 14 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [6] 4 0
s 1.300000000 _3_ AGT --- 15 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [3] 0 0
s 1.300000000 _10_ AGT --- 16 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [5] 0 0
r 1.317750110 _4_ AGT --- 16 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [5] 3 0
s 1.400000000 _19_ AGT --- 17 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [7] 0 0
r 1.425160154 _6_ AGT --- 17 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [7] 4 0
s 1.500000000 _3_ AGT --- 18 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [4] 0 0
s 1.500000000 _10_ AGT --- 19 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [6] 0 0
r 1.519030110 _4_ AGT --- 19 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [6] 3 0
s 1.600000000 _19_ AGT --- 20 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [8] 0 0
r 1.626440154 _6_ AGT --- 20 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [8] 4 0
s 1.700000000 _3_ AGT --- 21 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [5] 0 0
s 1.700000000 _10_ AGT --- 22 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [7] 0 0
r 1.717110110 _4_ AGT --- 22 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [7] 3 0
s 1.800000000 _19_ AGT --- 23 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [9] 0 0
r 1.822280154 _6_ AGT --- 23 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [9] 4 0
s 1.900000000 _3_ AGT --- 24 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [6] 0 0
s 1.900000000 _10_ AGT --- 25 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [8] 0 0
r 1.916790110 _4_ AGT --- 25 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [8] 3 0
s 2.000000000 _19_ AGT --- 26 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [10] 0 0
r 2.022280154 _6_ AGT --- 26 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [10] 4 0
s 2.100000000 _3_ AGT --- 27 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [7] 0 0
s 2.100000000 _10_ AGT --- 28 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [9] 0 0
r 2.116470110 _4_ AGT --- 28 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [9] 3 0
s 2.200000000 _19_ AGT --- 29 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [11] 0 0
r 2.224840154 _6_ AGT --- 29 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [11] 4 0
s 2.300000000 _3_ AGT --- 30 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [8] 0 0
s 2.300000000 _10_ AGT --- 31 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [10] 0 0
r 2.320630110 _4_ AGT --- 31 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [10] 3 0
s 2.400000000 _19_ AGT --- 32 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [12] 0 0
r 2.421320154 _6_ AGT --- 32 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [12] 4 0
s 2.500000000 _3_ AGT --- 33 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [9] 0 0
s 2.500000000 _10_ AGT --- 34 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [11] 0 0
r 2.518710110 _4_ AGT --- 34 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [11] 3 0
s 2.600000000 _19_ AGT --- 35 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [13] 0 0
r 2.623880154 _6_ AGT --- 35 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [13] 4 0
s 2.700000000 _3_ AGT --- 36 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [10] 0 0
s 2.700000000 _10_ AGT --- 37 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [12] 0 0
r 2.717750110 _4_ AGT --- 37 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [12] 3 0
s 2.800000000 _19_ AGT --- 38 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [14] 0 0
r 2.824840154 _6_ AGT --- 38 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [14] 4 0
s 2.900000000 _3_ AGT --- 39 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [11] 0 0
s 2.900000000 _10_ AGT --- 40 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [13] 0 0
r 2.918710110 _4_ AGT --- 40 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [13] 3 0
s 3.000000000 _19_ AGT --- 41 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [15] 0 0
r 3.022600154 _6_ AGT --- 41 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [15] 4 0
s 3.100000000 _3_ AGT --- 42 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [12] 0 0
s 3.100000000 _10_ AGT --- 43 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [14] 0 0
r 3.117430110 _4_ AGT --- 43 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [14] 3 0
s 3.200000000 _19_ AGT --- 44 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [16] 0 0
r 3.225480154 _6_ AGT --- 44 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [16] 4 0
s 3.300000000 _3_ AGT --- 45 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [13] 0 0
s 3.300000000 _10_ AGT --- 46 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [15] 0 0
r 3.317750110 _4_ AGT --- 46 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [15] 3 0
s 3.400000000 _19_ AGT --- 47 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [17] 0 0
r 3.424200154 _6_ AGT --- 47 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [17] 4 0
s 3.500000000 _3_ AGT --- 48 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [14] 0 0
s 3.500000000 _10_ AGT --- 49 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [16] 0 0
r 3.519350110 _4_ AGT --- 49 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [16] 3 0
s 3.600000000 _19_ AGT --- 50 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [18] 0 0
r 3.622600154 _6_ AGT --- 50 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [18] 4 0
s 3.700000000 _3_ AGT --- 51 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [15] 0 0
s 3.700000000 _10_ AGT --- 52 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [17] 0 0
r 3.717750110 _4_ AGT --- 52 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [17] 3 0
s 3.800000000 _19_ AGT --- 53 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [19] 0 0
r 3.825160154 _6_ AGT --- 53 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [19] 4 0
s 3.900000000 _3_ AGT --- 54 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [16] 0 0
s 3.900000000 _10_ AGT --- 55 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [18] 0 0
r 3.915830110 _4_ AGT --- 55 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [18] 3 0
s 4.000000000 _19_ AGT --- 56 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [20] 0 0
r 4.022920154 _6_ AGT --- 56 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [20] 4 0

---------- Post added 09-19-11 at 08:25 PM ----------

s 4.100000000 _3_ AGT --- 57 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [17] 0 0
s 4.100000000 _10_ AGT --- 58 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [19] 0 0
r 4.119350110 _4_ AGT --- 58 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [19] 3 0
s 4.200000000 _19_ AGT --- 59 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [21] 0 0
r 4.221320154 _6_ AGT --- 59 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [21] 4 0
s 4.300000000 _3_ AGT --- 60 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [18] 0 0
s 4.300000000 _10_ AGT --- 61 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [20] 0 0
r 4.317750110 _4_ AGT --- 61 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [20] 3 0
s 4.400000000 _19_ AGT --- 62 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [22] 0 0
r 4.423880154 _6_ AGT --- 62 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [22] 4 0
s 4.500000000 _3_ AGT --- 63 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [19] 0 0
s 4.500000000 _10_ AGT --- 64 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [21] 0 0
r 4.516790110 _4_ AGT --- 64 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [21] 3 0
s 4.600000000 _19_ AGT --- 65 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [23] 0 0
r 4.625160154 _6_ AGT --- 65 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [23] 4 0
s 4.700000000 _3_ AGT --- 66 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [20] 0 0
s 4.700000000 _10_ AGT --- 67 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [22] 0 0
r 4.717430110 _4_ AGT --- 67 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [22] 3 0
s 4.800000000 _19_ AGT --- 68 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [24] 0 0
r 4.824520154 _6_ AGT --- 68 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [24] 4 0
s 4.900000000 _3_ AGT --- 69 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [21] 0 0
s 4.900000000 _10_ AGT --- 70 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [23] 0 0
r 4.917110110 _4_ AGT --- 70 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [23] 3 0
s 5.000000000 _19_ AGT --- 71 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [25] 0 0
r 5.023240154 _6_ AGT --- 71 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [25] 4 0
s 5.100000000 _3_ AGT --- 72 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [22] 0 0
s 5.100000000 _10_ AGT --- 73 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [24] 0 0
r 5.119350110 _4_ AGT --- 73 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [24] 3 0
s 5.200000000 _19_ AGT --- 74 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [26] 0 0
r 5.225160154 _6_ AGT --- 74 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [26] 4 0
s 5.300000000 _3_ AGT --- 75 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [23] 0 0
s 5.300000000 _10_ AGT --- 76 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [25] 0 0
r 5.315190110 _4_ AGT --- 76 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [25] 3 0
s 5.400000000 _19_ AGT --- 77 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [27] 0 0
r 5.424840154 _6_ AGT --- 77 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [27] 4 0
s 5.500000000 _3_ AGT --- 78 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [24] 0 0
s 5.500000000 _10_ AGT --- 79 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [26] 0 0
r 5.520310110 _4_ AGT --- 79 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [26] 3 0
s 5.600000000 _19_ AGT --- 80 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [28] 0 0
r 5.622280154 _6_ AGT --- 80 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [28] 4 0
s 5.700000000 _3_ AGT --- 81 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [25] 0 0
s 5.700000000 _10_ AGT --- 82 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [27] 0 0
r 5.717750110 _4_ AGT --- 82 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [27] 3 0
s 5.800000000 _19_ AGT --- 83 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [29] 0 0
r 5.827400154 _6_ AGT --- 83 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [29] 4 0
s 5.900000000 _3_ AGT --- 84 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [26] 0 0
s 5.900000000 _10_ AGT --- 85 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [28] 0 0
r 5.915510110 _4_ AGT --- 85 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [28] 3 0
s 6.000000000 _19_ AGT --- 86 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [30] 0 0
r 6.024520154 _6_ AGT --- 86 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [30] 4 0
s 6.100000000 _3_ AGT --- 87 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [27] 0 0
s 6.100000000 _10_ AGT --- 88 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [29] 0 0
r 6.119030110 _4_ AGT --- 88 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [29] 3 0
r 6.188927321 _2_ AGT --- 6 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [0] 3 0
s 6.200000000 _19_ AGT --- 89 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [31] 0 0
r 6.204367321 _2_ AGT --- 9 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [1] 3 0
r 6.221583409 _2_ AGT --- 12 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [2] 3 0
r 6.225928154 _6_ AGT --- 89 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [31] 4 0
r 6.238031497 _2_ AGT --- 15 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [3] 3 0
r 6.252367585 _2_ AGT --- 18 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [4] 3 0
r 6.277163809 _2_ AGT --- 21 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [5] 3 0
r 6.283243902 _2_ AGT --- 24 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [6] 3 0
s 6.300000000 _3_ AGT --- 90 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [28] 0 0
s 6.300000000 _10_ AGT --- 91 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [30] 0 0
r 6.301199848 _2_ AGT --- 27 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [7] 3 0
r 6.316470110 _4_ AGT --- 91 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [30] 3 0
r 6.341356336 _2_ AGT --- 30 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [8] 3 0
r 6.346796428 _2_ AGT --- 33 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [9] 3 0
r 6.367532424 _2_ AGT --- 36 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [10] 3 0
r 6.381100521 _2_ AGT --- 39 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [11] 3 0
r 6.385900614 _2_ AGT --- 42 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [12] 3 0
D 6.390611348 _3_ RTR CBK 45 cbr 90 [0 b 3 800] ------- [3:0 2:0 30 11] [13] 0 0
D 6.390611348 _3_ RTR CBK 48 cbr 90 [0 b 3 800] ------- [3:0 2:0 30 11] [14] 0 0
D 6.390611348 _3_ RTR CBK 51 cbr 90 [0 b 3 800] ------- [3:0 2:0 30 11] [15] 0 0
D 6.390611348 _3_ RTR CBK 54 cbr 90 [0 b 3 800] ------- [3:0 2:0 30 11] [16] 0 0
D 6.390611348 _3_ RTR CBK 57 cbr 90 [0 b 3 800] ------- [3:0 2:0 30 11] [17] 0 0
D 6.390611348 _3_ RTR CBK 60 cbr 90 [0 b 3 800] ------- [3:0 2:0 30 11] [18] 0 0
D 6.390611348 _3_ RTR CBK 63 cbr 90 [0 b 3 800] ------- [3:0 2:0 30 11] [19] 0 0
D 6.390611348 _3_ RTR CBK 66 cbr 90 [0 b 3 800] ------- [3:0 2:0 30 11] [20] 0 0
D 6.390611348 _3_ RTR CBK 69 cbr 90 [0 b 3 800] ------- [3:0 2:0 30 11] [21] 0 0
r 6.391980706 _2_ AGT --- 90 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [28] 3 0
s 6.400000000 _19_ AGT --- 92 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [32] 0 0
r 6.420285321 _2_ AGT --- 72 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [22] 3 0
r 6.426120154 _6_ AGT --- 92 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [32] 4 0
r 6.434941370 _2_ AGT --- 75 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [23] 3 0
r 6.453645409 _2_ AGT --- 78 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [24] 3 0
r 6.473755546 _2_ AGT --- 81 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [25] 3 0
r 6.480155638 _2_ AGT --- 84 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [26] 3 0
r 6.497023585 _2_ AGT --- 87 cbr 90 [0 2 8 800] ------- [3:0 2:0 28 2] [27] 3 0
s 6.500000000 _3_ AGT --- 93 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [29] 0 0
s 6.500000000 _10_ AGT --- 94 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [31] 0 0
r 6.516470110 _4_ AGT --- 94 cbr 90 [0 4 f 800] ------- [10:0 4:0 28 4] [31] 3 0
D 6.549657229 _4_ RTR TTL 0 AODV 48 [0 ffffffff 14 800] ------- [4:255 -1:255 0 0] [0x2 6 4 [2 9] [3 12]] (REQUEST)
D 6.549657245 _21_ RTR TTL 0 AODV 48 [0 ffffffff 14 800] ------- [21:255 -1:255 0 0] [0x2 6 4 [2 9] [3 12]] (REQUEST)
D 6.549657246 _15_ RTR TTL 0 AODV 48 [0 ffffffff 14 800] ------- [15:255 -1:255 0 0] [0x2 6 4 [2 9] [3 12]] (REQUEST)
r 6.586563127 _2_ AGT --- 93 cbr 90 [0 2 e 800] ------- [3:0 2:0 28 2] [29] 3 0
s 6.600000000 _19_ AGT --- 95 cbr 70 [0 0 0 0] ------- [19:0 6:0 32 0] [33] 0 0
r 6.624520154 _6_ AGT --- 95 cbr 90 [0 6 18 800] ------- [19:0 6:0 27 6] [33] 4 0
s 6.700000000 _3_ AGT --- 96 cbr 70 [0 0 0 0] ------- [3:0 2:0 32 0] [30] 0 0
s 6.700000000 _10_ AGT --- 97 cbr 70 [0 0 0 0] ------- [10:0 4:0 32 0] [32] 0 0
 
Old 09-19-2011, 09:28 PM   #9
aicaicai
Member
 
Registered: Aug 2011
Posts: 40

Original Poster
Rep: Reputation: Disabled
the awk are as fellows.Thank you very much.

# 使用的是无线trace的旧格式
BEGIN {
highest_packet_id = 0;
delaysum=0;
i=0;
}
{
action = $1;
time = $2;
packet_id = $6;
type = $7;

# 不考虑路由包,可以保证序号为0的cbr被统计到
if ( type == "cbr" ) {

if ( packet_id > highest_packet_id )
highest_packet_id = packet_id;

#记录封包的传送时间
if ( start_time[packet_id] == 0 )
start_time[packet_id] = time;

#记录CBR 的接收时间
if ( action != "d" ) {
if ( action == "r" ) {
end_time[packet_id] = time;
}
} else {
#把不符合条件的数据包的时间设为-1
end_time[packet_id] = -1;
}
}
}


END {
#当资料列全部读取完后,开始计算有效封包的端点到端点延迟时间
for ( packet_id = 0; packet_id <= highest_packet_id; packet_id++ ) {
start = start_time[packet_id];
end = end_time[packet_id];
packet_duration = end - start;

#只把接收时间大于传送时间的记录列出来
if ( start < end ) {
delaysum+=packet_duration;
i++;
}
}
printf "delay:%f\n",(delaysum/i);
}
 
Old 09-20-2011, 12:10 AM   #10
rigor
Member
 
Registered: Sep 2011
Posts: 212

Rep: Reputation: Disabled
. . .
 
Old 09-20-2011, 01:51 AM   #11
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Please place your code and input file (seeing you didn't attach as a file) in [code][/code] tags so we have some chance of reading it.

You will also need to provide what your expected output would be using the above input data?
 
Old 09-20-2011, 05:29 AM   #12
kakaka
Member
 
Registered: Sep 2003
Posts: 382

Rep: Reputation: 87
Hi aicaicai,

If you are working with something that is somewhat like NAM or NS trace output, I may have gotten the program working.

I've attached two files to my comments. You can click on the links and download the files. The files are test.txt, which is the awk program, and new_data.txt which contains the most recent lines of data you've provided. LQ limits the file suffixes/extensions that can be used for an attached file. So the program could not be attached as test.awk The closest allowable suffix/extension seemed to be .txt. With the changes I made, when I run the program, I get this output:

Quote:
Average packet delay: 0.735167.
I could have combined some if statements and made other aspects of the program more sophisticated, but I wanted to keep it simple to illustrate the concepts.

Hope this helps.
Attached Files
File Type: txt new_data.txt (15.7 KB, 5 views)
File Type: txt test.txt (3.8 KB, 6 views)

Last edited by kakaka; 09-20-2011 at 05:32 AM.
 
Old 09-20-2011, 06:10 AM   #13
aicaicai
Member
 
Registered: Aug 2011
Posts: 40

Original Poster
Rep: Reputation: Disabled
Thank you very much!
 
Old 09-20-2011, 06:19 AM   #14
aicaicai
Member
 
Registered: Aug 2011
Posts: 40

Original Poster
Rep: Reputation: Disabled
TO #4 and #5
I want to ask you what cause the error as fellows:
awk:1:unexpected character 0xff

I have discussed it with my classmates.But we don't konw.When I run getratio.awk,frequency.awkand load.awk.There is also the error.I check the awk script,i don't think the awk script is wrong.

But i don't know what cause it.Please help me.Thank you very much.
 
Old 09-20-2011, 07:28 AM   #15
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Are the files you are working on created in a Windows environment? Could be they have unusual line ending that are causing awk some grief. Maybe run dos2unix
over the files first and see if you still get errors.
 
  


Reply


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
extracting columns from multiple files with awk orcaja Linux - Newbie 7 02-14-2012 11:24 PM
extracting columns with awk gav251 Programming 7 03-10-2011 09:40 AM
[SOLVED] Extracting auditing info using awk system and ausearch BlackCrowe Programming 6 09-02-2010 02:51 AM
AWK/Perl for extracting data from txt file to numerous other files briana.paige Linux - Newbie 2 05-05-2009 10:53 AM
Extracting text with grep or awk? UrbanDruid Linux - Newbie 5 04-07-2005 03:57 PM


All times are GMT -5. The time now is 07:02 PM.

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