Skip to content

Commit

Permalink
Add support for retrieving a RIB from a remote source.
Browse files Browse the repository at this point in the history
 * (M) go.{mod,sum}
  - Move to non-release version of ygot to get new `protomap` features.
 * (M) rib/remote.go
  - Add support for a RIB that is accessed via the `Get` RPC rather than
    locally.
 * (M) rib/rib(_test).go
  - Add a mechanism to retrieve RIB contents, improve testing.
  • Loading branch information
robshakir committed Sep 22, 2023
1 parent 197d34f commit 297adef
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/openconfig/gribi v1.0.0
github.com/openconfig/lemming v0.3.2-0.20230914210403-c6484d12af0a
github.com/openconfig/testt v0.0.0-20220311054427-efbb1a32ec07
github.com/openconfig/ygot v0.29.11-0.20230922074452-052ed885651c
github.com/openconfig/ygot v0.29.11-0.20230922181344-6c3af4108a57
go.uber.org/atomic v1.10.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d
google.golang.org/grpc v1.58.0-dev
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ github.com/openconfig/ygot v0.29.10 h1:FRZXxyeCdiJXz6uat5uOm3Hlg+PUu2N0mY+eiva12
github.com/openconfig/ygot v0.29.10/go.mod h1:RNnn1ytQ8GZV5LPts36l0cyoRjsYYpruiruJEvmU2sg=
github.com/openconfig/ygot v0.29.11-0.20230922074452-052ed885651c h1:0rE/tRnck61Guj+zkButSrb1VMWtDP0xX4cmanEDHL4=
github.com/openconfig/ygot v0.29.11-0.20230922074452-052ed885651c/go.mod h1:RNnn1ytQ8GZV5LPts36l0cyoRjsYYpruiruJEvmU2sg=
github.com/openconfig/ygot v0.29.11-0.20230922181344-6c3af4108a57 h1:z7bNYTNR1HzxYQNVwBUaf0veA4j4vuTBW7mTLRW4M1w=
github.com/openconfig/ygot v0.29.11-0.20230922181344-6c3af4108a57/go.mod h1:RNnn1ytQ8GZV5LPts36l0cyoRjsYYpruiruJEvmU2sg=
github.com/p4lang/p4runtime v1.4.0-rc.5.0.20220728214547-13f0d02a521e h1:AfZKoikDXbZ7zWvO/lvCRzLo7i6lM+gNleYVMxPiWyQ=
github.com/p4lang/p4runtime v1.4.0-rc.5.0.20220728214547-13f0d02a521e/go.mod h1:m9laObIMXM9N1ElGXijc66/MSM5eheZJLRLxg/TG+fU=
github.com/pborman/getopt v0.0.0-20190409184431-ee0cd42419d3/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o=
Expand Down
3 changes: 0 additions & 3 deletions rib/reconciler/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/openconfig/gribigo/client"
"github.com/openconfig/gribigo/rib"
"google.golang.org/protobuf/encoding/prototext"

spb "github.com/openconfig/gribi/v1/proto/service"
)
Expand Down Expand Up @@ -57,8 +56,6 @@ func (r *RemoteRIB) Get(ctx context.Context) (*rib.RIB, error) {
return nil, fmt.Errorf("cannot get remote RIB, %v", err)
}

fmt.Printf("%s\n", prototext.Format(resp))

// We always disable the RIB checking function because we want to see entries that have
// not got valid references so that we can reconcile them.
remRIB, err := rib.FromGetResponses(r.defaultName, []*spb.GetResponse{resp}, rib.DisableRIBCheckFn())
Expand Down
3 changes: 0 additions & 3 deletions rib/reconciler/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package reconciler

