Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for next-hop-group into reconciler. #199

Merged
merged 4 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,5 @@ require (
golang.org/x/text v0.12.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog v1.0.0 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
)
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down Expand Up @@ -606,8 +605,6 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
k8s.io/klog/v2 v2.90.1 h1:m4bYOKall2MmOiRaR1J+We67Do7vm9KiQVlT96lnHUw=
k8s.io/klog/v2 v2.90.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI=
Expand Down
41 changes: 34 additions & 7 deletions rib/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

// FromGetResponses returns a RIB from a slice of gRIBI GetResponse messages.
// The supplied defaultName is used as the default network instance name.
func FromGetResponses(defaultName string, responses []*spb.GetResponse, opt ...RIBOpt) (*RIB, error) {

Check failure on line 29 in rib/helpers.go

View workflow job for this annotation

GitHub Actions / go / Static Analysis

parameter 'opt' seems to be unused, consider removing or renaming it as _
r := New(defaultName)
niAFTs := map[string]*aftpb.Afts{}

Expand Down Expand Up @@ -112,17 +112,17 @@
}

// InjectNHG adds a next-hop-group entry to network instance ni, with the specified
// ID (nhgId). The next-hop-group contains the next hops specified in the nhs map,
// ID (nhgID). The next-hop-group contains the next hops specified in the nhs map,
// with the key of the map being the next-hop ID and the value being the weight within
// the group.
func (f *fakeRIB) InjectNHG(ni string, nhgId uint64, nhs map[uint64]uint64) error {
func (f *fakeRIB) InjectNHG(ni string, nhgID uint64, nhs map[uint64]uint64) error {
niR, ok := f.r.NetworkInstanceRIB(ni)
if !ok {
return fmt.Errorf("unknown NI, %s", ni)
}

nhg := &aftpb.Afts_NextHopGroupKey{
Id: nhgId,
Id: nhgID,
NextHopGroup: &aftpb.Afts_NextHopGroup{},
}
for nh, weight := range nhs {
Expand All @@ -142,19 +142,46 @@
}

// InjectNH adds a next-hop entry to network instance ni, with the specified
// index (nhIdx). An error is returned if it cannot be added.
func (f *fakeRIB) InjectNH(ni string, nhIdx uint64) error {
// index (nhIdx), and interface ref to intName. An error is returned if it cannot
// be added.
func (f *fakeRIB) InjectNH(ni string, nhIdx uint64, intName string) error {
niR, ok := f.r.NetworkInstanceRIB(ni)
if !ok {
return fmt.Errorf("unknown NI, %s", ni)
}

if _, _, err := niR.AddNextHop(&aftpb.Afts_NextHopKey{
Index: nhIdx,
NextHop: &aftpb.Afts_NextHop{},
Index: nhIdx,
NextHop: &aftpb.Afts_NextHop{
InterfaceRef: &aftpb.Afts_NextHop_InterfaceRef{
Interface: &wpb.StringValue{Value: intName},
},
},
}, false); err != nil {
return fmt.Errorf("cannot add NH entry, err: %v", err)
}

return nil
}

// InjectMPLS adds an MPLS (Label) entry to network instance ni, with the
// specified next-hop-group. An error is returned if it cannot be added.
func (f *fakeRIB) InjectMPLS(ni string, label, nhg uint64) error {
niR, ok := f.r.NetworkInstanceRIB(ni)
if !ok {
return fmt.Errorf("unknown NI, %s", ni)
}

if _, _, err := niR.AddMPLS(&aftpb.Afts_LabelEntryKey{
Label: &aftpb.Afts_LabelEntryKey_LabelUint64{
LabelUint64: label,
},
LabelEntry: &aftpb.Afts_LabelEntry{
NextHopGroup: &wpb.UintValue{Value: nhg},
},
}, false); err != nil {
return fmt.Errorf("cannot add MPLS entry, err: %v", err)
}

return nil
}
41 changes: 38 additions & 3 deletions rib/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func TestFakeRIB(t *testing.T) {
desc: "nh only",
inBuild: func() *fakeRIB {
f := NewFake(dn)
if err := f.InjectNH(dn, 1); err != nil {
if err := f.InjectNH(dn, 1, "int42"); err != nil {
t.Fatalf("cannot add NH, err: %v", err)
}
return f
Expand All @@ -280,7 +280,12 @@ func TestFakeRIB(t *testing.T) {
r: &aft.RIB{
Afts: &aft.Afts{
NextHop: map[uint64]*aft.Afts_NextHop{
1: {Index: ygot.Uint64(1)},
1: {
Index: ygot.Uint64(1),
InterfaceRef: &aft.Afts_NextHop_InterfaceRef{
Interface: ygot.String("int42"),
},
},
},
},
},
Expand Down Expand Up @@ -311,6 +316,33 @@ func TestFakeRIB(t *testing.T) {
},
},
},
}, {
desc: "mpls only",
inBuild: func() *fakeRIB {
f := NewFake(dn, DisableRIBCheckFn())
if err := f.InjectMPLS(dn, 42, 1); err != nil {
t.Fatalf("cannot add MPLS, err: %v", err)
}
return f
},
wantRIB: &RIB{
defaultName: dn,
niRIB: map[string]*RIBHolder{
dn: {
name: dn,
r: &aft.RIB{
Afts: &aft.Afts{
LabelEntry: map[aft.Afts_LabelEntry_Label_Union]*aft.Afts_LabelEntry{
aft.UnionUint32(42): {
Label: aft.UnionUint32(42),
NextHopGroup: ygot.Uint64(1),
},
},
},
},
},
},
},
}, {
desc: "nhg only",
inBuild: func() *fakeRIB {
Expand Down Expand Up @@ -348,7 +380,7 @@ func TestFakeRIB(t *testing.T) {
inBuild: func() *fakeRIB {
f := NewFake(dn)
// Discard the errors, since the test will check whether the entries are there.
f.InjectNH(dn, 1)
f.InjectNH(dn, 1, "int42")
f.InjectNHG(dn, 1, map[uint64]uint64{1: 1})
f.InjectIPv4(dn, "192.0.2.1/32", 1)
return f
Expand All @@ -363,6 +395,9 @@ func TestFakeRIB(t *testing.T) {
NextHop: map[uint64]*aft.Afts_NextHop{
1: {
Index: ygot.Uint64(1),
InterfaceRef: &aft.Afts_NextHop_InterfaceRef{
Interface: ygot.String("int42"),
},
},
},
NextHopGroup: map[uint64]*aft.Afts_NextHopGroup{
Expand Down
Loading
Loading