jablonka.czprosek.czf

netmap

Subversion Repositories:
[/] [gen_ospf_link.pl] - Rev 42 Go to most recent revision

Compare with Previous - Blame - Download


#!/usr/bin/perl
#
# Petr Simandl, www.simandl.cz
# v 0.0.3

#print "Content-type: text/html\n\n";

#print "<HTML><HEAD><META HTTP-EQUIV=Pragma CONTENT=no-cache></HEAD><BODY>\n";

$date = `date`;
#print "<BR>$date\n<BR>";

#print "<pre>";

@ol_names=`cat /home/www/cgi-bin/netmap/data/jablonecka.comp`;
#@ol_database=`/home/www/cgi-bin/ospfd_database.cgi`;
@ol_database=`wget -q http://10.33.0.11/cgi-bin/ospfd_database.cgi -O -`;
#print @ol_names;
@ol_basiclinks=`cat /home/www/cgi-bin/netmap/data/jablonecka.link.basic | grep ^00`;

foreach $ol_line (@ol_names)
{
@ol_pole=split(";",$ol_line);
#print "$ol_pole[0] $ol_pole[1]\n";
}

#print "Vypis routeru s jednotlivymi linky\n";
#print @ol_database;

@ol_routers=();
@ol_links=();
$ol_router="";
$ol_link="";

#picking up routers and their links into fields ol_routers and ol_links
foreach $ol_line (@ol_database)
{
  if ($ol_line =~ /Advertising/)
  {     @ol_string=split(" ",$ol_line);
#       print "\nrouter $ol_string[2]\n";
        #storing previous router 
        if ($ol_router eq "")
        #no previous found yet
        {#      print "prvni polozka\n";
        }
        else
        {
#               print "zapis routeru\n";
                push(@ol_routers, $ol_router );
#               print "@ol_routers\n";
#               print "@ol_links\n";
        }

        #prefilling with IP
        $ol_router=$ol_string[2];
        #using netmap config to substittute names instead IPs
        foreach $ol_name (@ol_names)
        {   @ol_name_split=split(";",$ol_name);
            #compare IPs
            if ("$ol_name_split[1]" eq "$ol_string[2]")
                { #print "jsou stejne $ol_name_split[0] a $ol_string[2]\n";
                  #name found so we will store it
                  $ol_router=$ol_name_split[0];
                }
        }
        if ("$ol_router" eq "$ol_string[2]")
        { #print "Router $ol_router neni v databazi!\n";
        }

        
        
#       $ol_router=$ol_string[2];
        $ol_link="";
  }

  #looking for first (central) side of link
  if ($ol_line =~ /Designated/)
  {     @ol_string=split(" ",$ol_line);
#       print "ifA $ol_string[5]\n";
        $ol_link=$ol_string[5];
  }

  #looking for second (local) side of link and storing this link into the ol_links
  if ($ol_line =~ /Interface/)
  {     @ol_string=split(" ",$ol_line);
#       print "ifB $ol_string[5]\n";
        #adding only second local side
        $ol_router=$ol_router." ".$ol_string[5];
        $ol_link=$ol_link." ".$ol_string[5];
        push(@ol_links, $ol_link );
        $ol_link="";
  }
}

#storing the last router
#print "Posledni zapis routeru\n";
push(@ol_routers, $ol_router );
#print "@ol_routers\n";


#print "\n\nVypis pole routeru\n";

#print "@ol_routers";

#print "\n\nVypis pole linku\n";
#print "@ol_links";

####################################################

#print "\n\nVypis pole linku redukovanych\n";

#kicking links with same begin and end
@ol_links_reduced=();

foreach $ol_line (@ol_links)
{   @ol_string=split(" ",$ol_line);
    if ("$ol_string[0]" eq "$ol_string[1]")
        { #print "jsou stejne $ol_string[0] a $ol_string[1]\n";
        }
        else
        {
        push(@ol_links_reduced, $ol_line );
        #print "added $ol_line\n";
        }

}


#print "@ol_links_reduced";

#prvni cast linku je vzdy designated
#seradit podle prvni casti linku
#roztridit do skupin podle prvni casti linku
#pokud chceme -zatim nedelat -  tak ve skupine vybrat nejmensi ip a vlozit ho za designated
#stale mame dvojice linku
#jdeme v seznamu routeru ol_routers a pekne v seznamu ol_links zamenime hlavni IP routeru za IP jeho rozhrani 

#print "\n\nVytvareni jmennych linku\n";

#going through all links and fill router names into links instead of interface IPs 
@ol_links_named=();
foreach $ol_link (@ol_links_reduced)
{   @ol_ips=split(" ",$ol_link);
#    print "$ol_link";
    #initially we fill both sides of link with real IPs
    $ol_ipa=$ol_ips[0];
    $ol_ipb=$ol_ips[1];
    foreach $ol_router_line (@ol_routers)
    {   @ol_router_ifaces=split(" ",$ol_router_line);
        $ol_router_name=shift(@ol_router_ifaces);
        #print "$ol_router_name ma @ol_router_ifaces\n";
        foreach $ol_iface (@ol_router_ifaces)
        { #print "$ol_iface\n";
          if ("$ol_iface" eq "$ol_ips[0]")
          { $ol_ipa=$ol_router_name;
          }
          if ("$ol_iface" eq "$ol_ips[1]")
          { $ol_ipb=$ol_router_name;
          }
        }
    }
    #
    push(@ol_links_named, $ol_ipa." ".$ol_ipb );
}

#now we will look into basic link file and all not found basic links (00) will be drawn in red color
foreach $ol_linkb (@ol_basiclinks)
{   @ol_nameb=split(/;/,$ol_linkb);
    @ol_nameb = sort (@ol_nameb);
    $ol_ispresent=0;
    #print $ol_name[3];
    
    foreach $ol_linko (@ol_links_named)
    {   @ol_nameo=split(" ",$ol_linko);
        @ol_nameo = sort (@ol_nameo);
        if (("$ol_nameo[0]" eq "$ol_nameb[2]") && ("$ol_nameo[1]" eq "$ol_nameb[3]")) 
        { $ol_ispresent=1;
#        print "92;$ol_nameo[0];$ol_nameo[1];\n";

        };
    };
    if ($ol_ispresent)
        { print "92;$ol_nameb[2];$ol_nameb[3];\n";}
        else
        { print "82;$ol_nameb[2];$ol_nameb[3];\n";}
}

#now we will look into ospf links and all not found in basic link file (00) will be drawn in red color
foreach $ol_linko (@ol_links_named)
{   @ol_nameo=split(" ",$ol_linko);
    @ol_nameo = sort (@ol_nameo);
    $ol_isnotpresent=1;

    foreach $ol_linkb (@ol_basiclinks)
    {   @ol_nameb=split(/;/,$ol_linkb);
        @ol_nameb = sort (@ol_nameb);
        if (("$ol_nameo[0]" eq "$ol_nameb[2]") && ("$ol_nameo[1]" eq "$ol_nameb[3]")) 
        { $ol_isnotpresent=0;
        };
    };
    if ($ol_isnotpresent)
        { print "01;$ol_nameo[0];$ol_nameo[1];\n";}
}

#print "</pre></BODY></HTML>";

exit

Powered by WebSVN 2.2.1