import (
"context"
"fmt"
"net"
"testing"
"time"
Expand Down Expand Up @@ -175,8 +174,6 @@ func TestGet(t *testing.T) {
if err != nil {
t.Fatalf("(*RemoteRIB).Get(ctx).RIBContents(): can't introspect RIB, err: %v", err)
}
fmt.Printf("%s\n", got.String())
fmt.Printf("%s\n", tt.inInjectedRIB)

if diff := cmp.Diff(gotContents, tt.wantRIBContents); diff != "" {
t.Fatalf("(*RemoteRIB).Get(ctx): did not get expected contents, diff(-got,+want):\n%s", diff)
Expand Down
8 changes: 0 additions & 8 deletions rib/rib.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"time"

log "github.com/golang/glog"
"github.com/kr/pretty"
"github.com/openconfig/gnmi/value"
"github.com/openconfig/goyang/pkg/yang"
"github.com/openconfig/gribigo/aft"
Expand All @@ -34,7 +33,6 @@ import (
"github.com/openconfig/ygot/ytypes"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"

gpb "github.com/openconfig/gnmi/proto/gnmi"
Expand Down Expand Up @@ -1820,8 +1818,6 @@ func concreteNextHopProto(e *aft.Afts_NextHop) (*aftpb.Afts_NextHopKey, error) {
// concreteNextHopGroupProto takes the input NextHopGroup GoStruct and returns it as a gRIBI
// NextHopGroupEntryKey protobuf. It returns an error if the protobuf cannot be marshalled.
func concreteNextHopGroupProto(e *aft.Afts_NextHopGroup) (*aftpb.Afts_NextHopGroupKey, error) {
fmt.Printf("input: %v\n", e)
fmt.Printf("val: %d\n", *e.Id)
nhgproto := &aftpb.Afts_NextHopGroup{}
if err := protoFromGoStruct(e, &gpb.Path{
Elem: []*gpb.PathElem{{
Expand All @@ -1834,7 +1830,6 @@ func concreteNextHopGroupProto(e *aft.Afts_NextHopGroup) (*aftpb.Afts_NextHopGro
}, nhgproto); err != nil {
return nil, fmt.Errorf("cannot marshal next-hop index %d, %v", e.GetId(), err)
}
fmt.Printf("concrete nhg: %s\n", prototext.Format(nhgproto))
return &aftpb.Afts_NextHopGroupKey{
Id: *e.Id,
NextHopGroup: nhgproto,
Expand All @@ -1858,7 +1853,6 @@ func protoFromGoStruct(s ygot.ValidatedGoStruct, prefix *gpb.Path, pb proto.Mess
vals[u.Path] = u.Val
}
}
pretty.Printf("vals: %s\n", vals)

if err := protomap.ProtoFromPaths(pb, vals,
protomap.ProtobufMessagePrefix(prefix),
Expand All @@ -1868,8 +1862,6 @@ func protoFromGoStruct(s ygot.ValidatedGoStruct, prefix *gpb.Path, pb proto.Mess
return fmt.Errorf("cannot unmarshal gNMI paths, %v", err)
}

fmt.Printf("unmarshalled: %s\n", prototext.Format(pb))

return nil
}

Expand Down
22 changes: 20 additions & 2 deletions rib/rib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,17 @@ func TestConcreteNHGProto(t *testing.T) {
a.GetOrCreateNextHop(1).Weight = ygot.Uint64(1)
return a
}(),
want: &aftpb.Afts_NextHopGroupKey{
Id: 1,
NextHopGroup: &aftpb.Afts_NextHopGroup{
NextHop: []*aftpb.Afts_NextHopGroup_NextHopKey{{
Index: 1,
NextHop: &aftpb.Afts_NextHopGroup_NextHop{
Weight: &wpb.UintValue{Value: 1},
},
}},
},
},
}}

for _, tt := range tests {
Expand Down Expand Up @@ -3205,8 +3216,15 @@ func TestGetRIB(t *testing.T) {
NetworkInstance: "VRF-42",
Entry: &spb.AFTEntry_NextHopGroup{
NextHopGroup: &aftpb.Afts_NextHopGroupKey{
Id: 42,
NextHopGroup: &aftpb.Afts_NextHopGroup{},
Id: 42,
NextHopGroup: &aftpb.Afts_NextHopGroup{
NextHop: []*aftpb.Afts_NextHopGroup_NextHopKey{{
Index: 1,
NextHop: &aftpb.Afts_NextHopGroup_NextHop{
Weight: &wpb.UintValue{Value: 1},
},
}},
},
},
},
}},
Expand Down

0 comments on commit 297adef

Please sign in to comment.