]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/SDN/FrrPlugin.pm
don't regenerate frr config if no router is defined
[pve-network.git] / PVE / Network / SDN / FrrPlugin.pm
CommitLineData
32602a38
AD
1package PVE::Network::SDN::FrrPlugin;
2
3use strict;
4use warnings;
5use PVE::Network::SDN::Plugin;
6use PVE::Tools;
7
8use base('PVE::Network::SDN::Plugin');
9
10sub type {
11 return 'frr';
12}
13
14sub properties {
15 return {
16 'asn' => {
17 type => 'integer',
18 description => "autonomous system number",
19 },
20 'peers' => {
21 description => "peers address list.",
7d35eaf5 22 type => 'string', #fixme: format
32602a38
AD
23 },
24 };
25}
26
27sub options {
28
29 return {
30 'uplink-id' => { optional => 0 },
31 'asn' => { optional => 0 },
32 'peers' => { optional => 0 },
33 };
34}
35
36# Plugin implementation
87d8b623
AD
37sub generate_frr_config {
38 my ($class, $plugin_config, $asn, $id, $uplinks, $config) = @_;
32602a38 39
32602a38
AD
40 my @peers = split(',', $plugin_config->{'peers'}) if $plugin_config->{'peers'};
41
42 my $uplink = $plugin_config->{'uplink-id'};
43
32602a38
AD
44 my $iface = "uplink$uplink";
45 my $ifaceip = "";
46
47 if($uplinks->{$uplink}->{name}) {
48 $iface = $uplinks->{$uplink}->{name};
87d8b623 49 $ifaceip = PVE::Network::SDN::Plugin::get_first_local_ipv4_from_interface($iface);
32602a38
AD
50 }
51
93dea3aa
AD
52 my @router_config = ();
53
93dea3aa
AD
54 push @router_config, "bgp router-id $ifaceip";
55 push @router_config, "coalesce-time 1000";
32602a38
AD
56
57 foreach my $address (@peers) {
58 next if $address eq $ifaceip;
93dea3aa 59 push @router_config, "neighbor $address remote-as $asn";
7d35eaf5 60 }
93dea3aa
AD
61 push @router_config, "!";
62 push @router_config, "address-family l2vpn evpn";
32602a38
AD
63 foreach my $address (@peers) {
64 next if $address eq $ifaceip;
93dea3aa 65 push @router_config, " neighbor $address activate";
32602a38 66 }
93dea3aa
AD
67 push @router_config, " advertise-all-vni";
68 push @router_config, "exit-address-family";
32602a38 69
87d8b623 70 push(@{$config->{router}->{"router bgp $asn"}}, @router_config);
32602a38
AD
71
72 return $config;
73}
74
75sub on_delete_hook {
5bda8607 76 my ($class, $routerid, $sdn_cfg) = @_;
32602a38 77
5bda8607
AD
78 # verify that transport is associated to this router
79 foreach my $id (keys %{$sdn_cfg->{ids}}) {
80 my $sdn = $sdn_cfg->{ids}->{$id};
81 die "router $routerid is used by $id"
82 if (defined($sdn->{router}) && $sdn->{router} eq $routerid);
83 }
32602a38
AD
84}
85
86sub on_update_hook {
5bda8607
AD
87 my ($class, $routerid, $sdn_cfg) = @_;
88
89 # verify that asn is not already used by another router
90 my $asn = $sdn_cfg->{ids}->{$routerid}->{asn};
91 foreach my $id (keys %{$sdn_cfg->{ids}}) {
92 next if $id eq $routerid;
93 my $sdn = $sdn_cfg->{ids}->{$id};
94 die "asn $asn is already used by $id"
95 if (defined($sdn->{asn}) && $sdn->{asn} eq $asn);
96 }
32602a38
AD
97}
98
991;
100
101