NS2网络模拟(2)-丢包率

  1: #NS2_有线部分\LossRate.awk
  2: 
  3: BEGIN {
  4:     #Initialize the variable
  5:     Lost = 0;      #the Sum of Lost packet
  6:     Send = 0;      #the Sum of Send packet
  7: }
  8: 
  9: {
 10: #Event Abbreviation Type Value
 11: #%g %d %d %s %d %s %d %d.%d %d.%d %d %d
 12: #Normal Event
 13:         #r: Receive
 14:         #d: Drop
 15:         #e: Error
 16:         #+: Enqueue
 17:         #-: Dequeue       
 18: #double  Time
 19: #int  (Link-layer) Source Node
 20: #int  (Link-layer) Destination Node
 21: #string  Packet Name
 22: #int  Packet Size
 23: #string  Flags
 24: #int  Flow ID
 25: #int  (Network-layer) Source Address
 26: #int  Source Port
 27: #int  (Network-layer) Destination Address
 28: #int  Destination Port
 29: #int  Sequence Number
 30: #int  Unique Packet ID
 31: 
 32:     #Evaluate the fields to new viariables
 33:     EVENT       = $1;
 34:     TIME        = $2;
 35:     SRCNODE     = $3
 36:     DSTNODE     = $4;
 37:     PKTNAME     = $5;
 38:     PKTSIZE     = $6;
 39:     FLAGS       = $7;
 40:     FLOWID      = $8;
 41:     SRCADDPORT  = $9;
 42:     DSTADDPORT  = $10;
 43:     SEQNO       = $11;
 44:     PKTID       = $12;
 45: 
 46:     #Count up the packets send from n1
 47:     if (EVENT == "+" && SRCNODE == 1 && DSTNODE == 0 && PKTNAME == "tcp")
 48:         Send ++;
 49:     #Count up the drop packet
 50:     if (EVENT == "d" && SRCNODE == 0 && DSTNODE == 1 && PKTNAME == "ack")
 51:         Lost ++;
 52: }
 53: 
 54: END {
 55:     printf("TCP:number of packets send: %d lost: %d\n", Send, Lost);
 56:     printf("TCP:the loss rate of packets: %.5f\n", Lost/Send);
 57: }
posted @ 2011-10-13 12:33  方倍工作室  阅读(1166)  评论(0编辑  收藏  举报