You are on page 1of 6

1. 2. 3. 4. 5.

c code v xy dng topology mng cng cc tham s cu hnh Tnh ton khong cch truyn d liu gia trm gc v MS Chy m phng i vi nh tuyn aodv v dsdv i vi topology trn Lu li cc file kt qu m phng phn tch Tnh bng thng : S dng on code trong chng trnh v lu kt qu ra cc file bandwidthBS*.tr 6. Nng lng : S dng cc cu lnh grep energy wired-cum-wireless.tr > ENERGY.tr lc ra cc d liu lin quan n nng lng ca tt c cc node v lu vo file ENERGY.tr Sau khi c file ENERGY.tr ta ln lt ly ra cc d liu v nng lng ca tng node v lu li cc file c dng node*.tr. Cu lnh s dng grep _*_ ENERGY.tr > node*.tr V d ly cc thng tin v nng lng node3 ta vit Grep _3_ ENERY.tr > node3.tr Sau khi c cc file node*.tr * c gi tr t 3 n 14, ta tip tc lc ly ra ch 2 thng s l thi gian v nng lng cn li ca tng node thc hin vic hin th. lm c vic , ta vit mt on code sau v lu li di file Column.awk : BEGIN { FS = " "} { nl++ } { print $2 " " $14} END {} Sau chy cu lnh sau thc hin lc d liu : $ awk f Column.awk node3.tr > node3energy Cu lnh ny s ch ly cc thng tin ct 2 v ct 14 c t file node3.tr v ghi li vo file node3energy. Sau khi thc hin i vi tt c cc node th s thu c node3energy n node14energy cho vic hin th 7. Tnh routing overhead : i vi nh tuyn AODV, ta vit on code awk sau v lu di file AODVCBR.awk BEGIN {aodvpktno = 0; aodvbyte = 0; cbrpktno = 0; cbrbyte = 0;cbrlostMAC = 0;totalDrop = 0;totalSND = 0} $1~/s/ && /AODV/ && /MAC/ { aodvpktno ++ ; aodvbyte+=$8 ;} $1~/s/ && /cbr/ && /MAC/ { cbrpktno ++ ; cbrbyte+=$8; } $1~/D/ && /cbr/ && /MAC/ { cbrlostMAC ++ } $1~/D/ { totalDrop ++ } $1~/s/ { totalSND ++ } END { print ( aodvpktno, aodvbyte , cbrpktno, cbrbyte, cbrlostMAC, totalDrop, totalSND) } Ta chy lnh $ awk f AODV-CBR.awk wired-cum-wireless.tr > routingOVERHEAD s thu c file routingOVERHEAD lu li cc thng s ly t file wired-cum-wireless.tr v s lng gi tin nh tuyn AODV, s bytes AODV, s gi tin d liu cbr , s bytes d liu cbr c gi i lp MAC tnh ton.

Cn i vi nh tuyn DSDV, cu lnh tm s gi nh tuyn trn ko dng c, nu dng s gy sai m ta tm trc tip trong file wired-cum-wireless.tr, cc bn tin nh tuyn l message i km vi s th t ca n. Ta tm c s cc gi tin nh tuyn ny cui cng ca file. Phn cn li v tm cc gi tin cbr vn c gi nguyn. 8. Tnh packet delivery ratio: Vit on code sau v lu di file SEND-RCVagent.awk: BEGIN {counter1 = 0; counter2 = 0;} $1~/s/ && /AGT/ { counter1 ++ } $1~/r/ && /AGT/ { counter2 ++ } END { print ( counter1, counter2) } Cc lnh ny thc hin m tng s gi tin truyn i v nhn c cp AGENT ( khng phi cp MAC ) Thc hin lnh sau : $ awk f SEND-RCVagent.awk wired-cum-wireless.tr > totalSEND-RCV ghi d liu vo file totalSEND-RCV 9. Tnh average hopcount th da vo 2 thng s tm c trong tnh ton tm packet delivery ratio v tm routing overhead l s packet truyn lp MAC v truyn AGENT. T s s gi tin pht lp MAC chia cho s gi tin pht AGENT cho ta kt qu 10. Tm throughput Throughput ch tnh lu lng gi tin c ch trong n v thi gian xc nh nn ta vit cu lnh sau v lu di file throughput.awk BEGIN {counter0 = 0; counter1 = 0; counter2 = 0;} $1~/r/ && /_0_/ && /AGT/ { counter0 += $8 } $1~/r/ && /_1_/ && /AGT/ { counter1 += $8 } $1~/r/ && /_2_/ && /AGT/ { counter2 += $8 }

END { print ( counter0*8/170, counter1*8/170, (counter0+counter1+counter2)*8/170 ) >> "wu.dat"}

counter2*8/170,

Thng tin s c lu li trong file wu.dat Chy lnh $ awk f throughput.awk wired-cum-wireless.tr 11. Tnh delay: Trc ht ta phi lc c ra cc thng tin lin quan n vic pht v nhn t mt node ny n mt node khc. Vit cu lnh sau v lu li file delay.awk:

