Skip to content

Commit

Permalink
Merge pull request #240 from nflath/nh-delete
Browse files Browse the repository at this point in the history
Don't populate an empty NextHop in AFTOperations
  • Loading branch information
nflath authored Jul 29, 2024
2 parents 27ecdc7 + 64302a8 commit ab0a020
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compliance/compliance.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ func AddIPv4EntryRandom(c *fluent.GRIBIClient, t testing.TB, _ ...TestOpt) {
defer flushServer(c, t)
ops := []func(){
func() {
c.Modify().AddEntry(t, fluent.NextHopEntry().WithNetworkInstance(defaultNetworkInstanceName).WithIndex(1))
c.Modify().AddEntry(t, fluent.NextHopEntry().WithNetworkInstance(defaultNetworkInstanceName).WithIndex(1).WithIPAddress("192.0.2.3"))
},
func() {
c.Modify().AddEntry(t, fluent.NextHopGroupEntry().WithNetworkInstance(defaultNetworkInstanceName).WithID(42).AddNextHop(1, 1))
Expand Down
35 changes: 32 additions & 3 deletions fluent/fluent.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,9 +796,7 @@ type nextHopEntry struct {
// gRIBI.
func NextHopEntry() *nextHopEntry {
return &nextHopEntry{
pb: &aftpb.Afts_NextHopKey{
NextHop: &aftpb.Afts_NextHop{},
},
pb: &aftpb.Afts_NextHopKey{},
}
}

Expand All @@ -818,12 +816,19 @@ func (n *nextHopEntry) WithNetworkInstance(ni string) *nextHopEntry {
// WithIPAddress specifies an IP address to be used for the next-hop. The IP
// address is resolved within the network instance specified by WithNextHopNetworkInstance.
func (n *nextHopEntry) WithIPAddress(addr string) *nextHopEntry {
if n.pb.NextHop == nil {
n.pb.NextHop = &aftpb.Afts_NextHop{}
}
n.pb.NextHop.IpAddress = &wpb.StringValue{Value: addr}

return n
}

// WithInterfaceRef specifies an interface to be used for the next-hop.
func (n *nextHopEntry) WithInterfaceRef(name string) *nextHopEntry {
if n.pb.NextHop == nil {
n.pb.NextHop = &aftpb.Afts_NextHop{}
}
n.pb.NextHop.InterfaceRef = &aftpb.Afts_NextHop_InterfaceRef{
Interface: &wpb.StringValue{Value: name},
}
Expand All @@ -833,6 +838,9 @@ func (n *nextHopEntry) WithInterfaceRef(name string) *nextHopEntry {
// WithSubinterfaceRef specifies both an interface and a specific
// subinterface to be used for the next-hop.
func (n *nextHopEntry) WithSubinterfaceRef(name string, subinterface uint64) *nextHopEntry {
if n.pb.NextHop == nil {
n.pb.NextHop = &aftpb.Afts_NextHop{}
}
n.pb.NextHop.InterfaceRef = &aftpb.Afts_NextHop_InterfaceRef{
Interface: &wpb.StringValue{Value: name},
Subinterface: &wpb.UintValue{Value: subinterface},
Expand All @@ -842,6 +850,9 @@ func (n *nextHopEntry) WithSubinterfaceRef(name string, subinterface uint64) *ne

// WithMacAddress specifies a MAC address to be used for the next-hop.
func (n *nextHopEntry) WithMacAddress(mac string) *nextHopEntry {
if n.pb.NextHop == nil {
n.pb.NextHop = &aftpb.Afts_NextHop{}
}
n.pb.NextHop.MacAddress = &wpb.StringValue{Value: mac}
return n
}
Expand All @@ -850,6 +861,9 @@ func (n *nextHopEntry) WithMacAddress(mac string) *nextHopEntry {
// the next-hop, and the source and destination IP addresses for the
// packet.
func (n *nextHopEntry) WithIPinIP(srcIP, dstIP string) *nextHopEntry {
if n.pb.NextHop == nil {
n.pb.NextHop = &aftpb.Afts_NextHop{}
}
n.pb.NextHop.IpInIp = &aftpb.Afts_NextHop_IpInIp{
SrcIp: &wpb.StringValue{Value: srcIP},
DstIp: &wpb.StringValue{Value: dstIP},
Expand All @@ -863,6 +877,9 @@ func (n *nextHopEntry) WithIPinIP(srcIP, dstIP string) *nextHopEntry {
// lookup uses the input packet within the specified network instance to determine the
// next-hop.
func (n *nextHopEntry) WithNextHopNetworkInstance(ni string) *nextHopEntry {
if n.pb.NextHop == nil {
n.pb.NextHop = &aftpb.Afts_NextHop{}
}
n.pb.NextHop.NetworkInstance = &wpb.StringValue{Value: ni}
return n
}
Expand All @@ -871,6 +888,9 @@ func (n *nextHopEntry) WithNextHopNetworkInstance(ni string) *nextHopEntry {
// packet. In this case, the exact value of the label to be popped need not be
// specified.
func (n *nextHopEntry) WithPopTopLabel() *nextHopEntry {
if n.pb.NextHop == nil {
n.pb.NextHop = &aftpb.Afts_NextHop{}
}
n.pb.NextHop.PopTopLabel = &wpb.BoolValue{Value: true}
return n
}
Expand All @@ -880,6 +900,9 @@ func (n *nextHopEntry) WithPopTopLabel() *nextHopEntry {
// in the inner-most to the outer-most such that the first label is the closest to the
// bottom of the stack.
func (n *nextHopEntry) WithPushedLabelStack(labels ...uint32) *nextHopEntry {
if n.pb.NextHop == nil {
n.pb.NextHop = &aftpb.Afts_NextHop{}
}
n.pb.NextHop.PushedMplsLabelStack = []*aftpb.Afts_NextHop_PushedMplsLabelStackUnion{}
for _, v := range labels {
lbl := &aftpb.Afts_NextHop_PushedMplsLabelStackUnion{
Expand Down Expand Up @@ -913,13 +936,19 @@ var (
// WithDecapsulateHeader specifies that the next-hop should apply an action to decapsulate
// the packet from the specified header, h.
func (n *nextHopEntry) WithDecapsulateHeader(h Header) *nextHopEntry {
if n.pb.NextHop == nil {
n.pb.NextHop = &aftpb.Afts_NextHop{}
}
n.pb.NextHop.DecapsulateHeader = encapMap[h]
return n
}

// WithEncapsulateHeader specifies that the next-hop should apply an action to encapsulate
// the packet with the specified header, h.
func (n *nextHopEntry) WithEncapsulateHeader(h Header) *nextHopEntry {
if n.pb.NextHop == nil {
n.pb.NextHop = &aftpb.Afts_NextHop{}
}
n.pb.NextHop.EncapsulateHeader = encapMap[h]
return n
}
Expand Down
18 changes: 18 additions & 0 deletions fluent/fluent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,24 @@ func TestEntriesToModifyRequest(t *testing.T) {
},
}},
},
}, {
desc: "one NH entry delete with only index",
inOp: spb.AFTOperation_DELETE,
inEntries: []GRIBIEntry{
NextHopEntry().WithNetworkInstance("DEFAULT").WithIndex(1),
},
wantModifyRequest: &spb.ModifyRequest{
Operation: []*spb.AFTOperation{{
Id: 1,
NetworkInstance: "DEFAULT",
Op: spb.AFTOperation_DELETE,
Entry: &spb.AFTOperation_NextHop{
NextHop: &aftpb.Afts_NextHopKey{
Index: 1,
},
},
}},
},
}}

for _, tt := range tests {
Expand Down

0 comments on commit ab0a020

Please sign in to comment.