]> git.sesse.net Git - nms/blob - config/make-port-config.pl
893d4f406c1b6256a8cf71eaec007b70b4ac99d4
[nms] / config / make-port-config.pl
1 #! /usr/bin/perl
2 open PATCHLIST, "<patchlist.txt"
3         or die "patchlist.txt: $!";
4 my %distros = ();
5
6 while (<PATCHLIST>) {
7         chomp;
8         my ($name, $distro, $port) = split / /;
9
10         $name =~ /e(\d+)-(\d+)/;
11         my ($row, $switch) = ($1, $2);
12
13         my $ip;
14         if ($switch == 1) {
15                 $ip = "87.76." . ($row) . ".1";
16         } elsif ($switch == 2) {
17                 $ip = "87.76." . ($row) . ".65";
18         } elsif ($switch == 3) {
19                 $ip = "87.76." . ($row) . ".129";
20         } elsif ($switch == 4) {
21                 $ip = "87.76." . ($row + 1) . ".1";
22         } elsif ($switch == 5) {
23                 $ip = "87.76." . ($row + 1) . ".65";
24         } elsif ($switch == 6) {
25                 $ip = "87.76." . ($row + 1) . ".129";
26         }
27
28         my $vlan = "$row$switch";
29         my $ipv6 = sprintf "F%02u%u", $row, $switch;
30
31         $distros{$distro} .= <<"EOF";
32 vlan $vlan
33   name $name
34 !
35 default interface vlan $vlan
36 interface vlan $vlan
37   description $name
38   ip address $ip 255.255.255.192
39   ip directed-broadcast 10
40   ip helper-address 87.76.254.2
41   no ip proxy-arp
42   ip access-group great-wall-of-tg in
43   ipv6 address 2001:16D8:FFFF:${ipv6}::1/64
44   ip igmp version 3
45   ip pim sparse-mode
46   no shutdown
47 !
48  
49 default interface $port
50 interface $port
51  description $name
52  switchport mode access
53  switchport access vlan $vlan
54
55  spanning-tree portfast
56  spanning-tree bpduguard enable
57
58  storm-control broadcast level 2
59  no shutdown
60 !
61 EOF
62 }
63
64 for my $distro (keys %distros) {
65         open DISTRO, ">$distro-config"
66                 or die "$distro-config: $!";
67         print DISTRO $distros{$distro};
68         print DISTRO "end\n";
69         close DISTRO;
70 }