#### ASpath-tree v.4.2 - Released on Thu APR 17 2003, h.16:58:12
#### File: lib/odd-routes.pl Last modified on Fri MAR 14 2003, h.15:42:35

# Routines to create the odd routes pages: three pages showing the invalid routes, the unaggregated routes sorted
# by origin AS and the unaggregated routes sorted by owner xTLA respectively

sub create_oddroutes_pages {
	my ($filename) = @_;

	my ($maxlen_inv, $maxlen_una, $maxlen_longer, $N_inv, $N_unag, $N_longer) = (0, 0, 0, 0, 0, 0);
	my @tmp = ();
	my %inv = ();
	my %una = ();
	my %una1 = ();
	my %una2 = ();

	foreach $key (keys(%ATTRIBUTES)) {
		@tmp = split(/\s+/, $ATTRIBUTES{$key});
		if ($tmp[0] == 0) {
			$N_inv++;
			if ($maxlen_inv < @tmp) {$maxlen_inv = @tmp}
			push (@{$inv{$tmp[1]}}, $key);
		}
		elsif ($tmp[0] == 2) {
			$N_unag++;
			if ($maxlen_una < @tmp) {$maxlen_una = @tmp}
			push (@{$una{$tmp[1]}}, $key);
			push (@{$una1{$tmp[3]}}, $key);
		}
		elsif ($tmp[0] == 5) {
			$N_longer++;
			if ($maxlen_longer < @tmp) {$maxlen_longer = @tmp}
			push (@{$una2{$tmp[1]}}, $key);
		}
	}
	&oddroutes_page('inv', $filename, $N_inv, $maxlen_inv, %inv);
	&oddroutes_page('unabyori', $filename, $N_unag, $maxlen_una, %una);
	&oddroutes_page('unabyown', $filename, $N_unag, $maxlen_una, %una1);
	&oddroutes_page('longer6to4', $filename, $N_longer, $maxlen_longer, %una2);
	return(0);
}

