#### ASpath-tree v.4.2 - Released on Thu APR 17 2003, h.16:58:12
#### File: lib/ASmain.pl Last modified on Wed MAR 19 2003, h.15:51:45

require ("$LIB/getbgptable.pl");
require ("$LIB/utility.pl");
require ("$LIB/ipv6prefix.pl");
require ("$LIB/elaborate-aspaths.pl");
require ("$LIB/history.pl");
require ("$LIB/bgp-tree.pl");
require ("$LIB/bgp-tree-changes.pl");
require ("$LIB/route-stability.pl");
require ("$LIB/odd-as.pl");
require ("$LIB/odd-routes.pl");
require ("$LIB/create-homepage.pl");

# Do the main tasks for ASpath-tree
sub asmain {
	my ($input) = @_;

# update information used by ASpath-tree
	&update_localdbs_tables(0);

#	return(0);
# set current and last update runtimes
	&log_runtime;

	&log_it("CREATING BGP PAGES...",1);
# Get IPv6 BGP table from router
	my ($irtable,$inums) = &get_bgp_table;
	unless (@$irtable) {&log_it_and_die("No router BGP table")}
	&log_it("  Get and Parse IPv6 BGP table: done",1);

# Initialize basic arrays
	&initialize_arrays(@$irtable);
	&log_it("  Setting runtime tables: done",1);

# Update history and create detail files
	my ($inums2,$idistance,$ipaths_withasspriv,$ipaths_withassreserved) = &update_details_and_history;
	&log_it("  Update history and create detail pages: done",1);

# Create the whole IPv6 BGP ASpath tree
	my $lastchange_time = &check_update_changes(0);
	&create_html_tree(0, $lastchange_time);
	if ($MORETREES) {
# Create the IPv6 BGP ASpath tree for the 6Bone backbone
		$lastchange_time = &check_update_changes(1);
		&create_html_tree(1, $lastchange_time);

# Create the IPv6 BGP ASpath tree for the other IANA assigned prefixes
		$lastchange_time = &check_update_changes(3);
		&create_html_tree(3, $lastchange_time);
	}
	&log_it("  Tree page(s): done",1);
# Create routes stability pages
#     for the 6bone backbone
	&create_stability_page("$HTMLDIR_LOCAL/ptla-stability.html", "ptla");
	&log_it("  bb stability page: done",1);
#     for the other IANA assigned prefixes
	&create_stability_page("$HTMLDIR_LOCAL/200x-stability.html", "stla");
	&log_it("  IANA stability page: done",1);

# Create Odd routes pages
	&create_oddroutes_pages("$HTMLDIR_LOCAL/odd-routes.html");
	&log_it("  Odd-routes pages: done",1);

# Create Odd AS pages
	&create_oddasn_pages("$HTMLDIR_LOCAL/odd-asnumbers.html", $ipaths_withasspriv, $ipaths_withassreserved)
	&create_oddroutes_pages("$HTMLDIR_LOCAL/odd-routes.html");
	&log_it("  Odd-AS pages: done",1);

# Create home page
	&home_page($inums, $inums2, $idistance);
	&log_it("  Home page: done",1);

# Copy files to HTMLDIR if it is different from HTMLDIR_LOCAL
	if ($HTMLDIR ne $HTMLDIR_LOCAL) {
		&log_it("COPYING files...",1);
		system "mv $HTMLDIR/details/complete $HTMLDIR_LOCAL/trash/";
		system "mv $DETAILDIRCO $HTMLDIR/details";
		if ($MORETREES) {
			system "mv $HTMLDIR/details/backbone $HTMLDIR_LOCAL/trash/";
			system "mv $DETAILDIRBB $HTMLDIR/details";
			system "mv $HTMLDIR/details/otherIANA $HTMLDIR_LOCAL/trash/";
			system "mv $DETAILDIRIANA $HTMLDIR/details";
		} else {
			if (-e $OUTPUTBB) {system "mv $OUTPUTBB $HTMLDIR_LOCAL/trash/"}
			$OUTPUTBB =~ m!([^/]*)$!;
			if (-e "$HTMLDIR/$1") {system "mv $HTMLDIR/$1 $HTMLDIR_LOCAL/trash/"}
			if (-e $OUTPUTIANA) {system "mv $OUTPUTIANA $HTMLDIR_LOCAL/trash/"}
			$OUTPUTIANA =~ m!([^/]*)$!;
			if (-e "$HTMLDIR/$1") {system "mv $HTMLDIR/$1 $HTMLDIR_LOCAL/trash/"}
		}
		system "mv $HTMLDIR/24h_history $HTMLDIR_LOCAL/trash/";
		system "mv $HISTORYHTMLDIR $HTMLDIR";

		if ($CHANGESFLAG) {
			if ((stat("$OUTPUTCOMPLETECHANGES"))[9] > $CURRENTTIME) {system "cp -f $OUTPUTCOMPLETECHANGES $HTMLDIR/changes/"}
			if ($MORETREES) {
				if ((stat("$OUTPUTBBCHANGES"))[9] > $CURRENTTIME) {system "cp -f $OUTPUTBBCHANGES $HTMLDIR/changes/"}
				if ((stat("$OUTPUTIANACHANGES"))[9] > $CURRENTTIME) {system "cp -f $OUTPUTIANACHANGES $HTMLDIR/changes/"}
			} else {
				if (-e $OUTPUTBBCHANGES) {system "mv $OUTPUTBBCHANGES $HTMLDIR_LOCAL/trash/"}
				$OUTPUTBBCHANGES =~ m!([^/]*)$!;
				if (-e "$HTMLDIR/changes/$1") {system "mv $HTMLDIR/changes/$1 $HTMLDIR_LOCAL/trash/"}
				if (-e $OUTPUTIANACHANGES) {system "mv $OUTPUTIANACHANGES $HTMLDIR_LOCAL/trash/"}
				$OUTPUTIANACHANGES =~ m!([^/]*)$!;
				if (-e "$HTMLDIR/changes/$1") {system "mv $HTMLDIR/changes/$1 $HTMLDIR_LOCAL/trash/"}
			}
		} elsif (-d "$HTMLDIR/changes") {system "mv $HTMLDIR/changes $HTMLDIR_LOCAL/trash/"}

		system "cp $HTMLDIR_LOCAL/bgp-page-*.html $HTMLDIR/";
		system "cp $HTMLDIR_LOCAL/bgp-table-snapshot.txt $HTMLDIR/";
		system "cp $HTMLDIR_LOCAL/odd-routes*.html $HTMLDIR/";
		system "cp $HTMLDIR_LOCAL/odd-asnumbers*.html $HTMLDIR/";
		system "cp $HTMLDIR_LOCAL/200x-stability.html $HTMLDIR";
		system "cp $HTMLDIR_LOCAL/ptla-stability.html $HTMLDIR";

		system "cp $HTMLDIR_LOCAL/$INDEXPAGE $HTMLDIR/$INDEXPAGE";
		&log_it("  Done!",1);

		&log_it("Emptying trash ...",1);
		system "rm -rf $HTMLDIR_LOCAL/trash/*";
		&log_it("  Done!",1);
	}

	return(0);
}

(1);
#### ASpath-tree v.4.2 - Released on Thu APR 17 2003, h.16:58:12
#### File: lib/ASmain.pl Last modified on Wed MAR 19 2003, h.15:51:45