$2>1 && $2 < 180 && (/_0_/ || /_3_/) "node3DL.tr" } $2>1 && $2 < 180 && (/_0_/ || /_4_/) "node4DL.tr" } $2>1 && $2 < 180 && (/_0_/ || /_5_/) "node5DL.tr" } $2>1 && $2 < 180 && (/_0_/ || /_6_/) "node6DL.tr" } $2>1 && $2 < 180 && (/_1_/ || /_7_/) "node7DL.tr" } $2>1 && $2 < 180 && (/_1_/ || /_8_/) "node8DL.tr" } $2>1 && $2 < 180 && (/_1_/ || /_9_/) "node9DL.tr" } $2>1 && $2 < 180 && (/_1_/ || /_10_/) "node10DL.tr" } $2>1 && $2 < 180 && (/_2_/ || /_11_/) "node11DL.tr" } $2>1 && $2 < 180 && (/_2_/ || /_12_/) "node12DL.tr" } $2>1 && $2 < 180 && (/_2_/ || /_13_/) "node13DL.tr" } $2>1 && $2 < 180 && (/_2_/ || /_14_/) "node14DL.tr" }

&& /AGT/ && /AGT/ && /AGT/ && /AGT/ && /AGT/ && /AGT/ && /AGT/ && /AGT/ && /AGT/ && /AGT/ && /AGT/ && /AGT/

{ print $1, $2, $6 > { { { print $1, $2, $6 > print $1, $2, $6 > print $1, $2, $6 >

{ print $1, $2, $6 > { { { print $1, $2, $6 > print $1, $2, $6 > print $1, $2, $6 >

{ print $1, $2, $6 > { { { print $1, $2, $6 > print $1, $2, $6 > print $1, $2, $6 >

Ta chy lnh $ awk f delay.awk wired-cum-wireless.tr Ta s thu c cc file node*DL.tr , * nhn cc gi tr t 3 n 14, mi file c 3 thng tin l gi hay nhn ( s hay r ) , thi gian s hay r , s th t ca gi tin xc nh cng mt gi tin. Vit mt on code C sau v lu li di file delay.c : #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { FILE *fin, *fout, *fout2; int pkt_index[5000]; double pkt_send_time[5000]; int head; //int tail; /* make sure it is large enough to hold all temprary data! */ int i,j,num;

double tm, tm_delay, total_delay, avg_delay, var_delay; int idx; char type; int flag; int num_sent; head = 0; for ( i=0; i<5000; i++) { pkt_index[i] = -1; pkt_send_time[i] = 0.0f; } fin = fopen(argv[1], "r"); fout = fopen (argv[2], "w"); fout2 = fopen ( argv[3],"a"); if(fin==NULL) { printf("Error: can't open file.\n"); return 1; } else { printf("File opened successfully.\n"); i=0; num = 0; num_sent = 0; while(!feof(fin)) { /* loop through and store the numbers into the array */ fscanf(fin, "%c %lf %d \n", &type,&tm, &idx); //printf( "%f\n", tm); if ( type == 's' ) { //addentry(idx, tm); pkt_index[head] = idx; pkt_send_time[head] = tm; head++; if ( head == 1000 ) head = 0; num_sent++;

} else if ( type == 'r' ) { flag = 0; for ( j=0; j< 1000; j++) { if ( pkt_index[j] == idx ) { //printf("match,%f, %f\n!" ,tm, pkt_send_time[j]); tm_delay = tm - pkt_send_time[j]; flag = 1; break; } } //addentry to output if ( flag == 1) { fprintf( fout,"%d %lf \n", idx, tm_delay ); total_delay += tm_delay; num++; } } i++; } avg_delay = total_delay / num ; fprintf(fout2,"Number of entries read: %d\n", i); fprintf(fout2,"Number of entries sent: %d\n", num_sent); fprintf(fout2,"Number of entries received: %d\n", num); fprintf(fout2,"average delay of entries : %lf\n", avg_delay); fclose(fin); fclose(fout);

//finally, calcualte variance fout = fopen ( argv[2], "r") ; if ( fout == NULL ) return -1; var_delay = 0; while (!feof(fout))

{ fscanf(fout, "%d %lf\n", &idx ,&tm); var_delay += ( tm - avg_delay ) * (tm - avg_delay); } var_delay /= num; fprintf(fout2, "variance of delay is : %lf\n", var_delay); fclose (fout); fclose (fout2); return 0; }

} Dch file delay.c ny thnh file delaycal.exe bng lnh $ gcc delay.c -o delaycal Sau s dng file delaycal.exe ny tnh cc thi gian tr trung bnh, lch v tnh ton tr ca tng packet c gi i phc v cho v th Chy cu lnh $ ./delaycal node3DL.tr DL31.dat DL32.dat ghi thng tin v tr ca tng gi vo file DL31.dat v ghi tr trung bnh v lch vo file DL32.dat Thc hin hin th cho tt c cc bc trn dng cu lnh graph.