f-41: watchdog: sessions BGP, L3VNI et routes exportées des VPC routés #41
All checks were successful
Documentation / publish (push) Successful in 1m27s
Release Pipeline / set-release-target (push) Successful in 2s
Release Pipeline / upload-assets (agent.service, systemd/agent.service) (push) Successful in 8s
Release Pipeline / upload-assets (dhcp@.service, systemd/dhcp@.service) (push) Successful in 7s
Release Pipeline / upload-assets (dnsmasq@.service, systemd/dnsmasq@.service) (push) Successful in 7s
Release Pipeline / upload-assets (metadata@.service, systemd/metadata@.service) (push) Successful in 7s
Release Pipeline / upload-assets (run-dhcp-in-netns.sh, scripts/run-dhcp-in-netns.sh) (push) Successful in 7s
Release Pipeline / build (dhcp, amd64, linux) (push) Successful in 0s
Release Pipeline / build (agent, amd64, linux) (push) Successful in 0s
Release Pipeline / build (metadata, amd64, linux) (push) Successful in 0s
Release Pipeline / upload-assets (run-dnsmasq-in-netns.sh, scripts/run-dnsmasq-in-netns.sh) (push) Successful in 7s
Release Pipeline / checksums (push) Successful in 8s
Release Pipeline / release (push) Successful in 28s
Release Pipeline / publish (push) Successful in 0s
Release Pipeline / build (push) Successful in 2m9s

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-11 20:42:01 +02:00
commit 9477dc91d2
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
9 changed files with 653 additions and 1 deletions

49
internal/frr/status.go Normal file
View file

@ -0,0 +1,49 @@
package frr
import (
"fmt"
"net"
"strings"
)
type VNIState struct {
Type string
State string
RouterMAC string
}
func (c *Client) NeighborEstablished(peer net.IP) (bool, error) {
out, err := c.exec("show bgp neighbors " + peer.String())
if err != nil {
return false, err
}
return strings.Contains(out, "BGP state = Established"), nil
}
func (c *Client) VNI(vni uint32) (VNIState, error) {
out, err := c.exec(fmt.Sprintf("show evpn vni %d", vni))
if err != nil {
return VNIState{}, err
}
return parseVNI(out), nil
}
func parseVNI(out string) VNIState {
var s VNIState
for _, l := range strings.Split(out, "\n") {
key, value, ok := strings.Cut(strings.TrimSpace(l), ": ")
if !ok {
continue
}
value = strings.TrimSpace(value)
switch strings.ToLower(key) {
case "type":
s.Type = value
case "state":
s.State = value
case "router mac":
s.RouterMAC = strings.ToLower(value)
}
}
return s
}

View file

@ -0,0 +1,50 @@
package frr
import (
"net"
"strings"
"testing"
)
const vniOutput = `VNI: 2700
Type: L3
Tenant VRF: vrf-s7
Vxlan-Intf: vxl3-s7
SVI-If: brl3-s7
State: Up
VNI Filter: none
System MAC: 02:02:c0:a8:0e:aa
Router MAC: 02:02:C0:A8:0E:0B
L2 VNIs:
`
func TestVNIReadsTypeStateAndRouterMAC(t *testing.T) {
f := &fakeVtysh{fail: map[string]string{"show evpn vni 2700": vniOutput}}
s, err := f.client().VNI(2700)
if err != nil {
t.Fatal(err)
}
want := VNIState{Type: "L3", State: "Up", RouterMAC: "02:02:c0:a8:0e:0b"}
if s != want {
t.Errorf("VNI = %+v, attendu %+v", s, want)
}
}
func TestVNIReportsAnUnknownVNI(t *testing.T) {
f := &fakeVtysh{fail: map[string]string{"show evpn vni 9": "% VNI 9 does not exist\n"}}
if _, err := f.client().VNI(9); err == nil || !strings.Contains(err.Error(), "does not exist") {
t.Errorf("erreur %v", err)
}
}
func TestNeighborEstablished(t *testing.T) {
rr := net.ParseIP("10.255.255.1")
f := &fakeVtysh{fail: map[string]string{"show bgp neighbors 10.255.255.1": "BGP neighbor is 10.255.255.1, remote AS 64600, local AS 64600, internal link\n BGP version 4, remote router ID 10.255.255.1\n BGP state = Established, up for 00:10:02\n"}}
if up, err := f.client().NeighborEstablished(rr); err != nil || !up {
t.Errorf("établie : %v, %v", up, err)
}
f = &fakeVtysh{fail: map[string]string{"show bgp neighbors 10.255.255.1": "BGP neighbor is 10.255.255.1\n BGP state = Active\n"}}
if up, err := f.client().NeighborEstablished(rr); err != nil || up {
t.Errorf("active : %v, %v", up, err)
}
}