Skip to content

Commit

Permalink
Make lemming dataplane gnmi use the SAI API (#334)
Browse files Browse the repository at this point in the history
* The big refactor

* fixes

* lint

* fix

* fixes

* feedback

* fixes

* build and ut fix
  • Loading branch information
DanG100 authored Nov 30, 2023
1 parent 7a1cb73 commit b22a398
Show file tree
Hide file tree
Showing 36 changed files with 2,260 additions and 5,738 deletions.
2 changes: 2 additions & 0 deletions cmd/lemming/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ go_library(
visibility = ["//visibility:private"],
deps = [
"//:lemming",
"//dataplane/config",
"//proto/forwarding",
"//sysrib",
"@com_github_golang_glog//:glog",
"@com_github_spf13_pflag//:pflag",
Expand Down
5 changes: 5 additions & 0 deletions cmd/lemming/lemming.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ import (
"google.golang.org/grpc/credentials/insecure"

"github.com/openconfig/lemming"
"github.com/openconfig/lemming/dataplane/config"
"github.com/openconfig/lemming/sysrib"

log "github.com/golang/glog"

fwdpb "github.com/openconfig/lemming/proto/forwarding"
)

var (
Expand All @@ -43,6 +46,8 @@ func main() {
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
viper.BindPFlags(pflag.CommandLine)
// TODO: A better way to config, this doesn't need to a be a flag.
viper.Set(config.NetDevForwardingType, fwdpb.PortType_name[int32(fwdpb.PortType_PORT_TYPE_TAP)])

creds := insecure.NewCredentials()
if *tlsCertFile != "" && *tlsKeyFile != "" {
Expand Down
34 changes: 17 additions & 17 deletions dataplane/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,57 @@ go_library(
importpath = "github.com/openconfig/lemming/dataplane",
visibility = ["//visibility:public"],
deps = [
"//dataplane/internal/engine",
"//dataplane/standalone/proto:sai",
"//dataplane/standalone/saiserver",
"//dataplane/standalone/saiserver/attrmgr",
"//gnmi/oc",
"//gnmi/reconciler",
"//proto/dataplane",
"//proto/forwarding",
"@com_github_openconfig_gnmi//proto/gnmi",
"@com_github_openconfig_ygnmi//ygnmi",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//credentials/local",
] + select({
"@io_bazel_rules_go//go/platform:aix": [
"//dataplane/handlers",
"//dataplane/dplanerc",
],
"@io_bazel_rules_go//go/platform:android": [
"//dataplane/handlers",
"//dataplane/dplanerc",
],
"@io_bazel_rules_go//go/platform:darwin": [
"//dataplane/handlers",
"//dataplane/dplanerc",
],
"@io_bazel_rules_go//go/platform:dragonfly": [
"//dataplane/handlers",
"//dataplane/dplanerc",
],
"@io_bazel_rules_go//go/platform:freebsd": [
"//dataplane/handlers",
"//dataplane/dplanerc",
],
"@io_bazel_rules_go//go/platform:illumos": [
"//dataplane/handlers",
"//dataplane/dplanerc",
],
"@io_bazel_rules_go//go/platform:ios": [
"//dataplane/handlers",
"//dataplane/dplanerc",
],
"@io_bazel_rules_go//go/platform:js": [
"//dataplane/handlers",
"//dataplane/dplanerc",
],
"@io_bazel_rules_go//go/platform:linux": [
"//dataplane/handlers",
"//dataplane/dplanerc",
],
"@io_bazel_rules_go//go/platform:netbsd": [
"//dataplane/handlers",
"//dataplane/dplanerc",
],
"@io_bazel_rules_go//go/platform:openbsd": [
"//dataplane/handlers",
"//dataplane/dplanerc",
],
"@io_bazel_rules_go//go/platform:plan9": [
"//dataplane/handlers",
"//dataplane/dplanerc",
],
"@io_bazel_rules_go//go/platform:solaris": [
"//dataplane/handlers",
"//dataplane/dplanerc",
],
"@io_bazel_rules_go//go/platform:windows": [
"//dataplane/handlers",
"//dataplane/dplanerc",
],
"//conditions:default": [],
}),
Expand Down
12 changes: 12 additions & 0 deletions dataplane/config/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "config",
srcs = ["config.go"],
importpath = "github.com/openconfig/lemming/dataplane/config",
visibility = ["//visibility:public"],
deps = [
"//proto/forwarding",
"@com_github_spf13_viper//:viper",
],
)
30 changes: 30 additions & 0 deletions dataplane/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package config

import (
"github.com/spf13/viper"

fwdpb "github.com/openconfig/lemming/proto/forwarding"
)

const (
// NetDevForwardingType configures the forwarding type of a SAI netdev hostif. Options are (KERNEL and TAP).
NetDevForwardingType = "dataplane.netDevType"
)

func init() {
viper.Set(NetDevForwardingType, fwdpb.PortType_name[int32(fwdpb.PortType_PORT_TYPE_KERNEL)])
}
18 changes: 13 additions & 5 deletions dataplane/handlers/BUILD → dataplane/dplanerc/BUILD
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "handlers",
name = "dplanerc",
srcs = [
"interface.go",
"routes.go",
],
importpath = "github.com/openconfig/lemming/dataplane/handlers",
importpath = "github.com/openconfig/lemming/dataplane/dplanerc",
visibility = ["//visibility:public"],
deps = [
"//dataplane/internal/engine",
"//dataplane/standalone/proto:sai",
"//gnmi",
"//gnmi/reconciler",
"//proto/dataplane",
"//proto/forwarding",
"@com_github_golang_glog//:glog",
"@com_github_google_gopacket//:gopacket",
"@com_github_google_gopacket//layers",
"@com_github_openconfig_ygnmi//schemaless",
"@com_github_openconfig_ygnmi//ygnmi",
"@org_golang_google_protobuf//proto",
] + select({
"@io_bazel_rules_go//go/platform:android": [
"//dataplane/forwarding/fwdconfig",
"//dataplane/internal/kernel",
"//dataplane/standalone/packetio/cpusink",
"//gnmi/gnmiclient",
"//gnmi/oc",
"//gnmi/oc/ocpath",
"//proto/forwarding",
"@com_github_openconfig_ygot//ygot",
"@com_github_vishvananda_netlink//:netlink",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_x_sys//unix",
],
"@io_bazel_rules_go//go/platform:linux": [
"//dataplane/forwarding/fwdconfig",
"//dataplane/internal/kernel",
"//dataplane/standalone/packetio/cpusink",
"//gnmi/gnmiclient",
"//gnmi/oc",
"//gnmi/oc/ocpath",
"//proto/forwarding",
"@com_github_openconfig_ygot//ygot",
"@com_github_vishvananda_netlink//:netlink",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_x_sys//unix",
],
"//conditions:default": [],
Expand Down
Loading

0 comments on commit b22a398

Please sign in to comment.