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 plumbing gRIBI server options through lemming. #451

Merged
merged 11 commits into from
Jul 16, 2024
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: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ go_library(
"//p4rt",
"//sysrib",
"@com_github_golang_glog//:glog",
"@com_github_openconfig_gribigo//server",
"@io_k8s_klog_v2//:klog",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//credentials",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/openconfig/gnsi v1.4.5
github.com/openconfig/goyang v1.4.5
github.com/openconfig/gribi v1.0.0
github.com/openconfig/gribigo v0.0.0-20240314002941-b59d04db23bd
github.com/openconfig/gribigo v0.0.0-20240712014900-6e0dad60c17a
github.com/openconfig/kne v0.1.18
github.com/openconfig/magna v0.0.0-20240326180454-518e16696c84
github.com/openconfig/ondatra v0.5.8
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1779,8 +1779,8 @@ github.com/openconfig/goyang v1.4.5/go.mod h1:sdNZi/wdTZyLNBNfgLzmmbi7kISm7FskMD
github.com/openconfig/gribi v0.1.1-0.20210423184541-ce37eb4ba92f/go.mod h1:OoH46A2kV42cIXGyviYmAlGmn6cHjGduyC2+I9d/iVs=
github.com/openconfig/gribi v1.0.0 h1:xMwEg0mBD+21mOxuFOw0d9dBKuIPwJEhMUUeUulZdLg=
github.com/openconfig/gribi v1.0.0/go.mod h1:VFqGH2ZPFIfnKTimP4/AQB4OK0eySW5muJNFxXAwP6k=
github.com/openconfig/gribigo v0.0.0-20240314002941-b59d04db23bd h1:MwzM4PieAaHBYDTUd5wMFqzVTzerf3OvHdLmjv7mD+g=
github.com/openconfig/gribigo v0.0.0-20240314002941-b59d04db23bd/go.mod h1:oMzEmz+ba6QQGNSPMwxJhZxx6gF5GBFnuuQPv6rd0oU=
github.com/openconfig/gribigo v0.0.0-20240712014900-6e0dad60c17a h1:KTuSH6nuZUQxarrctK/Lw5EzjALKpBYX+U0wqum1/S4=
github.com/openconfig/gribigo v0.0.0-20240712014900-6e0dad60c17a/go.mod h1:wMFhIe5tmza/FLGS5XtY3JCZfF7U81yyLCWbm8cTETM=
github.com/openconfig/grpctunnel v0.0.0-20220819142823-6f5422b8ca70 h1:t6SvvdfWCMlw0XPlsdxO8EgO+q/fXnTevDjdYREKFwU=
github.com/openconfig/grpctunnel v0.0.0-20220819142823-6f5422b8ca70/go.mod h1:OmTWe7RyZj2CIzIgy4ovEBzCLBJzRvWSZmn7u02U9gU=
github.com/openconfig/kne v0.1.18 h1:8D9SexWhj6knxfvEficyVj0F13GIvF1pQz7TKwVDSUI=
Expand Down
15 changes: 10 additions & 5 deletions gribi/gribi.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ type Server struct {
// installed.
// - root, if specified, will be used to populate connected routes into the RIB
// manager. Note this is intended to be used for unit/standalone device testing.
func New(s *grpc.Server, gClient gpb.GNMIClient, target string, root *oc.Root, sysribAddr string) (*Server, error) {
gs, err := createGRIBIServer(gClient, target, root, sysribAddr)
// - opts, if specified, will be used to control the underlying gRIBI server's
// behaviours.
func New(s *grpc.Server, gClient gpb.GNMIClient, target string, root *oc.Root, sysribAddr string, opts ...server.ServerOpt) (*Server, error) {
gs, err := createGRIBIServer(gClient, target, root, sysribAddr, opts...)
if err != nil {
return nil, fmt.Errorf("cannot create gRIBI server, %v", err)
}
Expand All @@ -73,7 +75,10 @@ func New(s *grpc.Server, gClient gpb.GNMIClient, target string, root *oc.Root, s
//
// - root, if specified, will be used to populate connected routes into the RIB
// manager. Note this is intended to be used for unit/standalone device testing.
func createGRIBIServer(gClient gpb.GNMIClient, target string, root *oc.Root, sysribAddr string) (*server.Server, error) {
//
// The ServerOpt slice provided is handed to the gRIBI fake server to control its
// behaviour.
func createGRIBIServer(gClient gpb.GNMIClient, target string, root *oc.Root, sysribAddr string, opts ...server.ServerOpt) (*server.Server, error) {
gzebraConn, err := grpc.Dial(sysribAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, fmt.Errorf("cannot dial to sysrib, %v", err)
Expand Down Expand Up @@ -153,11 +158,11 @@ func createGRIBIServer(gClient gpb.GNMIClient, target string, root *oc.Root, sys
log.Infof("Sent route %v with response %v", routeReq, resp)
}

return server.New(
return server.New(append([]server.ServerOpt{
server.WithPostChangeRIBHook(ribHookfn),
server.WithRIBResolvedEntryHook(ribAddfn),
server.WithVRFs(networkInstances),
)
}, opts...)...)
}

// createSetRouteRequest converts a Route to a sysrib SetRouteRequest
Expand Down
13 changes: 12 additions & 1 deletion lemming.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"google.golang.org/grpc/reflection"
"k8s.io/klog/v2"

gribis "github.com/openconfig/gribigo/server"

"github.com/openconfig/lemming/bgp"
"github.com/openconfig/lemming/dataplane"
"github.com/openconfig/lemming/dataplane/dplaneopts"
Expand Down Expand Up @@ -85,6 +87,7 @@ type opt struct {
bgpPort uint16
dataplane bool
dataplaneOpts []dplaneopts.Option
gribiOpts []gribis.ServerOpt
}

// resolveOpts applies all the options and returns a struct containing the result.
Expand Down Expand Up @@ -176,6 +179,14 @@ func WithSysribAddr(sysribAddr string) Option {
}
}

// WithGRIBIOpts specifies the set of gRIBI options that should be passed to
// the gRIBI server that lemming runs.
func WithGRIBIOpts(opts ...gribis.ServerOpt) Option {
return func(o *opt) {
o.gribiOpts = opts
}
}

// New returns a new initialized device.
func New(targetName, zapiURL string, opts ...Option) (*Device, error) {
var dplane *dataplane.Dataplane
Expand Down Expand Up @@ -248,7 +259,7 @@ func New(targetName, zapiURL string, opts ...Option) (*Device, error) {
log.Info("starting gRIBI")
// TODO(wenbli): Use gRIBIs once we change lemming's KNE config to use different ports.
// gRIBIs := grpc.NewServer()
gribiServer, err := fgribi.New(s, cacheClient, targetName, root, fmt.Sprintf("unix:%s", resolvedOpts.sysribAddr))
gribiServer, err := fgribi.New(s, cacheClient, targetName, root, fmt.Sprintf("unix:%s", resolvedOpts.sysribAddr), resolvedOpts.gribiOpts...)
if err != nil {
return nil, err
}
Expand Down
14 changes: 4 additions & 10 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1437,8 +1437,8 @@ def go_repositories():
go_repository(
name = "com_github_openconfig_gribigo",
importpath = "github.com/openconfig/gribigo",
sum = "h1:MwzM4PieAaHBYDTUd5wMFqzVTzerf3OvHdLmjv7mD+g=",
version = "v0.0.0-20240314002941-b59d04db23bd",
sum = "h1:KTuSH6nuZUQxarrctK/Lw5EzjALKpBYX+U0wqum1/S4=",
version = "v0.0.0-20240712014900-6e0dad60c17a",
)
go_repository(
name = "com_github_openconfig_grpctunnel",
Expand Down Expand Up @@ -1882,12 +1882,6 @@ def go_repositories():
sum = "h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8=",
version = "v0.0.4",
)
go_repository(
name = "com_github_wenovus_gobgp_v3",
importpath = "github.com/wenovus/gobgp/v3",
sum = "h1:jse5eORjbrlTIOPzOO3cpm4feJ16ZCntxzAHSdcWuy4=",
version = "v3.0.0-20230831013712-6d33842cbf42",
)
go_repository(
name = "com_github_wi2l_jsondiff",
importpath = "github.com/wI2L/jsondiff",
Expand Down Expand Up @@ -3078,8 +3072,8 @@ def go_repositories():
name = "org_golang_google_grpc",
build_file_proto_mode = "disable",
importpath = "google.golang.org/grpc",
sum = "h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=",
version = "v1.64.0",
sum = "h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA=",
version = "v1.64.1",
)
go_repository(
name = "org_golang_google_grpc_cmd_protoc_gen_go_grpc",
Expand Down
Loading