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