Skip to content

Commit

Permalink
Send non-empty NH, improve client error output.
Browse files Browse the repository at this point in the history
  * (M) client/client.go
    - Add String() method for operation result's details such that there
      is additional information as to what the error corresponds to.
  * (M) compliance/compliance.go
    - Ensure that we do not send an empty next-hop when at least one
      field must be populated. See #79 which tracks adding a fix to the
      server side code.
  • Loading branch information
robshakir committed Oct 10, 2021
1 parent 3d9f725 commit 498dac0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
47 changes: 33 additions & 14 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,20 +518,6 @@ type OpResult struct {
Details *OpDetailsResults
}

// OpDetailsResults provides details of an operation for use in the results.
type OpDetailsResults struct {
// Type is the type of the operation (i.e., ADD, MODIFY, DELETE)
Type constants.OpType

// NextHopIndex is the identifier for a next-hop modified by the operation.
NextHopIndex uint64
// NextHopGroupID is the identifier for a next-hop-group modified by the
// operation.
NextHopGroupID uint64
// IPv4Prefix is the IPv4 prefix modified by the operation.
IPv4Prefix string
}

// String returns a string for an OpResult for debugging purposes.
func (o *OpResult) String() string {
buf := &bytes.Buffer{}
Expand Down Expand Up @@ -559,6 +545,39 @@ func (o *OpResult) String() string {
return buf.String()
}

// OpDetailsResults provides details of an operation for use in the results.
type OpDetailsResults struct {
// Type is the type of the operation (i.e., ADD, MODIFY, DELETE)
Type constants.OpType

// NextHopIndex is the identifier for a next-hop modified by the operation.
NextHopIndex uint64
// NextHopGroupID is the identifier for a next-hop-group modified by the
// operation.
NextHopGroupID uint64
// IPv4Prefix is the IPv4 prefix modified by the operation.
IPv4Prefix string
}

func (o *OpDetailsResults) String() string {
if o == nil {
return "<nil>"
}
buf := &bytes.Buffer{}
buf.WriteString(fmt.Sprintf("<Type: %s ", o.Type))
switch {
case o.NextHopIndex != 0:
buf.WriteString(fmt.Sprintf("NH Index: %d", o.NextHopIndex))
case o.NextHopGroupID != 0:
buf.WriteString(fmt.Sprintf("NHG ID: %d", o.NextHopGroupID))
case o.IPv4Prefix != "":
buf.WriteString(fmt.Sprintf("IPv4: %s", o.IPv4Prefix))
}
buf.WriteString(">")

return buf.String()
}

// Q enqueues a ModifyRequest to be sent to the target.
func (c *Client) Q(m *spb.ModifyRequest) {
if err := c.handleModifyRequest(m); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion compliance/compliance.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func doOps(c *fluent.GRIBIClient, t testing.TB, ops []func(), wantACK fluent.Pro
func addNextHopGroupInternal(c *fluent.GRIBIClient, t testing.TB, wantACK fluent.ProgrammingResult) {
ops := []func(){
func() {
c.Modify().AddEntry(t, fluent.NextHopEntry().WithNetworkInstance(server.DefaultNetworkInstanceName).WithIndex(1))
c.Modify().AddEntry(t, fluent.NextHopEntry().WithNetworkInstance(server.DefaultNetworkInstanceName).WithIndex(1).WithIPAddress("192.0.2.1"))
},
func() {
c.Modify().AddEntry(t, fluent.NextHopGroupEntry().WithNetworkInstance(server.DefaultNetworkInstanceName).WithID(42).AddNextHop(1, 1))
Expand Down

0 comments on commit 498dac0

Please sign in to comment.