| 1 | 1 | simandl | #!/usr/bin/perl |
| 2 | | | # |
| 3 | | | # Petr Simandl, www.simandl.cz |
| 4 | | | # v 0.0.3 |
| 5 | | | |
| 6 | | | #print "Content-type: text/html\n\n"; |
| 7 | | | |
| 8 | | | #print "<HTML><HEAD><META HTTP-EQUIV=Pragma CONTENT=no-cache></HEAD><BODY>\n"; |
| 9 | | | |
| 10 | | | $date = `date`; |
| 11 | | | #print "<BR>$date\n<BR>"; |
| 12 | | | |
| 13 | | | #print "<pre>"; |
| 14 | | | |
| 15 | | | @ol_names=`cat /home/www/cgi-bin/netmap/data/jablonecka.comp`; |
| 16 | 27 | simandl | #@ol_database=`/home/www/cgi-bin/ospfd_database.cgi`; |
| 17 | 101 | simandl | @ol_database=`wget -q http://10.33.0.22/cgi-bin/ospfd_database.cgi -O -`; |
| 18 | 1 | simandl | #print @ol_names; |
| 19 | 28 | simandl | @ol_basiclinks=`cat /home/www/cgi-bin/netmap/data/jablonecka.link.basic | grep ^00`; |
| 20 | 1 | simandl | |
| 21 | | | foreach $ol_line (@ol_names) |
| 22 | | | { |
| 23 | | | @ol_pole=split(";",$ol_line); |
| 24 | | | #print "$ol_pole[0] $ol_pole[1]\n"; |
| 25 | | | } |
| 26 | | | |
| 27 | | | #print "Vypis routeru s jednotlivymi linky\n"; |
| 28 | | | #print @ol_database; |
| 29 | | | |
| 30 | | | @ol_routers=(); |
| 31 | | | @ol_links=(); |
| 32 | | | $ol_router=""; |
| 33 | | | $ol_link=""; |
| 34 | | | |
| 35 | | | #picking up routers and their links into fields ol_routers and ol_links |
| 36 | | | foreach $ol_line (@ol_database) |
| 37 | | | { |
| 38 | | | if ($ol_line =~ /Advertising/) |
| 39 | | | { @ol_string=split(" ",$ol_line); |
| 40 | | | # print "\nrouter $ol_string[2]\n"; |
| 41 | | | #storing previous router |
| 42 | | | if ($ol_router eq "") |
| 43 | | | #no previous found yet |
| 44 | | | {# print "prvni polozka\n"; |
| 45 | | | } |
| 46 | | | else |
| 47 | | | { |
| 48 | | | # print "zapis routeru\n"; |
| 49 | | | push(@ol_routers, $ol_router ); |
| 50 | | | # print "@ol_routers\n"; |
| 51 | | | # print "@ol_links\n"; |
| 52 | | | } |
| 53 | | | |
| 54 | | | #prefilling with IP |
| 55 | | | $ol_router=$ol_string[2]; |
| 56 | | | #using netmap config to substittute names instead IPs |
| 57 | | | foreach $ol_name (@ol_names) |
| 58 | | | { @ol_name_split=split(";",$ol_name); |
| 59 | | | #compare IPs |
| 60 | | | if ("$ol_name_split[1]" eq "$ol_string[2]") |
| 61 | | | { #print "jsou stejne $ol_name_split[0] a $ol_string[2]\n"; |
| 62 | 46 | simandl | #name found so we will store it and we add a router ip to cover possible PtP links |
| 63 | | | $ol_router=$ol_name_split[0]." ".$ol_string[2]; |
| 64 | 1 | simandl | } |
| 65 | | | } |
| 66 | | | if ("$ol_router" eq "$ol_string[2]") |
| 67 | | | { #print "Router $ol_router neni v databazi!\n"; |
| 68 | | | } |
| 69 | | | |
| 70 | | | # $ol_router=$ol_string[2]; |
| 71 | | | $ol_link=""; |
| 72 | | | } |
| 73 | | | |
| 74 | | | #looking for first (central) side of link |
| 75 | | | if ($ol_line =~ /Designated/) |
| 76 | | | { @ol_string=split(" ",$ol_line); |
| 77 | | | # print "ifA $ol_string[5]\n"; |
| 78 | | | $ol_link=$ol_string[5]; |
| 79 | | | } |
| 80 | | | |
| 81 | 46 | simandl | #looking for first (central) side of ptp link |
| 82 | | | if ($ol_line =~ /Neighboring/) |
| 83 | | | { @ol_string=split(" ",$ol_line); |
| 84 | | | # print "ifA $ol_string[5]\n"; |
| 85 | | | $ol_link=$ol_string[5]; |
| 86 | | | } |
| 87 | | | |
| 88 | 1 | simandl | #looking for second (local) side of link and storing this link into the ol_links |
| 89 | | | if ($ol_line =~ /Interface/) |
| 90 | | | { @ol_string=split(" ",$ol_line); |
| 91 | | | # print "ifB $ol_string[5]\n"; |
| 92 | | | #adding only second local side |
| 93 | | | $ol_router=$ol_router." ".$ol_string[5]; |
| 94 | | | $ol_link=$ol_link." ".$ol_string[5]; |
| 95 | | | push(@ol_links, $ol_link ); |
| 96 | | | $ol_link=""; |
| 97 | | | } |
| 98 | | | } |
| 99 | | | |
| 100 | | | #storing the last router |
| 101 | | | #print "Posledni zapis routeru\n"; |
| 102 | | | push(@ol_routers, $ol_router ); |
| 103 | | | #print "@ol_routers\n"; |
| 104 | | | |
| 105 | | | |
| 106 | | | #print "\n\nVypis pole routeru\n"; |
| 107 | | | |
| 108 | | | #print "@ol_routers"; |
| 109 | | | |
| 110 | | | #print "\n\nVypis pole linku\n"; |
| 111 | | | #print "@ol_links"; |
| 112 | | | |
| 113 | | | #################################################### |
| 114 | | | |
| 115 | | | #print "\n\nVypis pole linku redukovanych\n"; |
| 116 | | | |
| 117 | | | #kicking links with same begin and end |
| 118 | | | @ol_links_reduced=(); |
| 119 | | | |
| 120 | | | foreach $ol_line (@ol_links) |
| 121 | | | { @ol_string=split(" ",$ol_line); |
| 122 | | | if ("$ol_string[0]" eq "$ol_string[1]") |
| 123 | | | { #print "jsou stejne $ol_string[0] a $ol_string[1]\n"; |
| 124 | | | } |
| 125 | | | else |
| 126 | | | { |
| 127 | | | push(@ol_links_reduced, $ol_line ); |
| 128 | | | #print "added $ol_line\n"; |
| 129 | | | } |
| 130 | | | |
| 131 | | | } |
| 132 | | | |
| 133 | | | |
| 134 | | | #print "@ol_links_reduced"; |
| 135 | | | |
| 136 | | | #prvni cast linku je vzdy designated |
| 137 | | | #seradit podle prvni casti linku |
| 138 | | | #roztridit do skupin podle prvni casti linku |
| 139 | | | #pokud chceme -zatim nedelat - tak ve skupine vybrat nejmensi ip a vlozit ho za designated |
| 140 | | | #stale mame dvojice linku |
| 141 | | | #jdeme v seznamu routeru ol_routers a pekne v seznamu ol_links zamenime hlavni IP routeru za IP jeho rozhrani |
| 142 | | | |
| 143 | | | #print "\n\nVytvareni jmennych linku\n"; |
| 144 | | | |
| 145 | | | #going through all links and fill router names into links instead of interface IPs |
| 146 | | | @ol_links_named=(); |
| 147 | | | foreach $ol_link (@ol_links_reduced) |
| 148 | | | { @ol_ips=split(" ",$ol_link); |
| 149 | | | # print "$ol_link"; |
| 150 | | | #initially we fill both sides of link with real IPs |
| 151 | | | $ol_ipa=$ol_ips[0]; |
| 152 | | | $ol_ipb=$ol_ips[1]; |
| 153 | | | foreach $ol_router_line (@ol_routers) |
| 154 | | | { @ol_router_ifaces=split(" ",$ol_router_line); |
| 155 | | | $ol_router_name=shift(@ol_router_ifaces); |
| 156 | | | #print "$ol_router_name ma @ol_router_ifaces\n"; |
| 157 | | | foreach $ol_iface (@ol_router_ifaces) |
| 158 | | | { #print "$ol_iface\n"; |
| 159 | | | if ("$ol_iface" eq "$ol_ips[0]") |
| 160 | | | { $ol_ipa=$ol_router_name; |
| 161 | | | } |
| 162 | | | if ("$ol_iface" eq "$ol_ips[1]") |
| 163 | | | { $ol_ipb=$ol_router_name; |
| 164 | | | } |
| 165 | | | } |
| 166 | | | } |
| 167 | | | # |
| 168 | | | push(@ol_links_named, $ol_ipa." ".$ol_ipb ); |
| 169 | | | } |
| 170 | | | |
| 171 | 28 | simandl | #now we will look into basic link file and all not found basic links (00) will be drawn in red color |
| 172 | | | foreach $ol_linkb (@ol_basiclinks) |
| 173 | | | { @ol_nameb=split(/;/,$ol_linkb); |
| 174 | | | @ol_nameb = sort (@ol_nameb); |
| 175 | | | $ol_ispresent=0; |
| 176 | | | #print $ol_name[3]; |
| 177 | | | |
| 178 | | | foreach $ol_linko (@ol_links_named) |
| 179 | | | { @ol_nameo=split(" ",$ol_linko); |
| 180 | | | @ol_nameo = sort (@ol_nameo); |
| 181 | | | if (("$ol_nameo[0]" eq "$ol_nameb[2]") && ("$ol_nameo[1]" eq "$ol_nameb[3]")) |
| 182 | | | { $ol_ispresent=1; |
| 183 | | | # print "92;$ol_nameo[0];$ol_nameo[1];\n"; |
| 184 | | | |
| 185 | | | }; |
| 186 | | | }; |
| 187 | | | if ($ol_ispresent) |
| 188 | | | { print "92;$ol_nameb[2];$ol_nameb[3];\n";} |
| 189 | | | else |
| 190 | | | { print "82;$ol_nameb[2];$ol_nameb[3];\n";} |
| 191 | 1 | simandl | } |
| 192 | | | |
| 193 | 46 | simandl | #now we will look into ospf links and all not found in basic link file (00) will be drawn in black color |
| 194 | 39 | simandl | foreach $ol_linko (@ol_links_named) |
| 195 | | | { @ol_nameo=split(" ",$ol_linko); |
| 196 | | | @ol_nameo = sort (@ol_nameo); |
| 197 | | | $ol_isnotpresent=1; |
| 198 | | | |
| 199 | | | foreach $ol_linkb (@ol_basiclinks) |
| 200 | | | { @ol_nameb=split(/;/,$ol_linkb); |
| 201 | | | @ol_nameb = sort (@ol_nameb); |
| 202 | | | if (("$ol_nameo[0]" eq "$ol_nameb[2]") && ("$ol_nameo[1]" eq "$ol_nameb[3]")) |
| 203 | | | { $ol_isnotpresent=0; |
| 204 | | | }; |
| 205 | | | }; |
| 206 | | | if ($ol_isnotpresent) |
| 207 | 46 | simandl | { print "12;$ol_nameo[0];$ol_nameo[1];\n";} |
| 208 | 39 | simandl | } |
| 209 | | | |
| 210 | 1 | simandl | #print "</pre></BODY></HTML>"; |
| 211 | | | |
| 212 | | | exit |