⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 totals.pl

📁 在Linux下做的QuadTree的程序
💻 PL
📖 第 1 页 / 共 3 页
字号:
                #                if($OP == $OP_TX && $node == $src_ipaddr) {                        if($act_rt_len != 0) {                                print stderr "Error in GOD information\n$LINE\n";                                # if ($log_error_fatal) { exit 1; }                        }                        if($opt_rt_len > $MAX_ROUTE_LENGTH) {                                $opt_rt_len = $MAX_ROUTE_LENGTH + 1;                        }                        CBR->[$TOTALS]->[$OP_OPT_RTLEN]->[$opt_rt_len] += 1;                }                #                # The distribution of ACTUAL route lengths is collected at the receiver.                #                elsif($OP == $OP_RX && $node == $dst_ipaddr) {                        if($act_rt_len <= 0) {                                print stderr "Error in GOD information\n$LINE\n";                                if ($log_error_fatal) { exit 1; }                        }                        $len = $act_rt_len - $opt_rt_len;                                     #                        # Bound the difference between ACTUAL and OPTIMAL                        #                        if($len < 0) {                                print stderr "$LINE";                                print stderr "Actual RT Length < Optimal.\n";                                $len = 0;                        }                        elsif($len > $MAX_ROUTE_LENGTH) {                                print "$LINE";                                print "Actual RT Length > Optimal + $MAX_ROUTE_LENGTH.\n";                                $len = $MAX_ROUTE_LENGTH + 1;                        }                        #                        # Bound the ACTUAL route length.                        #                        if($act_rt_len > $MAX_ROUTE_LENGTH) {                                $act_rt_len = $MAX_ROUTE_LENGTH + 1;                        }                        CBR->[$TOTALS]->[$OP_ACT_RTLEN]->[$act_rt_len] += 1;                        CBR->[$TOTALS]->[$OP_DIF_RTLEN]->[$len] += 1;                }        }        else {                print stderr "CBR Logging error\n$LINE\n";                if ($log_error_fatal) { exit 1; }        }}# ======================================================================# MAC Packet Processing Routines# ======================================================================sub process_msg {        my $hdr = shift(@_);        my $LINE = shift(@_);              # line from log file        my $OP = $hdr->{opcode};        my $LOGTYPE = $hdr->{logtype};        my $REASON = $hdr->{logreason};        my $SIZE = $hdr->{pktsize};        if($OP == $OP_DR) {                log_drop(MSG->[$TOTALS]->[$OP], $LOGTYPE, $REASON);        }        MSG->[$TOTALS]->[$OP]->[$PCNT] += 1;        MSG->[$TOTALS]->[$OP]->[$BCNT] += $SIZE;}# ======================================================================# MAC Packet Processing Routines# ======================================================================sub process_mac {        my $hdr = shift(@_);        my $LINE = shift(@_);              # line from log file        my $OP = $hdr->{opcode};        my $LOGTYPE = $hdr->{logtype};        my $REASON = $hdr->{logreason};        my $SIZE = $hdr->{pktsize};	if($LINE =~ /\[(\w+) (\w+) (\w+) (\w+) (\w+)\]/o) {		$t = hex($1) & 255;		if($t == $MACTYPE_RTS) {			$pkt = "RTS";		}		elsif($t == $MACTYPE_CTS) {			$pkt = "CTS";		}		elsif($t == $MACTYPE_ACK) {			$pkt = "ACK";		}		else {			print stderr "Invalid MAC packet.\n";			if ($log_error_fatal) { exit 1; }		}		MAC->{$pkt}->[$OP]->[$PCNT] += 1;		MAC->{$pkt}->[$OP]->[$BCNT] += $SIZE;		if($OP == $OP_DR) {			log_drop(MAC->{$pkt}->[$OP], $LOGTYPE, $REASON);		}	}	else {		print stderr "MAC Logging error\n$LINE\n";		if ($log_error_fatal) { exit 1; }	}	MAC->[$TOTALS]->[$OP]->[$PCNT] += 1;	MAC->[$TOTALS]->[$OP]->[$BCNT] += $SIZE;}# ======================================================================# Imep stats# ======================================================================sub process_imep_stats {    my $LINE = shift(@_);        if ($LINE =~ /IL \d+\.\d+ _(\d+)_ (.*)/) {	print "$1:  $2\n";    }    if ($LINE =~ /Add-Adj: (\d+) New-Neigh: (\d+) Del-Neigh1: (\d+) Del-Neigh2: (\d+) Del-Neigh3: (\d+)/o) {	$Add_Adj += $1;	$New_Neigh +=  $2;	$Del_Neigh1 +=  $3;	$Del_Neigh2 +=  $4;	$Del_Neigh3 +=  $5;    } elsif ($LINE =~ /Created QRY: (\d+) UPD: (\d+) CLR: (\d+)/o) {	$CQRY +=  $1;	$CUPD +=  $2;	$CCLR +=  $3;    } elsif ($LINE =~ /Received QRY: (\d+) UPD: (\d+) CLR: (\d+)/o) {	$RQRY +=  $1;	$RUPD +=  $2;	$RCLR +=  $3;    } elsif ($LINE =~ /Total-Obj-Created: (\d+) Obj-Pkt-Created: (\d+) Obj-Pkt-Recvd: (\d+)/o) {	$Total_Obj_Created += $1;	$Obj_Pkt_Created +=  $2;	$Obj_Pkt_Recvd +=  $3;    } elsif ($LINE =~ /Rexmit Pkts: (\d+) Acked: (\d+) Retired: (\d+) Rexmits: (\d+)/o) {	$RPkts += $1;	$RAcked +=  $2;	$RRetired +=  $3;	$RRexmits +=  $4;    } elsif ($LINE =~ /Sum-Response-List-Size Created: (\d+) Retired: (\d+)/o) {	$SRLCreated +=  $1;	$SRLRetired +=  $2;    } elsif ($LINE =~ /Holes Created: (\d+) Retired: (\d+) ReSeqQ-Drops: (\d+) ReSeqQ-Recvd: (\d+)/o) { 	$HCreated += $1;	$HRetired += $2;	$HReSeqQ_Drops += $3;	$HReSeqQ_Recvd += $4;    } elsif ($LINE =~ /Unexpected-Acks: (\d+) Out-Win-Obj: (\d+) Out-Order-Obj: (\d+) In-Order-Obj: (\d+)/o) {	$Unexpected_Acks +=  $1;	$Out_Win_Obj +=  $2;	$Out_Order_Obj +=  $3;	$In_Order_Obj +=  $4;    }};sub dump_imep_stats {    print "\nIMEP STATS ========================================\n";    print "TOTALS:\n";    print " Add_Adj:  $Add_Adj  New_Neigh:  $New_Neigh  Del_Neigh1: $Del_Neigh1  Del_Neigh2: $Del_Neigh2  Del_Neigh3: $Del_Neigh3\n";    print " Created QRY:  $CQRY  UPD:  $CUPD  CLR:  $CCLR  \n";    print " Received QRY:  $RQRY  UPD:  $RUPD  CLR:  $RCLR  \n";    print " Total_Obj_Created:  $Total_Obj_Created  Obj_Pkt_Created:  $Obj_Pkt_Created  Obj_Pkt_Recvd:  $Obj_Pkt_Recvd  \n";    print " Rexmit Pkts:  $RPkts  Acked:  $RAcked  Retired:  $RRetired  Rexmits:  $RRexmits  \n";    print " Sum_Response_List_Size Created:  $SRLCreated  Retired:  $SRLRetired  \n";    print " Holes Created:  $HCreated  Retired:  $HRetired  ReSeqQ_Drops:  $HReSeqQ_Drops  HReSeqQ_Recvd:  $HReSeqQ_Recvd  \n";    print " Unexpected_Acks:  $Unexpected_Acks  Out_Win_Obj:  $Out_Win_Obj  Out_Order_Obj:  $Out_Order_Obj  In_Order_Obj:  $In_Order_Obj  \n";    print  "\nSTATS\n";    printf("  Ave Response List Len  Created:  %f   Retired: %f\n",	   $RPkts ? $SRLCreated / $RPkts : -1.0, 	   $RRetired ? $SRLRetired / $RRetired : -1.0);    printf("  Ave Rexmits/Pkt %f \n",	   $RPkts ? $RRexmits / $RPkts : -1.0);    printf("  In order Objs %f\% \n",	   $Obj_Pkt_Recvd ? 100.0 * $In_Order_Obj / $Obj_Pkt_Recvd : -1.0);};# ======================================================================# Main Procedure# ======================================================================if($#ARGV != 2) {	print stderr "\nusage: $0 <input file> <script type> <num nodes>\n\n";	exit 1;}if(! open $infile, $ARGV[0]) {	print stderr "Could not open $ARGV[0]\n";	exit 1;}$SCRIPT_TYPE = $ARGV[1];$MAX_NODES = $ARGV[2];$TOTALS = $MAX_NODES + 1;## Initialize Data Structures#init_type(MAC, @MACTYPE);init_type(CBR);init_type(ARP, @ARPTYPE);init_type(DSR, @DSRTYPE);init_type(TORA, @TORATYPE);init_type(IMEP, @IMEPTYPE);init_type(AODV, @AODVTYPE);while(<$infile>) {	$line += 1;	if(/^[rsfD] (\d+).\d+ _(\d+)_ (\S+)\s+(\S+) \d+ (\S+) (\d+) \[\w+ \w+ \S+ \w+ \w+\]/o) {                $time = $1;                $hdr->{node} = $2;                $hdr->{logtype} = $3;           # AGT, RTR, MAC                $hdr->{logreason} = $4;		$hdr->{pkttype} = $5;		$hdr->{pktsize} = $6;                if($SCRIPT_TYPE eq "RTR") {                        if($hdr->{logtype} ne "RTR" &&                           $hdr->{logtype} ne "IFQ") {                                next;                        }                }                elsif($SCRIPT_TYPE ne $hdr->{logtype}) {                        next;                }                # ============================================================                # Set the OPCODE for this line of input                # ============================================================		if(/^s /) {                        $hdr->{opcode} = $OP_TX;                }                elsif(/^f /) {			$hdr->{opcode} = $OP_FW;		}		elsif(/^r /) {			$hdr->{opcode} = $OP_RX;		}		elsif(/^D /) {                        $hdr->{opcode} = $OP_DR;                }		else {			print stderr "Invalid OPERATION\n$_\n";			if ($log_error_fatal) { exit 1; }		}                if($hdr->{pkttype} eq "MAC") {                        process_mac($hdr, $_);                }		elsif($hdr->{pkttype} eq "ARP") {                      	process_arp($hdr, $_);                }#                elsif($hdr->{pkttype} eq "tcp" || $hdr->{pkttype} eq "ack") {#                        process_tcp($opcode, $pktsize, $_);#                }                elsif($hdr->{pkttype} eq "TORA") {                        process_tora($hdr, $_);                }                elsif($hdr->{pkttype} eq "IMEP") {                        process_imep($hdr, $_);                }                elsif($hdr->{pkttype} eq "AODV") {                        process_aodv($hdr, $_);                }                elsif($hdr->{pkttype} eq "cbr") {                        process_cbr($hdr, $_);                }                elsif($hdr->{pkttype} eq "DSR") {                        process_dsr($hdr, $_);                }                elsif($hdr->{pkttype} eq "message") {                        process_msg($hdr, $_);                }	                else {                        print stderr "Invalid packet type $hdr->{pkttype}\n";                        if ($log_error_fatal) { exit 1; }                }	}	#	# Mobility Logging	#	elsif(/^M/o) {	}	#	# AODV Logging	#	elsif(/^A/o) {	}	#	# TORA Logging	#	elsif(/^T/o) {	}	#	# DSR Logging	#	elsif(/^SRR \d+.\d+ _\d+_ ([\w-]+)/o) {	    if ($1 eq "reply-sent") {		$reply_sent++;	    } elsif ($1 eq "reply-received") {		$reply_received++;	    } elsif ($1 eq "cache-reply-sent") {		$cache_reply_sent++;	    } elsif ($1 eq "new-request") {		$new_request++;	    } elsif ($1 eq "gratuitous-reply-sent") {		$grat_reply_sent++;	    } elsif ($1 eq "---") {		$bad_reply_not_salvaged++;	    }	} elsif(/^Ssb/o) {	    $snd_buf_drop++;	} elsif (/^Ssalv .* salvaging/o) {	    $pkts_salvaged++;	} elsif (/^Ssalv .* dropping/o) {	    $pkts_not_salvaged++;	} elsif (/^SIFQ .*len \d+$/o) {	    $ifq_above_25++;	} elsif (/^S/o) {	}	# 	# DSDV Logging	#	elsif(/^V/o) {	}	#	# GOD Logging	#	elsif(/^G/o) {	}	elsif(/^IL/o) {	    process_imep_stats($_);	}	else {		print stderr "Error, $line: '$_'\n";#		if ($log_error_fatal) { exit 1; }	}}$time += 1;		# accounts for fractional partdump_imep_stats();show_totals(MAC, @MACTYPE);show_totals(ARP, @ARPTYPE);show_totals(DSR, @DSRTYPE);show_totals(MSG, @MSGTYPE);show_totals(TORA, @TORATYPE);show_totals(IMEP, @IMEPTYPE);show_totals(AODV, @AODVTYPE);show_cbr_totals();printf("\nSimulation Time: %d\n", $time);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -