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

use vars qw ($MAINCOLOR $LINKCOLOR $LINESDETTABLECOLOR $SMALLBOLDCOLOR $MEDIUMBOLDCOLOR);

$MAINCOLOR = '#00009D';
$LINKCOLOR = '#00009D';
$VLINKCOLOR = '#00009D';
$LINESDETTABLECOLOR = '#C0C0C0';
$SMALLBOLDCOLOR = '#000000';
$MEDIUMBOLDCOLOR = '#000000';

# Routines to create the home page
sub home_page {
	my ($inumtable, $inumelab, $iasdist) = @_;

	&crea_bgp_page ($inumtable, $inumelab, $iasdist);
	return(0);
}

sub crea_bgp_page {

	my ($inumtable, $inumelab, $iasdist) = @_;
	my ($routesum, $sixto4link, $note, $privaslink, $resaslink);
	my $out_file = "$HTMLDIR_LOCAL/bgp.html";
	open (OUT_FILE,">$out_file") or die "Can't open $out_file: $!\n";

	print OUT_FILE &header("IPv6 BGP Operational Report from $SITENAME", 0);
	print OUT_FILE "  <TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=\"100\%\">\n<TR>";
	print OUT_FILE "<TD>\n<TABLE>\n<TR>";
	if ($SITEPICTURE) {
		print OUT_FILE "<TD VALIGN=top><IMG SRC=\"$ICONS/$SITEPICTURE\" BORDER=0></TD>\n";
	}
	print OUT_FILE "<TD VALIGN=bottom CLASS=a32b>&nbsp;IPv6 BGP Operational Report from $SITENAME</TD></TR>\n";
	print OUT_FILE "</TABLE>\n</TD>\n";

	print OUT_FILE "</TR>
    <TR><TD HEIGHT=\"2\" BGCOLOR=\"\#FFFFFF\"><IMG SRC=\"$ICONS/p.gif\" WIDTH=\"2\" ALT=\"\"></TD></TR>
    <TR><TD HEIGHT=\"2\" BGCOLOR=\"$MAINCOLOR\"><IMG SRC=\"$ICONS/p.gif\" WIDTH=\"2\" ALT=\"\"></TD></TR>
    <TR><TD HEIGHT=\"2\" BGCOLOR=\"\#FFFFFF\"><IMG SRC=\"$ICONS/p.gif\" WIDTH=\"2\" ALT=\"\"></TD></TR>
    ";
	print OUT_FILE "    <TR><TD VALIGN=top ALIGN=left>
      <TABLE CELLSPACING=0 CELLPADDING=5 BORDER=0 WIDTH=\"100\%\">
        <TR><TD VALIGN=top>
          <TABLE CELLSPACING=0 CELLPADDING=2 BORDER=1 WIDTH=\"100\%\">
            <TR><TD VALIGN=top ALIGN=left CLASS=a10b>
              <NOBR>Latest <A HREF=\"bgp-table-snapshot.txt\">snapshot</A> of the IPv6 BPG table<BR>
              $LONGDATE<P>
              Route summary<BR>\n";

	if (ROUTER =~ /^JUNIPER$/i) {$routesum = 'Active/Total'}
	else {$routesum = 'Best/Total'}

	print OUT_FILE "              <TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 ALIGN=center>
                <TR><TD CLASS=n10 ALIGN=left>$routesum routes:</TD>
                    <TD CLASS=t11 ALIGN=right>$$inumtable{best}</TD><TD CLASS=t11 ALIGN=right>\/</TD>
                    <TD CLASS=t11 ALIGN=right>$$inumtable{valid}</TD></TR>\n";

	if ($$inumtable{suppressed}) {
		print OUT_FILE "                <TR><TD CLASS=n10 ALIGN=left>Suppressed routes:</TD>
                    <TD CLASS=t11 ALIGN=right COLSPAN=3>$$inumtable{suppressed}</TD></TR>\n";
	}
	if ($$inumtable{damped}) {
		print OUT_FILE "                <TR><TD CLASS=n10 ALIGN=left>Damped routes:</TD>
                    <TD CLASS=t11 ALIGN=right COLSPAN=3>$$inumtable{damped}</TD></TR>\n";
	}
	if ($$inumtable{history}) {
		print OUT_FILE "                <TR><TD CLASS=n10 ALIGN=left>History routes:</TD>
                    <TD CLASS=t11 ALIGN=right COLSPAN=3>$$inumtable{history}</TD></TR>\n";
	}
	if ($$inumtable{RIBfailure}) {
		print OUT_FILE "                <TR><TD CLASS=n10 ALIGN=left>RIB failure routes:</TD>
                    <TD CLASS=t11 ALIGN=right COLSPAN=3>$$inumtable{RIBfailure}</TD></TR>\n";
	}

print OUT_FILE "              </TABLE>\n";
if ($$inumelab{ASintrees}) {
	if ($$inumelab{privAS}) {$privaslink = "<A HREF=\"odd-asnumbers.html\">private AS numbers</A>"}
	else {$privaslink = "private AS numbers"}
	if ($$inumelab{reservedAS}) {$resaslink = "<A HREF=\"odd-asnumbers1.html\">reserved AS numbers</A>"}
	else {$resaslink = "reserved AS numbers"}
	print OUT_FILE "              <P>Number of ASs in table: <SPAN CLASS=t11>$$inumelab{ASintrees}\/$$inumtable{ASs}</SPAN><BR>
              <SPAN CLASS=n10>(within active routes\/within total routes)</SPAN><BR>
              Among the ASs in active routes<BR>
              <TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 ALIGN=center>
                <TR><TD CLASS=n10 ALIGN=left>originating only ASs:</TD>
                    <TD CLASS=t11 ALIGN=right>$$inumelab{origAS}</TD></TR>
                <TR><TD CLASS=n10 ALIGN=left>originating/transit ASs:</TD>
                    <TD CLASS=t11 ALIGN=right>$$inumelab{bothAS}</TD></TR>
                <TR><TD CLASS=n10 ALIGN=left>transit only ASs:</TD>
                    <TD CLASS=t11 ALIGN=right>$$inumelab{transitAS}</TD></TR>
                <TR><TD CLASS=n10 ALIGN=left>$privaslink:</TD>
                    <TD CLASS=t11 ALIGN=right>$$inumelab{privAS}</TD></TR>
                <TR><TD CLASS=n10 ALIGN=left>$resaslink:</TD>
                    <TD CLASS=t11 ALIGN=right>$$inumelab{reservedAS}</TD></TR>
              </TABLE>\n";
}
if ($$inumelab{ASpaths}) {
	print OUT_FILE "              <P>Number of active AS paths: <SPAN CLASS=t11>$$inumelab{ASpaths}</SPAN>\n";
}
print OUT_FILE "              <P>Number of active peers: <SPAN CLASS=t11>$$inumelab{activePEERS}</SPAN>\n";

# Calculate distance stats
my ($sum, $prod, $sumlong) = (0, 0, 0);
foreach $key (sort {$a <=> $b} (keys(%$iasdist))) {
	$sum += $$iasdist{$key};
	$prod += $key*$$iasdist{$key};
	if ($key > 4) {$sumlong += $$iasdist{$key}}
}
if ($sum) {
	my @hops = ('&nbsp;1', '&nbsp;2', '&nbsp;3', '&nbsp;4', '&gt;4');
	my @perc = ();
	my $tmp;
	my ($perclen, $abslen) = (0, 0);
	for ($i=0;$i<4;$i++) {
		$tmp = $$iasdist{$i+1}/$sum*100;
		$perc[$i] = &trunc_number($tmp, 0);;
		if ($perclen < length($perc[$i])) {$perclen = length($perc[$i])}
		if ($abslen < length($$iasdist{$i+1})) {$abslen = length($$iasdist{$i+1})}
	}
	$tmp = $sumlong/$sum*100;
	$perc[4] = &trunc_number($tmp, 0);;
	if ($perclen < length($perc[4])) {$perclen = length($perc[4])}
	if ($abslen < length($sumlong)) {$abslen = length($sumlong)}
# cleaning up percentages
	$sum = $perc[0]+$perc[1]+$perc[2]+$perc[3]+$perc[4];
	if($sum <100) {for ($i=4;$>=0;$i--) {if ($perc[$i] > 0) {$perc[$i] += (100-$sum)};last}}
	if($sum >100) {for ($i=4;$>=0;$i--) {if (($perc[$i] - $sum +100) > 0) {$perc[$i] += ($sum-100)};last}}

	print OUT_FILE "              <P>AS distance<BR>
              <TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 ALIGN=center>
                <TR><TD CLASS=n10 ALIGN=center>\&nbsp;\&nbsp;Crossed ASs\&nbsp;\&nbsp;</TD><TD CLASS=n10 ALIGN=center>\&nbsp;\&nbsp;Prefixes\&nbsp;\&nbsp;</TD><TD CLASS=n10 ALIGN=center>\&nbsp;\&nbsp;Perc.\&nbsp;\&nbsp;</TD></TR>\n";
		my ($absval, $percval);
		for ($i=0;$i<5;$i++) {
			$percval = ('&nbsp;' x ($perclen - length($perc[$i]))) . $perc[$i];
			$tmp = $$iasdist{$i+1};
			if ($i == 4) {$tmp = $sumlong}
			$absval = ('&nbsp;' x ($abslen - length($tmp))) . $tmp;

			print OUT_FILE "                <TR><TD CLASS=t11 ALIGN=center>$hops[$i]</TD><TD CLASS=t11 ALIGN=center>$absval</TD><TD CLASS=t11 ALIGN=center>$percval\%</TD></TR>\n";
		}
		print OUT_FILE "              </TABLE>";
		print OUT_FILE "              Average: <SPAN CLASS=t11>$$inumelab{averageDIST} crossed ASs</SPAN>\n";
	}
	print OUT_FILE "            </TD></TR>
          </TABLE>
        </TD>
        <TD VALIGN=center ALIGN=left CLASS=n12>
          <SPAN CLASS=a18b>Graphic display</SPAN> of:
          <UL>
          <LI><A HREF=\"bgp-page-complete.html\" CLASS=l12b>all route entries within the IPv6 BGP cloud</A><BR>\n";
	if ($MORETREES) {
		print OUT_FILE "          <LI><A HREF=\"bgp-page-backbone.html\" CLASS=l12b>the 6Bone backbone BGP tree</A><BR>
          <LI><A HREF=\"bgp-page-otherIANA.html\" CLASS=l12b>the BGP tree for prefixes assigned by the RIRs</A>\n";
	}
	print OUT_FILE "          </UL>\n";

	if ($$inumelab{N_6to4}) {$sixto4link = "<LI>the 6to4 prefix"}

	print OUT_FILE "          <SPAN CLASS=a18b>Prefix analysis</SPAN>(*):<BR>
          <UL>
          <LI>$$inumelab{N_ptlas} 6Bone pTLAs
          <LI>$$inumelab{N_otherIANA} prefixes assigned by RIRs (prefix length in range [29,35])
          $sixto4link\n";
	if ($$inumelab{N_invalid} || $$inumelab{N_unaggr} || $$inumelab{N_longer6to4}) {
		print OUT_FILE "          <LI>the following <A HREF=\"odd-routes.html\" CLASS=l12b>odd routes</A>:
          <UL>
          <LI TYPE=square>$$inumelab{N_invalid} invalid prefixes (out of allocated public address space)</LI>
          <LI TYPE=square>$$inumelab{N_unaggr} unaggregated prefixes, sorted <A HREF=\"odd-routes1.html\" CLASS=l12b> by origin AS</A>
          and <A HREF=\"odd-routes2.html\" CLASS=l12b>by xTLA owner</A></LI>\n";
		if ($$inumelab{N_longer6to4}) {
			print OUT_FILE "          <LI TYPE=square>$$inumelab{N_longer6to4} <A HREF=\"odd-routes3.html\" CLASS=l12b>6to4 longer prefixes</A></LI>\n";
		}
	}
	else {print OUT_FILE "          <LI>no odd routes</LI>\n"}

print OUT_FILE "          </UL>\n          </UL>\n";
	$note = "(*) Excluding prefixes with local origin (no associated AS paths)";
	if ($FILTEROUT == 1) {$note .= " and prefixes within suppressed routes"}
	elsif ($FILTEROUT == 2) {$note .= " and prefixes within suppressed routes learned through iBGP"}
	print OUT_FILE "          $note\.<P>\n";
print OUT_FILE "          <SPAN CLASS=a18b>Routing stability analysis</SPAN>
          during the last 24 hours for:<BR>
          <UL>
          <LI><A HREF=\"ptla-stability.html\" CLASS=l12b>all the 6Bone pTLAs</A><BR>
          <LI><A HREF=\"200x-stability.html\" CLASS=l12b>the sTLAs assigned by the RIRs</A>
          </UL>
        </TD></TR>
      </TABLE>
    </TD></TR>\n";
	print OUT_FILE "
    <TR><TD HEIGHT=\"2\" BGCOLOR=\"\#FFFFFF\"><IMG SRC=\"$ICONS/p.gif\" WIDTH=\"2\" ALT=\"\"></TD></TR>
    <TR><TD HEIGHT=\"2\" BGCOLOR=\"$MAINCOLOR\"><IMG SRC=\"$ICONS/p.gif\" WIDTH=\"2\" ALT=\"\"></TD></TR>
    <TR><TD HEIGHT=\"2\" BGCOLOR=\"\#FFFFFF\"><IMG SRC=\"$ICONS/p.gif\" WIDTH=\"2\" ALT=\"\"></TD></TR>
    ";

	print OUT_FILE "    <TR><TD VALIGN=top ALIGN=left CLASS=n10>\n";
	print OUT_FILE &footer;
	print OUT_FILE "    </TD></TR>\n  </TABLE>\n</BODY>\n</HTML>\n";

	close (OUT_FILE);
	return(0);
}

