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 IPv6 in canResolve. #211

Merged
merged 8 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 9 additions & 4 deletions rib/rib.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,13 @@ func (r *RIB) canResolve(netInst string, candidate *aft.RIB) (bool, error) {

}

for _, i := range caft.Ipv6Entry {
if i.GetNextHopGroup() == 0 {
return false, fmt.Errorf("invalid zero-index NHG in IPv6Entry %s, NI %s", i.GetPrefix(), netInst)
}
return nhgResolvable(niRIB, i.GetNextHopGroupNetworkInstance(), i.GetNextHopGroup())
}

for _, i := range caft.LabelEntry {
if i.GetNextHopGroup() == 0 {
return false, fmt.Errorf("invalid zero index NHG in LabelEntry %v, NI %s", i.GetLabel(), netInst)
Expand Down Expand Up @@ -911,15 +918,13 @@ func (r *RIB) canDelete(netInst string, deletionCandidate *aft.RIB) (bool, error
// by the RIB implementation. It returns an error if it cannot.
func checkCandidate(caft *aft.Afts) error {
switch {
case len(caft.Ipv6Entry) != 0:
return fmt.Errorf("IPv6 entries are unsupported, got: %v", caft.Ipv6Entry)
case len(caft.MacEntry) != 0:
return fmt.Errorf("ethernet MAC entries are unsupported, got: %v", caft.MacEntry)
case len(caft.PolicyForwardingEntry) != 0:
return fmt.Errorf("PBR entries are unsupported, got: %v", caft.PolicyForwardingEntry)
case (len(caft.LabelEntry) + len(caft.Ipv4Entry) + len(caft.NextHopGroup) + len(caft.NextHop)) == 0:
case (len(caft.Ipv6Entry) + len(caft.LabelEntry) + len(caft.Ipv4Entry) + len(caft.NextHopGroup) + len(caft.NextHop)) == 0:
return errors.New("no entries in specified candidate")
case (len(caft.LabelEntry) + len(caft.Ipv4Entry) + len(caft.NextHopGroup) + len(caft.NextHop)) > 1:
case (len(caft.Ipv6Entry) + len(caft.LabelEntry) + len(caft.Ipv4Entry) + len(caft.NextHopGroup) + len(caft.NextHop)) > 1:
return fmt.Errorf("multiple entries are unsupported, got mpls: %v, ipv4: %v, next-hop-group: %v, next-hop: %v", caft.LabelEntry, caft.Ipv4Entry, caft.NextHopGroup, caft.NextHop)
}
return nil
Expand Down
100 changes: 89 additions & 11 deletions rib/rib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1751,17 +1751,6 @@ func TestCanResolve(t *testing.T) {
want: false,
wantErrSubstring: "invalid nil candidate",
}, {
desc: "ipv6 entry - invalid",
inRIB: New(defName),
inNI: defName,
inCand: func() *aft.RIB {
r := &aft.RIB{}
r.GetOrCreateAfts().GetOrCreateIpv6Entry("ff00::1/128")
return r
}(),
wantErrSubstring: "IPv6 entries are unsupported",
}, {

desc: "Ethernet - invalid",
inRIB: New(defName),
inNI: defName,
Expand Down Expand Up @@ -2038,6 +2027,95 @@ func TestCanResolve(t *testing.T) {
return r
}(),
want: true,
}, {
desc: "zero index nhg in IPv6 entry - invalid",
inRIB: New(defName),
inCand: func() *aft.RIB {
r := &aft.RIB{}
i := r.GetOrCreateAfts().GetOrCreateIpv6Entry("2001:db8::1/128")
i.NextHopGroup = ygot.Uint64(0)
return r
}(),
wantErrSubstring: "invalid zero-index NHG in IPv6Entry",
}, {
desc: "resolve ipv6 entry in nil NI - invalid",
inRIB: New(defName),
inCand: func() *aft.RIB {
r := &aft.RIB{}
i := r.GetOrCreateAfts().GetOrCreateIpv6Entry("2001:db8::1/128")
i.NextHopGroup = ygot.Uint64(1)
i.NextHopGroupNetworkInstance = ygot.String("404")
return r
}(),
wantErrSubstring: "invalid unknown network-instance for entry",
}, {
desc: "resolve ipv6 entry in default NI - implicit name",
inRIB: func() *RIB {
r := New(defName)
r.niRIB[defName].r = &aft.RIB{}
cc := r.niRIB[defName].r.GetOrCreateAfts()
cc.GetOrCreateNextHopGroup(1)
return r
}(),
inCand: func() *aft.RIB {
r := &aft.RIB{}
i := r.GetOrCreateAfts().GetOrCreateIpv6Entry("2001:db8::1/128")
i.NextHopGroup = ygot.Uint64(1)
return r
}(),
want: true,
}, {
desc: "resolve ipv6 entry in default NI - explicit name",
inRIB: func() *RIB {
r := New(defName)
r.niRIB[defName].r = &aft.RIB{}
cc := r.niRIB[defName].r.GetOrCreateAfts()
cc.GetOrCreateNextHopGroup(1)
return r
}(),
inCand: func() *aft.RIB {
r := &aft.RIB{}
i := r.GetOrCreateAfts().GetOrCreateIpv6Entry("2001:db8:1::/48")
i.NextHopGroup = ygot.Uint64(1)
i.NextHopGroupNetworkInstance = ygot.String(defName)
return r
}(),
want: true,
}, {
desc: "resolve ipv6 entry in non-default NI",
inRIB: func() *RIB {
r := New(defName)
r.niRIB["vrf-42"] = NewRIBHolder("vrf-42")
r.niRIB["vrf-42"].r = &aft.RIB{}
cc := r.niRIB["vrf-42"].r.GetOrCreateAfts()
cc.GetOrCreateNextHopGroup(1)
return r
}(),
inCand: func() *aft.RIB {
r := &aft.RIB{}
i := r.GetOrCreateAfts().GetOrCreateIpv6Entry("2001:db8::/32")
i.NextHopGroup = ygot.Uint64(1)
i.NextHopGroupNetworkInstance = ygot.String("vrf-42")
return r
}(),
want: true,
}, {
desc: "resolve ipv6 entry in non-default NI - not found",
inRIB: func() *RIB {
r := New(defName)
r.niRIB["vrf-42"] = NewRIBHolder("vrf-42")
r.niRIB["vrf-42"].r = &aft.RIB{}
r.niRIB["vrf-42"].r.GetOrCreateAfts()
// explicitly don't create NHG
return r
}(),
inCand: func() *aft.RIB {
r := &aft.RIB{}
i := r.GetOrCreateAfts().GetOrCreateIpv6Entry("2001:db8::/32")
i.NextHopGroup = ygot.Uint64(1)
i.NextHopGroupNetworkInstance = ygot.String("vrf-42")
return r
}(),
}}

for _, tt := range tests {
Expand Down
Loading