# Routine to create invalid routes odd-route page
sub oddroutes_page {
	my ($type, $filename, $flag, $maxlen, %hash) = @_;

	my ($asname, $origin, $origin_as, $link1, $link2, $link3, $prefix, $owner, $ptla_owner, $fptla_owner, $flag_whois);
	my ($numcol, $leftcol) = (0, 0);
	my $separator = "-";

	$filename =~ /(.*)\/{1}(.*)\.{1}.*$/;
	my $path = $1;
	my $link = $2;

	if ($type eq 'inv') {
		$link1 = 'Invalid Prefixes';
		open(HTMLFILE,">".$filename);
	}
	else {$link1 = "<A HREF=\"$link".".html"."\">Invalid Prefixes</A>"}
	if ($type eq 'unabyori') {
		$link2 = 'Unaggregated Prefixes (by origin)';
		open(HTMLFILE,">".$path."/".$link."1.html");
	}
	else {$link2 = "<A HREF=\"$link"."1.html"."\">Unaggregated Prefixes (by origin)</A>"}
	if ($type eq 'unabyown') {
		$link3 = 'Unaggregated Prefixes (by owner)';
		open(HTMLFILE,">".$path."/".$link."2.html");
	}
	else {$link3 = "<A HREF=\"$link"."2.html"."\">Unaggregated Prefixes (by owner)</A>"}
	if ($type eq 'longer6to4') {
		$link4 = '6to4 Longer Prefixes';
		open(HTMLFILE,">".$path."/".$link."3.html");
	}
	else {$link4 = "<A HREF=\"$link"."3.html"."\">6to4 Longer Prefixes</A>"}

	print HTMLFILE &header("IPv6 BGP table: unaggregated and invalid prefixes", 0);

	print HTMLFILE "<TABLE>\n<TR>";
	if ($SITEPICTURE) {
		print HTMLFILE "<TD VALIGN=top><IMG SRC=\"$ICONS/$SITEPICTURE\" BORDER=0></TD>\n";
	}
	else {print HTMLFILE "<TD>&nbsp;</TD>\n"}
	print HTMLFILE "<TD VALIGN=bottom CLASS=a32b>&nbsp;IPv6 BGP odd routes</TD></TR>\n";
	print HTMLFILE "<TR><TD ALIGN=center VALIGN=top COLSPAN=2 CLASS=n10b>Updated on $LONGDATE</TD></TR>\n";

	print HTMLFILE "<TR><TD ALIGN=center VALIGN=top COLSPAN=2 CLASS=n12>[&nbsp;";
	print HTMLFILE "$link1";
	print HTMLFILE "&nbsp;|&nbsp;";
	print HTMLFILE "$link2";
	print HTMLFILE "&nbsp;|&nbsp;";
	print HTMLFILE "$link3";
	print HTMLFILE "&nbsp;|&nbsp;";
	print HTMLFILE "$link4";
	print HTMLFILE "&nbsp;]</TD></TR>\n</TABLE>\n<P>\n";

	if ($type eq 'inv') {
		if ($flag) {
			$numcol = ($maxlen-5)*2;
			print HTMLFILE "<CENTER><TABLE CELLPADDING=5 BORDER=1>\n";
			print HTMLFILE "<TR BGCOLOR=\"$MAINCOLOR\"><TD ALIGN=center CLASS=w12b>Origin</TD>\n";
			print HTMLFILE "<TD ALIGN=center CLASS=w12b>Invalid&nbsp;Prefixes</TD>\n";
			print HTMLFILE "<TD CLASS=w12b>AS Paths</TD></TR>\n";

			foreach $origin (sort(keys(%hash))) {
				$origin_as = &format_originAS($origin);
				print HTMLFILE "<TR VALIGN=top><TD>$origin_as</TD>\n";
				print HTMLFILE "<TD><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>\n";
				foreach $prefix (@{$hash{$origin}}) {
					print HTMLFILE "<TR><TD>$prefix</TD></TR>\n";
				}
				print HTMLFILE "</TABLE></TD>\n";
				print HTMLFILE "<TD><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>\n";
				foreach $prefix (@{$hash{$origin}}) {
					@tmp = split(/\s+/, $ATTRIBUTES{$prefix});
					print HTMLFILE "<TR>\n";
					for ($i = 4; $i < $#tmp; $i++) {
						$asname = &format_asname($tmp[$i]);
						print HTMLFILE "<TD>$asname</TD>";
						print HTMLFILE "<TD>$separator</TD>\n";
					}
					$asname = &format_asname($tmp[$#tmp]);
					print HTMLFILE "<TD>$asname</TD>\n";
					if ($#tmp < $maxlen) {
						$leftcol = $numcol - ($#tmp - 4)*2 + 1;
						print HTMLFILE "<TD COLSPAN=$leftcol>&nbsp;</TD>\n";
					}
					print HTMLFILE "\n</TR>\n";
				}
				print HTMLFILE "</TABLE></TD></TR>\n";
			}
			print HTMLFILE "</TABLE></CENTER>\n<HR>\n";
		}
		else {
			print HTMLFILE "<SPAN CLASS=n12>There are no invalid prefixes.</SPAN><BR><HR>\n";
		}
	}
	elsif ($type eq 'unabyori') {
		if ($flag) {
			$numcol = ($maxlen-5)*2;
			print HTMLFILE "<CENTER><TABLE CELLPADDING=5 BORDER=1>\n";
			print HTMLFILE "<TR BGCOLOR=\"$MAINCOLOR\"><TD ALIGN=center CLASS=w12b>Origin</TD>\n";
			print HTMLFILE "<TD ALIGN=center CLASS=w12b>Unaggregated&nbsp;Prefixes</TD>\n";
			print HTMLFILE "<TD ALIGN=center CLASS=w12b>Assigned&nbsp;to</TD>\n";
			print HTMLFILE "<TD ALIGN=center CLASS=w12b>xTLA&nbsp;owner</TD>\n";
			print HTMLFILE "<TD CLASS=w12b>AS Paths</TD></TR>\n";

			foreach $origin (sort {$ASNAME{$a} cmp $ASNAME{$b}} (keys(%hash))) {
				$origin_as = &format_originAS($origin);
				print HTMLFILE "<TR VALIGN=top><TD>$origin_as</TD>\n";
				print HTMLFILE "<TD><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>";
				foreach $prefix (@{$hash{$origin}}) {print HTMLFILE "<TR><TD>$prefix</TD></TR>\n"}
				print HTMLFILE "</TABLE></TD>\n";
				print HTMLFILE "<TD><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>\n";
				foreach $prefix (@{$hash{$origin}}) {
					@tmp = split(/\s+/, $ATTRIBUTES{$prefix});
					if (&includedprefix($prefix,"3ffe::/16")) {$flag_whois = 0}
					else {$flag_whois = 1}
					$owner = &format_owner($tmp[2],$flag_whois);
					print HTMLFILE "<TR><TD>$owner</TD></TR>";
				}
				print HTMLFILE "</TABLE></TD>\n<TD>";
				print HTMLFILE "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>";
				foreach $prefix (@{$hash{$origin}}) {
					@tmp = split(/\s+/, $ATTRIBUTES{$prefix});
					if ($tmp[3] eq '?' || $tmp[3] eq '?') {$fptla_owner = '?'}
					else {
						if (&includedprefix($prefix,"3ffe::/16")) {$flag_whois = 0}
						else {$flag_whois = 1}
						$fptla_owner = &format_owner($tmp[3],$flag_whois);
					}
					print HTMLFILE "<TR><TD>$fptla_owner</TD></TR>\n";
				}
				print HTMLFILE "</TABLE></TD>\n";
				print HTMLFILE "<TD><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>\n";
				foreach $prefix (@{$hash{$origin}}) {
					@tmp = split(/\s+/, $ATTRIBUTES{$prefix});
					print HTMLFILE "<TR VALIGN=bottom>\n";
					for ($i = 4; $i < $#tmp; $i++) {
						$asname = &format_asname($tmp[$i]);
						print HTMLFILE "<TD>$asname</TD>";
						print HTMLFILE "<TD>$separator</TD>\n";
					}
					$asname = &format_asname($tmp[$#tmp]);
					print HTMLFILE "<TD>$asname</TD>\n";
					if ($#tmp < $maxlen) {
						$leftcol = $numcol - ($#tmp - 4)*2 + 1;
						print HTMLFILE "<TD COLSPAN=$leftcol>&nbsp;</TD>\n";
					}
					print HTMLFILE "</TR>\n";
				}
				print HTMLFILE "</TABLE></TD></TR>\n";
			}
			print HTMLFILE "</TABLE></CENTER>\n<HR>\n";
		}
		else {
			print HTMLFILE "<SPAN CLASS=n12>There are no unaggregated prefixes.</SPAN><BR><HR>\n";
		}
	}
	elsif ($type eq 'unabyown') {
		if ($flag) {
			$numcol = ($maxlen-5)*2;
			print HTMLFILE "<CENTER><TABLE CELLPADDING=5 BORDER=1>\n";
			print HTMLFILE "<TR BGCOLOR=\"$MAINCOLOR\"><TD ALIGN=center CLASS=w12b>xTLA&nbsp;owner</TD>\n";
			print HTMLFILE "<TD ALIGN=center CLASS=w12b>Unaggregated&nbsp;Prefixes</TD>\n";
			print HTMLFILE "<TD ALIGN=center CLASS=w12b>Assigned&nbsp;to</TD>\n";
			print HTMLFILE "<TD ALIGN=center CLASS=w12b>Origin</TD>\n";
			print HTMLFILE "<TD CLASS=w12b>AS Paths</TD></TR>\n";

			my @owners = sort(keys(%hash));
			if ($owners[0] eq '-') {shift(@owners);$owners[@owners] = '-'}
			foreach $ptla_owner (@owners) {
				print HTMLFILE "<TR VALIGN=top><TD>";
				if ($ptla_owner eq '?' || $ptla_owner eq '?') {$fptla_owner = '?'}
				else {
					if (grep(/$ptla_owner/, values(%PTLAS))) {$flag_whois = 0}
					else {$flag_whois = 1}
					$fptla_owner = &format_owner($ptla_owner,$flag_whois);
				}
				print HTMLFILE "$fptla_owner</TD>\n";
				print HTMLFILE "<TD><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>\n";
				foreach $prefix (@{$hash{$ptla_owner}}) {
					print HTMLFILE "<TR><TD>$prefix</TD></TR>\n";
				}
				print HTMLFILE "</TABLE></TD>\n";
				print HTMLFILE "<TD><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>";
				foreach $prefix (@{$hash{$ptla_owner}}) {
					@tmp = split(/\s+/, $ATTRIBUTES{$prefix});
					if (&includedprefix($prefix,"3ffe::/16")) {$flag_whois = 0}
					else {$flag_whois = 1}
					$owner = &format_owner($tmp[2],$flag_whois);
					print HTMLFILE "<TR><TD CLASS=n10>$owner</TD></TR>\n";
				}
				print HTMLFILE "</TABLE></TD>\n";
				print HTMLFILE "<TD><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>\n";
				foreach $prefix (@{$hash{$ptla_owner}}) {
					@tmp = split(/\s+/, $ATTRIBUTES{$prefix});
					$origin = &format_originAS($tmp[1]);
					print HTMLFILE "<TR><TD>$origin</TD></TR>\n";
				}
				print HTMLFILE "</TABLE></TD>\n";
				print HTMLFILE "<TD><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>\n";
				foreach $prefix (@{$hash{$ptla_owner}}) {
					@tmp = split(/\s+/, $ATTRIBUTES{$prefix});
					print HTMLFILE "<TR>\n";
					for ($i = 4; $i < $#tmp; $i++) {
						$asname = &format_asname($tmp[$i]);
						print HTMLFILE "<TD VALIGN=bottom CLASS=n10>$asname</TD>";
						print HTMLFILE "<TD VALIGN=bottom CLASS=n10>$separator</TD>\n";
					}
					$asname = &format_asname($tmp[$#tmp]);
					print HTMLFILE "<TD>$asname</TD>\n";
					if ($#tmp < $maxlen) {
						$leftcol = $numcol - ($#tmp - 4)*2 + 1;
						print HTMLFILE "<TD COLSPAN=$leftcol>&nbsp;</TD>\n";
					}
					print HTMLFILE "</TR>\n";
				}
				print HTMLFILE "</TABLE></TD></TR>\n";
			}
			print HTMLFILE "</TABLE></CENTER>\n<HR>\n";
		}
		else {
			print HTMLFILE "<SPAN CLASS=n12>There are no unaggregated prefixes.</SPAN><BR><HR>\n";
		}
	}
	elsif ($type eq 'longer6to4') {
		if ($flag) {
			$numcol = ($maxlen-5)*2;
			print HTMLFILE "<CENTER><TABLE CELLPADDING=5 BORDER=1>\n";
			print HTMLFILE "<TR BGCOLOR=\"$MAINCOLOR\"><TD ALIGN=center CLASS=w12b>Origin</TD>\n";
			print HTMLFILE "<TD ALIGN=center CLASS=w12b>Prefixes</TD>\n";
			print HTMLFILE "<TD CLASS=w12b>AS Paths</TD></TR>\n";

			foreach $origin (sort(keys(%hash))) {
				$origin_as = &format_originAS($origin);
				print HTMLFILE "<TR VALIGN=top><TD>$origin_as</TD>\n";
				print HTMLFILE "<TD><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>";
				foreach $prefix (@{$hash{$origin}}) {print HTMLFILE "<TR><TD>$prefix</TD></TR>\n"}
				print HTMLFILE "</TABLE></TD>\n";
				print HTMLFILE "<TD><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>\n";
				foreach $prefix (@{$hash{$origin}}) {
					@tmp = split(/\s+/, $ATTRIBUTES{$prefix});
					print HTMLFILE "<TR>\n";
					for ($i = 4; $i < $#tmp; $i++) {
						$asname = &format_asname($tmp[$i]);
						print HTMLFILE "<TD>$asname</TD>";
						print HTMLFILE "<TD>$separator</TD>\n";
					}
					$asname = &format_asname($tmp[$#tmp]);
					print HTMLFILE "<TD>$asname</TD>\n";
					if ($#tmp < $maxlen) {
						$leftcol = $numcol - ($#tmp - 4)*2 + 1;
						print HTMLFILE "<TD COLSPAN=$leftcol>&nbsp;</TD>\n";
					}
					print HTMLFILE "</TR>\n";
				}
				print HTMLFILE "</TABLE></TD></TR>\n";
			}
			print HTMLFILE "</TABLE></CENTER>\n<P><HR>\n";
		}
		else {
			print HTMLFILE "<SPAN CLASS=n12>There are no 6to4 longer prefixes.</SPAN><P><HR>\n";
		}
	}

	print HTMLFILE "<SPAN CLASS=n10><A HREF=\"./$INDEXPAGE\">Back to routing information page</A>\n";

	print HTMLFILE "
	<HR>\n
	This pages display all the anomalous IPv6 BGP prefixes (according to RFC2546 - &quot;IPv6 routing Practice&quot;)
	currently advertised inside the 6Bone backbone. In particular two kinds of anomalous prefixes are displayed:
	<UL>\n
	<LI><SPAN CLASS=r10>Invalid prefixes</SPAN>: prefixes outside of the IANA assigned address spaces
	(e.g. the old RFC1897 test addresses)\n
	<LI><SPAN CLASS=r10>Unaggregated prefixes</SPAN>: prefixes belonging to the 6Bone range
	but longer than a given pTLA delegation (according to RFC2546 these
	prefixes MUST NOT be advertised unless special peering agreements are implemented); prefixes
	belonging to the RIR&quot;s delegations but longer than assigned sTLAs.\n
	</UL>
	<HR>\n".&footer."
	</SPAN>\n</BODY>\n</HTML>\n";

	close(HTMLFILE);
}

(1);
#### ASpath-tree v.4.2 - Released on Thu APR 17 2003, h.16:58:12
#### File: lib/odd-routes.pl Last modified on Fri MAR 14 2003, h.15:42:35