sub header {
	my ($title, $flag) = @_;

	my $text = "<HTML>
<HEAD>
  <TITLE>$title</TITLE>
  <META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">
  <META HTTP-EQUIV=\"Refresh\" CONTENT=\"300\">
  <STYLE>
A {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; font-weight: bold; color: $LINKCOLOR}
A:hover {color: $VLINKCOLOR; text-decoration: none}
A:active {color: $VLINKCOLOR; text-decoration: none}
A:link {color: $LINKCOLOR; text-decoration: none}
A:visited {color: $LINKCOLOR; text-decoration: none}
";
	if ($flag == 1) {
	$text .= "TD {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; size: 1; font-weight: normal; color: $LINKCOLOR}\n";
	} else {
	$text .= "TD {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; size: 1; font-weight: normal; color: \#000000}\n";
	}
	$text .= ".a32b {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 32px; font-weight: bold; color: $MAINCOLOR}
.w32b {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 32px; font-weight: bold; color: #FFFFFF}
.a18b {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 18px; font-weight: bold; color: $MAINCOLOR}
.a16b {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 16px; size: 1; font-weight: bold; color: $MAINCOLOR}
.a12b {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; size: 1; font-weight: bold; color: $MAINCOLOR}
.l12b  {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; size: 1; font-weight: bold; color: $MEDIUMBOLDCOLOR}
.n12  {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; size: 1; font-weight: normal; color: #000000}
.n12b {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; size: 1; font-weight: bold; color: #000000}
.t12  {font-family: courier new, courier; font-size: 12px; size: 1; font-weight: normal; color: #000000}
.w12b {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color: #FFFFFF}
.t11  {font-family: Courier new, Courier; font-size: 11px; font-weight: normal; color: \#000000}
.a10  {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; size: 1; font-weight: normal; color: $MAINCOLOR}
.a10b {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; size: 1; font-weight: bold; color: $MAINCOLOR}
.n10  {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; size: 1; font-weight: normal; color: #000000}
.n10b {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; font-weight: bold; color: $SMALLBOLDCOLOR}
.g10  {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; size: 1; font-weight: normal; color: green}
.r10  {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; size: 1; font-weight: normal; color: red}
  </STYLE>
</HEAD>
<BODY BGCOLOR=\"#FFFFFF\" TOPMARGIN=2>\n";

	return($text);
}

sub footer {
	my $footer = "This page has been produced using the
	<A HREF=\"http://carmen.ipv6.tilab.com/ipv6/tools/ASpath-tree/index.html\">ASpath-tree</A> tool ($VER),
	developed at <A HREF=\"http://www.telecomitalialab.com\">Telecom Italia Lab</A> (formerly CSELT).<BR>
	Questions and comments to: <A HREF=\"mailto:$CONTACTMAIL\">$CONTACTNAME</A>\n";
	return($footer);
}

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