]>
Commit | Line | Data |
---|---|---|
32602a38 AD |
1 | package PVE::Network::SDN::FrrPlugin; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use PVE::Network::SDN::Plugin; | |
6 | use PVE::Tools; | |
7 | ||
8 | use base('PVE::Network::SDN::Plugin'); | |
9 | ||
10 | sub type { | |
11 | return 'frr'; | |
12 | } | |
13 | ||
14 | sub properties { | |
15 | return { | |
16 | 'asn' => { | |
17 | type => 'integer', | |
18 | description => "autonomous system number", | |
19 | }, | |
20 | 'peers' => { | |
21 | description => "peers address list.", | |
22 | type => 'string', #fixme: format | |
23 | }, | |
24 | }; | |
25 | } | |
26 | ||
27 | sub options { | |
28 | ||
29 | return { | |
30 | 'uplink-id' => { optional => 0 }, | |
31 | 'asn' => { optional => 0 }, | |
32 | 'peers' => { optional => 0 }, | |
33 | }; | |
34 | } | |
35 | ||
36 | # Plugin implementation | |
93dea3aa AD |
37 | sub generate_sdn_config { |
38 | my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_; | |
32602a38 AD |
39 | |
40 | my $asn = $plugin_config->{'asn'}; | |
41 | my @peers = split(',', $plugin_config->{'peers'}) if $plugin_config->{'peers'}; | |
42 | ||
43 | my $uplink = $plugin_config->{'uplink-id'}; | |
44 | ||
45 | die "missing peers" if !$plugin_config->{'peers'}; | |
46 | ||
47 | my $iface = "uplink$uplink"; | |
48 | my $ifaceip = ""; | |
49 | ||
50 | if($uplinks->{$uplink}->{name}) { | |
51 | $iface = $uplinks->{$uplink}->{name}; | |
52 | $ifaceip = get_first_local_ipv4_from_interface($iface); | |
53 | } | |
54 | ||
93dea3aa AD |
55 | my @router_config = (); |
56 | ||
57 | push @router_config, "router bgp $asn"; | |
58 | push @router_config, "bgp router-id $ifaceip"; | |
59 | push @router_config, "coalesce-time 1000"; | |
32602a38 AD |
60 | |
61 | foreach my $address (@peers) { | |
62 | next if $address eq $ifaceip; | |
93dea3aa | 63 | push @router_config, "neighbor $address remote-as $asn"; |
32602a38 | 64 | } |
93dea3aa AD |
65 | push @router_config, "!"; |
66 | push @router_config, "address-family l2vpn evpn"; | |
32602a38 AD |
67 | foreach my $address (@peers) { |
68 | next if $address eq $ifaceip; | |
93dea3aa | 69 | push @router_config, " neighbor $address activate"; |
32602a38 | 70 | } |
93dea3aa AD |
71 | push @router_config, " advertise-all-vni"; |
72 | push @router_config, "exit-address-family"; | |
73 | push @router_config, "!"; | |
74 | push @router_config, "line vty"; | |
75 | push @router_config, "!"; | |
32602a38 | 76 | |
93dea3aa | 77 | push(@{$config->{frr}->{$asn}}, @router_config); |
32602a38 AD |
78 | |
79 | return $config; | |
80 | } | |
81 | ||
82 | sub on_delete_hook { | |
83 | my ($class, $transportid, $sdn_cfg) = @_; | |
84 | ||
85 | } | |
86 | ||
87 | sub on_update_hook { | |
88 | my ($class, $transportid, $sdn_cfg) = @_; | |
89 | ||
90 | } | |
91 | ||
92 | 1; | |
93 | ||
94 |