diff --git a/apps/bmp-streamer/client/main.go b/apps/bmp-streamer/client/main.go index 05fdadc5ed9ad7d41d4a0e43aa8b2f3da3862462..55a8aad753da6f12f45dfa8e2bd81989fa81623e 100644 --- a/apps/bmp-streamer/client/main.go +++ b/apps/bmp-streamer/client/main.go @@ -31,9 +31,9 @@ func main() { c := pb.NewRIBServiceClient(conn) streamClient, err := c.AdjRIBInStream(context.Background(), &pb.AdjRIBInStreamRequest{ Router: &netapi.IP{ - Higher: rtr.Higher(), - Lower: rtr.Lower(), - IsLegacy: true, + Higher: rtr.Higher(), + Lower: rtr.Lower(), + Version: netapi.IP_IPv4, }, }) diff --git a/apps/bmp-streamer/pkg/apiserver/server.go b/apps/bmp-streamer/pkg/apiserver/server.go index b4dd11477a8062c63f4f4fefacc9cf55588d98aa..0fe16ff0e186893eef49fcc3064c1f725236fb9b 100644 --- a/apps/bmp-streamer/pkg/apiserver/server.go +++ b/apps/bmp-streamer/pkg/apiserver/server.go @@ -5,6 +5,7 @@ import ( pb "github.com/bio-routing/bio-rd/apps/bmp-streamer/pkg/bmpstreamer" net "github.com/bio-routing/bio-rd/net" + netapi "github.com/bio-routing/bio-rd/net/api" "github.com/bio-routing/bio-rd/protocols/bgp/packet" "github.com/bio-routing/bio-rd/protocols/bgp/server" "github.com/bio-routing/bio-rd/route" @@ -39,10 +40,12 @@ func (a *APIServer) AdjRIBInStream(req *pb.AdjRIBInStreamRequest, stream pb.RIBS r6 := newRIBClient() addr := net.IP{} - if req.Router.IsLegacy { + if req.Router.Version == netapi.IP_IPv4 { addr = net.IPv4(uint32(req.Router.Lower)) - } else { + } else if req.Router.Version == netapi.IP_IPv6 { addr = net.IPv6(req.Router.Higher, req.Router.Lower) + } else { + return fmt.Errorf("Unknown protocol") } ret := make(chan error) diff --git a/net/api/net.proto b/net/api/net.proto index 650789c431e299a85c21a585f05f6e2a141cb2c7..1583a2075b7b539117157419a1823c210d69883a 100644 --- a/net/api/net.proto +++ b/net/api/net.proto @@ -10,5 +10,9 @@ message Prefix { message IP { uint64 higher = 1; uint64 lower = 2; - bool is_legacy = 3; + enum Version { + IPv4 = 0; + IPv6 = 1; + } + Version version = 3; } diff --git a/net/ip.go b/net/ip.go index dbf17fe3d44f5f4d0c7868995d0fff36e3e7260f..e9dc9773c90ceace8795cc78c9db62e5bc53308e 100644 --- a/net/ip.go +++ b/net/ip.go @@ -4,7 +4,7 @@ import ( "fmt" "net" - "github.com/bio-routing/bio-rd/net/api" + api "github.com/bio-routing/bio-rd/net/api" ) // IP represents an IPv4 or IPv6 address @@ -19,16 +19,21 @@ func IPFromProtoIP(addr api.IP) IP { return IP{ higher: addr.Higher, lower: addr.Lower, - isLegacy: addr.IsLegacy, + isLegacy: addr.Version == api.IP_IPv4, } } // ToProto converts an IP to a proto IP func (ip IP) ToProto() *api.IP { + version := api.IP_IPv4 + if !ip.isLegacy { + version = api.IP_IPv6 + } + return &api.IP{ - Lower: ip.lower, - Higher: ip.higher, - IsLegacy: ip.isLegacy, + Lower: ip.lower, + Higher: ip.higher, + Version: version, } } diff --git a/net/ip_test.go b/net/ip_test.go index 53738b09d44663c4596ede2dec7aac0998cfff28..cc54e99f16e3c42dd9593107b42fc9a3941e2847 100644 --- a/net/ip_test.go +++ b/net/ip_test.go @@ -5,7 +5,7 @@ import ( "net" "testing" - "github.com/bio-routing/bio-rd/net/api" + api "github.com/bio-routing/bio-rd/net/api" "github.com/stretchr/testify/assert" ) @@ -83,8 +83,8 @@ func TestIPToProto(t *testing.T) { isLegacy: true, }, expected: &api.IP{ - Lower: 255, - IsLegacy: true, + Lower: 255, + Version: api.IP_IPv4, }, }, { @@ -95,9 +95,9 @@ func TestIPToProto(t *testing.T) { isLegacy: false, }, expected: &api.IP{ - Higher: 1000, - Lower: 255, - IsLegacy: false, + Higher: 1000, + Lower: 255, + Version: api.IP_IPv6, }, }, } @@ -117,9 +117,9 @@ func TestIPFromProtoIP(t *testing.T) { { name: "Test IPv4", proto: api.IP{ - Lower: 100, - Higher: 0, - IsLegacy: true, + Lower: 100, + Higher: 0, + Version: api.IP_IPv4, }, expected: IP{ lower: 100, @@ -130,9 +130,9 @@ func TestIPFromProtoIP(t *testing.T) { { name: "Test IPv6", proto: api.IP{ - Lower: 100, - Higher: 200, - IsLegacy: false, + Lower: 100, + Higher: 200, + Version: api.IP_IPv6, }, expected: IP{ lower: 100, @@ -144,7 +144,7 @@ func TestIPFromProtoIP(t *testing.T) { for _, test := range tests { res := IPFromProtoIP(test.proto) - assert.Equal(t, test.expected, res, test.name) + assert.Equal(t, test.expected, res, test.name) } } diff --git a/net/prefix.go b/net/prefix.go index 22158dc027cb51bd270acb6c24207dfc81f36121..85b4265d9ca4bef0914e7ff20ce3fdfd17d6178c 100644 --- a/net/prefix.go +++ b/net/prefix.go @@ -6,7 +6,7 @@ import ( "strconv" "strings" - "github.com/bio-routing/bio-rd/net/api" + api "github.com/bio-routing/bio-rd/net/api" ) // Prefix represents an IPv4 prefix diff --git a/net/prefix_test.go b/net/prefix_test.go index 52e2aea669be427ac6421bdf00a7bed0f946e6e9..41423a361a50f61bd443e801160cc8d52affb90e 100644 --- a/net/prefix_test.go +++ b/net/prefix_test.go @@ -3,7 +3,7 @@ package net import ( "testing" - "github.com/bio-routing/bio-rd/net/api" + api "github.com/bio-routing/bio-rd/net/api" "github.com/stretchr/testify/assert" ) @@ -24,8 +24,8 @@ func TestPrefixToProto(t *testing.T) { }, expected: &api.Prefix{ Address: &api.IP{ - Lower: 200, - IsLegacy: true, + Lower: 200, + Version: api.IP_IPv4, }, Pfxlen: 24, }, @@ -42,9 +42,9 @@ func TestPrefixToProto(t *testing.T) { }, expected: &api.Prefix{ Address: &api.IP{ - Higher: 100, - Lower: 200, - IsLegacy: false, + Higher: 100, + Lower: 200, + Version: api.IP_IPv6, }, Pfxlen: 64, }, @@ -67,9 +67,9 @@ func TestNewPrefixFromProtoPrefix(t *testing.T) { name: "IPv4", proto: api.Prefix{ Address: &api.IP{ - Higher: 0, - Lower: 2000, - IsLegacy: true, + Higher: 0, + Lower: 2000, + Version: api.IP_IPv4, }, Pfxlen: 24, }, @@ -86,9 +86,9 @@ func TestNewPrefixFromProtoPrefix(t *testing.T) { name: "IPv6", proto: api.Prefix{ Address: &api.IP{ - Higher: 1000, - Lower: 2000, - IsLegacy: false, + Higher: 1000, + Lower: 2000, + Version: api.IP_IPv6, }, Pfxlen: 64, }, diff --git a/route/api/route.proto b/route/api/route.proto index 6d8ef35586d7adbda8bf828396f1ddb94c4ad656..c1846ad8bf140da9c38c089f737f67d6389e1319 100644 --- a/route/api/route.proto +++ b/route/api/route.proto @@ -10,9 +10,13 @@ message Route { } message Path { - uint32 type = 1; - BGPPath BGP_path = 2; - StaticPath static_path = 3; + enum Type { + Static = 0; + BGP = 1; + } + Type type = 1; + StaticPath static_path = 2; + BGPPath BGP_path = 3; } message StaticPath { diff --git a/route/bgp_path.go b/route/bgp_path.go index c72cc6158e8de9bac6fcaa8d08f3088e5b3b085a..bddc90f30ad5361eaff78c635d61ee827a1b521a 100644 --- a/route/bgp_path.go +++ b/route/bgp_path.go @@ -47,10 +47,18 @@ func (b *BGPPath) ToProto() *api.BGPPath { } ret.NextHop.Lower = b.NextHop.Lower() ret.NextHop.Higher = b.NextHop.Higher() - ret.NextHop.IsLegacy = b.NextHop.IsLegacy() + ret.NextHop.Version = netapi.IP_IPv4 + if !b.NextHop.IsLegacy() { + ret.NextHop.Version = netapi.IP_IPv6 + } + ret.Source.Lower = b.Source.Lower() ret.Source.Higher = b.Source.Higher() - ret.Source.IsLegacy = b.Source.IsLegacy() + ret.Source.Version = netapi.IP_IPv4 + if !b.Source.IsLegacy() { + ret.Source.Version = netapi.IP_IPv6 + } + ret.EBGP = b.EBGP ret.BGPIdentifier = b.BGPIdentifier ret.ClusterList = b.ClusterList diff --git a/route/bgp_path_test.go b/route/bgp_path_test.go index e4eb882388924819f906411b6835522dfa31f700..d7b6da662644b74af15e3bf5e75cf36693ddcbe3 100644 --- a/route/bgp_path_test.go +++ b/route/bgp_path_test.go @@ -185,7 +185,7 @@ func TestBGPPathToProto(t *testing.T) { PathIdentifier: 10, NextHop: &netapi.IP{ Lower: 210, - IsLegacy: true, + Version: api.IP_IPv4, }, LocalPref: 20, ASPath: []*pb.ASPathSegment{ diff --git a/route/path.go b/route/path.go index 98a2c53282a35627fbc5b40852aaaaaf7ee75f64..81bcd6a14ea9b5c855a2ba7be96d85b67deea8df 100644 --- a/route/path.go +++ b/route/path.go @@ -15,8 +15,14 @@ type Path struct { // ToProto converts Path to Proto Path func (p *Path) ToProto() *api.Path { + t := api.Path_Static + switch p.Type { + case BGPPathType: + t = api.Path_BGP + } + return &api.Path{ - Type: uint32(p.Type), + Type: t, BGPPath: p.BGPPath.ToProto(), StaticPath: p.StaticPath.ToProto(), }