ONOS-6559 P4Runtime protocol library

Change-Id: I7070b69507dcf2ca47ee1c446bcc2505ca868fb1
diff --git a/protocols/p4runtime/proto/BUCK b/protocols/p4runtime/proto/BUCK
new file mode 100644
index 0000000..f7ef33e
--- /dev/null
+++ b/protocols/p4runtime/proto/BUCK
@@ -0,0 +1,55 @@
+include_defs(
+    '//bucklets/grpc.bucklet'
+)
+
+P4RT_PROTOC_VER = '3.0.2'
+P4RT_GRPC_VER = '1.3.0'
+
+PI_COMMIT = 'f110570ca0c8ddc5feaf5028b08a0f477ceb4eea'
+PI_BASEURL = 'https://github.com/p4lang/PI.git'
+
+# Wondering which .proto files to build? Check p4runtime's Makefile:
+# https://github.com/p4lang/PI/blob/master/proto/Makefile.am
+PROTO_SRCS = [
+    '/proto/p4/p4runtime.proto',
+    '/proto/p4/config/p4info.proto',
+    '/proto/google/rpc/status.proto',
+    '/proto/google/rpc/code.proto',
+    '/proto/p4/tmp/p4config.proto',
+]
+
+COMPILE_DEPS = [
+'//lib:CORE_DEPS',
+'//incubator/grpc-dependencies:grpc-core-repkg-' + P4RT_GRPC_VER,
+'//lib:grpc-stub-' + P4RT_GRPC_VER,
+'//lib:grpc-protobuf-' + P4RT_GRPC_VER,
+'//lib:protobuf-java-' + P4RT_PROTOC_VER,
+]
+
+genrule(
+    name = 'p4lang-pi-repo-' + PI_COMMIT,
+    bash = 'git clone --quiet ' + PI_BASEURL + ' $OUT > /dev/null && '
+    + 'cd $OUT && '
+    + 'git checkout --quiet -b buck-build ' + PI_COMMIT + ' > /dev/null && '
+    + 'git submodule update --quiet --init --recursive > /dev/null',
+    out = 'repo',
+)
+
+def get_proto_src_string():
+    proto_srcs = map(lambda x: "$(location :p4lang-pi-repo-%s)%s"  % (PI_COMMIT, x), PROTO_SRCS)
+    return " ".join(proto_srcs)
+
+grpc_jar(
+    src_string = get_proto_src_string(),
+    proto_paths = [
+        '$(location :p4lang-pi-repo-' + PI_COMMIT + ')/proto',
+    ],
+    protoc_version = P4RT_PROTOC_VER,
+    plugin_version = P4RT_GRPC_VER,
+    deps = COMPILE_DEPS,
+    include_std_lib = True,
+)
+
+project_config(
+    src_target = ':onos-protocols-p4runtime-proto'
+)
\ No newline at end of file