awk script- delay 계산 및 IP 주소 C 상에서 얻어오기

|

awk script- delay 계산

참고 : http://www.winlab.rutgers.edu/~zhibinwu/html/ns_trace.html
작성 : 2006.12.17 by 임헌정
http://www.4ellene.net

CMU use a special fomat. Basically, you could 

$ns use-newtrace

to generate the new trace and the detailed explanation could be found
in Ns Manual.By default, old trace format is used. We need to analyze
the source code ./trace/cmu-trace.cc to understand it completely.
For instance, the function format_ip will explain the trace of IP part.


void
CMUTrace::format_ip(Packet *p, int offset)
{
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);

// hack the IP address to convert pkt format to hostid format
// for now until port ids are removed from IP address. -Padma.
int src = Address::instance().get_nodeaddr(ih->saddr());
int dst = Address::instance().get_nodeaddr(ih->daddr());

............

}

void
CMUTrace::format_mac(Packet *p, int offset)
{

else {
sprintf(pt_->buffer() + offset,
" [%x %x %x %x] ",
//*((u_int16_t*) &mh->dh_fc),
mh->dh_duration,

ETHER_ADDR(mh->dh_ra),
ETHER_ADDR(mh->dh_ta),


GET_ETHER_TYPE(mh->dh_body));
}
......

}


A typical trace for a CBR traffic is:

s 20.000000000 _0_ AGT  --- 6 cbr 512 [0 0 0 0] ------- [0:0 1:0 32 0]
[0] 0 0
r 20.000000000 _0_ RTR --- 6 cbr 512 [0 0 0 0] ------- [0:0 1:0 32 0]
[0] 0 0
s 20.000000000 _0_ RTR --- 6 cbr 532 [0 0 0 0] ------- [0:0 1:0 32 1]
[0] 0 0
s 20.000275000 _0_ MAC --- 6 cbr 584 [13a 1 0 800] -------
[0:0 1:0 32 1] [0] 0 0
r 20.004947063 _1_ MAC --- 6 cbr 532 [13a 1 0 800] -------
[0:0 1:0 32 1] [0] 1 0
s 20.004957063 _1_ MAC --- 0 ACK 38 [0 0 0 0]
r 20.004972063 _1_ AGT --- 6 cbr 532 [13a 1 0 800] -------
[0:0 1:0 32 1] [0] 1 0
r 20.005261125 _0_ MAC --- 0 ACK 38 [0 0 0 0]

A typical awk code for analyzing traces is:

For a topology involve 4 flows with distinguishing source and
destination nodes,
this awkcode gets throughout data and put in wu.dat file

[예제]

BEGIN {counter1 = 0;}
$1~/r/ && $2>50 && $2< 100 && /_2_/ && /AGT/ { counter1 +=
($8- 20)
size = $8 - 20 }
END {
print (size , counter1*8/(50) ) >> "wu.dat"}

로 delay_throughout.awk 파일 생성

$ awk -f delay_though.awk aodv_3nodes_tcp.tr 실행
# 50~100ms 사이에, 2노드로 수신한 패킷들


BEGIN {counter1 = 0; counter2 = 0; counter3 = 0; counter4 = 0;}
$1~/r/ && $2>50 && $2< 100  && /_12_/ && /AGT/  {   counter1 += ($8- 20)
                       size = $8 - 20 }
$1~/r/ && $2>50 && $2 <100 && /_13_/ && /AGT/  {   counter2 += ($8- 20)
                       size = $8 - 20 }
$1~/r/ && $2>50 && $2<100 && /_14_/ && /AGT/  {   counter3 += ($8- 20)
                       size = $8 - 20 }
$1~/r/ && $2>50 && $2<100 && /_15_/ && /AGT/  {   counter4 += ($8- 20)
                       size = $8 - 20 }

END {
     print (size , counter1*8/(50), counter2*8/50, counter3*8/(50), counter4*8/50,
                 (counter1+counter2+counter3+counter4)*8/50 )  >> "wu.dat"}

To analyze throughout or delay in a finite time duration,

we need extract send and receive time from the trace file

[예제]
$ awk '$2>100 && $2 < 150 && (/_0_/ || /_2_/) && /AGT/ { print
$1, $2, $6 > "dst2.tr" }' aodv_3nodes_tcp.tr

$2>100 && $2 < 150 && (/_6_/ || /_2_/)  &&  /AGT/    {  print $1, $2, $6  > "dst2.tr" }
$2>100 && $2 <150 && (/_0_/ || /_9_/)  &&  /AGT/    {   print $1, $2, $6  > "dst9.tr" }
$2>100 && $2 <150 && (/_12_/ || /_3_/)  &&  /AGT/    {   print $1, $2, $6  > "dst3.tr" }
$2>100 && $2 <150 && (/_10_/ || /_4_/)  &&  /AGT/    {   print $1, $2, $6  > "dst4.tr" }
$2>100 && $2 <150 && (/_11_/ || /_8_/)  &&  /AGT/    {   print $1, $2, $6  > "dst8.tr" }

The respective new trace files such as "dst2.tr" will keep time, "s'"
or "r" and, "index",
From that we could use a program to calculate the mean of delay.
The files is here:
 

And to use this C code:
$ gcc delay.c -o delaycal
$ ./delaycal dst2.tr wu0.dat wu1.dat

And