mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
Merge pull request #2075 from akvorado/feature/gobgp4
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
Update Nix dependency hashes / Update dependency hashes (push) Has been cancelled
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
Update Nix dependency hashes / Update dependency hashes (push) Has been cancelled
Switch to GoBGP v4
This commit is contained in:
@@ -9,11 +9,12 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"net/netip"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bmp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bmp"
|
||||
)
|
||||
|
||||
// startBMPClient starts the BMP client
|
||||
@@ -31,9 +32,9 @@ func (c *Component) startBMPClient(ctx context.Context) {
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
peerHeader := bmp.NewBMPPeerHeader(
|
||||
bmp.BMP_PEER_TYPE_GLOBAL, 0, 0,
|
||||
c.config.PeerIP.Unmap().String(),
|
||||
c.config.PeerIP,
|
||||
uint32(c.config.PeerASN),
|
||||
"2.2.2.2",
|
||||
netip.MustParseAddr("2.2.2.2"),
|
||||
0)
|
||||
pkt, err := bmp.NewBMPInitiation([]bmp.BMPInfoTLVInterface{
|
||||
bmp.NewBMPInfoTLVString(bmp.BMP_INIT_TLV_TYPE_SYS_DESCR, "Fake exporter"),
|
||||
@@ -43,23 +44,31 @@ func (c *Component) startBMPClient(ctx context.Context) {
|
||||
panic(err)
|
||||
}
|
||||
buf.Write(pkt)
|
||||
pkt, err = bmp.NewBMPPeerUpNotification(*peerHeader, c.config.LocalIP.Unmap().String(), 179, 47647,
|
||||
bgp.NewBGPOpenMessage(c.config.LocalASN, 30, "1.1.1.1",
|
||||
[]bgp.OptionParameterInterface{
|
||||
bgp.NewOptionParameterCapability([]bgp.ParameterCapabilityInterface{
|
||||
bgp.NewCapMultiProtocol(bgp.RF_IPv4_UC),
|
||||
bgp.NewCapMultiProtocol(bgp.RF_IPv6_UC),
|
||||
}),
|
||||
},
|
||||
),
|
||||
bgp.NewBGPOpenMessage(c.config.PeerASN, 30, "2.2.2.2",
|
||||
[]bgp.OptionParameterInterface{
|
||||
bgp.NewOptionParameterCapability([]bgp.ParameterCapabilityInterface{
|
||||
bgp.NewCapMultiProtocol(bgp.RF_IPv4_UC),
|
||||
bgp.NewCapMultiProtocol(bgp.RF_IPv6_UC),
|
||||
}),
|
||||
},
|
||||
),
|
||||
om1, err := bgp.NewBGPOpenMessage(c.config.LocalASN, 30, netip.MustParseAddr("1.1.1.1"),
|
||||
[]bgp.OptionParameterInterface{
|
||||
bgp.NewOptionParameterCapability([]bgp.ParameterCapabilityInterface{
|
||||
bgp.NewCapMultiProtocol(bgp.RF_IPv4_UC),
|
||||
bgp.NewCapMultiProtocol(bgp.RF_IPv6_UC),
|
||||
}),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
om2, err := bgp.NewBGPOpenMessage(c.config.PeerASN, 30, netip.MustParseAddr("2.2.2.2"),
|
||||
[]bgp.OptionParameterInterface{
|
||||
bgp.NewOptionParameterCapability([]bgp.ParameterCapabilityInterface{
|
||||
bgp.NewCapMultiProtocol(bgp.RF_IPv4_UC),
|
||||
bgp.NewCapMultiProtocol(bgp.RF_IPv6_UC),
|
||||
}),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
pkt, err = bmp.NewBMPPeerUpNotification(*peerHeader, c.config.LocalIP, 179, 47647,
|
||||
om1,
|
||||
om2,
|
||||
).Serialize()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -67,28 +76,41 @@ func (c *Component) startBMPClient(ctx context.Context) {
|
||||
buf.Write(pkt)
|
||||
|
||||
// Send the routes
|
||||
for _, af := range []bgp.RouteFamily{bgp.RF_IPv4_UC, bgp.RF_IPv6_UC} {
|
||||
for _, af := range []bgp.Family{bgp.RF_IPv4_UC, bgp.RF_IPv6_UC} {
|
||||
var nh netip.Addr
|
||||
if af == bgp.RF_IPv4_UC {
|
||||
nh = netip.MustParseAddr("192.0.2.1")
|
||||
} else {
|
||||
nh = netip.MustParseAddr("fe80::1")
|
||||
}
|
||||
for _, route := range c.config.Routes {
|
||||
prefixes := []bgp.AddrPrefixInterface{}
|
||||
prefixes := []bgp.PathNLRI{}
|
||||
|
||||
for _, prefix := range route.Prefixes {
|
||||
if af == bgp.RF_IPv4_UC && prefix.Addr().Is4() {
|
||||
prefixes = append(prefixes,
|
||||
bgp.NewIPAddrPrefix(uint8(prefix.Bits()), prefix.Addr().String()))
|
||||
} else if af == bgp.RF_IPv6_UC && prefix.Addr().Is6() {
|
||||
prefixes = append(prefixes,
|
||||
bgp.NewIPv6AddrPrefix(uint8(prefix.Bits()), prefix.Addr().String()))
|
||||
if af == bgp.RF_IPv4_UC && prefix.Addr().Is4() || af == bgp.RF_IPv6_UC && prefix.Addr().Is6() {
|
||||
n, err := bgp.NewIPAddrPrefix(prefix)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
prefixes = append(prefixes, bgp.PathNLRI{
|
||||
NLRI: n,
|
||||
})
|
||||
}
|
||||
}
|
||||
if len(prefixes) == 0 {
|
||||
continue
|
||||
}
|
||||
nlri, err := bgp.NewPathAttributeMpReachNLRI(af, prefixes, nh)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
attrs := []bgp.PathAttributeInterface{
|
||||
// bgp.NewPathAttributeNextHop("192.0.2.20"),
|
||||
bgp.NewPathAttributeOrigin(1),
|
||||
bgp.NewPathAttributeAsPath([]bgp.AsPathParamInterface{
|
||||
bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, route.ASPath),
|
||||
}),
|
||||
bgp.NewPathAttributeMpReachNLRI("fe80::1", prefixes),
|
||||
nlri,
|
||||
}
|
||||
if route.Communities != nil {
|
||||
comms := make([]uint32, len(route.Communities))
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
gobmp "github.com/osrg/gobgp/v3/pkg/packet/bmp"
|
||||
gobmp "github.com/osrg/gobgp/v4/pkg/packet/bmp"
|
||||
|
||||
"akvorado/common/daemon"
|
||||
"akvorado/common/helpers"
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bgp"
|
||||
)
|
||||
|
||||
// Configuration describes the configuration for the BMP component. Only one peer is emulated.
|
||||
|
||||
6
go.mod
6
go.mod
@@ -37,7 +37,8 @@ require (
|
||||
github.com/openconfig/gnmic/pkg/api v0.1.9
|
||||
github.com/opencontainers/image-spec v1.1.1
|
||||
github.com/oschwald/maxminddb-golang/v2 v2.0.0
|
||||
github.com/osrg/gobgp/v3 v3.37.0
|
||||
github.com/osrg/gobgp/v4 v4.0.0
|
||||
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10
|
||||
github.com/prometheus/client_golang v1.23.2
|
||||
github.com/rs/zerolog v1.34.0
|
||||
github.com/scrapli/scrapligo v1.3.3
|
||||
@@ -123,7 +124,7 @@ require (
|
||||
github.com/jackc/pgx/v5 v5.6.0 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
github.com/jellydator/ttlcache/v2 v2.11.1 // indirect
|
||||
github.com/jessevdk/go-flags v1.5.0 // indirect
|
||||
github.com/jessevdk/go-flags v1.6.1 // indirect
|
||||
github.com/jhump/protoreflect v1.17.0 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
@@ -151,7 +152,6 @@ require (
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/pierrec/lz4/v4 v4.1.22 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
||||
github.com/prometheus/client_model v0.6.2 // indirect
|
||||
|
||||
17
go.sum
17
go.sum
@@ -157,8 +157,8 @@ github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq
|
||||
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||
github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg=
|
||||
github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
|
||||
github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U=
|
||||
github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
|
||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||
@@ -235,8 +235,8 @@ github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFr
|
||||
github.com/jellydator/ttlcache/v2 v2.11.1 h1:AZGME43Eh2Vv3giG6GeqeLeFXxwxn1/qHItqWZl6U64=
|
||||
github.com/jellydator/ttlcache/v2 v2.11.1/go.mod h1:RtE5Snf0/57e+2cLWFYWCCsLas2Hy3c5Z4n14XmSvTI=
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
|
||||
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
|
||||
github.com/jessevdk/go-flags v1.6.1 h1:Cvu5U8UGrLay1rZfv/zP7iLpSHGUZ/Ou68T0iX1bBK4=
|
||||
github.com/jessevdk/go-flags v1.6.1/go.mod h1:Mk8T1hIAWpOiJiHa9rJASDK2UGWji0EuPGBnNLMooyc=
|
||||
github.com/jhump/protoreflect v1.17.0 h1:qOEr613fac2lOuTgWN4tPAtLL7fUSbuJL5X5XumQh94=
|
||||
github.com/jhump/protoreflect v1.17.0/go.mod h1:h9+vUUL38jiBzck8ck+6G/aeMX8Z4QUY/NiJPwPNi+8=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
@@ -336,8 +336,8 @@ github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJw
|
||||
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
|
||||
github.com/oschwald/maxminddb-golang/v2 v2.0.0 h1:Gyljxck1kHbBxDgLM++NfDWBqvu1pWWfT8XbosSo0bo=
|
||||
github.com/oschwald/maxminddb-golang/v2 v2.0.0/go.mod h1:gG4V88LsawPEqtbL1Veh1WRh+nVSYwXzJ1P5Fcn77g0=
|
||||
github.com/osrg/gobgp/v3 v3.37.0 h1:+ObuOdvj7G7nxrT0fKFta+EAupdWf/q1WzbXydr8IOY=
|
||||
github.com/osrg/gobgp/v3 v3.37.0/go.mod h1:kVHVFy1/fyZHJ8P32+ctvPeJogn9qKwa1YCeMRXXrP0=
|
||||
github.com/osrg/gobgp/v4 v4.0.0 h1:DCL7iWUAPgL/DDBp1FSdkayQ0ptYYkucpuMkre+HGaI=
|
||||
github.com/osrg/gobgp/v4 v4.0.0/go.mod h1:1a0YiXMuyRPqcCX+fkXZ2UUtcOnUxAWynFunUOSZepk=
|
||||
github.com/pascaldekloe/name v1.0.1 h1:9lnXOHeqeHHnWLbKfH6X98+4+ETVqFqxN09UXSjcMb0=
|
||||
github.com/pascaldekloe/name v1.0.1/go.mod h1:Z//MfYJnH4jVpQ9wkclwu2I2MkHmXTlT9wR5UZScttM=
|
||||
github.com/paulmach/orb v0.11.1 h1:3koVegMC4X/WeiXYz9iswopaTwMem53NzTJuTF20JzU=
|
||||
@@ -450,8 +450,8 @@ github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLY
|
||||
github.com/ugorji/go/codec v1.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA=
|
||||
github.com/ugorji/go/codec v1.3.0/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
|
||||
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
|
||||
github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8=
|
||||
github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
|
||||
github.com/vishvananda/netns v0.0.5 h1:DfiHV+j8bA32MFM7bfEunvT8IAqQ/NzSJHtcmW5zdEY=
|
||||
github.com/vishvananda/netns v0.0.5/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
|
||||
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
|
||||
@@ -571,7 +571,6 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
bnet "github.com/bio-routing/bio-rd/net"
|
||||
rpb "github.com/bio-routing/bio-rd/route/api"
|
||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bgp"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/backoff"
|
||||
"google.golang.org/grpc/connectivity"
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
bnet "github.com/bio-routing/bio-rd/net"
|
||||
"github.com/bio-routing/bio-rd/protocols/bgp/server"
|
||||
rpb "github.com/bio-routing/bio-rd/route/api"
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bgp"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/reflection"
|
||||
|
||||
@@ -9,8 +9,10 @@ import (
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bmp"
|
||||
"akvorado/common/helpers"
|
||||
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bmp"
|
||||
)
|
||||
|
||||
// peerKey is the key used to identify a peer
|
||||
@@ -32,14 +34,13 @@ type peerInfo struct {
|
||||
|
||||
// peerKeyFromBMPPeerHeader computes the peer key from the BMP peer header.
|
||||
func peerKeyFromBMPPeerHeader(exporter netip.AddrPort, header *bmp.BMPPeerHeader) peerKey {
|
||||
peer, _ := netip.AddrFromSlice(header.PeerAddress.To16())
|
||||
return peerKey{
|
||||
exporter: exporter,
|
||||
ip: peer,
|
||||
ip: header.PeerAddress,
|
||||
ptype: header.PeerType,
|
||||
distinguisher: RD(header.PeerDistinguisher),
|
||||
asn: header.PeerAS,
|
||||
bgpID: binary.BigEndian.Uint32(header.PeerBGPID.To4()),
|
||||
bgpID: binary.BigEndian.Uint32(header.PeerBGPID.AsSlice()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,7 +179,7 @@ func (p *Provider) handlePeerUpNotification(pkey peerKey, body *bmp.BMPPeerUpNot
|
||||
}
|
||||
|
||||
// Check for ADD-PATH support.
|
||||
receivedAddPath := map[bgp.RouteFamily]bgp.BGPAddPathMode{}
|
||||
receivedAddPath := map[bgp.Family]bgp.BGPAddPathMode{}
|
||||
received, _ := body.ReceivedOpenMsg.Body.(*bgp.BGPOpen)
|
||||
for _, param := range received.OptParams {
|
||||
switch param := param.(type) {
|
||||
@@ -187,14 +188,14 @@ func (p *Provider) handlePeerUpNotification(pkey peerKey, body *bmp.BMPPeerUpNot
|
||||
switch capability := capability.(type) {
|
||||
case *bgp.CapAddPath:
|
||||
for _, tuple := range capability.Tuples {
|
||||
receivedAddPath[tuple.RouteFamily] = tuple.Mode
|
||||
receivedAddPath[tuple.Family] = tuple.Mode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sent, _ := body.SentOpenMsg.Body.(*bgp.BGPOpen)
|
||||
addPathOption := map[bgp.RouteFamily]bgp.BGPAddPathMode{}
|
||||
addPathOption := map[bgp.Family]bgp.BGPAddPathMode{}
|
||||
for _, param := range sent.OptParams {
|
||||
switch param := param.(type) {
|
||||
case *bgp.OptionParameterCapability:
|
||||
@@ -202,11 +203,11 @@ func (p *Provider) handlePeerUpNotification(pkey peerKey, body *bmp.BMPPeerUpNot
|
||||
switch capability := capability.(type) {
|
||||
case *bgp.CapAddPath:
|
||||
for _, sent := range capability.Tuples {
|
||||
receivedMode := receivedAddPath[sent.RouteFamily]
|
||||
receivedMode := receivedAddPath[sent.Family]
|
||||
if receivedMode == bgp.BGP_ADD_PATH_BOTH || receivedMode == bgp.BGP_ADD_PATH_SEND {
|
||||
if sent.Mode == bgp.BGP_ADD_PATH_BOTH || sent.Mode == bgp.BGP_ADD_PATH_RECEIVE {
|
||||
// We have at least the receive mode. We only do decoding.
|
||||
addPathOption[sent.RouteFamily] = bgp.BGP_ADD_PATH_RECEIVE
|
||||
addPathOption[sent.Family] = bgp.BGP_ADD_PATH_RECEIVE
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,7 +257,7 @@ func (p *Provider) handleRouteMonitoring(pkey peerKey, body *bmp.BMPRouteMonitor
|
||||
for _, attr := range update.PathAttributes {
|
||||
switch attr := attr.(type) {
|
||||
case *bgp.PathAttributeNextHop:
|
||||
nh, _ = netip.AddrFromSlice(attr.Value.To16())
|
||||
nh = helpers.AddrTo6(attr.Value)
|
||||
case *bgp.PathAttributeAsPath:
|
||||
if p.config.CollectASNs || p.config.CollectASPaths {
|
||||
rta.asPath = asPathFlat(attr)
|
||||
@@ -292,40 +293,37 @@ func (p *Provider) handleRouteMonitoring(pkey peerKey, body *bmp.BMPRouteMonitor
|
||||
|
||||
// Regular NLRI and withdrawn routes
|
||||
if pkey.ptype == bmp.BMP_PEER_TYPE_L3VPN || p.isAcceptedRD(0) {
|
||||
for _, ipprefix := range update.NLRI {
|
||||
prefix := ipprefix.Prefix
|
||||
plen := int(ipprefix.Length)
|
||||
if prefix.To4() != nil {
|
||||
prefix = prefix.To16()
|
||||
plen += 96
|
||||
// We know we have IPv4 NLRI
|
||||
for _, path := range update.NLRI {
|
||||
v4UCPrefix, ok := path.NLRI.(*bgp.IPAddrPrefix)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
pf, _ := netip.AddrFromSlice(prefix)
|
||||
added += p.rib.AddPrefix(netip.PrefixFrom(pf, plen), route{
|
||||
pfx := helpers.PrefixTo6(v4UCPrefix.Prefix)
|
||||
added += p.rib.AddPrefix(pfx, route{
|
||||
peer: pinfo.reference,
|
||||
nlri: p.rib.nlris.Put(nlri{
|
||||
family: bgp.RF_IPv4_UC,
|
||||
path: ipprefix.PathIdentifier(),
|
||||
path: path.ID,
|
||||
rd: pkey.distinguisher,
|
||||
}),
|
||||
nextHop: p.rib.nextHops.Put(nextHop(nh)),
|
||||
attributes: p.rib.rtas.Put(rta),
|
||||
prefixLen: uint8(plen),
|
||||
prefixLen: uint8(pfx.Bits()),
|
||||
})
|
||||
}
|
||||
for _, ipprefix := range update.WithdrawnRoutes {
|
||||
prefix := ipprefix.Prefix
|
||||
plen := int(ipprefix.Length)
|
||||
if prefix.To4() != nil {
|
||||
prefix = prefix.To16()
|
||||
plen += 96
|
||||
for _, path := range update.WithdrawnRoutes {
|
||||
v4UCPrefix, ok := path.NLRI.(*bgp.IPAddrPrefix)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
pf, _ := netip.AddrFromSlice(prefix)
|
||||
pfx := helpers.PrefixTo6(v4UCPrefix.Prefix)
|
||||
if nlriRef, ok := p.rib.nlris.Ref(nlri{
|
||||
family: bgp.RF_IPv4_UC,
|
||||
path: ipprefix.PathIdentifier(),
|
||||
path: path.ID,
|
||||
rd: pkey.distinguisher,
|
||||
}); ok {
|
||||
removed += p.rib.RemovePrefix(netip.PrefixFrom(pf, plen), route{
|
||||
removed += p.rib.RemovePrefix(pfx, route{
|
||||
peer: pinfo.reference,
|
||||
nlri: nlriRef,
|
||||
})
|
||||
@@ -335,58 +333,38 @@ func (p *Provider) handleRouteMonitoring(pkey peerKey, body *bmp.BMPRouteMonitor
|
||||
|
||||
// MP reach and unreach NLRI
|
||||
for _, attr := range update.PathAttributes {
|
||||
var pf netip.Addr
|
||||
var plen int
|
||||
var rd RD
|
||||
var ipprefixes []bgp.AddrPrefixInterface
|
||||
var paths []bgp.PathNLRI
|
||||
var family bgp.Family
|
||||
switch attr := attr.(type) {
|
||||
case *bgp.PathAttributeMpReachNLRI:
|
||||
nh, _ = netip.AddrFromSlice(attr.Nexthop.To16())
|
||||
ipprefixes = attr.Value
|
||||
nh = helpers.AddrTo6(attr.Nexthop)
|
||||
paths = attr.Value
|
||||
family = bgp.NewFamily(attr.AFI, attr.SAFI)
|
||||
case *bgp.PathAttributeMpUnreachNLRI:
|
||||
ipprefixes = attr.Value
|
||||
paths = attr.Value
|
||||
family = bgp.NewFamily(attr.AFI, attr.SAFI)
|
||||
}
|
||||
for _, ipprefix := range ipprefixes {
|
||||
switch ipprefix := ipprefix.(type) {
|
||||
for _, path := range paths {
|
||||
var pfx netip.Prefix
|
||||
var rd RD
|
||||
switch nlri := path.NLRI.(type) {
|
||||
case *bgp.IPAddrPrefix:
|
||||
pf, _ = netip.AddrFromSlice(ipprefix.Prefix.To16())
|
||||
plen = int(ipprefix.Length + 96)
|
||||
rd = pkey.distinguisher
|
||||
case *bgp.IPv6AddrPrefix:
|
||||
pf, _ = netip.AddrFromSlice(ipprefix.Prefix.To16())
|
||||
plen = int(ipprefix.Length)
|
||||
pfx = helpers.PrefixTo6(nlri.Prefix)
|
||||
rd = pkey.distinguisher
|
||||
case *bgp.LabeledIPAddrPrefix:
|
||||
pf, _ = netip.AddrFromSlice(ipprefix.Prefix.To16())
|
||||
plen = int(ipprefix.IPPrefixLen() + 96)
|
||||
rd = pkey.distinguisher
|
||||
case *bgp.LabeledIPv6AddrPrefix:
|
||||
pf, _ = netip.AddrFromSlice(ipprefix.Prefix.To16())
|
||||
plen = int(ipprefix.IPPrefixLen())
|
||||
pfx = helpers.PrefixTo6(nlri.Prefix)
|
||||
rd = pkey.distinguisher
|
||||
case *bgp.LabeledVPNIPAddrPrefix:
|
||||
pf, _ = netip.AddrFromSlice(ipprefix.Prefix.To16())
|
||||
plen = int(ipprefix.IPPrefixLen() + 96)
|
||||
rd = RDFromRouteDistinguisherInterface(ipprefix.RD)
|
||||
case *bgp.LabeledVPNIPv6AddrPrefix:
|
||||
pf, _ = netip.AddrFromSlice(ipprefix.Prefix.To16())
|
||||
plen = int(ipprefix.IPPrefixLen())
|
||||
rd = RDFromRouteDistinguisherInterface(ipprefix.RD)
|
||||
pfx = helpers.PrefixTo6(nlri.Prefix)
|
||||
rd = RDFromRouteDistinguisherInterface(nlri.RD)
|
||||
case *bgp.EVPNNLRI:
|
||||
switch route := ipprefix.RouteTypeData.(type) {
|
||||
switch route := nlri.RouteTypeData.(type) {
|
||||
case *bgp.EVPNIPPrefixRoute:
|
||||
prefix := route.IPPrefix
|
||||
plen = int(route.IPPrefixLength)
|
||||
if prefix.To4() != nil {
|
||||
prefix = prefix.To16()
|
||||
plen += 96
|
||||
}
|
||||
pf, _ = netip.AddrFromSlice(prefix.To16())
|
||||
pfx = helpers.PrefixTo6(netip.PrefixFrom(route.IPPrefix, int(route.IPPrefixLength)))
|
||||
rd = RDFromRouteDistinguisherInterface(route.RD)
|
||||
}
|
||||
default:
|
||||
p.metrics.ignoredNlri.WithLabelValues(exporterStr,
|
||||
bgp.AfiSafiToRouteFamily(ipprefix.AFI(), ipprefix.SAFI()).String()).Inc()
|
||||
p.metrics.ignoredNlri.WithLabelValues(exporterStr, family.String()).Inc()
|
||||
continue
|
||||
}
|
||||
if pkey.ptype != bmp.BMP_PEER_TYPE_L3VPN && !p.isAcceptedRD(rd) {
|
||||
@@ -394,24 +372,24 @@ func (p *Provider) handleRouteMonitoring(pkey peerKey, body *bmp.BMPRouteMonitor
|
||||
}
|
||||
switch attr.(type) {
|
||||
case *bgp.PathAttributeMpReachNLRI:
|
||||
added += p.rib.AddPrefix(netip.PrefixFrom(pf, plen), route{
|
||||
added += p.rib.AddPrefix(pfx, route{
|
||||
peer: pinfo.reference,
|
||||
nlri: p.rib.nlris.Put(nlri{
|
||||
family: bgp.AfiSafiToRouteFamily(ipprefix.AFI(), ipprefix.SAFI()),
|
||||
family: family,
|
||||
rd: rd,
|
||||
path: ipprefix.PathIdentifier(),
|
||||
path: path.ID,
|
||||
}),
|
||||
nextHop: p.rib.nextHops.Put(nextHop(nh)),
|
||||
attributes: p.rib.rtas.Put(rta),
|
||||
prefixLen: uint8(plen),
|
||||
prefixLen: uint8(pfx.Bits()),
|
||||
})
|
||||
case *bgp.PathAttributeMpUnreachNLRI:
|
||||
if nlriRef, ok := p.rib.nlris.Ref(nlri{
|
||||
family: bgp.AfiSafiToRouteFamily(ipprefix.AFI(), ipprefix.SAFI()),
|
||||
family: family,
|
||||
rd: rd,
|
||||
path: ipprefix.PathIdentifier(),
|
||||
path: path.ID,
|
||||
}); ok {
|
||||
removed += p.rib.RemovePrefix(netip.PrefixFrom(pf, plen), route{
|
||||
removed += p.rib.RemovePrefix(pfx, route{
|
||||
peer: pinfo.reference,
|
||||
nlri: nlriRef,
|
||||
})
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
"akvorado/common/helpers"
|
||||
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bgp"
|
||||
)
|
||||
|
||||
var asPathCache [][]uint32
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bgp"
|
||||
)
|
||||
|
||||
// RD defines a route distinguisher.
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
package bmp_test
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"testing"
|
||||
|
||||
"akvorado/common/helpers"
|
||||
"akvorado/outlet/routing/provider/bmp"
|
||||
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bgp"
|
||||
)
|
||||
|
||||
func TestParseRouteDistinguisher(t *testing.T) {
|
||||
@@ -70,7 +71,13 @@ func TestRDFromRouteDistinguisherInterface(t *testing.T) {
|
||||
{bgp.NewRouteDistinguisherFourOctetAS(100, 200), "2:100:200"},
|
||||
{bgp.NewRouteDistinguisherFourOctetAS(66000, 200), "66000:200"},
|
||||
{bgp.NewRouteDistinguisherTwoOctetAS(120, 200), "120:200"},
|
||||
{bgp.NewRouteDistinguisherIPAddressAS("2.2.2.2", 30), "2.2.2.2:30"},
|
||||
{func() bgp.RouteDistinguisherInterface {
|
||||
rd, err := bgp.NewRouteDistinguisherIPAddressAS(netip.MustParseAddr("2.2.2.2"), 30)
|
||||
if err != nil {
|
||||
t.Fatalf("bgp.NewRouteDistinguisherIPAddressAS() error:\n%+v", err)
|
||||
}
|
||||
return rd
|
||||
}(), "2.2.2.2:30"},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
got := bmp.RDFromRouteDistinguisherInterface(tc.input).String()
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"akvorado/common/helpers/intern"
|
||||
|
||||
"github.com/gaissmai/bart"
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bgp"
|
||||
)
|
||||
|
||||
// prefixIndex is a typed index for prefixes in the RIB
|
||||
@@ -49,7 +49,7 @@ type route struct {
|
||||
// nlri is the NLRI for the route (when combined with prefix). The
|
||||
// route family is included as we may normalize NLRI accross AFI/SAFI.
|
||||
type nlri struct {
|
||||
family bgp.RouteFamily
|
||||
family bgp.Family
|
||||
path uint32
|
||||
rd RD
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
"akvorado/common/helpers"
|
||||
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bgp"
|
||||
)
|
||||
|
||||
func TestLargeCommunitiesAlign(t *testing.T) {
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"akvorado/common/reporter"
|
||||
"akvorado/outlet/routing/provider"
|
||||
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bgp"
|
||||
)
|
||||
|
||||
func TestBMP(t *testing.T) {
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bmp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bmp"
|
||||
)
|
||||
|
||||
// serveConnection handle the connection from an exporter.
|
||||
|
||||
@@ -17,8 +17,8 @@ import (
|
||||
|
||||
"github.com/benbjohnson/clock"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bmp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bmp"
|
||||
)
|
||||
|
||||
// NewMock creates a new mock provider for BMP (it's a real one
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
package bmp
|
||||
|
||||
import "github.com/osrg/gobgp/v3/pkg/packet/bgp"
|
||||
import "github.com/osrg/gobgp/v4/pkg/packet/bgp"
|
||||
|
||||
// asPathFlat transforms an AS path to a flat AS path: first value of
|
||||
// a set is used, confed seq is considered as a regular seq.
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"akvorado/common/helpers"
|
||||
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bgp"
|
||||
)
|
||||
|
||||
func TestASPathFlat(t *testing.T) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"akvorado/common/reporter"
|
||||
|
||||
"github.com/benbjohnson/clock"
|
||||
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/v4/pkg/packet/bgp"
|
||||
)
|
||||
|
||||
// LookupResult is the result of the Lookup() function.
|
||||
|
||||
Reference in New Issue
Block a user