Skip to content

Commit

Permalink
Initialize gNPSI repo: Add relay service and server implementation.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 608751064
  • Loading branch information
RazorBach committed Feb 28, 2024
1 parent 63598e2 commit 26afdd5
Show file tree
Hide file tree
Showing 19 changed files with 743 additions and 803 deletions.
6 changes: 6 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build --cxxopt='-std=c++17' --host_cxxopt='-std=c++17'
run --cxxopt='-std=c++17' --host_cxxopt='-std=c++17'

# To allow loops with int and comparison against a .size() that's size_t.
build --copt='-Wno-sign-compare' --host_copt='-Wno-sign-compare'
run --copt='-Wno-sign-compare' --host_copt='-Wno-sign-compare'
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.4.0
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
bazel-${{ runner.os }}-build-
- name: Install bazelisk
run: |
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.8.1/$BAZEL"
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.17.0/$BAZEL"
chmod +x $BAZEL
sudo mv $BAZEL /usr/local/bin/bazel
- name: Build
run: bazel build //...
run: bazel build //...
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 Google LLC
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,4 @@
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.
limitations under the License.
39 changes: 38 additions & 1 deletion WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 Google LLC
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -21,10 +21,47 @@ load("gnpsi_deps.bzl", "gnpsi_deps")

gnpsi_deps()

# -- Load GRPC Dependencies ----------------------------------------------------
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")

switched_rules_by_language(
name = "com_google_googleapis_imports",
cc = True,
grpc = True,
go = True,
)

load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")

grpc_deps()

load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")

grpc_extra_deps()

# -- Load Protobuf -------------------------------------------------------------

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")

rules_proto_dependencies()

rules_proto_toolchains()



### Bazel rules for many languages to compile PROTO into gRPC libraries
http_archive(
name = "rules_proto_grpc",
sha256 = "bbe4db93499f5c9414926e46f9e35016999a4e9f6e3522482d3760dc61011070",
strip_prefix = "rules_proto_grpc-4.2.0",
urls = ["https://github.com/rules-proto-grpc/rules_proto_grpc/archive/4.2.0.tar.gz"],
)

load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_repos", "rules_proto_grpc_toolchains")

