jablonka.czprosek.czf

netmap

Subversion Repositories:
[/] [connection/] [gen_ospf_config.pl] - Blame information for rev 71

 

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

Powered by WebSVN 2.2.1