rules_proto_grpc_toolchains()
rules_proto_grpc_repos()
12 changes: 12 additions & 0 deletions bazel/patches/grpc-001-fix_file_watcher_race_condition.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/src/core/lib/iomgr/load_file.cc b/src/core/lib/iomgr/load_file.cc
index 9068670118..a4d9bc95b2 100644
--- a/src/core/lib/iomgr/load_file.cc
+++ b/src/core/lib/iomgr/load_file.cc
@@ -55,7 +55,6 @@ grpc_error_handle grpc_load_file(const char* filename, int add_null_terminator,
if (bytes_read < contents_size) {
gpr_free(contents);
error = GRPC_OS_ERROR(errno, "fread");
- GPR_ASSERT(ferror(file));
goto end;
}
if (add_null_terminator) {
11 changes: 5 additions & 6 deletions compile_protos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# 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
# 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,
Expand All @@ -15,11 +15,10 @@
#

#!/bin/bash
set -euo pipefail


# Go
for p in gnpsi; do
protoc --go-grpc_out=. --go-grpc_opt=paths=source_relative --go_out=. --go_opt=paths=source_relative proto/$p/$p.proto
done
# Cpp
PROTO_DIR="proto/gnpsi"
protoc -I $PROTO_DIR --grpc_out=$PROTO_DIR --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` $PROTO_DIR/gnpsi.proto
protoc -I $PROTO_DIR --cpp_out=$PROTO_DIR $PROTO_DIR/gnpsi.proto

61 changes: 47 additions & 14 deletions gnpsi_deps.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 Google LLC
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -21,31 +21,64 @@ def gnpsi_deps():
if not native.existing_rule("com_github_grpc_grpc"):
http_archive(
name = "com_github_grpc_grpc",
url = "https://github.com/grpc/grpc/archive/refs/tags/v1.43.2.tar.gz",
strip_prefix = "grpc-1.43.2",
sha256 = "b74ce7d26fe187970d1d8e2c06a5d3391122f7bc1fdce569aff5e435fb8fe780",
url = "https://github.com/grpc/grpc/archive/v1.61.0.zip",
strip_prefix = "grpc-1.61.0",
sha256 = "ba6c53c3924a1d01c663352010e0f73736bad3d99d72108e0f2b1a6466f9be20",
patch_args = ["-p1"],
patches = [
"@com_github_openconfig_gnpsi//:bazel/patches/grpc-001-fix_file_watcher_race_condition.patch",
],
)
if not native.existing_rule("com_google_absl"):
http_archive(
name = "com_google_absl",
url = "https://github.com/abseil/abseil-cpp/archive/20230802.0.tar.gz",
strip_prefix = "abseil-cpp-20230802.0",
sha256 = "59d2976af9d6ecf001a81a35749a6e551a335b949d34918cfade07737b9d93c5",
)
if not native.existing_rule("com_google_googletest"):
http_archive(
name = "com_google_googletest",
urls = ["https://github.com/google/googletest/archive/release-1.11.0.tar.gz"],
strip_prefix = "googletest-release-1.11.0",
sha256 = "b4870bf121ff7795ba20d20bcdd8627b8e088f2d1dab299a031c1034eddc93d5",
)
if not native.existing_rule("com_google_protobuf"):
http_archive(
name = "com_google_protobuf",
url = "https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protobuf-all-3.19.4.tar.gz",
strip_prefix = "protobuf-3.19.4",
sha256 = "ba0650be1b169d24908eeddbe6107f011d8df0da5b1a5a4449a913b10e578faf",
url = "https://github.com/protocolbuffers/protobuf/archive/refs/tags/v25.2.zip",
strip_prefix = "protobuf-25.2",
sha256 = "ddd0f5271f31b549efc74eb39061e142132653d5d043071fcec265bd571e73c4",
)
if not native.existing_rule("com_google_googleapis"):
http_archive(
name = "com_google_googleapis",
url = "https://github.com/googleapis/googleapis/archive/ccb9d245ddac58b8d4ad918e6a914e841a64cc28.zip",
strip_prefix = "googleapis-ccb9d245ddac58b8d4ad918e6a914e841a64cc28",
sha256 = "feca5804fa0af2bc48d041a8b6e0356fb9e4848b3dd6ee74ab847022e90c69ff",
url = "https://github.com/googleapis/googleapis/archive/f405c718d60484124808adb7fb5963974d654bb4.zip",
strip_prefix = "googleapis-f405c718d60484124808adb7fb5963974d654bb4",
sha256 = "406b64643eede84ce3e0821a1d01f66eaf6254e79cb9c4f53be9054551935e79",
)
if not native.existing_rule("com_github_google_glog"):
http_archive(
name = "com_github_google_glog",
url = "https://github.com/google/glog/archive/v0.6.0.tar.gz",
strip_prefix = "glog-0.6.0",
sha256 = "8a83bf982f37bb70825df71a9709fa90ea9f4447fb3c099e1d720a439d88bad6",
)

# Needed to make glog happy.
if not native.existing_rule("com_github_gflags_gflags"):
http_archive(
name = "com_github_gflags_gflags",
url = "https://github.com/gflags/gflags/archive/v2.2.2.tar.gz",
strip_prefix = "gflags-2.2.2",
sha256 = "34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf",
)
if not native.existing_rule("rules_proto"):
http_archive(
name = "rules_proto",
sha256 = "66bfdf8782796239d3875d37e7de19b1d94301e8972b3cbd2446b332429b4df1",
strip_prefix = "rules_proto-4.0.0",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0.tar.gz",
"https://github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0.tar.gz",
"https://github.com/bazelbuild/rules_proto/archive/5.3.0-21.7.tar.gz",
],
strip_prefix = "rules_proto-5.3.0-21.7",
sha256 = "dc3fb206a2cb3441b485eb1e423165b231235a1ea9b031b4433cf7bc1fa460dd",
)
20 changes: 16 additions & 4 deletions proto/gnpsi/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 Google LLC
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,11 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Supporting infrastructure for implementing and testing PINS.
#

load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")

# gnpsi defines a gRPC-based network packet sampling interface implemented on
# vendor network elements. It provides mechanisms for streaming packet
# samples/updates from the network element.
package(
default_visibility = ["//visibility:public"],
licenses = ["notice"],
Expand All @@ -25,10 +26,21 @@ package(
proto_library(
name = "gnpsi_proto",
srcs = ["gnpsi.proto"],
import_prefix = "github.com/openconfig/gnpsi",
deps = [
"@com_google_protobuf//:any_proto",
"@com_google_protobuf//:descriptor_proto",
],
)

cc_proto_library(
name = "gnpsi_cc_proto",
deps = [":gnpsi_proto"],
)

cc_grpc_library(
name = "gnpsi_grpc_proto",
srcs = [":gnpsi_proto"],
generate_mocks = True,
grpc_only = ["True"],
deps = [":gnpsi_cc_proto"],
)
Loading

0 comments on commit 26afdd5

Please sign in to comment.