From 6b9ea2687a375e9eff8cfec29cb56fc8231d0d35 Mon Sep 17 00:00:00 2001 From: Eric Seifert Date: Wed, 26 Feb 2020 13:57:25 -0800 Subject: [PATCH 01/13] Move files back to original location, take Makefile/README from upstream --- .gitignore | 5 +- Makefile | 162 +- README.md | 12 +- {src/common_utils => common_utils}/context.go | 0 .../dialout_client/dialout_client.go | 0 .../dialout_client/dialout_client_test.go | 0 .../dialout_client_cli/dialout_client_cli.go | 0 .../dialout_server/dialout_server.go | 0 .../dialout_server_cli/dialout_server_cli.go | 0 .../gnmi_clients => gnmi_clients}/gnmi_get.go | 0 .../gnmi_clients => gnmi_clients}/gnmi_set.go | 0 .../gnoi_client.go | 0 {src/gnmi_server => gnmi_server}/basicAuth.go | 0 .../clientCertAuth.go | 0 .../client_subscribe.go | 0 {src/gnmi_server => gnmi_server}/gnoi.go | 0 {src/gnmi_server => gnmi_server}/jwtAuth.go | 0 {src/gnmi_server => gnmi_server}/pamAuth.go | 0 .../run_gnmi_server_test.sh | 0 {src/gnmi_server => gnmi_server}/server.go | 0 .../server_test.go | 0 {src/proto => proto}/README.md | 0 {src/proto => proto}/dial_out.pb.go | 0 {src/proto => proto}/dial_out.proto | 0 {src/proto => proto}/gnoi/sonic.pb.go | 0 {src/proto => proto}/gnoi/sonic.proto | 0 {src/proto => proto}/gnoi/sonicpb_test.go | 0 {src/proto => proto}/sonic.pb.go | 0 {src/proto => proto}/sonic.proto | 0 {src/proto => proto}/sonic_internal.pb.go | 0 {src/proto => proto}/sonic_internal.proto | 0 .../db_client.go | 0 .../non_db_client.go | 0 .../transl_data_client.go | 0 .../trie.go | 0 .../virtual_db.go | 0 .../openconfig/gnmi/CONTRIBUTING.md | 23 - .../src/github.com/openconfig/gnmi/LICENSE | 202 -- .../src/github.com/openconfig/gnmi/README.md | 26 - .../github.com/openconfig/gnmi/cache/cache.go | 780 ----- .../openconfig/gnmi/cache/cache_test.go | 1248 -------- .../src/github.com/openconfig/gnmi/cli/cli.go | 389 --- .../openconfig/gnmi/cli/cli_test.go | 859 ------ .../openconfig/gnmi/client/cache.go | 116 - .../openconfig/gnmi/client/cache_test.go | 244 -- .../openconfig/gnmi/client/client.go | 215 -- .../openconfig/gnmi/client/client_test.go | 566 ---- .../openconfig/gnmi/client/fake/fake.go | 165 -- .../openconfig/gnmi/client/fake/fake_test.go | 69 - .../gnmi/client/flags/flags_test.go | 246 -- .../openconfig/gnmi/client/flags/intmap.go | 79 - .../gnmi/client/flags/stringlist.go | 50 - .../openconfig/gnmi/client/flags/stringmap.go | 71 - .../openconfig/gnmi/client/gnmi/client.go | 310 -- .../gnmi/client/gnmi/client_test.go | 519 ---- .../gnmi/client/gnmi/credentials.go | 55 - .../openconfig/gnmi/client/grpcutil/lookup.go | 59 - .../gnmi/client/grpcutil/lookup_test.go | 71 - .../openconfig/gnmi/client/notification.go | 64 - .../openconfig/gnmi/client/query.go | 278 -- .../openconfig/gnmi/client/reconnect.go | 200 -- .../openconfig/gnmi/client/reconnect_test.go | 102 - .../openconfig/gnmi/client/register.go | 196 -- .../openconfig/gnmi/client/values.go | 76 - .../openconfig/gnmi/cmd/gnmi_cli/gnmi_cli.go | 366 --- .../gnmi/cmd/gnmi_cli/gnmi_cli_test.go | 66 - .../gnmi/cmd/gnmi_collector/docker/Dockerfile | 22 - .../gnmi/cmd/gnmi_collector/docker/README.md | 33 - .../gnmi/cmd/gnmi_collector/docker/build.sh | 19 - .../cmd/gnmi_collector/docker/config/cert.pem | 31 - .../gnmi_collector/docker/config/example.cfg | 28 - .../cmd/gnmi_collector/docker/config/key.pem | 52 - .../gnmi/cmd/gnmi_collector/docker/run.sh | 20 - .../gnmi_collector/docker/supervisord.conf | 17 - .../gnmi/cmd/gnmi_collector/gnmi_collector.go | 228 -- .../cmd/gnmi_collector/gnmi_collector_test.go | 113 - .../gnmi/cmd/gnmi_collector/testdata/bad.cfg | 28 - .../gnmi/cmd/gnmi_collector/testdata/bad.crt | 11 - .../gnmi/cmd/gnmi_collector/testdata/bad.key | 12 - .../gnmi/cmd/gnmi_collector/testdata/good.cfg | 28 - .../gnmi/cmd/gnmi_collector/testdata/good.crt | 24 - .../gnmi/cmd/gnmi_collector/testdata/good.key | 28 - .../gnmi_collector/testdata/unparseable.cfg | 29 - .../openconfig/gnmi/coalesce/coalesce.go | 168 -- .../openconfig/gnmi/coalesce/coalesce_test.go | 146 - .../openconfig/gnmi/compile_protos.sh | 31 - .../openconfig/gnmi/connection/connection.go | 158 -- .../gnmi/connection/connection_test.go | 297 -- .../github.com/openconfig/gnmi/ctree/tree.go | 439 --- .../openconfig/gnmi/ctree/tree_test.go | 797 ------ .../openconfig/gnmi/errdiff/errdiff.go | 174 -- .../openconfig/gnmi/errdiff/errdiff_test.go | 211 -- .../openconfig/gnmi/errlist/errlist.go | 171 -- .../openconfig/gnmi/errlist/errlist_test.go | 159 -- .../github.com/openconfig/gnmi/match/match.go | 143 - .../openconfig/gnmi/match/match_test.go | 307 -- .../openconfig/gnmi/metadata/metadata.go | 211 -- .../openconfig/gnmi/metadata/metadata_test.go | 135 - .../github.com/openconfig/gnmi/path/path.go | 115 - .../openconfig/gnmi/path/path_test.go | 199 -- .../openconfig/gnmi/proto/gnmi/gnmi.pb.go | 2524 ----------------- .../openconfig/gnmi/proto/gnmi/gnmi.proto | 456 --- .../openconfig/gnmi/proto/gnmi/gnmi_pb2.py | 1891 ------------ .../gnmi/proto/gnmi/gnmi_pb2_grpc.py | 113 - .../gnmi/proto/gnmi_ext/gnmi_ext.pb.go | 361 --- .../gnmi/proto/gnmi_ext/gnmi_ext.proto | 73 - .../gnmi/proto/gnmi_ext/gnmi_ext_pb2.py | 295 -- .../gnmi/proto/gnmi_ext/gnmi_ext_pb2_grpc.py | 3 - .../openconfig/gnmi/proto/target/target.pb.go | 274 -- .../openconfig/gnmi/proto/target/target.proto | 70 - .../gnmi/proto/target/target_pb2.py | 353 --- .../gnmi/proto/target/target_pb2_grpc.py | 3 - .../openconfig/gnmi/subscribe/subscribe.go | 483 ---- .../gnmi/subscribe/subscribe_test.go | 1797 ------------ .../openconfig/gnmi/target/target.go | 177 -- .../openconfig/gnmi/target/target_test.go | 433 --- .../gnmi/testing/fake/gnmi/agent.go | 173 -- .../gnmi/testing/fake/gnmi/client.go | 321 --- .../fake/gnmi/cmd/fake_server/README.md | 30 - .../cmd/fake_server/example-config.pb.txt | 2 - .../fake/gnmi/cmd/fake_server/server.go | 120 - .../gnmi/cmd/gen_fake_config/gen_config.go | 63 - .../gnmi/testing/fake/gnmi/gnmi_test.go | 459 --- .../gnmi/testing/fake/proto/fake.pb.go | 1514 ---------- .../gnmi/testing/fake/proto/fake.proto | 241 -- .../gnmi/testing/fake/proto/fake_pb2.py | 1208 -------- .../gnmi/testing/fake/proto/fake_pb2_grpc.py | 80 - .../gnmi/testing/fake/queue/fixed_queue.go | 81 - .../gnmi/testing/fake/queue/queue.go | 406 --- .../gnmi/testing/fake/queue/queue_test.go | 1081 ------- .../fake/testing/grpc/config/config_test.go | 28 - .../fake/testing/grpc/config/server_option.go | 40 - .../gnmi/unimplemented/unimplemented.go | 77 - .../github.com/openconfig/gnmi/value/value.go | 199 -- .../openconfig/gnmi/value/value_test.go | 338 --- .../github.com/openconfig/gnmi/watch/watch.go | 56 - src/testdata/tls/tls.go | 73 - src/testdata/tls/tls_test.go | 60 - {src/telemetry => telemetry}/telemetry.go | 0 .../CONFIG_PFCWD_PORTS.txt | 0 .../COUNTERS:Ethernet1.txt | 0 .../COUNTERS:Ethernet68.txt | 0 .../COUNTERS:Ethernet68:Pfcwd.txt | 0 .../COUNTERS:Ethernet68:Pfcwd_alias.txt | 0 .../COUNTERS:Ethernet68:Queues.txt | 0 .../COUNTERS:Ethernet68:Queues_alias.txt | 0 .../COUNTERS:Ethernet_wildcard.txt | 0 .../COUNTERS:Ethernet_wildcard_PFC_7_RX.txt | 0 ...NTERS:Ethernet_wildcard_PFC_7_RX_alias.txt | 0 ...COUNTERS:Ethernet_wildcard_Pfcwd_alias.txt | 0 .../COUNTERS:Ethernet_wildcard_Queues.txt | 0 ...OUNTERS:Ethernet_wildcard_Queues_alias.txt | 0 .../COUNTERS:Ethernet_wildcard_alias.txt | 0 .../COUNTERS:oid:0x1500000000091c.txt | 0 .../COUNTERS:oid:0x1500000000091e.txt | 0 .../COUNTERS:oid:0x1500000000091f.txt | 0 .../COUNTERS:oid:0x1500000000092a.txt | 0 .../COUNTERS_PORT_ALIAS_MAP.txt | 0 .../COUNTERS_PORT_NAME_MAP.txt | 0 .../COUNTERS_QUEUE_NAME_MAP.txt | 0 .../check_interface_mtu_set.json | 0 {src/testdata => testdata}/interfaces.json | 0 .../json_tests/README.md | 0 .../json_tests/data_vrf.json | 0 .../json_tests/interface_ipv4.json | 0 .../json_tests/interface_mtu.json | 0 .../json_tests/mgmt_vrf.json | 0 .../json_tests/vrf_intf_bind.json | 0 .../set_interface_ipv4.json | 0 .../set_interface_mtu.json | 0 .../fake/testing => testdata}/tls/tls.go | 0 .../fake/testing => testdata}/tls/tls_test.go | 0 .../transl_utils.go | 0 173 files changed, 89 insertions(+), 28340 deletions(-) rename {src/common_utils => common_utils}/context.go (100%) rename {src/dialout => dialout}/dialout_client/dialout_client.go (100%) rename {src/dialout => dialout}/dialout_client/dialout_client_test.go (100%) rename {src/dialout => dialout}/dialout_client_cli/dialout_client_cli.go (100%) rename {src/dialout => dialout}/dialout_server/dialout_server.go (100%) rename {src/dialout => dialout}/dialout_server_cli/dialout_server_cli.go (100%) rename {src/gnmi_clients => gnmi_clients}/gnmi_get.go (100%) rename {src/gnmi_clients => gnmi_clients}/gnmi_set.go (100%) rename {src/gnmi_clients => gnmi_clients}/gnoi_client.go (100%) rename {src/gnmi_server => gnmi_server}/basicAuth.go (100%) rename {src/gnmi_server => gnmi_server}/clientCertAuth.go (100%) rename {src/gnmi_server => gnmi_server}/client_subscribe.go (100%) rename {src/gnmi_server => gnmi_server}/gnoi.go (100%) rename {src/gnmi_server => gnmi_server}/jwtAuth.go (100%) rename {src/gnmi_server => gnmi_server}/pamAuth.go (100%) rename {src/gnmi_server => gnmi_server}/run_gnmi_server_test.sh (100%) rename {src/gnmi_server => gnmi_server}/server.go (100%) rename {src/gnmi_server => gnmi_server}/server_test.go (100%) rename {src/proto => proto}/README.md (100%) rename {src/proto => proto}/dial_out.pb.go (100%) rename {src/proto => proto}/dial_out.proto (100%) rename {src/proto => proto}/gnoi/sonic.pb.go (100%) rename {src/proto => proto}/gnoi/sonic.proto (100%) rename {src/proto => proto}/gnoi/sonicpb_test.go (100%) rename {src/proto => proto}/sonic.pb.go (100%) rename {src/proto => proto}/sonic.proto (100%) rename {src/proto => proto}/sonic_internal.pb.go (100%) rename {src/proto => proto}/sonic_internal.proto (100%) rename {src/sonic_data_client => sonic_data_client}/db_client.go (100%) rename {src/sonic_data_client => sonic_data_client}/non_db_client.go (100%) rename {src/sonic_data_client => sonic_data_client}/transl_data_client.go (100%) rename {src/sonic_data_client => sonic_data_client}/trie.go (100%) rename {src/sonic_data_client => sonic_data_client}/virtual_db.go (100%) delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/CONTRIBUTING.md delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/LICENSE delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/README.md delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cache/cache.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cache/cache_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cli/cli.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cli/cli_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/cache.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/cache_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/client.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/client_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/fake/fake.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/fake/fake_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/flags/flags_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/flags/intmap.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/flags/stringlist.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/flags/stringmap.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/gnmi/client.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/gnmi/client_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/gnmi/credentials.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/grpcutil/lookup.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/grpcutil/lookup_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/notification.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/query.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/reconnect.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/reconnect_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/register.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/client/values.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_cli/gnmi_cli.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_cli/gnmi_cli_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/Dockerfile delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/README.md delete mode 100755 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/build.sh delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/config/cert.pem delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/config/example.cfg delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/config/key.pem delete mode 100755 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/run.sh delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/supervisord.conf delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/gnmi_collector.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/gnmi_collector_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/bad.cfg delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/bad.crt delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/bad.key delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/good.cfg delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/good.crt delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/good.key delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/unparseable.cfg delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/coalesce/coalesce.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/coalesce/coalesce_test.go delete mode 100755 src/gnmi_clients/src/github.com/openconfig/gnmi/compile_protos.sh delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/connection/connection.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/connection/connection_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/ctree/tree.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/ctree/tree_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/errdiff/errdiff.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/errdiff/errdiff_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/errlist/errlist.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/errlist/errlist_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/match/match.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/match/match_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/metadata/metadata.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/metadata/metadata_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/path/path.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/path/path_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi/gnmi.pb.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi/gnmi.proto delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi/gnmi_pb2.py delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi/gnmi_pb2_grpc.py delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.pb.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.proto delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext_pb2.py delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext_pb2_grpc.py delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/proto/target/target.pb.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/proto/target/target.proto delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/proto/target/target_pb2.py delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/proto/target/target_pb2_grpc.py delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/subscribe/subscribe.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/subscribe/subscribe_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/target/target.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/target/target_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/agent.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/client.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/cmd/fake_server/README.md delete mode 100755 src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/cmd/fake_server/example-config.pb.txt delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/cmd/fake_server/server.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/cmd/gen_fake_config/gen_config.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/gnmi_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/proto/fake.pb.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/proto/fake.proto delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/proto/fake_pb2.py delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/proto/fake_pb2_grpc.py delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/queue/fixed_queue.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/queue/queue.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/queue/queue_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/testing/grpc/config/config_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/testing/grpc/config/server_option.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/unimplemented/unimplemented.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/value/value.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/value/value_test.go delete mode 100644 src/gnmi_clients/src/github.com/openconfig/gnmi/watch/watch.go delete mode 100644 src/testdata/tls/tls.go delete mode 100644 src/testdata/tls/tls_test.go rename {src/telemetry => telemetry}/telemetry.go (100%) rename {src/testdata => testdata}/CONFIG_PFCWD_PORTS.txt (100%) rename {src/testdata => testdata}/COUNTERS:Ethernet1.txt (100%) rename {src/testdata => testdata}/COUNTERS:Ethernet68.txt (100%) rename {src/testdata => testdata}/COUNTERS:Ethernet68:Pfcwd.txt (100%) rename {src/testdata => testdata}/COUNTERS:Ethernet68:Pfcwd_alias.txt (100%) rename {src/testdata => testdata}/COUNTERS:Ethernet68:Queues.txt (100%) rename {src/testdata => testdata}/COUNTERS:Ethernet68:Queues_alias.txt (100%) rename {src/testdata => testdata}/COUNTERS:Ethernet_wildcard.txt (100%) rename {src/testdata => testdata}/COUNTERS:Ethernet_wildcard_PFC_7_RX.txt (100%) rename {src/testdata => testdata}/COUNTERS:Ethernet_wildcard_PFC_7_RX_alias.txt (100%) rename {src/testdata => testdata}/COUNTERS:Ethernet_wildcard_Pfcwd_alias.txt (100%) rename {src/testdata => testdata}/COUNTERS:Ethernet_wildcard_Queues.txt (100%) rename {src/testdata => testdata}/COUNTERS:Ethernet_wildcard_Queues_alias.txt (100%) rename {src/testdata => testdata}/COUNTERS:Ethernet_wildcard_alias.txt (100%) rename {src/testdata => testdata}/COUNTERS:oid:0x1500000000091c.txt (100%) rename {src/testdata => testdata}/COUNTERS:oid:0x1500000000091e.txt (100%) rename {src/testdata => testdata}/COUNTERS:oid:0x1500000000091f.txt (100%) rename {src/testdata => testdata}/COUNTERS:oid:0x1500000000092a.txt (100%) rename {src/testdata => testdata}/COUNTERS_PORT_ALIAS_MAP.txt (100%) rename {src/testdata => testdata}/COUNTERS_PORT_NAME_MAP.txt (100%) rename {src/testdata => testdata}/COUNTERS_QUEUE_NAME_MAP.txt (100%) rename {src/testdata => testdata}/check_interface_mtu_set.json (100%) rename {src/testdata => testdata}/interfaces.json (100%) rename {src/testdata => testdata}/json_tests/README.md (100%) rename {src/testdata => testdata}/json_tests/data_vrf.json (100%) rename {src/testdata => testdata}/json_tests/interface_ipv4.json (100%) rename {src/testdata => testdata}/json_tests/interface_mtu.json (100%) rename {src/testdata => testdata}/json_tests/mgmt_vrf.json (100%) rename {src/testdata => testdata}/json_tests/vrf_intf_bind.json (100%) rename {src/testdata => testdata}/set_interface_ipv4.json (100%) rename {src/testdata => testdata}/set_interface_mtu.json (100%) rename {src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/testing => testdata}/tls/tls.go (100%) rename {src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/testing => testdata}/tls/tls_test.go (100%) rename {src/transl_utils => transl_utils}/transl_utils.go (100%) diff --git a/.gitignore b/.gitignore index c4d59f613..d798d462d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,8 @@ debian/files debian/sonic-telemetry.debhelper.log debian/sonic-telemetry.substvars debian/sonic-telemetry/ -telemetry +vendor +src +cvl +translib *.swp diff --git a/Makefile b/Makefile index 56f5094d1..f0a64b0e7 100644 --- a/Makefile +++ b/Makefile @@ -1,95 +1,91 @@ -all: precheck deps telemetry -GO=/usr/local/go/bin/go +ifeq ($(GOPATH),) +export GOPATH=/tmp/go +endif +export PATH := $(PATH):$(GOPATH)/bin +INSTALL := /usr/bin/install +DBDIR := /var/run/redis/sonic-db/ +GO := /usr/local/go/bin/go TOP_DIR := $(abspath ..) -TELEM_DIR := $(abspath .) -GOFLAGS:= -BUILD_DIR=build -GO_DEP_PATH=$(abspath .)/$(BUILD_DIR) GO_MGMT_PATH=$(TOP_DIR)/sonic-mgmt-framework -GO_SONIC_TELEMETRY_PATH=$(TOP_DIR) -CVL_GOPATH=$(GO_MGMT_PATH)/build/gopkgs:$(GO_MGMT_PATH):$(GO_MGMT_PATH)/src/cvl/build -GOPATH = $(CVL_GOPATH):$(GO_DEP_PATH):$(GO_MGMT_PATH):/tmp/go:$(GO_SONIC_TELEMETRY_PATH):$(TELEM_DIR) -INSTALL := /usr/bin/install +BUILD_DIR := $(GOPATH)/bin +export CVL_SCHEMA_PATH := $(GO_MGMT_PATH)/src/cvl/schema SRC_FILES=$(shell find . -name '*.go' | grep -v '_test.go' | grep -v '/tests/') TEST_FILES=$(wildcard *_test.go) TELEMETRY_TEST_DIR = $(GO_MGMT_PATH)/build/tests/gnmi_server TELEMETRY_TEST_BIN = $(TELEMETRY_TEST_DIR)/server.test -.PHONY : all precheck deps telemetry clean cleanall check install deinstall - -ifdef DEBUG - GOFLAGS += -gcflags="all=-N -l" -endif - -all: deps telemetry $(TELEMETRY_TEST_BIN) - -precheck: - $(shell mkdir -p $(BUILD_DIR)) - -deps: $(BUILD_DIR)/.deps - -$(BUILD_DIR)/.deps: $(MAKEFILE_LIST) - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/Workiva/go-datastructures/queue - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/goyang - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/ygot/ygot - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/golang/glog - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/go-redis/redis - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/c9s/goprocinfo/linux - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/golang/protobuf/proto - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/gnmi/proto/gnmi - GOPATH=$(GO_DEP_PATH) $(GO) get -u golang.org/x/net/context - GOPATH=$(GO_DEP_PATH) $(GO) get -u google.golang.org/grpc - GOPATH=$(GO_DEP_PATH) $(GO) get -u google.golang.org/grpc/credentials - GOPATH=$(GO_DEP_PATH) $(GO) get -u gopkg.in/go-playground/validator.v9 - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/gorilla/mux - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/goyang - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/ygot/ygot - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/google/gnxi/utils - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/jipanyang/gnxi/utils/xpath - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/jipanyang/gnmi/client/gnmi - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/xeipuuv/gojsonschema - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/gnoi/system - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/msteinert/pam - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/dgrijalva/jwt-go - GOPATH=$(GO_DEP_PATH) $(GO) get -u gopkg.in/godbus/dbus.v5 - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/gogo/protobuf/gogoproto - touch $@ +.phony: mgmt-deps + +all: sonic-telemetry $(TELEMETRY_TEST_BIN) + +go.mod: + /usr/local/go/bin/go mod init github.com/Azure/sonic-telemetry +mgmt-deps: + rm -rf cvl + rm -rf translib + cp -r ../sonic-mgmt-framework/src/cvl ./ + cp -r ../sonic-mgmt-framework/src/translib ./ + find cvl -name \*\.go -exec sed -i -e 's/\"translib/\"github.com\/Azure\/sonic-telemetry\/translib/g' {} \; + find translib -name \*\.go -exec sed -i -e 's/\"translib/\"github.com\/Azure\/sonic-telemetry\/translib/g' {} \; + find cvl -name \*\.go -exec sed -i -e 's/\"cvl/\"github.com\/Azure\/sonic-telemetry\/cvl/g' {} \; + find translib -name \*\.go -exec sed -i -e 's/\"cvl/\"github.com\/Azure\/sonic-telemetry\/cvl/g' {} \; + sed -i -e 's/\.\.\/\.\.\/\.\.\/models\/yang/\.\.\/\.\.\/\.\.\/sonic-mgmt-framework\/models\/yang/' translib/ocbinds/oc.go + sed -i -e 's/\$$GO run \$$BUILD_GOPATH\/src\/github.com\/openconfig\/ygot\/generator\/generator.go/generator/' translib/ocbinds/oc.go + $(GO) get github.com/openconfig/gnmi@89b2bf29312cda887da916d0f3a32c1624b7935f + $(GO) get github.com/openconfig/ygot@724a6b18a9224343ef04fe49199dfb6020ce132a + $(GO) get github.com/openconfig/goyang@064f9690516f4f72db189f4690b84622c13b7296 + $(GO) get github.com/openconfig/goyang@064f9690516f4f72db189f4690b84622c13b7296 + $(GO) get golang.org/x/crypto/ssh/terminal@e9b2fee46413 + $(GO) get github.com/jipanyang/gnxi@f0a90cca6fd0041625bcce561b71f849c9b65a8d + $(GO) install github.com/openconfig/ygot/generator + $(GO) get -x github.com/golang/glog@23def4e6c14b4da8ac2ed8007337bc5eb5007998 + rm -rf vendor + $(GO) mod vendor + ln -s vendor src + cp -r $(GOPATH)/pkg/mod/github.com/openconfig/gnmi@v0.0.0-20190823184014-89b2bf29312c/* vendor/github.com/openconfig/gnmi/ + cp -r $(GOPATH)/pkg/mod/github.com/openconfig/goyang@v0.0.0-20190924211109-064f9690516f/* vendor/github.com/openconfig/goyang/ + cp -r $(GOPATH)/pkg/mod/github.com/openconfig/ygot@v0.6.1-0.20190723223108-724a6b18a922/* vendor/github.com/openconfig/ygot/ + cp -r $(GOPATH)/pkg/mod/golang.org/x/crypto@v0.0.0-20191206172530-e9b2fee46413 vendor/golang.org/x/crypto + chmod -R u+w vendor + patch -d vendor -p0 to see -your current agreements on file or to sign a new one. - -You generally only need to submit a CLA once, so if you've already submitted one -(even if it was for a different project), you probably don't need to do it -again. - -## Code reviews - -All submissions, including submissions by project members, require review. We -accept GitHub pull requests, however all commits are made internally and -mirrored out. This is done so that our internal verification steps run before -any code is submitted. diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/LICENSE b/src/gnmi_clients/src/github.com/openconfig/gnmi/LICENSE deleted file mode 100644 index d64569567..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/README.md b/src/gnmi_clients/src/github.com/openconfig/gnmi/README.md deleted file mode 100644 index 0e2ef19ac..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/README.md +++ /dev/null @@ -1,26 +0,0 @@ -# gNMI - gRPC Network Management Interface - -This repository contains reference Go implementations for gNMI. - -**Note:** This is not an official Google product. - -The implementations include: - -- client library implementation using `gnmi.proto` -- CLI for interacting with a gNMI service -- Caching collector that connects to multiple gNMI targets and makes the data - available over a single gNMI Subscribe RPC to clients - -## Installing - -To install the CLI, run - - go get -u github.com/openconfig/gnmi/cmd/gnmi_cli - -## Client libraries - -The main entry point for using the client libraries is in -`github.com/openconfig/gnmi/client`. - -See [godoc pages](https://godoc.org/github.com/openconfig/gnmi/client) for -documentation and usage examples. diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cache/cache.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/cache/cache.go deleted file mode 100644 index db779d086..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cache/cache.go +++ /dev/null @@ -1,780 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 cache is a tree-based cache of timestamped state provided from -// one or more gNMI targets. It accepts updates from the target(s) to -// refresh internal values that are made available to clients via subscriptions. -package cache - -import ( - "encoding/json" - "errors" - "fmt" - "sync" - "time" - - log "github.com/golang/glog" - "github.com/golang/protobuf/proto" - "github.com/openconfig/gnmi/client" - "github.com/openconfig/gnmi/ctree" - "github.com/openconfig/gnmi/metadata" - "github.com/openconfig/gnmi/path" - "github.com/openconfig/gnmi/value" - - gpb "github.com/openconfig/gnmi/proto/gnmi" -) - -// CTreeType is used to switch between client.Notification and gnmi.Notification cache. -// An alternative was to create a totally separate call stack for gnmi.Notification, -// but for the sake of reusing existing functions, preferred a switch. -type CTreeType int - -const ( - // ClientLeaf indicates that client.Leaf is stored in the cache - ClientLeaf CTreeType = iota - - // GnmiNoti indicates that gnmi.Notification is stored in the cache - GnmiNoti -) - -// Type indicates what is stored in the cache -var Type CTreeType - -// T provides a shorthand function to reference a timestamp with an -// int64 (nanoseconds since epoch). -func T(n int64) time.Time { return time.Unix(0, n) } - -type latency struct { - mu sync.Mutex - totalDiff time.Duration // cumulative difference in timestamps from device - count int64 // number of updates in latency count - min time.Duration // minimum latency - max time.Duration // maximum latency -} - -// A Target hosts an indexed cache of state for a single target. -type Target struct { - name string // name of the target - t *ctree.Tree // actual cache of target data - client func(*ctree.Leaf) // Function to pass all cache updates to. - sync bool // denotes whether this cache is in sync with target - meta *metadata.Metadata // metadata associated with target - lat latency // latency measurements - tsmu sync.Mutex // protects latest timestamp - ts time.Time // latest timestamp for an update -} - -// Cache is a structure holding state information for multiple targets. -type Cache struct { - mu sync.RWMutex - targets map[string]*Target // Map of per target caches. - client func(*ctree.Leaf) // Function to pass all cache updates to. -} - -// New creates a new instance of Cache that receives target updates from the -// translator and provides an interface to service client queries. -func New(targets []string) *Cache { - c := &Cache{ - targets: make(map[string]*Target, len(targets)), - client: func(*ctree.Leaf) {}, - } - for _, t := range targets { - c.Add(t) - } - return c -} - -// SetClient registers a callback function to receive calls for each update -// accepted by the cache. This call should be made prior to sending any updates -// into the cache, just after initialization. -func (c *Cache) SetClient(client func(*ctree.Leaf)) { - c.mu.Lock() - defer c.mu.Unlock() - c.client = client - for _, t := range c.targets { - t.client = client - } -} - -// Metadata returns the per-target metadata structures. -func (c *Cache) Metadata() map[string]*metadata.Metadata { - md := map[string]*metadata.Metadata{} - defer c.mu.RUnlock() - c.mu.RLock() - for target, cache := range c.targets { - md[target] = cache.meta - } - return md -} - -// UpdateMetadata copies the current metadata for each target cache to the -// metadata path within each target cache. -func (c *Cache) UpdateMetadata() { - c.updateCache((*Target).updateMeta) -} - -// UpdateSize computes the size of each target cache and updates the size -// metadata reported within the each target cache. -func (c *Cache) UpdateSize() { - c.updateCache((*Target).updateSize) -} - -// GetTarget returns the Target from the cache corresponding to the target name. -func (c *Cache) GetTarget(target string) *Target { - defer c.mu.RUnlock() - c.mu.RLock() - return c.targets[target] -} - -// HasTarget reports whether the specified target exists in the cache or a glob -// (*) is passed which will match any target (even if no targets yet exist). -func (c *Cache) HasTarget(target string) bool { - switch target { - case "": - return false - case "*": - return true - default: - defer c.mu.RUnlock() - c.mu.RLock() - return c.targets[target] != nil - } -} - -// Query calls the specified callback for all results matching the query. All -// values passed to fn are client.Notification. -func (c *Cache) Query(target string, query []string, fn ctree.VisitFunc) error { - switch { - case target == "": - return errors.New("no target specified in query") - case target == "*": - c.mu.RLock() - // Run the query sequentially for each target cache. - for _, target := range c.targets { - target.t.Query(query, fn) - } - c.mu.RUnlock() - default: - dc := c.GetTarget(target) - if dc == nil { - return fmt.Errorf("target %q not found in cache", target) - } - dc.t.Query(query, fn) - } - return nil -} - -// Add reserves space in c to receive updates for the specified target. -func (c *Cache) Add(target string) *Target { - defer c.mu.Unlock() - c.mu.Lock() - t := &Target{t: &ctree.Tree{}, name: target, meta: metadata.New(), client: c.client} - c.targets[target] = t - return t -} - -// Reset clears the cache for a target once a connection is resumed after -// having been lost. -func (c *Cache) Reset(target string) { - if t := c.GetTarget(target); t != nil { - t.Reset() - } -} - -// Remove removes the space in c corresponding to the specified target. -func (c *Cache) Remove(target string) { - defer c.mu.Unlock() - c.mu.Lock() - delete(c.targets, target) - // Notify clients that the target is removed. - switch Type { - case GnmiNoti: - c.client(ctree.DetachedLeaf(deleteNoti(target, "", []string{"*"}))) - case ClientLeaf: - c.client(ctree.DetachedLeaf(client.Delete{Path: []string{target}, TS: time.Now()})) - default: - log.Errorf("cache type is invalid: %v", Type) - } -} - -// Sync creates an internal gnmi.Notification with metadata/sync path -// to set the state to true for the specified target. -func (c *Cache) Sync(name string) { - if target := c.GetTarget(name); target != nil { - target.Sync() - } -} - -// Sync creates an internal gnmi.Notification with metadata/sync path -// to set the state to true for the specified target. -func (t *Target) Sync() { - if err := t.GnmiUpdate(metaNotiBool(t.name, metadata.Sync, true)); err != nil { - log.Errorf("target %q got error during meta sync update, %v", t.name, err) - } -} - -// Connect creates an internal gnmi.Notification for metadata/connected path -// to set the state to true for the specified target. -func (c *Cache) Connect(name string) { - if target := c.GetTarget(name); target != nil { - target.Connect() - } -} - -// Connect creates an internal gnmi.Notification for metadata/connected path -// to set the state to true for the specified target. -func (t *Target) Connect() { - if err := t.GnmiUpdate(metaNotiBool(t.name, metadata.Connected, true)); err != nil { - log.Errorf("target %q got error during meta connected update, %v", t.name, err) - } -} - -// Disconnect creates internal gnmi.Notifications for metadata/sync and -// metadata/connected paths to set their states to false for the specified target. -func (c *Cache) Disconnect(name string) { - if target := c.GetTarget(name); target != nil { - target.Disconnect() - } -} - -// Disconnect creates internal gnmi.Notifications for metadata/sync and -// metadata/connected paths to set their states to false for the specified target. -func (t *Target) Disconnect() { - if err := t.GnmiUpdate(metaNotiBool(t.name, metadata.Sync, false)); err != nil { - log.Errorf("target %q got error during meta sync update, %v", t.name, err) - } - if err := t.GnmiUpdate(metaNotiBool(t.name, metadata.Connected, false)); err != nil { - log.Errorf("target %q got error during meta connected update, %v", t.name, err) - } -} - -// Update sends a client.Notification into the cache. -func (c *Cache) Update(n client.Notification) error { - var l client.Leaf - switch u := n.(type) { - case client.Update: - l = (client.Leaf)(u) - case client.Delete: - l = (client.Leaf)(u) - default: - return fmt.Errorf("received unsupported client.Notification: %#v", n) - } - if len(l.Path) == 0 { - return errors.New("client.Update contained no Path") - } - name := l.Path[0] - target := c.GetTarget(name) - if target == nil { - return fmt.Errorf("target %q not found in cache", name) - } - target.checkTimestamp(l.TS) - switch u := n.(type) { - case client.Update: - nd, err := target.update(u) - if err != nil { - return err - } - if nd != nil { - c.client(nd) - } - case client.Delete: - for _, nd := range target.remove(u) { - c.client(nd) - } - } - return nil -} - -// GnmiUpdate sends a gpb.Notification into the cache. -// If the notification has multiple Updates/Deletes, -// each individual Update/Delete is sent to cache as -// a separate gnmi.Notification. -func (c *Cache) GnmiUpdate(n *gpb.Notification) error { - if n == nil { - return errors.New("gnmi.Notification is nil") - } - if n.GetPrefix() == nil { - return errors.New("gnmi.Notification prefix is nil") - } - target := c.GetTarget(n.GetPrefix().GetTarget()) - if target == nil { - return fmt.Errorf("target %q not found in cache", n.GetPrefix().GetTarget()) - } - return target.GnmiUpdate(n) -} - -// GnmiUpdate sends a gpb.Notification into the target cache. -// If the notification has multiple Updates/Deletes, -// each individual Update/Delete is sent to cache as -// a separate gnmi.Notification. -func (t *Target) GnmiUpdate(n *gpb.Notification) error { - t.checkTimestamp(T(n.GetTimestamp())) - // Store atomic notifications as a single leaf in the tree. - if n.Atomic { - t.meta.AddInt(metadata.UpdateCount, int64(len(n.GetUpdate()))) - nd, err := t.gnmiUpdate(n) - if err != nil { - return err - } - if nd != nil { - t.client(nd) - } - return nil - } - // Break non-atomic notifications with individual leaves per update. - updates := n.GetUpdate() - deletes := n.GetDelete() - n.Update, n.Delete = nil, nil - // restore back the notification updates and deletes - defer func() { - n.Update = updates - n.Delete = deletes - }() - for _, u := range updates { - noti := proto.Clone(n).(*gpb.Notification) - noti.Update = []*gpb.Update{u} - nd, err := t.gnmiUpdate(noti) - if err != nil { - return err - } - t.meta.AddInt(metadata.UpdateCount, 1) - if nd != nil { - t.client(nd) - } - } - - for _, d := range deletes { - noti := proto.Clone(n).(*gpb.Notification) - noti.Delete = []*gpb.Path{d} - t.meta.AddInt(metadata.UpdateCount, 1) - for _, nd := range t.gnmiRemove(noti) { - t.client(nd) - } - } - - return nil -} - -func (t *Target) checkTimestamp(ts time.Time) { - // Locking ensures that d.ts is always increasing regardless of the order in - // which updates are processed in parallel by multiple goroutines. - defer t.tsmu.Unlock() - t.tsmu.Lock() - // Track latest timestamp for a target. - if ts.After(t.ts) { - t.ts = ts - } -} - -func (t *Target) updateStatus(u client.Update) error { - switch u.Path[2] { - case metadata.Sync: - var ok bool - t.sync, ok = u.Val.(bool) - if !ok { - return fmt.Errorf("%v : has value %v of type %T, expected boolean", metadata.Path(metadata.Sync), u.Val, u.Val) - } - t.meta.SetBool(metadata.Sync, t.sync) - case metadata.Connected: - connected, ok := u.Val.(bool) - if !ok { - return fmt.Errorf("%v : has value %v of type %T, expected boolean", metadata.Path(metadata.Connected), u.Val, u.Val) - } - t.meta.SetBool(metadata.Connected, connected) - } - return nil -} - -func (t *Target) update(u client.Update) (*ctree.Leaf, error) { - path := u.Path[1:] - realData := true - switch { - case path[0] == metadata.Root: - if err := t.updateStatus(u); err != nil { - return nil, err - } - realData = false - case t.sync: - // Record latency for post-sync target updates. Exclude metadata updates. - t.lat.compute(u.TS) - } - // Update an existing leaf. - if oldval := t.t.GetLeaf(path); oldval != nil { - // Since we control what goes into the tree, oldval should always - // contain client.Update and there's no need to do a safe assertion. - old := oldval.Value().(client.Update) - if !old.TS.Before(u.TS) { - // Update rejected. Timestamp <= previous recorded timestamp. - t.meta.AddInt(metadata.StaleCount, 1) - return nil, errors.New("update is stale") - } - oldval.Update(u) - if realData { - t.meta.AddInt(metadata.UpdateCount, 1) - } - return oldval, nil - } - // Add a new leaf. - if err := t.t.Add(path, u); err != nil { - return nil, err - } - if realData { - t.meta.AddInt(metadata.UpdateCount, 1) - t.meta.AddInt(metadata.LeafCount, 1) - t.meta.AddInt(metadata.AddCount, 1) - } - return t.t.GetLeaf(path), nil -} - -func (t *Target) gnmiUpdate(n *gpb.Notification) (*ctree.Leaf, error) { - realData := true - suffix := n.Update[0].Path - // If the notification is an atomic group of updates, store them under the prefix only. - if n.Atomic { - suffix = nil - } - path := joinPrefixAndPath(n.Prefix, suffix) - switch { - case path[0] == metadata.Root: - realData = false - u := n.Update[0] - switch path[1] { - case metadata.Sync: - var ok bool - tv, ok := u.Val.Value.(*gpb.TypedValue_BoolVal) - if !ok { - return nil, fmt.Errorf("%v : has value %v of type %T, expected boolean", metadata.Path(metadata.Sync), u.Val, u.Val) - } - t.sync = tv.BoolVal - t.meta.SetBool(metadata.Sync, t.sync) - case metadata.Connected: - tv, ok := u.Val.Value.(*gpb.TypedValue_BoolVal) - if !ok { - return nil, fmt.Errorf("%v : has value %v of type %T, expected boolean", metadata.Path(metadata.Connected), u.Val, u.Val) - } - t.meta.SetBool(metadata.Connected, tv.BoolVal) - } - case t.sync: - // Record latency for post-sync target updates. Exclude metadata updates. - t.lat.compute(T(n.GetTimestamp())) - } - // Update an existing leaf. - if oldval := t.t.GetLeaf(path); oldval != nil { - // An update with corrupt data is possible to visit a node that does not - // contain *gpb.Notification. Thus, need type assertion here. - old, ok := oldval.Value().(*gpb.Notification) - if !ok { - return nil, fmt.Errorf("corrupt schema with collision for path %q, got %T", path, oldval.Value()) - } - if !T(old.GetTimestamp()).Before(T(n.GetTimestamp())) { - // Update rejected. Timestamp <= previous recorded timestamp. - t.meta.AddInt(metadata.StaleCount, 1) - return nil, errors.New("update is stale") - } - oldval.Update(n) - // Simulate event-driven for all non-atomic updates. - if !n.Atomic && value.Equal(old.Update[0].Val, n.Update[0].Val) { - t.meta.AddInt(metadata.SuppressedCount, 1) - return nil, errors.New("suppressed duplicate value") - } - return oldval, nil - } - // Add a new leaf. - if err := t.t.Add(path, n); err != nil { - return nil, err - } - if realData { - t.meta.AddInt(metadata.LeafCount, 1) - t.meta.AddInt(metadata.AddCount, 1) - } - return t.t.GetLeaf(path), nil -} - -func olderThan(t time.Time) func(interface{}) bool { - return func(x interface{}) bool { - var res bool - switch v := x.(type) { - case *gpb.Notification: - res = T(v.GetTimestamp()).Before(t) - case client.Update: - res = v.TS.Before(t) - } - return res - } -} - -func (t *Target) remove(u client.Delete) []*ctree.Leaf { - leaves := t.t.DeleteConditional(u.Path[1:], olderThan(u.TS)) - if len(leaves) == 0 { - return nil - } - deleted := int64(len(leaves)) - t.meta.AddInt(metadata.LeafCount, -deleted) - t.meta.AddInt(metadata.DelCount, deleted) - var ls []*ctree.Leaf - for _, l := range leaves { - ls = append(ls, ctree.DetachedLeaf(client.Delete{Path: append([]string{t.name}, l...), TS: u.TS})) - } - return ls -} - -func (t *Target) gnmiRemove(n *gpb.Notification) []*ctree.Leaf { - path := joinPrefixAndPath(n.Prefix, n.Delete[0]) - leaves := t.t.DeleteConditional(path, olderThan(T(n.GetTimestamp()))) - if len(leaves) == 0 { - return nil - } - deleted := int64(len(leaves)) - t.meta.AddInt(metadata.LeafCount, -deleted) - t.meta.AddInt(metadata.DelCount, deleted) - var ls []*ctree.Leaf - for _, l := range leaves { - noti := &gpb.Notification{ - Timestamp: n.GetTimestamp(), - Prefix: &gpb.Path{Target: n.GetPrefix().GetTarget()}, - Delete: []*gpb.Path{{Element: l}}, - } - ls = append(ls, ctree.DetachedLeaf(noti)) - } - return ls -} - -// updateCache calls fn for each Target. -func (c *Cache) updateCache(fn func(*Target, func(*ctree.Leaf))) { - defer c.mu.RUnlock() - c.mu.RLock() - for _, target := range c.targets { - fn(target, c.client) - } -} - -// updateSize walks the entire tree of the target, sums up marshaled sizes of -// all leaves and writes the sum in metadata. -func (t *Target) updateSize(func(*ctree.Leaf)) { - var s int64 - size := func(n interface{}) int64 { - buf, err := json.Marshal(n) - if err != nil { - return 0 - } - return int64(len(buf)) - } - t.t.Query([]string{"*"}, - func(_ []string, _ *ctree.Leaf, v interface{}) { - s += size(v) - }) - t.meta.SetInt(metadata.Size, s) -} - -// updateMeta updates the metadata values in the cache. -func (t *Target) updateMeta(clients func(*ctree.Leaf)) { - t.tsmu.Lock() - latest := t.ts - t.tsmu.Unlock() - t.meta.SetInt(metadata.LatestTimestamp, latest.UnixNano()) - - t.lat.updateReset(t.meta) - ts := time.Now() - for value := range metadata.TargetBoolValues { - v, err := t.meta.GetBool(value) - if err != nil { - continue - } - path := metadata.Path(value) - prev := t.t.GetLeafValue(path) - switch Type { - case ClientLeaf: - if prev == nil || prev.(client.Update).Val.(bool) != v { - if n, _ := t.update(client.Update{ - Path: append([]string{t.name}, path...), - Val: v, - TS: ts, - }); n != nil { - if clients != nil { - clients(n) - } - } - } - case GnmiNoti: - if prev == nil || prev.(*gpb.Notification).Update[0].Val.Value.(*gpb.TypedValue_BoolVal).BoolVal != v { - noti := metaNotiBool(t.name, value, v) - if n, _ := t.gnmiUpdate(noti); n != nil { - if clients != nil { - clients(n) - } - } - } - default: - log.Errorf("cache type is invalid: %v", Type) - } - } - - for value := range metadata.TargetIntValues { - v, err := t.meta.GetInt(value) - if err != nil { - continue - } - path := metadata.Path(value) - prev := t.t.GetLeafValue(path) - switch Type { - case ClientLeaf: - if prev == nil || prev.(client.Update).Val.(int64) != v { - if n, _ := t.update(client.Update{ - Path: append([]string{t.name}, path...), - Val: v, - TS: ts, - }); n != nil { - if clients != nil { - clients(n) - } - } - } - case GnmiNoti: - if prev == nil || prev.(*gpb.Notification).Update[0].Val.Value.(*gpb.TypedValue_IntVal).IntVal != v { - noti := metaNotiInt(t.name, value, v) - if n, _ := t.gnmiUpdate(noti); n != nil { - if clients != nil { - clients(n) - } - } - } - default: - log.Errorf("cache type is invalid: %v", Type) - } - } -} - -// Reset clears the Target of stale data upon a reconnection and notifies -// cache client of the removal. -func (t *Target) Reset() { - // Reset metadata to zero values (e.g. connected = false) and notify clients. - t.meta.Clear() - t.updateMeta(t.client) - resetTime := time.Now() - for root := range t.t.Children() { - if root == metadata.Root { - continue - } - t.t.Delete([]string{root}) - switch Type { - case ClientLeaf: - t.client(ctree.DetachedLeaf(client.Delete{Path: []string{t.name, root}, TS: resetTime})) - case GnmiNoti: - t.client(ctree.DetachedLeaf(deleteNoti(t.name, root, []string{"*"}))) - default: - log.Errorf("cache type is invalid: %v", Type) - } - } -} - -func (l *latency) compute(ts time.Time) { - l.mu.Lock() - defer l.mu.Unlock() - lat := time.Now().Sub(ts) - l.totalDiff += lat - l.count++ - if lat > l.max { - l.max = lat - } - if lat < l.min || l.min == 0 { - l.min = lat - } -} - -func (l *latency) updateReset(m *metadata.Metadata) { - l.mu.Lock() - defer l.mu.Unlock() - if l.count == 0 { - return - } - m.SetInt(metadata.LatencyAvg, (l.totalDiff / time.Duration(l.count)).Nanoseconds()) - m.SetInt(metadata.LatencyMax, l.max.Nanoseconds()) - m.SetInt(metadata.LatencyMin, l.min.Nanoseconds()) - l.totalDiff = 0 - l.count = 0 - l.min = 0 - l.max = 0 -} - -// IsTargetDelete is a convenience function that identifies a leaf as -// containing a delete notification for an entire target. -func IsTargetDelete(l *ctree.Leaf) bool { - switch v := l.Value().(type) { - case client.Delete: - return len(v.Path) == 1 - case *gpb.Notification: - if len(v.Delete) == 1 { - var orig string - if v.Prefix != nil { - orig = v.Prefix.Origin - } - // Prefix path is indexed without target and origin - p := path.ToStrings(v.Prefix, false) - p = append(p, path.ToStrings(v.Delete[0], false)...) - // When origin isn't set, intention must be to delete entire target. - return orig == "" && len(p) == 1 && p[0] == "*" - } - } - return false -} - -func joinPrefixAndPath(pr, ph *gpb.Path) []string { - // and are only valid as prefix gnmi.Path - // https://github.com/openconfig/reference/blob/master/rpc/gnmi-specification.md#222-paths - p := path.ToStrings(pr, true) - p = append(p, path.ToStrings(ph, false)...) - // remove the prepended target name - p = p[1:] - return p -} - -func deleteNoti(t, o string, p []string) *gpb.Notification { - pe := make([]*gpb.PathElem, 0, len(p)) - for _, e := range p { - pe = append(pe, &gpb.PathElem{Name: e}) - } - return &gpb.Notification{ - Timestamp: time.Now().UnixNano(), - Prefix: &gpb.Path{Target: t, Origin: o}, - Delete: []*gpb.Path{&gpb.Path{Elem: pe}}, - } -} - -func metaNoti(t, m string, v *gpb.TypedValue) *gpb.Notification { - mp := metadata.Path(m) - pe := make([]*gpb.PathElem, 0, len(mp)) - for _, p := range mp { - pe = append(pe, &gpb.PathElem{Name: p}) - } - return &gpb.Notification{ - Timestamp: time.Now().UnixNano(), - Prefix: &gpb.Path{Target: t}, - Update: []*gpb.Update{ - &gpb.Update{ - Path: &gpb.Path{Elem: pe}, - Val: v, - }, - }, - } -} - -func metaNotiBool(t, m string, v bool) *gpb.Notification { - return metaNoti(t, m, &gpb.TypedValue{Value: &gpb.TypedValue_BoolVal{v}}) -} - -func metaNotiInt(t, m string, v int64) *gpb.Notification { - return metaNoti(t, m, &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{v}}) -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cache/cache_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/cache/cache_test.go deleted file mode 100644 index 458faff1d..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cache/cache_test.go +++ /dev/null @@ -1,1248 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 cache - -import ( - "fmt" - "math/rand" - "reflect" - "runtime" - "sort" - "strconv" - "strings" - "sync" - "testing" - "time" - - "github.com/golang/protobuf/proto" - "github.com/google/go-cmp/cmp" - "github.com/openconfig/gnmi/client" - "github.com/openconfig/gnmi/ctree" - "github.com/openconfig/gnmi/errdiff" - "github.com/openconfig/gnmi/metadata" - - gpb "github.com/openconfig/gnmi/proto/gnmi" -) - -func TestHasTarget(t *testing.T) { - c := New(nil) - for _, tt := range []string{"", "dev1", "dev2", "dev3"} { - if c.HasTarget(tt) { - t.Errorf("HasTarget(%q) got true for empty cache, want false", tt) - } - } - if !c.HasTarget("*") { - t.Error("HasTarget(*) got false for empty cache, want true") - } - c = New([]string{"dev1", "dev2"}) - for tt, want := range map[string]bool{"": false, "*": true, "dev1": true, "dev2": true, "dev3": false} { - if got := c.HasTarget(tt); got != want { - t.Errorf("HasTarget(%q) got %t, want %t", tt, got, want) - } - } -} - -func TestAdd(t *testing.T) { - c := New(nil) - c.Add("dev1") - if !c.HasTarget("dev1") { - t.Error("dev1 not added") - } -} - -func TestRemove(t *testing.T) { - c := New([]string{"dev1"}) - c.Remove("dev1") - if c.HasTarget("dev1") { - t.Errorf("dev1 not deleted") - } -} - -func TestGNMIRemove(t *testing.T) { - Type = GnmiNoti - defer func() { - Type = ClientLeaf - }() - tg := "dev1" - c := New([]string{tg}) - var got interface{} - c.SetClient(func(l *ctree.Leaf) { - got = l.Value() - }) - c.Remove(tg) - if got == nil { - t.Fatalf("no update was received") - } - if c.HasTarget("dev1") { - t.Errorf("dev1 not deleted") - } - noti, ok := got.(*gpb.Notification) - if !ok { - t.Fatalf("got %T, want *gpb.Notification type", got) - } - if noti.Prefix.GetTarget() != tg { - t.Errorf("got %q, want %q", noti.Prefix.GetTarget(), tg) - } - if len(noti.Delete) != 1 { - t.Fatalf("got %d, want 1 delete update in notification", len(noti.Delete)) - } - d := noti.Delete[0] - if len(d.Elem) != 1 { - t.Fatalf("got %d, want 1 elems in delete notificatin path", len(d.Elem)) - } - if p := d.Elem[0].Name; p != "*" { - t.Errorf("got %q, want %q in target delete path", p, "*") - } -} - -type queryable struct { - t client.Notification - q bool - v string -} - -func TestQuery(t *testing.T) { - c := New([]string{"dev1"}) - c.Query("", nil, func([]string, *ctree.Leaf, interface{}) { t.Error("querying without a target invoked callback") }) - updates := []queryable{ - // This update is inserted here, but deleted below. - {client.Update{Path: []string{"dev1", "a", "e"}, Val: "value1", TS: T(0)}, true, ""}, - // This update is ovewritten below. - {client.Update{Path: []string{"dev1", "a", "b"}, Val: "value1", TS: T(0)}, true, "value3"}, - // This update is inserted and not modified. - {client.Update{Path: []string{"dev1", "a", "c"}, Val: "value4", TS: T(0)}, true, "value4"}, - // This update overwrites a previous above. - {client.Update{Path: []string{"dev1", "a", "b"}, Val: "value3", TS: T(1)}, true, "value3"}, - // These two targets don't exist in the cache and the updates are rejected. - {client.Update{Path: []string{"dev2", "a", "b"}, Val: "value1", TS: T(0)}, false, ""}, - {client.Update{Path: []string{"dev3", "a", "b"}, Val: "value2", TS: T(0)}, false, ""}, - // This is a delete that removes the first update, above. - {client.Delete{Path: []string{"dev1", "a", "e"}, TS: T(1)}, true, ""}, - } - // Add updates to cache. - for _, tt := range updates { - c.Update(tt.t) - } - // Run queries over the inserted updates. - for x, tt := range updates { - var l client.Leaf - switch v := tt.t.(type) { - case client.Update: - l = (client.Leaf)(v) - case client.Delete: - l = (client.Leaf)(v) - } - target, path := l.Path[0], l.Path[1:] - if r := c.HasTarget(target); r != tt.q { - t.Errorf("#%d: got %v, want %v", x, r, tt.q) - } - var results []interface{} - appendResults := func(_ []string, _ *ctree.Leaf, val interface{}) { results = append(results, val) } - c.Query(target, path, appendResults) - if len(results) != 1 { - if tt.v != "" { - t.Errorf("Query(%s, %v, ): got %d results, want 1", target, path, len(results)) - } - continue - } - val := results[0].(client.Update).Val.(string) - if val != tt.v { - t.Errorf("#%d: got %q, want %q", x, val, tt.v) - } - } -} - -func TestQueryAll(t *testing.T) { - c := New([]string{"dev1", "dev2", "dev3"}) - updates := map[string]client.Update{ - "value1": client.Update{Path: []string{"dev1", "a", "b"}, Val: "value1", TS: T(0)}, - "value2": client.Update{Path: []string{"dev2", "a", "c"}, Val: "value2", TS: T(0)}, - "value3": client.Update{Path: []string{"dev3", "a", "d"}, Val: "value3", TS: T(0)}, - } - // Add updates to cache. - for _, u := range updates { - c.Update(u) - } - target, path := "*", []string{"a"} - if r := c.HasTarget(target); !r { - t.Error("Query not executed against cache for target * and path a") - } - var results []interface{} - appendResults := func(_ []string, _ *ctree.Leaf, val interface{}) { results = append(results, val) } - c.Query(target, path, appendResults) - for _, v := range results { - val := v.(client.Update).Val.(string) - if _, ok := updates[val]; !ok { - t.Errorf("got unexpected update value %#v, want one of %v", v, updates) - } - delete(updates, val) - } - if len(updates) > 0 { - t.Errorf("the following updates were not received for query of target * with path a: %v", updates) - } -} - -func TestReset(t *testing.T) { - targets := []string{"dev1", "dev2", "dev3"} - c := New(targets) - updates := map[string]client.Update{ - "value1": client.Update{Path: []string{"dev1", "a", "b"}, Val: "value1", TS: T(0)}, - "value2": client.Update{Path: []string{"dev2", "a", "c"}, Val: "value2", TS: T(0)}, - "value3": client.Update{Path: []string{"dev3", "a", "d"}, Val: "value3", TS: T(0)}, - "invalid": client.Update{}, // Should have no effect on test. - } - // Add updates to cache. - for _, u := range updates { - c.Update(u) - } - var results []interface{} - var hasMeta bool - appendResults := func(path []string, _ *ctree.Leaf, val interface{}) { - if path[0] == metadata.Root { - hasMeta = true - } else { - results = append(results, val) - } - } - for _, target := range targets { - results = nil - hasMeta = false - c.Query(target, []string{"*"}, appendResults) - if got := len(results); got != 1 { - t.Errorf("Target %q got %d results, want 1\n\t%v", target, got, results) - } - if hasMeta { - t.Errorf("Target %q got metadata, want none", target) - } - c.Reset(target) - results = nil - hasMeta = false - c.Query(target, []string{"*"}, appendResults) - if got := len(results); got != 0 { - t.Errorf("Target %q got %d results, want 0\n\t%v", target, got, results) - } - if !hasMeta { - t.Errorf("Target %q got no metadata, want metadata", target) - } - } -} - -func TestResetUnknown(t *testing.T) { - c := New([]string{}) - c.Reset("dev1") - if c.HasTarget("dev1") { - t.Error("c.Reset created a target that didn't exist before") - } -} - -func TestClient(t *testing.T) { - c := New([]string{"dev1"}) - var got []interface{} - c.SetClient(func(n *ctree.Leaf) { - got = append(got, n.Value()) - }) - sortGot := func() { - path := func(i int) client.Path { - switch l := got[i].(type) { - case client.Update: - return l.Path - case client.Delete: - return l.Path - } - return nil - } - sort.Slice(got, func(i, j int) bool { - return path(i).Less(path(j)) - }) - } - - tests := []struct { - desc string - updates []client.Notification - want []interface{} - }{ - { - desc: "add new nodes", - updates: []client.Notification{ - client.Update{Path: []string{"dev1", "a", "b"}, Val: true, TS: T(1)}, - client.Update{Path: []string{"dev1", "a", "c"}, Val: true, TS: T(2)}, - client.Update{Path: []string{"dev1", "a", "d"}, Val: true, TS: T(3)}, - }, - want: []interface{}{ - client.Update{Path: []string{"dev1", "a", "b"}, Val: true, TS: T(1)}, - client.Update{Path: []string{"dev1", "a", "c"}, Val: true, TS: T(2)}, - client.Update{Path: []string{"dev1", "a", "d"}, Val: true, TS: T(3)}, - }, - }, - { - desc: "update nodes", - updates: []client.Notification{ - client.Update{Path: []string{"dev1", "a", "b"}, Val: true, TS: T(0)}, - client.Update{Path: []string{"dev1", "a", "b"}, Val: true, TS: T(1)}, - client.Update{Path: []string{"dev1", "a", "b"}, Val: false, TS: T(2)}, - }, - want: []interface{}{ - client.Update{Path: []string{"dev1", "a", "b"}, Val: false, TS: T(2)}, - }, - }, - { - desc: "delete nodes", - updates: []client.Notification{ - client.Delete{Path: []string{"dev1", "a", "b"}, TS: T(1)}, - client.Delete{Path: []string{"dev1", "a", "b"}, TS: T(3)}, - client.Delete{Path: []string{"dev1", "a"}, TS: T(4)}, - }, - want: []interface{}{ - client.Delete{Path: []string{"dev1", "a", "b"}, TS: T(3)}, - client.Delete{Path: []string{"dev1", "a", "c"}, TS: T(4)}, - client.Delete{Path: []string{"dev1", "a", "d"}, TS: T(4)}, - }, - }, - } - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - got = nil - for _, u := range tt.updates { - c.Update(u) - } - sortGot() - if diff := cmp.Diff(tt.want, got); diff != "" { - t.Errorf("sent updates: %v\ndiff in received updates:\n%s", tt.updates, diff) - } - }) - } - t.Run("remove target", func(t *testing.T) { - got = nil - c.Remove("dev1") - want := client.Delete{Path: []string{"dev1"}} - if len(got) != 1 { - t.Fatalf("Remove didn't produce correct client update, got: %+v, want: %+v", got, []interface{}{want}) - } - gotVal := got[0].(client.Delete) - // Clear timestamp before comparison. - gotVal.TS = time.Time{} - if diff := cmp.Diff(want, gotVal); diff != "" { - t.Errorf("diff in received update:\n%s", diff) - } - }) -} - -func TestMetadata(t *testing.T) { - targets := []string{"dev1", "dev2", "dev3"} - c := New(targets) - md := c.Metadata() - if got, want := len(md), len(targets); got != want { - t.Errorf("Metadata got %d targets, want %d", got, want) - } -} - -func TestUpdateMeta(t *testing.T) { - c := New([]string{"dev1"}) - - var lastSize, lastCount, lastAdds, lastUpds int64 - for i := 0; i < 10; i++ { - c.Update(client.Update{Path: []string{"dev1", "a", fmt.Sprint(i)}, Val: "b", TS: T(int64(i))}) - - c.GetTarget("dev1").updateSize(nil) - c.GetTarget("dev1").updateMeta(nil) - - var path []string - path = metadata.Path(metadata.Size) - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - newSize := v.(client.Update).Val.(int64) - if newSize <= lastSize { - t.Errorf("%s didn't increase after adding leaf #%d", - strings.Join(path, "/"), i+1) - } - lastSize = newSize - }) - path = metadata.Path(metadata.LeafCount) - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - newCount := v.(client.Update).Val.(int64) - if newCount <= lastCount { - t.Errorf("%s didn't increase after adding leaf #%d", - strings.Join(path, "/"), i+1) - } - lastCount = newCount - }) - path = metadata.Path(metadata.AddCount) - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - newAdds := v.(client.Update).Val.(int64) - if newAdds <= lastAdds { - t.Errorf("%s didn't increase after adding leaf #%d", - strings.Join(path, "/"), i+1) - } - lastAdds = newAdds - }) - path = metadata.Path(metadata.UpdateCount) - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - newUpds := v.(client.Update).Val.(int64) - if newUpds <= lastUpds { - t.Errorf("%s didn't increase after adding leaf #%d", - strings.Join(path, "/"), i+1) - } - lastUpds = newUpds - }) - path = metadata.Path(metadata.DelCount) - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - dels := v.(client.Update).Val.(int64) - if dels > 0 { - t.Errorf("%s is %d after adding leaf #%d, even though no leaves were removed", - strings.Join(path, "/"), dels, i+1) - } - }) - } -} - -func TestMetadataStale(t *testing.T) { - c := New([]string{"dev1"}) - for i := 0; i < 10; i++ { - c.Update(client.Update{Path: []string{"dev1", "a"}, Val: i, TS: T(int64(10 - i))}) - c.GetTarget("dev1").updateMeta(nil) - path := metadata.Path(metadata.StaleCount) - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - staleCount := v.(client.Update).Val.(int64) - if staleCount != int64(i) { - t.Errorf("got staleCount = %d, want %d", staleCount, i) - } - }) - path = metadata.Path(metadata.UpdateCount) - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - updates := v.(client.Update).Val.(int64) - if updates != 1 { - t.Errorf("got updates %d, want 1", updates) - } - }) - } -} - -func TestGNMIUpdateIntermediateUpdate(t *testing.T) { - c := New([]string{"dev1"}) - // Initialize a cache tree for next GnmiUpdate test. - n := gnmiNotification("dev1", []string{"prefix", "path"}, []string{"update", "a", "b", "c"}, 0, "", true) - if err := c.GnmiUpdate(n); err != nil { - t.Fatalf("GnmiUpdate(%+v): got %v, want nil error", n, err) - } - // This is a negative test case for invalid path in an update. - // For a cache tree initialized above with path "a"/"b"/"c", "a" is a non-leaf node. - // Because non-leaf node "a" does not contain notification, error should be returned in following update. - n = gnmiNotification("dev1", []string{"prefix", "path"}, []string{"update", "a"}, 0, "", true) - err := c.GnmiUpdate(n) - if diff := errdiff.Substring(err, "corrupt schema with collision"); diff != "" { - t.Errorf("GnmiUpdate(%+v): %v", n, diff) - } -} - -func TestMetadataSuppressed(t *testing.T) { - c := New([]string{"dev1"}) - // Unique values not suppressed. - for i := 0; i < 10; i++ { - c.GnmiUpdate(gnmiNotification("dev1", []string{"prefix", "path"}, []string{"update", "path"}, int64(i), strconv.Itoa(i), true)) - c.GetTarget("dev1").updateMeta(nil) - path := metadata.Path(metadata.SuppressedCount) - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - suppressedCount := v.(client.Update).Val.(int64) - if suppressedCount != 0 { - t.Errorf("got suppressedCount = %d, want 0", suppressedCount) - } - }) - path = metadata.Path(metadata.UpdateCount) - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - updates := v.(client.Update).Val.(int64) - if updates != int64(i+1) { - t.Errorf("got updates %d, want %d", updates, i) - } - }) - } - c.Reset("dev1") - // Duplicate values suppressed. - for i := 0; i < 10; i++ { - c.GnmiUpdate(gnmiNotification("dev1", []string{"prefix", "path"}, []string{"update", "path"}, int64(i), "same value", true)) - c.GetTarget("dev1").updateMeta(nil) - path := metadata.Path(metadata.SuppressedCount) - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - suppressedCount := v.(client.Update).Val.(int64) - if suppressedCount != int64(i) { - t.Errorf("got suppressedCount = %d, want %d", suppressedCount, i) - } - }) - path = metadata.Path(metadata.UpdateCount) - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - updates := v.(client.Update).Val.(int64) - if updates != 1 { - t.Errorf("got updates %d, want 1", updates) - } - }) - } -} - -func TestMetadataLatency(t *testing.T) { - c := New([]string{"dev1"}) - - for _, path := range [][]string{ - metadata.Path(metadata.LatencyAvg), - metadata.Path(metadata.LatencyMax), - metadata.Path(metadata.LatencyMin), - } { - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - if l := v.(client.Update).Val.(int64); l != 0 { - t.Errorf("%s exists with value %d when device not in sync", - strings.Join(path, "/"), l) - } - }) - } - timestamp := time.Now().Add(-time.Minute) - c.Update(client.Update{Path: append([]string{"dev1"}, metadata.Path(metadata.Sync)...), Val: true, TS: timestamp}) - c.Update(client.Update{Path: []string{"dev1", "a", "1"}, Val: "b", TS: timestamp}) - c.GetTarget("dev1").updateMeta(nil) - for _, path := range [][]string{ - metadata.Path(metadata.LatencyAvg), - metadata.Path(metadata.LatencyMax), - metadata.Path(metadata.LatencyMin), - } { - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - l := v.(client.Update).Val.(int64) - if want := time.Minute.Nanoseconds(); l < want { - t.Errorf("%s got value %d, want greater than %d", - strings.Join(path, "/"), l, want) - } - }) - } -} - -func TestUpdateMetadata(t *testing.T) { - c := New([]string{"dev1"}) - c.UpdateMetadata() - want := []client.Path{ - {metadata.Root, metadata.LatestTimestamp}, - {metadata.Root, metadata.LeafCount}, - {metadata.Root, metadata.AddCount}, - {metadata.Root, metadata.UpdateCount}, - {metadata.Root, metadata.DelCount}, - {metadata.Root, metadata.StaleCount}, - {metadata.Root, metadata.SuppressedCount}, - {metadata.Root, metadata.Connected}, - {metadata.Root, metadata.Sync}, - {metadata.Root, metadata.Size}, - {metadata.Root, metadata.LatencyAvg}, - {metadata.Root, metadata.LatencyMin}, - {metadata.Root, metadata.LatencyMax}, - } - var got []client.Path - c.Query("dev1", []string{metadata.Root}, func(path []string, _ *ctree.Leaf, _ interface{}) { - got = append(got, path) - }) - sort.Slice(got, func(i, j int) bool { return got[i].Less(got[j]) }) - sort.Slice(want, func(i, j int) bool { return want[i].Less(want[j]) }) - if !reflect.DeepEqual(got, want) { - t.Errorf("got update paths: %q\n want: %q", got, want) - } -} - -func TestUpdateSize(t *testing.T) { - c := New([]string{"dev1"}) - c.Update(client.Update{Path: []string{"dev1", "a", "1"}, Val: make([]byte, 1000), TS: T(0)}) - c.UpdateSize() - c.UpdateMetadata() - var val int64 - c.Query("dev1", []string{metadata.Root, metadata.Size}, func(_ []string, _ *ctree.Leaf, v interface{}) { - t.Logf("%v", v) - val = v.(client.Update).Val.(int64) - }) - if val <= 1000 { - t.Errorf("got size of %d want > 1000", val) - } -} - -type updateQueryData struct { - targets []string - paths [][]string - values []*string -} - -func sendUpdates(u updateQueryData, c *Cache, n int, wg *sync.WaitGroup) { - r := rand.New(rand.NewSource(5)) - for i := 0; i < n; i++ { - target := u.targets[r.Intn(len(u.targets))] - path := append([]string{target}, u.paths[r.Intn(len(u.paths))]...) - value := u.values[r.Intn(len(u.values))] - c.Update(client.Update{Path: path, Val: value, TS: T(int64(n))}) - } -} - -func makeQueries(u updateQueryData, c *Cache, n int, wg *sync.WaitGroup) { - r := rand.New(rand.NewSource(30)) - for i := 0; i < n; i++ { - target := u.targets[r.Intn(len(u.targets))] - path := u.paths[r.Intn(len(u.paths))] - c.Query(target, path, func([]string, *ctree.Leaf, interface{}) {}) - } - wg.Done() -} - -func createPaths(l, n int) [][]string { - var paths [][]string - if l == 0 { - for i := 0; i < n; i++ { - paths = append(paths, []string{fmt.Sprintf("level_%d_node_%d", l, i)}) - } - return paths - } - subpaths := createPaths(l-1, n) - for i := 0; i < n; i++ { - for _, p := range subpaths { - paths = append(paths, append([]string{fmt.Sprintf("level_%d_node_%d", l, i)}, p...)) - } - } - return paths -} - -func BenchmarkParallelUpdateQuery(b *testing.B) { - u := updateQueryData{ - targets: []string{"dev1", "dev2", "dev3"}, - paths: createPaths(5, 10), - values: []*string{nil}, - } - for v := 0; v < 100; v++ { - s := fmt.Sprintf("value_%d", v) - u.values = append(u.values, &s) - } - procs := runtime.GOMAXPROCS(0) - c := New(u.targets) - var wg sync.WaitGroup - b.ResetTimer() - for p := 0; p < procs; p++ { - wg.Add(2) - go sendUpdates(u, c, b.N, &wg) - go makeQueries(u, c, b.N, &wg) - } - wg.Wait() -} - -func TestIsDeleteTarget(t *testing.T) { - testCases := []struct { - name string - noti interface{} - want bool - }{ - { - name: "Update", - noti: client.Update{Path: client.Path{"a"}}, - want: false, - }, - { - name: "Leaf delete", - noti: client.Delete{Path: client.Path{"a", "b"}}, - want: false, - }, - { - name: "Target delete", - noti: client.Delete{Path: client.Path{"target"}}, - want: true, - }, - { - name: "GNMI Update", - noti: &gpb.Notification{ - Prefix: &gpb.Path{Target: "d", Origin: "o"}, - Update: []*gpb.Update{ - { - Path: &gpb.Path{ - Elem: []*gpb.PathElem{{Name: "p"}}, - }, - }, - }, - }, - want: false, - }, - { - name: "GNMI Leaf Delete", - noti: &gpb.Notification{ - Prefix: &gpb.Path{Target: "d", Origin: "o"}, - Delete: []*gpb.Path{{ - Elem: []*gpb.PathElem{{Name: "p"}}, - }}, - }, - want: false, - }, - { - name: "GNMI Root Delete", - noti: &gpb.Notification{ - Prefix: &gpb.Path{Target: "d", Origin: "o"}, - Delete: []*gpb.Path{{ - Elem: []*gpb.PathElem{{Name: "*"}}, - }}, - }, - want: false, - }, - { - name: "GNMI Target Delete", - noti: &gpb.Notification{ - Prefix: &gpb.Path{Target: "d"}, - Delete: []*gpb.Path{{ - Elem: []*gpb.PathElem{{Name: "*"}}, - }}, - }, - want: true, - }, - } - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - l := ctree.DetachedLeaf(tc.noti) - if got := IsTargetDelete(l); got != tc.want { - t.Errorf("got %t, want %t", got, tc.want) - } - }) - } -} - -func gnmiNotification(dev string, prefix []string, path []string, ts int64, val string, upd bool) *gpb.Notification { - if upd { - return &gpb.Notification{ - Prefix: &gpb.Path{Element: prefix, Target: dev}, - Timestamp: ts, - Update: []*gpb.Update{ - &gpb.Update{ - Path: &gpb.Path{ - Element: path, - }, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_StringVal{val}}, - }, - }, - } - } - return &gpb.Notification{ - Prefix: &gpb.Path{Element: prefix, Target: dev}, - Timestamp: ts, - Delete: []*gpb.Path{&gpb.Path{Element: path}}, - } -} - -func TestGNMIQuery(t *testing.T) { - Type = GnmiNoti - defer func() { Type = ClientLeaf }() - c := New([]string{"dev1"}) - c.Query("", nil, func([]string, *ctree.Leaf, interface{}) { t.Error("querying without a target invoked callback") }) - updates := []struct { - t *gpb.Notification - q bool - v string - }{ - // This update is inserted here, but deleted below. - {gnmiNotification("dev1", []string{}, []string{"a", "e"}, 0, "value1", true), true, ""}, - // This update is ovewritten below. - {gnmiNotification("dev1", []string{}, []string{"a", "b"}, 0, "value1", true), true, "value3"}, - // This update is inserted and not modified. - {gnmiNotification("dev1", []string{}, []string{"a", "c"}, 0, "value4", true), true, "value4"}, - // This update overwrites a previous above. - {gnmiNotification("dev1", []string{}, []string{"a", "b"}, 1, "value3", true), true, "value3"}, - // These two targets don't exist in the cache and the updates are rejected. - {gnmiNotification("dev2", []string{}, []string{"a", "b"}, 0, "value1", true), false, ""}, - {gnmiNotification("dev3", []string{}, []string{"a", "b"}, 0, "value2", true), false, ""}, - // This is a delete that removes the first update, above. - {gnmiNotification("dev1", []string{}, []string{"a", "e"}, 1, "", false), true, ""}, - } - // Add updates to cache. - for _, tt := range updates { - c.GnmiUpdate(tt.t) - } - // Run queries over the inserted updates. - for x, tt := range updates { - target := tt.t.GetPrefix().GetTarget() - var gp *gpb.Path - if tt.t.Update != nil { - gp = tt.t.Update[0].GetPath() - } else { - gp = tt.t.Delete[0] - } - p := joinPrefixAndPath(tt.t.GetPrefix(), gp) - if r := c.HasTarget(target); r != tt.q { - t.Errorf("#%d: got %v, want %v", x, r, tt.q) - } - var results []interface{} - appendResults := func(_ []string, _ *ctree.Leaf, val interface{}) { results = append(results, val) } - c.Query(target, p, appendResults) - if len(results) != 1 { - if tt.v != "" { - t.Errorf("Query(%s, %v, ): got %d results, want 1", target, p, len(results)) - } - continue - } - val := results[0].(*gpb.Notification).Update[0].Val.Value.(*gpb.TypedValue_StringVal).StringVal - if val != tt.v { - t.Errorf("#%d: got %q, want %q", x, val, tt.v) - } - } -} - -func TestGNMIQueryAll(t *testing.T) { - Type = GnmiNoti - defer func() { Type = ClientLeaf }() - c := New([]string{"dev1", "dev2", "dev3"}) - updates := map[string]*gpb.Notification{ - "value1": gnmiNotification("dev1", []string{}, []string{"a", "b"}, 0, "value1", true), - "value2": gnmiNotification("dev2", []string{}, []string{"a", "c"}, 0, "value2", true), - "value3": gnmiNotification("dev3", []string{}, []string{"a", "d"}, 0, "value3", true), - } - // Add updates to cache. - for _, u := range updates { - c.GnmiUpdate(u) - } - target, path := "*", []string{"a"} - if r := c.HasTarget(target); !r { - t.Error("Query not executed against cache for target * and path a") - } - var results []interface{} - appendResults := func(_ []string, _ *ctree.Leaf, val interface{}) { results = append(results, val) } - c.Query(target, path, appendResults) - for _, v := range results { - val := v.(*gpb.Notification).Update[0].Val.Value.(*gpb.TypedValue_StringVal).StringVal - if _, ok := updates[val]; !ok { - t.Errorf("got unexpected update value %#v, want one of %v", v, updates) - } - delete(updates, val) - } - if len(updates) > 0 { - t.Errorf("the following updates were not received for query of target * with path a: %v", updates) - } -} - -func TestGNMIAtomic(t *testing.T) { - Type = GnmiNoti - defer func() { Type = ClientLeaf }() - c := New([]string{"dev1"}) - n := &gpb.Notification{ - Atomic: true, - Timestamp: time.Now().UnixNano(), - Prefix: &gpb.Path{ - Target: "dev1", - Origin: "openconfig", - Elem: []*gpb.PathElem{{Name: "a"}, {Name: "b", Key: map[string]string{"key": "value"}}}, - }, - Update: []*gpb.Update{ - {Path: &gpb.Path{Elem: []*gpb.PathElem{{Name: "x"}}}, Val: &gpb.TypedValue{Value: &gpb.TypedValue_StringVal{"x val"}}}, - {Path: &gpb.Path{Elem: []*gpb.PathElem{{Name: "y"}}}, Val: &gpb.TypedValue{Value: &gpb.TypedValue_StringVal{"y val"}}}, - {Path: &gpb.Path{Elem: []*gpb.PathElem{{Name: "z"}}}, Val: &gpb.TypedValue{Value: &gpb.TypedValue_StringVal{"z val"}}}, - }, - } - c.GnmiUpdate(n) - tests := []struct { - path []string - expect bool - }{ - // Query paths that return the atomic update. - {path: []string{"*"}, expect: true}, - {path: []string{"openconfig"}, expect: true}, - {path: []string{"openconfig", "a"}, expect: true}, - {path: []string{"openconfig", "a", "b"}, expect: true}, - {path: []string{"openconfig", "a", "b", "value"}, expect: true}, - // Query paths that do not. - {path: []string{"foo"}}, - {path: []string{"openconfig", "a", "b", "value", "x"}}, - } - for _, tt := range tests { - c.Query("dev1", tt.path, func(_ []string, _ *ctree.Leaf, val interface{}) { - if !tt.expect { - t.Errorf("Query(%p): got notification %v, want none", tt.path, val) - } else { - if v, ok := val.(*gpb.Notification); !ok || !cmp.Equal(v, n) { - t.Errorf("got:\n%s want\n%s", proto.MarshalTextString(v), proto.MarshalTextString(n)) - } - } - }) - } -} - -func TestGNMIUpdateMeta(t *testing.T) { - Type = GnmiNoti - defer func() { Type = ClientLeaf }() - c := New([]string{"dev1"}) - - var lastSize, lastCount, lastAdds, lastUpds int64 - for i := 0; i < 10; i++ { - c.GnmiUpdate(gnmiNotification("dev1", []string{}, []string{"a", fmt.Sprint(i)}, int64(i), "b", true)) - - c.GetTarget("dev1").updateSize(nil) - c.GetTarget("dev1").updateMeta(nil) - - var path []string - path = metadata.Path(metadata.Size) - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - newSize := v.(*gpb.Notification).Update[0].Val.Value.(*gpb.TypedValue_IntVal).IntVal - if newSize <= lastSize { - t.Errorf("%s didn't increase after adding leaf #%d", - strings.Join(path, "/"), i+1) - } - lastSize = newSize - }) - path = metadata.Path(metadata.LeafCount) - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - newCount := v.(*gpb.Notification).Update[0].Val.Value.(*gpb.TypedValue_IntVal).IntVal - if newCount <= lastCount { - t.Errorf("%s didn't increase after adding leaf #%d", - strings.Join(path, "/"), i+1) - } - lastCount = newCount - }) - path = metadata.Path(metadata.AddCount) - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - newAdds := v.(*gpb.Notification).Update[0].Val.Value.(*gpb.TypedValue_IntVal).IntVal - if newAdds <= lastAdds { - t.Errorf("%s didn't increase after adding leaf #%d", - strings.Join(path, "/"), i+1) - } - lastAdds = newAdds - }) - path = metadata.Path(metadata.UpdateCount) - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - newUpds := v.(*gpb.Notification).Update[0].Val.Value.(*gpb.TypedValue_IntVal).IntVal - if newUpds <= lastUpds { - t.Errorf("%s didn't increase after adding leaf #%d", - strings.Join(path, "/"), i+1) - } - lastUpds = newUpds - }) - path = metadata.Path(metadata.DelCount) - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - dels := v.(*gpb.Notification).Update[0].Val.Value.(*gpb.TypedValue_IntVal).IntVal - if dels > 0 { - t.Errorf("%s is %d after adding leaf #%d, even though no leaves were removed", - strings.Join(path, "/"), dels, i+1) - } - }) - } - for _, path := range [][]string{ - metadata.Path(metadata.LatencyAvg), - metadata.Path(metadata.LatencyMax), - metadata.Path(metadata.LatencyMin), - } { - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - if l := v.(*gpb.Notification).Update[0].Val.Value.(*gpb.TypedValue_IntVal).IntVal; l != 0 { - t.Errorf("%s exists with value %d when device not in sync", - strings.Join(path, "/"), l) - } - }) - } - pathGen := func(ph []string) *gpb.Path { - pe := make([]*gpb.PathElem, 0, len(ph)) - for _, p := range ph { - pe = append(pe, &gpb.PathElem{Name: p}) - } - return &gpb.Path{Elem: pe} - } - timestamp := time.Now().Add(-time.Minute) - - c.Sync("dev1") - - c.GnmiUpdate( - &gpb.Notification{ - Timestamp: timestamp.UnixNano(), - Prefix: &gpb.Path{Target: "dev1"}, - Update: []*gpb.Update{ - &gpb.Update{ - Path: pathGen([]string{"a", "1"}), - Val: &gpb.TypedValue{Value: &gpb.TypedValue_StringVal{"b"}}, - }, - }, - }) - c.GetTarget("dev1").updateMeta(nil) - for _, path := range [][]string{ - metadata.Path(metadata.LatencyAvg), - metadata.Path(metadata.LatencyMax), - metadata.Path(metadata.LatencyMin), - } { - c.Query("dev1", path, func(_ []string, _ *ctree.Leaf, v interface{}) { - l := v.(*gpb.Notification).Update[0].Val.Value.(*gpb.TypedValue_IntVal).IntVal - if want := time.Minute.Nanoseconds(); l < want { - t.Errorf("%s got value %d, want greater than %d", - strings.Join(path, "/"), l, want) - } - }) - } -} - -func TestGNMIQueryWithPathElem(t *testing.T) { - Type = GnmiNoti - defer func() { Type = ClientLeaf }() - c := New([]string{"dev1"}) - c.Query("", nil, func([]string, *ctree.Leaf, interface{}) { t.Error("querying without a target invoked callback") }) - ns := []struct { - n *gpb.Notification - q []string - e string - }{ - { - // add value1 by sending update notification - n: &gpb.Notification{ - Prefix: &gpb.Path{ - Target: "dev1", - Elem: []*gpb.PathElem{&gpb.PathElem{Name: "a"}, &gpb.PathElem{Name: "b", Key: map[string]string{"bb": "x", "aa": "y"}}, &gpb.PathElem{Name: "c"}}, - }, - Update: []*gpb.Update{ - &gpb.Update{ - Path: &gpb.Path{Elem: []*gpb.PathElem{&gpb.PathElem{Name: "d", Key: map[string]string{"kk": "1", "ff": "2"}}, &gpb.PathElem{Name: "e"}}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_StringVal{"value1"}}, - }, - }, - Timestamp: 0, - }, - q: []string{"a", "b", "y", "x", "c", "d", "2", "1", "e"}, - e: "", - }, - { - // add value2 by sending update notification - n: &gpb.Notification{ - Prefix: &gpb.Path{ - Target: "dev1", - Elem: []*gpb.PathElem{&gpb.PathElem{Name: "a"}, &gpb.PathElem{Name: "b", Key: map[string]string{"bb": "x", "aa": "y"}}, &gpb.PathElem{Name: "c"}}, - }, - Update: []*gpb.Update{ - &gpb.Update{ - Path: &gpb.Path{Elem: []*gpb.PathElem{&gpb.PathElem{Name: "d", Key: map[string]string{"kk": "1", "ff": "3"}}, &gpb.PathElem{Name: "e"}}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_StringVal{"value2"}}, - }, - }, - Timestamp: 1, - }, - q: []string{"a", "b", "y", "x", "c", "d", "3", "1", "e"}, - e: "value2", - }, - { - // delete the value1 by sending a delete notification - n: &gpb.Notification{ - Prefix: &gpb.Path{ - Target: "dev1", - Elem: []*gpb.PathElem{&gpb.PathElem{Name: "a"}, &gpb.PathElem{Name: "b", Key: map[string]string{"bb": "x", "aa": "y"}}, &gpb.PathElem{Name: "c"}}, - }, - Delete: []*gpb.Path{ - &gpb.Path{Elem: []*gpb.PathElem{&gpb.PathElem{Name: "d", Key: map[string]string{"kk": "1", "ff": "2"}}, &gpb.PathElem{Name: "e"}}}, - }, - Timestamp: 2, - }, - q: []string{"a", "b", "y", "x", "c", "d", "2", "1", "e"}, - e: "", - }, - } - - for _, t := range ns { - c.GnmiUpdate(t.n) - } - - // Run queries over the inserted updates. - for x, tt := range ns { - target := tt.n.GetPrefix().GetTarget() - var gp *gpb.Path - if tt.n.Update != nil { - gp = tt.n.Update[0].GetPath() - } else { - gp = tt.n.Delete[0] - } - p := joinPrefixAndPath(tt.n.GetPrefix(), gp) - var results []interface{} - appendResults := func(_ []string, _ *ctree.Leaf, val interface{}) { results = append(results, val) } - c.Query(target, p, appendResults) - if len(results) != 1 { - if tt.e != "" { - t.Errorf("Query(%s, %v, ): got %d results, want 1", target, p, len(results)) - } - continue - } - val := results[0].(*gpb.Notification).Update[0].Val.Value.(*gpb.TypedValue_StringVal).StringVal - if val != tt.e { - t.Errorf("#%d: got %q, want %q", x, val, tt.e) - } - } -} - -func TestGNMIClient(t *testing.T) { - Type = GnmiNoti - defer func() { Type = ClientLeaf }() - c := New([]string{"dev1"}) - var got []interface{} - c.SetClient(func(n *ctree.Leaf) { - got = append(got, n.Value()) - }) - sortGot := func() { - path := func(i int) []string { - switch l := got[i].(type) { - case *gpb.Notification: - if len(l.Update) > 0 { - return joinPrefixAndPath(l.Prefix, l.Update[0].Path) - } - return joinPrefixAndPath(l.Prefix, l.Delete[0]) - default: - return nil - } - } - sort.Slice(got, func(i, j int) bool { - return client.Path(path(i)).Less(client.Path(path(j))) - }) - } - - tests := []struct { - desc string - updates []*gpb.Notification - want []interface{} - }{ - { - desc: "add new nodes", - updates: []*gpb.Notification{ - gnmiNotification("dev1", []string{}, []string{"a", "b"}, 1, "value1", true), - gnmiNotification("dev1", []string{}, []string{"a", "c"}, 2, "value2", true), - gnmiNotification("dev1", []string{}, []string{"a", "d"}, 3, "value3", true), - }, - want: []interface{}{ - gnmiNotification("dev1", []string{}, []string{"a", "b"}, 1, "value1", true), - gnmiNotification("dev1", []string{}, []string{"a", "c"}, 2, "value2", true), - gnmiNotification("dev1", []string{}, []string{"a", "d"}, 3, "value3", true), - }, - }, - { - desc: "update nodes", - updates: []*gpb.Notification{ - gnmiNotification("dev1", []string{}, []string{"a", "b"}, 0, "value1", true), - gnmiNotification("dev1", []string{}, []string{"a", "b"}, 1, "value1", true), - gnmiNotification("dev1", []string{}, []string{"a", "b"}, 2, "value11", true), - }, - want: []interface{}{ - gnmiNotification("dev1", []string{}, []string{"a", "b"}, 2, "value11", true), - }, - }, - { - desc: "delete nodes", - updates: []*gpb.Notification{ - gnmiNotification("dev1", []string{}, []string{"a", "b"}, 1, "", false), - gnmiNotification("dev1", []string{}, []string{"a", "b"}, 3, "", false), - gnmiNotification("dev1", []string{}, []string{"a"}, 4, "", false), - }, - want: []interface{}{ - gnmiNotification("dev1", nil, []string{"a", "b"}, 3, "", false), - gnmiNotification("dev1", nil, []string{"a", "c"}, 4, "", false), - gnmiNotification("dev1", nil, []string{"a", "d"}, 4, "", false), - }, - }, - } - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - got = nil - for _, u := range tt.updates { - c.GnmiUpdate(u) - } - sortGot() - if diff := cmp.Diff(tt.want, got); diff != "" { - t.Errorf("sent updates: %v\ndiff in received updates:\n%s", tt.updates, diff) - } - }) - } - t.Run("remove target", func(t *testing.T) { - got = nil - want := deleteNoti("dev1", "", []string{"*"}) - want.Timestamp = 0 - c.Remove("dev1") - if len(got) != 1 { - t.Fatalf("Remove didn't produce correct client update, got: %+v, want: %+v", got, []interface{}{want}) - } - gotVal := got[0].(*gpb.Notification) - // Clear timestamp before comparison. - gotVal.Timestamp = 0 - if diff := cmp.Diff(want, gotVal); diff != "" { - t.Errorf("diff in received update:\n%s", diff) - } - }) -} - -func TestGNMIReset(t *testing.T) { - Type = GnmiNoti - defer func() { Type = ClientLeaf }() - targets := []string{"dev1", "dev2", "dev3"} - c := New(targets) - updates := map[string]*gpb.Notification{ - "value1": gnmiNotification("dev1", []string{}, []string{"a", "b"}, 0, "value1", true), - "value2": gnmiNotification("dev2", []string{}, []string{"a", "c"}, 0, "value2", true), - "value3": gnmiNotification("dev3", []string{}, []string{"a", "d"}, 0, "value3", true), - "invalid": gnmiNotification("", []string{}, []string{}, 0, "", true), // Should have no effect on test. - } - // Add updates to cache. - for _, u := range updates { - c.GnmiUpdate(u) - } - var results []interface{} - var hasMeta bool - appendResults := func(path []string, _ *ctree.Leaf, val interface{}) { - if path[0] == metadata.Root { - hasMeta = true - } else { - results = append(results, val) - } - } - for _, target := range targets { - results = nil - hasMeta = false - c.Query(target, []string{"*"}, appendResults) - if got := len(results); got != 1 { - t.Errorf("Target %q got %d results, want 1\n\t%v", target, got, results) - } - if hasMeta { - t.Errorf("Target %q got metadata, want none", target) - } - c.Reset(target) - results = nil - hasMeta = false - c.Query(target, []string{"*"}, appendResults) - if got := len(results); got != 0 { - t.Errorf("Target %q got %d results, want 0\n\t%v", target, got, results) - } - if !hasMeta { - t.Errorf("Target %q got no metadata, want metadata", target) - } - } -} - -func TestGNMISyncConnectUpdates(t *testing.T) { - Type = GnmiNoti - defer func() { Type = ClientLeaf }() - c := New([]string{"dev1"}) - var got []interface{} - c.SetClient(func(l *ctree.Leaf) { - got = append(got, l.Value()) - }) - tests := []struct { - metadata string - helper func(string) - want []*gpb.Notification - }{ - {metadata: metadata.Sync, helper: c.Sync, want: []*gpb.Notification{metaNotiBool("dev1", metadata.Sync, true)}}, - {metadata: metadata.Connected, helper: c.Connect, want: []*gpb.Notification{metaNotiBool("dev1", metadata.Connected, true)}}, - {metadata: "disconnect", helper: c.Disconnect, want: []*gpb.Notification{metaNotiBool("dev1", metadata.Sync, false), metaNotiBool("dev1", metadata.Connected, false)}}, - } - - for _, tt := range tests { - t.Run(fmt.Sprintf("Test %v", tt.metadata), func(t *testing.T) { - tt.helper("dev1") - if len(got) < len(tt.want) { - t.Fatalf("got %d updates, want %d. got %v, want %v", len(got), len(tt.want), got, tt.want) - } - for i := 0; i < len(tt.want); i++ { - got[i].(*gpb.Notification).Timestamp = 0 - tt.want[i].Timestamp = 0 - if diff := cmp.Diff(tt.want[i], got[i]); diff != "" { - t.Errorf("diff in received update:\n%s", diff) - } - } - got = nil - }) - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cli/cli.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/cli/cli.go deleted file mode 100644 index 5407611a8..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cli/cli.go +++ /dev/null @@ -1,389 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 cli provides the query capabilities for streaming telemetry. -package cli - -import ( - "bytes" - "context" - "encoding/json" - "fmt" - "strings" - "time" - - "github.com/golang/protobuf/proto" - "github.com/openconfig/gnmi/client" - "github.com/openconfig/gnmi/ctree" - - gpb "github.com/openconfig/gnmi/proto/gnmi" -) - -const layout = "2006-01-02-15:04:05.000000000" - -var ( - queryTypeMap = map[string]client.Type{ - "o": client.Once, "once": client.Once, "ONCE": client.Once, - "p": client.Poll, "polling": client.Poll, "POLLING": client.Poll, - "s": client.Stream, "streaming": client.Stream, "STREAMING": client.Stream, - } - displayTypeMap = map[string]string{ - "g": "GROUP", "group": "GROUP", "GROUP": "GROUP", - "s": "SINGLE", "single": "SINGLE", "SINGLE": "SINGLE", - "p": "PROTO", "proto": "PROTO", "PROTO": "PROTO", - "sp": "SHORTPROTO", "shortproto": "SHORTPROTO", "SHORTPROTO": "SHORTPROTO", - } -) - -// Config is a type to hold parameters that affect how the cli sends and -// displays results. -type Config struct { - PollingInterval time.Duration // Duration between polling events. - StreamingDuration time.Duration // Duration to collect updates, 0 is forever. - Count uint // Number of polling/streaming events, 0 is infinite. - countExhausted bool // Trigger to indicate termination. - Delimiter string // Delimiter between path elements when converted to string. - Display func([]byte) // Function called to display each result. - DisplayPrefix string // Prefix for each line of result output. - DisplayIndent string // Indent per nesting level of result output. - DisplayType string // Display results in selected format, grouped, single, proto. - DisplayPeer bool // Display the immediate connected peer. - // - disable timestamp - // on - human readable timestamp according to layout - // raw - int64 nanos since epoch - // - human readable timestamp according to - Timestamp string // Formatting of timestamp in result output. - DisplaySize bool - Latency bool // Show latency to client - ClientTypes []string // List of client types to try. -} - -// QueryType returns a client query type for t after trying aliases for the -// type. -func QueryType(t string) client.Type { - return queryTypeMap[t] -} - -// QueryDisplay constructs a query from the supplied arguments (target, queries, -// queryType), sends as an RPC to the specified destination address and displays -// results with the supplied display function. -func QueryDisplay(ctx context.Context, query client.Query, cfg *Config) error { - if err := sendQueryAndDisplay(ctx, query, cfg); err != nil { - return fmt.Errorf("sendQueryAndDisplay(ctx, %+v, %+v):\n\t%v", query, cfg, err) - } - return nil -} - -// ParseSubscribeProto parses given gNMI SubscribeRequest text proto -// into client.Query. -func ParseSubscribeProto(p string) (client.Query, error) { - var tq client.Query - sr := &gpb.SubscribeRequest{} - if err := proto.UnmarshalText(p, sr); err != nil { - return tq, err - } - return client.NewQuery(sr) -} - -// sendQueryAndDisplay directs a query to the specified target. The returned -// results are formatted as a JSON string and passed to Config.Display(). -func sendQueryAndDisplay(ctx context.Context, query client.Query, cfg *Config) error { - cancel := func() {} - if cfg.StreamingDuration > 0 { - ctx, cancel = context.WithTimeout(ctx, cfg.StreamingDuration) - defer cancel() - } - switch displayTypeMap[cfg.DisplayType] { - default: - return fmt.Errorf("unknown display type %q", cfg.DisplayType) - case "GROUP": - case "SINGLE": - return displaySingleResults(ctx, query, cfg) - case "PROTO": - return displayProtoResults(ctx, query, cfg, func(r proto.Message) []byte { - return []byte(proto.MarshalTextString(r)) - }) - case "SHORTPROTO": - return displayProtoResults(ctx, query, cfg, func(r proto.Message) []byte { - // r.String() will add extra whitespace at the end for some reason. - // Trim it down. - return bytes.TrimSpace([]byte(r.String())) - }) - } - switch query.Type { - default: - return fmt.Errorf("unknown query type %v", query.Type) - case client.Once: - return displayOnceResults(ctx, query, cfg) - case client.Poll: - return displayPollingResults(ctx, query, cfg) - case client.Stream: - return displayStreamingResults(ctx, query, cfg) - } -} - -// genHandler takes a provided query and cfg and will build a display function -// that is custom for the client and display options configured. It really -// looks more scary than it is. For each client type and display method you -// need to build a custom handler for display the raw values rather than -// the normal "Leaf" value that client normally works with. -func genHandler(cfg *Config) client.NotificationHandler { - var buf bytes.Buffer // Reuse the same buffer in either case. - iDisplay := func(p client.Path, v interface{}, ts time.Time) { - buf.Reset() - buf.WriteString(strings.Join(p, cfg.Delimiter)) - buf.WriteString(fmt.Sprintf(", %v", v)) - var t interface{} - switch cfg.Timestamp { - default: // Assume user has passed a valid layout for time.Format - t = ts.Format(cfg.Timestamp) - case "": // Timestamp disabled. - case "on": - t = ts.Format(layout) - case "raw": - t = ts.UnixNano() - } - if t != nil { - buf.WriteString(fmt.Sprintf(", %v", t)) - } - if cfg.Latency { - buf.WriteString(fmt.Sprintf(", %s", time.Since(ts))) - } - cfg.Display(buf.Bytes()) - } - return func(n client.Notification) error { - switch v := n.(type) { - default: - return fmt.Errorf("invalid type: %#v", v) - case client.Update: - iDisplay(v.Path, v.Val, v.TS) - case client.Delete: - iDisplay(v.Path, v.Val, v.TS) - case client.Sync, client.Connected: - case client.Error: - return v - } - return nil - } -} - -// displaySingleResults displays each key/value pair returned on a single line. -func displaySingleResults(ctx context.Context, query client.Query, cfg *Config) error { - query.NotificationHandler = genHandler(cfg) - c := &client.BaseClient{} - if err := c.Subscribe(ctx, query); err != nil { - return fmt.Errorf("client had error while displaying results:\n\t%v", err) - } - return nil -} - -// displayProtoResults displays the raw protos returned for the supplied query. -func displayProtoResults(ctx context.Context, query client.Query, cfg *Config, formatter func(proto.Message) []byte) error { - var sum int64 - query.ProtoHandler = func(msg proto.Message) error { - if cfg.DisplaySize { - sum += int64(proto.Size(msg)) - } - cfg.Display(formatter(msg)) - return nil - } - c := &client.BaseClient{} - if err := c.Subscribe(ctx, query, cfg.ClientTypes...); err != nil { - return fmt.Errorf("client had error while displaying results:\n\t%v", err) - } - if cfg.DisplaySize { - cfg.Display([]byte(fmt.Sprintf("// total response size: %d", sum))) - } - return nil -} - -func displayPeer(c client.Client, cfg *Config) { - if !cfg.DisplayPeer { - return - } - var peer string - impl, err := c.Impl() - if err != nil { - return - } - if v, ok := impl.(interface { - Peer() string - }); ok { - peer = v.Peer() - } - if peer == "" { - cfg.Display([]byte("// No peer found for client")) - return - } - cfg.Display([]byte(fmt.Sprintf("// CLI peer: %s", peer))) -} - -// displayOnceResults builds all the results returned for for one application of -// query to the OpenConfig data tree and displays the resulting tree in JSON. -func displayOnceResults(ctx context.Context, query client.Query, cfg *Config) error { - c := client.New() - if err := c.Subscribe(ctx, query, cfg.ClientTypes...); err != nil { - return fmt.Errorf("client had error while displaying results:\n\t%v", err) - } - displayPeer(c, cfg) - displayWalk(query.Target, c, cfg) - return nil -} - -func countComplete(cfg *Config) bool { - switch { - case cfg.countExhausted: - return true - case cfg.Count == 0: - default: - cfg.Count-- - if cfg.Count == 0 { - cfg.countExhausted = true - } - } - return false -} - -// displayPollingResults repeatedly calls displayOnceResults at the requested -// interval. -func displayPollingResults(ctx context.Context, query client.Query, cfg *Config) error { - c := client.New() - if err := c.Subscribe(ctx, query, cfg.ClientTypes...); err != nil { - return fmt.Errorf("client had error while displaying results:\n\t%v", err) - } - defer c.Close() - header := false - for !countComplete(cfg) { - if err := c.Poll(); err != nil { - return fmt.Errorf("client.Poll(): %v", err) - } - if !header { - displayPeer(c, cfg) - header = true - } - displayWalk(query.Target, c, cfg) - if !cfg.countExhausted { - time.Sleep(cfg.PollingInterval) - } - } - return nil -} - -// displayStreamingResults calls displayOnceResults one time, followed by -// subsequent individual updates as they arrive. -func displayStreamingResults(ctx context.Context, query client.Query, cfg *Config) error { - c := client.New() - complete := false - display := func(path []string, ts time.Time, val interface{}) { - if !complete { - return - } - b := make(pathmap) - if cfg.Timestamp != "" { - b.add(append(path, "timestamp"), ts) - b.add(append(path, "value"), val) - } else { - b.add(path, val) - } - result, err := json.MarshalIndent(b, cfg.DisplayPrefix, cfg.DisplayIndent) - if err != nil { - cfg.Display([]byte(fmt.Sprintf("Error: failed to marshal result: %v", err))) - return - } - cfg.Display(result) - } - query.NotificationHandler = func(n client.Notification) error { - switch v := n.(type) { - case client.Update: - display(v.Path, v.TS, v.Val) - case client.Delete: - display(v.Path, v.TS, v.Val) - case client.Sync: - displayWalk(query.Target, c, cfg) - complete = true - case client.Error: - cfg.Display([]byte(fmt.Sprintf("Error: %v", v))) - } - return nil - } - return c.Subscribe(ctx, query, cfg.ClientTypes...) -} - -func displayWalk(target string, c *client.CacheClient, cfg *Config) { - b := make(pathmap) - var addFunc func(path []string, v client.TreeVal) - switch cfg.Timestamp { - default: - addFunc = func(path []string, v client.TreeVal) { - b.add(path, map[string]interface{}{ - "value": v.Val, - "timestamp": v.TS.Format(cfg.Timestamp), - }) - } - case "on": - addFunc = func(path []string, v client.TreeVal) { - b.add(path, map[string]interface{}{ - "value": v.Val, - "timestamp": v.TS.Format(layout), - }) - } - case "raw": - addFunc = func(path []string, v client.TreeVal) { - b.add(path, map[string]interface{}{ - "value": v.Val, - "timestamp": v.TS.UnixNano(), - }) - } - case "off", "": - addFunc = func(path []string, v client.TreeVal) { - b.add(path, v.Val) - } - } - c.WalkSorted(func(path []string, _ *ctree.Leaf, value interface{}) { - switch v := value.(type) { - default: - b.add(path, fmt.Sprintf("INVALID NODE %#v", value)) - case *ctree.Tree: - case client.TreeVal: - addFunc(path, v) - } - }) - result, err := json.MarshalIndent(b, cfg.DisplayPrefix, cfg.DisplayIndent) - if err != nil { - cfg.Display([]byte(fmt.Sprintf("Error: failed to marshal result: %v", err))) - return - } - cfg.Display(result) - if cfg.DisplaySize { - cfg.Display([]byte(fmt.Sprintf("// total response size: %d", len(result)))) - } -} - -type pathmap map[string]interface{} - -func (m pathmap) add(path []string, v interface{}) { - if len(path) == 1 { - m[path[0]] = v - return - } - - mm, ok := m[path[0]] - if !ok { - mm = make(pathmap) - } - mm.(pathmap).add(path[1:], v) - m[path[0]] = mm -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cli/cli_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/cli/cli_test.go deleted file mode 100644 index 3e88abb19..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cli/cli_test.go +++ /dev/null @@ -1,859 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 cli - -import ( - "context" - "crypto/tls" - "regexp" - "sort" - "strings" - "testing" - "time" - - "google.golang.org/grpc" - "github.com/openconfig/gnmi/client" - _ "github.com/openconfig/gnmi/client/gnmi" - "github.com/openconfig/gnmi/testing/fake/gnmi" - "github.com/openconfig/gnmi/testing/fake/testing/grpc/config" - - fpb "github.com/openconfig/gnmi/testing/fake/proto" -) - -func TestSendQueryAndDisplayFail(t *testing.T) { - tests := []struct { - desc string - q client.Query - cfg *Config - want string - }{{ - desc: "addr not set", - want: "Destination.Addrs is empty", - q: client.Query{Queries: []client.Path{{"a"}}, Type: client.Once}, - cfg: &Config{DisplayType: "group"}, - }, { - desc: "invalid display", - want: `unknown display type "invalid display"`, - q: client.Query{Queries: []client.Path{{"a"}}, Type: client.Once}, - cfg: &Config{DisplayType: "invalid display"}, - }, { - desc: "unknown query type", - want: `unknown query type`, - q: client.Query{Queries: []client.Path{{"a"}}, Type: client.Unknown}, - cfg: &Config{DisplayType: "group"}, - }} - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - if err := sendQueryAndDisplay(context.Background(), tt.q, tt.cfg); err == nil || !strings.Contains(err.Error(), tt.want) { - t.Errorf("sendQueryAndDisplay(ctx, %v, %v): unexpected error, got %v want error contains %q", tt.q, tt.cfg, err, tt.want) - } - }) - } -} - -func TestSendQueryAndDisplay(t *testing.T) { - var displayOut string - display := func(b []byte) { - displayOut += string(b) + "\n" - } - tests := []struct { - desc string - updates []*fpb.Value - query client.Query - cfg Config - want string - sort bool - }{{ - desc: "single target single output with provided layout", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Delimiter: "/", - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "single", - Timestamp: "2006-01-02-15:04:05", - }, - want: `dev1/a/b, 5, 1969-12-31-16:00:00 -`, - }, { - desc: "single target single output with timestamp on", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Delimiter: "/", - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "single", - Timestamp: "on", - }, - want: `dev1/a/b, 5, 1969-12-31-16:00:00.000000100 -`, - }, { - desc: "single target single output", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Delimiter: "/", - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "single", - }, - want: `dev1/a/b, 5 -`, - }, { - desc: "single target group output", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "group", - }, - want: `{ - "dev1": { - "a": { - "b": 5 - } - } -} -`, - }, { - desc: "single target single output with peer", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "group", - DisplayPeer: true, - }, - want: `// CLI peer: 127.0.0.1:port -{ - "dev1": { - "a": { - "b": 5 - } - } -} -`, - }, { - desc: "single target single output with latency", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Delimiter: "/", - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "single", - Latency: true, - }, - want: `dev1/a/b, 5, hm.s -`, - }, { - desc: "single target single output with delete", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - {Path: []string{"a", "c"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - {Path: []string{"a", "c"}, Value: &fpb.Value_Delete{Delete: &fpb.DeleteValue{}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 200}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Delimiter: "/", - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "single", - }, - want: `dev1/a/b, 5 -dev1/a/c, 5 -dev1/a/c, -`, - }, { - desc: "single target multiple paths", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - // The following is disallowed because the tree already has a branch where - // this leaf requests to be, thus dropped. - {Path: []string{"a"}, Value: &fpb.Value_StringValue{StringValue: &fpb.StringValue{Value: "foo"}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 105}}, - // The following is disallowed because the tree already has a leaf where - // this branch requests to be, thus dropped. - {Path: []string{"a", "b", "c"}, Value: &fpb.Value_DoubleValue{DoubleValue: &fpb.DoubleValue{Value: 3.14}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "group", - }, - want: `{ - "dev1": { - "a": { - "b": 5 - } - } -} -`, - }, { - desc: "single target single paths (proto)", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 1440807212000000000}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Display: display, - DisplayType: "proto", - }, - want: `sync_response: true - -update: < - timestamp: 1440807212000000000 - prefix: < - target: "dev1" - > - update: < - path: < - element: "a" - element: "b" - > - val: < - int_val: 5 - > - > -> - -`, - }, { - desc: "single target single paths (proto) with size", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 1440807212000000000}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Display: display, - DisplayType: "proto", - DisplaySize: true, - }, - want: `sync_response: true - -update: < - timestamp: 1440807212000000000 - prefix: < - target: "dev1" - > - update: < - path: < - element: "a" - element: "b" - > - val: < - int_val: 5 - > - > -> - -// total response size: 36 -`, - }, { - desc: "single target multiple paths (with timestamp)", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 1440807212000000000}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 1440807212000000001}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "group", - Timestamp: "on", - }, - want: `{ - "dev1": { - "a": { - "b": { - "timestamp": "2015-08-28-17:13:32.000000000", - "value": 5 - } - } - } -} -`, - }, { - desc: "single target multiple paths (with raw timestamp)", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "group", - Timestamp: "raw", - }, - want: `{ - "dev1": { - "a": { - "b": { - "timestamp": 100, - "value": 5 - } - } - } -} -`, - }, { - desc: "single target multiple paths (with DoW timestamp)", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 1440807212000000000}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 1440807212000000001}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "group", - Timestamp: "Monday", - }, - want: `{ - "dev1": { - "a": { - "b": { - "timestamp": "Friday", - "value": 5 - } - } - } -} -`, - }, { - desc: "single target multiple root paths", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - {Path: []string{"a", "c"}, Value: &fpb.Value_DoubleValue{DoubleValue: &fpb.DoubleValue{Value: 3.25}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 101}}, - {Path: []string{"d", "e", "f"}, Value: &fpb.Value_StringValue{StringValue: &fpb.StringValue{Value: "foo"}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 102}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"*"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "group", - }, - want: `{ - "dev1": { - "a": { - "b": 5, - "c": 3.25 - }, - "d": { - "e": { - "f": "foo" - } - } - } -} -`, - }, { - desc: "single target multiple paths (Pollingx2)", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Poll, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "group", - Count: 2, - PollingInterval: 100 * time.Millisecond, - }, - want: `{ - "dev1": { - "a": { - "b": 5 - } - } -} -{ - "dev1": { - "a": { - "b": 5 - } - } -} -`, - }, { - desc: "single target multiple paths (streaming)", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "group", - // StreamingDuration will expire before Count updates are received because - // no updates are being streamed in the test. - Count: 2, - StreamingDuration: 100 * time.Millisecond, - }, - want: `{ - "dev1": { - "a": { - "b": 5 - } - } -} -`, - }, { - desc: "single target multiple paths (single line)", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - {Path: []string{"a", "c"}, Value: &fpb.Value_DoubleValue{DoubleValue: &fpb.DoubleValue{Value: 3.25}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 101}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Delimiter: "/", - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "single", - }, - want: `dev1/a/b, 5 -dev1/a/c, 3.25 -`, - sort: true, - }, { - desc: "single target multiple paths (single line raw)", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - {Path: []string{"a", "c"}, Value: &fpb.Value_DoubleValue{DoubleValue: &fpb.DoubleValue{Value: 3.25}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 101}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Delimiter: ".", - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "single", - Timestamp: "raw", - }, - want: `dev1.a.b, 5, 100 -dev1.a.c, 3.25, 101 -`, - sort: true, - }, { - desc: "single target multiple paths (proto short)", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Display: display, - DisplayType: "shortproto", - }, - want: `update: update: val: > > -sync_response:true -`, - }, { - desc: "single target multiple paths (with display size)", - updates: []*fpb.Value{ - {Path: []string{"a", "b"}, Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 100}}, - {Value: &fpb.Value_Sync{Sync: 1}, Repeat: 1, Timestamp: &fpb.Timestamp{Timestamp: 300}}, - }, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Display: display, - DisplayIndent: " ", - DisplayType: "group", - DisplaySize: true, - }, - want: `{ - "dev1": { - "a": { - "b": 5 - } - } -} -// total response size: 49 -`, - }} - - opt, err := config.WithSelfTLSCert() - if err != nil { - t.Fatalf("failed to generate cert: %v", err) - } - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - displayOut = "" - s, err := gnmi.New( - &fpb.Config{ - Target: "dev1", - DisableSync: true, - Values: tt.updates, - }, - []grpc.ServerOption{opt}, - ) - if err != nil { - t.Fatal("failed to start test server") - } - defer s.Close() - - tt.query.Addrs = []string{s.Address()} - - if err := QueryDisplay(context.Background(), tt.query, &tt.cfg); err != nil { - // This is fine if we use cfg.StreamingDuration. - t.Logf("sendQueryAndDisplay returned error: %v", err) - } - - // The test server comes up on an arbitrary port. Remove the port number - // from the output before comparison. - re := regexp.MustCompile("localhost:[0-9]*") - got := re.ReplaceAllLiteralString(displayOut, "127.0.0.1:port") - reLat := regexp.MustCompile(`\d+h\d+m\d+.\d+s`) - got = reLat.ReplaceAllLiteralString(got, "hm.s") - if tt.sort { - lines := strings.Split(got, "\n") - sort.Strings(lines) - // move blank line to end - lines = append(lines[1:], lines[0]) - got = strings.Join(lines, "\n") - } - - if got != tt.want { - t.Errorf("sendQueryAndDisplay(ctx, address, %v, %v):\ngot(%d):\n%s\nwant(%d):\n%s", tt.query, tt.cfg, len(got), got, len(tt.want), tt.want) - } - }) - } -} - -func TestGNMIClient(t *testing.T) { - var displayOut string - display := func(b []byte) { - displayOut += string(b) + "\n" - } - tests := []struct { - desc string - updates []*fpb.Value - query client.Query - cfg Config - want string - sort bool - }{{ - desc: "single target single output with provided layout", - updates: []*fpb.Value{{ - Path: []string{"a"}, - Timestamp: &fpb.Timestamp{Timestamp: 100}, - Repeat: 1, - Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, - }, { - Path: []string{"a", "b"}, - Timestamp: &fpb.Timestamp{Timestamp: 100}, - Repeat: 1, - Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, - }, { - Path: []string{"a", "b"}, - Timestamp: &fpb.Timestamp{Timestamp: 200}, - Repeat: 1, - Value: &fpb.Value_Delete{Delete: &fpb.DeleteValue{}}, - }, { - Timestamp: &fpb.Timestamp{Timestamp: 300}, - Repeat: 1, - Value: &fpb.Value_Sync{Sync: 1}, - }}, - query: client.Query{ - Target: "dev", - Queries: []client.Path{{"a"}}, - Type: client.Once, - Timeout: 3 * time.Second, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Delimiter: "/", - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "single", - Timestamp: "2006-01-02-15:04:05", - }, - want: `dev/a, 5, 1969-12-31-16:00:00 -dev/a/b, 5, 1969-12-31-16:00:00 -dev/a/b, , 1969-12-31-16:00:00 -`, - }, { - desc: "single target group output with provided layout", - updates: []*fpb.Value{{ - Path: []string{"a"}, - Timestamp: &fpb.Timestamp{Timestamp: 100}, - Repeat: 1, - Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, - }, { - Path: []string{"a", "b"}, - Timestamp: &fpb.Timestamp{Timestamp: 100}, - Repeat: 1, - Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, - }, { - Path: []string{"a", "b"}, - Timestamp: &fpb.Timestamp{Timestamp: 200}, - Repeat: 1, - Value: &fpb.Value_Delete{Delete: &fpb.DeleteValue{}}, - }, { - Timestamp: &fpb.Timestamp{Timestamp: 300}, - Repeat: 1, - Value: &fpb.Value_Sync{Sync: 1}, - }}, - query: client.Query{ - Target: "dev", - Queries: []client.Path{{"a"}}, - Type: client.Once, - Timeout: 3 * time.Second, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Delimiter: "/", - Display: display, - DisplayPrefix: "", - DisplayIndent: " ", - DisplayType: "group", - Timestamp: "2006-01-02-15:04:05", - }, - want: `{ - "dev": { - "a": { - "timestamp": "1969-12-31-16:00:00", - "value": 5 - } - } -} -`, - }, { - desc: "single target multiple paths (proto short)", - updates: []*fpb.Value{{ - Path: []string{"a"}, - Timestamp: &fpb.Timestamp{Timestamp: 100}, - Repeat: 1, - Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, - }, { - Path: []string{"a", "b"}, - Timestamp: &fpb.Timestamp{Timestamp: 100}, - Repeat: 1, - Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, - }, { - Path: []string{"a", "b"}, - Timestamp: &fpb.Timestamp{Timestamp: 200}, - Repeat: 1, - Value: &fpb.Value_Delete{Delete: &fpb.DeleteValue{}}, - }, { - Timestamp: &fpb.Timestamp{Timestamp: 300}, - Repeat: 1, - Value: &fpb.Value_Sync{Sync: 1}, - }}, - query: client.Query{ - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - Timeout: 3 * time.Second, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - cfg: Config{ - Display: display, - DisplayType: "shortproto", - }, - want: `update: update: val: > > -update: update: val: > > -update: delete: > -sync_response:true -`, - }} - opt, err := config.WithSelfTLSCert() - if err != nil { - t.Fatalf("failed to generate cert: %v", err) - } - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - displayOut = "" - s, err := gnmi.New( - &fpb.Config{ - Target: "dev1", - DisableSync: true, - Values: tt.updates, - }, - []grpc.ServerOption{opt}, - ) - if err != nil { - t.Fatal("failed to start test server") - } - defer s.Close() - - tt.query.Addrs = []string{s.Address()} - if err := QueryDisplay(context.Background(), tt.query, &tt.cfg); err != nil { - // This is fine if we use cfg.StreamingDuration. - t.Logf("sendQueryAndDisplay returned error: %v", err) - } - - // The test server comes up on an arbitrary port. Remove the port number - // from the output before comparison. - re := regexp.MustCompile("127.0.0.1:[0-9]*") - got := re.ReplaceAllLiteralString(displayOut, "127.0.0.1:port") - reLat := regexp.MustCompile(`\d+h\d+m\d+.\d+s`) - got = reLat.ReplaceAllLiteralString(got, "hm.s") - if got != tt.want { - t.Errorf("sendQueryAndDisplay(ctx, address, %v, %v):\ngot(%d):\n%s\nwant(%d):\n%s", tt.query, tt.cfg, len(got), got, len(tt.want), tt.want) - } - }) - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/cache.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/cache.go deleted file mode 100644 index d1a33091b..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/cache.go +++ /dev/null @@ -1,116 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 client - -import ( - "context" - "fmt" - - log "github.com/golang/glog" - "github.com/openconfig/gnmi/ctree" -) - -// Client adds a caching layer on top of a simple query client. -// -// It works similarly to BaseClient and adds the Leaves method to return -// current tree state. -type CacheClient struct { - *BaseClient - *ctree.Tree - synced chan struct{} - clientHandler NotificationHandler -} - -var _ Client = &CacheClient{} - -// New returns an initialized caching client. -func New() *CacheClient { - c := &CacheClient{ - BaseClient: &BaseClient{}, - Tree: &ctree.Tree{}, - synced: make(chan struct{}), - } - return c -} - -// Subscribe implements the Client interface. -func (c *CacheClient) Subscribe(ctx context.Context, q Query, clientType ...string) error { - q.ProtoHandler = nil - if q.NotificationHandler != nil { - c.clientHandler = q.NotificationHandler - } - q.NotificationHandler = c.defaultHandler - return c.BaseClient.Subscribe(ctx, q, clientType...) -} - -// defaultHandler is passed into the client specific implementations. It will -// be called for each leaf notification generated by the client. -func (c *CacheClient) defaultHandler(n Notification) error { - switch v := n.(type) { - default: - return fmt.Errorf("invalid type %#v", v) - case Connected: // Ignore. - case Error: - return fmt.Errorf("received error: %v", v) - case Update: - c.Add(v.Path, TreeVal{TS: v.TS, Val: v.Val}) - case Delete: - c.Delete(v.Path) - case Sync: - select { - default: - close(c.synced) - case <-c.synced: - } - } - if c.clientHandler != nil { - return c.clientHandler(n) - } - return nil -} - -// Poll implements the Client interface. -// Poll also closes the channel returned by Synced and resets it. -func (c *CacheClient) Poll() error { - select { - default: - close(c.synced) - case <-c.synced: - } - return c.BaseClient.Poll() -} - -// Synced will close when a sync is recieved from the query. -func (c *CacheClient) Synced() <-chan struct{} { - return c.synced -} - -// Leaves returns the current state of the received tree. It's safe to call at -// any point after New. -func (c *CacheClient) Leaves() Leaves { - // Convert node items into Leaf (expand TreeVal leaves). - var pvs Leaves - c.WalkSorted(func(path []string, _ *ctree.Leaf, value interface{}) { - tv, ok := value.(TreeVal) - if !ok { - log.Errorf("Invalid value in tree: %s=%#v", path, value) - return - } - pvs = append(pvs, Leaf{Path: path, Val: tv.Val, TS: tv.TS}) - }) - return pvs -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/cache_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/cache_test.go deleted file mode 100644 index c4dff8e81..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/cache_test.go +++ /dev/null @@ -1,244 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 client_test - -import ( - "context" - "errors" - "fmt" - "reflect" - "testing" - "time" - - "github.com/openconfig/gnmi/client" - fake "github.com/openconfig/gnmi/client/fake" -) - -const ( - cacheTest = "cacheTest" - cacheFail = "cacheFail" -) - -func TestPollCache(t *testing.T) { - tests := []struct { - desc string - q client.Query - u [][]interface{} - want []client.Leaves - err bool - }{{ - desc: "invalid query type", - q: client.Query{ - Type: client.Once, - Addrs: []string{"fake"}, - Queries: []client.Path{{"*"}}, - NotificationHandler: func(client.Notification) error { return nil }, - }, - u: [][]interface{}{{ - client.Update{TS: time.Unix(0, 0), Path: client.Path{"a", "b"}, Val: 1}, - client.Sync{}, - }, {}}, - want: []client.Leaves{{ - {TS: time.Unix(0, 0), Path: client.Path{"a", "b"}, Val: 1}, - }, {}}, - err: true, - }, { - desc: "Poll With Entry Test", - q: client.Query{ - Type: client.Poll, - Addrs: []string{"fake"}, - Queries: []client.Path{{"*"}}, - NotificationHandler: func(client.Notification) error { return nil }, - }, - u: [][]interface{}{{ - client.Update{TS: time.Unix(0, 0), Path: client.Path{"a", "b"}, Val: 1}, - client.Sync{}, - }, { - client.Update{TS: time.Unix(3, 0), Path: client.Path{"a", "b"}, Val: 1}, - client.Sync{}, - }}, - want: []client.Leaves{{ - {TS: time.Unix(0, 0), Path: client.Path{"a", "b"}, Val: 1}, - }, { - {TS: time.Unix(3, 0), Path: client.Path{"a", "b"}, Val: 1}, - }}, - }} - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - fake.Mock(cacheTest, tt.u[0]) - c := client.New() - defer c.Close() - if err := c.Subscribe(context.Background(), tt.q, cacheTest); err != nil { - t.Errorf("Subscribe() failed: %v", err) - } - l := c.Leaves() - if !reflect.DeepEqual(l, tt.want[0]) { - t.Fatalf("Unexpected updates: got:\n%v\nwant:\n%v", l, tt.want[0]) - } - impl, err := c.Impl() - if err != nil { - t.Fatalf("c.Impl: %v", err) - } - impl.(*fake.Client).Reset(tt.u[1]) - err = c.Poll() - switch { - case err != nil && tt.err: - return - case err != nil && !tt.err: - t.Errorf("Poll() failed: %v", err) - return - case err == nil && tt.err: - t.Errorf("Poll() expected error.") - return - } - l = c.Leaves() - if !reflect.DeepEqual(l, tt.want[1]) { - t.Fatalf("Unexpected updates: got:\n%v\nwant:\n%v", l, tt.want[1]) - } - }) - } -} - -func TestCache(t *testing.T) { - fake.Mock(cacheFail, []interface{}{errors.New("client failed")}) - - nTest := false - tests := []struct { - desc string - q client.Query - u []interface{} - clientType []string - want client.Leaves - err bool - }{{ - desc: "Error New", - clientType: []string{cacheFail}, - q: client.Query{ - Type: client.Once, - Addrs: []string{"fake"}, - Queries: []client.Path{{"*"}}, - }, - want: nil, - err: true, - }, { - desc: "Once Test", - q: client.Query{ - Type: client.Once, - Addrs: []string{"fake"}, - Queries: []client.Path{{"*"}}, - }, - u: []interface{}{ - client.Update{TS: time.Unix(1, 0), Path: client.Path{"a", "b"}, Val: 1}, - client.Delete{TS: time.Unix(2, 0), Path: client.Path{"a", "b"}}, - client.Sync{}, - }, - want: nil, - }, { - desc: "Once With Entry Test", - q: client.Query{ - Type: client.Once, - Addrs: []string{"fake"}, - Queries: []client.Path{{"*"}}, - }, - u: []interface{}{ - client.Update{TS: time.Unix(0, 0), Path: client.Path{"a", "b"}, Val: 1}, - client.Sync{}, - }, - want: client.Leaves{ - {TS: time.Unix(0, 0), Path: client.Path{"a", "b"}, Val: 1}, - }, - }, { - desc: "Custom handler with Sync test", - q: client.Query{ - Type: client.Once, - Addrs: []string{"fake"}, - Queries: []client.Path{{"*"}}, - NotificationHandler: func(n client.Notification) error { - if _, ok := n.(client.Sync); ok { - nTest = true - } - return nil - }, - }, - u: []interface{}{ - client.Update{TS: time.Unix(0, 0), Path: client.Path{"a", "b"}, Val: 1}, - client.Sync{}, - }, - want: client.Leaves{ - {TS: time.Unix(0, 0), Path: client.Path{"a", "b"}, Val: 1}, - }, - }, { - desc: "Error on notification", - q: client.Query{ - Type: client.Once, - Addrs: []string{"fake"}, - Queries: []client.Path{{"*"}}, - }, - u: []interface{}{ - client.Error{}, - }, - err: true, - }, { - desc: "Error on Recv", - q: client.Query{ - Type: client.Once, - Addrs: []string{"fake"}, - Queries: []client.Path{{"*"}}, - }, - u: []interface{}{ - fmt.Errorf("Recv() error"), - }, - err: true, - }} - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - fake.Mock(cacheTest, tt.u) - - c := client.New() - defer c.Close() - if tt.q.NotificationHandler != nil { - go func() { - <-c.Synced() - if !nTest { - t.Errorf("Synced() failed: got %v, want true", nTest) - } - }() - } else { - tt.q.NotificationHandler = func(client.Notification) error { return nil } - } - clientType := []string{cacheTest} - if tt.clientType != nil { - clientType = tt.clientType - } - err := c.Subscribe(context.Background(), tt.q, clientType...) - switch { - case err != nil && tt.err: - return - case err != nil && !tt.err: - t.Errorf("Subscribe() failed: %v", err) - return - case err == nil && tt.err: - t.Errorf("Subscribe() expected error.") - return - } - l := c.Leaves() - if !reflect.DeepEqual(l, tt.want) { - t.Fatalf("Unexpected updates: got:\n%v\nwant:\n%v", l, tt.want) - } - }) - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/client.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/client.go deleted file mode 100644 index 007bc68ef..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/client.go +++ /dev/null @@ -1,215 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 client provides a generic access layer for streaming telemetry -// providers. -// -// The Client interface is implemented by 3 types in this package: -// -// - BaseClient simply forwards all messages from the underlying connection to -// NotificationHandler or ProtoHandler (see type Query). -// -// - CacheClient wraps around BaseClient and adds a persistence layer for all -// notifications. The notifications build up an internal tree which can be -// queried and walked using CacheClient's methods. -// -// - ReconnectClient wraps around any Client implementation (BaseClient, -// CacheClient or a user-provided one) and adds transparent reconnection loop -// in Subscribe. Reconnection attempts are done with exponential backoff. -// -// This package uses pluggable transport implementations. For example, for gNMI -// targets you need to add this blank import: -// import _ "github.com/openconfig/gnmi/client/gnmi" -// -// That import will automatically register itself as available ClientType in -// this package (using func init). -// -// If you want to write a custom implementation, implement Impl interface and -// register it with unique name via func Register. -// -// Take a look at package examples in godoc for typical use cases. -package client - -import ( - "context" - "errors" - "fmt" - "io" - "sync" - - log "github.com/golang/glog" -) - -// Client defines a set of methods which every client must implement. -// This package provides a few implementations: BaseClient, CacheClient, -// ReconnectClient. -// -// Do not confuse this with Impl. -type Client interface { - // Subscribe will perform the provided query against the requested - // clientType. clientType is the name of a specific Impl specified in - // Register (most implementations will call Register in init()). - // - // It will try each clientType listed in order until one succeeds. If - // clientType is nil, it will try each registered clientType in random - // order. - Subscribe(ctx context.Context, q Query, clientType ...string) error - // Poll will send a poll request to the server and process all - // notifications. It is up the caller to identify the sync and realize the - // Poll is complete. - Poll() error - // Close terminates the underlying Impl, which usually terminates the - // connection right away. - // Close must be called to release any resources that Impl could have - // allocated. - Close() error - // Impl will return the underlying client implementation. Most users - // shouldn't use this. - Impl() (Impl, error) -} - -var ( - // ErrStopReading is the common error defined to have the client stop a read - // loop. - ErrStopReading = errors.New("stop the result reading loop") - // ErrClientInit is the common error for when making calls before the client - // has been started via Subscribe. - ErrClientInit = errors.New("Subscribe() must be called before any operations on client") - // ErrUnsupported is returned by Impl's methods when the underlying - // implementation doesn't support it. - ErrUnsupported = errors.New("operation not supported by client implementation") -) - -// BaseClient is a streaming telemetry client with minimal footprint. The -// caller must call Subscribe to perform the actual query. BaseClient stores no -// state. All updates must be handled by the provided handlers inside of -// Query. -// -// The zero value of BaseClient is ready for use (there is no constructor). -type BaseClient struct { - mu sync.RWMutex - closed bool - clientImpl Impl - - query Query -} - -var _ Client = &BaseClient{} - -// Subscribe implements the Client interface. -func (c *BaseClient) Subscribe(ctx context.Context, q Query, clientType ...string) error { - if err := q.Validate(); err != nil { - return err - } - if len(clientType) == 0 { - clientType = RegisteredImpls() - } - - // TODO: concurrent subscribes can be removed after we enforce reflection - // at client Impl level. - fn := func(ctx context.Context, typ string, input interface{}) (Impl, error) { - q := input.(Query) - impl, err := NewImpl(ctx, q.Destination(), typ) - if err != nil { - return nil, err - } - if err := impl.Subscribe(ctx, q); err != nil { - impl.Close() - return nil, err - } - return impl, nil - } - impl, err := getFirst(ctx, clientType, q, fn) - if err != nil { - return err - } - - c.mu.Lock() - c.query = q - if c.clientImpl != nil { - c.clientImpl.Close() - } - c.clientImpl = impl - c.closed = false - c.mu.Unlock() - - return c.run(impl) -} - -// Poll implements the Client interface. -func (c *BaseClient) Poll() error { - impl, err := c.Impl() - if err != nil { - return ErrClientInit - } - if c.query.Type != Poll { - return fmt.Errorf("Poll() can only be used on Poll query type: %v", c.query.Type) - } - if err := impl.Poll(); err != nil { - return err - } - return c.run(impl) -} - -// Close implements the Client interface. -func (c *BaseClient) Close() error { - c.mu.Lock() - defer c.mu.Unlock() - if c.clientImpl == nil { - return ErrClientInit - } - c.closed = true - return c.clientImpl.Close() -} - -// Impl implements the Client interface. -func (c *BaseClient) Impl() (Impl, error) { - c.mu.Lock() - defer c.mu.Unlock() - if c.clientImpl == nil { - return nil, ErrClientInit - } - return c.clientImpl, nil -} - -func (c *BaseClient) run(impl Impl) error { - for { - err := impl.Recv() - switch err { - default: - log.V(1).Infof("impl.Recv() received unknown error: %v", err) - impl.Close() - return err - case io.EOF, ErrStopReading: - log.V(1).Infof("impl.Recv() stop marker: %v", err) - return nil - case nil: - } - - // Close fast, so that we don't deliver any buffered updates. - // - // Note: this approach still allows at most 1 update through after - // Close. A more thorough solution would be to do the check at - // Notification/ProtoHandler or Impl level, but that would involve much - // more work. - c.mu.RLock() - closed := c.closed - c.mu.RUnlock() - if closed { - return nil - } - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/client_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/client_test.go deleted file mode 100644 index f4dd41aa7..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/client_test.go +++ /dev/null @@ -1,566 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 client_test - -import ( - "context" - "fmt" - "reflect" - "sort" - "testing" - "time" - - "github.com/golang/protobuf/proto" - "github.com/openconfig/gnmi/client" - fclient "github.com/openconfig/gnmi/client/fake" -) - -const ( - defaultQuery = "*" -) - -func testImpl(ctx context.Context, d client.Destination) (client.Impl, error) { - if len(d.Addrs) > 0 && d.Addrs[0] == "error" { - return nil, fmt.Errorf("error") - } - return fclient.New(ctx, d) -} - -func TestRegister(t *testing.T) { - // In case some other test forgot, clean out registered impls. - client.ResetRegisteredImpls() - // Verify Reset - if got := client.RegisteredImpls(); got != nil { - t.Fatalf("client.ResetRegisteredImpls() failed: got %v want nil", got) - } - // Clean out what we registered. - defer client.ResetRegisteredImpls() - - // Registered names must not be reused unless you expect an error in duplicate - tests := []struct { - desc string - name string - f client.InitImpl - clientType []string - rErr bool - nErr bool - }{{ - desc: "Missing Impl", - name: "foo", - rErr: true, - }, { - desc: "No registration, unspecified client", - nErr: true, - }, { - desc: "Name only", - name: "foo", - rErr: true, - }, { - desc: "Valid Client", - name: "bar", - f: testImpl, - clientType: []string{"bar"}, - nErr: false, - }, { - desc: "Unspecified client with prior registeration", - nErr: false, - }, { - desc: "Duplicate Registration", - name: "bar", - f: testImpl, - clientType: []string{"bar"}, - rErr: true, - }, { - desc: "Unknown Registration", - name: "foobar", - f: testImpl, - clientType: []string{"zbaz"}, - nErr: true, - }, { - desc: "Multiple clients, one valid", - clientType: []string{"zbaz", "bar"}, - nErr: false, - }} - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - if tt.name != "" { - err := client.Register(tt.name, tt.f) - switch { - case tt.rErr && err == nil: - t.Fatalf("Register(%q, %v) unexpected success", tt.name, tt.f) - case !tt.rErr && err != nil: - t.Fatalf("Register(%q, %v) failed: %v", tt.name, tt.f, err) - case tt.rErr && err != nil: - return - } - } - err := client.New().Subscribe(context.Background(), client.Query{ - Type: client.Once, - Addrs: []string{"fake"}, - Queries: []client.Path{{"*"}}, - NotificationHandler: func(client.Notification) error { return nil }, - }, tt.clientType...) - switch { - case tt.nErr && err == nil: - t.Fatalf("Subscribe() unexpected success") - case !tt.nErr && err != nil: - t.Fatalf("Subscribe() failed: %v", err) - case tt.nErr && err != nil: - return - } - }) - } -} - -func TestRegisterHangingImpl(t *testing.T) { - // This test makes sure that a hanging client.NewImpl (due to blocked - // InitImpl, e.g. waiting for timeout) doesn't prevent other client.NewImpl - // calls from blocking too. This may happen due to a global mutex in - // register.go - - // In case some other test forgot, clean out registered impls. - client.ResetRegisteredImpls() - // Clean out what we registered. - defer client.ResetRegisteredImpls() - - blocked := make(chan struct{}) - client.Register("blocking", func(ctx context.Context, _ client.Destination) (client.Impl, error) { - close(blocked) - // Block until test returns. - <-ctx.Done() - return nil, nil - }) - client.Register("regular", func(context.Context, client.Destination) (client.Impl, error) { - return nil, nil - }) - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - connected := make(chan string, 1) - go func() { - client.NewImpl(ctx, client.Destination{}, "blocking") - connected <- "blocking" - }() - go func() { - // Wait for blocking Impl to start blocking. - <-blocked - client.NewImpl(ctx, client.Destination{}, "regular") - connected <- "regular" - }() - - select { - case got := <-connected: - if got != "regular" { - t.Errorf(`connected Impl %q, want "regular"`, got) - } - case <-time.After(5 * time.Second): - t.Error("blocking InitImpl prevents regular InitImpl from connecting (waiter 5s)") - } -} - -func TestQuery(t *testing.T) { - tests := []struct { - desc string - in client.Query - wantPath []client.Path - err bool - client []string - }{{ - desc: "Empty Query", - in: client.Query{}, - err: true, - wantPath: []client.Path{{defaultQuery}}, - }, { - desc: "No Addr", - wantPath: []client.Path{{defaultQuery}}, - in: client.Query{ - Queries: []client.Path{{"foo", "bar"}, {"a", "b"}}, - Type: client.Once, - }, - err: true, - }, { - desc: "No Target", - wantPath: []client.Path{{defaultQuery}}, - in: client.Query{ - Addrs: []string{"fake addr"}, - Queries: []client.Path{{"foo", "bar"}, {"a", "b"}}, - Type: client.Once, - }, - err: true, - }, { - desc: "No Type", - wantPath: []client.Path{{defaultQuery}}, - in: client.Query{ - Addrs: []string{"fake addr"}, - Target: "", - Queries: []client.Path{{"foo", "bar"}, {"a", "b"}}, - }, - err: true, - }, { - desc: "No Queries", - wantPath: []client.Path{{defaultQuery}}, - in: client.Query{ - Addrs: []string{"fake addr"}, - Target: "", - Type: client.Once, - }, - err: true, - }, { - desc: "Both handlers set", - wantPath: []client.Path{{"foo", "bar"}, {"a", "b"}}, - in: client.Query{ - Addrs: []string{"fake addr"}, - Target: "", - Queries: []client.Path{{"foo", "bar"}, {"a", "b"}}, - Type: client.Once, - NotificationHandler: func(_ client.Notification) error { return nil }, - ProtoHandler: func(_ proto.Message) error { return nil }, - }, - err: true, - }, { - desc: "Valid Query", - wantPath: []client.Path{{"foo", "bar"}, {"a", "b"}}, - in: client.Query{ - Addrs: []string{"fake addr"}, - Target: "", - Queries: []client.Path{{"foo", "bar"}, {"a", "b"}}, - Type: client.Once, - NotificationHandler: func(_ client.Notification) error { return nil }, - }, - }, { - desc: "Password contains forbidden characters", - in: client.Query{ - Credentials: &client.Credentials{Password: "\n"}, - }, - err: true, - }, { - desc: "Username contains forbidden characters", - in: client.Query{ - Credentials: &client.Credentials{Username: "\n"}, - }, - err: true, - }} - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - err := tt.in.Validate() - switch { - case err != nil && tt.err: - return - case err != nil && !tt.err: - t.Errorf("Validate() failed: %v", err) - return - case err == nil && tt.err: - t.Errorf("Validate() expected error.") - return - } - if !reflect.DeepEqual(tt.wantPath, tt.in.Queries) { - t.Errorf("Validate() failed: got %v, want %v", tt.in.Queries, tt.wantPath) - } - }) - } -} - -func TestLeaves(t *testing.T) { - tests := []struct { - desc string - in client.Leaves - want client.Leaves - }{{ - desc: "sorted", - in: client.Leaves{ - {TS: time.Unix(0, 0), Path: client.Path{"a"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"a", "b"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"a", "b", "c"}, Val: 1}, - }, - want: client.Leaves{ - {TS: time.Unix(0, 0), Path: client.Path{"a"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"a", "b"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"a", "b", "c"}, Val: 1}, - }, - }, { - desc: "unsorted", - in: client.Leaves{ - {TS: time.Unix(0, 0), Path: client.Path{"c"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"a", "b"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"b", "b", "c"}, Val: 1}, - }, - want: client.Leaves{ - {TS: time.Unix(0, 0), Path: client.Path{"a", "b"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"b", "b", "c"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"c"}, Val: 1}, - }, - }, { - desc: "stable", - in: client.Leaves{ - {TS: time.Unix(0, 0), Path: client.Path{"c"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"b", "b", "c"}, Val: 2}, - {TS: time.Unix(0, 0), Path: client.Path{"a", "b"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"c"}, Val: 2}, - {TS: time.Unix(0, 0), Path: client.Path{"b", "b", "c"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"c"}, Val: 3}, - }, - want: client.Leaves{ - {TS: time.Unix(0, 0), Path: client.Path{"a", "b"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"b", "b", "c"}, Val: 2}, - {TS: time.Unix(0, 0), Path: client.Path{"b", "b", "c"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"c"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"c"}, Val: 2}, - {TS: time.Unix(0, 0), Path: client.Path{"c"}, Val: 3}, - }, - }, { - desc: "nil path", - in: client.Leaves{ - {TS: time.Unix(0, 0), Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"a", "b"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"c"}, Val: 2}, - {TS: time.Unix(0, 0), Path: client.Path{"b", "b", "c"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"c"}, Val: 3}, - }, - want: client.Leaves{ - {TS: time.Unix(0, 0), Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"a", "b"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"b", "b", "c"}, Val: 1}, - {TS: time.Unix(0, 0), Path: client.Path{"c"}, Val: 2}, - {TS: time.Unix(0, 0), Path: client.Path{"c"}, Val: 3}, - }, - }} - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - got := make(client.Leaves, len(tt.in)) - copy(got, tt.in) - sort.Sort(got) - if !reflect.DeepEqual(got, tt.want) { - t.Fatalf("sort.Sort(%v) failed: got %v, want %v", tt.in, got, tt.want) - } - }) - } -} - -func TestPath(t *testing.T) { - tests := []struct { - desc string - in client.Path - cmp client.Path - want bool - }{{ - desc: "same", - in: client.Path{"a", "b", "c"}, - cmp: client.Path{"a", "b", "c"}, - want: true, - }, { - desc: "different length", - in: client.Path{"a", "b", "c"}, - cmp: client.Path{"a", "b"}, - want: false, - }, { - desc: "different", - in: client.Path{"a", "b", "c"}, - cmp: client.Path{"a", "b", "d"}, - want: false, - }} - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - if got := tt.in.Equal(tt.cmp); got != tt.want { - t.Fatalf("%+v.Equal(%+v) failed: got %v, want %v", tt.in, tt.cmp, got, tt.want) - } - }) - } -} - -func TestNewType(t *testing.T) { - tests := []struct { - desc string - in string - want client.Type - }{{ - desc: "Unknown", - in: "foo", - want: client.Unknown, - }, { - desc: "Once", - in: "once", - want: client.Once, - }, { - desc: "Stream", - in: "stream", - want: client.Stream, - }, { - desc: "Poll", - in: "poll", - want: client.Poll, - }} - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - if got := client.NewType(tt.in); got != tt.want { - t.Fatalf("client.NewType(%+v) failed: got %v, want %v", tt.in, got, tt.want) - } - }) - } -} - -func TestError(t *testing.T) { - want := "foo" - e := client.NewError(want) - if got := e.Error(); got != want { - t.Errorf("client.NewError(%q) failed: got %v, want %v", want, got, want) - } -} - -func TestClientUpdatesAfterClose(t *testing.T) { - client.ResetRegisteredImpls() - - fake := fakeStreamingClient{ch: make(chan struct{})} - client.Register("fake", func(context.Context, client.Destination) (client.Impl, error) { - return fake, nil - }) - - c := &client.BaseClient{} - done := make(chan struct{}) - go func() { - defer close(done) - err := c.Subscribe(context.Background(), client.Query{ - Addrs: []string{"fake"}, - Type: client.Stream, - Queries: []client.Path{{"*"}}, - NotificationHandler: func(client.Notification) error { return nil }, - }, "fake") - if err != nil { - t.Errorf("Subscribe(): %v", err) - } - }() - - for i := 0; i < 10; i++ { - select { - case fake.ch <- struct{}{}: - case <-done: - t.Fatal("Subscribe returned before close") - } - } - c.Close() - - var updatesAfterClose int -loop: - for { - select { - case fake.ch <- struct{}{}: - updatesAfterClose++ - case <-done: - break loop - } - } - if updatesAfterClose > 1 { - t.Errorf("got %d updates after Close, expect at most 1", updatesAfterClose) - } -} - -type fakeStreamingClient struct { - client.Impl - ch chan struct{} -} - -func (f fakeStreamingClient) Subscribe(context.Context, client.Query) error { - return nil -} - -func (f fakeStreamingClient) Recv() error { - <-f.ch - return nil -} - -func (f fakeStreamingClient) Close() error { return nil } - -// Once client will run the query and once complete you can act on the -// returned tree. -func ExampleClient_Once() { - q := client.Query{ - Addrs: []string{"127.0.0.1:1234"}, - Target: "dev", - Queries: []client.Path{{"*"}}, - Type: client.Once, - } - c := client.New() - defer c.Close() - err := c.Subscribe(context.Background(), q) - if err != nil { - fmt.Println(err) - return - } - for _, v := range c.Leaves() { - fmt.Printf("%v: %v\n", v.Path, v.Val) - } -} - -// Poll client is like Once client, but can be re-triggered via Poll to -// re-execute the query. -func ExampleClient_Poll() { - q := client.Query{ - Addrs: []string{"127.0.0.1:1234"}, - Target: "dev", - Queries: []client.Path{{"*"}}, - Type: client.Poll, - } - c := client.New() - defer c.Close() - err := c.Subscribe(context.Background(), q) - if err != nil { - fmt.Println(err) - return - } - for _, v := range c.Leaves() { - fmt.Printf("%v: %v\n", v.Path, v.Val) - } - err = c.Poll() // Poll allows the underyling Query to keep running - if err != nil { - fmt.Println(err) - return - } - for _, v := range c.Leaves() { - fmt.Printf("%v: %v\n", v.Path, v.Val) - } -} - -// Stream client returns the current state for the query and keeps running -// until closed or the underlying connection breaks. -func ExampleClient_Stream() { - q := client.Query{ - Addrs: []string{"127.0.0.1:1234"}, - Target: "dev", - Queries: []client.Path{{"*"}}, - Type: client.Stream, - NotificationHandler: func(n client.Notification) error { - switch nn := n.(type) { - case client.Connected: - fmt.Println("client is connected") - case client.Sync: - fmt.Println("client is synced") - case client.Update, client.Delete: - fmt.Printf("update: %+v\n", nn) - case client.Error: - fmt.Printf("error: %v\n", nn) - } - return nil - }, - } - c := client.New() - defer c.Close() - // Note that Subscribe will block. - err := c.Subscribe(context.Background(), q) - if err != nil { - fmt.Println(err) - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/fake/fake.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/fake/fake.go deleted file mode 100644 index 9fe4124fb..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/fake/fake.go +++ /dev/null @@ -1,165 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 client implements a fake client implementation to be used with -// streaming telemetry collection. It provides a simple Updates queue of data -// to send it should be used to provide an RPC free test infra for user facing -// libraries. -package client - -import ( - "context" - "fmt" - - log "github.com/golang/glog" - "github.com/golang/protobuf/proto" - "github.com/openconfig/gnmi/client" -) - -// New can be replaced for any negative testing you would like to do as well. -// -// New exists for compatibility reasons. Most new clients should use Mock. -// Mock ensures that q.NotificationHandler and ctx aren't forgotten. -var New = func(ctx context.Context, _ client.Destination) (client.Impl, error) { - return &Client{Context: ctx}, nil -} - -// Mock overrides a client implementation named typ (most implementation -// libraries have Type constant containing that name) with a fake client -// sending given updates. -// -// See Client documentation about updates slice contents. -func Mock(typ string, updates []interface{}) { - client.RegisterTest(typ, func(ctx context.Context, _ client.Destination) (client.Impl, error) { - c := &Client{ - Context: ctx, - Updates: updates, - } - return c, nil - }) -} - -// Client is the fake of a client implementation. It will provide a simple -// list of updates to send to the generic client. -// -// The Updates slice can contain: -// - client.Notification: passed to query.NotificationHandler -// - proto.Message: passed to query.ProtoHandler -// - error: returned from Recv, interrupts the update stream -// - Block: pauses Recv, proceeds to next update on Unblock -// -// See ExampleClient for sample use case. -type Client struct { - currUpdate int - Updates []interface{} - Handler client.NotificationHandler - ProtoHandler client.ProtoHandler - // BlockAfterSync is deprecated: use Block update as last Updates slice - // element instead. - // - // When BlockAfterSync is set, Client will read from it in Recv after - // sending all Updates before returning ErrStopReading. - // BlockAfterSync is closed when Close is called. - BlockAfterSync chan struct{} - connected bool - Context context.Context -} - -// Subscribe implements the client.Impl interface. -func (c *Client) Subscribe(ctx context.Context, q client.Query) error { - c.Handler = q.NotificationHandler - c.ProtoHandler = q.ProtoHandler - return nil -} - -// Reset will reset the client to start playing new updates. -func (c *Client) Reset(u []interface{}) { - c.currUpdate = 0 - c.Updates = u -} - -// Recv will be called for each update the generic client wants to receive. -func (c *Client) Recv() error { - if c.Context == nil { - c.Context = context.Background() - } - if !c.connected && c.Handler != nil { - c.Handler(client.Connected{}) - c.connected = true - } - - for c.currUpdate < len(c.Updates) { - u := c.Updates[c.currUpdate] - c.currUpdate++ - log.V(1).Infof("fake client update: %v", u) - switch v := u.(type) { - case client.Notification: - if c.Handler == nil { - return fmt.Errorf("update %+v is client.Notification but query.NotificationHandler wasn't set", v) - } - return c.Handler(v) - case proto.Message: - if c.ProtoHandler == nil { - return fmt.Errorf("update %+v is proto.Message but query.ProtoHandler wasn't set", v) - } - return c.ProtoHandler(v) - case error: - return v - case Block: - select { - case <-c.Context.Done(): - return c.Context.Err() - case <-v: - } - } - } - - if c.Handler != nil { - c.Handler(client.Sync{}) - } - // We went through all c.Update items. - if c.BlockAfterSync != nil { - log.Info("No more updates, blocking on BlockAfterSync") - select { - case <-c.Context.Done(): - return c.Context.Err() - case <-c.BlockAfterSync: - } - } - log.Infof("Recv() returning %v", client.ErrStopReading) - return client.ErrStopReading -} - -// Close is a noop in the fake. -func (c *Client) Close() error { - if c.BlockAfterSync != nil { - close(c.BlockAfterSync) - } - return nil -} - -// Poll is a noop in the fake. -func (c *Client) Poll() error { - return nil -} - -// Block is a special update that lets the stream of updates to be paused. -// See Client docs for usage example. -type Block chan struct{} - -// Unblock unpauses the update stream following the Block. Can only be called -// once. -func (b Block) Unblock() { close(b) } diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/fake/fake_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/fake/fake_test.go deleted file mode 100644 index f2b33c9d8..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/fake/fake_test.go +++ /dev/null @@ -1,69 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 client - -import ( - "context" - "errors" - "fmt" - "time" - - "github.com/openconfig/gnmi/client" -) - -func ExampleClient() { - block := make(Block) - Mock("fake", []interface{}{ - client.Update{Path: []string{"target", "a", "b"}, Val: 1, TS: time.Now()}, - client.Update{Path: []string{"target", "a", "c"}, Val: 2, TS: time.Now()}, - block, - client.Delete{Path: []string{"target", "a", "b"}, TS: time.Now()}, - errors.New("unexpected error"), - }) - - // Unblock the stream after a second. - go func() { - time.Sleep(time.Second) - block.Unblock() - }() - - err := client.New().Subscribe(context.Background(), client.Query{ - Addrs: []string{""}, - Queries: []client.Path{{"*"}}, - Type: client.Once, - NotificationHandler: func(n client.Notification) error { - switch nn := n.(type) { - case client.Connected: - fmt.Println("connected") - case client.Sync: - fmt.Println("sync") - case client.Update: - fmt.Printf("%q: %v\n", nn.Path, nn.Val) - case client.Delete: - fmt.Printf("%q deleted\n", nn.Path) - } - return nil - }, - }) - fmt.Println("got error:", err) - // Output: - // connected - // ["target" "a" "b"]: 1 - // ["target" "a" "c"]: 2 - // ["target" "a" "b"] deleted - // got error: unexpected error -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/flags/flags_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/flags/flags_test.go deleted file mode 100644 index 7b4d5f3ec..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/flags/flags_test.go +++ /dev/null @@ -1,246 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 flags - -import ( - "flag" - "reflect" - "strings" - "testing" -) - -var tests = []struct { - desc string - in []string - wantStringList StringList - wantStringMap StringMap - wantIntMap IntMap - wantErr string -}{{ - desc: "empty args", - in: []string{}, - wantStringList: []string{"0"}, - wantStringMap: map[string]string{"a": "1", "b": "2"}, - wantIntMap: map[string]int64{"a": 1, "b": 2}, -}, { - desc: "Stringlist args", - in: []string{"-test_stringList=asdf,foo"}, - wantStringList: []string{"asdf", "foo"}, - wantStringMap: map[string]string{"a": "1", "b": "2"}, - wantIntMap: map[string]int64{"a": 1, "b": 2}, -}, { - desc: "StringMap args", - in: []string{"-test_stringMap=a=10,b=20"}, - wantStringList: []string{"0"}, - wantStringMap: map[string]string{"a": "10", "b": "20"}, - wantIntMap: map[string]int64{"a": 1, "b": 2}, -}, { - desc: "StringMap args (missing default key)", - in: []string{"-test_stringMap=a=10,c=30"}, - wantStringList: []string{"0"}, - wantStringMap: map[string]string{"a": "10", "c": "30"}, - wantIntMap: map[string]int64{"a": 1, "b": 2}, -}, { - desc: "StringMap args (invalid key/value)", - in: []string{"-test_stringMap=a10,c=30"}, - wantStringList: []string{"0"}, - wantStringMap: map[string]string{"a": "10", "c": "30"}, - wantIntMap: map[string]int64{"a": 1, "b": 2}, - wantErr: "invalid value", -}, { - desc: "StringMap args (nil key)", - in: []string{"-test_stringMap==10,c=30"}, - wantStringList: []string{"0"}, - wantStringMap: map[string]string{"a": "10", "c": "30"}, - wantIntMap: map[string]int64{"a": 1, "b": 2}, - wantErr: "invalid value", -}, { - desc: "StringMap args (empty)", - in: []string{"-test_stringMap="}, - wantStringList: []string{"0"}, - wantStringMap: map[string]string{}, - wantIntMap: map[string]int64{"a": 1, "b": 2}, - wantErr: "invalid value", -}, { - desc: "IntMap args", - in: []string{"-test_intMap=a=10,b=20"}, - wantStringList: []string{"0"}, - wantStringMap: map[string]string{"a": "1", "b": "2"}, - wantIntMap: map[string]int64{"a": 10, "b": 20}, -}, { - desc: "IntMap args (additional)", - in: []string{"-test_intMap=a=10,b=20,c=30"}, - wantStringList: []string{"0"}, - wantStringMap: map[string]string{"a": "1", "b": "2"}, - wantIntMap: map[string]int64{"a": 10, "b": 20, "c": 30}, -}, { - desc: "IntMap args (additional spaces)", - in: []string{"-test_intMap=a= 10, b=20, c= 30"}, - wantStringList: []string{"0"}, - wantStringMap: map[string]string{"a": "1", "b": "2"}, - wantIntMap: map[string]int64{"a": 10, "b": 20, "c": 30}, -}, { - desc: "IntMap args (parse error)", - in: []string{"-test_intMap=a= 10, b=20, c=asdf"}, - wantStringList: []string{"0"}, - wantStringMap: map[string]string{"a": "1", "b": "2"}, - wantIntMap: map[string]int64{"a": 10, "b": 20, "c": 30}, - wantErr: "invalid value", -}, { - desc: "IntMap args (missing default key)", - in: []string{"-test_intMap=a=10,c=30"}, - wantStringList: []string{"0"}, - wantStringMap: map[string]string{"a": "1", "b": "2"}, - wantIntMap: map[string]int64{"a": 10, "c": 30}, - wantErr: "invalid value", -}, { - desc: "IntMap args (invalid key/value)", - in: []string{"-test_intMap=a10,c=30"}, - wantStringList: []string{"0"}, - wantStringMap: map[string]string{"a": "1", "b": "2"}, - wantIntMap: map[string]int64{"a": 10, "c": 30}, - wantErr: "invalid value", -}, { - desc: "IntMap args (nil key)", - in: []string{"-test_intMap==10,c=30"}, - wantStringList: []string{"0"}, - wantStringMap: map[string]string{"a": "1", "b": "2"}, - wantIntMap: map[string]int64{"a": 10, "c": 30}, - wantErr: "invalid value", -}, { - desc: "IntMap args (empty)", - in: []string{"-test_intMap="}, - wantStringList: []string{"0"}, - wantStringMap: map[string]string{"a": "1", "b": "2"}, - wantIntMap: map[string]int64{}, - wantErr: "invalid value", -}, { - desc: "All Set", - in: []string{"-test_intMap=a=1,b=2", "-test_stringMap=foo=bar,baz=faz", "-test_stringList=asdf,foo,bar"}, - wantStringList: []string{"asdf", "foo", "bar"}, - wantStringMap: map[string]string{"foo": "bar", "baz": "faz"}, - wantIntMap: map[string]int64{"a": 1, "b": 2}, - wantErr: "invalid value", -}} - -func TestFlags(t *testing.T) { - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - stringList := StringList{"0"} - stringMap := StringMap{"a": "1", "b": "2"} - intMap := IntMap{"a": 1, "b": 2} - f := &flag.FlagSet{} - f.Var(&stringList, "test_stringList", "[]string value") - f.Var(&stringMap, "test_stringMap", "map[string]string") - f.Var(&intMap, "test_intMap", "map[string]int64") - err := f.Parse(tt.in) - if err != nil { - if strings.Contains(err.Error(), tt.wantErr) { - return - } - t.Errorf("flag.CommandLine.Parse(%v) err: %v", tt.in, err) - } - if !reflect.DeepEqual(stringList, tt.wantStringList) { - t.Errorf("flag.CommandLine.Parse(%v) failed: stringList got %v, want %v", tt.in, stringList, tt.wantStringList) - } - if !reflect.DeepEqual(stringList.Get().(StringList), tt.wantStringList) { - t.Errorf("flag.CommandLine.Parse(%v) failed: stringList.Get() got %v, want %v", tt.in, stringList, tt.wantStringList) - } - if stringList.String() != tt.wantStringList.String() { - t.Errorf("flag.CommandLine.Parse(%v) failed: stringList got %q, want %q", tt.in, stringList.String(), tt.wantStringList.String()) - } - if !reflect.DeepEqual(stringMap, tt.wantStringMap) { - t.Errorf("flag.CommandLine.Parse(%v) failed: stringMap got %v, want %v", tt.in, stringMap, tt.wantStringMap) - } - if !reflect.DeepEqual(stringMap.Get().(StringMap), tt.wantStringMap) { - t.Errorf("flag.CommandLine.Parse(%v) failed: stringMap.Get() got %v, want %v", tt.in, stringMap, tt.wantStringMap) - } - if stringMap.String() != tt.wantStringMap.String() { - t.Errorf("flag.CommandLine.Parse(%v) failed: stringList got %q, want %q", tt.in, stringMap.String(), tt.wantStringMap.String()) - } - if !reflect.DeepEqual(intMap, tt.wantIntMap) { - t.Errorf("flag.CommandLine.Parse(%v) failed: intMap got %v, want %v", tt.in, intMap, tt.wantIntMap) - } - if !reflect.DeepEqual(intMap.Get().(IntMap), tt.wantIntMap) { - t.Errorf("flag.CommandLine.Parse(%v) failed: intMap.Get() got %v, want %v", tt.in, intMap, tt.wantIntMap) - } - if intMap.String() != tt.wantIntMap.String() { - t.Errorf("flag.CommandLine.Parse(%v) failed: stringList got %q, want %q", tt.in, intMap.String(), tt.wantIntMap.String()) - } - }) - } -} - -func TestNewFlags(t *testing.T) { - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - listVar := []string{} - stringMapVar := map[string]string{} - intMapVar := map[string]int64{} - stringList := NewStringList(&listVar, []string{"0"}) - stringMap := NewStringMap(&stringMapVar, map[string]string{"a": "1", "b": "2"}) - intMap := NewIntMap(&intMapVar, map[string]int64{"a": 1, "b": 2}) - f := &flag.FlagSet{} - f.Var(stringList, "test_stringList", "[]string value") - f.Var(stringMap, "test_stringMap", "map[string]string") - f.Var(intMap, "test_intMap", "map[string]int64") - err := f.Parse(tt.in) - if err != nil { - if strings.Contains(err.Error(), tt.wantErr) { - return - } - t.Errorf("flag.CommandLine.Parse(%v) err: %v", tt.in, err) - } - if reflect.ValueOf(listVar).Pointer() != reflect.ValueOf(*stringList).Pointer() { - t.Errorf("flag.CommandLine.Parse(%v) failed: stringList Pointer() got %v, want %v", tt.in, stringList, tt.wantStringList) - } - if !reflect.DeepEqual(*stringList, tt.wantStringList) { - t.Errorf("flag.CommandLine.Parse(%v) failed: stringList got %v, want %v", tt.in, stringList, tt.wantStringList) - } - if !reflect.DeepEqual(stringList.Get().(StringList), tt.wantStringList) { - t.Errorf("flag.CommandLine.Parse(%v) failed: stringList.Get() got %v, want %v", tt.in, stringList, tt.wantStringList) - } - if stringList.String() != tt.wantStringList.String() { - t.Errorf("flag.CommandLine.Parse(%v) failed: stringList got %q, want %q", tt.in, stringList.String(), tt.wantStringList.String()) - } - if reflect.ValueOf(stringMapVar).Pointer() != reflect.ValueOf(*stringMap).Pointer() { - t.Errorf("flag.CommandLine.Parse(%v) failed: stringMap Pointer() got %v, want %v", tt.in, stringList, tt.wantStringList) - } - if !reflect.DeepEqual(*stringMap, tt.wantStringMap) { - t.Errorf("flag.CommandLine.Parse(%v) failed: stringMap got %v, want %v", tt.in, stringMap, tt.wantStringMap) - } - if !reflect.DeepEqual(stringMap.Get().(StringMap), tt.wantStringMap) { - t.Errorf("flag.CommandLine.Parse(%v) failed: stringMap.Get() got %v, want %v", tt.in, stringMap, tt.wantStringMap) - } - if stringMap.String() != tt.wantStringMap.String() { - t.Errorf("flag.CommandLine.Parse(%v) failed: stringList got %q, want %q", tt.in, stringMap.String(), tt.wantStringMap.String()) - } - if reflect.ValueOf(intMapVar).Pointer() != reflect.ValueOf(*intMap).Pointer() { - t.Errorf("flag.CommandLine.Parse(%v) failed: intMap Pointer() got %v, want %v", tt.in, stringList, tt.wantStringList) - } - if !reflect.DeepEqual(*intMap, tt.wantIntMap) { - t.Errorf("flag.CommandLine.Parse(%v) failed: intMap got %v, want %v", tt.in, intMap, tt.wantIntMap) - } - if !reflect.DeepEqual(intMap.Get().(IntMap), tt.wantIntMap) { - t.Errorf("flag.CommandLine.Parse(%v) failed: intMap.Get() got %v, want %v", tt.in, intMap, tt.wantIntMap) - } - if intMap.String() != tt.wantIntMap.String() { - t.Errorf("flag.CommandLine.Parse(%v) failed: stringList got %q, want %q", tt.in, intMap.String(), tt.wantIntMap.String()) - } - }) - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/flags/intmap.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/flags/intmap.go deleted file mode 100644 index e532a13ae..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/flags/intmap.go +++ /dev/null @@ -1,79 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 flags - -import ( - "fmt" - "sort" - "strconv" - "strings" -) - -// IntMap is a map[string]int64 container for command line flags. The default -// initialization will create an empty map. If you need default backing map use -// NewIntMap. -type IntMap map[string]int64 - -func (m *IntMap) String() string { - s := make([]string, 0, len(*m)) - for k, v := range *m { - s = append(s, fmt.Sprintf("%s=%d", k, v)) - } - sort.Strings(s) - return strings.Join(s, ",") -} - -// Get returns the values of m. The interface will need to be type asserted to -// IntMap for use. -func (m *IntMap) Get() interface{} { - return *m -} - -// Set will take a string in the format =,= and -// parse the resulting value into a map[string]int64. Values may contain "=", -// keys may not. -func (m *IntMap) Set(v string) error { - *m = IntMap{} - for _, entry := range strings.Split(v, ",") { - data := strings.SplitN(entry, "=", 2) - if len(data) != 2 { - return fmt.Errorf("invalid key=value pair: %s", entry) - } - k := strings.TrimSpace(data[0]) - vString := strings.TrimSpace(data[1]) - if len(k) == 0 { - return fmt.Errorf("invalid key=value pair: %s", entry) - } - var err error - v := 0 - if len(vString) != 0 { - v, err = strconv.Atoi(vString) - if err != nil { - return err - } - } - (*m)[k] = int64(v) - } - return nil -} - -// NewIntMap will wrap the pointer to the map in a IntMap and set the -// underlying map to val. -func NewIntMap(p *map[string]int64, val map[string]int64) *IntMap { - *p = val - return (*IntMap)(p) -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/flags/stringlist.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/flags/stringlist.go deleted file mode 100644 index 6edcc91d5..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/flags/stringlist.go +++ /dev/null @@ -1,50 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 flags defines extra flag types for use in command line flag parsing. -package flags - -import ( - "strings" -) - -// StringList is a []string container for command line flags. The default -// initialization will create an empty slice. If you need default backing slice -// map use NewStringList. -type StringList []string - -func (ss *StringList) String() string { - return strings.Join(*ss, ",") -} - -// Get returns the values of ss. The interface will need to be type asserted to -// StringList for use. -func (ss *StringList) Get() interface{} { - return *ss -} - -// Set sets the value of ss to the comma separated values in s. -func (ss *StringList) Set(s string) error { - *ss = StringList(strings.Split(s, ",")) - return nil -} - -// NewStringList will wrap the pointer to the slice in a StringList and set the -// underlying slice to val. -func NewStringList(p *[]string, val []string) *StringList { - *p = val - return (*StringList)(p) -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/flags/stringmap.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/flags/stringmap.go deleted file mode 100644 index 5c9c8c40e..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/flags/stringmap.go +++ /dev/null @@ -1,71 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 flags - -import ( - "fmt" - "sort" - "strings" -) - -// StringMap is a map[string]string container for command line flags. The -// default initialization will create an empty map. If you need default backing -// map use NewStringMap. -type StringMap map[string]string - -func (m *StringMap) String() string { - s := make([]string, len(*m)) - i := 0 - for k, v := range *m { - s[i] = fmt.Sprintf("%s=%s", k, v) - i++ - } - sort.Strings(s) - return strings.Join(s, ",") -} - -// Get returns the values of m. The interface will need to be type asserted to -// StringMap for use. -func (m *StringMap) Get() interface{} { - return *m -} - -// Set will take a string in the format =,= and -// parse the resulting value into a map[string]string. -func (m *StringMap) Set(v string) error { - *m = StringMap{} - for _, entry := range strings.Split(v, ",") { - data := strings.SplitN(entry, "=", 2) - if len(data) != 2 { - return fmt.Errorf("invalid key=value pair: %s", entry) - } - k := strings.TrimSpace(data[0]) - v := strings.TrimSpace(data[1]) - if len(k) == 0 { - return fmt.Errorf("invalid key=value pair: %s", entry) - } - (*m)[k] = v - } - return nil -} - -// NewStringMap will wrap the pointer to the map in a StringMap and set the -// underlying map to val. -func NewStringMap(p *map[string]string, val map[string]string) *StringMap { - *p = val - return (*StringMap)(p) -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/gnmi/client.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/gnmi/client.go deleted file mode 100644 index a92839a33..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/gnmi/client.go +++ /dev/null @@ -1,310 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 client contains transport implementation for the parent client -// library using gnmi.proto. -// -// Note: this package should not be used directly. Use -// github.com/openconfig/gnmi/client instead. -package client - -import ( - "context" - "encoding/json" - "fmt" - "math" - "strings" - "time" - - log "github.com/golang/glog" - "github.com/golang/protobuf/proto" - "google.golang.org/grpc/credentials" - "google.golang.org/grpc" - "github.com/openconfig/ygot/ygot" - "github.com/openconfig/gnmi/client" - "github.com/openconfig/gnmi/client/grpcutil" - "github.com/openconfig/gnmi/path" - "github.com/openconfig/gnmi/value" - - gpb "github.com/openconfig/gnmi/proto/gnmi" -) - -// Type defines the name resolution for this client type. -const Type = "gnmi" - -// Client handles execution of the query and caching of its results. -type Client struct { - conn *grpc.ClientConn - client gpb.GNMIClient - sub gpb.GNMI_SubscribeClient - query client.Query - recv client.ProtoHandler - handler client.NotificationHandler - connected bool -} - -// New returns a new initialized client. If error is nil, returned Client has -// established a connection to d. Close needs to be called for cleanup. -func New(ctx context.Context, d client.Destination) (client.Impl, error) { - if len(d.Addrs) != 1 { - return nil, fmt.Errorf("d.Addrs must only contain one entry: %v", d.Addrs) - } - opts := []grpc.DialOption{ - grpc.WithTimeout(d.Timeout), - grpc.WithBlock(), - grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32)), - } - - switch d.TLS { - case nil: - opts = append(opts, grpc.WithInsecure()) - default: - opts = append(opts, grpc.WithTransportCredentials(credentials.NewTLS(d.TLS))) - } - - if d.Credentials != nil { - pc := newPassCred(d.Credentials.Username, d.Credentials.Password, true) - opts = append(opts, grpc.WithPerRPCCredentials(pc)) - } - conn, err := grpc.DialContext(ctx, d.Addrs[0], opts...) - if err != nil { - return nil, fmt.Errorf("Dialer(%s, %v): %v", d.Addrs[0], d.Timeout, err) - } - return NewFromConn(ctx, conn, d) -} - -// NewFromConn creates and returns the client based on the provided transport. -func NewFromConn(ctx context.Context, conn *grpc.ClientConn, d client.Destination) (*Client, error) { - ok, err := grpcutil.Lookup(ctx, conn, "gnmi.gNMI") - if err != nil { - log.V(1).Infof("gRPC reflection lookup on %q for service gnmi.gNMI failed: %v", d.Addrs, err) - // This check is disabled for now. Reflection will become part of gNMI - // specification in the near future, so we can't enforce it yet. - } - if !ok { - // This check is disabled for now. Reflection will become part of gNMI - // specification in the near future, so we can't enforce it yet. - } - - cl := gpb.NewGNMIClient(conn) - return &Client{ - conn: conn, - client: cl, - }, nil -} - -// Subscribe sends the gNMI Subscribe RPC to the server. -func (c *Client) Subscribe(ctx context.Context, q client.Query) error { - sub, err := c.client.Subscribe(ctx) - if err != nil { - return fmt.Errorf("gpb.GNMIClient.Subscribe(%v) failed to initialize Subscribe RPC: %v", q, err) - } - - sr := q.SubReq - if sr == nil { - sr, err = subscribe(q) - if err != nil { - return fmt.Errorf("generating SubscribeRequest proto: %v", err) - } - } - - if err := sub.Send(sr); err != nil { - return fmt.Errorf("client.Send(%+v): %v", sr, err) - } - - c.sub = sub - c.query = q - if q.ProtoHandler == nil { - c.recv = c.defaultRecv - c.handler = q.NotificationHandler - } else { - c.recv = q.ProtoHandler - } - return nil -} - -// Poll will send a single gNMI poll request to the server. -func (c *Client) Poll() error { - if err := c.sub.Send(&gpb.SubscribeRequest{Request: &gpb.SubscribeRequest_Poll{Poll: &gpb.Poll{}}}); err != nil { - return fmt.Errorf("client.Poll(): %v", err) - } - return nil -} - -// Peer returns the peer of the current stream. If the client is not created or -// if the peer is not valid nil is returned. -func (c *Client) Peer() string { - return c.query.Addrs[0] -} - -// Close forcefully closes the underlying connection, terminating the query -// right away. It's safe to call Close multiple times. -func (c *Client) Close() error { - return c.conn.Close() -} - -// Recv will recieve a single message from the server and process it based on -// the provided handlers (Proto or Notification). -func (c *Client) Recv() error { - n, err := c.sub.Recv() - if err != nil { - return err - } - return c.recv(n) -} - -// defaultRecv is the default implementation of recv provided by the client. -// This function will be replaced by the ProtoHandler member of the Query -// struct passed to New(), if it is set. -func (c *Client) defaultRecv(msg proto.Message) error { - if !c.connected { - c.handler(client.Connected{}) - c.connected = true - } - - resp, ok := msg.(*gpb.SubscribeResponse) - if !ok { - return fmt.Errorf("failed to type assert message %#v", msg) - } - log.V(1).Info(resp) - switch v := resp.Response.(type) { - default: - return fmt.Errorf("unknown response %T: %s", v, v) - case *gpb.SubscribeResponse_Error: - return fmt.Errorf("error in response: %s", v) - case *gpb.SubscribeResponse_SyncResponse: - c.handler(client.Sync{}) - if c.query.Type == client.Poll || c.query.Type == client.Once { - return client.ErrStopReading - } - case *gpb.SubscribeResponse_Update: - n := v.Update - p := path.ToStrings(n.Prefix, true) - ts := time.Unix(0, n.Timestamp) - for _, u := range n.Update { - if u.Path == nil { - return fmt.Errorf("invalid nil path in update: %v", u) - } - u, err := noti(p, u.Path, ts, u) - if err != nil { - return err - } - c.handler(u) - } - for _, d := range n.Delete { - u, err := noti(p, d, ts, nil) - if err != nil { - return err - } - c.handler(u) - } - } - return nil -} - -// Capabilities calls the gNMI Capabilities RPC. -func (c *Client) Capabilities(ctx context.Context, r *gpb.CapabilityRequest) (*gpb.CapabilityResponse, error) { - return c.client.Capabilities(ctx, r) -} - -// Get calls the gNMI Get RPC. -func (c *Client) Get(ctx context.Context, r *gpb.GetRequest) (*gpb.GetResponse, error) { - return c.client.Get(ctx, r) -} - -// Set calls the gNMI Set RPC. -func (c *Client) Set(ctx context.Context, r *gpb.SetRequest) (*gpb.SetResponse, error) { - return c.client.Set(ctx, r) -} - -func getType(t client.Type) gpb.SubscriptionList_Mode { - switch t { - case client.Once: - return gpb.SubscriptionList_ONCE - case client.Stream: - return gpb.SubscriptionList_STREAM - case client.Poll: - return gpb.SubscriptionList_POLL - } - return gpb.SubscriptionList_ONCE -} - -func subscribe(q client.Query) (*gpb.SubscribeRequest, error) { - s := &gpb.SubscribeRequest_Subscribe{ - Subscribe: &gpb.SubscriptionList{ - Mode: getType(q.Type), - Prefix: &gpb.Path{Target: q.Target}, - }, - } - if q.UpdatesOnly { - s.Subscribe.UpdatesOnly = true - } - for _, qq := range q.Queries { - pp, err := ygot.StringToPath(pathToString(qq), ygot.StructuredPath, ygot.StringSlicePath) - if err != nil { - return nil, fmt.Errorf("invalid query path %q: %v", qq, err) - } - s.Subscribe.Subscription = append(s.Subscribe.Subscription, &gpb.Subscription{Path: pp, Mode: q.Streaming_type, SampleInterval: q.Streaming_sample_int, HeartbeatInterval: q.Heartbeat_int, SuppressRedundant: q.Suppress_redundant}) - } - return &gpb.SubscribeRequest{Request: s}, nil -} - -func noti(prefix []string, pp *gpb.Path, ts time.Time, u *gpb.Update) (client.Notification, error) { - sp := path.ToStrings(pp, false) - // Make a full new copy of prefix + u.Path to avoid any reuse of underlying - // slice arrays. - p := make([]string, 0, len(prefix)+len(sp)) - p = append(p, prefix...) - p = append(p, sp...) - - if u == nil { - return client.Delete{Path: p, TS: ts}, nil - } - if u.Val != nil { - val, err := value.ToScalar(u.Val) - if err != nil { - return nil, err - } - return client.Update{Path: p, TS: ts, Val: val, Dups: u.Duplicates}, nil - } - switch v := u.Value; v.Type { - case gpb.Encoding_BYTES: - return client.Update{Path: p, TS: ts, Val: v.Value, Dups: u.Duplicates}, nil - case gpb.Encoding_JSON, gpb.Encoding_JSON_IETF: - var val interface{} - if err := json.Unmarshal(v.Value, &val); err != nil { - return nil, fmt.Errorf("json.Unmarshal(%q, val): %v", v, err) - } - return client.Update{Path: p, TS: ts, Val: val, Dups: u.Duplicates}, nil - default: - return nil, fmt.Errorf("Unsupported value type: %v", v.Type) - } -} - -func init() { - client.Register(Type, New) -} - -func pathToString(q client.Path) string { - qq := make(client.Path, len(q)) - copy(qq, q) - // Escape all slashes within a path element. ygot.StringToPath will handle - // these escapes. - for i, e := range qq { - qq[i] = strings.Replace(e, "/", "\\/", -1) - } - return strings.Join(qq, "/") -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/gnmi/client_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/gnmi/client_test.go deleted file mode 100644 index 734abcb69..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/gnmi/client_test.go +++ /dev/null @@ -1,519 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 client - -import ( - "context" - "crypto/tls" - "testing" - "time" - - "github.com/kylelemons/godebug/pretty" - "google.golang.org/grpc" - "github.com/openconfig/ygot/ygot" - "github.com/openconfig/gnmi/client" - "github.com/openconfig/gnmi/testing/fake/gnmi" - "github.com/openconfig/gnmi/testing/fake/testing/grpc/config" - - gpb "github.com/openconfig/gnmi/proto/gnmi" - fpb "github.com/openconfig/gnmi/testing/fake/proto" -) - -func TestClient(t *testing.T) { - tests := []struct { - desc string - q client.Query - updates []*fpb.Value - disableEOF bool - wantErr bool - wantNoti []client.Notification - - poll int - wantPollErr string - }{{ - desc: "empty query", - q: client.Query{}, - wantErr: true, - }, { - desc: "once query with one update", - q: client.Query{ - Target: "dev", - Type: client.Once, - Queries: []client.Path{{"a"}}, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - updates: []*fpb.Value{{ - Path: []string{"a"}, - Timestamp: &fpb.Timestamp{Timestamp: 100}, - Repeat: 1, - Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, - }, { - Timestamp: &fpb.Timestamp{Timestamp: 100}, - Repeat: 1, - Value: &fpb.Value_Sync{Sync: 1}, - }}, - wantNoti: []client.Notification{ - client.Connected{}, - client.Update{Path: []string{"dev", "a"}, TS: time.Unix(0, 100), Val: 5}, - client.Sync{}, - }, - }, { - desc: "poll query with x3 by Poll()", - poll: 3, - q: client.Query{ - Target: "dev", - Type: client.Poll, - Queries: []client.Path{{"a"}}, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - updates: []*fpb.Value{{ - Path: []string{"a"}, - Timestamp: &fpb.Timestamp{Timestamp: 100}, - Repeat: 1, - Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, - }, { - Timestamp: &fpb.Timestamp{Timestamp: 100}, - Repeat: 1, - Value: &fpb.Value_Sync{Sync: 1}, - }}, - wantNoti: []client.Notification{ - client.Connected{}, - client.Update{Path: []string{"dev", "a"}, TS: time.Unix(0, 100), Val: 5}, - client.Sync{}, - client.Update{Path: []string{"dev", "a"}, TS: time.Unix(0, 100), Val: 5}, - client.Sync{}, - client.Update{Path: []string{"dev", "a"}, TS: time.Unix(0, 100), Val: 5}, - client.Sync{}, - client.Update{Path: []string{"dev", "a"}, TS: time.Unix(0, 100), Val: 5}, - client.Sync{}, - }, - }, { - desc: "once query with updates and deletes", - q: client.Query{ - Target: "dev", - Type: client.Once, - Queries: []client.Path{{"a"}}, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - updates: []*fpb.Value{{ - Path: []string{"a"}, - Timestamp: &fpb.Timestamp{Timestamp: 100}, - Repeat: 1, - Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, - }, { - Path: []string{"a", "b"}, - Timestamp: &fpb.Timestamp{Timestamp: 100}, - Repeat: 1, - Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, - }, { - Path: []string{"a", "b"}, - Timestamp: &fpb.Timestamp{Timestamp: 200}, - Repeat: 1, - Value: &fpb.Value_Delete{Delete: &fpb.DeleteValue{}}, - }, { - Timestamp: &fpb.Timestamp{Timestamp: 300}, - Repeat: 1, - Value: &fpb.Value_Sync{Sync: 1}, - }}, - wantNoti: []client.Notification{ - client.Connected{}, - client.Update{Path: []string{"dev", "a"}, TS: time.Unix(0, 100), Val: 5}, - client.Update{Path: []string{"dev", "a", "b"}, TS: time.Unix(0, 100), Val: 5}, - client.Delete{Path: []string{"dev", "a", "b"}, TS: time.Unix(0, 200)}, - client.Sync{}, - }, - }, { - desc: "stream query with updates and deletes", - disableEOF: true, - q: client.Query{ - Target: "dev", - Type: client.Stream, - Queries: []client.Path{{"a"}}, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - updates: []*fpb.Value{{ - Timestamp: &fpb.Timestamp{Timestamp: 100}, - Repeat: 1, - Value: &fpb.Value_Sync{Sync: 1}, - }, { - Path: []string{"a"}, - Timestamp: &fpb.Timestamp{Timestamp: 200}, - Repeat: 1, - Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, - }, { - Path: []string{"a", "b"}, - Timestamp: &fpb.Timestamp{Timestamp: 200}, - Repeat: 1, - Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, - }, { - Path: []string{"a", "c"}, - Timestamp: &fpb.Timestamp{Timestamp: 200}, - Repeat: 1, - Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 5}}, - }, { - Path: []string{"a", "b"}, - Timestamp: &fpb.Timestamp{Timestamp: 300}, - Repeat: 1, - Value: &fpb.Value_Delete{Delete: &fpb.DeleteValue{}}, - }, { - Path: []string{"a", "c"}, - Timestamp: &fpb.Timestamp{Timestamp: 400}, - Repeat: 1, - Value: &fpb.Value_IntValue{IntValue: &fpb.IntValue{Value: 50}}, - }}, - wantNoti: []client.Notification{ - client.Connected{}, - client.Sync{}, - client.Update{Path: []string{"dev", "a"}, TS: time.Unix(0, 200), Val: 5}, - client.Update{Path: []string{"dev", "a", "b"}, TS: time.Unix(0, 200), Val: 5}, - client.Update{Path: []string{"dev", "a", "c"}, TS: time.Unix(0, 200), Val: 5}, - client.Delete{Path: []string{"dev", "a", "b"}, TS: time.Unix(0, 300)}, - client.Update{Path: []string{"dev", "a", "c"}, TS: time.Unix(0, 400), Val: 50}, - }, - }} - opt, err := config.WithSelfTLSCert() - if err != nil { - t.Fatalf("failed to generate cert: %v", err) - } - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - s, err := gnmi.New( - &fpb.Config{ - Target: "dev1", - DisableSync: true, - Values: tt.updates, - DisableEof: tt.disableEOF, - }, - []grpc.ServerOption{opt}, - ) - if err != nil { - t.Fatal("failed to start test server") - } - defer s.Close() - - q := tt.q - q.Addrs = []string{s.Address()} - c := client.New() - defer c.Close() - var gotNoti []client.Notification - q.NotificationHandler = func(n client.Notification) error { - gotNoti = append(gotNoti, n) - return nil - } - err = c.Subscribe(context.Background(), q) - switch { - case tt.wantErr && err != nil: - return - case tt.wantErr && err == nil: - t.Fatalf("c.Subscribe(): got nil error, expected non-nil") - case !tt.wantErr && err != nil: - t.Fatalf("c.Subscribe(): got error %v, expected nil", err) - } - for i := 0; i < tt.poll; i++ { - err := c.Poll() - switch { - case err == nil && tt.wantPollErr != "": - t.Errorf("c.Poll(): got nil error, expected non-nil %v", tt.wantPollErr) - case err != nil && tt.wantPollErr == "": - t.Errorf("c.Poll(): got error %v, expected nil", err) - case err != nil && err.Error() != tt.wantPollErr: - t.Errorf("c.Poll(): got error %v, expected error %v", err, tt.wantPollErr) - } - } - if diff := pretty.Compare(tt.wantNoti, gotNoti); diff != "" { - t.Errorf("unexpected updates:\n%s", diff) - } - impl, err := c.Impl() - if err != nil { - t.Fatalf("c.Impl() failed: %v", err) - } - if got, want := impl.(*Client).Peer(), s.Address(); got != want { - t.Errorf("Peer() failed: got %v, want %v", got, want) - } - }) - } -} - -func TestGNMIMessageUpdates(t *testing.T) { - var gotNoti []client.Notification - q := client.Query{ - Target: "dev", - Type: client.Stream, - Queries: []client.Path{{"a"}}, - TLS: &tls.Config{InsecureSkipVerify: true}, - NotificationHandler: func(n client.Notification) error { - gotNoti = append(gotNoti, n) - return nil - }, - } - updates := []*gpb.SubscribeResponse{ - {Response: &gpb.SubscribeResponse_Update{ - Update: &gpb.Notification{ - Timestamp: 200, - Update: []*gpb.Update{ - { - Path: &gpb.Path{Element: []string{"a"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{5}}, - }, - }, - }, - }}, - {Response: &gpb.SubscribeResponse_Update{ - Update: &gpb.Notification{ - Timestamp: 300, - Prefix: &gpb.Path{Target: "dev", Element: []string{"a"}}, - Update: []*gpb.Update{ - { - Path: &gpb.Path{Element: []string{"b"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{5}}, - }, - }, - }, - }}, - {Response: &gpb.SubscribeResponse_Update{ - Update: &gpb.Notification{ - Timestamp: 400, - Prefix: &gpb.Path{Target: "dev", Origin: "oc", Element: []string{"a"}}, - Update: []*gpb.Update{ - { - Path: &gpb.Path{Element: []string{"b"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{5}}, - }, - }, - }, - }}, - } - wantNoti := []client.Notification{ - client.Connected{}, - client.Update{Path: []string{"dev", "a"}, TS: time.Unix(0, 200), Val: 5}, - client.Update{Path: []string{"dev", "a", "b"}, TS: time.Unix(0, 300), Val: 5}, - client.Update{Path: []string{"dev", "oc", "a", "b"}, TS: time.Unix(0, 400), Val: 5}, - client.Sync{}, - } - opt, err := config.WithSelfTLSCert() - if err != nil { - t.Fatalf("failed to generate cert: %v", err) - } - s, err := gnmi.New( - &fpb.Config{ - Generator: &fpb.Config_Fixed{Fixed: &fpb.FixedGenerator{Responses: updates}}, - }, - []grpc.ServerOption{opt}, - ) - if err != nil { - t.Fatal("failed to start test server") - } - defer s.Close() - q.Addrs = []string{s.Address()} - c := client.New() - defer c.Close() - err = c.Subscribe(context.Background(), q) - if diff := pretty.Compare(wantNoti, gotNoti); diff != "" { - t.Errorf("unexpected updates:\n%s", diff) - } -} - -func TestGNMIWithSubscribeRequest(t *testing.T) { - q, err := client.NewQuery(&gpb.SubscribeRequest{ - Request: &gpb.SubscribeRequest_Subscribe{ - Subscribe: &gpb.SubscriptionList{ - Mode: gpb.SubscriptionList_STREAM, - Prefix: &gpb.Path{Target: "dev"}, - Subscription: []*gpb.Subscription{ - {Path: &gpb.Path{Element: []string{"a"}}}, - }, - }, - }, - }) - if err != nil { - t.Fatalf("failed to create Query from gnmi SubscribeRequest: %v", err) - } - q.TLS = &tls.Config{InsecureSkipVerify: true} - var gotNoti []client.Notification - q.NotificationHandler = func(n client.Notification) error { - gotNoti = append(gotNoti, n) - return nil - } - updates := []*gpb.SubscribeResponse{ - {Response: &gpb.SubscribeResponse_Update{ - Update: &gpb.Notification{ - Timestamp: 200, - Update: []*gpb.Update{ - { - Path: &gpb.Path{Element: []string{"a"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{5}}, - }, - }, - }, - }}, - {Response: &gpb.SubscribeResponse_Update{ - Update: &gpb.Notification{ - Timestamp: 300, - Prefix: &gpb.Path{Target: "dev", Element: []string{"a"}}, - Update: []*gpb.Update{ - { - Path: &gpb.Path{Element: []string{"b"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{5}}, - }, - }, - }, - }}, - {Response: &gpb.SubscribeResponse_Update{ - Update: &gpb.Notification{ - Timestamp: 400, - Prefix: &gpb.Path{Target: "dev", Origin: "oc", Element: []string{"a"}}, - Update: []*gpb.Update{ - { - Path: &gpb.Path{Element: []string{"b"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{5}}, - }, - }, - }, - }}, - } - wantNoti := []client.Notification{ - client.Connected{}, - client.Update{Path: []string{"dev", "a"}, TS: time.Unix(0, 200), Val: 5}, - client.Update{Path: []string{"dev", "a", "b"}, TS: time.Unix(0, 300), Val: 5}, - client.Update{Path: []string{"dev", "oc", "a", "b"}, TS: time.Unix(0, 400), Val: 5}, - client.Sync{}, - } - opt, err := config.WithSelfTLSCert() - if err != nil { - t.Fatalf("failed to generate cert: %v", err) - } - s, err := gnmi.New( - &fpb.Config{ - Generator: &fpb.Config_Fixed{Fixed: &fpb.FixedGenerator{Responses: updates}}, - }, - []grpc.ServerOption{opt}, - ) - if err != nil { - t.Fatal("failed to start test server") - } - defer s.Close() - q.Addrs = []string{s.Address()} - c := client.New() - defer c.Close() - err = c.Subscribe(context.Background(), q) - if diff := pretty.Compare(wantNoti, gotNoti); diff != "" { - t.Errorf("unexpected updates:\n%s\nwantnoti:%v\ngotnoti:%v\n", diff, wantNoti, gotNoti) - } -} - -func stringToPath(p string) *gpb.Path { - pp, err := ygot.StringToPath(p, ygot.StructuredPath, ygot.StringSlicePath) - if err != nil { - panic(err) - } - return pp -} - -func TestNoti(t *testing.T) { - tests := []struct { - desc string - prefix []string - path *gpb.Path - ts time.Time - u *gpb.Update - wantNoti client.Notification - wantErr bool - }{ - { - desc: "nil update means delete", - path: stringToPath("dev/a/b"), - ts: time.Unix(0, 200), - wantNoti: client.Delete{Path: []string{"dev", "a", "b"}, TS: time.Unix(0, 200)}, - }, { - desc: "update with TypedValue", - path: stringToPath("dev/a"), - ts: time.Unix(0, 100), - u: &gpb.Update{Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{5}}}, - wantNoti: client.Update{Path: []string{"dev", "a"}, TS: time.Unix(0, 100), Val: 5}, - }, { - desc: "update with non-scalar TypedValue", - path: stringToPath("dev/a"), - ts: time.Unix(0, 100), - u: &gpb.Update{Val: &gpb.TypedValue{Value: &gpb.TypedValue_JsonVal{[]byte("5")}}}, - wantErr: true, - }, { - desc: "update with JSON value", - path: stringToPath("dev/a"), - ts: time.Unix(0, 100), - u: &gpb.Update{Value: &gpb.Value{Type: gpb.Encoding_JSON, Value: []byte("5")}}, - wantNoti: client.Update{Path: []string{"dev", "a"}, TS: time.Unix(0, 100), Val: 5}, - }, { - desc: "update with bytes value", - path: stringToPath("dev/a"), - ts: time.Unix(0, 100), - u: &gpb.Update{Value: &gpb.Value{Type: gpb.Encoding_BYTES, Value: []byte("5")}}, - wantNoti: client.Update{Path: []string{"dev", "a"}, TS: time.Unix(0, 100), Val: []byte("5")}, - }, { - desc: "update with un-unmarshalable JSON value", - path: stringToPath("dev/a"), - ts: time.Unix(0, 100), - u: &gpb.Update{Value: &gpb.Value{Type: gpb.Encoding_JSON, Value: []byte(`"5`)}}, - wantErr: true, - }, { - desc: "update with unsupported value", - path: stringToPath("dev/a"), - ts: time.Unix(0, 100), - u: &gpb.Update{Value: &gpb.Value{Type: gpb.Encoding_PROTO}}, - wantErr: true, - }, { - desc: "with prefix", - prefix: []string{"dev"}, - path: stringToPath("a"), - ts: time.Unix(0, 100), - u: &gpb.Update{Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{5}}}, - wantNoti: client.Update{Path: []string{"dev", "a"}, TS: time.Unix(0, 100), Val: 5}, - }, - } - for _, tt := range tests { - got, err := noti(tt.prefix, tt.path, tt.ts, tt.u) - switch { - case err != nil && !tt.wantErr: - t.Errorf("%s: got error %v, want nil", tt.desc, err) - case err == nil && tt.wantErr: - t.Errorf("%s: got nil error, want non-nil", tt.desc) - } - if diff := pretty.Compare(tt.wantNoti, got); diff != "" { - t.Errorf("%s: notification diff:\n%s", tt.desc, diff) - } - } -} - -func TestPathToString(t *testing.T) { - tests := []struct { - desc string - in client.Path - want string - }{ - {"simple path", client.Path{"a", "b", "c"}, "a/b/c"}, - {"path with attributes", client.Path{"a", "b[k=v]", "c"}, "a/b[k=v]/c"}, - {"path with slashes", client.Path{"a", "b/0/1", "c"}, "a/b\\/0\\/1/c"}, - } - - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - got := pathToString(tt.in) - if got != tt.want { - t.Fatalf("got %q, want %q", got, tt.want) - } - }) - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/gnmi/credentials.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/gnmi/credentials.go deleted file mode 100644 index 4a0cf24f1..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/gnmi/credentials.go +++ /dev/null @@ -1,55 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 client - -import ( - "golang.org/x/net/context" - - "google.golang.org/grpc/credentials" -) - -// passCred is an username/password implementation of credentials.Credentials. -type passCred struct { - username string - password string - secure bool -} - -// GetRequestMetadata returns the current request metadata, including -// username and password in this case. -// This implements the required interface fuction of credentials.Credentials. -func (pc *passCred) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) { - return map[string]string{ - "username": pc.username, - "password": pc.password, - }, nil -} - -// RequireTransportSecurity indicates whether the credentials requires transport security. -// This implements the required interface fuction of credentials.Credentials. -func (pc *passCred) RequireTransportSecurity() bool { - return pc.secure -} - -// newPassCred returns a newly created passCred as credentials.Credentials. -func newPassCred(username, password string, secure bool) credentials.PerRPCCredentials { - return &passCred{ - username: username, - password: password, - secure: secure, - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/grpcutil/lookup.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/grpcutil/lookup.go deleted file mode 100644 index fa64e66f2..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/grpcutil/lookup.go +++ /dev/null @@ -1,59 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 grpcutil provides helper functions for working with gRPC targets. -package grpcutil - -import ( - "context" - - "google.golang.org/grpc" - - rpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha" -) - -// Lookup uses ServerReflection service on conn to find a named service. -// It returns an error if the remote side doesn't support ServerReflection or -// if any other error occurs. -// -// If lookup succeeds and service is found, true is returned. -func Lookup(ctx context.Context, conn *grpc.ClientConn, service string) (bool, error) { - c, err := rpb.NewServerReflectionClient(conn).ServerReflectionInfo(ctx) - if err != nil { - return false, err - } - defer c.CloseSend() - - if err := c.Send(&rpb.ServerReflectionRequest{ - MessageRequest: &rpb.ServerReflectionRequest_ListServices{}, - }); err != nil { - return false, err - } - - resp, err := c.Recv() - if err != nil { - return false, err - } - - lsResp := resp.GetListServicesResponse() - for _, s := range lsResp.GetService() { - if s.Name == service { - return true, nil - } - } - - return false, nil -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/grpcutil/lookup_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/grpcutil/lookup_test.go deleted file mode 100644 index 4a599fbcc..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/grpcutil/lookup_test.go +++ /dev/null @@ -1,71 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 grpcutil - -import ( - "golang.org/x/net/context" - "net" - "testing" - - log "github.com/golang/glog" - "google.golang.org/grpc" - "google.golang.org/grpc/reflection" - "github.com/openconfig/gnmi/unimplemented" - - gpb "github.com/openconfig/gnmi/proto/gnmi" -) - -func TestLookup(t *testing.T) { - l, err := net.Listen("tcp", ":0") - if err != nil { - t.Fatal(err) - } - srv := grpc.NewServer() - defer srv.Stop() - - gpb.RegisterGNMIServer(srv, &unimplemented.Server{}) - reflection.Register(srv) - - go srv.Serve(l) - - c, err := grpc.Dial(l.Addr().String(), grpc.WithInsecure()) - if err != nil { - log.Fatal(err) - } - - ctx := context.Background() - - t.Run("valid service", func(t *testing.T) { - ok, err := Lookup(ctx, c, "gnmi.gNMI") - if err != nil { - log.Error(err) - } - if !ok { - log.Error("got false, want true") - } - }) - t.Run("unknown service", func(t *testing.T) { - ok, err := Lookup(ctx, c, "unknown.Unknown") - if err != nil { - log.Error(err) - } - if ok { - log.Error("got true, want false") - } - }) - -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/notification.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/notification.go deleted file mode 100644 index 16f4a6cf9..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/notification.go +++ /dev/null @@ -1,64 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 client - -// Notification are internal messages used for abstracting protocol specific -// messages for clients. isNotification is only present to force typing -// assertions. -type Notification interface { - isNotification() -} - -// Update is an update to the leaf in the tree. -type Update Leaf - -func (u Update) isNotification() {} - -// Delete is an explicit delete of the path in the tree. -type Delete Leaf - -func (d Delete) isNotification() {} - -// Error is a inband error notification. It could be received without breaking -// the query or connection. -type Error struct { - s string -} - -// NewError will return a new error with the provided text. -func NewError(s string) Error { - return Error{s: s} -} - -// Error is provided to implement the error interface. -func (e Error) Error() string { - return e.s -} -func (e Error) isNotification() {} - -// Sync is an inband notification that the client has sent everything in it's -// cache at least once. This does not mean EVERYTHING you wanted is there only -// that the target has sent everything it currently has... which may be nothing. -type Sync struct{} - -func (s Sync) isNotification() {} - -// Connected is a synthetic notification sent when connection is established. -// It's sent before any other notifications on a new client. -type Connected struct{} - -func (s Connected) isNotification() {} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/query.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/query.go deleted file mode 100644 index 6ae4330e4..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/query.go +++ /dev/null @@ -1,278 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 client - -import ( - "crypto/tls" - "errors" - "fmt" - "regexp" - "time" - - "github.com/golang/protobuf/proto" - "github.com/openconfig/gnmi/path" - gpb "github.com/openconfig/gnmi/proto/gnmi" -) - -// NotificationHandler is a type for the client specific handler function. -// -// Client implementations will pass all kinds of received notifications as they -// arrive. -type NotificationHandler func(Notification) error - -// ProtoHandler is a type for the raw handling of the RPC layer. Most users -// should use NotificationHandler instead. -type ProtoHandler func(proto.Message) error - -// Type defines the type of query in a Query. -type Type int - -// NewType returns a new QueryType based on the provided string. -func NewType(s string) Type { - v, ok := typeConst[s] - if !ok { - return Unknown - } - return v -} - -// String returns the string representation of the QueryType. -func (q Type) String() string { - return typeString[q] -} - -const ( - // Unknown is an unknown query and should always be treated as an error. - Unknown Type = iota - // Once will perform a Once query against the agent. - Once - // Poll will perform a Polling query against the agent. - Poll - // Stream will perform a Streaming query against the agent. - Stream -) - -var ( - typeString = map[Type]string{ - Unknown: "unknown", - Once: "once", - Poll: "poll", - Stream: "stream", - } - - typeConst = map[string]Type{ - "unknown": Unknown, - "once": Once, - "poll": Poll, - "stream": Stream, - } - - // Pre-compiled regex to match ASCII characters between [\x20-\x7E] - // i.e., printable ASCII characters and space - // https://github.com/grpc/blob/master/doc/PROTOCOL-HTTP2.md - printableASCII = regexp.MustCompile(`^[\x20-\x7E]*$`).MatchString -) - -// Destination contains data used to connect to a server. -type Destination struct { - // Addrs is a slice of addresses by which a target may be reached. Most - // clients will only handle the first element. - Addrs []string - // Target is the target of the query. Maybe empty if the query is performed - // against an end target vs. a collector. - Target string - // Replica is the specific backend to contact. This field is implementation - // specific and for direct agent communication should not be set. default is - // first available. - Replica int - // Timeout is the connection timeout for the query. It will *not* prevent a - // slow (or streaming) query from completing, this only affects the initial - // connection and broken connection detection. - // - // If Timeout is not set, default is 1 minute. - Timeout time.Duration - // Credentials are used for authentication with the target. Optional. - Credentials *Credentials - // TLS config to use when connecting to target. Optional. - TLS *tls.Config - // Extra contains arbitrary additional metadata to be passed to the - // target. Optional. - Extra map[string]string -} - -// Validate validates the fields of Destination. -func (d Destination) Validate() error { - if len(d.Addrs) == 0 { - return errors.New("Destination.Addrs is empty") - } - if d.Credentials != nil { - return d.Credentials.validate() - } - return nil -} - -// Query contains all of the parameters necessary to initiate the query. -type Query struct { - // Addrs is a slice of addresses by which a target may be reached. Most - // clients will only handle the first element. - Addrs []string - AddressChains [][]string - // Target is the target of the query. Maybe empty if the query is performed - // against an end target vs. a collector. - Target string - // Replica is the specific backend to contact. This field is implementation - // specific and for direct agent communication should not be set. default is - // first available. - Replica int - // UpdatesOnly will only stream incremental updates rather than providing the - // client with an initial snapshot. This again is implementation specific - // if the agent doesn't not accept that query it is up the client library to - // decide wheter to return an error or to make a normal subscription then - // ignore the initial sync and only provide increment updates. - UpdatesOnly bool - // Queries contains the list of Paths to query. - Queries []Path - // Type of query to perform. - Type Type - // Timeout is the connection timeout for the query. It will *not* prevent a - // slow (or streaming) query from completing, this only affects the initial - // connection and broken connection detection. - // - // If Timeout is not set, default is 1 minute. - Timeout time.Duration - // NotificationHandler is the per notification callback handed to a vendor - // specific implementation. For every notificaiton this call back will be - // called. - NotificationHandler NotificationHandler - // ProtoHandler, if set, will receive all response protos sent by the - // backend. Only one of NotificationHandler or ProtoHandler may be - // set. - ProtoHandler ProtoHandler - // Credentials are used for authentication with the target. Optional. - Credentials *Credentials - // TLS config to use when connecting to target. Optional. - TLS *tls.Config - // Extra contains arbitrary additional metadata to be passed to the - // target. Optional. - Extra map[string]string - // SubReq is an optional field. If not nil, gnmi client implementation uses - // it rather than generating from client.Query while sending gnmi Subscribe RPC. - SubReq *gpb.SubscribeRequest - Streaming_type gpb.SubscriptionMode - Streaming_sample_int uint64 - Heartbeat_int uint64 - Suppress_redundant bool -} - -// Destination extracts a Destination instance out of Query fields. -// -// Ideally we would embed Destination in Query. But in order to not break the -// existing API we have this workaround. -func (q Query) Destination() Destination { - return Destination{ - Addrs: q.Addrs, - Target: q.Target, - Replica: q.Replica, - Timeout: q.Timeout, - Credentials: q.Credentials, - TLS: q.TLS, - Extra: q.Extra, - } -} - -// Credentials contains information necessary to authenticate with the target. -// Currently only username/password are supported, but may contain TLS client -// certificate in the future. -type Credentials struct { - Username string - Password string -} - -// Validates the credentials against printable ASCII characters -func (c Credentials) validate() error { - if !printableASCII(c.Username) { - return errors.New("Credentials.Username contains non printable ASCII characters") - } - if !printableASCII(c.Password) { - return errors.New("Credentials.Password contains non printable ASCII characters") - } - return nil -} - -// NewQuery returns a populated Query from given gnmi SubscribeRequest. -// Query fields that are not part of SubscribeRequest must be set on -// the returned object. -// During transtion to support only gnmi, having Query and SubscribeRequest -// in sync is important. There are two approaches to ensure that; one is -// validating whether Query and SubscribeRequest are same after they are set, the other is -// populating the fields of Query from SubscribeRequest and filling out the rest -// on the returned object. NewQuery embraces the latter option. -func NewQuery(sr *gpb.SubscribeRequest) (Query, error) { - q := Query{} - if sr == nil { - return q, errors.New("input is nil") - } - - s, ok := sr.Request.(*gpb.SubscribeRequest_Subscribe) - if !ok { - return q, fmt.Errorf("got %T, want gpb.SubscribeRequest_Subscribe as input", sr) - } - - if s.Subscribe == nil { - return q, errors.New("Subscribe field in SubscribeRequest_Subscribe is nil") - } - - if s.Subscribe.Prefix == nil { - return q, errors.New("Prefix field in SubscriptionList is nil") - } - q.Target = s.Subscribe.Prefix.Target - q.UpdatesOnly = s.Subscribe.UpdatesOnly - switch s.Subscribe.Mode { - case gpb.SubscriptionList_ONCE: - q.Type = Once - case gpb.SubscriptionList_POLL: - q.Type = Poll - case gpb.SubscriptionList_STREAM: - q.Type = Stream - } - - for _, su := range s.Subscribe.Subscription { - q.Queries = append(q.Queries, path.ToStrings(su.Path, false)) - } - q.SubReq = sr - - return q, nil -} - -// Validate validates that query contains valid values that any client should -// be able use to form a valid backend request. -func (q Query) Validate() error { - if err := q.Destination().Validate(); err != nil { - return err - } - switch { - case q.Type == Unknown: - return errors.New("Query type cannot be Unknown") - case len(q.Queries) == 0: - return errors.New("Query.Queries not set") - case q.NotificationHandler != nil && q.ProtoHandler != nil: - return errors.New("only one of Notification or ProtoHandler must be set") - case q.NotificationHandler == nil && q.ProtoHandler == nil: - return errors.New("one of Notification or ProtoHandler must be set") - } - return nil -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/reconnect.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/reconnect.go deleted file mode 100644 index 91aec2fab..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/reconnect.go +++ /dev/null @@ -1,200 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 client - -import ( - "context" - "fmt" - "math/rand" - "sync" - "time" - - log "github.com/golang/glog" -) - -var ( - // ReconnectBaseDelay is the minimum delay between re-Subscribe attempts in - // Reconnect. You can change this before creating ReconnectClient instances. - ReconnectBaseDelay = time.Second - // ReconnectMaxDelay is the maximum delay between re-Subscribe attempts in - // Reconnect. You can change this before creating ReconnectClient instances. - ReconnectMaxDelay = time.Minute -) - -// ReconnectClient is a wrapper around any Client that never returns from -// Subscribe (unless explicitly closed). Underlying calls to Subscribe are -// repeated indefinitely, with an exponential backoff between attempts. -// -// ReconnectClient should only be used with streaming or polling queries. Once -// queries will fail immediately in Subscribe. -type ReconnectClient struct { - Client - disconnect func() - reset func() - - mu sync.Mutex - subscribeDone chan struct{} - cancel func() - closed bool -} - -var _ Client = &ReconnectClient{} - -// Reconnect wraps c and returns a new ReconnectClient using it. -// -// disconnect callback is called each time the underlying Subscribe returns, it -// may be nil. -// -// reset callback is called each time the underlying Subscribe is retried, it -// may be nil. -// -// Closing the returned ReconnectClient will unblock Subscribe. -func Reconnect(c Client, disconnect, reset func()) *ReconnectClient { - return &ReconnectClient{Client: c, disconnect: disconnect, reset: reset} -} - -// Subscribe implements Client interface. -func (p *ReconnectClient) Subscribe(ctx context.Context, q Query, clientType ...string) error { - switch q.Type { - default: - return fmt.Errorf("ReconnectClient used for %s query", q.Type) - case Stream, Poll: - } - - ctx, done := p.initDone(ctx) - defer done() - - failCount := 0 - for { - start := time.Now() - err := p.Client.Subscribe(ctx, q, clientType...) - if p.disconnect != nil { - p.disconnect() - } - failCount++ - - // Check if Subscribe returned because ctx was canceled. - select { - case <-ctx.Done(): - return ctx.Err() - default: - } - - if err == nil { - failCount = 0 - } - // Since Client won't tell us whether error was immediate or after - // streaming for a while, try to "guess" if it's the latter. - if time.Since(start) > ReconnectMaxDelay { - failCount = 0 - } - - bo := backoff(ReconnectBaseDelay, ReconnectMaxDelay, failCount) - log.Errorf("client.Subscribe (target %q) failed (%d times): %v; reconnecting in %s", q.Target, failCount, err, bo) - time.Sleep(bo) - - // Signal caller right before we attempt to reconnect. - if p.reset != nil { - p.reset() - } - } -} - -// initDone finishes Subscribe initialization before starting the inner -// Subscribe loop. -// If p is closed before initDone, a cancelled context is returned. -func (p *ReconnectClient) initDone(ctx context.Context) (context.Context, func()) { - p.mu.Lock() - defer p.mu.Unlock() - p.subscribeDone = make(chan struct{}) - - // ctx is cancelled in p.Close(). - ctx, p.cancel = context.WithCancel(ctx) - - // If Close was called before initDone returned, it didn't have a cancel - // func to trigger. Trigger it here instead. - // Since initDone and Cancel are synchronizing on p.mu, either this or - // Close will call p.cancel(), preventing a hanging client. - if p.closed { - p.cancel() - } - - return ctx, func() { - close(p.subscribeDone) - } -} - -// Close implements Client interface. -func (p *ReconnectClient) Close() error { - subscribeDone := func() chan struct{} { - p.mu.Lock() - defer p.mu.Unlock() - - if p.cancel != nil { - p.cancel() - } - p.closed = true - - return p.subscribeDone - }() - - err := p.Client.Close() - - // Wait for Subscribe to return. - if subscribeDone != nil { - <-subscribeDone - } - return err -} - -// Impl implements Client interface. -func (p *ReconnectClient) Impl() (Impl, error) { - return p.Client.Impl() -} - -// Poll implements Client interface. -// Poll may fail if Subscribe is reconnecting when it's called. -func (p *ReconnectClient) Poll() error { - return p.Client.Poll() -} - -const ( - backoffFactor = 1.3 // backoff increases by this factor on each retry - backoffRange = 0.4 // backoff is randomized downwards by this factor -) - -// backoff a duration to wait for before retrying a query. The duration grows -// exponentially as retries increases. -func backoff(baseDelay, maxDelay time.Duration, retries int) time.Duration { - backoff, max := float64(baseDelay), float64(maxDelay) - for backoff < max && retries > 0 { - backoff = backoff * backoffFactor - retries-- - } - if backoff > max { - backoff = max - } - - // Randomize backoff delays so that if a cluster of requests start at - // the same time, they won't operate in lockstep. We just subtract up - // to 40% so that we obey maxDelay. - backoff -= backoff * backoffRange * rand.Float64() - if backoff < 0 { - return 0 - } - return time.Duration(backoff) -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/reconnect_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/reconnect_test.go deleted file mode 100644 index 29667b194..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/reconnect_test.go +++ /dev/null @@ -1,102 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 client_test - -import ( - "context" - "errors" - "testing" - "time" - - "github.com/openconfig/gnmi/client" - fclient "github.com/openconfig/gnmi/client/fake" -) - -func TestReconnect(t *testing.T) { - c := breakingSubscribeClient{ - BaseClient: &client.BaseClient{}, - ch: make(chan error), - } - - disconnect := make(chan struct{}, 1) - reset := make(chan struct{}) - rc := client.Reconnect(c, func() { disconnect <- struct{}{} }, func() { reset <- struct{}{} }) - client.ReconnectBaseDelay = time.Nanosecond - client.ReconnectMaxDelay = time.Millisecond - - subscribeDone := make(chan struct{}) - go func() { - defer close(subscribeDone) - rc.Subscribe(context.Background(), client.Query{Type: client.Stream}) - }() - for i := 0; i < 100; i++ { - c.ch <- errors.New("break") - <-disconnect - <-reset - } - - // Try to trigger a race between rc.Close and rc.Subscribe. - // rc.Close should return only after rc.Subscribe is done. - closeDone := make(chan struct{}) - go func() { - defer close(closeDone) - rc.Close() - }() - select { - case <-subscribeDone: - case <-closeDone: - t.Error("rc.Close returned before rc.Subscribe") - } -} - -type breakingSubscribeClient struct { - *client.BaseClient - ch chan error -} - -func (c breakingSubscribeClient) Subscribe(ctx context.Context, q client.Query, clientType ...string) error { - return <-c.ch -} - -func (c breakingSubscribeClient) Close() error { - c.ch <- errors.New("closed") - return nil -} - -func TestReconnectEarlyClose(t *testing.T) { - block := make(fclient.Block) - defer close(block) - fclient.Mock("fake", []interface{}{block}) - - rc := client.Reconnect(&client.BaseClient{}, nil, nil) - rc.Close() - - done := make(chan struct{}) - go func() { - rc.Subscribe(context.Background(), client.Query{ - Type: client.Stream, - NotificationHandler: func(client.Notification) error { return nil }, - }, "fake") - close(done) - }() - - select { - case <-done: - case <-time.After(time.Second): - t.Error("Subscribe on a closed ReconnectClient didn't return after 1s") - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/register.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/register.go deleted file mode 100644 index 500147bdd..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/register.go +++ /dev/null @@ -1,196 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 client - -import ( - "context" - "errors" - "fmt" - "sort" - "sync" - "time" - - log "github.com/golang/glog" - "github.com/openconfig/gnmi/errlist" -) - -var ( - mu sync.Mutex - clientImpl = map[string]InitImpl{} -) - -// Default timeout for all queries. -const defaultTimeout = time.Minute - -// Impl is the protocol/RPC specific implementation of the streaming Client. -// Unless you're implementing a new RPC format, this shouldn't be used directly. -type Impl interface { - // Subscribe sends a Subscribe request to the server. - Subscribe(context.Context, Query) error - // Recv processes a single message from the server. This method is exposed to - // allow the generic client control the state of message processing. - Recv() error - // Close will close the underlying rpc connections. - Close() error - // Poll will send an implementation specific Poll request to the server. - Poll() error -} - -// InitImpl is a constructor signature for all transport specific implementations. -type InitImpl func(context.Context, Destination) (Impl, error) - -// Register will register the transport specific implementation. -// The name must be unique across all transports. -func Register(t string, f InitImpl) error { - mu.Lock() - defer mu.Unlock() - if _, ok := clientImpl[t]; ok { - return fmt.Errorf("Duplicate registration of type %q", t) - } - if f == nil { - return errors.New("RegisterFunc cannot be nil") - } - clientImpl[t] = f - log.V(1).Infof("client.Register(%q, func) successful.", t) - return nil -} - -// RegisterTest allows tests to override client implementation for any client -// type. It's identical to Register, except t uniqueness is not enforced. -// -// RegisterTest is similar to ResetRegisteredImpls + Register. -// Commonly used with the fake client (./fake directory). -func RegisterTest(t string, f InitImpl) error { - mu.Lock() - defer mu.Unlock() - if f == nil { - return errors.New("RegisterFunc cannot be nil") - } - clientImpl[t] = f - log.V(1).Infof("client.Register(%q, func) successful.", t) - return nil -} - -// NewImpl returns a client implementation based on the registered types. -// It will try all clientTypes listed in parallel until one succeeds. If -// clientType is nil, it will try all registered clientTypes. -// -// This function is only used internally and is exposed for testing only. -func NewImpl(ctx context.Context, d Destination, clientType ...string) (Impl, error) { - mu.Lock() - registeredCount := len(clientImpl) - if clientType == nil { - for t := range clientImpl { - clientType = append(clientType, t) - } - } - mu.Unlock() - if registeredCount == 0 { - return nil, errors.New("no registered client types") - } - - // If Timeout is not set, use a default one. There is pretty much never a - // case where clients will want to wait for initial connection - // indefinitely. Reconnect client helps with retries. - if d.Timeout == 0 { - d.Timeout = defaultTimeout - } - - log.V(1).Infof("Attempting client types: %v", clientType) - fn := func(ctx context.Context, typ string, input interface{}) (Impl, error) { - mu.Lock() - f, ok := clientImpl[typ] - mu.Unlock() - if !ok { - return nil, fmt.Errorf("no registered client %q", typ) - } - d := input.(Destination) - impl, err := f(ctx, d) - if err != nil { - return nil, err - } - log.V(1).Infof("client %q create with type %T", typ, impl) - return impl, nil - } - return getFirst(ctx, clientType, d, fn) -} - -type implFunc func(ctx context.Context, typ string, input interface{}) (Impl, error) - -// getFirst tries fn with all types in parallel and returns the Impl from first -// one to succeed. input is passed directly to fn so it's safe to use an -// unchecked type asserting inside fn. -func getFirst(ctx context.Context, types []string, input interface{}, fn implFunc) (Impl, error) { - if len(types) == 0 { - return nil, errors.New("getFirst: no client types provided") - } - errC := make(chan error, len(types)) - implC := make(chan Impl) - done := make(chan struct{}) - defer close(done) - for _, t := range types { - // Launch each clientType in parallel where each sends either an error or - // an implementation over a channel. - go func(t string) { - impl, err := fn(ctx, t, input) - if err != nil { - errC <- fmt.Errorf("client %q : %v", t, err) - return - } - select { - case implC <- impl: - case <-done: - impl.Close() - } - }(t) - } - errs := errlist.Error{List: errlist.List{Separator: "\n\t"}} - // Look for the first non-error client implementation or return an error if - // all client types fail. - for { - select { - case err := <-errC: - errs.Add(err) - if len(errs.Errors()) == len(types) { - return nil, errs.Err() - } - case impl := <-implC: - return impl, nil - } - } -} - -// ResetRegisteredImpls removes and Impls registered with Register. This should -// only be used in tests to clear out their mock Impls, so that they don't -// affect other tests. -func ResetRegisteredImpls() { - mu.Lock() - defer mu.Unlock() - clientImpl = make(map[string]InitImpl) -} - -// RegisteredImpls returns a slice of currently registered client types. -func RegisteredImpls() []string { - mu.Lock() - defer mu.Unlock() - var impls []string - for k := range clientImpl { - impls = append(impls, k) - } - sort.Strings(impls) - return impls -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/values.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/client/values.go deleted file mode 100644 index 81506153c..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/client/values.go +++ /dev/null @@ -1,76 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 client - -import "time" - -// Leaf represents a leaf value in the tree. It includes the path to the node in -// the tree. This is returned via Leaves. It is also the basis for all -// Notification types that are used by the NotificationHandler callbacks see -// "notification.go". -type Leaf struct { - Path Path - Val interface{} - TS time.Time // TS is the timestamp of last update to this leaf. - Dups uint32 // Dups is the number of coalesced duplicates for this leaf. -} - -// Leaves implements sort.Interface over []Leaf based on paths. -type Leaves []Leaf - -func (pv Leaves) Len() int { return len(pv) } -func (pv Leaves) Swap(i, j int) { pv[i], pv[j] = pv[j], pv[i] } -func (pv Leaves) Less(i, j int) bool { - return pv[i].Path.Less(pv[j].Path) -} - -// TreeVal contains the current branch's value and the timestamp when the -// node was last updated. -type TreeVal struct { - Val interface{} `json:"value"` - TS time.Time `json:"timestamp"` -} - -// Path is a standard type for describing a path inside of streaming telemetry -// tree. -type Path []string - -// Less returns true if p sorts before p2. -func (p Path) Less(p2 Path) bool { - for x := 0; x < len(p) && x < len(p2); x++ { - if p[x] < p2[x] { - return true - } - if p[x] > p2[x] { - return false - } - } - return len(p) < len(p2) -} - -// Equal returns true if p is equivalent to p2. -func (p Path) Equal(p2 Path) bool { - if len(p) != len(p2) { - return false - } - for x := 0; x < len(p); x++ { - if p[x] != p2[x] { - return false - } - } - return true -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_cli/gnmi_cli.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_cli/gnmi_cli.go deleted file mode 100644 index 550fbcfd2..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_cli/gnmi_cli.go +++ /dev/null @@ -1,366 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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. -*/ - -// The gnmi_cli program implements the GNMI CLI. -// -// usage: -// gnmi_cli --address=
\ -// -q= \ -// [-qt=] \ -// [-] -package main - -import ( - "context" - "crypto/tls" - "crypto/x509" - "errors" - "fmt" - "io/ioutil" - "os" - "os/signal" - "strings" - "sync" - "time" - "unicode/utf8" - - "flag" - - log "github.com/golang/glog" - "github.com/golang/protobuf/proto" - "golang.org/x/crypto/ssh/terminal" - "github.com/openconfig/gnmi/cli" - "github.com/openconfig/gnmi/client" - "github.com/openconfig/gnmi/client/flags" - gclient "github.com/openconfig/gnmi/client/gnmi" - - gpb "github.com/openconfig/gnmi/proto/gnmi" -) - -var ( - q = client.Query{TLS: &tls.Config{}} - mu sync.Mutex - cfg = cli.Config{Display: func(b []byte) { - defer mu.Unlock() - mu.Lock() - os.Stdout.Write(append(b, '\n')) - }} - - clientTypes = flags.NewStringList(&cfg.ClientTypes, []string{gclient.Type}) - queryFlag = &flags.StringList{} - queryType = flag.String("query_type", client.Once.String(), "Type of result, one of: (o, once, p, polling, s, streaming).") - queryAddr = flags.NewStringList(&q.Addrs, nil) - - reqProto = flag.String("proto", "", "Text proto for gNMI request.") - - capabilitiesFlag = flag.Bool("capabilities", false, `When set, CLI will perform a Capabilities request. Usage: gnmi_cli -capabilities [-proto ] -address
[other flags ...]`) - getFlag = flag.Bool("get", false, `When set, CLI will perform a Get request. Usage: gnmi_cli -get -proto -address
[other flags ...]`) - setFlag = flag.Bool("set", false, `When set, CLI will perform a Set request. Usage: gnmi_cli -set -proto -address
[other flags ...]`) - - withUserPass = flag.Bool("with_user_pass", false, "When set, CLI will prompt for username/password to use when connecting to a target.") - - // Certificate files. - caCert = flag.String("ca_crt", "", "CA certificate file. Used to verify server TLS certificate.") - clientCert = flag.String("client_crt", "", "Client certificate file. Used for client certificate-based authentication.") - clientKey = flag.String("client_key", "", "Client private key file. Used for client certificate-based authentication.") - //Subscribe Options - streaming_type = flag.String("streaming_type", "TARGET_DEFINED", "One of TARGET_DEFINED, ON_CHANGE or SAMPLE") - streaming_sample_int = flag.Uint("streaming_sample_interval", 0, "Streaming sample inteval seconds, 0 means lowest supported.") - heartbeat_int = flag.Uint("heartbeat_interval", 0, "Heartbeat inteval seconds.") - suppress_redundant = flag.Bool("suppress_redundant", false, "Suppress Redundant Subscription Updates") -) - -func init() { - flag.Var(clientTypes, "client_types", fmt.Sprintf("List of explicit client types to attempt, one of: %s.", strings.Join(client.RegisteredImpls(), ", "))) - flag.Var(queryFlag, "query", "Comma separated list of queries. Each query is a delimited list of OpenConfig path nodes which may also be specified as a glob (*). The delimeter can be specified with the --delimiter flag.") - // Query command-line flags. - flag.Var(queryAddr, "address", "Address of the GNMI target to query.") - flag.BoolVar(&q.UpdatesOnly, "updates_only", false, "Only stream updates, not the initial sync. Setting this flag for once or polling queries will cause nothing to be returned.") - // Config command-line flags. - flag.DurationVar(&cfg.PollingInterval, "polling_interval", 30*time.Second, "Interval at which to poll in seconds if polling is specified for query_type.") - flag.UintVar(&cfg.Count, "count", 0, "Number of polling/streaming events (0 is infinite).") - flag.StringVar(&cfg.Delimiter, "delimiter", "/", "Delimiter between path nodes in query. Must be a single UTF-8 code point.") - flag.DurationVar(&cfg.StreamingDuration, "streaming_duration", 0, "Length of time to collect streaming queries (0 is infinite).") - flag.StringVar(&cfg.DisplayPrefix, "display_prefix", "", "Per output line prefix.") - flag.StringVar(&cfg.DisplayIndent, "display_indent", " ", "Output line, per nesting-level indent.") - flag.StringVar(&cfg.DisplayType, "display_type", "group", "Display output type (g, group, s, single, p, proto).") - flag.StringVar(&q.Target, "target", "", "Name of the gNMI target.") - flag.DurationVar(&q.Timeout, "timeout", 30*time.Second, "Terminate query if no RPC is established within the timeout duration.") - flag.StringVar(&cfg.Timestamp, "timestamp", "", "Specify timestamp formatting in output. One of (, on, raw, ) where is disabled, on is human readable, raw is int64 nanos since epoch, and is according to golang time.Format()") - flag.BoolVar(&cfg.DisplaySize, "display_size", false, "Display the total size of query response.") - flag.BoolVar(&cfg.Latency, "latency", false, "Display the latency for receiving each update (Now - update timestamp).") - flag.StringVar(&q.TLS.ServerName, "server_name", "", "When set, CLI will use this hostname to verify server certificate during TLS handshake.") - flag.BoolVar(&q.TLS.InsecureSkipVerify, "insecure", false, "When set, CLI will not verify the server certificate during TLS handshake.") - - // Shortcut flags that can be used in place of the longform flags above. - flag.Var(queryAddr, "a", "Short for address.") - flag.Var(queryFlag, "q", "Short for query.") - flag.StringVar(&q.Target, "t", q.Target, "Short for target.") - flag.BoolVar(&q.UpdatesOnly, "u", q.UpdatesOnly, "Short for updates_only.") - flag.UintVar(&cfg.Count, "c", cfg.Count, "Short for count.") - flag.StringVar(&cfg.Delimiter, "d", cfg.Delimiter, "Short for delimiter.") - flag.StringVar(&cfg.Timestamp, "ts", cfg.Timestamp, "Short for timestamp.") - flag.StringVar(queryType, "qt", *queryType, "Short for query_type.") - flag.StringVar(&cfg.DisplayType, "dt", cfg.DisplayType, "Short for display_type.") - flag.DurationVar(&cfg.StreamingDuration, "sd", cfg.StreamingDuration, "Short for streaming_duration.") - flag.DurationVar(&cfg.PollingInterval, "pi", cfg.PollingInterval, "Short for polling_interval.") - flag.BoolVar(&cfg.DisplaySize, "ds", cfg.DisplaySize, "Short for display_size.") - flag.BoolVar(&cfg.Latency, "l", cfg.Latency, "Short for latency.") - flag.StringVar(reqProto, "p", *reqProto, "Short for request proto.") -} - -func main() { - flag.Parse() - - ctx, cancel := context.WithCancel(context.Background()) - // Terminate immediately on Ctrl+C, skipping lame-duck mode. - go func() { - c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt) - <-c - cancel() - }() - - if len(q.Addrs) == 0 { - log.Exit("--address must be set") - } - if *withUserPass { - var err error - q.Credentials, err = readCredentials() - if err != nil { - log.Exit(err) - } - } - - if *caCert != "" { - certPool := x509.NewCertPool() - ca, err := ioutil.ReadFile(*caCert) - if err != nil { - log.Exitf("could not read %q: %s", *caCert, err) - } - if ok := certPool.AppendCertsFromPEM(ca); !ok { - log.Exit("failed to append CA certificates") - } - - q.TLS.RootCAs = certPool - } - - if *clientCert != "" || *clientKey != "" { - if *clientCert == "" || *clientKey == "" { - log.Exit("--client_crt and --client_key must be set with file locations") - } - certificate, err := tls.LoadX509KeyPair(*clientCert, *clientKey) - if err != nil { - log.Exitf("could not load client key pair: %s", err) - } - - q.TLS.Certificates = []tls.Certificate{certificate} - } - - var err error - switch { - case *capabilitiesFlag: // gnmi.Capabilities - err = executeCapabilities(ctx) - case *setFlag: // gnmi.Set - err = executeSet(ctx) - case *getFlag: // gnmi.Get - err = executeGet(ctx) - default: // gnmi.Subscribe - err = executeSubscribe(ctx) - } - if err != nil { - log.Error(err) - } -} - -func executeCapabilities(ctx context.Context) error { - r := &gpb.CapabilityRequest{} - if err := proto.UnmarshalText(*reqProto, r); err != nil { - return fmt.Errorf("unable to parse gnmi.CapabilityRequest from %q : %v", *reqProto, err) - } - c, err := gclient.New(ctx, client.Destination{ - Addrs: q.Addrs, - Target: q.Target, - Timeout: q.Timeout, - Credentials: q.Credentials, - TLS: q.TLS, - }) - if err != nil { - return fmt.Errorf("could not create a gNMI client: %v", err) - } - response, err := c.(*gclient.Client).Capabilities(ctx, r) - if err != nil { - return fmt.Errorf("target returned RPC error for Capabilities(%q): %v", r.String(), err) - } - cfg.Display([]byte(proto.MarshalTextString(response))) - return nil -} - -func executeGet(ctx context.Context) error { - if *reqProto == "" { - return errors.New("-proto must be set") - } - r := &gpb.GetRequest{} - if err := proto.UnmarshalText(*reqProto, r); err != nil { - return fmt.Errorf("unable to parse gnmi.GetRequest from %q : %v", *reqProto, err) - } - c, err := gclient.New(ctx, client.Destination{ - Addrs: q.Addrs, - Target: q.Target, - Timeout: q.Timeout, - Credentials: q.Credentials, - TLS: q.TLS, - }) - if err != nil { - return fmt.Errorf("could not create a gNMI client: %v", err) - } - response, err := c.(*gclient.Client).Get(ctx, r) - if err != nil { - return fmt.Errorf("target returned RPC error for Get(%q): %v", r.String(), err) - } - cfg.Display([]byte(proto.MarshalTextString(response))) - return nil -} - -func executeSet(ctx context.Context) error { - if *reqProto == "" { - return errors.New("-proto must be set") - } - r := &gpb.SetRequest{} - if err := proto.UnmarshalText(*reqProto, r); err != nil { - return fmt.Errorf("unable to parse gnmi.SetRequest from %q : %v", *reqProto, err) - } - c, err := gclient.New(ctx, client.Destination{ - Addrs: q.Addrs, - Target: q.Target, - Timeout: q.Timeout, - Credentials: q.Credentials, - TLS: q.TLS, - }) - if err != nil { - return fmt.Errorf("could not create a gNMI client: %v", err) - } - response, err := c.(*gclient.Client).Set(ctx, r) - if err != nil { - return fmt.Errorf("target returned RPC error for Set(%q) : %v", r, err) - } - cfg.Display([]byte(proto.MarshalTextString(response))) - return nil -} - -func executeSubscribe(ctx context.Context) error { - if *reqProto != "" { - // Convert SubscribeRequest to a client.Query - tq, err := cli.ParseSubscribeProto(*reqProto) - if err != nil { - log.Exitf("failed to parse gNMI SubscribeRequest text proto: %v", err) - } - // Set the fields that are not set as part of conversion above. - tq.Addrs = q.Addrs - tq.Credentials = q.Credentials - tq.Timeout = q.Timeout - tq.TLS = q.TLS - return cli.QueryDisplay(ctx, tq, &cfg) - } - - if q.Type = cli.QueryType(*queryType); q.Type == client.Unknown { - return errors.New("--query_type must be one of: (o, once, p, polling, s, streaming)") - } - // Parse queryFlag into appropriate format. - if len(*queryFlag) == 0 { - return errors.New("--query must be set") - } - if *streaming_type == "TARGET_DEFINED" { - q.Streaming_type = gpb.SubscriptionMode(0) - } else if *streaming_type == "ON_CHANGE" { - q.Streaming_type = gpb.SubscriptionMode(1) - } else if *streaming_type == "SAMPLE" { - q.Streaming_type = gpb.SubscriptionMode(2) - } else { - return errors.New("-streaming_type must be one of: (TARGET_DEFINED, ON_CHANGE, SAMPLE)") - } - q.Streaming_sample_int = uint64(*streaming_sample_int)*uint64(time.Second) - if *queryType == "streaming" || *queryType == "s" { - q.Heartbeat_int = uint64(*heartbeat_int)*uint64(time.Second) - } else if *heartbeat_int > 0 { - return errors.New("-heartbeat_interval only valid with streaming query type") - } - q.Suppress_redundant = bool(*suppress_redundant) - for _, path := range *queryFlag { - query, err := parseQuery(path, cfg.Delimiter) - if err != nil { - return fmt.Errorf("invalid query %q : %v", path, err) - } - q.Queries = append(q.Queries, query) - } - return cli.QueryDisplay(ctx, q, &cfg) -} - -func readCredentials() (*client.Credentials, error) { - c := &client.Credentials{} - - fmt.Print("username: ") - _, err := fmt.Scan(&c.Username) - if err != nil { - return nil, err - } - - fmt.Print("password: ") - pass, err := terminal.ReadPassword(int(os.Stdin.Fd())) - if err != nil { - return nil, err - } - c.Password = string(pass) - - return c, nil -} - -func parseQuery(query, delim string) ([]string, error) { - d, w := utf8.DecodeRuneInString(delim) - if w == 0 || w != len(delim) { - return nil, fmt.Errorf("delimiter must be single UTF-8 codepoint: %q", delim) - } - // Ignore leading and trailing delimters. - query = strings.Trim(query, delim) - // Split path on delimeter with contextually aware key/value handling. - var buf []rune - inKey := false - null := rune(0) - for _, r := range query { - switch r { - case '[': - if inKey { - return nil, fmt.Errorf("malformed query, nested '[': %q ", query) - } - inKey = true - case ']': - if !inKey { - return nil, fmt.Errorf("malformed query, unmatched ']': %q", query) - } - inKey = false - case d: - if !inKey { - buf = append(buf, null) - continue - } - } - buf = append(buf, r) - } - if inKey { - return nil, fmt.Errorf("malformed query, missing trailing ']': %q", query) - } - return strings.Split(string(buf), string(null)), nil -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_cli/gnmi_cli_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_cli/gnmi_cli_test.go deleted file mode 100644 index 32959174b..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_cli/gnmi_cli_test.go +++ /dev/null @@ -1,66 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 main - -import ( - "reflect" - "testing" -) - -func TestParseQuery(t *testing.T) { - tests := []struct { - name string - input string - delim string - output []string - err bool - }{ - {name: "Invalid delimiter", delim: "ab", err: true}, - {name: "Dot delimiter", input: "a.b", delim: ".", output: []string{"a", "b"}}, - {name: "Leading delimiter", input: "/foo", delim: "/", output: []string{"foo"}}, - {name: "Trailing delimiter", input: "foo/", delim: "/", output: []string{"foo"}}, - {name: "Leading and trailing delimiter", input: "/foo/", delim: "/", output: []string{"foo"}}, - {name: "No leading and trailing delimiter", input: "foo", delim: "/", output: []string{"foo"}}, - {name: "Leading delimiter multi", input: "/foo/bar", delim: "/", output: []string{"foo", "bar"}}, - {name: "Trailing delimiter multi", input: "foo/bar/", delim: "/", output: []string{"foo", "bar"}}, - {name: "Leading and trailing delimiter multi", input: "/foo/bar/", delim: "/", output: []string{"foo", "bar"}}, - {name: "No leading and trailing delimiter multi", input: "foo/bar", delim: "/", output: []string{"foo", "bar"}}, - {name: "Key value", input: "foo[key=value]/bar", delim: "/", output: []string{"foo[key=value]", "bar"}}, - {name: "Key value contains delimiter", input: "foo[key=a/b]/bar", delim: "/", output: []string{"foo[key=a/b]", "bar"}}, - {name: "Multiple key value contains delimiter", input: "foo[key=a/b]/bar[key=c/d]/blah", delim: "/", output: []string{"foo[key=a/b]", "bar[key=c/d]", "blah"}}, - {name: "Missing [ for key value", input: "fookey=a/b]/bar", err: true}, - {name: "Missing ] for key value", input: "foo[key=a/b/bar", err: true}, - {name: "Nested [] for key value", input: "foo[key=[nest]]/bar", err: true}, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got, err := parseQuery(test.input, test.delim) - switch { - case test.err && err != nil: - return - case test.err && err == nil: - t.Errorf("parseQuery(%q): want error, got nil", test.input) - case err != nil: - t.Errorf("parseQuery(%q): got error %v, want nil", test.input, err) - default: - if !reflect.DeepEqual(got, test.output) { - t.Errorf("parseQuery(%q): got %q, want %q", test.input, got, test.output) - } - } - }) - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/Dockerfile b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/Dockerfile deleted file mode 100644 index 9b5af4e4f..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2018 Google Inc. -# 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. - -# Build a simple Docker image with supervisord which runs the gnmi_collector -# binary. - -FROM alpine:3.7 -RUN apk update && apk add -u python py-pip -RUN pip install supervisor -ADD supervisord.conf /etc/supervisord.conf -ADD gnmi_collector / - -ENTRYPOINT ["supervisord", "--nodaemon", "--configuration", "/etc/supervisord.conf"] - diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/README.md b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/README.md deleted file mode 100644 index a577cdb29..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# gNMI Collector Docker Image - -This directory contains the files required to build a Docker image for the gNMI -collector. - -This is not an official Google product. - -## Launching the Docker Image - -To run the gNMI collector simply execute `run.sh` on a system running the Docker -daemon. By default: - - * The collector listens on tcp/8888 for connections. It can be connected to - using the gnmi_cli command-line tool. - * The configuration within the `config` directory (`example.cfg`) is used for - the collector. This file is a textproto whose format is defined by the - protobuf in `proto/target/target.proto` within this repository. - * The SSL certificate (`cert.pem`, `key.pem` within the `config` directory) are - used for the collector instance. For use of this image anywhere else other - than for testing, this certificate should be regenerated. - -## Building Docker Image - -To rebuild the `gnmi_collector` binary, and rebuild the Docker image, execute -the `build.sh` script. - -## Image on Docker Hub - -This image can be pulled from Docker Hub using: - -``` -docker pull openconfig/gnmi_collector -``` diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/build.sh b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/build.sh deleted file mode 100755 index 9debb4253..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/build.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -# Copyright 2018 Google Inc. -# 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. - -# This file builds a simple docker image for the gnmi_collector -# based on Alpine Linux. - -(cd $GOPATH/src/github.com/openconfig/gnmi/cmd/gnmi_collector && CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo .) -cp $GOPATH/src/github.com/openconfig/gnmi/cmd/gnmi_collector/gnmi_collector . -docker build -t gnmi_collector -f Dockerfile . diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/config/cert.pem b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/config/cert.pem deleted file mode 100644 index 7f357c630..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/config/cert.pem +++ /dev/null @@ -1,31 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIFYDCCA0igAwIBAgIJAIahRoMjmR+WMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV -BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX -aWRnaXRzIFB0eSBMdGQwHhcNMTgwNjE5MDYxODEyWhcNMTkwNjE5MDYxODEyWjBF -MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50 -ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIIC -CgKCAgEA16i9MxwEK7St9wHig+6FPaaDNP4hWZ47BTZWZqWE8DEC1ky+TOSmCQbD -YzNcVuK0wLrwtxOWg7YcSU/ebiCQlAz0jgkvfAUpr0b0F59Q6UyJoPHTYQsHHBVr -c+vFB72gZ7ut9DcbdqtOyE7w8ftIm7H6MFZdRHcJ9gDY/zNN+IRLMsXyMqpDgLW1 -vEYm0vsJYaVhdhBVXjsz/mM/04gYlE9I4boUgvZmQ1OGGSligFjxZiFLM9zxMvGN -+Hm/MEdB4/2dk1Z+fsJ3wKlm7TZ2NsfHx7QXKgYmnbiUlF6hXjcXagxplB0vbufy -A2cHMYAgEkKja+Ymyqj7c0xVWzgbgK2XeUnhRfRkf5y6yLvpUSBs2GuAVaWVvlB6 -Ds8UGkRljFXY7F9+HmrXX2dAPY0wpT/x1EjbJLCm1hx0zfMD+TaDF8kqclcIFG1P -6rtijR3OaHycUj+HwqKe5rjvF0fjNngWYTIE3A9hEoQOCbVcFmTYL8Ri9GUq4o5J -Ri3kVGKeeqTdvbR+PtcVxeDa8i9V8Tlp38ldCDbfWiI0jxwEg8oKLT8Yvd7RGdTe -k7iLTGRHd47/VkZmZv0ltoAcI+mN4d4Dd0yDBuu9G6gp4JKUce/jTI+jVG2PsW2O -c1INFaXx3cbxuZqG6qVSmMYUprbA31HOqGJ6GTjGhgzjbErIezcCAwEAAaNTMFEw -HQYDVR0OBBYEFJ9cI4MTGf/W57cqv/l7RHz7jvfSMB8GA1UdIwQYMBaAFJ9cI4MT -Gf/W57cqv/l7RHz7jvfSMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQAD -ggIBAD4PpicahaNGos8lYMGHopGZMztWaUfJ4jmwi1ckJmfYpXIpzd8Jz9JjfgXU -BKSi8SoHKDpnHcNGJ1yO2FF4aggcOILY6bx/WBNnSHF3sT0fbFH6753vVEqbCv8R -MvQ1kDR7rsge6Q34WLXRgypO80MqHtLKJKrXlFuxHazRwvqRms2p15SaL82U7kHS -382TCKCJwxp7l5lqVuYZ7z9dTDa3zvEUh4Q5CzaCpePs8PjKL10L8lshpF48Js+Q -s3sgsyekEKGQ1gQgrZKmy7AaFXhwqFdtJft0F1L56cOGV6dV6GoVbxknOSEexuOh -0WVz3JcnOIjpNWFNPTdOUMRMOKYeT1ZCIOu1A/qZIMpNFUaXE9kIfvivCkAh0N+R -Du4xvxJSEQsPm5GxVvxy5Xms31O3MOh5COWb78TyNhHkSaDwEVJS72/YEAzMGrzq -jb76RthMkdxs6kZvyfuh/Q7E7WA4DI5gUKFWmigyDAngyJ1tSQ2vet/6PBPa/bMC -woZS5WHdxSCoTaeG9iSkxDZwT/VplBC6l8FZrM7W8bQqfP31eEGyd5lB3C6I6D/A -9Xvcx7rQjOKj6zKh+Ecwse3SRTwl1BErALMWx194he1r0nK4FskYenNJ63fyAaxv -/APDkxNzWZysIVU01xPHKGviinCCeAa4+apFMVyP6mD6oQ8i ------END CERTIFICATE----- diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/config/example.cfg b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/config/example.cfg deleted file mode 100644 index b288174b3..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/config/example.cfg +++ /dev/null @@ -1,28 +0,0 @@ -request: < - key: "interfaces" - value: < - subscribe: < - prefix: < - origin: "openconfig" - > - subscription: < - path: < - elem: < - name: "interfaces" - > - > - > - > - > -> -target: < - key: "target1" - value: < - address: "192.0.2.1:10162" - request: "interfaces" - credentials: < - username: "username" - password: "password" - > - > -> diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/config/key.pem b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/config/key.pem deleted file mode 100644 index 28d339a0e..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/config/key.pem +++ /dev/null @@ -1,52 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIJRAIBADANBgkqhkiG9w0BAQEFAASCCS4wggkqAgEAAoICAQDXqL0zHAQrtK33 -AeKD7oU9poM0/iFZnjsFNlZmpYTwMQLWTL5M5KYJBsNjM1xW4rTAuvC3E5aDthxJ -T95uIJCUDPSOCS98BSmvRvQXn1DpTImg8dNhCwccFWtz68UHvaBnu630Nxt2q07I -TvDx+0ibsfowVl1Edwn2ANj/M034hEsyxfIyqkOAtbW8RibS+wlhpWF2EFVeOzP+ -Yz/TiBiUT0jhuhSC9mZDU4YZKWKAWPFmIUsz3PEy8Y34eb8wR0Hj/Z2TVn5+wnfA -qWbtNnY2x8fHtBcqBiaduJSUXqFeNxdqDGmUHS9u5/IDZwcxgCASQqNr5ibKqPtz -TFVbOBuArZd5SeFF9GR/nLrIu+lRIGzYa4BVpZW+UHoOzxQaRGWMVdjsX34eatdf -Z0A9jTClP/HUSNsksKbWHHTN8wP5NoMXySpyVwgUbU/qu2KNHc5ofJxSP4fCop7m -uO8XR+M2eBZhMgTcD2EShA4JtVwWZNgvxGL0ZSrijklGLeRUYp56pN29tH4+1xXF -4NryL1XxOWnfyV0INt9aIjSPHASDygotPxi93tEZ1N6TuItMZEd3jv9WRmZm/SW2 -gBwj6Y3h3gN3TIMG670bqCngkpRx7+NMj6NUbY+xbY5zUg0VpfHdxvG5mobqpVKY -xhSmtsDfUc6oYnoZOMaGDONsSsh7NwIDAQABAoICAQDRNZ+9qisdnxy4p/pvlH9r -jFJyoSoHP2nwJ4Nv9phdTp56+F4QSCwOS6JWZOfqXemNooyMfhMg2RTdxf55BVxc -U6kW9TA8duG2aPW4yNP8T0SgfphZ5xHRm7Hu9cThOoMWvsoFRUR+PbeiuHojtWr9 -p42XQOEf3v8pyC66e7HjKautqLvJjMUJYr3X1JIrUF8MfBxtJXE7heFtoiiz864s -ijGg0Ry+43vXSnqnhC9LZX1hX2EOAgN3MUBR0QG5OxdfrpQj79+s5si3fV8dNh0+ -DVbwk/N40Bi8Huj8ekS/GmC7fykZB6sRQy/TPyqKScpTDJRuwwnUxlOQyXdwk6CQ -z2bgN4iMpSiMlS1nbtDJOqLLwjWYgDeahRFJLaCJYXK54IlhC76q+xvsoH7hH7w9 -fDsdSiOBP7jPDBMQrvolaff5wQ13yVKuWKJeScqTfcDeyTogDB2dIT/lVhqQ/L3w -m5Byd7GgDSvXWpKVqZtyFTa4wkhEUyBQwNgpLqw4yVT4oUO2/0vvSE6PHcX4PBgF -b5t+2Xhh3Un5aCLoKuDMsr3oweHlZ+C4RaH5ShiMYmlssPch9tpdAwDzjL4dZew2 -95GV64PVNOESrMkQbHbtCXLOn5mffECQNufUERoZwf4r0VFwcF1Hg0EDE8zr6kfJ -CxZgEMP66vGm5W0Fi2PvYQKCAQEA7oZf6szL5FH+93bvZqosNBzbqicIEESCiECb -+2EZiirV136/0JCG7+HiE/BdQXftJJyx4DsBp9bYfjFB4w1W+tr01GZY5XEMjM6e -gNPc9vQbl7BDF3dvweCCMHvJ+IgXJJlLols/kl0ENQiGFoNIEgU7cbt5S/SZRbZ1 -xmcOoXhLNJcOg+twU+PXNWRzoJcVNxtnGHP9Zw71Nenk+rarm9KMlmEinr+sisPX -v3q19krL6joPH6cmVB8KP3onvjqx0ka0l4p/a9b2bIw5m+2T7VBQAGKQAxxvV9dh -9AnCZTNLOm1DYEvVMNI5QkbfUL39+f6ci/I5TXDKH8klM6HbEQKCAQEA53WCHjpx -ai/l2PiIYIY50cwOylrd1mMQfkrkDkBZWWi0Gs8uWosCXh7ngnMVFhPaRUumTrUB -Vrw5mFgi294mfJeoH8kTsc30gfgp6MX8BA+0AumlaqpSEbDt68qXLlV/82Ok2geZ -/Rc8j4tTW1L9ojKK0lFhoOoWTUj0LF99Y1JuDSz9TU26UWsvXTF2SmvCkwsdz37b -7V2yhwmESvnDLfgfMTNfDaV06hnWLo4TOPxGhIe9TvB9lNlOitYnPNzHCmsdcC1X -7iuz9O3/l1UZzcMA7kvS8LizAVozwTpivB/JqcglagQITljg9Ysn2/XDprqE9DXz -UuawVEfqWxohxwKCAQEAzGAC65LS2S2Qw8T62ALToUtgxGhxNk8dcVW60Sef1I1j -cSO/gxtzIzNunRsFLMVvQkGo/7JPdtpV4bqe88dIUeUuhpezb9Tvpe6cTVI7MLZ0 -tgJnWkISVhLiOly27+bbvZZEAjchP23H3xEQo1WVeStWhdrW0cghVGREgd1n4d7K -waL04v/m3VqJ2cvaby1FFlS6f29THuzoGmvwsQm3/OnpYCiWm2MsmjG4OO8R3pi0 -JFve/YYhB08ZXs5yI0LzfnLq5jXbfDFSMCvuaLamW17HTa0mLCQ/GwsHeSyrjj7n -JIbehjIz14MpYKqNSgehCIWq6RaBFuOfrKCS6ayzoQKCAQEAptQOvkT3nEb7z2CL -w67bm/kNrBLElJMAv1axfAgrnoMWVcCBM6fARCDYUzEpwKj8iTfWniJe3ap7hO/5 -6Cn96Y3SE172QBEnrEo3wtx5ImBDKlpH7VLoJnI1et+iCjZ8K+zlVHVoK4EFGJ2e -rlNqFu+BGcioqrgu7POpcxY8pUszoXGM/ZwJsEemcvCEx21WaG/5w6Y3VKZVWHmm -jffqE4ckzGyvlYFtfJK0yweCmW9UUJAaBfzXN2NN9koXLAohuMOuCz3ThAqiAedN -c0FWgPWOBTRHzVQDSfU/GoY/xkLPMv3c4cYYSohLVRBA4Y0JwXHtBKyiPl2iOI1B -QPrb3wKCAQAhqoqz1O0ALJSXpcU7TxbmkCGKrntByS8fAczXcCzgz6ynbhP3EX0S -rGN75dNsnOiA0Zjuj43C32Ldr/pTkNW585RwWF/CZILCJfsiqM9qlnWOQhemC5DC -6+OZbcQfhmDNrI/6ee+Af2l0td7KmX1ARanfhXz0jNveV1gU8l9YmbuqFPb98BBf -PX0UymTwYe8aWUh0VTRaL+2sJcQmlxrtKrYVii9Zcfx8f/AEM2PDf06NGnd4ric8 -VL3H5Cxo0Nrsf/JyKsC+ocs0yrqJqlcs7087Ou/KwVdTpTw0kMDSToM8pYDhujpc -FPoKEpZNSeG9PhdCnycaJnEDPOkja+nP ------END PRIVATE KEY----- diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/run.sh b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/run.sh deleted file mode 100755 index 991153d61..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/run.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# Copyright 2017 Google Inc. -# 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. - -# This file launches a Docker image of the gNMI collector. It uses -# the configuration stored in the "config" directory (example.cfg) -# and the certificate files stored in this directory. The collector -# listens on tcp/8888 which is forwarded to the host. - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -docker run -d -v $DIR/config:/config -p 8888:8888 openconfig/gnmi_collector diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/supervisord.conf b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/supervisord.conf deleted file mode 100644 index 96b91c796..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/docker/supervisord.conf +++ /dev/null @@ -1,17 +0,0 @@ -[supervisord] -logfile=/var/log/supervisord.log ; supervisord log file -logfile_maxbytes=50MB ; maximum size of logfile before rotation -logfile_backups=10 ; number of backed up logfiles -loglevel=error ; info, debug, warn, trace -pidfile=/var/run/supervisord.pid ; pidfile location -nodaemon=true ; do not daemonize -minfds=1024 ; number of startup file descriptors -minprocs=200 ; number of process descriptors -user=root ; default user -childlogdir=/var/log/ ; where child log files will live - -[program:collector] -command = /gnmi_collector -config_file /config/example.cfg -cert_file /config/cert.pem -key_file /config/key.pem -port 8888 -alsologtostderr -startsecs=10 -startretries=10 -autorestart=true diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/gnmi_collector.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/gnmi_collector.go deleted file mode 100644 index c40e7385f..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/gnmi_collector.go +++ /dev/null @@ -1,228 +0,0 @@ -/* -Copyright 2018 Google Inc. - -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. -*/ - -// The gnmi_collector program implements a caching gNMI collector. -package main - -import ( - "context" - "crypto/tls" - "errors" - "flag" - "fmt" - "io/ioutil" - "net" - "time" - - - log "github.com/golang/glog" - "github.com/golang/protobuf/proto" - "google.golang.org/grpc/credentials" - "google.golang.org/grpc" - "github.com/openconfig/gnmi/cache" - "github.com/openconfig/gnmi/client" - gnmiclient "github.com/openconfig/gnmi/client/gnmi" - "github.com/openconfig/gnmi/subscribe" - "github.com/openconfig/gnmi/target" - - gnmipb "github.com/openconfig/gnmi/proto/gnmi" - targetpb "github.com/openconfig/gnmi/proto/target" -) - -var ( - configFile = flag.String("config_file", "", "File path for collector configuration.") - certFile = flag.String("cert_file", "", "File path for TLS certificate.") - keyFile = flag.String("key_file", "", "File path for TLS key.") - port = flag.Int("port", 0, "server port") - dialTimeout = flag.Duration("dial_timeout", time.Minute, "Timeout for dialing a connection to a target.") - metadataUpdatePeriod = flag.Duration("metadata_update_period", 0, "Period for target metadata update. 0 disables updates.") - sizeUpdatePeriod = flag.Duration("size_update_period", 0, "Period for updating the target size in metadata. 0 disables updates.") -) - -func periodic(period time.Duration, fn func()) { - if period == 0 { - return - } - t := time.NewTicker(period) - defer t.Stop() - for range t.C { - fn() - } -} - -// Under normal conditions, this function will not terminate. Cancelling -// the context will stop the collector. -func runCollector(ctx context.Context) error { - if *configFile == "" { - return errors.New("config_file must be specified") - } - if *certFile == "" { - return errors.New("cert_file must be specified") - } - if *keyFile == "" { - return errors.New("key_file must be specified") - } - - c := collector{config: &targetpb.Configuration{}} - // Initialize configuration. - buf, err := ioutil.ReadFile(*configFile) - if err != nil { - return fmt.Errorf("Could not read configuration from %q: %v", *configFile, err) - } - if err := proto.UnmarshalText(string(buf), c.config); err != nil { - return fmt.Errorf("Could not parse configuration from %q: %v", *configFile, err) - } - if err := target.Validate(c.config); err != nil { - return fmt.Errorf("Configuration in %q is invalid: %v", *configFile, err) - } - - // Initialize TLS credentials. - creds, err := credentials.NewServerTLSFromFile(*certFile, *keyFile) - if err != nil { - return fmt.Errorf("Failed to generate credentials %v", err) - } - - // Initialize cache. - cache.Type = cache.GnmiNoti - c.cache = cache.New(nil) - - // Start functions to periodically update metadata stored in the cache for each target. - go periodic(*metadataUpdatePeriod, c.cache.UpdateMetadata) - go periodic(*sizeUpdatePeriod, c.cache.UpdateSize) - - // Initialize collectors. - c.start(context.Background()) - - // Create a grpc Server. - srv := grpc.NewServer(grpc.Creds(creds)) - // Initialize gNMI Proxy Subscribe server. - subscribeSrv, err := subscribe.NewServer(c.cache) - if err != nil { - return fmt.Errorf("Could not instantiate gNMI server: %v", err) - } - gnmipb.RegisterGNMIServer(srv, subscribeSrv) - // Forward streaming updates to clients. - c.cache.SetClient(subscribeSrv.Update) - // Register listening port and start serving. - lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) - if err != nil { - return fmt.Errorf("failed to listen: %v", err) - } - go srv.Serve(lis) - defer srv.Stop() - <-ctx.Done() - return ctx.Err() -} - -// Container for some of the target state data. It is created once -// for every device and used as a closure parameter by ProtoHandler. -type state struct { - name string - target *cache.Target - // connected status is set to true when the first gnmi notification is received. - // it gets reset to false when disconnect call back of ReconnectClient is called. - connected bool -} - -func (s *state) disconnect() { - s.connected = false - s.target.Reset() -} - -// handleUpdate parses a protobuf message received from the target. This implementation handles only -// gNMI SubscribeResponse messages. When the message is an Update, the GnmiUpdate method of the -// cache.Target is called to generate an update. If the message is a sync_response, then target is -// marked as synchronised. -func (s *state) handleUpdate(msg proto.Message) error { - if !s.connected { - s.target.Connect() - s.connected = true - } - resp, ok := msg.(*gnmipb.SubscribeResponse) - if !ok { - return fmt.Errorf("failed to type assert message %#v", msg) - } - switch v := resp.Response.(type) { - case *gnmipb.SubscribeResponse_Update: - // Gracefully handle gNMI implementations that do not set Prefix.Target in their - // SubscribeResponse Updates. - if v.Update.GetPrefix() == nil { - v.Update.Prefix = &gnmipb.Path{} - } - if v.Update.Prefix.Target == "" { - v.Update.Prefix.Target = s.name - } - s.target.GnmiUpdate(v.Update) - case *gnmipb.SubscribeResponse_SyncResponse: - s.target.Sync() - case *gnmipb.SubscribeResponse_Error: - return fmt.Errorf("error in response: %s", v) - default: - return fmt.Errorf("unknown response %T: %s", v, v) - } - return nil -} - -type collector struct { - cache *cache.Cache - config *targetpb.Configuration -} - -func (c *collector) start(ctx context.Context) { - for name, target := range c.config.Target { - go func(name string, target *targetpb.Target) { - s := &state{name: name, target: c.cache.Add(name)} - qr := c.config.Request[target.Request] - q, err := client.NewQuery(qr) - if err != nil { - log.Errorf("NewQuery(%s): %v", qr.String(), err) - return - } - q.Addrs = target.Addresses - - if target.Credentials != nil { - q.Credentials = &client.Credentials{ - Username: target.Credentials.Username, - Password: target.Credentials.Password, - } - } - - // TLS is always enabled for a target. - q.TLS = &tls.Config{ - // Today, we assume that we should not verify the certificate from the target. - InsecureSkipVerify: true, - } - - q.Target = name - q.Timeout = *dialTimeout - q.ProtoHandler = s.handleUpdate - if err := q.Validate(); err != nil { - log.Errorf("query.Validate(): %v", err) - return - } - cl := client.Reconnect(&client.BaseClient{}, s.disconnect, nil) - if err := cl.Subscribe(ctx, q, gnmiclient.Type); err != nil { - log.Errorf("Subscribe failed for target %q: %v", name, err) - } - }(name, target) - } -} - -func main() { - // Flag initialization. - flag.Parse() - log.Exit(runCollector(context.Background())) -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/gnmi_collector_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/gnmi_collector_test.go deleted file mode 100644 index 287f0b23e..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/gnmi_collector_test.go +++ /dev/null @@ -1,113 +0,0 @@ -/* -Copyright 2018 Google Inc. - -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 main - -import ( - "context" - "path/filepath" - "testing" - "time" -) - -func TestErrorsRunCollector(t *testing.T) { - tests := []struct { - desc, config, cert, key string - valid bool - }{{ - desc: "valid config, cert and key", - config: "good.cfg", - cert: "good.crt", - key: "good.key", - valid: true, - }, { - desc: "empty config name", - cert: "good.crt", - key: "good.key", - }, { - desc: "unparseable config", - config: "unparseable.cfg", - cert: "good.crt", - key: "good.key", - }, { - desc: "invalid config", - config: "bad.cfg", - cert: "good.crt", - key: "good.key", - }, { - desc: "missing config", - config: "missing.cfg", - cert: "good.crt", - key: "good.key", - }, { - desc: "empty cert name", - config: "good.cfg", - key: "good.key", - }, { - desc: "invalid cert", - config: "good.cfg", - cert: "bad.crt", - key: "good.key", - }, { - desc: "missing cert", - config: "good.cfg", - cert: "missing.crt", - key: "good.key", - }, { - desc: "empty key name", - config: "good.cfg", - cert: "good.crt", - }, { - desc: "invalid key", - config: "good.cfg", - cert: "good.crt", - key: "bad.key", - }, { - key: "missing.key", - config: "good.cfg", - cert: "good.crt", - desc: "missing key", - }} - for _, test := range tests { - t.Run(test.desc, func(t *testing.T) { - if test.config != "" { - *configFile = filepath.Join("testdata", test.config) - defer func() { *configFile = "" }() - } - if test.cert != "" { - *certFile = filepath.Join("testdata", test.cert) - defer func() { *certFile = "" }() - } - if test.key != "" { - *keyFile = filepath.Join("testdata", test.key) - defer func() { *keyFile = "" }() - } - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - defer cancel() - err := runCollector(ctx) - t.Logf("runCollector(ctx) : %v", err) - if test.valid { - if err != context.DeadlineExceeded { - t.Errorf("got %v, want %v", err, context.DeadlineExceeded) - } - } else { - if err == nil { - t.Error("got nil error, wanted error") - } - } - }) - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/bad.cfg b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/bad.cfg deleted file mode 100644 index c12778997..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/bad.cfg +++ /dev/null @@ -1,28 +0,0 @@ -request: < - key: "interfaces" - value: < - subscribe: < - prefix: < - origin: "openconfig" - > - subscription: < - path: < - elem: < - name: "interfaces" - > - > - > - > - > -> -target: < - key: "target1" - value: < - addresses: "127.0.0.1:9998" - request: "protocols" - credentials: < - username: "username" - password: "password" - > - > -> diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/bad.crt b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/bad.crt deleted file mode 100644 index dfdadf19d..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/bad.crt +++ /dev/null @@ -1,11 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIEADCCAuigAwIBAgIJAOZpdHfZp2BmMA0GCSqGSIb3DQEBCwUAMIGUMQswCQYD -VQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTESMBAGA1UEBwwJU3Vubnl2YWxl -MQ8wDQYDVQQKDAZHb29nbGUxEzARBgNVBAsMCk5ldHdvcmtpbmcxFzAVBgNVBAMM -DmNzbEBnb29nbGUuY29tMR0wGwYJKoZIhvcNAQkBFg5jc2xAZ29vZ2xlLmNvbTAe -Fw0xODA2MTUyMjUyMTJaFw0xOTA2MTUyMjUyMTJaMIGUMQswCQYDVQQGEwJVUzET -MBEGA1UECAwKQ2FsaWZvcm5pYTESMBAGA1UEBwwJU3Vubnl2YWxlMQ8wDQYDVQQK -DAZHb29nbGUxEzARBgNVBAsMCk5ldHdvcmtpbmcxFzAVBgNVBAMMDmNzbEBnb29n -bGUuY29tMR0wGwYJKoZIhvcNAQkBFg5jc2xAZ29vZ2xlLmNvbTCCASIwDQYJKoZI -hvcNAQEBBQADggEPADCCAQoCggEBAMC7FFKUBder3aOCs5FJyTAcVjaJv7ATdhPX -Pvdzdx8D85mhwz93cGWNhhybp37Kjwb0FxkiEcmv+wKTZWCNqYL3KL3qjqsW/1u8 diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/bad.key b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/bad.key deleted file mode 100644 index 83d45f1e9..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/bad.key +++ /dev/null @@ -1,12 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAuxRSlAXXq92j -grORSckwHFY2ib+wE3YT1z73c3cfA/OZocM/d3BljYYcm6d+yo8G9BcZIhHJr/sC -k2VgjamC9yi96o6rFv9bvPstE1/aJiwAyKw3Ii+lC4l8l03BooN9esDoe33ckgMw -XF8xke4qv0vgSnhbFYyzb0cTiTYE5ua56Ivf/vvHzhrDcXrBMBlweDsPv9A+fZl3 -U13IAahHvN65EIhlWFZMdZ8XIrhy76bXqRQUn2+xF27RqPvBP72xFJ/VRBMmUy9d -bPDklJR5ntLIIoDRMPz8FDqNxLKC5dLGg3Q6tdeki46O9NMekqrnNzzuN5l9MEI5 -4kfHdf91AgMBAAECggEBALZHeZYMV2Y+LxY5RFnR/kzZUBSuvTPrhA6J0gy5EN2t -oBQacQ4yiYQSkNe3w3dgXluGOd5UYZxuKympfAUQllS+K7NLBvn7ezIpjyl3nH03 -AwEOygou8/7V5YeHlkvfxxrDIXX/be9RzWBMzN+WFDoryLht1lzXCcafJQruB8Aj -djw/4xa+N64+PoNFDqu/a2xBoYJq44xBYx55e9E0PSFN8Dy+eWkNKpUR647uLjMI -CWWi5i45wXtRvqhZ6aVyTbOmSh6NMW3tnEMoCQMYt0GAJn8nlo3jfqVr7lruwzE1 diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/good.cfg b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/good.cfg deleted file mode 100644 index 77ce0ee13..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/good.cfg +++ /dev/null @@ -1,28 +0,0 @@ -request: < - key: "interfaces" - value: < - subscribe: < - prefix: < - origin: "openconfig" - > - subscription: < - path: < - elem: < - name: "interfaces" - > - > - > - > - > -> -target: < - key: "target1" - value: < - addresses: "127.0.0.1:9998" - request: "interfaces" - credentials: < - username: "username" - password: "password" - > - > -> diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/good.crt b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/good.crt deleted file mode 100644 index f6f15027c..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/good.crt +++ /dev/null @@ -1,24 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIEADCCAuigAwIBAgIJAOZpdHfZp2BmMA0GCSqGSIb3DQEBCwUAMIGUMQswCQYD -VQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTESMBAGA1UEBwwJU3Vubnl2YWxl -MQ8wDQYDVQQKDAZHb29nbGUxEzARBgNVBAsMCk5ldHdvcmtpbmcxFzAVBgNVBAMM -DmNzbEBnb29nbGUuY29tMR0wGwYJKoZIhvcNAQkBFg5jc2xAZ29vZ2xlLmNvbTAe -Fw0xODA2MTUyMjUyMTJaFw0xOTA2MTUyMjUyMTJaMIGUMQswCQYDVQQGEwJVUzET -MBEGA1UECAwKQ2FsaWZvcm5pYTESMBAGA1UEBwwJU3Vubnl2YWxlMQ8wDQYDVQQK -DAZHb29nbGUxEzARBgNVBAsMCk5ldHdvcmtpbmcxFzAVBgNVBAMMDmNzbEBnb29n -bGUuY29tMR0wGwYJKoZIhvcNAQkBFg5jc2xAZ29vZ2xlLmNvbTCCASIwDQYJKoZI -hvcNAQEBBQADggEPADCCAQoCggEBAMC7FFKUBder3aOCs5FJyTAcVjaJv7ATdhPX -Pvdzdx8D85mhwz93cGWNhhybp37Kjwb0FxkiEcmv+wKTZWCNqYL3KL3qjqsW/1u8 -+y0TX9omLADIrDciL6ULiXyXTcGig316wOh7fdySAzBcXzGR7iq/S+BKeFsVjLNv -RxOJNgTm5rnoi9/++8fOGsNxesEwGXB4Ow+/0D59mXdTXcgBqEe83rkQiGVYVkx1 -nxciuHLvptepFBSfb7EXbtGo+8E/vbEUn9VEEyZTL11s8OSUlHme0sgigNEw/PwU -Oo3EsoLl0saDdDq116SLjo700x6Squc3PO43mX0wQjniR8d1/3UCAwEAAaNTMFEw -HQYDVR0OBBYEFDrZ1HErw89GWWW9RDCuhdtywcr1MB8GA1UdIwQYMBaAFDrZ1HEr -w89GWWW9RDCuhdtywcr1MA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQAD -ggEBAFxmRzjeM469YXHL5byt1gYEukSICDBwmFQKd3eoDOspPFPVC8+FF01X1OBq -3HbTssL2Tu1UxQtCdhkkqjvE4HWeat2vI/0pyXoUOWrblXAS2maF1roZuriJzJ/5 -dIY8tUlts8ZBKtbX4JjzI2Il/fB98Kv9+MTs9zQfHsRh0D9GUY+ZPFFIRYiGCwox -xOzI4ax8IsZ86yK0GpusWyw0WEOqReBRB5pBKHrUhze54nBWOUnuBook2n0EhMtp -IpNBAI0ABmlbwnamvpLbykVNUyj8CnYRm2jEVxqghid2fHRLHaw+pL9zQYPw3xCP -1L/kksDZ6KL2Y/R+BvqpYZ90Zzs= ------END CERTIFICATE----- diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/good.key b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/good.key deleted file mode 100644 index 948fd5376..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/good.key +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAuxRSlAXXq92j -grORSckwHFY2ib+wE3YT1z73c3cfA/OZocM/d3BljYYcm6d+yo8G9BcZIhHJr/sC -k2VgjamC9yi96o6rFv9bvPstE1/aJiwAyKw3Ii+lC4l8l03BooN9esDoe33ckgMw -XF8xke4qv0vgSnhbFYyzb0cTiTYE5ua56Ivf/vvHzhrDcXrBMBlweDsPv9A+fZl3 -U13IAahHvN65EIhlWFZMdZ8XIrhy76bXqRQUn2+xF27RqPvBP72xFJ/VRBMmUy9d -bPDklJR5ntLIIoDRMPz8FDqNxLKC5dLGg3Q6tdeki46O9NMekqrnNzzuN5l9MEI5 -4kfHdf91AgMBAAECggEBALZHeZYMV2Y+LxY5RFnR/kzZUBSuvTPrhA6J0gy5EN2t -oBQacQ4yiYQSkNe3w3dgXluGOd5UYZxuKympfAUQllS+K7NLBvn7ezIpjyl3nH03 -AwEOygou8/7V5YeHlkvfxxrDIXX/be9RzWBMzN+WFDoryLht1lzXCcafJQruB8Aj -djw/4xa+N64+PoNFDqu/a2xBoYJq44xBYx55e9E0PSFN8Dy+eWkNKpUR647uLjMI -CWWi5i45wXtRvqhZ6aVyTbOmSh6NMW3tnEMoCQMYt0GAJn8nlo3jfqVr7lruwzE1 -xWARwLhh5m836l30HaYAwbF1mtYj2Aj/UbomKrAbNXUCgYEA/Noq/Gxc2Ue+4m7Y -HtNbTjLNWN96FD0kYs6xfmVDMJQbSOFkFtZDE246Fu/9M9WfH73+jFVkHZGD4FcQ -9jw2OmemtDPOQhbFvyw35RT6OJ9AruXGElq0w7eQKluliDOH0FfQHq30NEOh7E+r -W/OIG3FgQx6EmGigWGmlt59A7hMCgYEAwyFOa5yVKQDa1YOfbTKzi532SwY61LYY -30xMzFrvAxz3dRy7LN0lGQdPIHt1+A5NcNPflk0aZ5M6c9W1AMCB8qT/0cfZS74f -O3afJS6X/7/awngJsn4xIpXKfvJcGejFG78yaGdKA0r64hAcOJ/i1WZOEnDH9s4c -y10pkKW9bVcCgYEAy0lUGhG9LGuESmQ3mcDvvZUWh4dUjQUDRfVLuoULWfkZXqTn -ZXzp/Ks4RMy503zCLDECgCz/Cs69KhaV6oJKTvaajnLAN147qhGQ9rrA2dkflf3i -G0uV3WytmYCJO1HCtXyENMZCeeqOOoFrEchf+0BR1mSo0if8ElkOBO0itMUCgYBC -SHAREfGBKi8r1Dg1qcFfrdraBVW6p9ivEYYM7N6/2fkdKRNT3BMb+2WfjRC3oHQh -3XbX4X0UrehvLKr9hGcf+3iC1DY2CnEli9fnk3pCf/NZl9kDbuZV7zgIA1/R1UYP -dNU0rdFwaOnsHLjZa0ZsYwImNXVXmxAg7JaP8hz0pQKBgQDDQehYCkTABhwn6PpS -hfW4R9rdPvj7UNHsK0pf8x9w+r0l04qM7y71hKCZ47kVNYNrDWCZfTvFyrMdHGT1 -8KPj4gSjvpuCU9pOKYGqwO5rOY04WJf9gtdlQrK5qNU2TFzIexyhTEkXb1+zbY/J -1KD4NaF9iYRfrMFjKSRzQoUanw== ------END PRIVATE KEY----- diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/unparseable.cfg b/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/unparseable.cfg deleted file mode 100644 index 6b2236550..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/cmd/gnmi_collector/testdata/unparseable.cfg +++ /dev/null @@ -1,29 +0,0 @@ -foo: "invalid message" -request: < - key: "interfaces" - value: < - subscribe: < - prefix: < - origin: "openconfig" - > - subscription: < - path: < - elem: < - name: "interfaces" - > - > - > - > - > -> -target: < - key: "target1" - value: < - addresses: "127.0.0.1:9998" - request: "interfaces" - credentials: < - username: "username" - password: "password" - > - > -> diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/coalesce/coalesce.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/coalesce/coalesce.go deleted file mode 100644 index eb280d439..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/coalesce/coalesce.go +++ /dev/null @@ -1,168 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 coalesce provides an in-order queue for collecting outputs from a -// producer to provide inputs to a consumer. Coalescing happens when an output -// has been produced more than once by the producer before being consumed. In -// this case the outputs are coalesced and delivered only once. -package coalesce - -import ( - "context" - "errors" - "sync" -) - -// Queue is a structure that implements in-order delivery of coalesced inputs. -// Operations on Queue are threadsafe and any number of producers may contribute -// to the queue and any number of consumers may receive, however, no fairness -// among consumers is guaranteed and it is possible for starvation to occur. -type Queue struct { - sync.Mutex - // inserted is used to signal blocked consumers that a value has been added. - inserted chan struct{} - // closed is a signal that no Inserts can occur and Next should return error - // for an empty queue. - closed chan struct{} - // coalesced tracks the number of values per interface that have been - // coalesced. - coalesced map[interface{}]uint32 - // queue is the in-order values transferred from producer to consumer. - queue []interface{} -} - -// NewQueue returns an initialized Queue ready for use. -func NewQueue() *Queue { - return &Queue{ - inserted: make(chan struct{}, 1), - closed: make(chan struct{}), - coalesced: make(map[interface{}]uint32), - } -} - -var errClosedQueue = errors.New("closed queue") - -// IsClosedQueue returns whether a given error is coalesce.errClosedQueue. -func IsClosedQueue(err error) bool { - return err == errClosedQueue -} - -// Insert adds i to the queue and returns true if i does not already exist. -// Insert returns an error if the Queue has been closed. -func (q *Queue) Insert(i interface{}) (bool, error) { - select { - case <-q.closed: - return false, errClosedQueue - default: - } - - ok := q.insert(i) - - if ok { - select { - case q.inserted <- struct{}{}: - default: - } - } - - return ok, nil -} - -func (q *Queue) insert(i interface{}) bool { - defer q.Unlock() - q.Lock() - - if _, ok := q.coalesced[i]; ok { - q.coalesced[i]++ - return false - } - q.queue = append(q.queue, i) - q.coalesced[i] = 0 - return true -} - -// Next returns the next item in the queue and the number of duplicates that -// were dropped, or an error if the Queue is empty and has been closed. Calls to -// Next are blocking. -func (q *Queue) Next(ctx context.Context) (interface{}, uint32, error) { - for { - i, coalesced, valid := q.next() - if valid { - return i, coalesced, nil - } - // Wait for an insert or a close. - select { - case <-ctx.Done(): - return nil, 0, ctx.Err() - case <-q.inserted: - case <-q.closed: - // Make sure all values are delivered. - if q.Len() == 0 { - return nil, 0, errClosedQueue - } - } - } -} - -// next returns the next item and the number of coalesced duplicates if there is -// an item to consume as indicated by the bool. If the bool is false, the -// caller has to option to block and try again or return an error. -func (q *Queue) next() (interface{}, uint32, bool) { - defer q.Unlock() - q.Lock() - if len(q.queue) == 0 { - return nil, 0, false - } - var i interface{} - i, q.queue = q.queue[0], q.queue[1:] - coalesced := q.coalesced[i] - delete(q.coalesced, i) - return i, coalesced, true -} - -// Len returns the current length of the queue, useful for reporting statistics. -// Since the queue is designed to be operated on by one or more producers and -// one or more consumers, this return value only indicates what the length was -// at the instant it was evaluated which may change before the caller gets the -// return value. -func (q *Queue) Len() int { - defer q.Unlock() - q.Lock() - return len(q.queue) -} - -// Close closes the queue for inserts. -func (q *Queue) Close() { - defer q.Unlock() - q.Lock() - // Avoid panic on closing the closed channel. - select { - case <-q.closed: - return - default: - close(q.closed) - } -} - -// IsClosed reports if the queue is in a closed state. -func (q *Queue) IsClosed() bool { - select { - case <-q.closed: - return true - default: - } - return false -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/coalesce/coalesce_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/coalesce/coalesce_test.go deleted file mode 100644 index a3647a01b..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/coalesce/coalesce_test.go +++ /dev/null @@ -1,146 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 coalesce - -import ( - "context" - "testing" -) - -func TestInsert(t *testing.T) { - q := NewQueue() - tests := []struct { - s string - want bool - size int - }{ - {"hello", true, 1}, - {"hello", false, 1}, - {"world", true, 2}, - {"hello", false, 2}, - {"world", false, 2}, - {"world", false, 2}, - {"!", true, 3}, - } - for x, tt := range tests { - if got, _ := q.Insert(tt.s); got != tt.want { - t.Errorf("#%d: q.Insert(%q): got %t, want %t", x, tt.s, got, tt.want) - } - if size := q.Len(); size != tt.size { - t.Errorf("#%d: got queue length %d, want %d", x, size, tt.size) - } - } -} - -func TestNext(t *testing.T) { - q := NewQueue() - type stringCount struct { - s string - count uint32 - } - tests := []struct { - s []string - want []stringCount - }{ - {[]string{"hello"}, []stringCount{{"hello", 0}}}, - {[]string{"hello", "hello", "hello"}, []stringCount{{"hello", 2}}}, - {[]string{"hello", "world", "hello"}, []stringCount{{"hello", 1}, {"world", 0}}}, - {[]string{"hello"}, []stringCount{{"hello", 0}}}, - } - for x, tt := range tests { - for _, s := range tt.s { - q.Insert(s) - } - for _, want := range tt.want { - i, count, err := q.Next(context.Background()) - if err != nil { - t.Errorf("#%d: q.Next() unexpected error %v", x, err) - continue - } - s, ok := i.(string) - if !ok { - t.Errorf("#%d: unable to cast to string %v", x, i) - continue - } - if s != want.s || count != want.count { - t.Errorf("#%d: q.Next(): got %q (%d) want %q (%d)", x, s, count, want.s, want.count) - } - } - } -} - -func TestNextCancelContext(t *testing.T) { - q := NewQueue() - start := make(chan struct{}) - done := make(chan struct{}) - ctx, cancel := context.WithCancel(context.Background()) - go func() { - close(start) - _, _, err := q.Next(ctx) - if err == nil { - t.Error("got nil error, want error") - } - close(done) - }() - <-start - cancel() - <-done -} - -func TestClose(t *testing.T) { - ctx := context.Background() - for _, tt := range [][]string{ - {}, - {"a"}, - {"a", "b"}, - {"a", "b", "c"}, - } { - q := NewQueue() - if q.IsClosed() { - t.Error("newly created queue IsClosed() got true, want false") - } - for _, s := range tt { - _, err := q.Insert(s) - if err != nil { - t.Fatal(err) - } - } - q.Close() - if !q.IsClosed() { - t.Error("closed queue IsClosed() got false, want true") - } - if _, err := q.Insert("foo"); !IsClosedQueue(err) { - t.Errorf("q.Insert() got %v, want %v", err, errClosedQueue) - } - for x, want := range tt { - i, _, err := q.Next(ctx) - got, ok := i.(string) - switch { - case err != nil: - t.Errorf("#%d: q.Next(): got error %v before result %q received.", x, err, want) - case !ok || got != want: - t.Errorf("#%d: q.Next(): got %q, want %q", x, got, want) - } - } - if _, _, err := q.Next(ctx); !IsClosedQueue(err) { - t.Errorf("q.Next(): got %v, want %v", err, errClosedQueue) - } - if _, err := q.Insert("foo"); !IsClosedQueue(err) { - t.Errorf("q.Insert() got %v, want %v", err, errClosedQueue) - } - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/compile_protos.sh b/src/gnmi_clients/src/github.com/openconfig/gnmi/compile_protos.sh deleted file mode 100755 index 8e966da9b..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/compile_protos.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh - -# Copyright 2017 Google Inc. -# -# 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. - -set -euo pipefail - -proto_imports=".:${GOPATH}/src/github.com/google/protobuf/src:${GOPATH}/src" - -# Go -protoc -I=$proto_imports --go_out=. testing/fake/proto/fake.proto -protoc -I=$proto_imports --go_out=plugins=grpc:. proto/gnmi/gnmi.proto -protoc -I=$proto_imports --go_out=plugins=grpc:. proto/gnmi_ext/gnmi_ext.proto -protoc -I=$proto_imports --go_out=. proto/target/target.proto - -# Python -python -m grpc_tools.protoc -I=$proto_imports --python_out=. --grpc_python_out=. testing/fake/proto/fake.proto -python -m grpc_tools.protoc -I=$proto_imports --python_out=. --grpc_python_out=. proto/gnmi_ext/gnmi_ext.proto -python -m grpc_tools.protoc -I=$proto_imports --python_out=. --grpc_python_out=. proto/gnmi_ext/gnmi_ext.proto -python -m grpc_tools.protoc -I=$proto_imports --python_out=. --grpc_python_out=. proto/target/target.proto diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/connection/connection.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/connection/connection.go deleted file mode 100644 index a75de139a..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/connection/connection.go +++ /dev/null @@ -1,158 +0,0 @@ -/* -Copyright 2019 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 connection manages cached client connections to gRPC servers. -package connection - -import ( - "context" - "errors" - "sync" - - log "github.com/golang/glog" - "google.golang.org/grpc" -) - -type connection struct { - id string - ref int - c *grpc.ClientConn // Set during dial attempt, before signaling ready. - err error // Set during dial attempt, before signaling ready. - ready chan struct{} -} - -// Manager provides functionality for creating cached client gRPC connections. -type Manager struct { - opts []grpc.DialOption - d Dial - - mu sync.Mutex - conns map[string]*connection -} - -// NewManager creates a new Manager. The opts arguments are used -// to dial new gRPC targets, with the same semantics as grpc.DialContext. -func NewManager(opts ...grpc.DialOption) (*Manager, error) { - return NewManagerCustom(grpc.DialContext, opts...) -} - -// Dial defines a function to dial the gRPC connection. -type Dial func(ctx context.Context, target string, opts ...grpc.DialOption) (conn *grpc.ClientConn, err error) - -// NewManagerCustom creates a new Manager. The opts arguments are used -// to dial new gRPC targets, using the provided Dial function. -func NewManagerCustom(d Dial, opts ...grpc.DialOption) (*Manager, error) { - if d == nil { - return nil, errors.New("nil Dial provided") - } - m := &Manager{} - m.conns = map[string]*connection{} - m.opts = opts - m.d = d - return m, nil -} - -// remove should be called while locking m. -func (m *Manager) remove(addr string) { - c, ok := m.conns[addr] - if !ok { - log.Errorf("Connection %q missing or already removed", addr) - } - delete(m.conns, addr) - if c.c != nil { - if err := c.c.Close(); err != nil { - log.Errorf("Error cleaning up connection %q: %v", addr, err) - } - } -} - -func (m *Manager) dial(ctx context.Context, addr string, c *connection) { - defer close(c.ready) - cc, err := m.d(ctx, addr, m.opts...) - if err != nil { - log.Infof("Error creating gRPC connection to %q: %v", addr, err) - m.mu.Lock() - m.remove(addr) - c.err = err - m.mu.Unlock() - return - } - - log.Infof("Created gRPC connection to %q", addr) - c.c = cc -} - -func (c *connection) done(m *Manager) func() { - var once sync.Once - fn := func() { - if c == nil { - log.Error("Attempted to call done on nil connection") - return - } - m.mu.Lock() - defer m.mu.Unlock() - c.ref-- - if c.ref <= 0 { - m.remove(c.id) - } - } - return func() { - once.Do(fn) - } -} - -func newConnection(addr string) *connection { - return &connection{ - id: addr, - ready: make(chan struct{}), - } -} - -// Connection creates a new grpc.ClientConn to the destination address or -// returns the existing connection, along with a done function. -// -// Usage is registered when a connection is retrieved using Connection. Clients -// should call the returned done function when the returned connection handle is -// unused. Subsequent calls to the same done function have no effect. If an -// error is returned, done has no effect. Connections with no usages will be -// immediately closed and removed from Manager. -// -// If there is already a pending connection attempt for the same addr, -// Connection blocks until that attempt finishes and returns a shared result. -// Note that canceling the context of a pending attempt early would propagate -// an error to blocked callers. -func (m *Manager) Connection(ctx context.Context, addr string) (conn *grpc.ClientConn, done func(), err error) { - select { - case <-ctx.Done(): - return nil, func() {}, ctx.Err() - default: - m.mu.Lock() - c, ok := m.conns[addr] - if !ok { - c = newConnection(addr) - m.conns[addr] = c - go m.dial(ctx, addr, c) - } - c.ref++ - m.mu.Unlock() - - <-c.ready - if c.err != nil { - return nil, func() {}, c.err - } - log.V(2).Infof("Reusing connection %q", addr) - return c.c, c.done(m), nil - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/connection/connection_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/connection/connection_test.go deleted file mode 100644 index feb9bab98..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/connection/connection_test.go +++ /dev/null @@ -1,297 +0,0 @@ -/* -Copyright 2019 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 connection - -import ( - "context" - "errors" - "net" - "sync" - "testing" - "time" - - "google.golang.org/grpc" - "github.com/openconfig/gnmi/unimplemented" - - pb "github.com/openconfig/gnmi/proto/gnmi" -) - -func newDevice(t *testing.T) (string, func()) { - t.Helper() - - srv := grpc.NewServer() - s := &unimplemented.Server{} - pb.RegisterGNMIServer(srv, s) - lis, err := net.Listen("tcp", "localhost:0") - if err != nil { - t.Fatalf("Failed to listen: %v", err) - } - go srv.Serve(lis) - - return lis.Addr().String(), srv.Stop -} - -func TestCtxCanceled(t *testing.T) { - addr, stop := newDevice(t) - defer stop() - ctx, cancel := context.WithCancel(context.Background()) - cancel() - m, err := NewManager(grpc.WithBlock(), grpc.WithInsecure()) - if err != nil { - t.Fatalf("Failed to initialize Manager: %v", err) - } - if _, _, err := m.Connection(ctx, addr); err == nil { - t.Errorf("Connection returned no error, want error") - } -} - -func assertConns(t *testing.T, m *Manager, want int) { - if l := len(m.conns); l != want { - t.Fatalf("got %v connections, want %v", l, want) - } -} - -func assertRefs(t *testing.T, m *Manager, addr string, want int) { - c, ok := m.conns[addr] - if !ok { - t.Fatalf("connection %q missing", addr) - } - if r := c.ref; r != want { - t.Fatalf("got %v references, want %v", r, want) - } -} - -func TestConcurrentConnection(t *testing.T) { - addr, stop := newDevice(t) - defer stop() - ctx := context.Background() - m, err := NewManager(grpc.WithBlock(), grpc.WithInsecure()) - if err != nil { - t.Fatalf("Failed to initialize Manager: %v", err) - } - var wg sync.WaitGroup - lim := 300 - wg.Add(lim) - - for i := 0; i < lim; i++ { - go func() { - conn, _, err := m.Connection(ctx, addr) - if err != nil { - t.Fatalf("got error creating connection: %v, want no error", err) - } - if conn == nil { - t.Fatalf("got nil connection, expected not nil") - } - wg.Done() - }() - } - wg.Wait() - - assertConns(t, m, 1) - assertRefs(t, m, addr, lim) -} - -func TestDone(t *testing.T) { - addr, stop := newDevice(t) - defer stop() - ctx := context.Background() - m, err := NewManager(grpc.WithBlock(), grpc.WithInsecure()) - if err != nil { - t.Fatalf("Failed to initialize Manager: %v", err) - } - - _, done1, err := m.Connection(ctx, addr) - if err != nil { - t.Fatalf("got error creating connection: %v, want no error", err) - } - assertConns(t, m, 1) - assertRefs(t, m, addr, 1) - - _, done2, err := m.Connection(ctx, addr) - if err != nil { - t.Fatalf("got error creating connection: %v, want no error", err) - } - assertConns(t, m, 1) - assertRefs(t, m, addr, 2) - - done1() - assertConns(t, m, 1) - assertRefs(t, m, addr, 1) - - done2() - assertConns(t, m, 0) - - done1() // No panic. - done2() // No panic. -} - -// TestConnectionDone simulates concurrently creating, reusing, and -// destroying multiple connections to different addresses. -func TestConnectionDone(t *testing.T) { - type connTest struct { - desc string - connections int - dones int - connectionID string // Populated by test. - } - - tests := []*connTest{ - // NOTE: done counts are relatively low to avoid connection - // thrashing that causes gRPC attempts to hang and affect this test. - { - desc: "connection1", - connections: 200, - dones: 20, - }, - { - desc: "connection2", - connections: 200, - dones: 25, - }, - { - desc: "connection3", - connections: 200, - dones: 30, - }, - } - - process := func(ctx context.Context, t *testing.T, c *connTest, m *Manager, wg *sync.WaitGroup) { - for i := 0; i < c.connections; i++ { - d := i - go func() { - conn, done, err := m.Connection(ctx, c.connectionID) - wg.Done() - if conn == nil { - t.Fatalf("got nil connection") - } - if err != nil { - t.Fatalf("got error creating connection: %v, want no error", err) - } - if d < c.dones { - go func() { - done() - wg.Done() - }() - } - }() - } - } - - var wg sync.WaitGroup - m, err := NewManager(grpc.WithBlock(), grpc.WithInsecure()) - if err != nil { - t.Fatalf("Failed to initialize Manager: %v", err) - } - for _, tt := range tests { - wg.Add(tt.connections + tt.dones) - addr, stop := newDevice(t) - defer stop() - tt.connectionID = addr - } - for _, tt := range tests { - go process(context.Background(), t, tt, m, &wg) - } - wg.Wait() - - if len(m.conns) != len(tests) { - t.Fatalf("got %v connections, want %v", len(m.conns), len(tests)) - } - for _, tt := range tests { - _, ok := m.conns[tt.connectionID] - if !ok { - t.Fatalf("%s: missing connection", tt.desc) - } - assertRefs(t, m, tt.connectionID, tt.connections-tt.dones) - } -} - -func errDialWait(d time.Duration) func(_ context.Context, _ string, _ ...grpc.DialOption) (*grpc.ClientConn, error) { - return func(_ context.Context, _ string, _ ...grpc.DialOption) (*grpc.ClientConn, error) { - time.Sleep(d) - return nil, errors.New("error occurred") - } -} - -func TestConcurrentDialErr(t *testing.T) { - ctx := context.Background() - m, err := NewManagerCustom(errDialWait(time.Second), grpc.WithBlock(), grpc.WithInsecure()) - if err != nil { - t.Fatalf("Failed to initialize Manager: %v", err) - } - var wg sync.WaitGroup - lim := 2 - wg.Add(lim) - errs := make(chan error, lim) - start := make(chan struct{}) - - for i := 0; i < lim; i++ { - go func() { - <-start - _, _, err := m.Connection(ctx, "") - if err == nil { - t.Fatal("got no error, want error") - } - errs <- err - wg.Done() - }() - } - close(start) - wg.Wait() - - close(errs) - var prevErr error - for err := range errs { - if prevErr == nil { - prevErr = err - } - if err != prevErr { - t.Fatal("got different error instance, want same") - } - } -} - -func TestNewManagerCustom(t *testing.T) { - tests := []struct { - desc string - d Dial - opts []grpc.DialOption - wantErr bool - }{ - { - desc: "missing dial", - opts: []grpc.DialOption{grpc.WithBlock()}, - wantErr: true, - }, { - desc: "missing opts", - d: grpc.DialContext, - }, { - desc: "valid dial and opts", - opts: []grpc.DialOption{grpc.WithBlock()}, - d: grpc.DialContext, - }, - } - - for _, tt := range tests { - _, err := NewManagerCustom(tt.d, tt.opts...) - switch { - case err == nil && !tt.wantErr: - case err == nil && tt.wantErr: - t.Errorf("%v: got no error, want error.", tt.desc) - case err != nil && !tt.wantErr: - t.Errorf("%v: got error, want no error.", tt.desc) - } - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/ctree/tree.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/ctree/tree.go deleted file mode 100644 index 5c71f12e9..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/ctree/tree.go +++ /dev/null @@ -1,439 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 ctree implements a Tree container whose methods are all thread-safe -// allowing concurrent access for multiple goroutines. This container was -// designed to support concurrent reads using sync.RWLock and are optimized for -// situations where reads and updates to previously Added values are -// dominant. The acquisition of write locks is avoided wherever possible. -package ctree - -import ( - "fmt" - "sort" - "strings" - "sync" -) - -type branch map[string]*Tree - -// Tree is a thread-safe container. -type Tree struct { - mu sync.RWMutex - // Each node is either a leaf or a branch. - leafBranch interface{} -} - -// Leaf is a Tree node that represents a leaf. -// -// Leaf is safe for use from multiple goroutines and will return the latest -// value. -// This means that if value in this leaf was updated after Leaf was retrieved, -// Value will return the updated content, not the original one. -// This also means that multiple calls to Value may return different results. -type Leaf Tree - -// DetachedLeaf returns a Leaf that's not attached to any tree. -func DetachedLeaf(val interface{}) *Leaf { - return &Leaf{leafBranch: val} -} - -// Value returns the latest value stored in this leaf. Value is safe to call on -// nil Leaf. -func (l *Leaf) Value() interface{} { - if l == nil { - return nil - } - defer l.mu.RUnlock() - l.mu.RLock() - return l.leafBranch -} - -// Update sets the value of this Leaf to val. -func (l *Leaf) Update(val interface{}) { - defer l.mu.Unlock() - l.mu.Lock() - l.leafBranch = val -} - -func newBranch(path []string, value interface{}) *Tree { - if len(path) == 0 { - return &Tree{leafBranch: value} - } - return &Tree{leafBranch: branch{path[0]: newBranch(path[1:], value)}} -} - -// isBranch assumes the calling function holds a lock on t. -func (t *Tree) isBranch() bool { - _, ok := t.leafBranch.(branch) - return ok -} - -// IsBranch returns whether the Tree node represents a branch. -// Returns false if called on a nil node. -func (t *Tree) IsBranch() bool { - if t == nil { - return false - } - defer t.mu.RUnlock() - t.mu.RLock() - return t.isBranch() -} - -// Children returns a mapping of child nodes if current node represents a branch, nil otherwise. -func (t *Tree) Children() map[string]*Tree { - if t == nil { - return nil - } - defer t.mu.RUnlock() - t.mu.RLock() - if t.isBranch() { - ret := make(branch) - for k, v := range t.leafBranch.(branch) { - ret[k] = v - } - return ret - } - return nil -} - -// Value returns the latest value stored in node t if it represents a leaf, nil otherwise. Value is safe to call on -// nil Tree. -func (t *Tree) Value() interface{} { - if t == nil { - return nil - } - defer t.mu.RUnlock() - t.mu.RLock() - if t.isBranch() { - return nil - } - return t.leafBranch -} - -// slowAdd will add a new branch to Tree t all the way to the leaf containing -// value, unless another routine added the branch before the write lock was -// acquired, in which case it will return to the normal Add for the remaining -// path that exists, but while still holding the write lock. This routine is -// called as a fallback by Add when a node does not already exist. -func (t *Tree) slowAdd(path []string, value interface{}) error { - if t.leafBranch == nil { - t.leafBranch = branch{} - } - switch b := t.leafBranch.(type) { - case branch: - // Verify the branch was not added by another routine during the - // reader/writer lock exchange. - br := b[path[0]] - if br == nil { - br = newBranch(path[1:], value) - b[path[0]] = br - } - return br.Add(path[1:], value) - default: - return fmt.Errorf("attempted to add value %#v at path %q which is already a leaf with value %#v", value, path, t.leafBranch) - } -} - -func (t *Tree) terminalAdd(value interface{}) error { - defer t.mu.Unlock() - t.mu.Lock() - if _, ok := t.leafBranch.(branch); ok { - return fmt.Errorf("attempted to add a leaf in place of a branch") - } - t.leafBranch = value - return nil -} - -func (t *Tree) intermediateAdd(path []string, value interface{}) error { - readerLocked := true - defer func() { - if readerLocked { - t.mu.RUnlock() - } - }() - t.mu.RLock() - var br *Tree - switch b := t.leafBranch.(type) { - case nil: - case branch: - br = b[path[0]] - default: - return fmt.Errorf("attempted to add value %#v at path %q which is already a leaf with value %#v", value, path, t.leafBranch) - } - if br == nil { - // Exchange the reader lock on t for a writer lock to add new node(s) to the - // Tree. - t.mu.RUnlock() - readerLocked = false - defer t.mu.Unlock() - t.mu.Lock() - return t.slowAdd(path, value) - } - return br.Add(path[1:], value) -} - -// Add adds value to the Tree at the specified path and returns true on -// success. -func (t *Tree) Add(path []string, value interface{}) error { - if len(path) == 0 { - return t.terminalAdd(value) - } - return t.intermediateAdd(path, value) -} - -// Get returns the Tree node if path points to it, nil otherwise. -// All nodes in path must be fully specified with no globbing (*). -func (t *Tree) Get(path []string) *Tree { - defer t.mu.RUnlock() - t.mu.RLock() - if len(path) == 0 { - return t - } - if b, ok := t.leafBranch.(branch); ok { - if br := b[path[0]]; br != nil { - return br.Get(path[1:]) - } - } - return nil -} - -// GetLeafValue returns the leaf value if path points to a leaf in t, nil otherwise. All -// nodes in path must be fully specified with no globbing (*). -func (t *Tree) GetLeafValue(path []string) interface{} { - return t.Get(path).Value() -} - -// GetLeaf returns the leaf node if path points to a leaf in t, nil otherwise. All -// nodes in path must be fully specified with no globbing (*). -func (t *Tree) GetLeaf(path []string) *Leaf { - return (*Leaf)(t.Get(path)) -} - -// VisitFunc is a callback func triggered on leaf values by Query and Walk. -// -// The provided Leaf is the leaf node of the tree, val is the value stored -// inside of it. l can be retained after VisitFunc returns and l.Value() can be -// called to get the latest value for that leaf. -// -// Note that l.Value can *not* be called inside VisitFunc, because the node is -// already locked by Query/Walk. -type VisitFunc func(path []string, l *Leaf, val interface{}) - -func (t *Tree) enumerateChildren(prefix, path []string, f VisitFunc) { - // Caller should hold a read lock on t. - if len(path) == 0 { - switch b := t.leafBranch.(type) { - case branch: - for k, br := range b { - br.queryInternal(append(prefix, k), path, f) - } - default: - f(prefix, (*Leaf)(t), t.leafBranch) - } - return - } - if b, ok := t.leafBranch.(branch); ok { - for k, br := range b { - br.queryInternal(append(prefix, k), path[1:], f) - } - } -} - -// Query calls f for all leaves that match a given query where zero or more -// nodes in path may be specified by globs (*). Results and their full paths -// are passed to f as they are found in the Tree. No ordering of paths is -// guaranteed. -func (t *Tree) Query(path []string, f VisitFunc) { - t.queryInternal(nil, path, f) -} - -func (t *Tree) queryInternal(prefix, path []string, f VisitFunc) { - defer t.mu.RUnlock() - t.mu.RLock() - if len(path) == 0 || path[0] == "*" { - t.enumerateChildren(prefix, path, f) - return - } - if b, ok := t.leafBranch.(branch); ok { - if br := b[path[0]]; br != nil { - br.queryInternal(append(prefix, path[0]), path[1:], f) - } - } -} - -func (t *Tree) walkInternal(path []string, f VisitFunc) { - defer t.mu.RUnlock() - t.mu.RLock() - if b, ok := t.leafBranch.(branch); ok { - l := len(path) - for name, br := range b { - p := make([]string, l, l+1) - copy(p, path) - br.walkInternal(append(p, name), f) - } - return - } - // If this is the root node and it has no children and the value is nil, - // most likely it's just the zero value of Tree not a valid leaf. - if len(path) == 0 && t.leafBranch == nil { - return - } - f(path, (*Leaf)(t), t.leafBranch) -} - -// Walk calls f for all leaves. -func (t *Tree) Walk(f VisitFunc) { - t.walkInternal(nil, f) -} - -func (t *Tree) walkInternalSorted(path []string, f VisitFunc) { - defer t.mu.RUnlock() - t.mu.RLock() - if b, ok := t.leafBranch.(branch); ok { - names := make([]string, 0, len(b)) - for name := range b { - names = append(names, name) - } - sort.Strings(names) - l := len(path) - for _, name := range names { - p := make([]string, l, l+1) - copy(p, path) - b[name].walkInternalSorted(append(p, name), f) - } - return - } - // If this is the root node and it has no children and the value is nil, - // most likely it's just the zero value of Tree not a valid leaf. - if len(path) == 0 && t.leafBranch == nil { - return - } - f(path, (*Leaf)(t), t.leafBranch) -} - -// WalkSorted calls f for all leaves in string sorted order. -func (t *Tree) WalkSorted(f VisitFunc) { - t.walkInternalSorted(nil, f) -} - -// internalDelete removes nodes recursively that match subpath. It returns true -// if the current node is to be removed from the parent and a slice of subpaths -// ([]string) for all leaves deleted thus far. -func (t *Tree) internalDelete(subpath []string, condition func(interface{}) bool) (bool, [][]string) { - if len(subpath) == 0 || subpath[0] == "*" { - if len(subpath) != 0 { - subpath = subpath[1:] - } - // The subpath is a full path to a leaf. - switch b := t.leafBranch.(type) { - case branch: - // The subpath terminates in a branch node and will recursively delete any - // progeny leaves. - allLeaves := [][]string{} - for k, v := range b { - del, leaves := v.internalDelete(subpath, condition) - leaf := []string{k} - for _, l := range leaves { - allLeaves = append(allLeaves, append(leaf, l...)) - } - if del { - delete(b, k) - } - } - return len(t.leafBranch.(branch)) == 0, allLeaves - default: - if condition(t.leafBranch) { - // The second parameter is an empty path that will be filled as recursion - // unwinds for this leaf that will be deleted in its parent. - return true, [][]string{[]string{}} - } - return false, [][]string{} - } - } - if b, ok := t.leafBranch.(branch); ok { - // Continue to recurse on subpath while it matches nodes in the Tree. - if br := b[subpath[0]]; br != nil { - delBr, allLeaves := br.internalDelete(subpath[1:], condition) - leaf := []string{subpath[0]} - // Prepend branch node name to all progeny leaves of branch. - for i := range allLeaves { - allLeaves[i] = append(leaf, allLeaves[i]...) - } - // Remove branch if requested. - if delBr { - delete(b, subpath[0]) - } - // Node contains no branches so remove this branch node as well. - if len(b) == 0 { - return true, allLeaves - } - // This node still contains branches, don't delete it. - return false, allLeaves - } - } - // The subpath doesn't match any Tree branch, return empty list of leaves. - return false, [][]string{} -} - -// DeleteConditional removes all leaves at or below subpath as well as any -// ancestors with no children for those leaves which the given conditional -// function returns true, returning the list of all leaves removed. -// DeleteConditional prevents all other concurrent access. -func (t *Tree) DeleteConditional(subpath []string, condition func(interface{}) bool) [][]string { - // It is possible that a single delete operation will remove the whole Tree, - // so only the top level write lock is obtained to prevent concurrent accesses - // to the entire Tree. - defer t.mu.Unlock() - t.mu.Lock() - delBr, leaves := t.internalDelete(subpath, condition) - if delBr { - t.leafBranch = nil - } - return leaves -} - -// Delete removes all leaves at or below subpath as well as any ancestors with -// no children, returning the list of all leaves removed. Deletes prevent all -// other concurrent access. -func (t *Tree) Delete(subpath []string) [][]string { - always := func(interface{}) bool { return true } - return t.DeleteConditional(subpath, always) -} - -// String implements the string interface for Tree returning a stable output -// sorting keys at each level. -func (t *Tree) String() string { - if t == nil { - return "" - } - defer t.mu.RUnlock() - t.mu.RLock() - if t.isBranch() { - b := t.leafBranch.(branch) - keys := make([]string, 0, len(b)) - for k := range b { - keys = append(keys, k) - } - sort.Strings(keys) - children := make([]string, 0, len(b)) - for _, k := range keys { - children = append(children, fmt.Sprintf("%q: %s", k, b[k])) - } - return fmt.Sprintf("{ %s }", strings.Join(children, ", ")) - } - return fmt.Sprintf("%#v", t.leafBranch) -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/ctree/tree_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/ctree/tree_test.go deleted file mode 100644 index 602ede71e..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/ctree/tree_test.go +++ /dev/null @@ -1,797 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 ctree - -import ( - "fmt" - "reflect" - "runtime" - "strings" - "sync" - "sync/atomic" - "testing" - - "github.com/kylelemons/godebug/pretty" -) - -func TestAdd(t *testing.T) { - tr := &Tree{} - if err := tr.Add([]string{}, "foo"); err != nil { - t.Error(err) - } - if err := tr.Add([]string{"a"}, "foo"); err == nil { - t.Error("got nil, expected error adding a leaf to a leaf") - } - tr = &Tree{} - if err := tr.Add([]string{"a"}, "foo"); err != nil { - t.Error(err) - } - if err := tr.Add([]string{}, "foo"); err == nil { - t.Error("got nil, want error adding leaf in place of a branch") - } - if err := tr.Add([]string{"a", "b"}, "foo"); err == nil { - t.Error("got nil, want error adding a leaf to a leaf") - } - if err := tr.Add([]string{"b", "c", "d", "e"}, "foo"); err != nil { - t.Error(err) - } -} - -func TestSlowAdd(t *testing.T) { - for _, test := range []struct { - tree *Tree - path []string - expectErr bool - }{ - { - tree: &Tree{leafBranch: "not a branch"}, - path: []string{"a"}, - expectErr: true, - }, - { - tree: &Tree{leafBranch: branch{"a": &Tree{leafBranch: "a"}}}, - path: []string{"a"}, - expectErr: false, - }, - } { - testVal := "testVal" - err := test.tree.slowAdd(test.path, testVal) - gotErr := err != nil - if gotErr != test.expectErr { - t.Errorf("slowAdd(%v, %v) = %v, want %v", test.path, testVal, gotErr, test.expectErr) - } - } -} - -func TestTreeGetLeafValue(t *testing.T) { - tr := &Tree{} - for x, tt := range []struct { - path []string - value string - }{ - {[]string{"a", "b"}, "value0"}, - {[]string{"a", "c"}, "value1"}, - {[]string{"a", "d"}, "value2"}, - {[]string{"b"}, "value2"}, - {[]string{"c", "a"}, "value3"}, - {[]string{"c", "b", "a"}, "value4"}, - {[]string{"c", "d"}, "value5"}, - } { - // Value shouldn't exist before addition. - if value := tr.GetLeafValue(tt.path); nil != value { - t.Errorf("#%d: got %v, expected %v", x, value, nil) - } - if err := tr.Add(tt.path, tt.value); err != nil { - t.Error(err) - } - value := tr.GetLeafValue(tt.path) - // Value should exist on successful addition. - if tt.value != value { - t.Errorf("#%d: got %v, expected %v", x, value, tt.value) - } - } -} - -var testPaths = [][]string{ - []string{"a", "b", "c"}, - []string{"a", "d"}, - []string{"b", "a", "d"}, - []string{"b", "c", "d"}, - []string{"c", "d", "e", "f", "g", "h", "i"}, - []string{"d"}, -} - -func buildTree(t *Tree) { - buildTreePaths(t, testPaths) -} - -func buildTreePaths(t *Tree, paths [][]string) { - for _, path := range paths { - value := strings.Join(path, "/") - t.Add(path, value) - } -} - -type expectedQuery struct { - query []string - results map[string]interface{} -} - -func TestQuery(t *testing.T) { - tr := &Tree{} - results := make(map[string]interface{}) - appendResults := func(p []string, _ *Leaf, v interface{}) { results[strings.Join(p, "/")] = v } - - tr.Query([]string{"*"}, appendResults) - if len(results) > 0 { - t.Errorf("tr.Query: got %d results, expected 0", len(results)) - } - - buildTree(tr) - // Test a set of queries. - for x, tt := range []expectedQuery{ - {[]string{"a", "d"}, map[string]interface{}{"a/d": "a/d"}}, - {[]string{"a"}, map[string]interface{}{"a/d": "a/d", "a/b/c": "a/b/c"}}, - // A trailing glob is equivalent to a query without it, as above. - {[]string{"a", "*"}, map[string]interface{}{"a/d": "a/d", "a/b/c": "a/b/c"}}, - {[]string{"*"}, map[string]interface{}{"a/d": "a/d", "a/b/c": "a/b/c", "b/c/d": "b/c/d", "b/a/d": "b/a/d", "c/d/e/f/g/h/i": "c/d/e/f/g/h/i", "d": "d"}}, - {[]string{"*", "*", "d"}, map[string]interface{}{"b/c/d": "b/c/d", "b/a/d": "b/a/d"}}, - {[]string{"c", "d", "e"}, map[string]interface{}{"c/d/e/f/g/h/i": "c/d/e/f/g/h/i"}}, - } { - results = make(map[string]interface{}) - tr.Query(tt.query, appendResults) - - if !reflect.DeepEqual(results, tt.results) { - t.Errorf("#%d: got results: %v\nwant results: %v", x, results, tt.results) - } - } -} - -func TestUpdateLeaf(t *testing.T) { - tr := &Tree{} - buildTree(tr) - - l := tr.GetLeaf(testPaths[0]) - - nv := "new value" - tr.Add(testPaths[0], nv) - - if got := l.Value(); got != nv { - t.Errorf("Value on updated leaf returned %+v, want %+v", got, nv) - } -} - -func TestWalk(t *testing.T) { - tr := &Tree{} - buildTree(tr) - paths := [][]string{} - tr.Walk(func(path []string, _ *Leaf, value interface{}) { - got, want := value.(string), strings.Join(path, "/") - if got != want { - t.Errorf("Walk got value %q, want %q", got, want) - } - paths = append(paths, path) - }) - if got, want := len(paths), len(testPaths); got != want { - t.Errorf("Walk got %d paths, want %d", got, want) - } -gotpaths: - for _, p := range paths { - for _, tp := range testPaths { - if reflect.DeepEqual(p, tp) { - continue gotpaths - } - } - t.Errorf("Walk got path %q, wanted one of %q", p, testPaths) - } -wantpaths: - for _, tp := range testPaths { - for _, p := range paths { - if reflect.DeepEqual(p, tp) { - continue wantpaths - } - } - t.Errorf("Walk got paths %q, want %q included", paths, tp) - } -} - -func TestWalkSorted(t *testing.T) { - tr := &Tree{} - buildTree(tr) - paths := [][]string{} - tr.WalkSorted(func(path []string, _ *Leaf, value interface{}) { - got, want := value.(string), strings.Join(path, "/") - if got != want { - t.Errorf("WalkSorted got value %q, want %q", got, want) - } - paths = append(paths, path) - }) - if got, want := len(paths), len(testPaths); got != want { - t.Errorf("WalkSorted got %d paths, want %d", got, want) - } - if !reflect.DeepEqual(paths, testPaths) { - t.Errorf("WalkSorted got %q, want %q", paths, testPaths) - } -} - -func TestEmptyWalk(t *testing.T) { - tr := &Tree{} - tr.Walk(func(_ []string, _ *Leaf, _ interface{}) { - t.Error("Walk on empty tree should not call func.") - }) - tr.WalkSorted(func(_ []string, _ *Leaf, _ interface{}) { - t.Error("WalkSorted on empty tree should not call func.") - }) -} - -type expectedDelete struct { - subpath []string - leaves map[string]bool -} - -func TestDelete(t *testing.T) { - tr := &Tree{} - deleted := tr.Delete([]string{"a", "b"}) - if len(deleted) > 0 { - t.Errorf("Delete on empty tree should return empty slice.") - } - for x, tt := range []expectedDelete{ - {[]string{"x"}, map[string]bool{}}, - // root delete with glob appended for a non-existing root - {[]string{"x", "*"}, map[string]bool{}}, - {[]string{"d"}, map[string]bool{"d": true}}, - {[]string{"a"}, map[string]bool{"a/d": true, "a/b/c": true}}, - // root delete with a glob appended - {[]string{"a", "*"}, map[string]bool{"a/d": true, "a/b/c": true}}, - {[]string{"b", "c", "d"}, map[string]bool{"b/c/d": true}}, - // delete with glob in the middle of the path - {[]string{"b", "*", "d"}, map[string]bool{"b/a/d": true, "b/c/d": true}}, - // delete with glob in the middle of the path for a non-existing path - {[]string{"b", "*", "x"}, map[string]bool{}}, - {[]string{"b"}, map[string]bool{"b/a/d": true, "b/c/d": true}}, - {[]string{"c", "d", "e"}, map[string]bool{"c/d/e/f/g/h/i": true}}, - {[]string{}, map[string]bool{"a/d": true, "a/b/c": true, "b/a/d": true, "b/c/d": true, "c/d/e/f/g/h/i": true, "d": true}}, - // just glob in the path to delete all the tree - {[]string{"*"}, map[string]bool{"a/d": true, "a/b/c": true, "b/a/d": true, "b/c/d": true, "c/d/e/f/g/h/i": true, "d": true}}, - } { - // Rebuild tree for each query. - buildTree(tr) - for _, leaf := range tr.Delete(tt.subpath) { - leafpath := strings.Join(leaf, "/") - if _, ok := tt.leaves[leafpath]; !ok { - t.Errorf("#%d: unexpected deleted leaf %v", x, leaf) - } - delete(tt.leaves, leafpath) - } - if len(tt.leaves) > 0 { - t.Errorf("#%d: expected leaves missing from return: %v", x, tt.leaves) - } - } - if tr.leafBranch != nil { - t.Errorf("tree should be empty, but root still has branches %#v", tr.leafBranch) - } -} - -func TestDeleteConditional(t *testing.T) { - never := func(interface{}) bool { return false } - tr := &Tree{} - buildTree(tr) - leaves := tr.DeleteConditional([]string{}, never) - if len(leaves) > 0 { - t.Errorf("Leaves deleted for false condition: %v", leaves) - } - always := func(interface{}) bool { return true } - // This is the same test as the last case for TestDelete, above. - leaves = tr.DeleteConditional([]string{}, always) - if len(leaves) != 6 { - t.Errorf("Not all leaves deleted: %v", leaves) - } - valEqualsD := func(v interface{}) bool { return v == "d" } - buildTree(tr) - leaves = tr.DeleteConditional([]string{}, valEqualsD) - if expected := [][]string{[]string{"d"}}; !reflect.DeepEqual(expected, leaves) { - t.Errorf("got %v, expected %v", leaves, expected) - } - if v := tr.GetLeafValue([]string{"d"}); nil != v { - t.Errorf("got %v, expected %v", v, nil) - } -} - -type expectedTreeEqual struct { - t1 *Tree - t2 *Tree - equal bool -} - -func TestEqual(t *testing.T) { - for x, tt := range []expectedTreeEqual{ - {nil, nil, true}, - {nil, &Tree{}, false}, - {&Tree{}, nil, false}, - {&Tree{}, &Tree{}, true}, - {&Tree{leafBranch: branch{"a": &Tree{leafBranch: "a"}}}, - &Tree{}, - false}, - {&Tree{leafBranch: branch{"a": &Tree{leafBranch: "a"}}}, - &Tree{leafBranch: branch{"a": &Tree{leafBranch: "a"}}}, - true}, - {&Tree{leafBranch: branch{"a": &Tree{leafBranch: "a"}, "b": &Tree{leafBranch: "b"}}}, - &Tree{leafBranch: branch{"a": &Tree{leafBranch: "a"}}}, - false}, - {&Tree{leafBranch: branch{"a": &Tree{leafBranch: "a"}}}, - &Tree{leafBranch: branch{"a": &Tree{leafBranch: "a"}, "b": &Tree{leafBranch: "b"}}}, - false}, - {&Tree{leafBranch: branch{"a": &Tree{leafBranch: "a"}, "b": &Tree{leafBranch: "b"}}}, - &Tree{leafBranch: branch{"a": &Tree{leafBranch: "a"}, "b": &Tree{leafBranch: "b"}}}, - true}, - {&Tree{leafBranch: branch{"a": &Tree{leafBranch: "a"}, "b": &Tree{leafBranch: branch{"b/c": &Tree{leafBranch: "b/c"}}}}}, - &Tree{leafBranch: branch{"a": &Tree{leafBranch: "a"}, "b": &Tree{leafBranch: "b"}}}, - false}, - {&Tree{leafBranch: branch{"a": &Tree{leafBranch: "a"}, "b": &Tree{leafBranch: branch{"b/c": &Tree{leafBranch: "b/c"}}}}}, - &Tree{leafBranch: branch{"a": &Tree{leafBranch: "a"}, "b": &Tree{leafBranch: branch{"b/c": &Tree{leafBranch: "b/c"}}}}}, - true}, - } { - if equal := reflect.DeepEqual(tt.t1, tt.t2); tt.equal != equal { - t.Errorf("#%d: got %t, expected %t", x, equal, tt.equal) - } - } -} - -func generatePaths(count int) [][]string { - paths := [][]string{} - for c := 0; c < count; c++ { - p := []string{} - for d := 3; d < 16; d++ { - p = append(p, string(c%d+65)) - } - paths = append(paths, p) - } - return paths -} - -func buildTreeRange(wg *sync.WaitGroup, t *Tree, paths [][]string, index, modulus int) { - if wg != nil { - defer wg.Done() - } - for i := index; i < len(paths); i += modulus { - t.Add(paths[i], strings.Join(paths[i], "/")) - } -} - -func TestParallelAdd(t *testing.T) { - trees := []*Tree{} - paths := generatePaths(10000) - wg := new(sync.WaitGroup) - r := runtime.GOMAXPROCS(8) - for _, tt := range []int{1, 2, 4, 8} { - atree := &Tree{} - trees = append(trees, atree) - for i := 0; i < tt; i++ { - wg.Add(1) - go buildTreeRange(wg, atree, paths, i, tt) - } - } - wg.Wait() - runtime.GOMAXPROCS(r) - for i := 1; i < len(trees); i++ { - if !reflect.DeepEqual(trees[0], trees[i]) { - t.Errorf("tree %d does not equal serially created tree.", i) - } - } -} - -func deleteTreeRange(wg *sync.WaitGroup, t *Tree, paths [][]string, index, modulus int) { - defer wg.Done() - for i := index; i < len(paths); i += modulus { - t.Delete(paths[i]) - } -} - -func TestParallelDelete(t *testing.T) { - trees := []*Tree{} - paths := generatePaths(100000) - wg := new(sync.WaitGroup) - r := runtime.GOMAXPROCS(8) - parallelSize := []int{2, 4, 8} - for _, tt := range parallelSize { - atree := &Tree{} - trees = append(trees, atree) - for i := 0; i < tt; i++ { - wg.Add(1) - go buildTreeRange(wg, atree, paths, i, tt) - } - } - wg.Wait() - for x, tt := range parallelSize { - atree := trees[x] - for i := 0; i < tt; i++ { - wg.Add(1) - go deleteTreeRange(wg, atree, paths, i, tt) - } - } - wg.Wait() - runtime.GOMAXPROCS(r) - emptyTree := &Tree{} - for i := 0; i < len(trees); i++ { - if !reflect.DeepEqual(trees[i], emptyTree) { - t.Errorf("tree %d does not equal empty tree. %#v != %#v", i, trees[i], emptyTree) - } - } -} - -func query(tr *Tree, path []string) (ret []interface{}) { - tr.Query(path, func(_ []string, _ *Leaf, val interface{}) { - ret = append(ret, val) - }) - return ret -} - -func queryGetTreeRange(t *testing.T, wg *sync.WaitGroup, tr *Tree, paths [][]string, index, modulus int) { - defer wg.Done() - for i := index; i < len(paths); i += modulus { - // Test get of paths. - got := tr.GetLeafValue(paths[i]) - if want := strings.Join(paths[i], "/"); got != want { - t.Errorf("Get(%v): got result %s, want %s using %d threads", paths[i], got, want, modulus) - } - // Test query of whole paths. - results := query(tr, paths[i]) - if n := len(results); n != 1 { - t.Errorf("Query(%v): got %d results, want 1", paths[i], n) - } - for _, got := range results { - if want := strings.Join(paths[i], "/"); got != want { - t.Errorf("got result %s, want %s using %d threads", got, want, modulus) - } - } - // Test query of partial paths. - results = query(tr, paths[i][:3]) - if n := len(results); n < 1 { - t.Errorf("Query(%v): got %d results, want >= 1", paths[i], n) - } - for _, got := range results { - if want := strings.Join(paths[i][0:1], "/"); !strings.HasPrefix(got.(string), want) { - t.Errorf("got result %s, want to have prefix %s using %d threads", got, want, modulus) - } - } - } -} - -func TestParallelQueryGet(t *testing.T) { - paths := generatePaths(10000) - r := runtime.GOMAXPROCS(8) - atree := &Tree{} - buildTreeRange(nil, atree, paths, 0, 1) - wg := new(sync.WaitGroup) - for _, tt := range []int{2, 4, 8} { - for i := 0; i < tt; i++ { - wg.Add(1) - go queryGetTreeRange(t, wg, atree, paths, i, tt) - } - } - wg.Wait() - runtime.GOMAXPROCS(r) -} - -func makePath(i int64) []string { - path := []string{} - for depth := 0; depth < 5; depth++ { - path = append(path, fmt.Sprintf("%d", i&15)) - i >>= 4 - } - return path -} - -func makePathValue(i int64) ([]string, *string) { - value := fmt.Sprintf("value_%d", i) - return makePath(i), &value -} - -func BenchmarkTreeParallelAddNew(b *testing.B) { - t := &Tree{} - var x int64 - b.RunParallel(func(pb *testing.PB) { - for pb.Next() { - t.Add(makePathValue(atomic.AddInt64(&x, 1))) - } - }) -} - -func BenchmarkTreeParallelAddUpdate(b *testing.B) { - t := &Tree{} - for i := 0; i < b.N; i++ { - t.Add(makePathValue(int64(i))) - } - // Only time the updates to already existing keys. - b.ResetTimer() - var x int64 - b.RunParallel(func(pb *testing.PB) { - for pb.Next() { - t.Add(makePathValue(atomic.AddInt64(&x, 1))) - } - }) -} - -func BenchmarkTreeParallelGet(b *testing.B) { - t := &Tree{} - for i := 0; i < b.N; i++ { - t.Add(makePathValue(int64(i))) - } - // Only time the Get calls. - b.ResetTimer() - var x int64 - b.RunParallel(func(pb *testing.PB) { - for pb.Next() { - t.GetLeafValue(makePath(atomic.AddInt64(&x, 1))) - } - }) -} - -func BenchmarkTreeParallelQuerySingle(b *testing.B) { - t := &Tree{} - for i := 1; i <= b.N; i++ { - t.Add(makePathValue(int64(i))) - } - var count int64 - // Create a query channel. - c := make(chan interface{}, 1000) - // Create parallel consumers. - var wg sync.WaitGroup - collect := func(c <-chan interface{}) { - for r := range c { - if r != nil { - atomic.AddInt64(&count, 1) - } - } - wg.Done() - } - for i := 0; i < runtime.GOMAXPROCS(0); i++ { - wg.Add(1) - go collect(c) - } - // Only time the Query calls. - b.ResetTimer() - var x int64 - b.RunParallel(func(pb *testing.PB) { - for pb.Next() { - t.Query(makePath(atomic.AddInt64(&x, 1)), func(_ []string, _ *Leaf, val interface{}) { c <- val }) - } - }) - close(c) - wg.Wait() - b.Logf("Query result count: %v", count) -} - -func BenchmarkTreeParallelQueryMany(b *testing.B) { - t := &Tree{} - for i := 1; i <= b.N; i++ { - t.Add(makePathValue(int64(i))) - } - var count int64 - // Create a query channel. - c := make(chan interface{}, 1000) - // Create parallel consumers. - var wg sync.WaitGroup - collect := func(c <-chan interface{}) { - for r := range c { - if r != nil { - atomic.AddInt64(&count, 1) - } - } - wg.Done() - } - for i := 0; i < runtime.GOMAXPROCS(0); i++ { - wg.Add(1) - go collect(c) - } - // Only time the Query calls. - b.ResetTimer() - var x int64 - b.RunParallel(func(pb *testing.PB) { - for pb.Next() { - // For each query, use only a subpath to retrieve multiple elements. - t.Query(makePath(atomic.AddInt64(&x, 1))[0:3], func(_ []string, _ *Leaf, val interface{}) { c <- val }) - } - }) - close(c) - wg.Wait() - b.Logf("Query result count: %v", count) -} - -func TestIsBranch(t *testing.T) { - tr := &Tree{} - buildTree(tr) - for _, test := range []struct { - node *Tree - want bool - }{ - { - node: tr, - want: true, - }, { - node: tr.Get(testPaths[0]), - want: false, - }, { - node: nil, - want: false, - }, - } { - got := test.node.IsBranch() - if got != test.want { - t.Errorf("IsBranch(%v) = %v, want %v", test.node, got, test.want) - } - } -} - -func TestGet(t *testing.T) { - tr := &Tree{} - testPaths = [][]string{ - []string{"a", "b", "c"}, - []string{"a", "d"}, - []string{"d"}, - } - buildTreePaths(tr, testPaths) - for _, test := range []struct { - path []string - want *Tree - }{ - { - path: []string{"a"}, - want: &Tree{leafBranch: branch{ - "b": &Tree{leafBranch: branch{ - "c": &Tree{leafBranch: "a/b/c"}}}, - "d": &Tree{leafBranch: "a/d"}}}, - }, { - path: []string{"a", "d"}, - want: &Tree{leafBranch: "a/d"}, - }, { - path: []string{}, - want: &Tree{leafBranch: branch{ - "a": &Tree{leafBranch: branch{ - "b": &Tree{leafBranch: branch{ - "c": &Tree{leafBranch: "a/b/c"}}}, - "d": &Tree{leafBranch: "a/d"}}}, - "d": &Tree{leafBranch: "d"}}}, - }, { - path: []string{"non existent path"}, - want: nil, - }, - } { - got := tr.Get(test.path) - if diff := pretty.Compare(got, test.want); diff != "" { - t.Errorf("Get(%v) returned diff (-got +want):\n%s", test.path, diff) - } - } -} - -func TestGetChildren(t *testing.T) { - tr := &Tree{} - testPaths = [][]string{ - []string{"a", "b", "c"}, - []string{"a", "d"}, - []string{"d"}, - } - buildTreePaths(tr, testPaths) - for _, test := range []struct { - node *Tree - want branch - }{ - { - node: tr, - want: branch{ - "a": &Tree{leafBranch: branch{ - "b": &Tree{leafBranch: branch{ - "c": &Tree{leafBranch: "a/b/c"}}}, - "d": &Tree{leafBranch: "a/d"}}}, - "d": &Tree{leafBranch: "d"}, - }, - }, { - node: tr.Get(testPaths[0]), // Leaf. - want: nil, - }, { - node: nil, - want: nil, - }, - } { - got := test.node.Children() - if diff := pretty.Compare(got, test.want); diff != "" { - t.Errorf("Children(%s) returned diff (-got +want):\n%s", test.node, diff) - } - } -} - -func TestTreeValue(t *testing.T) { - for _, test := range []struct { - node *Tree - want interface{} - }{ - { - node: &Tree{leafBranch: branch{}}, - want: nil, - }, { - node: &Tree{leafBranch: "val1"}, - want: "val1", - }, { - node: nil, - want: nil, - }, - } { - got := test.node.Value() - if got != test.want { - t.Errorf("Value(%v) = %v, want %v", test.node, got, test.want) - } - } -} - -func TestLeafValue(t *testing.T) { - for _, test := range []struct { - node *Leaf - want interface{} - }{ - { - node: &Leaf{leafBranch: "val1"}, - want: "val1", - }, { - node: nil, - want: nil, - }, - } { - got := test.node.Value() - if got != test.want { - t.Errorf("Value(%v) = %v, want %v", test.node, got, test.want) - } - } -} - -func TestString(t *testing.T) { - tr := &Tree{} - testPaths = [][]string{ - []string{"a", "b", "c"}, - []string{"a", "d"}, - []string{"d"}, - } - buildTreePaths(tr, testPaths) - for _, test := range []struct { - node *Tree - want string - }{ - { - node: tr, - want: `{ "a": { "b": { "c": "a/b/c" }, "d": "a/d" }, "d": "d" }`, - }, { - node: tr.Get([]string{"a"}), - want: `{ "b": { "c": "a/b/c" }, "d": "a/d" }`, - }, { - node: tr.Get([]string{"d"}), - want: `"d"`, - }, { - node: nil, - want: "", - }, - } { - // Test explicitly. - got := test.node.String() - if got != test.want { - t.Errorf("String\n\tgot: %q\n\twant: %q", got, test.want) - } - // Test via string format specifier. - got = fmt.Sprintf("%s", test.node) - if got != test.want { - t.Errorf("string format specifier\n\tgot: %q\n\twant: %q", got, test.want) - } - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/errdiff/errdiff.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/errdiff/errdiff.go deleted file mode 100644 index dfc087907..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/errdiff/errdiff.go +++ /dev/null @@ -1,174 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 errdiff makes it easy to compare Error by code, substring or exact -// match in tests. -// -// Similar in intended usage to messagediff.Diff and pretty.Compare, -// particularly in table-driven tests. -// -// Example usage: -// -// testCases := []struct { -// ... -// wantSubstring string -// }{ -// // Success -// {...}, -// // Failures -// {..., wantSubstring: "failed"}, -// {..., wantSubstring: "too many users"}, -// } -// for _, c := range testCases { -// got, err := fn(...) -// if diff := errdiff.Substring(err, c.wantSubstring); diff != "" { -// t.Errorf("fn() %v", diff) -// continue -// } -// ... -// } -// -// The generic function Check may be used in place of Code or -// Substring or when comparing against another error or for simple -// existance of an error: -// -// testCases := []struct { -// ... -// err interface{} -// }{ -// // Success -// {...}, -// // Failures -// {..., err: io.EOF}, // An explicit error -// {..., err: "my expected error string"}, // contains text -// {..., err: true}, // expect an error, don't care what -// } -// for _, c := range testCases { -// got, err := fn(...) -// if diff := errdiff.Check(err, c.err); diff != "" { -// t.Errorf("fn() %v", diff) -// continue -// } -// ... -package errdiff - -import ( - "fmt" - "strings" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc" -) - -// Text returns a message describing the difference between the -// error text and the desired input. want="" indicates that no error is -// expected. -func Text(got error, want string) string { - if want == "" { - if got == nil { - return "" - } - return fmt.Sprintf("got err=%v, want err=nil", got) - } - if got == nil { - return fmt.Sprintf("got err=nil, want err with exact text %v", want) - } - if got.Error() != want { - return fmt.Sprintf("got err=%v, want err with exact text %v", got, want) - } - return "" -} - -// Substring returns a message describing the difference between the -// error text and the desired input. want="" indicates that no error is -// expected. -func Substring(got error, want string) string { - if want == "" { - if got == nil { - return "" - } - return fmt.Sprintf("got err=%v, want err=nil", got) - } - if got == nil { - return fmt.Sprintf("got err=nil, want err containing %v", want) - } - if !strings.Contains(got.Error(), want) { - return fmt.Sprintf("got err=%v, want err containing %v", got, want) - } - return "" -} - -// Code returns a message describing the difference between the error's -// code and the desired codes. want=codes.OK indicates that no error is -// expected. -func Code(got error, want codes.Code) string { - if want == codes.OK { - if got == nil { - return "" - } - return fmt.Sprintf("got err=%v, want OK", got) - } - if got == nil { - return fmt.Sprintf("got err=nil, want code %v", want) - } - if grpc.Code(got) != want { - return fmt.Sprintf("got err=%v, want code %v", got, want) - } - return "" -} - -// Check returns a message describing the difference between the error err and -// want. If want is a codes.Code, this function is the same as Code. -// If want is a string, this function is the same as Substring. If -// want is an error, this is essentially the same as ExactTextCompare(got, -// w.Error()). If want is a bool, err is simply tested for existance (want of -// true means an error is wanted). -func Check(got error, want interface{}) string { - switch w := want.(type) { - case nil: - if got == nil { - return "" - } - return fmt.Sprintf("got err=%v, want err=nil", got) - case bool: - switch { - case w && got == nil: - return "did not get expected error" - case !w && got != nil: - return fmt.Sprintf("got err=%v, want err=nil", got) - } - return "" - case codes.Code: - return Code(got, w) - case string: - return Substring(got, w) - case error: - switch { - case got == nil && w == nil: - return "" - case got == nil && w != nil: - return fmt.Sprintf("got err=nil, want err=%v", w) - case w == nil: - return fmt.Sprintf("got err=%v, want err=nil", got) - case got.Error() == w.Error(): - return "" - default: - return fmt.Sprintf("got err=%v, want err=%v", got, w) - } - default: - return fmt.Sprintf("unsupported type in Check: %T", want) - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/errdiff/errdiff_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/errdiff/errdiff_test.go deleted file mode 100644 index a7dda6146..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/errdiff/errdiff_test.go +++ /dev/null @@ -1,211 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 errdiff - -import ( - "errors" - "io" - "strings" - "testing" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc" -) - -func TestText(t *testing.T) { - tests := []struct { - desc string - got error - want string - result string - }{ - {desc: "empty error"}, - {desc: "match", got: errors.New("abc"), want: "abc", result: ""}, - {desc: "message no match", got: errors.New("ab"), want: "abc", result: `got err=ab, want err with exact text abc`}, - {desc: "want nil", got: errors.New("ab"), result: `got err=ab, want err=nil`}, - {desc: "want nil got message", got: errors.New(""), result: `got err=, want err=nil`}, - } - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - if got := Text(tt.got, tt.want); got != tt.result { - t.Errorf("Text(%v, %v): got=%q want=%q", tt.got, tt.want, got, tt.result) - } - }) - } -} - -func TestSubstring(t *testing.T) { - tests := []struct { - desc string - got error - want string - result string - }{ - {desc: "empty"}, - {desc: "subsring match", got: errors.New("abc"), want: "bc", result: ""}, - {desc: "exact match", got: errors.New("abc"), want: "abc", result: ""}, - {desc: "message no match", got: errors.New("ab"), want: "abc", result: `got err=ab, want err containing abc`}, - {desc: "want nil", got: errors.New("ab"), result: `got err=ab, want err=nil`}, - {desc: "want nil got message", got: errors.New(""), result: `got err=, want err=nil`}, - } - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - if got := Substring(tt.got, tt.want); got != tt.result { - t.Errorf("Substring(%v, %v): got=%q want=%q", tt.got, tt.want, got, tt.result) - } - if got := Check(tt.got, tt.want); got != tt.result { - t.Errorf("Check(%v, %v): got=%q want=%q", tt.got, tt.want, got, tt.result) - } - }) - } -} - -func TestCode(t *testing.T) { - tests := []struct { - desc string - got error - want codes.Code - result string - }{ - {desc: "empty message"}, - { - desc: "Unimplemented match", - got: grpc.Errorf(codes.Unimplemented, ""), - want: codes.Unimplemented, - result: "", - }, - { - desc: "code no match", - got: grpc.Errorf(codes.Unimplemented, ""), - want: codes.InvalidArgument, - result: `got err=rpc error: code = Unimplemented desc = , want code InvalidArgument`, - }, - { - desc: "nil match", - got: grpc.Errorf(codes.Unimplemented, ""), - result: `got err=rpc error: code = Unimplemented desc = , want OK`, - }, - { - desc: "no code", - got: errors.New("other"), - want: codes.InvalidArgument, - result: `got err=other, want code InvalidArgument`, - }, - } - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - if got := Code(tt.got, tt.want); got != tt.result { - t.Errorf("CodeCompare(%v, %v): got=%q want=%q", tt.got, tt.want, got, tt.result) - } - if got := Check(tt.got, tt.want); got != tt.result { - t.Errorf("Check(%v, %v): got=%q want=%q", tt.got, tt.want, got, tt.result) - } - }) - } -} - -type elist []string - -func (e elist) Error() string { return strings.Join(e, ", ") } - -func TestCheck(t *testing.T) { - elist1 := elist{"error1a", "error1b"} - elist2 := elist{"error2a", "error2b"} - - tests := []struct { - desc string - got error - want interface{} - result string - }{ - {desc: "empty"}, - { - desc: "exact same error", - got: io.EOF, - want: io.EOF, - }, - { - desc: "different errors with same string", - want: errors.New("an error"), - got: errors.New("an error"), - }, - { - desc: "nil want", - got: io.EOF, - result: `got err=EOF, want err=nil`, - }, - { - desc: "nil got", - want: io.EOF, - result: `got err=nil, want err=EOF`, - }, - { - desc: "different error", - want: errors.New("this error"), - got: errors.New("that error"), - result: `got err=that error, want err=this error`, - }, - { - desc: "do not want error", - want: false, - }, - { - desc: "do want error", - want: true, - result: `did not get expected error`, - }, - { - desc: "got err=error, want err=none", - got: io.EOF, - want: false, - result: `got err=EOF, want err=nil`, - }, - { - desc: "got error, want error", - got: io.EOF, - want: true, - }, - { - desc: "unexpected errlist", - got: elist1, - result: `got err=error1a, error1b, want err=nil`, - }, - { - desc: "missing errlist", - want: elist1, - result: `got err=nil, want err=error1a, error1b`, - }, - { - desc: "correct errlist", - got: elist1, - want: elist1, - }, - { - desc: "wrong errlist", - got: elist1, - want: elist2, - result: `got err=error1a, error1b, want err=error2a, error2b`, - }, - } - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - if got := Check(tt.got, tt.want); got != tt.result { - t.Errorf("Check(%v, %v): got=%q want=%q", tt.got, tt.want, got, tt.result) - } - }) - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/errlist/errlist.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/errlist/errlist.go deleted file mode 100644 index 248339495..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/errlist/errlist.go +++ /dev/null @@ -1,171 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 errlist implents an error type that contains a list of other errors. -// The provided Add function correctly handles nil so it may be unconditionally -// called with an error, even if the error is nil. -// -// Package errlist exports two types, List and Error. List is always used to -// construct a list of errors, and Error is used when introspecting an error. -// List does not implement the error interface to prevent an empty list from -// being returned. -// -// EXAMPLE -// -// func checkStrings(source []string) error { -// var errs errlist.List -// for _, s := range source { -// errs.Add(check(s)) -// } -// return errs.Err() -// } -// -// func check(s string) error { -// if len(s) < 1 || len(s) > 5 { -// return fmt.Errorf("bad string: %q", s) -// } -// return nil -// } -// -// -// func errHasPrefix(err error, prefix string) bool { -// switch errs := err.(type) { -// case errlist.Error: -// for _, err := range errs.Errors() { -// if errHasPrefix(err, prefix) { -// return true -// } -// } -// default: -// return strings.HasPrefix(err.Error(), prefix) -// } -// return false -// } -package errlist - -import ( - "reflect" - "strings" -) - -// Separator is used to separate error messages when calling Error on a list. -// Only package main should set Separator. It should only be set in an init -// function defined in the main package. -var Separator = ", " - -// An Error is a list of errors and implements the error interface. An Error -// should never be declared directly, use a List and then it's Err -// method to return a proper error. -type Error struct { - List -} - -// List is the working representation of an Error, it does not implement -// the error interface. Use the Add method to add errors to a List. -// -// Separator may optionally be set as the string to separate errors when -// displayed. If not set, it defaults to the global Separator value. -type List struct { - Separator string - errors []error -} - -// Errors is implemented by error types that can return lists of errors. -type Errors interface { - // Errors returns the list of errors associated with the recevier. It - // returns nil if there are no errors associated with the recevier. - Errors() []error -} - -// etype is used for detecting types that are simply slices of error. -var etype = reflect.TypeOf([]error{}) - -// Add adds all non-nil errs to the list of errors in e and returns true if errs -// contains a non-nil error. If no non-nil errors are passed Add does nothing -// and returns false. Add will never add a nil error to the List. If err -// implementes the Errors interface or its underlying type is a slice of errors -// then e.Add is called on each individual error. -func (e *List) Add(errs ...error) bool { - added := false - for _, err := range errs { - if err != nil { - if el, ok := err.(Errors); ok { - errs := el.Errors() - if len(errs) == 0 { - continue - } - e.errors = append(e.errors, errs...) - added = true - continue - } - if rv := reflect.ValueOf(err); rv.Type().AssignableTo(etype) { - a := false - n := rv.Len() - for i := 0; i < n; i++ { - errI, ok := rv.Index(i).Interface().(error) - if ok { - a = e.Add(errI) || a - } - } - added = added || a - continue - } - e.errors = append(e.errors, err) - added = true - } - } - return added -} - -// Reset resets the error list in e to nil. -func (e *List) Reset() { - e.errors = nil -} - -// Append implements the deprecated usage of the previous errlist package. -// Use Add instead. -func (e *List) Append(err error) { - e.Add(err) -} - -// Err returns e as an error of type Error if e has errors, or nil. -func (e List) Err() error { - if len(e.errors) == 0 { - return nil - } - return Error{e} -} - -// Error implements the error interface. -func (e Error) Error() string { - sep := e.Separator - if sep == "" { - sep = Separator - } - msgs := make([]string, len(e.errors)) - for x, err := range e.errors { - msgs[x] = err.Error() - } - return strings.Join(msgs, sep) -} - -// Errors returns the list of errors in e, or nil if e has no errors. -func (e Error) Errors() []error { - if len(e.errors) > 0 { - return e.errors - } - return nil -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/errlist/errlist_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/errlist/errlist_test.go deleted file mode 100644 index 91370f332..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/errlist/errlist_test.go +++ /dev/null @@ -1,159 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 errlist_test - -// Use package errlist_test rather than errlist to prevent the tests from having -// any internal access to the actual List or Error types. - -import ( - "errors" - "strings" - "testing" - - "github.com/openconfig/gnmi/errlist" -) - -func TestNil(t *testing.T) { - var err errlist.List - - func(e error) { - if e != nil { - t.Error("did not get expected nil") - } - }(err.Err()) -} - -func TestInteface(t *testing.T) { - var err errlist.List - var i interface{} - i = err - - if _, ok := i.(error); ok { - t.Error("List implements error, it should not") - } - err.Add(errors.New("some error")) - i = err.Err() - if _, ok := i.(error); !ok { - t.Error("List.Err does not implement error, it should") - } -} - -func errsEqual(a, b []error) bool { - if len(a) != len(b) { - return false - } - for x, s := range a { - if b[x] != s { - return false - } - } - return true -} - -func TestAdd(t *testing.T) { - var err errlist.List - errs := []error{ - errors.New("error 1"), - errors.New("error 2"), - errors.New("error 3"), - } - - check := func(i int, err error) { - switch { - case err == nil && i == 0: - case err == nil: - t.Errorf("#%d: got nil, expected errors", i) - case i == 0: - t.Errorf("#%d: got unexpected errors: %v", i, err) - default: - e := err.(errlist.Error).Errors() - if !errsEqual(errs[:i], e) { - t.Errorf("#%d: got %v, want %v", i, e, errs[:i]) - } - } - } - err.Add(nil) // should be a no-op - check(0, err.Err()) - for i, e := range errs { - err.Add(e) - err.Add(nil) // should be a no-op - check(i+1, err.Err()) - } -} - -// elist implements the error interface. -type elist []error - -func (e elist) Err() error { return e } -func (e elist) Error() string { - var m []string - for _, err := range e { - m = append(m, err.Error()) - } - // We use :: to join to be different from what errlist.Error will - // use to join. - return strings.Join(m, "::") -} - -func TestAddList(t *testing.T) { - var err, err1 errlist.List - err.Add(err1.Err()) - if e := err.Err(); e != nil { - t.Fatalf("got error %v, want nil", e) - } - err1.Add(errors.New("error1")) - err1.Add(errors.New("error2")) - err.Add(err1.Err()) - - er := err.Err() - - switch e := er.(type) { - case errlist.Error: - if n := len(e.Errors()); n != 2 { - t.Fatalf("got %d errors, want 2", n) - } - default: - t.Fatalf("got error type %T, want errlist.Error", er) - } - - var errNil error - el := elist{nil, errors.New("error3"), errors.New("error4"), errNil} - err.Add(el.Err()) - - if got, want := err.Err().Error(), "error1, error2, error3, error4"; got != want { - t.Fatalf("got error %q, want %q", got, want) - } -} - -func TestSep(t *testing.T) { - var list errlist.List - defer func(s string) { errlist.Separator = s }(errlist.Separator) - errlist.Separator = ":" - - list.Add(errors.New("one")) - list.Add(errors.New("two")) - err := list.Err() - if got, want := err.Error(), "one:two"; got != want { - t.Errorf("got %q, want %q", got, want) - } - - list.Separator = "-" - err = list.Err() - if got, want := err.Error(), "one-two"; got != want { - t.Errorf("got %q, want %q", got, want) - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/match/match.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/match/match.go deleted file mode 100644 index d25ff53d0..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/match/match.go +++ /dev/null @@ -1,143 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 match builds a tree of active subscriptions that is matched against -// all incoming updates. -package match - -import ( - "sync" -) - -// Glob is a special string used to indicate a match of any path node. -const Glob = "*" - -// Client is a interface for a callback invoked for all matching updates. -type Client interface { - Update(interface{}) -} - -type branch struct { - clients map[Client]struct{} - children map[string]*branch -} - -// Match is a structure that will invoke registered query callbacks for each -// matching update. -type Match struct { - mu sync.RWMutex - tree *branch -} - -// New creates a new Match structure. -func New() *Match { - return &Match{tree: &branch{}} -} - -// AddQuery registers a client callback for all matching nodes. It returns a -// callback to remove the query. The remove function is idempotent. -func (m *Match) AddQuery(query []string, client Client) (remove func()) { - defer m.mu.Unlock() - m.mu.Lock() - m.tree.addQuery(query, client) - return func() { - defer m.mu.Unlock() - m.mu.Lock() - m.tree.removeQuery(query, client) - } -} - -func (b *branch) addQuery(query []string, client Client) { - if len(query) == 0 { - if b.clients == nil { - b.clients = map[Client]struct{}{} - } - b.clients[client] = struct{}{} - return - } - if b.children == nil { - b.children = map[string]*branch{} - } - sb, ok := b.children[query[0]] - if !ok { - sb = &branch{} - b.children[query[0]] = sb - } - sb.addQuery(query[1:], client) -} - -func (b *branch) removeQuery(query []string, client Client) (empty bool) { - defer func() { - empty = (len(b.clients) == 0 && len(b.children) == 0) - }() - if len(query) == 0 { - if b.clients != nil { - delete(b.clients, client) - } - return - } - sb, ok := b.children[query[0]] - if !ok { - return - } - if sb.removeQuery(query[1:], client) { - delete(b.children, query[0]) - } - return -} - -// Update invokes all client callbacks for queries that match the supplied node. -func (m *Match) Update(n interface{}, p []string) { - defer m.mu.RUnlock() - m.mu.RLock() - m.tree.update(n, p) -} - -func (b *branch) update(n interface{}, path []string) { - // Update all clients at this level. - for client := range b.clients { - client.Update(n) - } - // Terminate recursion. - if len(b.children) == 0 { - return - } - // Implicit recursion for intermediate deletes. - if len(path) == 0 { - for _, c := range b.children { - c.update(n, nil) - } - return - } - // This captures only target delete gnmi.Notification as it is going - // to have Glob in the path elem in addition to device name. - // For target delete client.Notification, device name is sufficient, - // so it will not satisfy this case. - if path[0] == Glob { - for _, c := range b.children { - c.update(n, path[1:]) - } - } else { - // Update all glob clients. - if sb, ok := b.children[Glob]; ok { - sb.update(n, path[1:]) - } - // Update all explicit clients. - if sb, ok := b.children[path[0]]; ok { - sb.update(n, path[1:]) - } - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/match/match_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/match/match_test.go deleted file mode 100644 index 00b52efef..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/match/match_test.go +++ /dev/null @@ -1,307 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 match - -import ( - "reflect" - "testing" -) - -type stored struct { - ph []string -} - -type testClient struct { - updates []stored -} - -type testQuery struct { - client testClient - query []string - match []stored - noMatch []stored - remove func() -} - -func (t *testClient) Update(n interface{}) { - t.updates = append(t.updates, n.(stored)) -} - -func TestClient(t *testing.T) { - tests := []*testQuery{ - { - query: []string{}, - match: []stored{ - {ph: []string{"a"}}, - {ph: []string{"a", "b"}}, - {ph: []string{"a", "b", "c", "d", "e", "f", "g"}}, - }, - }, { - query: []string{Glob}, - match: []stored{ - {ph: []string{"a"}}, - {ph: []string{"a", "b"}}, - {ph: []string{"a", "b", "c", "d", "e", "f", "g"}}, - }, - }, { - query: []string{"a"}, - match: []stored{ - {ph: []string{"a"}}, - {ph: []string{"a", "b"}}, - {ph: []string{"a", "b", "c", "d", "e", "f", "g"}}, - }, - noMatch: []stored{ - {ph: []string{"b"}}, - {ph: []string{"c"}}, - {ph: []string{"d", "e", "f", "g"}}, - }, - }, { - query: []string{"a", "b"}, - match: []stored{ - {ph: []string{"a"}}, // Target delete. - {ph: []string{"a", "b"}}, - {ph: []string{"a", "b", "c", "d", "e", "f", "g"}}, - }, - noMatch: []stored{ - {ph: []string{"a", "c"}}, - {ph: []string{"b"}}, - {ph: []string{"c"}}, - {ph: []string{"d", "e", "f", "g"}}, - }, - }, { - query: []string{"a", "b", Glob}, - match: []stored{ - {ph: []string{"a"}}, // Target delete. - {ph: []string{"a", "b"}}, // Intermediate delete. - {ph: []string{"a", "b", "c", "d", "e", "f", "g"}}, - }, - noMatch: []stored{ - {ph: []string{"a", "c"}}, - {ph: []string{"b"}}, - {ph: []string{"c"}}, - {ph: []string{"d", "e", "f", "g"}}, - }, - }, { - query: []string{Glob, "b"}, - match: []stored{ - {ph: []string{"a"}}, // Target delete. - {ph: []string{"b"}}, // Target delete. - {ph: []string{"c"}}, // Target delete. - {ph: []string{"a", "b"}}, - {ph: []string{"a", "b", "c", "d", "e", "f", "g"}}, - {ph: []string{"e", "b", "y"}}, - }, - noMatch: []stored{ - {ph: []string{"a", "c"}}, - {ph: []string{"d", "e", "f", "g"}}, - }, - }, { - query: []string{"a", "b", "*", "d", "e", "f", "g"}, - match: []stored{ - {ph: []string{"a"}}, // Target delete. - {ph: []string{"a", "b"}}, - {ph: []string{"a", "b", "c"}}, - {ph: []string{"a", "b", "c", "d"}}, - {ph: []string{"a", "b", "c", "d", "e"}}, - {ph: []string{"a", "b", "c", "d", "e", "f"}}, - {ph: []string{"a", "b", "c", "d", "e", "f", "g"}}, - {ph: []string{"a", "b", "c", "d", "e", "f", "g"}}, - }, - noMatch: []stored{ - {ph: []string{"a", "c"}}, - {ph: []string{"d", "e", "f", "g"}}, - }, - }, - } - for _, tt := range tests { - match := New() - remove := match.AddQuery(tt.query, &tt.client) - for _, m := range tt.match { - match.Update(m, m.ph) - } - for _, m := range tt.noMatch { - match.Update(m, m.ph) - } - if !reflect.DeepEqual(tt.client.updates, tt.match) { - t.Errorf("query %q got updates %q, want %q", tt.query, tt.client.updates, tt.match) - } - remove() - tt.client.updates = nil - for _, m := range tt.match { - match.Update(m, m.ph) - } - for _, m := range tt.noMatch { - match.Update(m, m.ph) - } - if tt.client.updates != nil { - t.Errorf("removed query %q got updates %q, want nil", tt.query, tt.client.updates) - } - } -} - -func TestMultipleClients(t *testing.T) { - updates := []stored{ - {ph: []string{"a"}}, - {ph: []string{"a", "b"}}, - {ph: []string{"a", "b", "c", "d", "e", "f", "g"}}, - {ph: []string{"b"}}, - {ph: []string{"c"}}, - {ph: []string{"d", "e", "f", "g"}}, - {ph: []string{"e", "b", "y"}}, - } - tests := []*testQuery{ - { - query: []string{}, - match: []stored{ - {ph: []string{"a"}}, - {ph: []string{"a", "b"}}, - {ph: []string{"a", "b", "c", "d", "e", "f", "g"}}, - {ph: []string{"b"}}, - {ph: []string{"c"}}, - {ph: []string{"d", "e", "f", "g"}}, - {ph: []string{"e", "b", "y"}}, - }, - }, { - query: []string{Glob}, - match: []stored{ - {ph: []string{"a"}}, - {ph: []string{"a", "b"}}, - {ph: []string{"a", "b", "c", "d", "e", "f", "g"}}, - {ph: []string{"b"}}, - {ph: []string{"c"}}, - {ph: []string{"d", "e", "f", "g"}}, - {ph: []string{"e", "b", "y"}}, - }, - }, { - query: []string{"a"}, - match: []stored{ - {ph: []string{"a"}}, - {ph: []string{"a", "b"}}, - {ph: []string{"a", "b", "c", "d", "e", "f", "g"}}, - }, - }, { - query: []string{"a", "b"}, - match: []stored{ - {ph: []string{"a"}}, // Target delete. - {ph: []string{"a", "b"}}, - {ph: []string{"a", "b", "c", "d", "e", "f", "g"}}, - }, - }, { - query: []string{"b"}, - match: []stored{ - {ph: []string{"b"}}, - }, - }, { - query: []string{"q"}, - }, - } - match := New() - // Add one query at a time. - for x, tt := range tests { - for _, tt := range tests { - tt.client.updates = nil - } - tt.remove = match.AddQuery(tt.query, &tt.client) - for _, u := range updates { - match.Update(u, u.ph) - } - for _, tt := range tests[:x+1] { - if !reflect.DeepEqual(tt.client.updates, tt.match) { - t.Errorf("query %q got updates %q, want %q", tt.query, tt.client.updates, tt.match) - } - } - } - // Remove one query at a time. - for x, tt := range tests { - for _, tt := range tests { - tt.client.updates = nil - } - tt.remove() - for _, u := range updates { - match.Update(u, u.ph) - } - for _, tt := range tests[x+1:] { - if !reflect.DeepEqual(tt.client.updates, tt.match) { - t.Errorf("query %q got updates %q, want %q", tt.query, tt.client.updates, tt.match) - } - } - } -} - -type globTestClient struct { - match bool -} - -type globQuery struct { - client globTestClient - query []string - expect bool - remove func() -} - -func (t *globTestClient) Update(n interface{}) { - t.match = true -} - -func TestGlobUpdates(t *testing.T) { - tests := []struct { - update stored - queries []*globQuery - }{ - // test updates with Glob at the end of the path - { - update: stored{ph: []string{"a", Glob}}, - queries: []*globQuery{ - &globQuery{query: []string{"a"}, expect: true}, - &globQuery{query: []string{"a", Glob}, expect: true}, - &globQuery{query: []string{"a", "b"}, expect: true}, - &globQuery{query: []string{"b"}, expect: false}, - }, - }, - // test updates with Glob in the middle of the path - { - update: stored{ph: []string{"a", Glob, "b"}}, - queries: []*globQuery{ - &globQuery{query: []string{"a"}, expect: true}, - &globQuery{query: []string{"a", Glob}, expect: true}, - &globQuery{query: []string{"a", "b"}, expect: true}, - &globQuery{query: []string{"a", "c", "b"}, expect: true}, - &globQuery{query: []string{"a", "c", "c"}, expect: false}, - &globQuery{query: []string{"a", Glob, "b"}, expect: true}, - &globQuery{query: []string{"a", Glob, "c"}, expect: false}, - &globQuery{query: []string{"b"}, expect: false}, - }, - }, - } - - for i, tt := range tests { - match := New() - // register all the queries - for _, q := range tt.queries { - q.remove = match.AddQuery(q.query, &q.client) - } - match.Update(tt.update, tt.update.ph) - for j, q := range tt.queries { - if q.client.match != q.expect { - t.Errorf("#%d update message %v; #%d query path %v; got %v, want %v", i, tt.update.ph, j, q.query, q.client.match, q.expect) - } - } - for _, q := range tt.queries { - q.remove() - } - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/metadata/metadata.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/metadata/metadata.go deleted file mode 100644 index 1c339d927..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/metadata/metadata.go +++ /dev/null @@ -1,211 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 metadata describes metadata paths stored in the cache per target. -package metadata - -import ( - "errors" - "sync" -) - -const ( - // Root node where metadata is cached. - Root = "meta" - - // Per-target metadata - - // Sync is a boolean that reports whether all target state is cached. - Sync = "sync" - // Connected is a boolean that reports whether updates are being received. - Connected = "connected" - // AddCount is the total number of leaves that have been added. - AddCount = "targetLeavesAdded" - // DelCount is the total number of leaves that have been deleted. - DelCount = "targetLeavesDeleted" - // LeafCount is the current total leaves stored in the cache. - LeafCount = "targetLeaves" - // UpdateCount is the total number of leaf updates received. - UpdateCount = "targetLeavesUpdated" - // StaleCount is the total number of leaf updates that had timestamp older - // than that cached. - StaleCount = "targetLeavesStale" - // SuppressedCount is the total number of leaf updates that were suppressed - // because the update had the same value as already cached. - SuppressedCount = "targetLeavesSuppressed" - // LatencyAvg is the average latency between target timestamp and cache - // reception. - LatencyAvg = "latencyAvg" - // LatencyMax is the maximum latency between target timestamp and cache - // reception. - LatencyMax = "latencyMax" - // LatencyMin is the minimum latency between target timestamp and cache - // reception. - LatencyMin = "latencyMin" - // Size is the total number of bytes used to store all values. This count - // excludes all indexing overhead. - Size = "targetSize" - // LatestTimestamp is the latest timestamp for any update received for the - // target. - LatestTimestamp = "latestTimestamp" -) - -var ( - // TargetBoolValues is the list of all bool metadata fields. - TargetBoolValues = map[string]bool{ - Sync: true, - Connected: true, - } - - // TargetIntValues is the list of all int64 metadata fields. - TargetIntValues = map[string]bool{ - AddCount: true, - DelCount: true, - LeafCount: true, - UpdateCount: true, - StaleCount: true, - SuppressedCount: true, - LatencyAvg: true, - LatencyMax: true, - LatencyMin: true, - Size: true, - LatestTimestamp: true, - } -) - -// Metadata is the container for all target specific metadata. -type Metadata struct { - mu sync.Mutex - valuesInt map[string]int64 - valuesBool map[string]bool -} - -// Path is a convenience function that will return the full metadata path for -// any valid metadata value. Only metadata values registered above in -// TargetBoolValues and TargetIntValues will return a path. An invalid metadata -// value will return nil. -func Path(value string) []string { - if TargetBoolValues[value] || TargetIntValues[value] { - return []string{Root, value} - } - return nil -} - -// New returns an initialized Metadata structure. Integer values are -// initialized to 0 and boolean values are initialized to false. -func New() *Metadata { - m := Metadata{ - valuesInt: make(map[string]int64, len(TargetIntValues)), - valuesBool: make(map[string]bool, len(TargetBoolValues)), - } - m.Clear() - return &m -} - -// ErrInvalidValue is returned when a metadata operation is attempted on a value -// that does not exist. -var ErrInvalidValue = errors.New("invalid metadata value") - -func validInt(value string) error { - if valid := TargetIntValues[value]; !valid { - return ErrInvalidValue - } - return nil -} - -func validBool(value string) error { - if valid := TargetBoolValues[value]; !valid { - return ErrInvalidValue - } - return nil -} - -// Clear sets all metadata values to zero values. -func (m *Metadata) Clear() { - m.mu.Lock() - defer m.mu.Unlock() - for k := range TargetBoolValues { - m.valuesBool[k] = false - } - for k := range TargetIntValues { - m.valuesInt[k] = 0 - } -} - -// AddInt atomically increments the metadata value specified by i. -func (m *Metadata) AddInt(value string, i int64) error { - if err := validInt(value); err != nil { - return err - } - m.mu.Lock() - m.valuesInt[value] += i - m.mu.Unlock() - return nil -} - -// SetInt atomically sets the metadata value specified to v. -func (m *Metadata) SetInt(value string, v int64) error { - if err := validInt(value); err != nil { - return err - } - m.mu.Lock() - m.valuesInt[value] = v - m.mu.Unlock() - return nil -} - -// ErrUnsetValue is returned when a metadata Get is attempted on a value that -// has not been Set (or Added). -var ErrUnsetValue = errors.New("unset value") - -// GetInt atomically retrieves the metadata value specified. -func (m *Metadata) GetInt(value string) (int64, error) { - if err := validInt(value); err != nil { - return 0, err - } - m.mu.Lock() - v, ok := m.valuesInt[value] - m.mu.Unlock() - if !ok { - return 0, ErrUnsetValue - } - return v, nil -} - -// SetBool atomically sets the metadata value specified to v. -func (m *Metadata) SetBool(value string, v bool) error { - if err := validBool(value); err != nil { - return err - } - m.mu.Lock() - m.valuesBool[value] = v - m.mu.Unlock() - return nil -} - -// GetBool atomically retrieves the metadata value specified. -func (m *Metadata) GetBool(value string) (bool, error) { - if err := validBool(value); err != nil { - return false, err - } - m.mu.Lock() - v, ok := m.valuesBool[value] - m.mu.Unlock() - if !ok { - return false, ErrUnsetValue - } - return v, nil -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/metadata/metadata_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/metadata/metadata_test.go deleted file mode 100644 index cda65fec3..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/metadata/metadata_test.go +++ /dev/null @@ -1,135 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 metadata - -import "testing" - -func TestPath(t *testing.T) { - if path := Path("invalid"); path != nil { - t.Errorf("Path(%q) returned %v for invalid value.", "invalid", path) - } - for value := range TargetBoolValues { - if path := Path(value); path == nil { - t.Errorf("Path(%q) returned nil for valid value.", value) - } - } - for value := range TargetIntValues { - if path := Path(value); path == nil { - t.Errorf("Path(%q) returned nil for valid value.", value) - } - } -} - -func TestGetInt(t *testing.T) { - m := New() - for value := range TargetIntValues { - v, err := m.GetInt(value) - switch { - case err != nil: - t.Errorf("GetInt(%q) got error: %q, want nil", value, err) - case v != 0: - t.Errorf("GetInt(%q) got %d for uninitialized value, want 0", value, v) - } - } -} - -func TestGetBool(t *testing.T) { - m := New() - for value := range TargetBoolValues { - v, err := m.GetBool(value) - switch { - case err != nil: - t.Errorf("GetBool(%q) got error: %q, want nil", value, err) - case v != false: - t.Errorf("GetBool(%q) got %t for uninitialized value, want false", value, v) - } - } -} - -func TestAddGetInt(t *testing.T) { - m := New() - if err := m.AddInt("invalid", 1); err != ErrInvalidValue { - t.Error("AddInt accepted invalid metadata value.") - } - for i := 1; i < 6; i++ { - for value := range TargetIntValues { - if err := m.AddInt(value, 1); err != nil { - t.Errorf("AddInt(%q, 1) returned error: %v", value, err) - } - got, err := m.GetInt(value) - if err != nil { - t.Errorf("GetInt(%q) returned error: %v", value, err) - continue - } - want := int64(i) - if got != want { - t.Errorf("%d: GetInt(%q): got %d, want %d", i, value, got, want) - } - } - } - if _, err := m.GetInt("invalid"); err != ErrInvalidValue { - t.Error("GetInt accepted invalid metadata value.") - } -} - -func TestSetGetInt(t *testing.T) { - m := New() - if err := m.SetInt("invalid", 1); err != ErrInvalidValue { - t.Error("SetInt accepted invalid metadata value.") - } - for i := 0; i < 10; i++ { - var x int - for value := range TargetIntValues { - x++ - want := int64(x + i) - if err := m.SetInt(value, want); err != nil { - t.Errorf("SetInt(%q, %d) returned error: %v", value, want, err) - } - got, err := m.GetInt(value) - if err != nil { - t.Errorf("GetInt(%q) returned error: %v", value, err) - } - if got != want { - t.Errorf("GetInt(%q): got %d, want %d", value, got, want) - } - } - } -} - -func TestSetGetBool(t *testing.T) { - m := New() - if err := m.SetBool("invalid", true); err != ErrInvalidValue { - t.Error("SetBool accepted invalid metadata value.") - } - for _, want := range []bool{true, false, true, false} { - for value := range TargetBoolValues { - if err := m.SetBool(value, want); err != nil { - t.Errorf("SetBool(%q, %t) returned error: %v", value, want, err) - } - got, err := m.GetBool(value) - if err != nil { - t.Errorf("GetBool(%q) returned error: %v", value, err) - } - if got != want { - t.Errorf("GetBool(%q): got %t, want %t", value, got, want) - } - } - } - if _, err := m.GetBool("invalid"); err != ErrInvalidValue { - t.Error("GetBool accepted invalid metadata value.") - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/path/path.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/path/path.go deleted file mode 100644 index df2c32b72..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/path/path.go +++ /dev/null @@ -1,115 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 path provides utility functions to convert a given gnmi.Path -// into index strings. -package path - -import ( - "errors" - "sort" - - gpb "github.com/openconfig/gnmi/proto/gnmi" -) - -// ToStrings converts gnmi.Path to index strings. When index strings are generated, -// gnmi.Path will be irreversibly lost. Index strings will be built by using name field -// in gnmi.PathElem. If gnmi.PathElem has key field, values will be included in -// alphabetical order of the keys. -// E.g. //a/b[b:d, a:c]/e will be returned as //a/b/c/d/e -// If prefix parameter is set to true, and fields of -// the gnmi.Path will be prepended in the index strings unless they are empty string. -// gnmi.Path.Element field is deprecated, but being gracefully handled by this function -// in the absence of gnmi.Path.Elem. -func ToStrings(p *gpb.Path, prefix bool) []string { - is := []string{} - if p == nil { - return is - } - if prefix { - // add target to the list of index strings - if t := p.GetTarget(); t != "" { - is = append(is, t) - } - // add origin to the list of index strings - if o := p.GetOrigin(); o != "" { - is = append(is, o) - } - } - pe := []string{} - for _, e := range p.GetElem() { - pe = append(pe, e.GetName()) - pe = append(pe, sortedVals(e.GetKey())...) - } - // gnmi.Path.Element is deprecated, but being gracefully handled - // when gnmi.PathElem doesn't exist - if len(pe) > 0 { - is = append(is, pe...) - } else { - is = append(is, p.GetElement()...) - } - return is -} - -func sortedVals(m map[string]string) []string { - // Special case single key lists. - if len(m) == 1 { - for _, v := range m { - return []string{v} - } - } - // Return deterministic ordering of multi-key lists. - ks := make([]string, 0, len(m)) - for k := range m { - ks = append(ks, k) - } - sort.Strings(ks) - vs := make([]string, 0, len(m)) - for _, k := range ks { - vs = append(vs, m[k]) - } - return vs -} - -// CompletePath joins provided prefix and subscription paths. Also, verifies -// whether origin is set properly according to: -// https://github.com/openconfig/reference/blob/master/rpc/gnmi/mixed-schema.md -// Note that this function doesn't add "openconfig" default origin if neither -// prefix nor path specifies the origin. Also, target field isn't prepended in -// the returned path. -func CompletePath(prefix, path *gpb.Path) ([]string, error) { - oPre, oPath := prefix.GetOrigin(), path.GetOrigin() - - var fullPrefix []string - indexedPrefix := ToStrings(prefix, false) - switch { - case oPre != "" && oPath != "": - return nil, errors.New("origin is set both in prefix and path") - case oPre != "": - fullPrefix = append(fullPrefix, oPre) - fullPrefix = append(fullPrefix, indexedPrefix...) - case oPath != "": - if len(indexedPrefix) > 0 { - return nil, errors.New("path elements in prefix are set even though origin is set in path") - } - fullPrefix = append(fullPrefix, oPath) - default: - // Neither prefix nor path specified an origin. Include the path elements in prefix. - fullPrefix = append(fullPrefix, indexedPrefix...) - } - - return append(fullPrefix, ToStrings(path, false)...), nil -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/path/path_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/path/path_test.go deleted file mode 100644 index ce2c0f105..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/path/path_test.go +++ /dev/null @@ -1,199 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 path - -import ( - "reflect" - "testing" - - "github.com/openconfig/gnmi/errdiff" - gpb "github.com/openconfig/gnmi/proto/gnmi" -) - -func TestSortedValues(t *testing.T) { - tests := []struct { - inp map[string]string - exp []string - }{ - { - inp: map[string]string{}, - exp: []string{}, - }, - { - inp: map[string]string{"a": "1", "b": "2"}, - exp: []string{"1", "2"}, - }, - { - inp: map[string]string{"c": "1", "a": "2", "d": "3"}, - exp: []string{"2", "1", "3"}, - }, - } - - for _, tt := range tests { - ret := sortedVals(tt.inp) - if !reflect.DeepEqual(ret, tt.exp) { - t.Errorf("sortedVals(%v) = got %v, want %v", tt.inp, ret, tt.exp) - } - } -} - -func TestToStrings(t *testing.T) { - tests := []struct { - p *gpb.Path - wOd bool - e []string - }{ - // test nil gnmi.Path - { - e: []string{}, - }, - // test non-nil gnmi.Path - { - p: &gpb.Path{}, - e: []string{}, - }, - // test deprecated gnmi.Path.Element - { - p: &gpb.Path{ - Element: []string{"x", "y"}, - }, - e: []string{"x", "y"}, - }, - // test is prepended into index string list - { - p: &gpb.Path{ - Elem: []*gpb.PathElem{ - &gpb.PathElem{Name: "a"}, - &gpb.PathElem{Name: "b", Key: map[string]string{"n": "c"}}, - &gpb.PathElem{Name: "d"}, - }, - Target: "t", - }, - e: []string{"t", "a", "b", "c", "d"}, - wOd: true, - }, - // test missing isn't added to the index string list - { - p: &gpb.Path{ - Elem: []*gpb.PathElem{ - &gpb.PathElem{Name: "a"}, - &gpb.PathElem{Name: "b", Key: map[string]string{"n": "c"}}, - &gpb.PathElem{Name: "d"}, - }, - }, - e: []string{"a", "b", "c", "d"}, - wOd: true, - }, - // test both and are prepended into index string list - { - p: &gpb.Path{ - Elem: []*gpb.PathElem{ - &gpb.PathElem{Name: "a"}, - &gpb.PathElem{Name: "b", Key: map[string]string{"n": "c"}}, - &gpb.PathElem{Name: "d"}, - }, - Target: "t", - Origin: "o", - }, - e: []string{"t", "o", "a", "b", "c", "d"}, - wOd: true, - }, - // test having multiple keys in one gnmi.PathElem - { - p: &gpb.Path{ - Elem: []*gpb.PathElem{ - &gpb.PathElem{Name: "a"}, - &gpb.PathElem{Name: "b", Key: map[string]string{"b": "2", "a": "1", "c": "3"}}, - &gpb.PathElem{Name: "c"}, - }, - }, - e: []string{"a", "b", "1", "2", "3", "c"}, - }, - // multiple gnmi.PathElems have multiple keys in them - { - p: &gpb.Path{ - Elem: []*gpb.PathElem{ - &gpb.PathElem{Name: "a", Key: map[string]string{"l": "2", "k": "1"}}, - &gpb.PathElem{Name: "b", Key: map[string]string{"b": "2", "a": "1", "c": "3"}}, - &gpb.PathElem{Name: "c"}, - }, - }, - e: []string{"a", "1", "2", "b", "1", "2", "3", "c"}, - }, - // missign gnmi.PathElems, but have gnmi.Path.Element - { - p: &gpb.Path{ - Element: []string{"a", "b", "c", "d"}, - }, - e: []string{"a", "b", "c", "d"}, - }, - } - - for _, tt := range tests { - r := ToStrings(tt.p, tt.wOd) - if !reflect.DeepEqual(r, tt.e) { - t.Errorf("ToStrings(%v) = got %v, want %v", tt.p, r, tt.e) - } - } -} - -func TestCompletePath(t *testing.T) { - tests := []struct { - desc string - inPrefix *gpb.Path - inPath *gpb.Path - wantSlice []string - wantErrSubstr string - }{ - { - desc: "origin is just set in prefix", - inPrefix: &gpb.Path{Target: "t", Origin: "o"}, - wantSlice: []string{"o"}, - }, - { - desc: "origin is set both in prefix and path", - inPrefix: &gpb.Path{Target: "t", Origin: "o"}, - inPath: &gpb.Path{Origin: "o"}, - wantErrSubstr: "origin is set both in prefix and path", - }, - { - desc: "origin is set in path, but prefix has path elements", - inPrefix: &gpb.Path{Target: "t", Elem: []*gpb.PathElem{{Name: "e"}}}, - inPath: &gpb.Path{Origin: "o"}, - wantErrSubstr: "path elements in prefix are set even though origin is set in path", - }, - { - desc: "origin is set in path properly", - inPrefix: &gpb.Path{Target: "t"}, - inPath: &gpb.Path{Origin: "o", Elem: []*gpb.PathElem{{Name: "e"}}}, - wantSlice: []string{"o", "e"}, - }, - } - - for _, tt := range tests { - gotSlice, err := CompletePath(tt.inPrefix, tt.inPath) - if diff := errdiff.Substring(err, tt.wantErrSubstr); diff != "" { - t.Errorf("%s: %v", tt.desc, diff) - } - if err != nil { - continue - } - if !reflect.DeepEqual(tt.wantSlice, gotSlice) { - t.Errorf("%s: got %v, want %v", tt.desc, gotSlice, tt.wantSlice) - } - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi/gnmi.pb.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi/gnmi.pb.go deleted file mode 100644 index 09959ac5f..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi/gnmi.pb.go +++ /dev/null @@ -1,2524 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: proto/gnmi/gnmi.proto - -// Package gNMI defines a service specification for the gRPC Network Management -// Interface. This interface is defined to be a standard interface via which -// a network management system ("client") can subscribe to state values, -// retrieve snapshots of state information, and manipulate the state of a data -// tree supported by a device ("target"). -// -// This document references the gNMI Specification which can be found at -// http://github.com/openconfig/reference/blob/master/rpc/gnmi - -package gnmi - -import ( - context "context" - fmt "fmt" - proto "github.com/golang/protobuf/proto" - descriptor "github.com/golang/protobuf/protoc-gen-go/descriptor" - any "github.com/golang/protobuf/ptypes/any" - gnmi_ext "github.com/openconfig/gnmi/proto/gnmi_ext" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - math "math" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -// Encoding defines the value encoding formats that are supported by the gNMI -// protocol. These encodings are used by both the client (when sending Set -// messages to modify the state of the target) and the target when serializing -// data to be returned to the client (in both Subscribe and Get RPCs). -// Reference: gNMI Specification Section 2.3 -type Encoding int32 - -const ( - Encoding_JSON Encoding = 0 - Encoding_BYTES Encoding = 1 - Encoding_PROTO Encoding = 2 - Encoding_ASCII Encoding = 3 - Encoding_JSON_IETF Encoding = 4 -) - -var Encoding_name = map[int32]string{ - 0: "JSON", - 1: "BYTES", - 2: "PROTO", - 3: "ASCII", - 4: "JSON_IETF", -} - -var Encoding_value = map[string]int32{ - "JSON": 0, - "BYTES": 1, - "PROTO": 2, - "ASCII": 3, - "JSON_IETF": 4, -} - -func (x Encoding) String() string { - return proto.EnumName(Encoding_name, int32(x)) -} - -func (Encoding) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{0} -} - -// SubscriptionMode is the mode of the subscription, specifying how the -// target must return values in a subscription. -// Reference: gNMI Specification Section 3.5.1.3 -type SubscriptionMode int32 - -const ( - SubscriptionMode_TARGET_DEFINED SubscriptionMode = 0 - SubscriptionMode_ON_CHANGE SubscriptionMode = 1 - SubscriptionMode_SAMPLE SubscriptionMode = 2 -) - -var SubscriptionMode_name = map[int32]string{ - 0: "TARGET_DEFINED", - 1: "ON_CHANGE", - 2: "SAMPLE", -} - -var SubscriptionMode_value = map[string]int32{ - "TARGET_DEFINED": 0, - "ON_CHANGE": 1, - "SAMPLE": 2, -} - -func (x SubscriptionMode) String() string { - return proto.EnumName(SubscriptionMode_name, int32(x)) -} - -func (SubscriptionMode) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{1} -} - -// Mode of the subscription. -type SubscriptionList_Mode int32 - -const ( - SubscriptionList_STREAM SubscriptionList_Mode = 0 - SubscriptionList_ONCE SubscriptionList_Mode = 1 - SubscriptionList_POLL SubscriptionList_Mode = 2 -) - -var SubscriptionList_Mode_name = map[int32]string{ - 0: "STREAM", - 1: "ONCE", - 2: "POLL", -} - -var SubscriptionList_Mode_value = map[string]int32{ - "STREAM": 0, - "ONCE": 1, - "POLL": 2, -} - -func (x SubscriptionList_Mode) String() string { - return proto.EnumName(SubscriptionList_Mode_name, int32(x)) -} - -func (SubscriptionList_Mode) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{12, 0} -} - -// The operation that was associated with the Path specified. -type UpdateResult_Operation int32 - -const ( - UpdateResult_INVALID UpdateResult_Operation = 0 - UpdateResult_DELETE UpdateResult_Operation = 1 - UpdateResult_REPLACE UpdateResult_Operation = 2 - UpdateResult_UPDATE UpdateResult_Operation = 3 -) - -var UpdateResult_Operation_name = map[int32]string{ - 0: "INVALID", - 1: "DELETE", - 2: "REPLACE", - 3: "UPDATE", -} - -var UpdateResult_Operation_value = map[string]int32{ - "INVALID": 0, - "DELETE": 1, - "REPLACE": 2, - "UPDATE": 3, -} - -func (x UpdateResult_Operation) String() string { - return proto.EnumName(UpdateResult_Operation_name, int32(x)) -} - -func (UpdateResult_Operation) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{19, 0} -} - -// Type of elements within the data tree. -type GetRequest_DataType int32 - -const ( - GetRequest_ALL GetRequest_DataType = 0 - GetRequest_CONFIG GetRequest_DataType = 1 - GetRequest_STATE GetRequest_DataType = 2 - // Data elements marked in the schema as operational. This refers to data - // elements whose value relates to the state of processes or interactions - // running on the device. - GetRequest_OPERATIONAL GetRequest_DataType = 3 -) - -var GetRequest_DataType_name = map[int32]string{ - 0: "ALL", - 1: "CONFIG", - 2: "STATE", - 3: "OPERATIONAL", -} - -var GetRequest_DataType_value = map[string]int32{ - "ALL": 0, - "CONFIG": 1, - "STATE": 2, - "OPERATIONAL": 3, -} - -func (x GetRequest_DataType) String() string { - return proto.EnumName(GetRequest_DataType_name, int32(x)) -} - -func (GetRequest_DataType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{20, 0} -} - -// Notification is a re-usable message that is used to encode data from the -// target to the client. A Notification carries two types of changes to the data -// tree: -// - Deleted values (delete) - a set of paths that have been removed from the -// data tree. -// - Updated values (update) - a set of path-value pairs indicating the path -// whose value has changed in the data tree. -// Reference: gNMI Specification Section 2.1 -type Notification struct { - Timestamp int64 `protobuf:"varint,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` - Prefix *Path `protobuf:"bytes,2,opt,name=prefix,proto3" json:"prefix,omitempty"` - // An alias for the path specified in the prefix field. - // Reference: gNMI Specification Section 2.4.2 - Alias string `protobuf:"bytes,3,opt,name=alias,proto3" json:"alias,omitempty"` - Update []*Update `protobuf:"bytes,4,rep,name=update,proto3" json:"update,omitempty"` - Delete []*Path `protobuf:"bytes,5,rep,name=delete,proto3" json:"delete,omitempty"` - // This notification contains a set of paths that are always updated together - // referenced by a globally unique prefix. - Atomic bool `protobuf:"varint,6,opt,name=atomic,proto3" json:"atomic,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Notification) Reset() { *m = Notification{} } -func (m *Notification) String() string { return proto.CompactTextString(m) } -func (*Notification) ProtoMessage() {} -func (*Notification) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{0} -} - -func (m *Notification) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Notification.Unmarshal(m, b) -} -func (m *Notification) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Notification.Marshal(b, m, deterministic) -} -func (m *Notification) XXX_Merge(src proto.Message) { - xxx_messageInfo_Notification.Merge(m, src) -} -func (m *Notification) XXX_Size() int { - return xxx_messageInfo_Notification.Size(m) -} -func (m *Notification) XXX_DiscardUnknown() { - xxx_messageInfo_Notification.DiscardUnknown(m) -} - -var xxx_messageInfo_Notification proto.InternalMessageInfo - -func (m *Notification) GetTimestamp() int64 { - if m != nil { - return m.Timestamp - } - return 0 -} - -func (m *Notification) GetPrefix() *Path { - if m != nil { - return m.Prefix - } - return nil -} - -func (m *Notification) GetAlias() string { - if m != nil { - return m.Alias - } - return "" -} - -func (m *Notification) GetUpdate() []*Update { - if m != nil { - return m.Update - } - return nil -} - -func (m *Notification) GetDelete() []*Path { - if m != nil { - return m.Delete - } - return nil -} - -func (m *Notification) GetAtomic() bool { - if m != nil { - return m.Atomic - } - return false -} - -// Update is a re-usable message that is used to store a particular Path, -// Value pair. -// Reference: gNMI Specification Section 2.1 -type Update struct { - Path *Path `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"` - Value *Value `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` // Deprecated: Do not use. - Val *TypedValue `protobuf:"bytes,3,opt,name=val,proto3" json:"val,omitempty"` - Duplicates uint32 `protobuf:"varint,4,opt,name=duplicates,proto3" json:"duplicates,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Update) Reset() { *m = Update{} } -func (m *Update) String() string { return proto.CompactTextString(m) } -func (*Update) ProtoMessage() {} -func (*Update) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{1} -} - -func (m *Update) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Update.Unmarshal(m, b) -} -func (m *Update) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Update.Marshal(b, m, deterministic) -} -func (m *Update) XXX_Merge(src proto.Message) { - xxx_messageInfo_Update.Merge(m, src) -} -func (m *Update) XXX_Size() int { - return xxx_messageInfo_Update.Size(m) -} -func (m *Update) XXX_DiscardUnknown() { - xxx_messageInfo_Update.DiscardUnknown(m) -} - -var xxx_messageInfo_Update proto.InternalMessageInfo - -func (m *Update) GetPath() *Path { - if m != nil { - return m.Path - } - return nil -} - -// Deprecated: Do not use. -func (m *Update) GetValue() *Value { - if m != nil { - return m.Value - } - return nil -} - -func (m *Update) GetVal() *TypedValue { - if m != nil { - return m.Val - } - return nil -} - -func (m *Update) GetDuplicates() uint32 { - if m != nil { - return m.Duplicates - } - return 0 -} - -// TypedValue is used to encode a value being sent between the client and -// target (originated by either entity). -type TypedValue struct { - // One of the fields within the val oneof is populated with the value - // of the update. The type of the value being included in the Update - // determines which field should be populated. In the case that the - // encoding is a particular form of the base protobuf type, a specific - // field is used to store the value (e.g., json_val). - // - // Types that are valid to be assigned to Value: - // *TypedValue_StringVal - // *TypedValue_IntVal - // *TypedValue_UintVal - // *TypedValue_BoolVal - // *TypedValue_BytesVal - // *TypedValue_FloatVal - // *TypedValue_DecimalVal - // *TypedValue_LeaflistVal - // *TypedValue_AnyVal - // *TypedValue_JsonVal - // *TypedValue_JsonIetfVal - // *TypedValue_AsciiVal - // *TypedValue_ProtoBytes - Value isTypedValue_Value `protobuf_oneof:"value"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *TypedValue) Reset() { *m = TypedValue{} } -func (m *TypedValue) String() string { return proto.CompactTextString(m) } -func (*TypedValue) ProtoMessage() {} -func (*TypedValue) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{2} -} - -func (m *TypedValue) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_TypedValue.Unmarshal(m, b) -} -func (m *TypedValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_TypedValue.Marshal(b, m, deterministic) -} -func (m *TypedValue) XXX_Merge(src proto.Message) { - xxx_messageInfo_TypedValue.Merge(m, src) -} -func (m *TypedValue) XXX_Size() int { - return xxx_messageInfo_TypedValue.Size(m) -} -func (m *TypedValue) XXX_DiscardUnknown() { - xxx_messageInfo_TypedValue.DiscardUnknown(m) -} - -var xxx_messageInfo_TypedValue proto.InternalMessageInfo - -type isTypedValue_Value interface { - isTypedValue_Value() -} - -type TypedValue_StringVal struct { - StringVal string `protobuf:"bytes,1,opt,name=string_val,json=stringVal,proto3,oneof"` -} - -type TypedValue_IntVal struct { - IntVal int64 `protobuf:"varint,2,opt,name=int_val,json=intVal,proto3,oneof"` -} - -type TypedValue_UintVal struct { - UintVal uint64 `protobuf:"varint,3,opt,name=uint_val,json=uintVal,proto3,oneof"` -} - -type TypedValue_BoolVal struct { - BoolVal bool `protobuf:"varint,4,opt,name=bool_val,json=boolVal,proto3,oneof"` -} - -type TypedValue_BytesVal struct { - BytesVal []byte `protobuf:"bytes,5,opt,name=bytes_val,json=bytesVal,proto3,oneof"` -} - -type TypedValue_FloatVal struct { - FloatVal float32 `protobuf:"fixed32,6,opt,name=float_val,json=floatVal,proto3,oneof"` -} - -type TypedValue_DecimalVal struct { - DecimalVal *Decimal64 `protobuf:"bytes,7,opt,name=decimal_val,json=decimalVal,proto3,oneof"` -} - -type TypedValue_LeaflistVal struct { - LeaflistVal *ScalarArray `protobuf:"bytes,8,opt,name=leaflist_val,json=leaflistVal,proto3,oneof"` -} - -type TypedValue_AnyVal struct { - AnyVal *any.Any `protobuf:"bytes,9,opt,name=any_val,json=anyVal,proto3,oneof"` -} - -type TypedValue_JsonVal struct { - JsonVal []byte `protobuf:"bytes,10,opt,name=json_val,json=jsonVal,proto3,oneof"` -} - -type TypedValue_JsonIetfVal struct { - JsonIetfVal []byte `protobuf:"bytes,11,opt,name=json_ietf_val,json=jsonIetfVal,proto3,oneof"` -} - -type TypedValue_AsciiVal struct { - AsciiVal string `protobuf:"bytes,12,opt,name=ascii_val,json=asciiVal,proto3,oneof"` -} - -type TypedValue_ProtoBytes struct { - ProtoBytes []byte `protobuf:"bytes,13,opt,name=proto_bytes,json=protoBytes,proto3,oneof"` -} - -func (*TypedValue_StringVal) isTypedValue_Value() {} - -func (*TypedValue_IntVal) isTypedValue_Value() {} - -func (*TypedValue_UintVal) isTypedValue_Value() {} - -func (*TypedValue_BoolVal) isTypedValue_Value() {} - -func (*TypedValue_BytesVal) isTypedValue_Value() {} - -func (*TypedValue_FloatVal) isTypedValue_Value() {} - -func (*TypedValue_DecimalVal) isTypedValue_Value() {} - -func (*TypedValue_LeaflistVal) isTypedValue_Value() {} - -func (*TypedValue_AnyVal) isTypedValue_Value() {} - -func (*TypedValue_JsonVal) isTypedValue_Value() {} - -func (*TypedValue_JsonIetfVal) isTypedValue_Value() {} - -func (*TypedValue_AsciiVal) isTypedValue_Value() {} - -func (*TypedValue_ProtoBytes) isTypedValue_Value() {} - -func (m *TypedValue) GetValue() isTypedValue_Value { - if m != nil { - return m.Value - } - return nil -} - -func (m *TypedValue) GetStringVal() string { - if x, ok := m.GetValue().(*TypedValue_StringVal); ok { - return x.StringVal - } - return "" -} - -func (m *TypedValue) GetIntVal() int64 { - if x, ok := m.GetValue().(*TypedValue_IntVal); ok { - return x.IntVal - } - return 0 -} - -func (m *TypedValue) GetUintVal() uint64 { - if x, ok := m.GetValue().(*TypedValue_UintVal); ok { - return x.UintVal - } - return 0 -} - -func (m *TypedValue) GetBoolVal() bool { - if x, ok := m.GetValue().(*TypedValue_BoolVal); ok { - return x.BoolVal - } - return false -} - -func (m *TypedValue) GetBytesVal() []byte { - if x, ok := m.GetValue().(*TypedValue_BytesVal); ok { - return x.BytesVal - } - return nil -} - -func (m *TypedValue) GetFloatVal() float32 { - if x, ok := m.GetValue().(*TypedValue_FloatVal); ok { - return x.FloatVal - } - return 0 -} - -func (m *TypedValue) GetDecimalVal() *Decimal64 { - if x, ok := m.GetValue().(*TypedValue_DecimalVal); ok { - return x.DecimalVal - } - return nil -} - -func (m *TypedValue) GetLeaflistVal() *ScalarArray { - if x, ok := m.GetValue().(*TypedValue_LeaflistVal); ok { - return x.LeaflistVal - } - return nil -} - -func (m *TypedValue) GetAnyVal() *any.Any { - if x, ok := m.GetValue().(*TypedValue_AnyVal); ok { - return x.AnyVal - } - return nil -} - -func (m *TypedValue) GetJsonVal() []byte { - if x, ok := m.GetValue().(*TypedValue_JsonVal); ok { - return x.JsonVal - } - return nil -} - -func (m *TypedValue) GetJsonIetfVal() []byte { - if x, ok := m.GetValue().(*TypedValue_JsonIetfVal); ok { - return x.JsonIetfVal - } - return nil -} - -func (m *TypedValue) GetAsciiVal() string { - if x, ok := m.GetValue().(*TypedValue_AsciiVal); ok { - return x.AsciiVal - } - return "" -} - -func (m *TypedValue) GetProtoBytes() []byte { - if x, ok := m.GetValue().(*TypedValue_ProtoBytes); ok { - return x.ProtoBytes - } - return nil -} - -// XXX_OneofWrappers is for the internal use of the proto package. -func (*TypedValue) XXX_OneofWrappers() []interface{} { - return []interface{}{ - (*TypedValue_StringVal)(nil), - (*TypedValue_IntVal)(nil), - (*TypedValue_UintVal)(nil), - (*TypedValue_BoolVal)(nil), - (*TypedValue_BytesVal)(nil), - (*TypedValue_FloatVal)(nil), - (*TypedValue_DecimalVal)(nil), - (*TypedValue_LeaflistVal)(nil), - (*TypedValue_AnyVal)(nil), - (*TypedValue_JsonVal)(nil), - (*TypedValue_JsonIetfVal)(nil), - (*TypedValue_AsciiVal)(nil), - (*TypedValue_ProtoBytes)(nil), - } -} - -// Path encodes a data tree path as a series of repeated strings, with -// each element of the path representing a data tree node name and the -// associated attributes. -// Reference: gNMI Specification Section 2.2.2. -type Path struct { - // Elements of the path are no longer encoded as a string, but rather within - // the elem field as a PathElem message. - Element []string `protobuf:"bytes,1,rep,name=element,proto3" json:"element,omitempty"` // Deprecated: Do not use. - Origin string `protobuf:"bytes,2,opt,name=origin,proto3" json:"origin,omitempty"` - Elem []*PathElem `protobuf:"bytes,3,rep,name=elem,proto3" json:"elem,omitempty"` - Target string `protobuf:"bytes,4,opt,name=target,proto3" json:"target,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Path) Reset() { *m = Path{} } -func (m *Path) String() string { return proto.CompactTextString(m) } -func (*Path) ProtoMessage() {} -func (*Path) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{3} -} - -func (m *Path) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Path.Unmarshal(m, b) -} -func (m *Path) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Path.Marshal(b, m, deterministic) -} -func (m *Path) XXX_Merge(src proto.Message) { - xxx_messageInfo_Path.Merge(m, src) -} -func (m *Path) XXX_Size() int { - return xxx_messageInfo_Path.Size(m) -} -func (m *Path) XXX_DiscardUnknown() { - xxx_messageInfo_Path.DiscardUnknown(m) -} - -var xxx_messageInfo_Path proto.InternalMessageInfo - -// Deprecated: Do not use. -func (m *Path) GetElement() []string { - if m != nil { - return m.Element - } - return nil -} - -func (m *Path) GetOrigin() string { - if m != nil { - return m.Origin - } - return "" -} - -func (m *Path) GetElem() []*PathElem { - if m != nil { - return m.Elem - } - return nil -} - -func (m *Path) GetTarget() string { - if m != nil { - return m.Target - } - return "" -} - -// PathElem encodes an element of a gNMI path, along with any attributes (keys) -// that may be associated with it. -// Reference: gNMI Specification Section 2.2.2. -type PathElem struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Key map[string]string `protobuf:"bytes,2,rep,name=key,proto3" json:"key,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *PathElem) Reset() { *m = PathElem{} } -func (m *PathElem) String() string { return proto.CompactTextString(m) } -func (*PathElem) ProtoMessage() {} -func (*PathElem) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{4} -} - -func (m *PathElem) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_PathElem.Unmarshal(m, b) -} -func (m *PathElem) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_PathElem.Marshal(b, m, deterministic) -} -func (m *PathElem) XXX_Merge(src proto.Message) { - xxx_messageInfo_PathElem.Merge(m, src) -} -func (m *PathElem) XXX_Size() int { - return xxx_messageInfo_PathElem.Size(m) -} -func (m *PathElem) XXX_DiscardUnknown() { - xxx_messageInfo_PathElem.DiscardUnknown(m) -} - -var xxx_messageInfo_PathElem proto.InternalMessageInfo - -func (m *PathElem) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -func (m *PathElem) GetKey() map[string]string { - if m != nil { - return m.Key - } - return nil -} - -// Value encodes a data tree node's value - along with the way in which -// the value is encoded. This message is deprecated by gNMI 0.3.0. -// Reference: gNMI Specification Section 2.2.3. -// -// Deprecated: Do not use. -type Value struct { - Value []byte `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` - Type Encoding `protobuf:"varint,2,opt,name=type,proto3,enum=gnmi.Encoding" json:"type,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Value) Reset() { *m = Value{} } -func (m *Value) String() string { return proto.CompactTextString(m) } -func (*Value) ProtoMessage() {} -func (*Value) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{5} -} - -func (m *Value) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Value.Unmarshal(m, b) -} -func (m *Value) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Value.Marshal(b, m, deterministic) -} -func (m *Value) XXX_Merge(src proto.Message) { - xxx_messageInfo_Value.Merge(m, src) -} -func (m *Value) XXX_Size() int { - return xxx_messageInfo_Value.Size(m) -} -func (m *Value) XXX_DiscardUnknown() { - xxx_messageInfo_Value.DiscardUnknown(m) -} - -var xxx_messageInfo_Value proto.InternalMessageInfo - -func (m *Value) GetValue() []byte { - if m != nil { - return m.Value - } - return nil -} - -func (m *Value) GetType() Encoding { - if m != nil { - return m.Type - } - return Encoding_JSON -} - -// Error message previously utilised to return errors to the client. Deprecated -// in favour of using the google.golang.org/genproto/googleapis/rpc/status -// message in the RPC response. -// Reference: gNMI Specification Section 2.5 -// -// Deprecated: Do not use. -type Error struct { - Code uint32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` - Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` - Data *any.Any `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Error) Reset() { *m = Error{} } -func (m *Error) String() string { return proto.CompactTextString(m) } -func (*Error) ProtoMessage() {} -func (*Error) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{6} -} - -func (m *Error) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Error.Unmarshal(m, b) -} -func (m *Error) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Error.Marshal(b, m, deterministic) -} -func (m *Error) XXX_Merge(src proto.Message) { - xxx_messageInfo_Error.Merge(m, src) -} -func (m *Error) XXX_Size() int { - return xxx_messageInfo_Error.Size(m) -} -func (m *Error) XXX_DiscardUnknown() { - xxx_messageInfo_Error.DiscardUnknown(m) -} - -var xxx_messageInfo_Error proto.InternalMessageInfo - -func (m *Error) GetCode() uint32 { - if m != nil { - return m.Code - } - return 0 -} - -func (m *Error) GetMessage() string { - if m != nil { - return m.Message - } - return "" -} - -func (m *Error) GetData() *any.Any { - if m != nil { - return m.Data - } - return nil -} - -// Decimal64 is used to encode a fixed precision decimal number. The value -// is expressed as a set of digits with the precision specifying the -// number of digits following the decimal point in the digit set. -type Decimal64 struct { - Digits int64 `protobuf:"varint,1,opt,name=digits,proto3" json:"digits,omitempty"` - Precision uint32 `protobuf:"varint,2,opt,name=precision,proto3" json:"precision,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Decimal64) Reset() { *m = Decimal64{} } -func (m *Decimal64) String() string { return proto.CompactTextString(m) } -func (*Decimal64) ProtoMessage() {} -func (*Decimal64) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{7} -} - -func (m *Decimal64) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Decimal64.Unmarshal(m, b) -} -func (m *Decimal64) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Decimal64.Marshal(b, m, deterministic) -} -func (m *Decimal64) XXX_Merge(src proto.Message) { - xxx_messageInfo_Decimal64.Merge(m, src) -} -func (m *Decimal64) XXX_Size() int { - return xxx_messageInfo_Decimal64.Size(m) -} -func (m *Decimal64) XXX_DiscardUnknown() { - xxx_messageInfo_Decimal64.DiscardUnknown(m) -} - -var xxx_messageInfo_Decimal64 proto.InternalMessageInfo - -func (m *Decimal64) GetDigits() int64 { - if m != nil { - return m.Digits - } - return 0 -} - -func (m *Decimal64) GetPrecision() uint32 { - if m != nil { - return m.Precision - } - return 0 -} - -// ScalarArray is used to encode a mixed-type array of values. -type ScalarArray struct { - // The set of elements within the array. Each TypedValue message should - // specify only elements that have a field identifier of 1-7 (i.e., the - // values are scalar values). - Element []*TypedValue `protobuf:"bytes,1,rep,name=element,proto3" json:"element,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ScalarArray) Reset() { *m = ScalarArray{} } -func (m *ScalarArray) String() string { return proto.CompactTextString(m) } -func (*ScalarArray) ProtoMessage() {} -func (*ScalarArray) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{8} -} - -func (m *ScalarArray) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ScalarArray.Unmarshal(m, b) -} -func (m *ScalarArray) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ScalarArray.Marshal(b, m, deterministic) -} -func (m *ScalarArray) XXX_Merge(src proto.Message) { - xxx_messageInfo_ScalarArray.Merge(m, src) -} -func (m *ScalarArray) XXX_Size() int { - return xxx_messageInfo_ScalarArray.Size(m) -} -func (m *ScalarArray) XXX_DiscardUnknown() { - xxx_messageInfo_ScalarArray.DiscardUnknown(m) -} - -var xxx_messageInfo_ScalarArray proto.InternalMessageInfo - -func (m *ScalarArray) GetElement() []*TypedValue { - if m != nil { - return m.Element - } - return nil -} - -// SubscribeRequest is the message sent by the client to the target when -// initiating a subscription to a set of paths within the data tree. The -// request field must be populated and the initial message must specify a -// SubscriptionList to initiate a subscription. The message is subsequently -// used to define aliases or trigger polled data to be sent by the target. -// Reference: gNMI Specification Section 3.5.1.1 -type SubscribeRequest struct { - // Types that are valid to be assigned to Request: - // *SubscribeRequest_Subscribe - // *SubscribeRequest_Poll - // *SubscribeRequest_Aliases - Request isSubscribeRequest_Request `protobuf_oneof:"request"` - // Extension messages associated with the SubscribeRequest. See the - // gNMI extension specification for further definition. - Extension []*gnmi_ext.Extension `protobuf:"bytes,5,rep,name=extension,proto3" json:"extension,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *SubscribeRequest) Reset() { *m = SubscribeRequest{} } -func (m *SubscribeRequest) String() string { return proto.CompactTextString(m) } -func (*SubscribeRequest) ProtoMessage() {} -func (*SubscribeRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{9} -} - -func (m *SubscribeRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_SubscribeRequest.Unmarshal(m, b) -} -func (m *SubscribeRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_SubscribeRequest.Marshal(b, m, deterministic) -} -func (m *SubscribeRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_SubscribeRequest.Merge(m, src) -} -func (m *SubscribeRequest) XXX_Size() int { - return xxx_messageInfo_SubscribeRequest.Size(m) -} -func (m *SubscribeRequest) XXX_DiscardUnknown() { - xxx_messageInfo_SubscribeRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_SubscribeRequest proto.InternalMessageInfo - -type isSubscribeRequest_Request interface { - isSubscribeRequest_Request() -} - -type SubscribeRequest_Subscribe struct { - Subscribe *SubscriptionList `protobuf:"bytes,1,opt,name=subscribe,proto3,oneof"` -} - -type SubscribeRequest_Poll struct { - Poll *Poll `protobuf:"bytes,3,opt,name=poll,proto3,oneof"` -} - -type SubscribeRequest_Aliases struct { - Aliases *AliasList `protobuf:"bytes,4,opt,name=aliases,proto3,oneof"` -} - -func (*SubscribeRequest_Subscribe) isSubscribeRequest_Request() {} - -func (*SubscribeRequest_Poll) isSubscribeRequest_Request() {} - -func (*SubscribeRequest_Aliases) isSubscribeRequest_Request() {} - -func (m *SubscribeRequest) GetRequest() isSubscribeRequest_Request { - if m != nil { - return m.Request - } - return nil -} - -func (m *SubscribeRequest) GetSubscribe() *SubscriptionList { - if x, ok := m.GetRequest().(*SubscribeRequest_Subscribe); ok { - return x.Subscribe - } - return nil -} - -func (m *SubscribeRequest) GetPoll() *Poll { - if x, ok := m.GetRequest().(*SubscribeRequest_Poll); ok { - return x.Poll - } - return nil -} - -func (m *SubscribeRequest) GetAliases() *AliasList { - if x, ok := m.GetRequest().(*SubscribeRequest_Aliases); ok { - return x.Aliases - } - return nil -} - -func (m *SubscribeRequest) GetExtension() []*gnmi_ext.Extension { - if m != nil { - return m.Extension - } - return nil -} - -// XXX_OneofWrappers is for the internal use of the proto package. -func (*SubscribeRequest) XXX_OneofWrappers() []interface{} { - return []interface{}{ - (*SubscribeRequest_Subscribe)(nil), - (*SubscribeRequest_Poll)(nil), - (*SubscribeRequest_Aliases)(nil), - } -} - -// Poll is sent within a SubscribeRequest to trigger the device to -// send telemetry updates for the paths that are associated with the -// subscription. -// Reference: gNMI Specification Section Section 3.5.1.4 -type Poll struct { - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Poll) Reset() { *m = Poll{} } -func (m *Poll) String() string { return proto.CompactTextString(m) } -func (*Poll) ProtoMessage() {} -func (*Poll) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{10} -} - -func (m *Poll) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Poll.Unmarshal(m, b) -} -func (m *Poll) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Poll.Marshal(b, m, deterministic) -} -func (m *Poll) XXX_Merge(src proto.Message) { - xxx_messageInfo_Poll.Merge(m, src) -} -func (m *Poll) XXX_Size() int { - return xxx_messageInfo_Poll.Size(m) -} -func (m *Poll) XXX_DiscardUnknown() { - xxx_messageInfo_Poll.DiscardUnknown(m) -} - -var xxx_messageInfo_Poll proto.InternalMessageInfo - -// SubscribeResponse is the message used by the target within a Subscribe RPC. -// The target includes a Notification message which is used to transmit values -// of the path(s) that are associated with the subscription. The same message -// is to indicate that the target has sent all data values once (is -// synchronized). -// Reference: gNMI Specification Section 3.5.1.4 -type SubscribeResponse struct { - // Types that are valid to be assigned to Response: - // *SubscribeResponse_Update - // *SubscribeResponse_SyncResponse - // *SubscribeResponse_Error - Response isSubscribeResponse_Response `protobuf_oneof:"response"` - // Extension messages associated with the SubscribeResponse. See the - // gNMI extension specification for further definition. - Extension []*gnmi_ext.Extension `protobuf:"bytes,5,rep,name=extension,proto3" json:"extension,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *SubscribeResponse) Reset() { *m = SubscribeResponse{} } -func (m *SubscribeResponse) String() string { return proto.CompactTextString(m) } -func (*SubscribeResponse) ProtoMessage() {} -func (*SubscribeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{11} -} - -func (m *SubscribeResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_SubscribeResponse.Unmarshal(m, b) -} -func (m *SubscribeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_SubscribeResponse.Marshal(b, m, deterministic) -} -func (m *SubscribeResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_SubscribeResponse.Merge(m, src) -} -func (m *SubscribeResponse) XXX_Size() int { - return xxx_messageInfo_SubscribeResponse.Size(m) -} -func (m *SubscribeResponse) XXX_DiscardUnknown() { - xxx_messageInfo_SubscribeResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_SubscribeResponse proto.InternalMessageInfo - -type isSubscribeResponse_Response interface { - isSubscribeResponse_Response() -} - -type SubscribeResponse_Update struct { - Update *Notification `protobuf:"bytes,1,opt,name=update,proto3,oneof"` -} - -type SubscribeResponse_SyncResponse struct { - SyncResponse bool `protobuf:"varint,3,opt,name=sync_response,json=syncResponse,proto3,oneof"` -} - -type SubscribeResponse_Error struct { - Error *Error `protobuf:"bytes,4,opt,name=error,proto3,oneof"` -} - -func (*SubscribeResponse_Update) isSubscribeResponse_Response() {} - -func (*SubscribeResponse_SyncResponse) isSubscribeResponse_Response() {} - -func (*SubscribeResponse_Error) isSubscribeResponse_Response() {} - -func (m *SubscribeResponse) GetResponse() isSubscribeResponse_Response { - if m != nil { - return m.Response - } - return nil -} - -func (m *SubscribeResponse) GetUpdate() *Notification { - if x, ok := m.GetResponse().(*SubscribeResponse_Update); ok { - return x.Update - } - return nil -} - -func (m *SubscribeResponse) GetSyncResponse() bool { - if x, ok := m.GetResponse().(*SubscribeResponse_SyncResponse); ok { - return x.SyncResponse - } - return false -} - -// Deprecated: Do not use. -func (m *SubscribeResponse) GetError() *Error { - if x, ok := m.GetResponse().(*SubscribeResponse_Error); ok { - return x.Error - } - return nil -} - -func (m *SubscribeResponse) GetExtension() []*gnmi_ext.Extension { - if m != nil { - return m.Extension - } - return nil -} - -// XXX_OneofWrappers is for the internal use of the proto package. -func (*SubscribeResponse) XXX_OneofWrappers() []interface{} { - return []interface{}{ - (*SubscribeResponse_Update)(nil), - (*SubscribeResponse_SyncResponse)(nil), - (*SubscribeResponse_Error)(nil), - } -} - -// SubscriptionList is used within a Subscribe message to specify the list of -// paths that the client wishes to subscribe to. The message consists of a -// list of (possibly prefixed) paths, and options that relate to the -// subscription. -// Reference: gNMI Specification Section 3.5.1.2 -type SubscriptionList struct { - Prefix *Path `protobuf:"bytes,1,opt,name=prefix,proto3" json:"prefix,omitempty"` - Subscription []*Subscription `protobuf:"bytes,2,rep,name=subscription,proto3" json:"subscription,omitempty"` - // Whether target defined aliases are allowed within the subscription. - UseAliases bool `protobuf:"varint,3,opt,name=use_aliases,json=useAliases,proto3" json:"use_aliases,omitempty"` - Qos *QOSMarking `protobuf:"bytes,4,opt,name=qos,proto3" json:"qos,omitempty"` - Mode SubscriptionList_Mode `protobuf:"varint,5,opt,name=mode,proto3,enum=gnmi.SubscriptionList_Mode" json:"mode,omitempty"` - // Whether elements of the schema that are marked as eligible for aggregation - // should be aggregated or not. - AllowAggregation bool `protobuf:"varint,6,opt,name=allow_aggregation,json=allowAggregation,proto3" json:"allow_aggregation,omitempty"` - // The set of schemas that define the elements of the data tree that should - // be sent by the target. - UseModels []*ModelData `protobuf:"bytes,7,rep,name=use_models,json=useModels,proto3" json:"use_models,omitempty"` - // The encoding that the target should use within the Notifications generated - // corresponding to the SubscriptionList. - Encoding Encoding `protobuf:"varint,8,opt,name=encoding,proto3,enum=gnmi.Encoding" json:"encoding,omitempty"` - // An optional field to specify that only updates to current state should be - // sent to a client. If set, the initial state is not sent to the client but - // rather only the sync message followed by any subsequent updates to the - // current state. For ONCE and POLL modes, this causes the server to send only - // the sync message (Sec. 3.5.2.3). - UpdatesOnly bool `protobuf:"varint,9,opt,name=updates_only,json=updatesOnly,proto3" json:"updates_only,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *SubscriptionList) Reset() { *m = SubscriptionList{} } -func (m *SubscriptionList) String() string { return proto.CompactTextString(m) } -func (*SubscriptionList) ProtoMessage() {} -func (*SubscriptionList) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{12} -} - -func (m *SubscriptionList) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_SubscriptionList.Unmarshal(m, b) -} -func (m *SubscriptionList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_SubscriptionList.Marshal(b, m, deterministic) -} -func (m *SubscriptionList) XXX_Merge(src proto.Message) { - xxx_messageInfo_SubscriptionList.Merge(m, src) -} -func (m *SubscriptionList) XXX_Size() int { - return xxx_messageInfo_SubscriptionList.Size(m) -} -func (m *SubscriptionList) XXX_DiscardUnknown() { - xxx_messageInfo_SubscriptionList.DiscardUnknown(m) -} - -var xxx_messageInfo_SubscriptionList proto.InternalMessageInfo - -func (m *SubscriptionList) GetPrefix() *Path { - if m != nil { - return m.Prefix - } - return nil -} - -func (m *SubscriptionList) GetSubscription() []*Subscription { - if m != nil { - return m.Subscription - } - return nil -} - -func (m *SubscriptionList) GetUseAliases() bool { - if m != nil { - return m.UseAliases - } - return false -} - -func (m *SubscriptionList) GetQos() *QOSMarking { - if m != nil { - return m.Qos - } - return nil -} - -func (m *SubscriptionList) GetMode() SubscriptionList_Mode { - if m != nil { - return m.Mode - } - return SubscriptionList_STREAM -} - -func (m *SubscriptionList) GetAllowAggregation() bool { - if m != nil { - return m.AllowAggregation - } - return false -} - -func (m *SubscriptionList) GetUseModels() []*ModelData { - if m != nil { - return m.UseModels - } - return nil -} - -func (m *SubscriptionList) GetEncoding() Encoding { - if m != nil { - return m.Encoding - } - return Encoding_JSON -} - -func (m *SubscriptionList) GetUpdatesOnly() bool { - if m != nil { - return m.UpdatesOnly - } - return false -} - -// Subscription is a single request within a SubscriptionList. The path -// specified is interpreted (along with the prefix) as the elements of the data -// tree that the client is subscribing to. The mode determines how the target -// should trigger updates to be sent. -// Reference: gNMI Specification Section 3.5.1.3 -type Subscription struct { - Path *Path `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"` - Mode SubscriptionMode `protobuf:"varint,2,opt,name=mode,proto3,enum=gnmi.SubscriptionMode" json:"mode,omitempty"` - SampleInterval uint64 `protobuf:"varint,3,opt,name=sample_interval,json=sampleInterval,proto3" json:"sample_interval,omitempty"` - // Indicates whether values that have not changed should be sent in a SAMPLE - // subscription. - SuppressRedundant bool `protobuf:"varint,4,opt,name=suppress_redundant,json=suppressRedundant,proto3" json:"suppress_redundant,omitempty"` - // Specifies the maximum allowable silent period in nanoseconds when - // suppress_redundant is in use. The target should send a value at least once - // in the period specified. - HeartbeatInterval uint64 `protobuf:"varint,5,opt,name=heartbeat_interval,json=heartbeatInterval,proto3" json:"heartbeat_interval,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Subscription) Reset() { *m = Subscription{} } -func (m *Subscription) String() string { return proto.CompactTextString(m) } -func (*Subscription) ProtoMessage() {} -func (*Subscription) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{13} -} - -func (m *Subscription) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Subscription.Unmarshal(m, b) -} -func (m *Subscription) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Subscription.Marshal(b, m, deterministic) -} -func (m *Subscription) XXX_Merge(src proto.Message) { - xxx_messageInfo_Subscription.Merge(m, src) -} -func (m *Subscription) XXX_Size() int { - return xxx_messageInfo_Subscription.Size(m) -} -func (m *Subscription) XXX_DiscardUnknown() { - xxx_messageInfo_Subscription.DiscardUnknown(m) -} - -var xxx_messageInfo_Subscription proto.InternalMessageInfo - -func (m *Subscription) GetPath() *Path { - if m != nil { - return m.Path - } - return nil -} - -func (m *Subscription) GetMode() SubscriptionMode { - if m != nil { - return m.Mode - } - return SubscriptionMode_TARGET_DEFINED -} - -func (m *Subscription) GetSampleInterval() uint64 { - if m != nil { - return m.SampleInterval - } - return 0 -} - -func (m *Subscription) GetSuppressRedundant() bool { - if m != nil { - return m.SuppressRedundant - } - return false -} - -func (m *Subscription) GetHeartbeatInterval() uint64 { - if m != nil { - return m.HeartbeatInterval - } - return 0 -} - -// QOSMarking specifies the DSCP value to be set on transmitted telemetry -// updates from the target. -// Reference: gNMI Specification Section 3.5.1.2 -type QOSMarking struct { - Marking uint32 `protobuf:"varint,1,opt,name=marking,proto3" json:"marking,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *QOSMarking) Reset() { *m = QOSMarking{} } -func (m *QOSMarking) String() string { return proto.CompactTextString(m) } -func (*QOSMarking) ProtoMessage() {} -func (*QOSMarking) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{14} -} - -func (m *QOSMarking) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_QOSMarking.Unmarshal(m, b) -} -func (m *QOSMarking) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_QOSMarking.Marshal(b, m, deterministic) -} -func (m *QOSMarking) XXX_Merge(src proto.Message) { - xxx_messageInfo_QOSMarking.Merge(m, src) -} -func (m *QOSMarking) XXX_Size() int { - return xxx_messageInfo_QOSMarking.Size(m) -} -func (m *QOSMarking) XXX_DiscardUnknown() { - xxx_messageInfo_QOSMarking.DiscardUnknown(m) -} - -var xxx_messageInfo_QOSMarking proto.InternalMessageInfo - -func (m *QOSMarking) GetMarking() uint32 { - if m != nil { - return m.Marking - } - return 0 -} - -// Alias specifies a data tree path, and an associated string which defines an -// alias which is to be used for this path in the context of the RPC. The alias -// is specified as a string which is prefixed with "#" to disambiguate it from -// data tree element paths. -// Reference: gNMI Specification Section 2.4.2 -type Alias struct { - Path *Path `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"` - Alias string `protobuf:"bytes,2,opt,name=alias,proto3" json:"alias,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Alias) Reset() { *m = Alias{} } -func (m *Alias) String() string { return proto.CompactTextString(m) } -func (*Alias) ProtoMessage() {} -func (*Alias) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{15} -} - -func (m *Alias) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Alias.Unmarshal(m, b) -} -func (m *Alias) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Alias.Marshal(b, m, deterministic) -} -func (m *Alias) XXX_Merge(src proto.Message) { - xxx_messageInfo_Alias.Merge(m, src) -} -func (m *Alias) XXX_Size() int { - return xxx_messageInfo_Alias.Size(m) -} -func (m *Alias) XXX_DiscardUnknown() { - xxx_messageInfo_Alias.DiscardUnknown(m) -} - -var xxx_messageInfo_Alias proto.InternalMessageInfo - -func (m *Alias) GetPath() *Path { - if m != nil { - return m.Path - } - return nil -} - -func (m *Alias) GetAlias() string { - if m != nil { - return m.Alias - } - return "" -} - -// AliasList specifies a list of aliases. It is used in a SubscribeRequest for -// a client to create a set of aliases that the target is to utilize. -// Reference: gNMI Specification Section 3.5.1.6 -type AliasList struct { - Alias []*Alias `protobuf:"bytes,1,rep,name=alias,proto3" json:"alias,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *AliasList) Reset() { *m = AliasList{} } -func (m *AliasList) String() string { return proto.CompactTextString(m) } -func (*AliasList) ProtoMessage() {} -func (*AliasList) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{16} -} - -func (m *AliasList) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_AliasList.Unmarshal(m, b) -} -func (m *AliasList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_AliasList.Marshal(b, m, deterministic) -} -func (m *AliasList) XXX_Merge(src proto.Message) { - xxx_messageInfo_AliasList.Merge(m, src) -} -func (m *AliasList) XXX_Size() int { - return xxx_messageInfo_AliasList.Size(m) -} -func (m *AliasList) XXX_DiscardUnknown() { - xxx_messageInfo_AliasList.DiscardUnknown(m) -} - -var xxx_messageInfo_AliasList proto.InternalMessageInfo - -func (m *AliasList) GetAlias() []*Alias { - if m != nil { - return m.Alias - } - return nil -} - -// SetRequest is sent from a client to the target to update values in the data -// tree. Paths are either deleted by the client, or modified by means of being -// updated, or replaced. Where a replace is used, unspecified values are -// considered to be replaced, whereas when update is used the changes are -// considered to be incremental. The set of changes that are specified within -// a single SetRequest are considered to be a transaction. -// Reference: gNMI Specification Section 3.4.1 -type SetRequest struct { - Prefix *Path `protobuf:"bytes,1,opt,name=prefix,proto3" json:"prefix,omitempty"` - Delete []*Path `protobuf:"bytes,2,rep,name=delete,proto3" json:"delete,omitempty"` - Replace []*Update `protobuf:"bytes,3,rep,name=replace,proto3" json:"replace,omitempty"` - Update []*Update `protobuf:"bytes,4,rep,name=update,proto3" json:"update,omitempty"` - // Extension messages associated with the SetRequest. See the - // gNMI extension specification for further definition. - Extension []*gnmi_ext.Extension `protobuf:"bytes,5,rep,name=extension,proto3" json:"extension,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *SetRequest) Reset() { *m = SetRequest{} } -func (m *SetRequest) String() string { return proto.CompactTextString(m) } -func (*SetRequest) ProtoMessage() {} -func (*SetRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{17} -} - -func (m *SetRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_SetRequest.Unmarshal(m, b) -} -func (m *SetRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_SetRequest.Marshal(b, m, deterministic) -} -func (m *SetRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_SetRequest.Merge(m, src) -} -func (m *SetRequest) XXX_Size() int { - return xxx_messageInfo_SetRequest.Size(m) -} -func (m *SetRequest) XXX_DiscardUnknown() { - xxx_messageInfo_SetRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_SetRequest proto.InternalMessageInfo - -func (m *SetRequest) GetPrefix() *Path { - if m != nil { - return m.Prefix - } - return nil -} - -func (m *SetRequest) GetDelete() []*Path { - if m != nil { - return m.Delete - } - return nil -} - -func (m *SetRequest) GetReplace() []*Update { - if m != nil { - return m.Replace - } - return nil -} - -func (m *SetRequest) GetUpdate() []*Update { - if m != nil { - return m.Update - } - return nil -} - -func (m *SetRequest) GetExtension() []*gnmi_ext.Extension { - if m != nil { - return m.Extension - } - return nil -} - -// SetResponse is the response to a SetRequest, sent from the target to the -// client. It reports the result of the modifications to the data tree that were -// specified by the client. Errors for this RPC should be reported using the -// https://github.com/googleapis/googleapis/blob/master/google/rpc/status.proto -// message in the RPC return. The gnmi.Error message can be used to add additional -// details where required. -// Reference: gNMI Specification Section 3.4.2 -type SetResponse struct { - Prefix *Path `protobuf:"bytes,1,opt,name=prefix,proto3" json:"prefix,omitempty"` - // A set of responses specifying the result of the operations specified in - // the SetRequest. - Response []*UpdateResult `protobuf:"bytes,2,rep,name=response,proto3" json:"response,omitempty"` - Message *Error `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // Deprecated: Do not use. - Timestamp int64 `protobuf:"varint,4,opt,name=timestamp,proto3" json:"timestamp,omitempty"` - // Extension messages associated with the SetResponse. See the - // gNMI extension specification for further definition. - Extension []*gnmi_ext.Extension `protobuf:"bytes,5,rep,name=extension,proto3" json:"extension,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *SetResponse) Reset() { *m = SetResponse{} } -func (m *SetResponse) String() string { return proto.CompactTextString(m) } -func (*SetResponse) ProtoMessage() {} -func (*SetResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{18} -} - -func (m *SetResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_SetResponse.Unmarshal(m, b) -} -func (m *SetResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_SetResponse.Marshal(b, m, deterministic) -} -func (m *SetResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_SetResponse.Merge(m, src) -} -func (m *SetResponse) XXX_Size() int { - return xxx_messageInfo_SetResponse.Size(m) -} -func (m *SetResponse) XXX_DiscardUnknown() { - xxx_messageInfo_SetResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_SetResponse proto.InternalMessageInfo - -func (m *SetResponse) GetPrefix() *Path { - if m != nil { - return m.Prefix - } - return nil -} - -func (m *SetResponse) GetResponse() []*UpdateResult { - if m != nil { - return m.Response - } - return nil -} - -// Deprecated: Do not use. -func (m *SetResponse) GetMessage() *Error { - if m != nil { - return m.Message - } - return nil -} - -func (m *SetResponse) GetTimestamp() int64 { - if m != nil { - return m.Timestamp - } - return 0 -} - -func (m *SetResponse) GetExtension() []*gnmi_ext.Extension { - if m != nil { - return m.Extension - } - return nil -} - -// UpdateResult is used within the SetResponse message to communicate the -// result of an operation specified within a SetRequest message. -// Reference: gNMI Specification Section 3.4.2 -type UpdateResult struct { - // Deprecated timestamp for the UpdateResult, this field has been - // replaced by the timestamp within the SetResponse message, since - // all mutations effected by a set should be applied as a single - // transaction. - Timestamp int64 `protobuf:"varint,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` // Deprecated: Do not use. - Path *Path `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"` - Message *Error `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // Deprecated: Do not use. - Op UpdateResult_Operation `protobuf:"varint,4,opt,name=op,proto3,enum=gnmi.UpdateResult_Operation" json:"op,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *UpdateResult) Reset() { *m = UpdateResult{} } -func (m *UpdateResult) String() string { return proto.CompactTextString(m) } -func (*UpdateResult) ProtoMessage() {} -func (*UpdateResult) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{19} -} - -func (m *UpdateResult) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_UpdateResult.Unmarshal(m, b) -} -func (m *UpdateResult) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_UpdateResult.Marshal(b, m, deterministic) -} -func (m *UpdateResult) XXX_Merge(src proto.Message) { - xxx_messageInfo_UpdateResult.Merge(m, src) -} -func (m *UpdateResult) XXX_Size() int { - return xxx_messageInfo_UpdateResult.Size(m) -} -func (m *UpdateResult) XXX_DiscardUnknown() { - xxx_messageInfo_UpdateResult.DiscardUnknown(m) -} - -var xxx_messageInfo_UpdateResult proto.InternalMessageInfo - -// Deprecated: Do not use. -func (m *UpdateResult) GetTimestamp() int64 { - if m != nil { - return m.Timestamp - } - return 0 -} - -func (m *UpdateResult) GetPath() *Path { - if m != nil { - return m.Path - } - return nil -} - -// Deprecated: Do not use. -func (m *UpdateResult) GetMessage() *Error { - if m != nil { - return m.Message - } - return nil -} - -func (m *UpdateResult) GetOp() UpdateResult_Operation { - if m != nil { - return m.Op - } - return UpdateResult_INVALID -} - -// GetRequest is sent when a client initiates a Get RPC. It is used to specify -// the set of data elements for which the target should return a snapshot of -// data. The use_models field specifies the set of schema modules that are to -// be used by the target - where use_models is not specified then the target -// must use all schema models that it has. -// Reference: gNMI Specification Section 3.3.1 -type GetRequest struct { - Prefix *Path `protobuf:"bytes,1,opt,name=prefix,proto3" json:"prefix,omitempty"` - Path []*Path `protobuf:"bytes,2,rep,name=path,proto3" json:"path,omitempty"` - Type GetRequest_DataType `protobuf:"varint,3,opt,name=type,proto3,enum=gnmi.GetRequest_DataType" json:"type,omitempty"` - Encoding Encoding `protobuf:"varint,5,opt,name=encoding,proto3,enum=gnmi.Encoding" json:"encoding,omitempty"` - UseModels []*ModelData `protobuf:"bytes,6,rep,name=use_models,json=useModels,proto3" json:"use_models,omitempty"` - // Extension messages associated with the GetRequest. See the - // gNMI extension specification for further definition. - Extension []*gnmi_ext.Extension `protobuf:"bytes,7,rep,name=extension,proto3" json:"extension,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *GetRequest) Reset() { *m = GetRequest{} } -func (m *GetRequest) String() string { return proto.CompactTextString(m) } -func (*GetRequest) ProtoMessage() {} -func (*GetRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{20} -} - -func (m *GetRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_GetRequest.Unmarshal(m, b) -} -func (m *GetRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_GetRequest.Marshal(b, m, deterministic) -} -func (m *GetRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetRequest.Merge(m, src) -} -func (m *GetRequest) XXX_Size() int { - return xxx_messageInfo_GetRequest.Size(m) -} -func (m *GetRequest) XXX_DiscardUnknown() { - xxx_messageInfo_GetRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_GetRequest proto.InternalMessageInfo - -func (m *GetRequest) GetPrefix() *Path { - if m != nil { - return m.Prefix - } - return nil -} - -func (m *GetRequest) GetPath() []*Path { - if m != nil { - return m.Path - } - return nil -} - -func (m *GetRequest) GetType() GetRequest_DataType { - if m != nil { - return m.Type - } - return GetRequest_ALL -} - -func (m *GetRequest) GetEncoding() Encoding { - if m != nil { - return m.Encoding - } - return Encoding_JSON -} - -func (m *GetRequest) GetUseModels() []*ModelData { - if m != nil { - return m.UseModels - } - return nil -} - -func (m *GetRequest) GetExtension() []*gnmi_ext.Extension { - if m != nil { - return m.Extension - } - return nil -} - -// GetResponse is used by the target to respond to a GetRequest from a client. -// The set of Notifications corresponds to the data values that are requested -// by the client in the GetRequest. -// Reference: gNMI Specification Section 3.3.2 -type GetResponse struct { - Notification []*Notification `protobuf:"bytes,1,rep,name=notification,proto3" json:"notification,omitempty"` - Error *Error `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"` // Deprecated: Do not use. - // Extension messages associated with the GetResponse. See the - // gNMI extension specification for further definition. - Extension []*gnmi_ext.Extension `protobuf:"bytes,3,rep,name=extension,proto3" json:"extension,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *GetResponse) Reset() { *m = GetResponse{} } -func (m *GetResponse) String() string { return proto.CompactTextString(m) } -func (*GetResponse) ProtoMessage() {} -func (*GetResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{21} -} - -func (m *GetResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_GetResponse.Unmarshal(m, b) -} -func (m *GetResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_GetResponse.Marshal(b, m, deterministic) -} -func (m *GetResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetResponse.Merge(m, src) -} -func (m *GetResponse) XXX_Size() int { - return xxx_messageInfo_GetResponse.Size(m) -} -func (m *GetResponse) XXX_DiscardUnknown() { - xxx_messageInfo_GetResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_GetResponse proto.InternalMessageInfo - -func (m *GetResponse) GetNotification() []*Notification { - if m != nil { - return m.Notification - } - return nil -} - -// Deprecated: Do not use. -func (m *GetResponse) GetError() *Error { - if m != nil { - return m.Error - } - return nil -} - -func (m *GetResponse) GetExtension() []*gnmi_ext.Extension { - if m != nil { - return m.Extension - } - return nil -} - -// CapabilityRequest is sent by the client in the Capabilities RPC to request -// that the target reports its capabilities. -// Reference: gNMI Specification Section 3.2.1 -type CapabilityRequest struct { - // Extension messages associated with the CapabilityRequest. See the - // gNMI extension specification for further definition. - Extension []*gnmi_ext.Extension `protobuf:"bytes,1,rep,name=extension,proto3" json:"extension,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *CapabilityRequest) Reset() { *m = CapabilityRequest{} } -func (m *CapabilityRequest) String() string { return proto.CompactTextString(m) } -func (*CapabilityRequest) ProtoMessage() {} -func (*CapabilityRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{22} -} - -func (m *CapabilityRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_CapabilityRequest.Unmarshal(m, b) -} -func (m *CapabilityRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_CapabilityRequest.Marshal(b, m, deterministic) -} -func (m *CapabilityRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_CapabilityRequest.Merge(m, src) -} -func (m *CapabilityRequest) XXX_Size() int { - return xxx_messageInfo_CapabilityRequest.Size(m) -} -func (m *CapabilityRequest) XXX_DiscardUnknown() { - xxx_messageInfo_CapabilityRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_CapabilityRequest proto.InternalMessageInfo - -func (m *CapabilityRequest) GetExtension() []*gnmi_ext.Extension { - if m != nil { - return m.Extension - } - return nil -} - -// CapabilityResponse is used by the target to report its capabilities to the -// client within the Capabilities RPC. -// Reference: gNMI Specification Section 3.2.2 -type CapabilityResponse struct { - SupportedModels []*ModelData `protobuf:"bytes,1,rep,name=supported_models,json=supportedModels,proto3" json:"supported_models,omitempty"` - SupportedEncodings []Encoding `protobuf:"varint,2,rep,packed,name=supported_encodings,json=supportedEncodings,proto3,enum=gnmi.Encoding" json:"supported_encodings,omitempty"` - GNMIVersion string `protobuf:"bytes,3,opt,name=gNMI_version,json=gNMIVersion,proto3" json:"gNMI_version,omitempty"` - // Extension messages associated with the CapabilityResponse. See the - // gNMI extension specification for further definition. - Extension []*gnmi_ext.Extension `protobuf:"bytes,4,rep,name=extension,proto3" json:"extension,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *CapabilityResponse) Reset() { *m = CapabilityResponse{} } -func (m *CapabilityResponse) String() string { return proto.CompactTextString(m) } -func (*CapabilityResponse) ProtoMessage() {} -func (*CapabilityResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{23} -} - -func (m *CapabilityResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_CapabilityResponse.Unmarshal(m, b) -} -func (m *CapabilityResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_CapabilityResponse.Marshal(b, m, deterministic) -} -func (m *CapabilityResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_CapabilityResponse.Merge(m, src) -} -func (m *CapabilityResponse) XXX_Size() int { - return xxx_messageInfo_CapabilityResponse.Size(m) -} -func (m *CapabilityResponse) XXX_DiscardUnknown() { - xxx_messageInfo_CapabilityResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_CapabilityResponse proto.InternalMessageInfo - -func (m *CapabilityResponse) GetSupportedModels() []*ModelData { - if m != nil { - return m.SupportedModels - } - return nil -} - -func (m *CapabilityResponse) GetSupportedEncodings() []Encoding { - if m != nil { - return m.SupportedEncodings - } - return nil -} - -func (m *CapabilityResponse) GetGNMIVersion() string { - if m != nil { - return m.GNMIVersion - } - return "" -} - -func (m *CapabilityResponse) GetExtension() []*gnmi_ext.Extension { - if m != nil { - return m.Extension - } - return nil -} - -// ModelData is used to describe a set of schema modules. It can be used in a -// CapabilityResponse where a target reports the set of modules that it -// supports, and within the SubscribeRequest and GetRequest messages to specify -// the set of models from which data tree elements should be reported. -// Reference: gNMI Specification Section 3.2.3 -type ModelData struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Organization string `protobuf:"bytes,2,opt,name=organization,proto3" json:"organization,omitempty"` - Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ModelData) Reset() { *m = ModelData{} } -func (m *ModelData) String() string { return proto.CompactTextString(m) } -func (*ModelData) ProtoMessage() {} -func (*ModelData) Descriptor() ([]byte, []int) { - return fileDescriptor_49fc5824be3cfb8d, []int{24} -} - -func (m *ModelData) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ModelData.Unmarshal(m, b) -} -func (m *ModelData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ModelData.Marshal(b, m, deterministic) -} -func (m *ModelData) XXX_Merge(src proto.Message) { - xxx_messageInfo_ModelData.Merge(m, src) -} -func (m *ModelData) XXX_Size() int { - return xxx_messageInfo_ModelData.Size(m) -} -func (m *ModelData) XXX_DiscardUnknown() { - xxx_messageInfo_ModelData.DiscardUnknown(m) -} - -var xxx_messageInfo_ModelData proto.InternalMessageInfo - -func (m *ModelData) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -func (m *ModelData) GetOrganization() string { - if m != nil { - return m.Organization - } - return "" -} - -func (m *ModelData) GetVersion() string { - if m != nil { - return m.Version - } - return "" -} - -var E_GnmiService = &proto.ExtensionDesc{ - ExtendedType: (*descriptor.FileOptions)(nil), - ExtensionType: (*string)(nil), - Field: 1001, - Name: "gnmi.gnmi_service", - Tag: "bytes,1001,opt,name=gnmi_service", - Filename: "proto/gnmi/gnmi.proto", -} - -func init() { - proto.RegisterEnum("gnmi.Encoding", Encoding_name, Encoding_value) - proto.RegisterEnum("gnmi.SubscriptionMode", SubscriptionMode_name, SubscriptionMode_value) - proto.RegisterEnum("gnmi.SubscriptionList_Mode", SubscriptionList_Mode_name, SubscriptionList_Mode_value) - proto.RegisterEnum("gnmi.UpdateResult_Operation", UpdateResult_Operation_name, UpdateResult_Operation_value) - proto.RegisterEnum("gnmi.GetRequest_DataType", GetRequest_DataType_name, GetRequest_DataType_value) - proto.RegisterType((*Notification)(nil), "gnmi.Notification") - proto.RegisterType((*Update)(nil), "gnmi.Update") - proto.RegisterType((*TypedValue)(nil), "gnmi.TypedValue") - proto.RegisterType((*Path)(nil), "gnmi.Path") - proto.RegisterType((*PathElem)(nil), "gnmi.PathElem") - proto.RegisterMapType((map[string]string)(nil), "gnmi.PathElem.KeyEntry") - proto.RegisterType((*Value)(nil), "gnmi.Value") - proto.RegisterType((*Error)(nil), "gnmi.Error") - proto.RegisterType((*Decimal64)(nil), "gnmi.Decimal64") - proto.RegisterType((*ScalarArray)(nil), "gnmi.ScalarArray") - proto.RegisterType((*SubscribeRequest)(nil), "gnmi.SubscribeRequest") - proto.RegisterType((*Poll)(nil), "gnmi.Poll") - proto.RegisterType((*SubscribeResponse)(nil), "gnmi.SubscribeResponse") - proto.RegisterType((*SubscriptionList)(nil), "gnmi.SubscriptionList") - proto.RegisterType((*Subscription)(nil), "gnmi.Subscription") - proto.RegisterType((*QOSMarking)(nil), "gnmi.QOSMarking") - proto.RegisterType((*Alias)(nil), "gnmi.Alias") - proto.RegisterType((*AliasList)(nil), "gnmi.AliasList") - proto.RegisterType((*SetRequest)(nil), "gnmi.SetRequest") - proto.RegisterType((*SetResponse)(nil), "gnmi.SetResponse") - proto.RegisterType((*UpdateResult)(nil), "gnmi.UpdateResult") - proto.RegisterType((*GetRequest)(nil), "gnmi.GetRequest") - proto.RegisterType((*GetResponse)(nil), "gnmi.GetResponse") - proto.RegisterType((*CapabilityRequest)(nil), "gnmi.CapabilityRequest") - proto.RegisterType((*CapabilityResponse)(nil), "gnmi.CapabilityResponse") - proto.RegisterType((*ModelData)(nil), "gnmi.ModelData") - proto.RegisterExtension(E_GnmiService) -} - -func init() { proto.RegisterFile("proto/gnmi/gnmi.proto", fileDescriptor_49fc5824be3cfb8d) } - -var fileDescriptor_49fc5824be3cfb8d = []byte{ - // 1952 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x57, 0x5f, 0x93, 0xe3, 0x46, - 0x11, 0xb7, 0x2c, 0xf9, 0x8f, 0x5a, 0xde, 0x3d, 0xed, 0x24, 0x24, 0xce, 0xe6, 0x48, 0x7c, 0xaa, - 0xe4, 0xe2, 0x6c, 0x12, 0xef, 0xb1, 0x50, 0x4b, 0x38, 0x2a, 0x10, 0xed, 0xae, 0x76, 0xd7, 0xe0, - 0xb5, 0x97, 0xb1, 0x73, 0x55, 0x3c, 0x50, 0xae, 0x59, 0x7b, 0xd6, 0x27, 0x22, 0x4b, 0x8a, 0x34, - 0x3e, 0xce, 0xbc, 0xf1, 0x19, 0xf8, 0x00, 0x7c, 0x0d, 0x3e, 0x02, 0x05, 0x2f, 0xbc, 0x50, 0x3c, - 0xf1, 0x40, 0xf1, 0x00, 0x14, 0x5f, 0x82, 0x9a, 0x3f, 0x92, 0xec, 0xb3, 0xaf, 0x6e, 0x2f, 0x2f, - 0x2e, 0x4d, 0xff, 0xba, 0x7b, 0xa6, 0xa7, 0x7b, 0x7e, 0xdd, 0x86, 0xef, 0xc4, 0x49, 0xc4, 0xa2, - 0xc3, 0x59, 0x38, 0xf7, 0xc5, 0x4f, 0x47, 0xac, 0x91, 0xc1, 0xbf, 0xf7, 0xdf, 0x99, 0x45, 0xd1, - 0x2c, 0xa0, 0x87, 0x42, 0x76, 0xb3, 0xb8, 0x3d, 0x24, 0xe1, 0x52, 0x2a, 0xec, 0xb7, 0x5e, 0x84, - 0xa6, 0x34, 0x9d, 0x24, 0x7e, 0xcc, 0xa2, 0x44, 0x69, 0x7c, 0x3e, 0xf3, 0xd9, 0xd3, 0xc5, 0x4d, - 0x67, 0x12, 0xcd, 0x0f, 0xa3, 0x98, 0x86, 0x93, 0x28, 0xbc, 0xf5, 0x67, 0x72, 0xa7, 0x62, 0xd3, - 0x31, 0x7d, 0xce, 0xf2, 0x0f, 0x69, 0xe9, 0xfc, 0x49, 0x83, 0x46, 0x3f, 0x62, 0xfe, 0xad, 0x3f, - 0x21, 0xcc, 0x8f, 0x42, 0x74, 0x1f, 0x4c, 0xe6, 0xcf, 0x69, 0xca, 0xc8, 0x3c, 0x6e, 0x6a, 0x2d, - 0xad, 0xad, 0xe3, 0x42, 0x80, 0x1c, 0xa8, 0xc6, 0x09, 0xbd, 0xf5, 0x9f, 0x37, 0xcb, 0x2d, 0xad, - 0x6d, 0x1d, 0x41, 0x47, 0x04, 0x72, 0x4d, 0xd8, 0x53, 0xac, 0x10, 0xf4, 0x26, 0x54, 0x48, 0xe0, - 0x93, 0xb4, 0xa9, 0xb7, 0xb4, 0xb6, 0x89, 0xe5, 0x02, 0x7d, 0x00, 0xd5, 0x45, 0x3c, 0x25, 0x8c, - 0x36, 0x8d, 0x96, 0xde, 0xb6, 0x8e, 0x1a, 0xd2, 0xf2, 0x2b, 0x21, 0xc3, 0x0a, 0xe3, 0xfe, 0xa7, - 0x34, 0xa0, 0x8c, 0x36, 0x2b, 0x42, 0x6b, 0xcd, 0xbf, 0x44, 0xd0, 0x5b, 0x50, 0x25, 0x2c, 0x9a, - 0xfb, 0x93, 0x66, 0xb5, 0xa5, 0xb5, 0xeb, 0x58, 0xad, 0x9c, 0xdf, 0x6b, 0x50, 0x95, 0xee, 0xd0, - 0x7b, 0x60, 0xc4, 0x84, 0x3d, 0x15, 0xe7, 0x5f, 0x77, 0x22, 0xe4, 0xe8, 0x43, 0xa8, 0x3c, 0x23, - 0xc1, 0x82, 0xaa, 0x28, 0x2c, 0xa9, 0xf0, 0x84, 0x8b, 0x4e, 0xca, 0x4d, 0x0d, 0x4b, 0x14, 0x39, - 0xa0, 0x3f, 0x23, 0x81, 0x88, 0xc3, 0x3a, 0xb2, 0xa5, 0xd2, 0x68, 0x19, 0xd3, 0xa9, 0xd0, 0xc4, - 0x1c, 0x44, 0xef, 0x01, 0x4c, 0x17, 0x71, 0xc0, 0xaf, 0x8f, 0xa6, 0x4d, 0xa3, 0xa5, 0xb5, 0x77, - 0xf0, 0x8a, 0xc4, 0xf9, 0x9f, 0x0e, 0x50, 0xd8, 0xa0, 0xf7, 0x01, 0x52, 0x96, 0xf8, 0xe1, 0x6c, - 0xcc, 0x3d, 0xf3, 0xf3, 0x99, 0x97, 0x25, 0x6c, 0x4a, 0xd9, 0x13, 0x12, 0xa0, 0x77, 0xa0, 0xe6, - 0x87, 0x4c, 0xa0, 0xfc, 0x70, 0xfa, 0x65, 0x09, 0x57, 0xfd, 0x90, 0x71, 0xe8, 0x5d, 0xa8, 0x2f, - 0x32, 0x8c, 0x9f, 0xc9, 0xb8, 0x2c, 0xe1, 0xda, 0xa2, 0x00, 0x6f, 0xa2, 0x28, 0x10, 0x20, 0x3f, - 0x45, 0x9d, 0x83, 0x5c, 0xc2, 0xc1, 0xef, 0x82, 0x79, 0xb3, 0x64, 0x34, 0x15, 0x68, 0xa5, 0xa5, - 0xb5, 0x1b, 0x97, 0x25, 0x5c, 0x17, 0x22, 0x05, 0xdf, 0x06, 0x11, 0x91, 0x9e, 0xf9, 0xa5, 0x96, - 0x39, 0x2c, 0x44, 0x1c, 0x3e, 0x02, 0x6b, 0x4a, 0x27, 0xfe, 0x9c, 0x48, 0xef, 0x35, 0x71, 0x1d, - 0xf7, 0xe4, 0x75, 0x9c, 0x49, 0xe0, 0xf8, 0x07, 0x97, 0x25, 0x0c, 0x4a, 0x8b, 0xdb, 0x1c, 0x43, - 0x23, 0xa0, 0xe4, 0x36, 0xf0, 0x53, 0xe9, 0xb5, 0x2e, 0x8c, 0xf6, 0xa4, 0xd1, 0x70, 0x42, 0x02, - 0x92, 0xb8, 0x49, 0x42, 0x96, 0x97, 0x25, 0x6c, 0x65, 0x8a, 0xdc, 0xee, 0x10, 0x6a, 0x24, 0x5c, - 0x0a, 0x13, 0x53, 0x98, 0xbc, 0xd9, 0x91, 0xd5, 0xdf, 0xc9, 0xaa, 0xbf, 0xe3, 0x86, 0xdc, 0xaa, - 0x4a, 0xc2, 0xa5, 0x8a, 0xfb, 0xd7, 0x69, 0x14, 0x0a, 0x0b, 0x50, 0x91, 0xd5, 0xb8, 0x84, 0x83, - 0x1f, 0xc0, 0x8e, 0x00, 0x7d, 0xca, 0x6e, 0x85, 0x86, 0xa5, 0x34, 0x2c, 0x2e, 0xee, 0x52, 0x76, - 0xab, 0xc2, 0x27, 0xe9, 0xc4, 0xf7, 0x85, 0x46, 0x43, 0xa5, 0xa4, 0x2e, 0x44, 0x1c, 0x7e, 0x00, - 0x96, 0xd8, 0x7b, 0x2c, 0xee, 0xab, 0xb9, 0xa3, 0x5c, 0x80, 0x10, 0x9e, 0x70, 0xd9, 0x49, 0x4d, - 0xd5, 0x93, 0xf3, 0x1c, 0x0c, 0x5e, 0x66, 0xe8, 0x3e, 0xd4, 0x68, 0x40, 0xe7, 0x34, 0x64, 0x4d, - 0xad, 0xa5, 0xb7, 0x4d, 0x51, 0x55, 0x99, 0x88, 0x57, 0x70, 0x94, 0xf8, 0x33, 0x3f, 0x14, 0x29, - 0x36, 0xb1, 0x5a, 0x21, 0x07, 0x0c, 0xae, 0xd2, 0xd4, 0x45, 0xed, 0xef, 0x16, 0x65, 0xeb, 0x05, - 0x74, 0x8e, 0x05, 0xc6, 0x6d, 0x19, 0x49, 0x66, 0x94, 0x89, 0x2c, 0x9b, 0x58, 0xad, 0x9c, 0xdf, - 0x69, 0x50, 0xcf, 0x54, 0x11, 0x02, 0x23, 0x24, 0x73, 0x2a, 0xeb, 0x0b, 0x8b, 0x6f, 0xf4, 0x31, - 0xe8, 0x5f, 0xd3, 0x65, 0xb3, 0x2c, 0x7c, 0xbf, 0xbd, 0xee, 0xbb, 0xf3, 0x73, 0xba, 0xf4, 0x42, - 0x96, 0x2c, 0x31, 0xd7, 0xd9, 0x3f, 0x86, 0x7a, 0x26, 0x40, 0xb6, 0x34, 0x93, 0x9e, 0xf8, 0x27, - 0x7f, 0xdf, 0xc5, 0xe3, 0x31, 0xd5, 0x5b, 0x79, 0x5c, 0xfe, 0x5c, 0x73, 0x3c, 0xa8, 0xc8, 0x2a, - 0xcf, 0x55, 0xb8, 0x59, 0xa3, 0x78, 0x4e, 0x06, 0x5b, 0xc6, 0xd2, 0x6e, 0x37, 0x0b, 0xcf, 0x0b, - 0x27, 0xd1, 0xd4, 0x0f, 0x67, 0x58, 0x60, 0x8f, 0xcb, 0x4d, 0xcd, 0x99, 0x40, 0xc5, 0x4b, 0x92, - 0x28, 0xe1, 0x61, 0x4c, 0xa2, 0xa9, 0xf4, 0xb2, 0x83, 0xc5, 0x37, 0x6a, 0x42, 0x6d, 0x4e, 0xd3, - 0x94, 0xcc, 0xb2, 0xfd, 0xb3, 0x25, 0x6a, 0x83, 0x31, 0x25, 0x8c, 0xa8, 0xe7, 0xba, 0xb5, 0x6e, - 0xb0, 0xd0, 0x10, 0x9b, 0xb8, 0x60, 0xe6, 0xb5, 0xcb, 0x2f, 0x75, 0xea, 0xcf, 0x7c, 0x96, 0x2a, - 0xc6, 0x53, 0x2b, 0x4e, 0x86, 0x71, 0x42, 0x27, 0x7e, 0xea, 0x47, 0x32, 0x57, 0x3b, 0xb8, 0x10, - 0x38, 0x3f, 0x02, 0x6b, 0xa5, 0x92, 0xd1, 0xc1, 0x7a, 0xce, 0xb7, 0x31, 0x46, 0xa6, 0xe0, 0xfc, - 0x5d, 0x03, 0x7b, 0xb8, 0xb8, 0xe1, 0x34, 0x7e, 0x43, 0x31, 0xfd, 0x66, 0x41, 0x53, 0x86, 0x8e, - 0xc1, 0x4c, 0x33, 0x99, 0xa2, 0xae, 0xb7, 0xd4, 0x83, 0x91, 0xe2, 0x98, 0x33, 0x74, 0xcf, 0x4f, - 0x99, 0xa0, 0x8c, 0x4c, 0x15, 0xb5, 0xc0, 0x88, 0xa3, 0x20, 0xe3, 0xa9, 0x8c, 0xed, 0xa2, 0x20, - 0xb8, 0x2c, 0x61, 0x81, 0xa0, 0x4f, 0xa0, 0x26, 0x58, 0x58, 0x31, 0x54, 0xfe, 0x7a, 0x5d, 0x2e, - 0x54, 0x0e, 0x33, 0x0d, 0xf4, 0x3d, 0x30, 0xe9, 0x73, 0x46, 0x43, 0x11, 0xb4, 0xa4, 0xe1, 0x37, - 0x3a, 0x79, 0xdb, 0xf0, 0x32, 0x08, 0x17, 0x5a, 0x27, 0x26, 0xd4, 0x12, 0x19, 0x84, 0x53, 0x05, - 0x83, 0x6f, 0xed, 0xfc, 0x55, 0x83, 0xbd, 0x95, 0x08, 0xd3, 0x38, 0x0a, 0x53, 0x8a, 0x3e, 0xcd, - 0xbb, 0x80, 0x8c, 0x0f, 0xc9, 0x73, 0xac, 0x76, 0x20, 0xfe, 0xb6, 0x55, 0x37, 0xf8, 0x10, 0x76, - 0xd2, 0x65, 0x38, 0x19, 0x27, 0xca, 0x5c, 0x44, 0xc8, 0x89, 0xad, 0xc1, 0xc5, 0xb9, 0xd3, 0x8f, - 0xa0, 0x42, 0x79, 0xbd, 0xa8, 0xd8, 0x14, 0x9b, 0x8b, 0x12, 0xe2, 0xef, 0xee, 0xb2, 0x84, 0x25, - 0xfe, 0x6d, 0x22, 0x03, 0xa8, 0x67, 0xbb, 0x3b, 0x7f, 0xd4, 0xf3, 0xa4, 0xe5, 0x99, 0x58, 0xe9, - 0x88, 0xda, 0x4b, 0x3b, 0xe2, 0x31, 0x34, 0xd2, 0x15, 0x3b, 0xf5, 0x06, 0xd1, 0x66, 0x6e, 0xf1, - 0x9a, 0x1e, 0x7a, 0x1f, 0xac, 0x45, 0x4a, 0xc7, 0x59, 0xea, 0x44, 0xf4, 0x18, 0x16, 0x29, 0x75, - 0x55, 0xaa, 0x1c, 0xd0, 0xbf, 0x89, 0xb2, 0x9c, 0xaa, 0x72, 0xfb, 0xc5, 0x60, 0x78, 0x45, 0x92, - 0xaf, 0xf9, 0x93, 0xe2, 0x20, 0x3a, 0x04, 0x63, 0xce, 0x1f, 0x51, 0x45, 0xbc, 0xba, 0x77, 0xb7, - 0x17, 0x54, 0xe7, 0x2a, 0x9a, 0x52, 0x2c, 0x14, 0xd1, 0x27, 0xb0, 0x47, 0x82, 0x20, 0xfa, 0xcd, - 0x98, 0xcc, 0x66, 0x09, 0x9d, 0x89, 0xa4, 0xa8, 0x56, 0x6b, 0x0b, 0xc0, 0x2d, 0xe4, 0xa8, 0x03, - 0xfc, 0x3c, 0x63, 0x6e, 0x18, 0xa4, 0xcd, 0x9a, 0x08, 0x4c, 0x15, 0x17, 0x77, 0x19, 0x9c, 0x11, - 0x46, 0xb0, 0xb9, 0x48, 0xa9, 0x58, 0xa5, 0xe8, 0x00, 0xea, 0x54, 0xbd, 0x78, 0xd1, 0x13, 0x36, - 0x79, 0x20, 0xc7, 0xd1, 0x03, 0x68, 0xc8, 0x42, 0x48, 0xc7, 0x51, 0x18, 0x2c, 0x45, 0x43, 0xa8, - 0x63, 0x4b, 0xc9, 0x06, 0x61, 0xb0, 0x74, 0x1e, 0x82, 0xc1, 0x1d, 0x23, 0x80, 0xea, 0x70, 0x84, - 0x3d, 0xf7, 0xca, 0x2e, 0xa1, 0x3a, 0x18, 0x83, 0xfe, 0xa9, 0x67, 0x6b, 0xfc, 0xeb, 0x7a, 0xd0, - 0xeb, 0xd9, 0x65, 0xe7, 0x9f, 0x1a, 0x34, 0x56, 0x63, 0x7e, 0xe5, 0x84, 0x70, 0xa0, 0x6e, 0x4d, - 0x72, 0xd5, 0x96, 0x67, 0xb8, 0x72, 0x61, 0x1f, 0xc1, 0xbd, 0x94, 0xcc, 0xe3, 0x80, 0x8e, 0xfd, - 0x90, 0xd1, 0x24, 0x6f, 0xcf, 0x78, 0x57, 0x8a, 0xbb, 0x4a, 0x8a, 0x3e, 0x03, 0x94, 0x2e, 0xe2, - 0x38, 0xa1, 0x69, 0x3a, 0x4e, 0xe8, 0x74, 0x11, 0x4e, 0x49, 0x28, 0x79, 0xbc, 0x8e, 0xf7, 0x32, - 0x04, 0x67, 0x00, 0x57, 0x7f, 0x4a, 0x49, 0xc2, 0x6e, 0x28, 0x61, 0x85, 0xeb, 0x8a, 0x70, 0xbd, - 0x97, 0x23, 0x99, 0x77, 0xe7, 0x21, 0x40, 0x91, 0x7b, 0xc1, 0x93, 0xf2, 0x53, 0xd1, 0x67, 0xb6, - 0x74, 0xbe, 0x80, 0x8a, 0xa8, 0x9f, 0x57, 0xde, 0x41, 0x3e, 0xc8, 0x95, 0x57, 0x06, 0x39, 0xa7, - 0x03, 0x66, 0x4e, 0x1b, 0xe8, 0x41, 0xa6, 0x22, 0x19, 0xcf, 0x5a, 0xa1, 0x95, 0x4c, 0xff, 0x6f, - 0x1a, 0xc0, 0x90, 0xb2, 0x8c, 0xe4, 0xee, 0xf2, 0x5e, 0x8a, 0x29, 0xb0, 0xfc, 0xd2, 0x29, 0xf0, - 0x21, 0xa7, 0x9c, 0x38, 0x20, 0x13, 0xaa, 0xda, 0xe5, 0xfa, 0x40, 0x99, 0x81, 0x77, 0x9c, 0x3b, - 0x5f, 0x9f, 0x19, 0x9c, 0x7f, 0x68, 0x60, 0x89, 0xb8, 0x14, 0x0b, 0xdd, 0x25, 0xb0, 0x4e, 0xc1, - 0x26, 0xeb, 0x24, 0xa0, 0x8e, 0x43, 0xd3, 0x45, 0xc0, 0x70, 0xae, 0x83, 0x3e, 0x2e, 0x9a, 0x9d, - 0xbe, 0x95, 0xdb, 0x8a, 0xee, 0xb7, 0x36, 0xb7, 0x1b, 0x2f, 0xce, 0xed, 0xdf, 0x22, 0xbe, 0xff, - 0x68, 0xd0, 0x58, 0x3d, 0x16, 0x6a, 0x6d, 0xfc, 0x33, 0x10, 0x27, 0x58, 0xd9, 0x25, 0x2b, 0xa8, - 0xf2, 0x4b, 0x0a, 0xea, 0x35, 0xc2, 0xf9, 0x14, 0xca, 0x91, 0x8c, 0x63, 0xf7, 0xe8, 0xfe, 0xe6, - 0x1d, 0x75, 0x06, 0x31, 0x4d, 0x04, 0x03, 0xe1, 0x72, 0x14, 0x3b, 0x5f, 0x80, 0x99, 0x0b, 0x90, - 0x05, 0xb5, 0x6e, 0xff, 0x89, 0xdb, 0xeb, 0x9e, 0xd9, 0x25, 0x4e, 0x0c, 0x67, 0x5e, 0xcf, 0x1b, - 0x71, 0x3a, 0xb0, 0xa0, 0x86, 0xbd, 0xeb, 0x9e, 0x7b, 0xea, 0xd9, 0x65, 0x0e, 0x7c, 0x75, 0x7d, - 0xe6, 0x8e, 0x3c, 0x5b, 0x77, 0xfe, 0x52, 0x06, 0xb8, 0x78, 0xbd, 0x12, 0x2d, 0x42, 0xd5, 0xb7, - 0x86, 0xfa, 0x99, 0x9a, 0x75, 0x74, 0x11, 0xc1, 0x3b, 0x12, 0x2f, 0xf6, 0xe8, 0x70, 0x5e, 0xe4, - 0x83, 0x81, 0x1c, 0x7b, 0xd6, 0x68, 0xb1, 0xf2, 0x0a, 0x5a, 0x5c, 0xa7, 0xdc, 0xea, 0x2b, 0x29, - 0x77, 0x2d, 0xf7, 0xb5, 0x3b, 0xe5, 0xfe, 0xc7, 0x50, 0xcf, 0x0e, 0x88, 0x6a, 0xa0, 0xbb, 0xbd, - 0x9e, 0xbc, 0xca, 0xd3, 0x41, 0xff, 0xbc, 0x7b, 0x61, 0x6b, 0xc8, 0x84, 0xca, 0x70, 0xc4, 0x2f, - 0xaf, 0x8c, 0xee, 0x81, 0x35, 0xb8, 0xf6, 0xb0, 0x3b, 0xea, 0x0e, 0xfa, 0x6e, 0xcf, 0xd6, 0x9d, - 0x3f, 0x68, 0x60, 0x5d, 0xac, 0x3c, 0x8c, 0x63, 0x68, 0x84, 0x2b, 0xfd, 0x5d, 0x51, 0xc5, 0x96, - 0xce, 0x8f, 0xd7, 0xf4, 0xf8, 0x9f, 0x34, 0xd9, 0xd6, 0xcb, 0xdb, 0x6b, 0x65, 0x5b, 0x53, 0xd7, - 0xef, 0x14, 0xde, 0x39, 0xec, 0x9d, 0x92, 0x98, 0xdc, 0xf8, 0x81, 0xcf, 0x96, 0x59, 0xd6, 0xd7, - 0xfc, 0x68, 0x77, 0xf2, 0xf3, 0x6f, 0x0d, 0xd0, 0xaa, 0x23, 0x15, 0xf0, 0x63, 0xb0, 0x39, 0x99, - 0x47, 0x09, 0xa3, 0xd3, 0x2c, 0x4d, 0xda, 0xf6, 0x34, 0xdd, 0xcb, 0x15, 0x55, 0xb2, 0x7e, 0x0a, - 0x6f, 0x14, 0xb6, 0x59, 0xca, 0x53, 0x51, 0x66, 0x9b, 0x35, 0x81, 0x72, 0xd5, 0x4c, 0x94, 0xf2, - 0xa6, 0x39, 0xeb, 0x5f, 0x75, 0xc7, 0xcf, 0x68, 0xa2, 0x6e, 0x84, 0x73, 0xb7, 0xc5, 0x65, 0x4f, - 0xa4, 0x68, 0x3d, 0x52, 0xe3, 0x4e, 0x91, 0xfe, 0x0a, 0xcc, 0xfc, 0xd0, 0x5b, 0xff, 0x5d, 0x38, - 0xd0, 0x88, 0x92, 0x19, 0x09, 0xfd, 0xdf, 0x12, 0x96, 0x0d, 0xcb, 0x26, 0x5e, 0x93, 0xf1, 0x96, - 0xb4, 0x7e, 0xaa, 0x6c, 0x79, 0x70, 0x06, 0xf5, 0x2c, 0x02, 0xde, 0xb4, 0x7f, 0x36, 0x1c, 0xf4, - 0xed, 0x12, 0x2f, 0xb2, 0x93, 0x5f, 0x8e, 0xbc, 0xa1, 0xac, 0xb7, 0x6b, 0x3c, 0x18, 0x0d, 0xec, - 0x32, 0xff, 0x74, 0x87, 0xa7, 0xdd, 0xae, 0xad, 0xa3, 0x1d, 0x30, 0xb9, 0xea, 0xb8, 0xeb, 0x8d, - 0xce, 0x6d, 0xe3, 0xc0, 0x5d, 0x1f, 0xcf, 0xc4, 0x60, 0x80, 0x60, 0x77, 0xe4, 0xe2, 0x0b, 0x6f, - 0x34, 0x3e, 0xf3, 0xce, 0xbb, 0x7d, 0x8f, 0x73, 0xc2, 0x0e, 0x98, 0x83, 0xfe, 0xf8, 0xf4, 0xd2, - 0xed, 0x5f, 0x70, 0x5a, 0xe0, 0xb3, 0x83, 0x7b, 0x75, 0xdd, 0xf3, 0xec, 0xf2, 0xd1, 0xbf, 0x34, - 0x30, 0xf8, 0x55, 0x21, 0x17, 0x1a, 0x79, 0x66, 0x7d, 0x9a, 0x22, 0xf5, 0x87, 0x69, 0xa3, 0x6c, - 0xf6, 0x9b, 0x9b, 0x80, 0x2a, 0x83, 0x03, 0xd0, 0x2f, 0x28, 0x43, 0xf6, 0x8b, 0x6f, 0x7f, 0x7f, - 0x6f, 0x45, 0x52, 0xe8, 0x0e, 0x0b, 0xdd, 0xe1, 0x86, 0xee, 0x6a, 0xa3, 0xf9, 0x12, 0xcc, 0x7c, - 0xb0, 0x46, 0xeb, 0x93, 0x49, 0xfe, 0x5f, 0x62, 0xff, 0xed, 0x0d, 0xb9, 0xb4, 0x6e, 0x6b, 0x8f, - 0xb4, 0xc7, 0x5f, 0x42, 0x43, 0xa4, 0x3b, 0xa5, 0xc9, 0x33, 0x7f, 0x42, 0xd1, 0xfd, 0x8d, 0xff, - 0x4a, 0xe7, 0x7e, 0x40, 0x07, 0xe2, 0x16, 0xd3, 0xe6, 0x7f, 0x6b, 0xaa, 0x84, 0xc2, 0xb9, 0x3f, - 0x94, 0x16, 0x27, 0xf5, 0x3f, 0xff, 0xa4, 0xf2, 0xa8, 0xf3, 0xc3, 0xce, 0xa3, 0x9b, 0xaa, 0xb0, - 0xf9, 0xfe, 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0xe1, 0x84, 0x75, 0xee, 0xdd, 0x12, 0x00, 0x00, -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// GNMIClient is the client API for GNMI service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type GNMIClient interface { - // Capabilities allows the client to retrieve the set of capabilities that - // is supported by the target. This allows the target to validate the - // service version that is implemented and retrieve the set of models that - // the target supports. The models can then be specified in subsequent RPCs - // to restrict the set of data that is utilized. - // Reference: gNMI Specification Section 3.2 - Capabilities(ctx context.Context, in *CapabilityRequest, opts ...grpc.CallOption) (*CapabilityResponse, error) - // Retrieve a snapshot of data from the target. A Get RPC requests that the - // target snapshots a subset of the data tree as specified by the paths - // included in the message and serializes this to be returned to the - // client using the specified encoding. - // Reference: gNMI Specification Section 3.3 - Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) - // Set allows the client to modify the state of data on the target. The - // paths to modified along with the new values that the client wishes - // to set the value to. - // Reference: gNMI Specification Section 3.4 - Set(ctx context.Context, in *SetRequest, opts ...grpc.CallOption) (*SetResponse, error) - // Subscribe allows a client to request the target to send it values - // of particular paths within the data tree. These values may be streamed - // at a particular cadence (STREAM), sent one off on a long-lived channel - // (POLL), or sent as a one-off retrieval (ONCE). - // Reference: gNMI Specification Section 3.5 - Subscribe(ctx context.Context, opts ...grpc.CallOption) (GNMI_SubscribeClient, error) -} - -type gNMIClient struct { - cc *grpc.ClientConn -} - -func NewGNMIClient(cc *grpc.ClientConn) GNMIClient { - return &gNMIClient{cc} -} - -func (c *gNMIClient) Capabilities(ctx context.Context, in *CapabilityRequest, opts ...grpc.CallOption) (*CapabilityResponse, error) { - out := new(CapabilityResponse) - err := c.cc.Invoke(ctx, "/gnmi.gNMI/Capabilities", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *gNMIClient) Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) { - out := new(GetResponse) - err := c.cc.Invoke(ctx, "/gnmi.gNMI/Get", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *gNMIClient) Set(ctx context.Context, in *SetRequest, opts ...grpc.CallOption) (*SetResponse, error) { - out := new(SetResponse) - err := c.cc.Invoke(ctx, "/gnmi.gNMI/Set", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *gNMIClient) Subscribe(ctx context.Context, opts ...grpc.CallOption) (GNMI_SubscribeClient, error) { - stream, err := c.cc.NewStream(ctx, &_GNMI_serviceDesc.Streams[0], "/gnmi.gNMI/Subscribe", opts...) - if err != nil { - return nil, err - } - x := &gNMISubscribeClient{stream} - return x, nil -} - -type GNMI_SubscribeClient interface { - Send(*SubscribeRequest) error - Recv() (*SubscribeResponse, error) - grpc.ClientStream -} - -type gNMISubscribeClient struct { - grpc.ClientStream -} - -func (x *gNMISubscribeClient) Send(m *SubscribeRequest) error { - return x.ClientStream.SendMsg(m) -} - -func (x *gNMISubscribeClient) Recv() (*SubscribeResponse, error) { - m := new(SubscribeResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -// GNMIServer is the server API for GNMI service. -type GNMIServer interface { - // Capabilities allows the client to retrieve the set of capabilities that - // is supported by the target. This allows the target to validate the - // service version that is implemented and retrieve the set of models that - // the target supports. The models can then be specified in subsequent RPCs - // to restrict the set of data that is utilized. - // Reference: gNMI Specification Section 3.2 - Capabilities(context.Context, *CapabilityRequest) (*CapabilityResponse, error) - // Retrieve a snapshot of data from the target. A Get RPC requests that the - // target snapshots a subset of the data tree as specified by the paths - // included in the message and serializes this to be returned to the - // client using the specified encoding. - // Reference: gNMI Specification Section 3.3 - Get(context.Context, *GetRequest) (*GetResponse, error) - // Set allows the client to modify the state of data on the target. The - // paths to modified along with the new values that the client wishes - // to set the value to. - // Reference: gNMI Specification Section 3.4 - Set(context.Context, *SetRequest) (*SetResponse, error) - // Subscribe allows a client to request the target to send it values - // of particular paths within the data tree. These values may be streamed - // at a particular cadence (STREAM), sent one off on a long-lived channel - // (POLL), or sent as a one-off retrieval (ONCE). - // Reference: gNMI Specification Section 3.5 - Subscribe(GNMI_SubscribeServer) error -} - -// UnimplementedGNMIServer can be embedded to have forward compatible implementations. -type UnimplementedGNMIServer struct { -} - -func (*UnimplementedGNMIServer) Capabilities(ctx context.Context, req *CapabilityRequest) (*CapabilityResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Capabilities not implemented") -} -func (*UnimplementedGNMIServer) Get(ctx context.Context, req *GetRequest) (*GetResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Get not implemented") -} -func (*UnimplementedGNMIServer) Set(ctx context.Context, req *SetRequest) (*SetResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Set not implemented") -} -func (*UnimplementedGNMIServer) Subscribe(srv GNMI_SubscribeServer) error { - return status.Errorf(codes.Unimplemented, "method Subscribe not implemented") -} - -func RegisterGNMIServer(s *grpc.Server, srv GNMIServer) { - s.RegisterService(&_GNMI_serviceDesc, srv) -} - -func _GNMI_Capabilities_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(CapabilityRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(GNMIServer).Capabilities(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/gnmi.gNMI/Capabilities", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(GNMIServer).Capabilities(ctx, req.(*CapabilityRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _GNMI_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(GNMIServer).Get(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/gnmi.gNMI/Get", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(GNMIServer).Get(ctx, req.(*GetRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _GNMI_Set_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(SetRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(GNMIServer).Set(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/gnmi.gNMI/Set", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(GNMIServer).Set(ctx, req.(*SetRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _GNMI_Subscribe_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(GNMIServer).Subscribe(&gNMISubscribeServer{stream}) -} - -type GNMI_SubscribeServer interface { - Send(*SubscribeResponse) error - Recv() (*SubscribeRequest, error) - grpc.ServerStream -} - -type gNMISubscribeServer struct { - grpc.ServerStream -} - -func (x *gNMISubscribeServer) Send(m *SubscribeResponse) error { - return x.ServerStream.SendMsg(m) -} - -func (x *gNMISubscribeServer) Recv() (*SubscribeRequest, error) { - m := new(SubscribeRequest) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -var _GNMI_serviceDesc = grpc.ServiceDesc{ - ServiceName: "gnmi.gNMI", - HandlerType: (*GNMIServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Capabilities", - Handler: _GNMI_Capabilities_Handler, - }, - { - MethodName: "Get", - Handler: _GNMI_Get_Handler, - }, - { - MethodName: "Set", - Handler: _GNMI_Set_Handler, - }, - }, - Streams: []grpc.StreamDesc{ - { - StreamName: "Subscribe", - Handler: _GNMI_Subscribe_Handler, - ServerStreams: true, - ClientStreams: true, - }, - }, - Metadata: "proto/gnmi/gnmi.proto", -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi/gnmi.proto b/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi/gnmi.proto deleted file mode 100644 index 0a6b31224..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi/gnmi.proto +++ /dev/null @@ -1,456 +0,0 @@ -// -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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. -// -syntax = "proto3"; - -import "google/protobuf/any.proto"; -import "google/protobuf/descriptor.proto"; -import "github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.proto"; - -// Package gNMI defines a service specification for the gRPC Network Management -// Interface. This interface is defined to be a standard interface via which -// a network management system ("client") can subscribe to state values, -// retrieve snapshots of state information, and manipulate the state of a data -// tree supported by a device ("target"). -// -// This document references the gNMI Specification which can be found at -// http://github.com/openconfig/reference/blob/master/rpc/gnmi -package gnmi; - -// Define a protobuf FileOption that defines the gNMI service version. -extend google.protobuf.FileOptions { - // The gNMI service semantic version. - string gnmi_service = 1001; -} - -// gNMI_service is the current version of the gNMI service, returned through -// the Capabilities RPC. -option (gnmi_service) = "0.7.0"; - -service gNMI { - // Capabilities allows the client to retrieve the set of capabilities that - // is supported by the target. This allows the target to validate the - // service version that is implemented and retrieve the set of models that - // the target supports. The models can then be specified in subsequent RPCs - // to restrict the set of data that is utilized. - // Reference: gNMI Specification Section 3.2 - rpc Capabilities(CapabilityRequest) returns (CapabilityResponse); - // Retrieve a snapshot of data from the target. A Get RPC requests that the - // target snapshots a subset of the data tree as specified by the paths - // included in the message and serializes this to be returned to the - // client using the specified encoding. - // Reference: gNMI Specification Section 3.3 - rpc Get(GetRequest) returns (GetResponse); - // Set allows the client to modify the state of data on the target. The - // paths to modified along with the new values that the client wishes - // to set the value to. - // Reference: gNMI Specification Section 3.4 - rpc Set(SetRequest) returns (SetResponse); - // Subscribe allows a client to request the target to send it values - // of particular paths within the data tree. These values may be streamed - // at a particular cadence (STREAM), sent one off on a long-lived channel - // (POLL), or sent as a one-off retrieval (ONCE). - // Reference: gNMI Specification Section 3.5 - rpc Subscribe(stream SubscribeRequest) returns (stream SubscribeResponse); -} - -// Notification is a re-usable message that is used to encode data from the -// target to the client. A Notification carries two types of changes to the data -// tree: -// - Deleted values (delete) - a set of paths that have been removed from the -// data tree. -// - Updated values (update) - a set of path-value pairs indicating the path -// whose value has changed in the data tree. -// Reference: gNMI Specification Section 2.1 -message Notification { - int64 timestamp = 1; // Timestamp in nanoseconds since Epoch. - Path prefix = 2; // Prefix used for paths in the message. - // An alias for the path specified in the prefix field. - // Reference: gNMI Specification Section 2.4.2 - string alias = 3; - repeated Update update = 4; // Data elements that have changed values. - repeated Path delete = 5; // Data elements that have been deleted. - // This notification contains a set of paths that are always updated together - // referenced by a globally unique prefix. - bool atomic = 6; -} - -// Update is a re-usable message that is used to store a particular Path, -// Value pair. -// Reference: gNMI Specification Section 2.1 -message Update { - Path path = 1; // The path (key) for the update. - Value value = 2 [deprecated=true]; // The value (value) for the update. - TypedValue val = 3; // The explicitly typed update value. - uint32 duplicates = 4; // Number of coalesced duplicates. -} - -// TypedValue is used to encode a value being sent between the client and -// target (originated by either entity). -message TypedValue { - // One of the fields within the val oneof is populated with the value - // of the update. The type of the value being included in the Update - // determines which field should be populated. In the case that the - // encoding is a particular form of the base protobuf type, a specific - // field is used to store the value (e.g., json_val). - oneof value { - string string_val = 1; // String value. - int64 int_val = 2; // Integer value. - uint64 uint_val = 3; // Unsigned integer value. - bool bool_val = 4; // Bool value. - bytes bytes_val = 5; // Arbitrary byte sequence value. - float float_val = 6; // Floating point value. - Decimal64 decimal_val = 7; // Decimal64 encoded value. - ScalarArray leaflist_val = 8; // Mixed type scalar array value. - google.protobuf.Any any_val = 9; // protobuf.Any encoded bytes. - bytes json_val = 10; // JSON-encoded text. - bytes json_ietf_val = 11; // JSON-encoded text per RFC7951. - string ascii_val = 12; // Arbitrary ASCII text. - // Protobuf binary encoded bytes. The message type is not included. - // See the specification at - // github.com/openconfig/reference/blob/master/rpc/gnmi/protobuf-vals.md - // for a complete specification. - bytes proto_bytes = 13; - } -} - -// Path encodes a data tree path as a series of repeated strings, with -// each element of the path representing a data tree node name and the -// associated attributes. -// Reference: gNMI Specification Section 2.2.2. -message Path { - // Elements of the path are no longer encoded as a string, but rather within - // the elem field as a PathElem message. - repeated string element = 1 [deprecated=true]; - string origin = 2; // Label to disambiguate path. - repeated PathElem elem = 3; // Elements of the path. - string target = 4; // The name of the target - // (Sec. 2.2.2.1) -} - -// PathElem encodes an element of a gNMI path, along with any attributes (keys) -// that may be associated with it. -// Reference: gNMI Specification Section 2.2.2. -message PathElem { - string name = 1; // The name of the element in the path. - map key = 2; // Map of key (attribute) name to value. -} - -// Value encodes a data tree node's value - along with the way in which -// the value is encoded. This message is deprecated by gNMI 0.3.0. -// Reference: gNMI Specification Section 2.2.3. -message Value { - option deprecated = true; - bytes value = 1; // Value of the variable being transmitted. - Encoding type = 2; // Encoding used for the value field. -} - -// Encoding defines the value encoding formats that are supported by the gNMI -// protocol. These encodings are used by both the client (when sending Set -// messages to modify the state of the target) and the target when serializing -// data to be returned to the client (in both Subscribe and Get RPCs). -// Reference: gNMI Specification Section 2.3 -enum Encoding { - JSON = 0; // JSON encoded text. - BYTES = 1; // Arbitrarily encoded bytes. - PROTO = 2; // Encoded according to out-of-band agreed Protobuf. - ASCII = 3; // ASCII text of an out-of-band agreed format. - JSON_IETF = 4; // JSON encoded text as per RFC7951. -} - -// Error message previously utilised to return errors to the client. Deprecated -// in favour of using the google.golang.org/genproto/googleapis/rpc/status -// message in the RPC response. -// Reference: gNMI Specification Section 2.5 -message Error { - option deprecated = true; - uint32 code = 1; // Canonical gRPC error code. - string message = 2; // Human readable error. - google.protobuf.Any data = 3; // Optional additional information. -} - -// Decimal64 is used to encode a fixed precision decimal number. The value -// is expressed as a set of digits with the precision specifying the -// number of digits following the decimal point in the digit set. -message Decimal64 { - int64 digits = 1; // Set of digits. - uint32 precision = 2; // Number of digits following the decimal point. -} - -// ScalarArray is used to encode a mixed-type array of values. -message ScalarArray { - // The set of elements within the array. Each TypedValue message should - // specify only elements that have a field identifier of 1-7 (i.e., the - // values are scalar values). - repeated TypedValue element = 1; -} - -// SubscribeRequest is the message sent by the client to the target when -// initiating a subscription to a set of paths within the data tree. The -// request field must be populated and the initial message must specify a -// SubscriptionList to initiate a subscription. The message is subsequently -// used to define aliases or trigger polled data to be sent by the target. -// Reference: gNMI Specification Section 3.5.1.1 -message SubscribeRequest { - oneof request { - SubscriptionList subscribe = 1; // Specify the paths within a subscription. - Poll poll = 3; // Trigger a polled update. - AliasList aliases = 4; // Aliases to be created. - } - // Extension messages associated with the SubscribeRequest. See the - // gNMI extension specification for further definition. - repeated gnmi_ext.Extension extension = 5; -} - -// Poll is sent within a SubscribeRequest to trigger the device to -// send telemetry updates for the paths that are associated with the -// subscription. -// Reference: gNMI Specification Section Section 3.5.1.4 -message Poll { -} - -// SubscribeResponse is the message used by the target within a Subscribe RPC. -// The target includes a Notification message which is used to transmit values -// of the path(s) that are associated with the subscription. The same message -// is to indicate that the target has sent all data values once (is -// synchronized). -// Reference: gNMI Specification Section 3.5.1.4 -message SubscribeResponse { - oneof response { - Notification update = 1; // Changed or sampled value for a path. - // Indicate target has sent all values associated with the subscription - // at least once. - bool sync_response = 3; - // Deprecated in favour of google.golang.org/genproto/googleapis/rpc/status - Error error = 4 [deprecated=true]; - } - // Extension messages associated with the SubscribeResponse. See the - // gNMI extension specification for further definition. - repeated gnmi_ext.Extension extension = 5; -} - -// SubscriptionList is used within a Subscribe message to specify the list of -// paths that the client wishes to subscribe to. The message consists of a -// list of (possibly prefixed) paths, and options that relate to the -// subscription. -// Reference: gNMI Specification Section 3.5.1.2 -message SubscriptionList { - Path prefix = 1; // Prefix used for paths. - repeated Subscription subscription = 2; // Set of subscriptions to create. - // Whether target defined aliases are allowed within the subscription. - bool use_aliases = 3; - QOSMarking qos = 4; // DSCP marking to be used. - // Mode of the subscription. - enum Mode { - STREAM = 0; // Values streamed by the target (Sec. 3.5.1.5.2). - ONCE = 1; // Values sent once-off by the target (Sec. 3.5.1.5.1). - POLL = 2; // Values sent in response to a poll request (Sec. 3.5.1.5.3). - } - Mode mode = 5; - // Whether elements of the schema that are marked as eligible for aggregation - // should be aggregated or not. - bool allow_aggregation = 6; - // The set of schemas that define the elements of the data tree that should - // be sent by the target. - repeated ModelData use_models = 7; - // The encoding that the target should use within the Notifications generated - // corresponding to the SubscriptionList. - Encoding encoding = 8; - // An optional field to specify that only updates to current state should be - // sent to a client. If set, the initial state is not sent to the client but - // rather only the sync message followed by any subsequent updates to the - // current state. For ONCE and POLL modes, this causes the server to send only - // the sync message (Sec. 3.5.2.3). - bool updates_only = 9; -} - -// Subscription is a single request within a SubscriptionList. The path -// specified is interpreted (along with the prefix) as the elements of the data -// tree that the client is subscribing to. The mode determines how the target -// should trigger updates to be sent. -// Reference: gNMI Specification Section 3.5.1.3 -message Subscription { - Path path = 1; // The data tree path. - SubscriptionMode mode = 2; // Subscription mode to be used. - uint64 sample_interval = 3; // ns between samples in SAMPLE mode. - // Indicates whether values that have not changed should be sent in a SAMPLE - // subscription. - bool suppress_redundant = 4; - // Specifies the maximum allowable silent period in nanoseconds when - // suppress_redundant is in use. The target should send a value at least once - // in the period specified. - uint64 heartbeat_interval = 5; -} - -// SubscriptionMode is the mode of the subscription, specifying how the -// target must return values in a subscription. -// Reference: gNMI Specification Section 3.5.1.3 -enum SubscriptionMode { - TARGET_DEFINED = 0; // The target selects the relevant mode for each element. - ON_CHANGE = 1; // The target sends an update on element value change. - SAMPLE = 2; // The target samples values according to the interval. -} - -// QOSMarking specifies the DSCP value to be set on transmitted telemetry -// updates from the target. -// Reference: gNMI Specification Section 3.5.1.2 -message QOSMarking { - uint32 marking = 1; -} - -// Alias specifies a data tree path, and an associated string which defines an -// alias which is to be used for this path in the context of the RPC. The alias -// is specified as a string which is prefixed with "#" to disambiguate it from -// data tree element paths. -// Reference: gNMI Specification Section 2.4.2 -message Alias { - Path path = 1; // The path to be aliased. - string alias = 2; // The alias value, a string prefixed by "#". -} - -// AliasList specifies a list of aliases. It is used in a SubscribeRequest for -// a client to create a set of aliases that the target is to utilize. -// Reference: gNMI Specification Section 3.5.1.6 -message AliasList { - repeated Alias alias = 1; // The set of aliases to be created. -} - -// SetRequest is sent from a client to the target to update values in the data -// tree. Paths are either deleted by the client, or modified by means of being -// updated, or replaced. Where a replace is used, unspecified values are -// considered to be replaced, whereas when update is used the changes are -// considered to be incremental. The set of changes that are specified within -// a single SetRequest are considered to be a transaction. -// Reference: gNMI Specification Section 3.4.1 -message SetRequest { - Path prefix = 1; // Prefix used for paths in the message. - repeated Path delete = 2; // Paths to be deleted from the data tree. - repeated Update replace = 3; // Updates specifying elements to be replaced. - repeated Update update = 4; // Updates specifying elements to updated. - // Extension messages associated with the SetRequest. See the - // gNMI extension specification for further definition. - repeated gnmi_ext.Extension extension = 5; -} - -// SetResponse is the response to a SetRequest, sent from the target to the -// client. It reports the result of the modifications to the data tree that were -// specified by the client. Errors for this RPC should be reported using the -// https://github.com/googleapis/googleapis/blob/master/google/rpc/status.proto -// message in the RPC return. The gnmi.Error message can be used to add additional -// details where required. -// Reference: gNMI Specification Section 3.4.2 -message SetResponse { - Path prefix = 1; // Prefix used for paths. - // A set of responses specifying the result of the operations specified in - // the SetRequest. - repeated UpdateResult response = 2; - Error message = 3 [deprecated=true]; // The overall status of the transaction. - int64 timestamp = 4; // Timestamp of transaction (ns since epoch). - // Extension messages associated with the SetResponse. See the - // gNMI extension specification for further definition. - repeated gnmi_ext.Extension extension = 5; -} - -// UpdateResult is used within the SetResponse message to communicate the -// result of an operation specified within a SetRequest message. -// Reference: gNMI Specification Section 3.4.2 -message UpdateResult { - // The operation that was associated with the Path specified. - enum Operation { - INVALID = 0; - DELETE = 1; // The result relates to a delete of Path. - REPLACE = 2; // The result relates to a replace of Path. - UPDATE = 3; // The result relates to an update of Path. - } - // Deprecated timestamp for the UpdateResult, this field has been - // replaced by the timestamp within the SetResponse message, since - // all mutations effected by a set should be applied as a single - // transaction. - int64 timestamp = 1 [deprecated=true]; - Path path = 2; // Path associated with the update. - Error message = 3 [deprecated=true]; // Status of the update operation. - Operation op = 4; // Update operation type. -} - -// GetRequest is sent when a client initiates a Get RPC. It is used to specify -// the set of data elements for which the target should return a snapshot of -// data. The use_models field specifies the set of schema modules that are to -// be used by the target - where use_models is not specified then the target -// must use all schema models that it has. -// Reference: gNMI Specification Section 3.3.1 -message GetRequest { - Path prefix = 1; // Prefix used for paths. - repeated Path path = 2; // Paths requested by the client. - // Type of elements within the data tree. - enum DataType { - ALL = 0; // All data elements. - CONFIG = 1; // Config (rw) only elements. - STATE = 2; // State (ro) only elements. - // Data elements marked in the schema as operational. This refers to data - // elements whose value relates to the state of processes or interactions - // running on the device. - OPERATIONAL = 3; - } - DataType type = 3; // The type of data being requested. - Encoding encoding = 5; // Encoding to be used. - repeated ModelData use_models = 6; // The schema models to be used. - // Extension messages associated with the GetRequest. See the - // gNMI extension specification for further definition. - repeated gnmi_ext.Extension extension = 7; -} - -// GetResponse is used by the target to respond to a GetRequest from a client. -// The set of Notifications corresponds to the data values that are requested -// by the client in the GetRequest. -// Reference: gNMI Specification Section 3.3.2 -message GetResponse { - repeated Notification notification = 1; // Data values. - Error error = 2 [deprecated=true]; // Errors that occurred in the Get. - // Extension messages associated with the GetResponse. See the - // gNMI extension specification for further definition. - repeated gnmi_ext.Extension extension = 3; -} - -// CapabilityRequest is sent by the client in the Capabilities RPC to request -// that the target reports its capabilities. -// Reference: gNMI Specification Section 3.2.1 -message CapabilityRequest { - // Extension messages associated with the CapabilityRequest. See the - // gNMI extension specification for further definition. - repeated gnmi_ext.Extension extension = 1; -} - -// CapabilityResponse is used by the target to report its capabilities to the -// client within the Capabilities RPC. -// Reference: gNMI Specification Section 3.2.2 -message CapabilityResponse { - repeated ModelData supported_models = 1; // Supported schema models. - repeated Encoding supported_encodings = 2; // Supported encodings. - string gNMI_version = 3; // Supported gNMI version. - // Extension messages associated with the CapabilityResponse. See the - // gNMI extension specification for further definition. - repeated gnmi_ext.Extension extension = 4; -} - -// ModelData is used to describe a set of schema modules. It can be used in a -// CapabilityResponse where a target reports the set of modules that it -// supports, and within the SubscribeRequest and GetRequest messages to specify -// the set of models from which data tree elements should be reported. -// Reference: gNMI Specification Section 3.2.3 -message ModelData { - string name = 1; // Name of the model. - string organization = 2; // Organization publishing the model. - string version = 3; // Semantic version of the model. -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi/gnmi_pb2.py b/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi/gnmi_pb2.py deleted file mode 100644 index bdace9a84..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi/gnmi_pb2.py +++ /dev/null @@ -1,1891 +0,0 @@ -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: proto/gnmi/gnmi.proto - -import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) -from google.protobuf.internal import enum_type_wrapper -from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection -from google.protobuf import symbol_database as _symbol_database -from google.protobuf import descriptor_pb2 -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - -from google.protobuf import any_pb2 as google_dot_protobuf_dot_any__pb2 -from google.protobuf import descriptor_pb2 as google_dot_protobuf_dot_descriptor__pb2 -from github.com.openconfig.gnmi.proto.gnmi_ext import gnmi_ext_pb2 as github_dot_com_dot_openconfig_dot_gnmi_dot_proto_dot_gnmi__ext_dot_gnmi__ext__pb2 - - -DESCRIPTOR = _descriptor.FileDescriptor( - name='proto/gnmi/gnmi.proto', - package='gnmi', - syntax='proto3', - serialized_pb=_b('\n\x15proto/gnmi/gnmi.proto\x12\x04gnmi\x1a\x19google/protobuf/any.proto\x1a google/protobuf/descriptor.proto\x1a\x38github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.proto\"\x86\x01\n\x0cNotification\x12\x11\n\ttimestamp\x18\x01 \x01(\x03\x12\x1a\n\x06prefix\x18\x02 \x01(\x0b\x32\n.gnmi.Path\x12\r\n\x05\x61lias\x18\x03 \x01(\t\x12\x1c\n\x06update\x18\x04 \x03(\x0b\x32\x0c.gnmi.Update\x12\x1a\n\x06\x64\x65lete\x18\x05 \x03(\x0b\x32\n.gnmi.Path\"u\n\x06Update\x12\x18\n\x04path\x18\x01 \x01(\x0b\x32\n.gnmi.Path\x12\x1e\n\x05value\x18\x02 \x01(\x0b\x32\x0b.gnmi.ValueB\x02\x18\x01\x12\x1d\n\x03val\x18\x03 \x01(\x0b\x32\x10.gnmi.TypedValue\x12\x12\n\nduplicates\x18\x04 \x01(\r\"\xce\x02\n\nTypedValue\x12\x14\n\nstring_val\x18\x01 \x01(\tH\x00\x12\x11\n\x07int_val\x18\x02 \x01(\x03H\x00\x12\x12\n\x08uint_val\x18\x03 \x01(\x04H\x00\x12\x12\n\x08\x62ool_val\x18\x04 \x01(\x08H\x00\x12\x13\n\tbytes_val\x18\x05 \x01(\x0cH\x00\x12\x13\n\tfloat_val\x18\x06 \x01(\x02H\x00\x12&\n\x0b\x64\x65\x63imal_val\x18\x07 \x01(\x0b\x32\x0f.gnmi.Decimal64H\x00\x12)\n\x0cleaflist_val\x18\x08 \x01(\x0b\x32\x11.gnmi.ScalarArrayH\x00\x12\'\n\x07\x61ny_val\x18\t \x01(\x0b\x32\x14.google.protobuf.AnyH\x00\x12\x12\n\x08json_val\x18\n \x01(\x0cH\x00\x12\x17\n\rjson_ietf_val\x18\x0b \x01(\x0cH\x00\x12\x13\n\tascii_val\x18\x0c \x01(\tH\x00\x42\x07\n\x05value\"Y\n\x04Path\x12\x13\n\x07\x65lement\x18\x01 \x03(\tB\x02\x18\x01\x12\x0e\n\x06origin\x18\x02 \x01(\t\x12\x1c\n\x04\x65lem\x18\x03 \x03(\x0b\x32\x0e.gnmi.PathElem\x12\x0e\n\x06target\x18\x04 \x01(\t\"j\n\x08PathElem\x12\x0c\n\x04name\x18\x01 \x01(\t\x12$\n\x03key\x18\x02 \x03(\x0b\x32\x17.gnmi.PathElem.KeyEntry\x1a*\n\x08KeyEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"8\n\x05Value\x12\r\n\x05value\x18\x01 \x01(\x0c\x12\x1c\n\x04type\x18\x02 \x01(\x0e\x32\x0e.gnmi.Encoding:\x02\x18\x01\"N\n\x05\x45rror\x12\x0c\n\x04\x63ode\x18\x01 \x01(\r\x12\x0f\n\x07message\x18\x02 \x01(\t\x12\"\n\x04\x64\x61ta\x18\x03 \x01(\x0b\x32\x14.google.protobuf.Any:\x02\x18\x01\".\n\tDecimal64\x12\x0e\n\x06\x64igits\x18\x01 \x01(\x03\x12\x11\n\tprecision\x18\x02 \x01(\r\"0\n\x0bScalarArray\x12!\n\x07\x65lement\x18\x01 \x03(\x0b\x32\x10.gnmi.TypedValue\"\xb2\x01\n\x10SubscribeRequest\x12+\n\tsubscribe\x18\x01 \x01(\x0b\x32\x16.gnmi.SubscriptionListH\x00\x12\x1a\n\x04poll\x18\x03 \x01(\x0b\x32\n.gnmi.PollH\x00\x12\"\n\x07\x61liases\x18\x04 \x01(\x0b\x32\x0f.gnmi.AliasListH\x00\x12&\n\textension\x18\x05 \x03(\x0b\x32\x13.gnmi_ext.ExtensionB\t\n\x07request\"\x06\n\x04Poll\"\xa8\x01\n\x11SubscribeResponse\x12$\n\x06update\x18\x01 \x01(\x0b\x32\x12.gnmi.NotificationH\x00\x12\x17\n\rsync_response\x18\x03 \x01(\x08H\x00\x12 \n\x05\x65rror\x18\x04 \x01(\x0b\x32\x0b.gnmi.ErrorB\x02\x18\x01H\x00\x12&\n\textension\x18\x05 \x03(\x0b\x32\x13.gnmi_ext.ExtensionB\n\n\x08response\"\xd7\x02\n\x10SubscriptionList\x12\x1a\n\x06prefix\x18\x01 \x01(\x0b\x32\n.gnmi.Path\x12(\n\x0csubscription\x18\x02 \x03(\x0b\x32\x12.gnmi.Subscription\x12\x13\n\x0buse_aliases\x18\x03 \x01(\x08\x12\x1d\n\x03qos\x18\x04 \x01(\x0b\x32\x10.gnmi.QOSMarking\x12)\n\x04mode\x18\x05 \x01(\x0e\x32\x1b.gnmi.SubscriptionList.Mode\x12\x19\n\x11\x61llow_aggregation\x18\x06 \x01(\x08\x12#\n\nuse_models\x18\x07 \x03(\x0b\x32\x0f.gnmi.ModelData\x12 \n\x08\x65ncoding\x18\x08 \x01(\x0e\x32\x0e.gnmi.Encoding\x12\x14\n\x0cupdates_only\x18\t \x01(\x08\"&\n\x04Mode\x12\n\n\x06STREAM\x10\x00\x12\x08\n\x04ONCE\x10\x01\x12\x08\n\x04POLL\x10\x02\"\x9f\x01\n\x0cSubscription\x12\x18\n\x04path\x18\x01 \x01(\x0b\x32\n.gnmi.Path\x12$\n\x04mode\x18\x02 \x01(\x0e\x32\x16.gnmi.SubscriptionMode\x12\x17\n\x0fsample_interval\x18\x03 \x01(\x04\x12\x1a\n\x12suppress_redundant\x18\x04 \x01(\x08\x12\x1a\n\x12heartbeat_interval\x18\x05 \x01(\x04\"\x1d\n\nQOSMarking\x12\x0f\n\x07marking\x18\x01 \x01(\r\"0\n\x05\x41lias\x12\x18\n\x04path\x18\x01 \x01(\x0b\x32\n.gnmi.Path\x12\r\n\x05\x61lias\x18\x02 \x01(\t\"\'\n\tAliasList\x12\x1a\n\x05\x61lias\x18\x01 \x03(\x0b\x32\x0b.gnmi.Alias\"\xa9\x01\n\nSetRequest\x12\x1a\n\x06prefix\x18\x01 \x01(\x0b\x32\n.gnmi.Path\x12\x1a\n\x06\x64\x65lete\x18\x02 \x03(\x0b\x32\n.gnmi.Path\x12\x1d\n\x07replace\x18\x03 \x03(\x0b\x32\x0c.gnmi.Update\x12\x1c\n\x06update\x18\x04 \x03(\x0b\x32\x0c.gnmi.Update\x12&\n\textension\x18\x05 \x03(\x0b\x32\x13.gnmi_ext.Extension\"\xac\x01\n\x0bSetResponse\x12\x1a\n\x06prefix\x18\x01 \x01(\x0b\x32\n.gnmi.Path\x12$\n\x08response\x18\x02 \x03(\x0b\x32\x12.gnmi.UpdateResult\x12 \n\x07message\x18\x03 \x01(\x0b\x32\x0b.gnmi.ErrorB\x02\x18\x01\x12\x11\n\ttimestamp\x18\x04 \x01(\x03\x12&\n\textension\x18\x05 \x03(\x0b\x32\x13.gnmi_ext.Extension\"\xca\x01\n\x0cUpdateResult\x12\x15\n\ttimestamp\x18\x01 \x01(\x03\x42\x02\x18\x01\x12\x18\n\x04path\x18\x02 \x01(\x0b\x32\n.gnmi.Path\x12 \n\x07message\x18\x03 \x01(\x0b\x32\x0b.gnmi.ErrorB\x02\x18\x01\x12(\n\x02op\x18\x04 \x01(\x0e\x32\x1c.gnmi.UpdateResult.Operation\"=\n\tOperation\x12\x0b\n\x07INVALID\x10\x00\x12\n\n\x06\x44\x45LETE\x10\x01\x12\x0b\n\x07REPLACE\x10\x02\x12\n\n\x06UPDATE\x10\x03\"\x97\x02\n\nGetRequest\x12\x1a\n\x06prefix\x18\x01 \x01(\x0b\x32\n.gnmi.Path\x12\x18\n\x04path\x18\x02 \x03(\x0b\x32\n.gnmi.Path\x12\'\n\x04type\x18\x03 \x01(\x0e\x32\x19.gnmi.GetRequest.DataType\x12 \n\x08\x65ncoding\x18\x05 \x01(\x0e\x32\x0e.gnmi.Encoding\x12#\n\nuse_models\x18\x06 \x03(\x0b\x32\x0f.gnmi.ModelData\x12&\n\textension\x18\x07 \x03(\x0b\x32\x13.gnmi_ext.Extension\";\n\x08\x44\x61taType\x12\x07\n\x03\x41LL\x10\x00\x12\n\n\x06\x43ONFIG\x10\x01\x12\t\n\x05STATE\x10\x02\x12\x0f\n\x0bOPERATIONAL\x10\x03\"\x7f\n\x0bGetResponse\x12(\n\x0cnotification\x18\x01 \x03(\x0b\x32\x12.gnmi.Notification\x12\x1e\n\x05\x65rror\x18\x02 \x01(\x0b\x32\x0b.gnmi.ErrorB\x02\x18\x01\x12&\n\textension\x18\x03 \x03(\x0b\x32\x13.gnmi_ext.Extension\";\n\x11\x43\x61pabilityRequest\x12&\n\textension\x18\x01 \x03(\x0b\x32\x13.gnmi_ext.Extension\"\xaa\x01\n\x12\x43\x61pabilityResponse\x12)\n\x10supported_models\x18\x01 \x03(\x0b\x32\x0f.gnmi.ModelData\x12+\n\x13supported_encodings\x18\x02 \x03(\x0e\x32\x0e.gnmi.Encoding\x12\x14\n\x0cgNMI_version\x18\x03 \x01(\t\x12&\n\textension\x18\x04 \x03(\x0b\x32\x13.gnmi_ext.Extension\"@\n\tModelData\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x14\n\x0corganization\x18\x02 \x01(\t\x12\x0f\n\x07version\x18\x03 \x01(\t*D\n\x08\x45ncoding\x12\x08\n\x04JSON\x10\x00\x12\t\n\x05\x42YTES\x10\x01\x12\t\n\x05PROTO\x10\x02\x12\t\n\x05\x41SCII\x10\x03\x12\r\n\tJSON_IETF\x10\x04*A\n\x10SubscriptionMode\x12\x12\n\x0eTARGET_DEFINED\x10\x00\x12\r\n\tON_CHANGE\x10\x01\x12\n\n\x06SAMPLE\x10\x02\x32\xe3\x01\n\x04gNMI\x12\x41\n\x0c\x43\x61pabilities\x12\x17.gnmi.CapabilityRequest\x1a\x18.gnmi.CapabilityResponse\x12*\n\x03Get\x12\x10.gnmi.GetRequest\x1a\x11.gnmi.GetResponse\x12*\n\x03Set\x12\x10.gnmi.SetRequest\x1a\x11.gnmi.SetResponse\x12@\n\tSubscribe\x12\x16.gnmi.SubscribeRequest\x1a\x17.gnmi.SubscribeResponse(\x01\x30\x01:3\n\x0cgnmi_service\x12\x1c.google.protobuf.FileOptions\x18\xe9\x07 \x01(\tB\x08\xca>\x05\x30.6.0b\x06proto3') - , - dependencies=[google_dot_protobuf_dot_any__pb2.DESCRIPTOR,google_dot_protobuf_dot_descriptor__pb2.DESCRIPTOR,github_dot_com_dot_openconfig_dot_gnmi_dot_proto_dot_gnmi__ext_dot_gnmi__ext__pb2.DESCRIPTOR,]) - -_ENCODING = _descriptor.EnumDescriptor( - name='Encoding', - full_name='gnmi.Encoding', - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name='JSON', index=0, number=0, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='BYTES', index=1, number=1, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='PROTO', index=2, number=2, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='ASCII', index=3, number=3, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='JSON_IETF', index=4, number=4, - options=None, - type=None), - ], - containing_type=None, - options=None, - serialized_start=3431, - serialized_end=3499, -) -_sym_db.RegisterEnumDescriptor(_ENCODING) - -Encoding = enum_type_wrapper.EnumTypeWrapper(_ENCODING) -_SUBSCRIPTIONMODE = _descriptor.EnumDescriptor( - name='SubscriptionMode', - full_name='gnmi.SubscriptionMode', - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name='TARGET_DEFINED', index=0, number=0, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='ON_CHANGE', index=1, number=1, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='SAMPLE', index=2, number=2, - options=None, - type=None), - ], - containing_type=None, - options=None, - serialized_start=3501, - serialized_end=3566, -) -_sym_db.RegisterEnumDescriptor(_SUBSCRIPTIONMODE) - -SubscriptionMode = enum_type_wrapper.EnumTypeWrapper(_SUBSCRIPTIONMODE) -JSON = 0 -BYTES = 1 -PROTO = 2 -ASCII = 3 -JSON_IETF = 4 -TARGET_DEFINED = 0 -ON_CHANGE = 1 -SAMPLE = 2 - -GNMI_SERVICE_FIELD_NUMBER = 1001 -gnmi_service = _descriptor.FieldDescriptor( - name='gnmi_service', full_name='gnmi.gnmi_service', index=0, - number=1001, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=True, extension_scope=None, - options=None, file=DESCRIPTOR) - -_SUBSCRIPTIONLIST_MODE = _descriptor.EnumDescriptor( - name='Mode', - full_name='gnmi.SubscriptionList.Mode', - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name='STREAM', index=0, number=0, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='ONCE', index=1, number=1, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='POLL', index=2, number=2, - options=None, - type=None), - ], - containing_type=None, - options=None, - serialized_start=1844, - serialized_end=1882, -) -_sym_db.RegisterEnumDescriptor(_SUBSCRIPTIONLIST_MODE) - -_UPDATERESULT_OPERATION = _descriptor.EnumDescriptor( - name='Operation', - full_name='gnmi.UpdateResult.Operation', - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name='INVALID', index=0, number=0, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='DELETE', index=1, number=1, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='REPLACE', index=2, number=2, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='UPDATE', index=3, number=3, - options=None, - type=None), - ], - containing_type=None, - options=None, - serialized_start=2657, - serialized_end=2718, -) -_sym_db.RegisterEnumDescriptor(_UPDATERESULT_OPERATION) - -_GETREQUEST_DATATYPE = _descriptor.EnumDescriptor( - name='DataType', - full_name='gnmi.GetRequest.DataType', - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name='ALL', index=0, number=0, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='CONFIG', index=1, number=1, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='STATE', index=2, number=2, - options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='OPERATIONAL', index=3, number=3, - options=None, - type=None), - ], - containing_type=None, - options=None, - serialized_start=2941, - serialized_end=3000, -) -_sym_db.RegisterEnumDescriptor(_GETREQUEST_DATATYPE) - - -_NOTIFICATION = _descriptor.Descriptor( - name='Notification', - full_name='gnmi.Notification', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='timestamp', full_name='gnmi.Notification.timestamp', index=0, - number=1, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='prefix', full_name='gnmi.Notification.prefix', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='alias', full_name='gnmi.Notification.alias', index=2, - number=3, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='update', full_name='gnmi.Notification.update', index=3, - number=4, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='delete', full_name='gnmi.Notification.delete', index=4, - number=5, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=151, - serialized_end=285, -) - - -_UPDATE = _descriptor.Descriptor( - name='Update', - full_name='gnmi.Update', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='path', full_name='gnmi.Update.path', index=0, - number=1, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='value', full_name='gnmi.Update.value', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=_descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\030\001')), file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='val', full_name='gnmi.Update.val', index=2, - number=3, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='duplicates', full_name='gnmi.Update.duplicates', index=3, - number=4, type=13, cpp_type=3, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=287, - serialized_end=404, -) - - -_TYPEDVALUE = _descriptor.Descriptor( - name='TypedValue', - full_name='gnmi.TypedValue', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='string_val', full_name='gnmi.TypedValue.string_val', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='int_val', full_name='gnmi.TypedValue.int_val', index=1, - number=2, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='uint_val', full_name='gnmi.TypedValue.uint_val', index=2, - number=3, type=4, cpp_type=4, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='bool_val', full_name='gnmi.TypedValue.bool_val', index=3, - number=4, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='bytes_val', full_name='gnmi.TypedValue.bytes_val', index=4, - number=5, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='float_val', full_name='gnmi.TypedValue.float_val', index=5, - number=6, type=2, cpp_type=6, label=1, - has_default_value=False, default_value=float(0), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='decimal_val', full_name='gnmi.TypedValue.decimal_val', index=6, - number=7, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='leaflist_val', full_name='gnmi.TypedValue.leaflist_val', index=7, - number=8, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='any_val', full_name='gnmi.TypedValue.any_val', index=8, - number=9, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='json_val', full_name='gnmi.TypedValue.json_val', index=9, - number=10, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='json_ietf_val', full_name='gnmi.TypedValue.json_ietf_val', index=10, - number=11, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='ascii_val', full_name='gnmi.TypedValue.ascii_val', index=11, - number=12, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - _descriptor.OneofDescriptor( - name='value', full_name='gnmi.TypedValue.value', - index=0, containing_type=None, fields=[]), - ], - serialized_start=407, - serialized_end=741, -) - - -_PATH = _descriptor.Descriptor( - name='Path', - full_name='gnmi.Path', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='element', full_name='gnmi.Path.element', index=0, - number=1, type=9, cpp_type=9, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=_descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\030\001')), file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='origin', full_name='gnmi.Path.origin', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='elem', full_name='gnmi.Path.elem', index=2, - number=3, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='target', full_name='gnmi.Path.target', index=3, - number=4, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=743, - serialized_end=832, -) - - -_PATHELEM_KEYENTRY = _descriptor.Descriptor( - name='KeyEntry', - full_name='gnmi.PathElem.KeyEntry', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='key', full_name='gnmi.PathElem.KeyEntry.key', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='value', full_name='gnmi.PathElem.KeyEntry.value', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=_descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')), - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=898, - serialized_end=940, -) - -_PATHELEM = _descriptor.Descriptor( - name='PathElem', - full_name='gnmi.PathElem', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='name', full_name='gnmi.PathElem.name', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='key', full_name='gnmi.PathElem.key', index=1, - number=2, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[_PATHELEM_KEYENTRY, ], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=834, - serialized_end=940, -) - - -_VALUE = _descriptor.Descriptor( - name='Value', - full_name='gnmi.Value', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='value', full_name='gnmi.Value.value', index=0, - number=1, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='type', full_name='gnmi.Value.type', index=1, - number=2, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=_descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('\030\001')), - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=942, - serialized_end=998, -) - - -_ERROR = _descriptor.Descriptor( - name='Error', - full_name='gnmi.Error', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='code', full_name='gnmi.Error.code', index=0, - number=1, type=13, cpp_type=3, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='message', full_name='gnmi.Error.message', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='data', full_name='gnmi.Error.data', index=2, - number=3, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=_descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('\030\001')), - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1000, - serialized_end=1078, -) - - -_DECIMAL64 = _descriptor.Descriptor( - name='Decimal64', - full_name='gnmi.Decimal64', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='digits', full_name='gnmi.Decimal64.digits', index=0, - number=1, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='precision', full_name='gnmi.Decimal64.precision', index=1, - number=2, type=13, cpp_type=3, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1080, - serialized_end=1126, -) - - -_SCALARARRAY = _descriptor.Descriptor( - name='ScalarArray', - full_name='gnmi.ScalarArray', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='element', full_name='gnmi.ScalarArray.element', index=0, - number=1, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1128, - serialized_end=1176, -) - - -_SUBSCRIBEREQUEST = _descriptor.Descriptor( - name='SubscribeRequest', - full_name='gnmi.SubscribeRequest', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='subscribe', full_name='gnmi.SubscribeRequest.subscribe', index=0, - number=1, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='poll', full_name='gnmi.SubscribeRequest.poll', index=1, - number=3, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='aliases', full_name='gnmi.SubscribeRequest.aliases', index=2, - number=4, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='extension', full_name='gnmi.SubscribeRequest.extension', index=3, - number=5, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - _descriptor.OneofDescriptor( - name='request', full_name='gnmi.SubscribeRequest.request', - index=0, containing_type=None, fields=[]), - ], - serialized_start=1179, - serialized_end=1357, -) - - -_POLL = _descriptor.Descriptor( - name='Poll', - full_name='gnmi.Poll', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1359, - serialized_end=1365, -) - - -_SUBSCRIBERESPONSE = _descriptor.Descriptor( - name='SubscribeResponse', - full_name='gnmi.SubscribeResponse', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='update', full_name='gnmi.SubscribeResponse.update', index=0, - number=1, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='sync_response', full_name='gnmi.SubscribeResponse.sync_response', index=1, - number=3, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='error', full_name='gnmi.SubscribeResponse.error', index=2, - number=4, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=_descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\030\001')), file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='extension', full_name='gnmi.SubscribeResponse.extension', index=3, - number=5, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - _descriptor.OneofDescriptor( - name='response', full_name='gnmi.SubscribeResponse.response', - index=0, containing_type=None, fields=[]), - ], - serialized_start=1368, - serialized_end=1536, -) - - -_SUBSCRIPTIONLIST = _descriptor.Descriptor( - name='SubscriptionList', - full_name='gnmi.SubscriptionList', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='prefix', full_name='gnmi.SubscriptionList.prefix', index=0, - number=1, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='subscription', full_name='gnmi.SubscriptionList.subscription', index=1, - number=2, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='use_aliases', full_name='gnmi.SubscriptionList.use_aliases', index=2, - number=3, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='qos', full_name='gnmi.SubscriptionList.qos', index=3, - number=4, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='mode', full_name='gnmi.SubscriptionList.mode', index=4, - number=5, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='allow_aggregation', full_name='gnmi.SubscriptionList.allow_aggregation', index=5, - number=6, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='use_models', full_name='gnmi.SubscriptionList.use_models', index=6, - number=7, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='encoding', full_name='gnmi.SubscriptionList.encoding', index=7, - number=8, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='updates_only', full_name='gnmi.SubscriptionList.updates_only', index=8, - number=9, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - _SUBSCRIPTIONLIST_MODE, - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1539, - serialized_end=1882, -) - - -_SUBSCRIPTION = _descriptor.Descriptor( - name='Subscription', - full_name='gnmi.Subscription', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='path', full_name='gnmi.Subscription.path', index=0, - number=1, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='mode', full_name='gnmi.Subscription.mode', index=1, - number=2, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='sample_interval', full_name='gnmi.Subscription.sample_interval', index=2, - number=3, type=4, cpp_type=4, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='suppress_redundant', full_name='gnmi.Subscription.suppress_redundant', index=3, - number=4, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='heartbeat_interval', full_name='gnmi.Subscription.heartbeat_interval', index=4, - number=5, type=4, cpp_type=4, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1885, - serialized_end=2044, -) - - -_QOSMARKING = _descriptor.Descriptor( - name='QOSMarking', - full_name='gnmi.QOSMarking', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='marking', full_name='gnmi.QOSMarking.marking', index=0, - number=1, type=13, cpp_type=3, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=2046, - serialized_end=2075, -) - - -_ALIAS = _descriptor.Descriptor( - name='Alias', - full_name='gnmi.Alias', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='path', full_name='gnmi.Alias.path', index=0, - number=1, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='alias', full_name='gnmi.Alias.alias', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=2077, - serialized_end=2125, -) - - -_ALIASLIST = _descriptor.Descriptor( - name='AliasList', - full_name='gnmi.AliasList', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='alias', full_name='gnmi.AliasList.alias', index=0, - number=1, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=2127, - serialized_end=2166, -) - - -_SETREQUEST = _descriptor.Descriptor( - name='SetRequest', - full_name='gnmi.SetRequest', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='prefix', full_name='gnmi.SetRequest.prefix', index=0, - number=1, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='delete', full_name='gnmi.SetRequest.delete', index=1, - number=2, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='replace', full_name='gnmi.SetRequest.replace', index=2, - number=3, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='update', full_name='gnmi.SetRequest.update', index=3, - number=4, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='extension', full_name='gnmi.SetRequest.extension', index=4, - number=5, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=2169, - serialized_end=2338, -) - - -_SETRESPONSE = _descriptor.Descriptor( - name='SetResponse', - full_name='gnmi.SetResponse', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='prefix', full_name='gnmi.SetResponse.prefix', index=0, - number=1, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='response', full_name='gnmi.SetResponse.response', index=1, - number=2, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='message', full_name='gnmi.SetResponse.message', index=2, - number=3, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=_descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\030\001')), file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='timestamp', full_name='gnmi.SetResponse.timestamp', index=3, - number=4, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='extension', full_name='gnmi.SetResponse.extension', index=4, - number=5, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=2341, - serialized_end=2513, -) - - -_UPDATERESULT = _descriptor.Descriptor( - name='UpdateResult', - full_name='gnmi.UpdateResult', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='timestamp', full_name='gnmi.UpdateResult.timestamp', index=0, - number=1, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=_descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\030\001')), file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='path', full_name='gnmi.UpdateResult.path', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='message', full_name='gnmi.UpdateResult.message', index=2, - number=3, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=_descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\030\001')), file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='op', full_name='gnmi.UpdateResult.op', index=3, - number=4, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - _UPDATERESULT_OPERATION, - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=2516, - serialized_end=2718, -) - - -_GETREQUEST = _descriptor.Descriptor( - name='GetRequest', - full_name='gnmi.GetRequest', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='prefix', full_name='gnmi.GetRequest.prefix', index=0, - number=1, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='path', full_name='gnmi.GetRequest.path', index=1, - number=2, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='type', full_name='gnmi.GetRequest.type', index=2, - number=3, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='encoding', full_name='gnmi.GetRequest.encoding', index=3, - number=5, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='use_models', full_name='gnmi.GetRequest.use_models', index=4, - number=6, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='extension', full_name='gnmi.GetRequest.extension', index=5, - number=7, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - _GETREQUEST_DATATYPE, - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=2721, - serialized_end=3000, -) - - -_GETRESPONSE = _descriptor.Descriptor( - name='GetResponse', - full_name='gnmi.GetResponse', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='notification', full_name='gnmi.GetResponse.notification', index=0, - number=1, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='error', full_name='gnmi.GetResponse.error', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=_descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\030\001')), file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='extension', full_name='gnmi.GetResponse.extension', index=2, - number=3, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=3002, - serialized_end=3129, -) - - -_CAPABILITYREQUEST = _descriptor.Descriptor( - name='CapabilityRequest', - full_name='gnmi.CapabilityRequest', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='extension', full_name='gnmi.CapabilityRequest.extension', index=0, - number=1, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=3131, - serialized_end=3190, -) - - -_CAPABILITYRESPONSE = _descriptor.Descriptor( - name='CapabilityResponse', - full_name='gnmi.CapabilityResponse', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='supported_models', full_name='gnmi.CapabilityResponse.supported_models', index=0, - number=1, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='supported_encodings', full_name='gnmi.CapabilityResponse.supported_encodings', index=1, - number=2, type=14, cpp_type=8, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='gNMI_version', full_name='gnmi.CapabilityResponse.gNMI_version', index=2, - number=3, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='extension', full_name='gnmi.CapabilityResponse.extension', index=3, - number=4, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=3193, - serialized_end=3363, -) - - -_MODELDATA = _descriptor.Descriptor( - name='ModelData', - full_name='gnmi.ModelData', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='name', full_name='gnmi.ModelData.name', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='organization', full_name='gnmi.ModelData.organization', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='version', full_name='gnmi.ModelData.version', index=2, - number=3, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=3365, - serialized_end=3429, -) - -_NOTIFICATION.fields_by_name['prefix'].message_type = _PATH -_NOTIFICATION.fields_by_name['update'].message_type = _UPDATE -_NOTIFICATION.fields_by_name['delete'].message_type = _PATH -_UPDATE.fields_by_name['path'].message_type = _PATH -_UPDATE.fields_by_name['value'].message_type = _VALUE -_UPDATE.fields_by_name['val'].message_type = _TYPEDVALUE -_TYPEDVALUE.fields_by_name['decimal_val'].message_type = _DECIMAL64 -_TYPEDVALUE.fields_by_name['leaflist_val'].message_type = _SCALARARRAY -_TYPEDVALUE.fields_by_name['any_val'].message_type = google_dot_protobuf_dot_any__pb2._ANY -_TYPEDVALUE.oneofs_by_name['value'].fields.append( - _TYPEDVALUE.fields_by_name['string_val']) -_TYPEDVALUE.fields_by_name['string_val'].containing_oneof = _TYPEDVALUE.oneofs_by_name['value'] -_TYPEDVALUE.oneofs_by_name['value'].fields.append( - _TYPEDVALUE.fields_by_name['int_val']) -_TYPEDVALUE.fields_by_name['int_val'].containing_oneof = _TYPEDVALUE.oneofs_by_name['value'] -_TYPEDVALUE.oneofs_by_name['value'].fields.append( - _TYPEDVALUE.fields_by_name['uint_val']) -_TYPEDVALUE.fields_by_name['uint_val'].containing_oneof = _TYPEDVALUE.oneofs_by_name['value'] -_TYPEDVALUE.oneofs_by_name['value'].fields.append( - _TYPEDVALUE.fields_by_name['bool_val']) -_TYPEDVALUE.fields_by_name['bool_val'].containing_oneof = _TYPEDVALUE.oneofs_by_name['value'] -_TYPEDVALUE.oneofs_by_name['value'].fields.append( - _TYPEDVALUE.fields_by_name['bytes_val']) -_TYPEDVALUE.fields_by_name['bytes_val'].containing_oneof = _TYPEDVALUE.oneofs_by_name['value'] -_TYPEDVALUE.oneofs_by_name['value'].fields.append( - _TYPEDVALUE.fields_by_name['float_val']) -_TYPEDVALUE.fields_by_name['float_val'].containing_oneof = _TYPEDVALUE.oneofs_by_name['value'] -_TYPEDVALUE.oneofs_by_name['value'].fields.append( - _TYPEDVALUE.fields_by_name['decimal_val']) -_TYPEDVALUE.fields_by_name['decimal_val'].containing_oneof = _TYPEDVALUE.oneofs_by_name['value'] -_TYPEDVALUE.oneofs_by_name['value'].fields.append( - _TYPEDVALUE.fields_by_name['leaflist_val']) -_TYPEDVALUE.fields_by_name['leaflist_val'].containing_oneof = _TYPEDVALUE.oneofs_by_name['value'] -_TYPEDVALUE.oneofs_by_name['value'].fields.append( - _TYPEDVALUE.fields_by_name['any_val']) -_TYPEDVALUE.fields_by_name['any_val'].containing_oneof = _TYPEDVALUE.oneofs_by_name['value'] -_TYPEDVALUE.oneofs_by_name['value'].fields.append( - _TYPEDVALUE.fields_by_name['json_val']) -_TYPEDVALUE.fields_by_name['json_val'].containing_oneof = _TYPEDVALUE.oneofs_by_name['value'] -_TYPEDVALUE.oneofs_by_name['value'].fields.append( - _TYPEDVALUE.fields_by_name['json_ietf_val']) -_TYPEDVALUE.fields_by_name['json_ietf_val'].containing_oneof = _TYPEDVALUE.oneofs_by_name['value'] -_TYPEDVALUE.oneofs_by_name['value'].fields.append( - _TYPEDVALUE.fields_by_name['ascii_val']) -_TYPEDVALUE.fields_by_name['ascii_val'].containing_oneof = _TYPEDVALUE.oneofs_by_name['value'] -_PATH.fields_by_name['elem'].message_type = _PATHELEM -_PATHELEM_KEYENTRY.containing_type = _PATHELEM -_PATHELEM.fields_by_name['key'].message_type = _PATHELEM_KEYENTRY -_VALUE.fields_by_name['type'].enum_type = _ENCODING -_ERROR.fields_by_name['data'].message_type = google_dot_protobuf_dot_any__pb2._ANY -_SCALARARRAY.fields_by_name['element'].message_type = _TYPEDVALUE -_SUBSCRIBEREQUEST.fields_by_name['subscribe'].message_type = _SUBSCRIPTIONLIST -_SUBSCRIBEREQUEST.fields_by_name['poll'].message_type = _POLL -_SUBSCRIBEREQUEST.fields_by_name['aliases'].message_type = _ALIASLIST -_SUBSCRIBEREQUEST.fields_by_name['extension'].message_type = github_dot_com_dot_openconfig_dot_gnmi_dot_proto_dot_gnmi__ext_dot_gnmi__ext__pb2._EXTENSION -_SUBSCRIBEREQUEST.oneofs_by_name['request'].fields.append( - _SUBSCRIBEREQUEST.fields_by_name['subscribe']) -_SUBSCRIBEREQUEST.fields_by_name['subscribe'].containing_oneof = _SUBSCRIBEREQUEST.oneofs_by_name['request'] -_SUBSCRIBEREQUEST.oneofs_by_name['request'].fields.append( - _SUBSCRIBEREQUEST.fields_by_name['poll']) -_SUBSCRIBEREQUEST.fields_by_name['poll'].containing_oneof = _SUBSCRIBEREQUEST.oneofs_by_name['request'] -_SUBSCRIBEREQUEST.oneofs_by_name['request'].fields.append( - _SUBSCRIBEREQUEST.fields_by_name['aliases']) -_SUBSCRIBEREQUEST.fields_by_name['aliases'].containing_oneof = _SUBSCRIBEREQUEST.oneofs_by_name['request'] -_SUBSCRIBERESPONSE.fields_by_name['update'].message_type = _NOTIFICATION -_SUBSCRIBERESPONSE.fields_by_name['error'].message_type = _ERROR -_SUBSCRIBERESPONSE.fields_by_name['extension'].message_type = github_dot_com_dot_openconfig_dot_gnmi_dot_proto_dot_gnmi__ext_dot_gnmi__ext__pb2._EXTENSION -_SUBSCRIBERESPONSE.oneofs_by_name['response'].fields.append( - _SUBSCRIBERESPONSE.fields_by_name['update']) -_SUBSCRIBERESPONSE.fields_by_name['update'].containing_oneof = _SUBSCRIBERESPONSE.oneofs_by_name['response'] -_SUBSCRIBERESPONSE.oneofs_by_name['response'].fields.append( - _SUBSCRIBERESPONSE.fields_by_name['sync_response']) -_SUBSCRIBERESPONSE.fields_by_name['sync_response'].containing_oneof = _SUBSCRIBERESPONSE.oneofs_by_name['response'] -_SUBSCRIBERESPONSE.oneofs_by_name['response'].fields.append( - _SUBSCRIBERESPONSE.fields_by_name['error']) -_SUBSCRIBERESPONSE.fields_by_name['error'].containing_oneof = _SUBSCRIBERESPONSE.oneofs_by_name['response'] -_SUBSCRIPTIONLIST.fields_by_name['prefix'].message_type = _PATH -_SUBSCRIPTIONLIST.fields_by_name['subscription'].message_type = _SUBSCRIPTION -_SUBSCRIPTIONLIST.fields_by_name['qos'].message_type = _QOSMARKING -_SUBSCRIPTIONLIST.fields_by_name['mode'].enum_type = _SUBSCRIPTIONLIST_MODE -_SUBSCRIPTIONLIST.fields_by_name['use_models'].message_type = _MODELDATA -_SUBSCRIPTIONLIST.fields_by_name['encoding'].enum_type = _ENCODING -_SUBSCRIPTIONLIST_MODE.containing_type = _SUBSCRIPTIONLIST -_SUBSCRIPTION.fields_by_name['path'].message_type = _PATH -_SUBSCRIPTION.fields_by_name['mode'].enum_type = _SUBSCRIPTIONMODE -_ALIAS.fields_by_name['path'].message_type = _PATH -_ALIASLIST.fields_by_name['alias'].message_type = _ALIAS -_SETREQUEST.fields_by_name['prefix'].message_type = _PATH -_SETREQUEST.fields_by_name['delete'].message_type = _PATH -_SETREQUEST.fields_by_name['replace'].message_type = _UPDATE -_SETREQUEST.fields_by_name['update'].message_type = _UPDATE -_SETREQUEST.fields_by_name['extension'].message_type = github_dot_com_dot_openconfig_dot_gnmi_dot_proto_dot_gnmi__ext_dot_gnmi__ext__pb2._EXTENSION -_SETRESPONSE.fields_by_name['prefix'].message_type = _PATH -_SETRESPONSE.fields_by_name['response'].message_type = _UPDATERESULT -_SETRESPONSE.fields_by_name['message'].message_type = _ERROR -_SETRESPONSE.fields_by_name['extension'].message_type = github_dot_com_dot_openconfig_dot_gnmi_dot_proto_dot_gnmi__ext_dot_gnmi__ext__pb2._EXTENSION -_UPDATERESULT.fields_by_name['path'].message_type = _PATH -_UPDATERESULT.fields_by_name['message'].message_type = _ERROR -_UPDATERESULT.fields_by_name['op'].enum_type = _UPDATERESULT_OPERATION -_UPDATERESULT_OPERATION.containing_type = _UPDATERESULT -_GETREQUEST.fields_by_name['prefix'].message_type = _PATH -_GETREQUEST.fields_by_name['path'].message_type = _PATH -_GETREQUEST.fields_by_name['type'].enum_type = _GETREQUEST_DATATYPE -_GETREQUEST.fields_by_name['encoding'].enum_type = _ENCODING -_GETREQUEST.fields_by_name['use_models'].message_type = _MODELDATA -_GETREQUEST.fields_by_name['extension'].message_type = github_dot_com_dot_openconfig_dot_gnmi_dot_proto_dot_gnmi__ext_dot_gnmi__ext__pb2._EXTENSION -_GETREQUEST_DATATYPE.containing_type = _GETREQUEST -_GETRESPONSE.fields_by_name['notification'].message_type = _NOTIFICATION -_GETRESPONSE.fields_by_name['error'].message_type = _ERROR -_GETRESPONSE.fields_by_name['extension'].message_type = github_dot_com_dot_openconfig_dot_gnmi_dot_proto_dot_gnmi__ext_dot_gnmi__ext__pb2._EXTENSION -_CAPABILITYREQUEST.fields_by_name['extension'].message_type = github_dot_com_dot_openconfig_dot_gnmi_dot_proto_dot_gnmi__ext_dot_gnmi__ext__pb2._EXTENSION -_CAPABILITYRESPONSE.fields_by_name['supported_models'].message_type = _MODELDATA -_CAPABILITYRESPONSE.fields_by_name['supported_encodings'].enum_type = _ENCODING -_CAPABILITYRESPONSE.fields_by_name['extension'].message_type = github_dot_com_dot_openconfig_dot_gnmi_dot_proto_dot_gnmi__ext_dot_gnmi__ext__pb2._EXTENSION -DESCRIPTOR.message_types_by_name['Notification'] = _NOTIFICATION -DESCRIPTOR.message_types_by_name['Update'] = _UPDATE -DESCRIPTOR.message_types_by_name['TypedValue'] = _TYPEDVALUE -DESCRIPTOR.message_types_by_name['Path'] = _PATH -DESCRIPTOR.message_types_by_name['PathElem'] = _PATHELEM -DESCRIPTOR.message_types_by_name['Value'] = _VALUE -DESCRIPTOR.message_types_by_name['Error'] = _ERROR -DESCRIPTOR.message_types_by_name['Decimal64'] = _DECIMAL64 -DESCRIPTOR.message_types_by_name['ScalarArray'] = _SCALARARRAY -DESCRIPTOR.message_types_by_name['SubscribeRequest'] = _SUBSCRIBEREQUEST -DESCRIPTOR.message_types_by_name['Poll'] = _POLL -DESCRIPTOR.message_types_by_name['SubscribeResponse'] = _SUBSCRIBERESPONSE -DESCRIPTOR.message_types_by_name['SubscriptionList'] = _SUBSCRIPTIONLIST -DESCRIPTOR.message_types_by_name['Subscription'] = _SUBSCRIPTION -DESCRIPTOR.message_types_by_name['QOSMarking'] = _QOSMARKING -DESCRIPTOR.message_types_by_name['Alias'] = _ALIAS -DESCRIPTOR.message_types_by_name['AliasList'] = _ALIASLIST -DESCRIPTOR.message_types_by_name['SetRequest'] = _SETREQUEST -DESCRIPTOR.message_types_by_name['SetResponse'] = _SETRESPONSE -DESCRIPTOR.message_types_by_name['UpdateResult'] = _UPDATERESULT -DESCRIPTOR.message_types_by_name['GetRequest'] = _GETREQUEST -DESCRIPTOR.message_types_by_name['GetResponse'] = _GETRESPONSE -DESCRIPTOR.message_types_by_name['CapabilityRequest'] = _CAPABILITYREQUEST -DESCRIPTOR.message_types_by_name['CapabilityResponse'] = _CAPABILITYRESPONSE -DESCRIPTOR.message_types_by_name['ModelData'] = _MODELDATA -DESCRIPTOR.enum_types_by_name['Encoding'] = _ENCODING -DESCRIPTOR.enum_types_by_name['SubscriptionMode'] = _SUBSCRIPTIONMODE -DESCRIPTOR.extensions_by_name['gnmi_service'] = gnmi_service -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -Notification = _reflection.GeneratedProtocolMessageType('Notification', (_message.Message,), dict( - DESCRIPTOR = _NOTIFICATION, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.Notification) - )) -_sym_db.RegisterMessage(Notification) - -Update = _reflection.GeneratedProtocolMessageType('Update', (_message.Message,), dict( - DESCRIPTOR = _UPDATE, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.Update) - )) -_sym_db.RegisterMessage(Update) - -TypedValue = _reflection.GeneratedProtocolMessageType('TypedValue', (_message.Message,), dict( - DESCRIPTOR = _TYPEDVALUE, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.TypedValue) - )) -_sym_db.RegisterMessage(TypedValue) - -Path = _reflection.GeneratedProtocolMessageType('Path', (_message.Message,), dict( - DESCRIPTOR = _PATH, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.Path) - )) -_sym_db.RegisterMessage(Path) - -PathElem = _reflection.GeneratedProtocolMessageType('PathElem', (_message.Message,), dict( - - KeyEntry = _reflection.GeneratedProtocolMessageType('KeyEntry', (_message.Message,), dict( - DESCRIPTOR = _PATHELEM_KEYENTRY, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.PathElem.KeyEntry) - )) - , - DESCRIPTOR = _PATHELEM, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.PathElem) - )) -_sym_db.RegisterMessage(PathElem) -_sym_db.RegisterMessage(PathElem.KeyEntry) - -Value = _reflection.GeneratedProtocolMessageType('Value', (_message.Message,), dict( - DESCRIPTOR = _VALUE, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.Value) - )) -_sym_db.RegisterMessage(Value) - -Error = _reflection.GeneratedProtocolMessageType('Error', (_message.Message,), dict( - DESCRIPTOR = _ERROR, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.Error) - )) -_sym_db.RegisterMessage(Error) - -Decimal64 = _reflection.GeneratedProtocolMessageType('Decimal64', (_message.Message,), dict( - DESCRIPTOR = _DECIMAL64, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.Decimal64) - )) -_sym_db.RegisterMessage(Decimal64) - -ScalarArray = _reflection.GeneratedProtocolMessageType('ScalarArray', (_message.Message,), dict( - DESCRIPTOR = _SCALARARRAY, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.ScalarArray) - )) -_sym_db.RegisterMessage(ScalarArray) - -SubscribeRequest = _reflection.GeneratedProtocolMessageType('SubscribeRequest', (_message.Message,), dict( - DESCRIPTOR = _SUBSCRIBEREQUEST, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.SubscribeRequest) - )) -_sym_db.RegisterMessage(SubscribeRequest) - -Poll = _reflection.GeneratedProtocolMessageType('Poll', (_message.Message,), dict( - DESCRIPTOR = _POLL, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.Poll) - )) -_sym_db.RegisterMessage(Poll) - -SubscribeResponse = _reflection.GeneratedProtocolMessageType('SubscribeResponse', (_message.Message,), dict( - DESCRIPTOR = _SUBSCRIBERESPONSE, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.SubscribeResponse) - )) -_sym_db.RegisterMessage(SubscribeResponse) - -SubscriptionList = _reflection.GeneratedProtocolMessageType('SubscriptionList', (_message.Message,), dict( - DESCRIPTOR = _SUBSCRIPTIONLIST, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.SubscriptionList) - )) -_sym_db.RegisterMessage(SubscriptionList) - -Subscription = _reflection.GeneratedProtocolMessageType('Subscription', (_message.Message,), dict( - DESCRIPTOR = _SUBSCRIPTION, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.Subscription) - )) -_sym_db.RegisterMessage(Subscription) - -QOSMarking = _reflection.GeneratedProtocolMessageType('QOSMarking', (_message.Message,), dict( - DESCRIPTOR = _QOSMARKING, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.QOSMarking) - )) -_sym_db.RegisterMessage(QOSMarking) - -Alias = _reflection.GeneratedProtocolMessageType('Alias', (_message.Message,), dict( - DESCRIPTOR = _ALIAS, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.Alias) - )) -_sym_db.RegisterMessage(Alias) - -AliasList = _reflection.GeneratedProtocolMessageType('AliasList', (_message.Message,), dict( - DESCRIPTOR = _ALIASLIST, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.AliasList) - )) -_sym_db.RegisterMessage(AliasList) - -SetRequest = _reflection.GeneratedProtocolMessageType('SetRequest', (_message.Message,), dict( - DESCRIPTOR = _SETREQUEST, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.SetRequest) - )) -_sym_db.RegisterMessage(SetRequest) - -SetResponse = _reflection.GeneratedProtocolMessageType('SetResponse', (_message.Message,), dict( - DESCRIPTOR = _SETRESPONSE, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.SetResponse) - )) -_sym_db.RegisterMessage(SetResponse) - -UpdateResult = _reflection.GeneratedProtocolMessageType('UpdateResult', (_message.Message,), dict( - DESCRIPTOR = _UPDATERESULT, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.UpdateResult) - )) -_sym_db.RegisterMessage(UpdateResult) - -GetRequest = _reflection.GeneratedProtocolMessageType('GetRequest', (_message.Message,), dict( - DESCRIPTOR = _GETREQUEST, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.GetRequest) - )) -_sym_db.RegisterMessage(GetRequest) - -GetResponse = _reflection.GeneratedProtocolMessageType('GetResponse', (_message.Message,), dict( - DESCRIPTOR = _GETRESPONSE, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.GetResponse) - )) -_sym_db.RegisterMessage(GetResponse) - -CapabilityRequest = _reflection.GeneratedProtocolMessageType('CapabilityRequest', (_message.Message,), dict( - DESCRIPTOR = _CAPABILITYREQUEST, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.CapabilityRequest) - )) -_sym_db.RegisterMessage(CapabilityRequest) - -CapabilityResponse = _reflection.GeneratedProtocolMessageType('CapabilityResponse', (_message.Message,), dict( - DESCRIPTOR = _CAPABILITYRESPONSE, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.CapabilityResponse) - )) -_sym_db.RegisterMessage(CapabilityResponse) - -ModelData = _reflection.GeneratedProtocolMessageType('ModelData', (_message.Message,), dict( - DESCRIPTOR = _MODELDATA, - __module__ = 'proto.gnmi.gnmi_pb2' - # @@protoc_insertion_point(class_scope:gnmi.ModelData) - )) -_sym_db.RegisterMessage(ModelData) - -google_dot_protobuf_dot_descriptor__pb2.FileOptions.RegisterExtension(gnmi_service) - -DESCRIPTOR.has_options = True -DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\312>\0050.6.0')) -_UPDATE.fields_by_name['value'].has_options = True -_UPDATE.fields_by_name['value']._options = _descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\030\001')) -_PATH.fields_by_name['element'].has_options = True -_PATH.fields_by_name['element']._options = _descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\030\001')) -_PATHELEM_KEYENTRY.has_options = True -_PATHELEM_KEYENTRY._options = _descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')) -_VALUE.has_options = True -_VALUE._options = _descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('\030\001')) -_ERROR.has_options = True -_ERROR._options = _descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('\030\001')) -_SUBSCRIBERESPONSE.fields_by_name['error'].has_options = True -_SUBSCRIBERESPONSE.fields_by_name['error']._options = _descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\030\001')) -_SETRESPONSE.fields_by_name['message'].has_options = True -_SETRESPONSE.fields_by_name['message']._options = _descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\030\001')) -_UPDATERESULT.fields_by_name['timestamp'].has_options = True -_UPDATERESULT.fields_by_name['timestamp']._options = _descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\030\001')) -_UPDATERESULT.fields_by_name['message'].has_options = True -_UPDATERESULT.fields_by_name['message']._options = _descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\030\001')) -_GETRESPONSE.fields_by_name['error'].has_options = True -_GETRESPONSE.fields_by_name['error']._options = _descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\030\001')) - -_GNMI = _descriptor.ServiceDescriptor( - name='gNMI', - full_name='gnmi.gNMI', - file=DESCRIPTOR, - index=0, - options=None, - serialized_start=3569, - serialized_end=3796, - methods=[ - _descriptor.MethodDescriptor( - name='Capabilities', - full_name='gnmi.gNMI.Capabilities', - index=0, - containing_service=None, - input_type=_CAPABILITYREQUEST, - output_type=_CAPABILITYRESPONSE, - options=None, - ), - _descriptor.MethodDescriptor( - name='Get', - full_name='gnmi.gNMI.Get', - index=1, - containing_service=None, - input_type=_GETREQUEST, - output_type=_GETRESPONSE, - options=None, - ), - _descriptor.MethodDescriptor( - name='Set', - full_name='gnmi.gNMI.Set', - index=2, - containing_service=None, - input_type=_SETREQUEST, - output_type=_SETRESPONSE, - options=None, - ), - _descriptor.MethodDescriptor( - name='Subscribe', - full_name='gnmi.gNMI.Subscribe', - index=3, - containing_service=None, - input_type=_SUBSCRIBEREQUEST, - output_type=_SUBSCRIBERESPONSE, - options=None, - ), -]) -_sym_db.RegisterServiceDescriptor(_GNMI) - -DESCRIPTOR.services_by_name['gNMI'] = _GNMI - -# @@protoc_insertion_point(module_scope) diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi/gnmi_pb2_grpc.py b/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi/gnmi_pb2_grpc.py deleted file mode 100644 index 7bf943363..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi/gnmi_pb2_grpc.py +++ /dev/null @@ -1,113 +0,0 @@ -# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! -import grpc - -from proto.gnmi import gnmi_pb2 as proto_dot_gnmi_dot_gnmi__pb2 - - -class gNMIStub(object): - # missing associated documentation comment in .proto file - pass - - def __init__(self, channel): - """Constructor. - - Args: - channel: A grpc.Channel. - """ - self.Capabilities = channel.unary_unary( - '/gnmi.gNMI/Capabilities', - request_serializer=proto_dot_gnmi_dot_gnmi__pb2.CapabilityRequest.SerializeToString, - response_deserializer=proto_dot_gnmi_dot_gnmi__pb2.CapabilityResponse.FromString, - ) - self.Get = channel.unary_unary( - '/gnmi.gNMI/Get', - request_serializer=proto_dot_gnmi_dot_gnmi__pb2.GetRequest.SerializeToString, - response_deserializer=proto_dot_gnmi_dot_gnmi__pb2.GetResponse.FromString, - ) - self.Set = channel.unary_unary( - '/gnmi.gNMI/Set', - request_serializer=proto_dot_gnmi_dot_gnmi__pb2.SetRequest.SerializeToString, - response_deserializer=proto_dot_gnmi_dot_gnmi__pb2.SetResponse.FromString, - ) - self.Subscribe = channel.stream_stream( - '/gnmi.gNMI/Subscribe', - request_serializer=proto_dot_gnmi_dot_gnmi__pb2.SubscribeRequest.SerializeToString, - response_deserializer=proto_dot_gnmi_dot_gnmi__pb2.SubscribeResponse.FromString, - ) - - -class gNMIServicer(object): - # missing associated documentation comment in .proto file - pass - - def Capabilities(self, request, context): - """Capabilities allows the client to retrieve the set of capabilities that - is supported by the target. This allows the target to validate the - service version that is implemented and retrieve the set of models that - the target supports. The models can then be specified in subsequent RPCs - to restrict the set of data that is utilized. - Reference: gNMI Specification Section 3.2 - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def Get(self, request, context): - """Retrieve a snapshot of data from the target. A Get RPC requests that the - target snapshots a subset of the data tree as specified by the paths - included in the message and serializes this to be returned to the - client using the specified encoding. - Reference: gNMI Specification Section 3.3 - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def Set(self, request, context): - """Set allows the client to modify the state of data on the target. The - paths to modified along with the new values that the client wishes - to set the value to. - Reference: gNMI Specification Section 3.4 - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def Subscribe(self, request_iterator, context): - """Subscribe allows a client to request the target to send it values - of particular paths within the data tree. These values may be streamed - at a particular cadence (STREAM), sent one off on a long-lived channel - (POLL), or sent as a one-off retrieval (ONCE). - Reference: gNMI Specification Section 3.5 - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - -def add_gNMIServicer_to_server(servicer, server): - rpc_method_handlers = { - 'Capabilities': grpc.unary_unary_rpc_method_handler( - servicer.Capabilities, - request_deserializer=proto_dot_gnmi_dot_gnmi__pb2.CapabilityRequest.FromString, - response_serializer=proto_dot_gnmi_dot_gnmi__pb2.CapabilityResponse.SerializeToString, - ), - 'Get': grpc.unary_unary_rpc_method_handler( - servicer.Get, - request_deserializer=proto_dot_gnmi_dot_gnmi__pb2.GetRequest.FromString, - response_serializer=proto_dot_gnmi_dot_gnmi__pb2.GetResponse.SerializeToString, - ), - 'Set': grpc.unary_unary_rpc_method_handler( - servicer.Set, - request_deserializer=proto_dot_gnmi_dot_gnmi__pb2.SetRequest.FromString, - response_serializer=proto_dot_gnmi_dot_gnmi__pb2.SetResponse.SerializeToString, - ), - 'Subscribe': grpc.stream_stream_rpc_method_handler( - servicer.Subscribe, - request_deserializer=proto_dot_gnmi_dot_gnmi__pb2.SubscribeRequest.FromString, - response_serializer=proto_dot_gnmi_dot_gnmi__pb2.SubscribeResponse.SerializeToString, - ), - } - generic_handler = grpc.method_handlers_generic_handler( - 'gnmi.gNMI', rpc_method_handlers) - server.add_generic_rpc_handlers((generic_handler,)) diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.pb.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.pb.go deleted file mode 100644 index db8533465..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.pb.go +++ /dev/null @@ -1,361 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: proto/gnmi_ext/gnmi_ext.proto - -// Package gnmi_ext defines a set of extensions messages which can be optionally -// included with the request and response messages of gNMI RPCs. A set of -// well-known extensions are defined within this file, along with a registry for -// extensions defined outside of this package. - -package gnmi_ext - -import ( - fmt "fmt" - proto "github.com/golang/protobuf/proto" - math "math" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -// RegisteredExtension is an enumeration acting as a registry for extensions -// defined by external sources. -type ExtensionID int32 - -const ( - ExtensionID_EID_UNSET ExtensionID = 0 - // An experimental extension that may be used during prototyping of a new - // extension. - ExtensionID_EID_EXPERIMENTAL ExtensionID = 999 -) - -var ExtensionID_name = map[int32]string{ - 0: "EID_UNSET", - 999: "EID_EXPERIMENTAL", -} - -var ExtensionID_value = map[string]int32{ - "EID_UNSET": 0, - "EID_EXPERIMENTAL": 999, -} - -func (x ExtensionID) String() string { - return proto.EnumName(ExtensionID_name, int32(x)) -} - -func (ExtensionID) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_716f7a09950f71e3, []int{0} -} - -// The Extension message contains a single gNMI extension. -type Extension struct { - // Types that are valid to be assigned to Ext: - // *Extension_RegisteredExt - // *Extension_MasterArbitration - Ext isExtension_Ext `protobuf_oneof:"ext"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Extension) Reset() { *m = Extension{} } -func (m *Extension) String() string { return proto.CompactTextString(m) } -func (*Extension) ProtoMessage() {} -func (*Extension) Descriptor() ([]byte, []int) { - return fileDescriptor_716f7a09950f71e3, []int{0} -} - -func (m *Extension) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Extension.Unmarshal(m, b) -} -func (m *Extension) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Extension.Marshal(b, m, deterministic) -} -func (m *Extension) XXX_Merge(src proto.Message) { - xxx_messageInfo_Extension.Merge(m, src) -} -func (m *Extension) XXX_Size() int { - return xxx_messageInfo_Extension.Size(m) -} -func (m *Extension) XXX_DiscardUnknown() { - xxx_messageInfo_Extension.DiscardUnknown(m) -} - -var xxx_messageInfo_Extension proto.InternalMessageInfo - -type isExtension_Ext interface { - isExtension_Ext() -} - -type Extension_RegisteredExt struct { - RegisteredExt *RegisteredExtension `protobuf:"bytes,1,opt,name=registered_ext,json=registeredExt,proto3,oneof"` -} - -type Extension_MasterArbitration struct { - MasterArbitration *MasterArbitration `protobuf:"bytes,2,opt,name=master_arbitration,json=masterArbitration,proto3,oneof"` -} - -func (*Extension_RegisteredExt) isExtension_Ext() {} - -func (*Extension_MasterArbitration) isExtension_Ext() {} - -func (m *Extension) GetExt() isExtension_Ext { - if m != nil { - return m.Ext - } - return nil -} - -func (m *Extension) GetRegisteredExt() *RegisteredExtension { - if x, ok := m.GetExt().(*Extension_RegisteredExt); ok { - return x.RegisteredExt - } - return nil -} - -func (m *Extension) GetMasterArbitration() *MasterArbitration { - if x, ok := m.GetExt().(*Extension_MasterArbitration); ok { - return x.MasterArbitration - } - return nil -} - -// XXX_OneofWrappers is for the internal use of the proto package. -func (*Extension) XXX_OneofWrappers() []interface{} { - return []interface{}{ - (*Extension_RegisteredExt)(nil), - (*Extension_MasterArbitration)(nil), - } -} - -// The RegisteredExtension message defines an extension which is defined outside -// of this file. -type RegisteredExtension struct { - Id ExtensionID `protobuf:"varint,1,opt,name=id,proto3,enum=gnmi_ext.ExtensionID" json:"id,omitempty"` - Msg []byte `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *RegisteredExtension) Reset() { *m = RegisteredExtension{} } -func (m *RegisteredExtension) String() string { return proto.CompactTextString(m) } -func (*RegisteredExtension) ProtoMessage() {} -func (*RegisteredExtension) Descriptor() ([]byte, []int) { - return fileDescriptor_716f7a09950f71e3, []int{1} -} - -func (m *RegisteredExtension) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_RegisteredExtension.Unmarshal(m, b) -} -func (m *RegisteredExtension) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_RegisteredExtension.Marshal(b, m, deterministic) -} -func (m *RegisteredExtension) XXX_Merge(src proto.Message) { - xxx_messageInfo_RegisteredExtension.Merge(m, src) -} -func (m *RegisteredExtension) XXX_Size() int { - return xxx_messageInfo_RegisteredExtension.Size(m) -} -func (m *RegisteredExtension) XXX_DiscardUnknown() { - xxx_messageInfo_RegisteredExtension.DiscardUnknown(m) -} - -var xxx_messageInfo_RegisteredExtension proto.InternalMessageInfo - -func (m *RegisteredExtension) GetId() ExtensionID { - if m != nil { - return m.Id - } - return ExtensionID_EID_UNSET -} - -func (m *RegisteredExtension) GetMsg() []byte { - if m != nil { - return m.Msg - } - return nil -} - -// MasterArbitration is used to select the master among multiple gNMI clients -// with the same Roles. The client with the largest election_id is honored as -// the master. -// The document about gNMI master arbitration can be found at -// https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-master-arbitration.md -type MasterArbitration struct { - Role *Role `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` - ElectionId *Uint128 `protobuf:"bytes,2,opt,name=election_id,json=electionId,proto3" json:"election_id,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *MasterArbitration) Reset() { *m = MasterArbitration{} } -func (m *MasterArbitration) String() string { return proto.CompactTextString(m) } -func (*MasterArbitration) ProtoMessage() {} -func (*MasterArbitration) Descriptor() ([]byte, []int) { - return fileDescriptor_716f7a09950f71e3, []int{2} -} - -func (m *MasterArbitration) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_MasterArbitration.Unmarshal(m, b) -} -func (m *MasterArbitration) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_MasterArbitration.Marshal(b, m, deterministic) -} -func (m *MasterArbitration) XXX_Merge(src proto.Message) { - xxx_messageInfo_MasterArbitration.Merge(m, src) -} -func (m *MasterArbitration) XXX_Size() int { - return xxx_messageInfo_MasterArbitration.Size(m) -} -func (m *MasterArbitration) XXX_DiscardUnknown() { - xxx_messageInfo_MasterArbitration.DiscardUnknown(m) -} - -var xxx_messageInfo_MasterArbitration proto.InternalMessageInfo - -func (m *MasterArbitration) GetRole() *Role { - if m != nil { - return m.Role - } - return nil -} - -func (m *MasterArbitration) GetElectionId() *Uint128 { - if m != nil { - return m.ElectionId - } - return nil -} - -// Representation of unsigned 128-bit integer. -type Uint128 struct { - High uint64 `protobuf:"varint,1,opt,name=high,proto3" json:"high,omitempty"` - Low uint64 `protobuf:"varint,2,opt,name=low,proto3" json:"low,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Uint128) Reset() { *m = Uint128{} } -func (m *Uint128) String() string { return proto.CompactTextString(m) } -func (*Uint128) ProtoMessage() {} -func (*Uint128) Descriptor() ([]byte, []int) { - return fileDescriptor_716f7a09950f71e3, []int{3} -} - -func (m *Uint128) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Uint128.Unmarshal(m, b) -} -func (m *Uint128) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Uint128.Marshal(b, m, deterministic) -} -func (m *Uint128) XXX_Merge(src proto.Message) { - xxx_messageInfo_Uint128.Merge(m, src) -} -func (m *Uint128) XXX_Size() int { - return xxx_messageInfo_Uint128.Size(m) -} -func (m *Uint128) XXX_DiscardUnknown() { - xxx_messageInfo_Uint128.DiscardUnknown(m) -} - -var xxx_messageInfo_Uint128 proto.InternalMessageInfo - -func (m *Uint128) GetHigh() uint64 { - if m != nil { - return m.High - } - return 0 -} - -func (m *Uint128) GetLow() uint64 { - if m != nil { - return m.Low - } - return 0 -} - -// There can be one master for each role. The role is identified by its id. -type Role struct { - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Role) Reset() { *m = Role{} } -func (m *Role) String() string { return proto.CompactTextString(m) } -func (*Role) ProtoMessage() {} -func (*Role) Descriptor() ([]byte, []int) { - return fileDescriptor_716f7a09950f71e3, []int{4} -} - -func (m *Role) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Role.Unmarshal(m, b) -} -func (m *Role) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Role.Marshal(b, m, deterministic) -} -func (m *Role) XXX_Merge(src proto.Message) { - xxx_messageInfo_Role.Merge(m, src) -} -func (m *Role) XXX_Size() int { - return xxx_messageInfo_Role.Size(m) -} -func (m *Role) XXX_DiscardUnknown() { - xxx_messageInfo_Role.DiscardUnknown(m) -} - -var xxx_messageInfo_Role proto.InternalMessageInfo - -func (m *Role) GetId() string { - if m != nil { - return m.Id - } - return "" -} - -func init() { - proto.RegisterEnum("gnmi_ext.ExtensionID", ExtensionID_name, ExtensionID_value) - proto.RegisterType((*Extension)(nil), "gnmi_ext.Extension") - proto.RegisterType((*RegisteredExtension)(nil), "gnmi_ext.RegisteredExtension") - proto.RegisterType((*MasterArbitration)(nil), "gnmi_ext.MasterArbitration") - proto.RegisterType((*Uint128)(nil), "gnmi_ext.Uint128") - proto.RegisterType((*Role)(nil), "gnmi_ext.Role") -} - -func init() { proto.RegisterFile("proto/gnmi_ext/gnmi_ext.proto", fileDescriptor_716f7a09950f71e3) } - -var fileDescriptor_716f7a09950f71e3 = []byte{ - // 323 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x51, 0x5d, 0x4b, 0x02, 0x41, - 0x14, 0xf5, 0x63, 0xcb, 0xbc, 0xe6, 0xb2, 0xde, 0x30, 0x84, 0x10, 0x62, 0x21, 0x88, 0x1e, 0x94, - 0xd6, 0x97, 0x5e, 0x0d, 0x27, 0x5c, 0x50, 0x89, 0x49, 0xa1, 0xb7, 0x45, 0xdb, 0x61, 0x1d, 0xda, - 0xdd, 0x89, 0x71, 0x20, 0x7f, 0x52, 0xff, 0xac, 0xbf, 0x11, 0x33, 0xe8, 0xec, 0x52, 0xbd, 0x9d, - 0x7b, 0xee, 0x99, 0x73, 0xcf, 0x61, 0xa0, 0xff, 0x21, 0x85, 0x12, 0xc3, 0x24, 0xcf, 0x78, 0xc4, - 0xf6, 0xca, 0x82, 0x81, 0xe1, 0xf1, 0xec, 0x38, 0xfb, 0x5f, 0x55, 0x68, 0x92, 0xbd, 0x62, 0xf9, - 0x8e, 0x8b, 0x1c, 0x9f, 0xc0, 0x95, 0x2c, 0xe1, 0x3b, 0xc5, 0x24, 0x8b, 0xf5, 0xbe, 0x57, 0xbd, - 0xae, 0xde, 0xb6, 0x82, 0xfe, 0xc0, 0x1a, 0x50, 0xbb, 0xb7, 0xcf, 0xa6, 0x15, 0xda, 0x96, 0x65, - 0x1a, 0x67, 0x80, 0xd9, 0x5a, 0x8f, 0xd1, 0x5a, 0x6e, 0xb8, 0x92, 0x6b, 0xc5, 0x45, 0xde, 0xab, - 0x19, 0xaf, 0xab, 0xc2, 0x6b, 0x6e, 0x34, 0xe3, 0x42, 0x32, 0xad, 0xd0, 0x4e, 0xf6, 0x9b, 0x7c, - 0x3c, 0x81, 0xba, 0x8e, 0xba, 0x80, 0x8b, 0x7f, 0x8e, 0xe3, 0x0d, 0xd4, 0x78, 0x6c, 0x72, 0xba, - 0x41, 0xb7, 0xf0, 0xb6, 0x82, 0x70, 0x42, 0x6b, 0x3c, 0x46, 0x0f, 0xea, 0xd9, 0x2e, 0x31, 0x19, - 0xce, 0xa9, 0x86, 0xfe, 0x3b, 0x74, 0xfe, 0x04, 0x40, 0x1f, 0x1c, 0x29, 0x52, 0x76, 0xe8, 0xed, - 0x96, 0x7a, 0x8b, 0x94, 0x51, 0xb3, 0xc3, 0x00, 0x5a, 0x2c, 0x65, 0x6f, 0x5a, 0x1f, 0xf1, 0xf8, - 0x50, 0xab, 0x53, 0x48, 0x57, 0x3c, 0x57, 0xf7, 0xc1, 0x03, 0x85, 0xa3, 0x2a, 0x8c, 0xfd, 0x21, - 0x34, 0x0e, 0x34, 0x22, 0x38, 0x5b, 0x9e, 0x6c, 0xcd, 0x09, 0x87, 0x1a, 0xac, 0xd3, 0xa5, 0xe2, - 0xd3, 0x58, 0x39, 0x54, 0x43, 0xff, 0x12, 0x1c, 0x7d, 0x12, 0x5d, 0x5b, 0xaf, 0xa9, 0x7b, 0xdc, - 0x8d, 0xa0, 0x55, 0xaa, 0x86, 0x6d, 0x68, 0x92, 0x70, 0x12, 0xad, 0x16, 0x2f, 0x64, 0xe9, 0x55, - 0xb0, 0x0b, 0x9e, 0x1e, 0xc9, 0xeb, 0x33, 0xa1, 0xe1, 0x9c, 0x2c, 0x96, 0xe3, 0x99, 0xf7, 0xdd, - 0xd8, 0x9c, 0x9a, 0x6f, 0x1f, 0xfd, 0x04, 0x00, 0x00, 0xff, 0xff, 0x56, 0xb1, 0xb7, 0xbc, 0x17, - 0x02, 0x00, 0x00, -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.proto b/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.proto deleted file mode 100644 index c06ba2bc2..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.proto +++ /dev/null @@ -1,73 +0,0 @@ -// -// Copyright 2018 Google Inc. All Rights Reserved. -// -// 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. -// -syntax = "proto3"; - -// Package gnmi_ext defines a set of extensions messages which can be optionally -// included with the request and response messages of gNMI RPCs. A set of -// well-known extensions are defined within this file, along with a registry for -// extensions defined outside of this package. -package gnmi_ext; - -// The Extension message contains a single gNMI extension. -message Extension { - oneof ext { - RegisteredExtension registered_ext = 1; // A registered extension. - // Well known extensions. - MasterArbitration master_arbitration = 2; // Master arbitration extension. - } -} - -// The RegisteredExtension message defines an extension which is defined outside -// of this file. -message RegisteredExtension { - ExtensionID id = 1; // The unique ID assigned to this extension. - bytes msg = 2; // The binary-marshalled protobuf extension payload. -} - -// RegisteredExtension is an enumeration acting as a registry for extensions -// defined by external sources. -enum ExtensionID { - EID_UNSET = 0; - // New extensions are to be defined within this enumeration - their definition - // MUST link to a reference describing their implementation. - - // An experimental extension that may be used during prototyping of a new - // extension. - EID_EXPERIMENTAL = 999; -} - -// MasterArbitration is used to select the master among multiple gNMI clients -// with the same Roles. The client with the largest election_id is honored as -// the master. -// The document about gNMI master arbitration can be found at -// https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-master-arbitration.md -message MasterArbitration { - Role role = 1; - Uint128 election_id = 2; -} - -// Representation of unsigned 128-bit integer. -message Uint128 { - uint64 high = 1; - uint64 low = 2; -} - -// There can be one master for each role. The role is identified by its id. -message Role { - string id = 1; - // More fields can be added if needed, for example, to specify what paths the - // role can read/write. -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext_pb2.py b/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext_pb2.py deleted file mode 100644 index 68b07d5ed..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext_pb2.py +++ /dev/null @@ -1,295 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: proto/gnmi_ext/gnmi_ext.proto - -import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) -from google.protobuf.internal import enum_type_wrapper -from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection -from google.protobuf import symbol_database as _symbol_database -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - - - -DESCRIPTOR = _descriptor.FileDescriptor( - name='proto/gnmi_ext/gnmi_ext.proto', - package='gnmi_ext', - syntax='proto3', - serialized_options=None, - serialized_pb=_b('\n\x1dproto/gnmi_ext/gnmi_ext.proto\x12\x08gnmi_ext\"\x86\x01\n\tExtension\x12\x37\n\x0eregistered_ext\x18\x01 \x01(\x0b\x32\x1d.gnmi_ext.RegisteredExtensionH\x00\x12\x39\n\x12master_arbitration\x18\x02 \x01(\x0b\x32\x1b.gnmi_ext.MasterArbitrationH\x00\x42\x05\n\x03\x65xt\"E\n\x13RegisteredExtension\x12!\n\x02id\x18\x01 \x01(\x0e\x32\x15.gnmi_ext.ExtensionID\x12\x0b\n\x03msg\x18\x02 \x01(\x0c\"Y\n\x11MasterArbitration\x12\x1c\n\x04role\x18\x01 \x01(\x0b\x32\x0e.gnmi_ext.Role\x12&\n\x0b\x65lection_id\x18\x02 \x01(\x0b\x32\x11.gnmi_ext.Uint128\"$\n\x07Uint128\x12\x0c\n\x04high\x18\x01 \x01(\x04\x12\x0b\n\x03low\x18\x02 \x01(\x04\"\x12\n\x04Role\x12\n\n\x02id\x18\x01 \x01(\t*3\n\x0b\x45xtensionID\x12\r\n\tEID_UNSET\x10\x00\x12\x15\n\x10\x45ID_EXPERIMENTAL\x10\xe7\x07\x62\x06proto3') -) - -_EXTENSIONID = _descriptor.EnumDescriptor( - name='ExtensionID', - full_name='gnmi_ext.ExtensionID', - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name='EID_UNSET', index=0, number=0, - serialized_options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='EID_EXPERIMENTAL', index=1, number=999, - serialized_options=None, - type=None), - ], - containing_type=None, - serialized_options=None, - serialized_start=400, - serialized_end=451, -) -_sym_db.RegisterEnumDescriptor(_EXTENSIONID) - -ExtensionID = enum_type_wrapper.EnumTypeWrapper(_EXTENSIONID) -EID_UNSET = 0 -EID_EXPERIMENTAL = 999 - - - -_EXTENSION = _descriptor.Descriptor( - name='Extension', - full_name='gnmi_ext.Extension', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='registered_ext', full_name='gnmi_ext.Extension.registered_ext', index=0, - number=1, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='master_arbitration', full_name='gnmi_ext.Extension.master_arbitration', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - _descriptor.OneofDescriptor( - name='ext', full_name='gnmi_ext.Extension.ext', - index=0, containing_type=None, fields=[]), - ], - serialized_start=44, - serialized_end=178, -) - - -_REGISTEREDEXTENSION = _descriptor.Descriptor( - name='RegisteredExtension', - full_name='gnmi_ext.RegisteredExtension', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='id', full_name='gnmi_ext.RegisteredExtension.id', index=0, - number=1, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='msg', full_name='gnmi_ext.RegisteredExtension.msg', index=1, - number=2, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=180, - serialized_end=249, -) - - -_MASTERARBITRATION = _descriptor.Descriptor( - name='MasterArbitration', - full_name='gnmi_ext.MasterArbitration', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='role', full_name='gnmi_ext.MasterArbitration.role', index=0, - number=1, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='election_id', full_name='gnmi_ext.MasterArbitration.election_id', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=251, - serialized_end=340, -) - - -_UINT128 = _descriptor.Descriptor( - name='Uint128', - full_name='gnmi_ext.Uint128', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='high', full_name='gnmi_ext.Uint128.high', index=0, - number=1, type=4, cpp_type=4, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='low', full_name='gnmi_ext.Uint128.low', index=1, - number=2, type=4, cpp_type=4, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=342, - serialized_end=378, -) - - -_ROLE = _descriptor.Descriptor( - name='Role', - full_name='gnmi_ext.Role', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='id', full_name='gnmi_ext.Role.id', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=380, - serialized_end=398, -) - -_EXTENSION.fields_by_name['registered_ext'].message_type = _REGISTEREDEXTENSION -_EXTENSION.fields_by_name['master_arbitration'].message_type = _MASTERARBITRATION -_EXTENSION.oneofs_by_name['ext'].fields.append( - _EXTENSION.fields_by_name['registered_ext']) -_EXTENSION.fields_by_name['registered_ext'].containing_oneof = _EXTENSION.oneofs_by_name['ext'] -_EXTENSION.oneofs_by_name['ext'].fields.append( - _EXTENSION.fields_by_name['master_arbitration']) -_EXTENSION.fields_by_name['master_arbitration'].containing_oneof = _EXTENSION.oneofs_by_name['ext'] -_REGISTEREDEXTENSION.fields_by_name['id'].enum_type = _EXTENSIONID -_MASTERARBITRATION.fields_by_name['role'].message_type = _ROLE -_MASTERARBITRATION.fields_by_name['election_id'].message_type = _UINT128 -DESCRIPTOR.message_types_by_name['Extension'] = _EXTENSION -DESCRIPTOR.message_types_by_name['RegisteredExtension'] = _REGISTEREDEXTENSION -DESCRIPTOR.message_types_by_name['MasterArbitration'] = _MASTERARBITRATION -DESCRIPTOR.message_types_by_name['Uint128'] = _UINT128 -DESCRIPTOR.message_types_by_name['Role'] = _ROLE -DESCRIPTOR.enum_types_by_name['ExtensionID'] = _EXTENSIONID -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -Extension = _reflection.GeneratedProtocolMessageType('Extension', (_message.Message,), dict( - DESCRIPTOR = _EXTENSION, - __module__ = 'proto.gnmi_ext.gnmi_ext_pb2' - # @@protoc_insertion_point(class_scope:gnmi_ext.Extension) - )) -_sym_db.RegisterMessage(Extension) - -RegisteredExtension = _reflection.GeneratedProtocolMessageType('RegisteredExtension', (_message.Message,), dict( - DESCRIPTOR = _REGISTEREDEXTENSION, - __module__ = 'proto.gnmi_ext.gnmi_ext_pb2' - # @@protoc_insertion_point(class_scope:gnmi_ext.RegisteredExtension) - )) -_sym_db.RegisterMessage(RegisteredExtension) - -MasterArbitration = _reflection.GeneratedProtocolMessageType('MasterArbitration', (_message.Message,), dict( - DESCRIPTOR = _MASTERARBITRATION, - __module__ = 'proto.gnmi_ext.gnmi_ext_pb2' - # @@protoc_insertion_point(class_scope:gnmi_ext.MasterArbitration) - )) -_sym_db.RegisterMessage(MasterArbitration) - -Uint128 = _reflection.GeneratedProtocolMessageType('Uint128', (_message.Message,), dict( - DESCRIPTOR = _UINT128, - __module__ = 'proto.gnmi_ext.gnmi_ext_pb2' - # @@protoc_insertion_point(class_scope:gnmi_ext.Uint128) - )) -_sym_db.RegisterMessage(Uint128) - -Role = _reflection.GeneratedProtocolMessageType('Role', (_message.Message,), dict( - DESCRIPTOR = _ROLE, - __module__ = 'proto.gnmi_ext.gnmi_ext_pb2' - # @@protoc_insertion_point(class_scope:gnmi_ext.Role) - )) -_sym_db.RegisterMessage(Role) - - -# @@protoc_insertion_point(module_scope) diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext_pb2_grpc.py b/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext_pb2_grpc.py deleted file mode 100644 index a89435267..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext_pb2_grpc.py +++ /dev/null @@ -1,3 +0,0 @@ -# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! -import grpc - diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/target/target.pb.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/target/target.pb.go deleted file mode 100644 index f04de5f89..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/target/target.pb.go +++ /dev/null @@ -1,274 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: proto/target/target.proto - -// Package target contains messages for defining a configuration of a caching -// collector to connect to multiple gNMI targets. - -package target - -import ( - fmt "fmt" - proto "github.com/golang/protobuf/proto" - gnmi "github.com/openconfig/gnmi/proto/gnmi" - math "math" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -// Configuration holds all information necessary for a caching gNMI collector -// to establish subscriptions to a list of gNMI targets. -type Configuration struct { - // Request is a keyed list of all SubscriptionRequests that can be sent to - // to targets in the Configuration. - // The request must have at minimum a SubscriptionList with a prefix - // containing origin and one or more Subscriptions. Only the STREAM mode is - // supported. - Request map[string]*gnmi.SubscribeRequest `protobuf:"bytes,1,rep,name=request,proto3" json:"request,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - // Target is the full list of targets connected to by a caching gNMI - // collector. The key of the map is a unique name to identify a target and - // is set in the prefix.target of a SubscriptionRequest message when connecting - // to each respective target. - Target map[string]*Target `protobuf:"bytes,2,rep,name=target,proto3" json:"target,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - // Identifier for the caching collector. - InstanceId string `protobuf:"bytes,3,opt,name=instance_id,json=instanceId,proto3" json:"instance_id,omitempty"` - // Revision for this Configuration. Systems that non-atomically write - // configuration should populate and require revision, leveraging canonical - // protobuf serialization of fields in order. Presence of this field makes no - // guarantee. Consumers should account for atomicity constraints of their - // environment and any custom encoding. - Revision int64 `protobuf:"varint,536870911,opt,name=revision,proto3" json:"revision,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Configuration) Reset() { *m = Configuration{} } -func (m *Configuration) String() string { return proto.CompactTextString(m) } -func (*Configuration) ProtoMessage() {} -func (*Configuration) Descriptor() ([]byte, []int) { - return fileDescriptor_b39e290eb88e6184, []int{0} -} - -func (m *Configuration) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Configuration.Unmarshal(m, b) -} -func (m *Configuration) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Configuration.Marshal(b, m, deterministic) -} -func (m *Configuration) XXX_Merge(src proto.Message) { - xxx_messageInfo_Configuration.Merge(m, src) -} -func (m *Configuration) XXX_Size() int { - return xxx_messageInfo_Configuration.Size(m) -} -func (m *Configuration) XXX_DiscardUnknown() { - xxx_messageInfo_Configuration.DiscardUnknown(m) -} - -var xxx_messageInfo_Configuration proto.InternalMessageInfo - -func (m *Configuration) GetRequest() map[string]*gnmi.SubscribeRequest { - if m != nil { - return m.Request - } - return nil -} - -func (m *Configuration) GetTarget() map[string]*Target { - if m != nil { - return m.Target - } - return nil -} - -func (m *Configuration) GetInstanceId() string { - if m != nil { - return m.InstanceId - } - return "" -} - -func (m *Configuration) GetRevision() int64 { - if m != nil { - return m.Revision - } - return 0 -} - -// Target is the information necessary to establish a single gNMI Subscribe RPC -// to be collected and cached. -type Target struct { - // A list of address and port or name that resolves to an address and port. - Addresses []string `protobuf:"bytes,1,rep,name=addresses,proto3" json:"addresses,omitempty"` - // Credentials to use in metadata for authorization of the RPC - Credentials *Credentials `protobuf:"bytes,2,opt,name=credentials,proto3" json:"credentials,omitempty"` - // The request to be sent to the target. The string supplied is looked up in - // the request map of the Configuration message. - Request string `protobuf:"bytes,3,opt,name=request,proto3" json:"request,omitempty"` - // Additional target metadata. - Meta map[string]string `protobuf:"bytes,4,rep,name=meta,proto3" json:"meta,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Target) Reset() { *m = Target{} } -func (m *Target) String() string { return proto.CompactTextString(m) } -func (*Target) ProtoMessage() {} -func (*Target) Descriptor() ([]byte, []int) { - return fileDescriptor_b39e290eb88e6184, []int{1} -} - -func (m *Target) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Target.Unmarshal(m, b) -} -func (m *Target) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Target.Marshal(b, m, deterministic) -} -func (m *Target) XXX_Merge(src proto.Message) { - xxx_messageInfo_Target.Merge(m, src) -} -func (m *Target) XXX_Size() int { - return xxx_messageInfo_Target.Size(m) -} -func (m *Target) XXX_DiscardUnknown() { - xxx_messageInfo_Target.DiscardUnknown(m) -} - -var xxx_messageInfo_Target proto.InternalMessageInfo - -func (m *Target) GetAddresses() []string { - if m != nil { - return m.Addresses - } - return nil -} - -func (m *Target) GetCredentials() *Credentials { - if m != nil { - return m.Credentials - } - return nil -} - -func (m *Target) GetRequest() string { - if m != nil { - return m.Request - } - return "" -} - -func (m *Target) GetMeta() map[string]string { - if m != nil { - return m.Meta - } - return nil -} - -// Credentials contains the fields necessary for authentication of the client to -// the target. -type Credentials struct { - Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` - Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` - // Password lookup ID. - PasswordId string `protobuf:"bytes,3,opt,name=password_id,json=passwordId,proto3" json:"password_id,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Credentials) Reset() { *m = Credentials{} } -func (m *Credentials) String() string { return proto.CompactTextString(m) } -func (*Credentials) ProtoMessage() {} -func (*Credentials) Descriptor() ([]byte, []int) { - return fileDescriptor_b39e290eb88e6184, []int{2} -} - -func (m *Credentials) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Credentials.Unmarshal(m, b) -} -func (m *Credentials) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Credentials.Marshal(b, m, deterministic) -} -func (m *Credentials) XXX_Merge(src proto.Message) { - xxx_messageInfo_Credentials.Merge(m, src) -} -func (m *Credentials) XXX_Size() int { - return xxx_messageInfo_Credentials.Size(m) -} -func (m *Credentials) XXX_DiscardUnknown() { - xxx_messageInfo_Credentials.DiscardUnknown(m) -} - -var xxx_messageInfo_Credentials proto.InternalMessageInfo - -func (m *Credentials) GetUsername() string { - if m != nil { - return m.Username - } - return "" -} - -func (m *Credentials) GetPassword() string { - if m != nil { - return m.Password - } - return "" -} - -func (m *Credentials) GetPasswordId() string { - if m != nil { - return m.PasswordId - } - return "" -} - -func init() { - proto.RegisterType((*Configuration)(nil), "target.Configuration") - proto.RegisterMapType((map[string]*gnmi.SubscribeRequest)(nil), "target.Configuration.RequestEntry") - proto.RegisterMapType((map[string]*Target)(nil), "target.Configuration.TargetEntry") - proto.RegisterType((*Target)(nil), "target.Target") - proto.RegisterMapType((map[string]string)(nil), "target.Target.MetaEntry") - proto.RegisterType((*Credentials)(nil), "target.Credentials") -} - -func init() { proto.RegisterFile("proto/target/target.proto", fileDescriptor_b39e290eb88e6184) } - -var fileDescriptor_b39e290eb88e6184 = []byte{ - // 403 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x52, 0x4d, 0x8f, 0xd3, 0x30, - 0x10, 0x95, 0xdb, 0xa5, 0x6c, 0x26, 0x80, 0x90, 0x41, 0xc8, 0x44, 0x08, 0x4a, 0xc5, 0xa1, 0x87, - 0x55, 0x8a, 0x16, 0x21, 0x3e, 0xc4, 0x0d, 0x71, 0xe8, 0x81, 0x8b, 0xe1, 0x8e, 0xdc, 0x64, 0x36, - 0x58, 0x6c, 0xec, 0x62, 0x3b, 0x8b, 0xf6, 0xcf, 0x72, 0xe6, 0x5f, 0x04, 0xc5, 0x76, 0x52, 0x57, - 0xea, 0xa5, 0x9d, 0x79, 0x7e, 0xef, 0x65, 0xbe, 0xe0, 0xe9, 0xde, 0x68, 0xa7, 0x37, 0x4e, 0x98, - 0x06, 0x5d, 0xfc, 0x2b, 0x3d, 0x46, 0x17, 0x21, 0x2b, 0x5e, 0x37, 0xd2, 0xfd, 0xec, 0x76, 0x65, - 0xa5, 0xdb, 0x8d, 0xde, 0xa3, 0xaa, 0xb4, 0xba, 0x92, 0xcd, 0xa6, 0x51, 0xad, 0xdc, 0x04, 0xb5, - 0x0f, 0x87, 0x9f, 0xa0, 0x5c, 0xfd, 0x9b, 0xc1, 0xfd, 0xcf, 0x9e, 0xd5, 0x19, 0xe1, 0xa4, 0x56, - 0xf4, 0x13, 0xdc, 0x35, 0xf8, 0xbb, 0x43, 0xeb, 0x18, 0x59, 0xce, 0xd7, 0xf9, 0xe5, 0xaa, 0x8c, - 0xdf, 0x3a, 0xe2, 0x95, 0x3c, 0x90, 0xbe, 0x28, 0x67, 0x6e, 0xf9, 0x28, 0xa1, 0x1f, 0x20, 0xd6, - 0xc2, 0x66, 0x5e, 0xfc, 0xf2, 0xb4, 0xf8, 0xbb, 0x07, 0x83, 0x36, 0x0a, 0xe8, 0x0b, 0xc8, 0xa5, - 0xb2, 0x4e, 0xa8, 0x0a, 0x7f, 0xc8, 0x9a, 0xcd, 0x97, 0x64, 0x9d, 0x71, 0x18, 0xa1, 0x6d, 0x4d, - 0x9f, 0xc3, 0xb9, 0xc1, 0x1b, 0x69, 0xa5, 0x56, 0xac, 0xef, 0xfb, 0x9e, 0x2c, 0xc9, 0x7a, 0xce, - 0x27, 0xac, 0xe0, 0x70, 0x2f, 0x2d, 0x8a, 0x3e, 0x84, 0xf9, 0x2f, 0xbc, 0x65, 0xc4, 0x1b, 0x0d, - 0x21, 0xbd, 0x80, 0x3b, 0x37, 0xe2, 0xba, 0x43, 0x36, 0x5b, 0x92, 0x75, 0x7e, 0xf9, 0xa4, 0xf4, - 0x93, 0xf8, 0xd6, 0xed, 0x6c, 0x65, 0xe4, 0x0e, 0xa3, 0x9a, 0x07, 0xd2, 0xc7, 0xd9, 0x7b, 0x52, - 0x6c, 0x21, 0x4f, 0x6a, 0x3d, 0x61, 0xf9, 0xea, 0xd8, 0xf2, 0xc1, 0xd8, 0x6f, 0x50, 0x25, 0x56, - 0xab, 0xbf, 0x04, 0x16, 0x01, 0xa5, 0xcf, 0x20, 0x13, 0x75, 0x6d, 0xd0, 0x5a, 0xb4, 0x7e, 0xca, - 0x19, 0x3f, 0x00, 0xf4, 0x2d, 0xe4, 0x95, 0xc1, 0x1a, 0x95, 0x93, 0xe2, 0xda, 0x46, 0xe3, 0x47, - 0xd3, 0x20, 0x0f, 0x4f, 0x3c, 0xe5, 0x51, 0x76, 0x58, 0x5c, 0x98, 0xdd, 0xb4, 0x94, 0x0b, 0x38, - 0x6b, 0xd1, 0x09, 0x76, 0xe6, 0x57, 0xc2, 0x8e, 0x4b, 0x2c, 0xbf, 0xa2, 0x13, 0x61, 0x13, 0x9e, - 0x55, 0xbc, 0x83, 0x6c, 0x82, 0x4e, 0x34, 0xfc, 0x38, 0x6d, 0x38, 0x4b, 0x1b, 0xbc, 0x82, 0x3c, - 0x29, 0x8e, 0x16, 0x70, 0xde, 0x59, 0x34, 0x4a, 0xb4, 0x18, 0xf5, 0x53, 0x3e, 0xbc, 0xed, 0x85, - 0xb5, 0x7f, 0xb4, 0xa9, 0xa3, 0xcf, 0x94, 0x0f, 0x77, 0x30, 0xc6, 0xc9, 0x1d, 0x8c, 0xd0, 0xb6, - 0xde, 0x2d, 0xfc, 0xe9, 0xbe, 0xf9, 0x1f, 0x00, 0x00, 0xff, 0xff, 0x90, 0x77, 0xbc, 0x59, 0x11, - 0x03, 0x00, 0x00, -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/target/target.proto b/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/target/target.proto deleted file mode 100644 index 3ae1415ed..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/target/target.proto +++ /dev/null @@ -1,70 +0,0 @@ -// -// Copyright 2018 Google Inc. All Rights Reserved. -// -// 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. -// -syntax = "proto3"; - -// Package target contains messages for defining a configuration of a caching -// collector to connect to multiple gNMI targets. -package target; - -import "github.com/openconfig/gnmi/proto/gnmi/gnmi.proto"; - -// Configuration holds all information necessary for a caching gNMI collector -// to establish subscriptions to a list of gNMI targets. -message Configuration { - // Request is a keyed list of all SubscriptionRequests that can be sent to - // to targets in the Configuration. - // The request must have at minimum a SubscriptionList with a prefix - // containing origin and one or more Subscriptions. Only the STREAM mode is - // supported. - map request = 1; - // Target is the full list of targets connected to by a caching gNMI - // collector. The key of the map is a unique name to identify a target and - // is set in the prefix.target of a SubscriptionRequest message when connecting - // to each respective target. - map target = 2; - // Identifier for the caching collector. - string instance_id = 3; - // Revision for this Configuration. Systems that non-atomically write - // configuration should populate and require revision, leveraging canonical - // protobuf serialization of fields in order. Presence of this field makes no - // guarantee. Consumers should account for atomicity constraints of their - // environment and any custom encoding. - int64 revision = 536870911; - -} - -// Target is the information necessary to establish a single gNMI Subscribe RPC -// to be collected and cached. -message Target { - // A list of address and port or name that resolves to an address and port. - repeated string addresses = 1; - // Credentials to use in metadata for authorization of the RPC - Credentials credentials = 2; - // The request to be sent to the target. The string supplied is looked up in - // the request map of the Configuration message. - string request = 3; - // Additional target metadata. - map meta = 4; -} - -// Credentials contains the fields necessary for authentication of the client to -// the target. -message Credentials { - string username = 1; - string password = 2; - // Password lookup ID. - string password_id = 3; -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/target/target_pb2.py b/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/target/target_pb2.py deleted file mode 100644 index 468fcf053..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/target/target_pb2.py +++ /dev/null @@ -1,353 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: proto/target/target.proto - -import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) -from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection -from google.protobuf import symbol_database as _symbol_database -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - -from github.com.openconfig.gnmi.proto.gnmi import gnmi_pb2 as github_dot_com_dot_openconfig_dot_gnmi_dot_proto_dot_gnmi_dot_gnmi__pb2 - - -DESCRIPTOR = _descriptor.FileDescriptor( - name='proto/target/target.proto', - package='target', - syntax='proto3', - serialized_options=None, - serialized_pb=_b('\n\x19proto/target/target.proto\x12\x06target\x1a\x30github.com/openconfig/gnmi/proto/gnmi/gnmi.proto\"\xa9\x02\n\rConfiguration\x12\x33\n\x07request\x18\x01 \x03(\x0b\x32\".target.Configuration.RequestEntry\x12\x31\n\x06target\x18\x02 \x03(\x0b\x32!.target.Configuration.TargetEntry\x12\x13\n\x0binstance_id\x18\x03 \x01(\t\x12\x14\n\x08revision\x18\xff\xff\xff\xff\x01 \x01(\x03\x1a\x46\n\x0cRequestEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12%\n\x05value\x18\x02 \x01(\x0b\x32\x16.gnmi.SubscribeRequest:\x02\x38\x01\x1a=\n\x0bTargetEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\x1d\n\x05value\x18\x02 \x01(\x0b\x32\x0e.target.Target:\x02\x38\x01\"\xab\x01\n\x06Target\x12\x11\n\taddresses\x18\x01 \x03(\t\x12(\n\x0b\x63redentials\x18\x02 \x01(\x0b\x32\x13.target.Credentials\x12\x0f\n\x07request\x18\x03 \x01(\t\x12&\n\x04meta\x18\x04 \x03(\x0b\x32\x18.target.Target.MetaEntry\x1a+\n\tMetaEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"F\n\x0b\x43redentials\x12\x10\n\x08username\x18\x01 \x01(\t\x12\x10\n\x08password\x18\x02 \x01(\t\x12\x13\n\x0bpassword_id\x18\x03 \x01(\tb\x06proto3') - , - dependencies=[github_dot_com_dot_openconfig_dot_gnmi_dot_proto_dot_gnmi_dot_gnmi__pb2.DESCRIPTOR,]) - - - - -_CONFIGURATION_REQUESTENTRY = _descriptor.Descriptor( - name='RequestEntry', - full_name='target.Configuration.RequestEntry', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='key', full_name='target.Configuration.RequestEntry.key', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='value', full_name='target.Configuration.RequestEntry.value', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=_b('8\001'), - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=252, - serialized_end=322, -) - -_CONFIGURATION_TARGETENTRY = _descriptor.Descriptor( - name='TargetEntry', - full_name='target.Configuration.TargetEntry', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='key', full_name='target.Configuration.TargetEntry.key', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='value', full_name='target.Configuration.TargetEntry.value', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=_b('8\001'), - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=324, - serialized_end=385, -) - -_CONFIGURATION = _descriptor.Descriptor( - name='Configuration', - full_name='target.Configuration', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='request', full_name='target.Configuration.request', index=0, - number=1, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='target', full_name='target.Configuration.target', index=1, - number=2, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='instance_id', full_name='target.Configuration.instance_id', index=2, - number=3, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='revision', full_name='target.Configuration.revision', index=3, - number=536870911, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[_CONFIGURATION_REQUESTENTRY, _CONFIGURATION_TARGETENTRY, ], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=88, - serialized_end=385, -) - - -_TARGET_METAENTRY = _descriptor.Descriptor( - name='MetaEntry', - full_name='target.Target.MetaEntry', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='key', full_name='target.Target.MetaEntry.key', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='value', full_name='target.Target.MetaEntry.value', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=_b('8\001'), - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=516, - serialized_end=559, -) - -_TARGET = _descriptor.Descriptor( - name='Target', - full_name='target.Target', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='addresses', full_name='target.Target.addresses', index=0, - number=1, type=9, cpp_type=9, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='credentials', full_name='target.Target.credentials', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='request', full_name='target.Target.request', index=2, - number=3, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='meta', full_name='target.Target.meta', index=3, - number=4, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[_TARGET_METAENTRY, ], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=388, - serialized_end=559, -) - - -_CREDENTIALS = _descriptor.Descriptor( - name='Credentials', - full_name='target.Credentials', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='username', full_name='target.Credentials.username', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='password', full_name='target.Credentials.password', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='password_id', full_name='target.Credentials.password_id', index=2, - number=3, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=561, - serialized_end=631, -) - -_CONFIGURATION_REQUESTENTRY.fields_by_name['value'].message_type = github_dot_com_dot_openconfig_dot_gnmi_dot_proto_dot_gnmi_dot_gnmi__pb2._SUBSCRIBEREQUEST -_CONFIGURATION_REQUESTENTRY.containing_type = _CONFIGURATION -_CONFIGURATION_TARGETENTRY.fields_by_name['value'].message_type = _TARGET -_CONFIGURATION_TARGETENTRY.containing_type = _CONFIGURATION -_CONFIGURATION.fields_by_name['request'].message_type = _CONFIGURATION_REQUESTENTRY -_CONFIGURATION.fields_by_name['target'].message_type = _CONFIGURATION_TARGETENTRY -_TARGET_METAENTRY.containing_type = _TARGET -_TARGET.fields_by_name['credentials'].message_type = _CREDENTIALS -_TARGET.fields_by_name['meta'].message_type = _TARGET_METAENTRY -DESCRIPTOR.message_types_by_name['Configuration'] = _CONFIGURATION -DESCRIPTOR.message_types_by_name['Target'] = _TARGET -DESCRIPTOR.message_types_by_name['Credentials'] = _CREDENTIALS -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -Configuration = _reflection.GeneratedProtocolMessageType('Configuration', (_message.Message,), dict( - - RequestEntry = _reflection.GeneratedProtocolMessageType('RequestEntry', (_message.Message,), dict( - DESCRIPTOR = _CONFIGURATION_REQUESTENTRY, - __module__ = 'proto.target.target_pb2' - # @@protoc_insertion_point(class_scope:target.Configuration.RequestEntry) - )) - , - - TargetEntry = _reflection.GeneratedProtocolMessageType('TargetEntry', (_message.Message,), dict( - DESCRIPTOR = _CONFIGURATION_TARGETENTRY, - __module__ = 'proto.target.target_pb2' - # @@protoc_insertion_point(class_scope:target.Configuration.TargetEntry) - )) - , - DESCRIPTOR = _CONFIGURATION, - __module__ = 'proto.target.target_pb2' - # @@protoc_insertion_point(class_scope:target.Configuration) - )) -_sym_db.RegisterMessage(Configuration) -_sym_db.RegisterMessage(Configuration.RequestEntry) -_sym_db.RegisterMessage(Configuration.TargetEntry) - -Target = _reflection.GeneratedProtocolMessageType('Target', (_message.Message,), dict( - - MetaEntry = _reflection.GeneratedProtocolMessageType('MetaEntry', (_message.Message,), dict( - DESCRIPTOR = _TARGET_METAENTRY, - __module__ = 'proto.target.target_pb2' - # @@protoc_insertion_point(class_scope:target.Target.MetaEntry) - )) - , - DESCRIPTOR = _TARGET, - __module__ = 'proto.target.target_pb2' - # @@protoc_insertion_point(class_scope:target.Target) - )) -_sym_db.RegisterMessage(Target) -_sym_db.RegisterMessage(Target.MetaEntry) - -Credentials = _reflection.GeneratedProtocolMessageType('Credentials', (_message.Message,), dict( - DESCRIPTOR = _CREDENTIALS, - __module__ = 'proto.target.target_pb2' - # @@protoc_insertion_point(class_scope:target.Credentials) - )) -_sym_db.RegisterMessage(Credentials) - - -_CONFIGURATION_REQUESTENTRY._options = None -_CONFIGURATION_TARGETENTRY._options = None -_TARGET_METAENTRY._options = None -# @@protoc_insertion_point(module_scope) diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/target/target_pb2_grpc.py b/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/target/target_pb2_grpc.py deleted file mode 100644 index a89435267..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/proto/target/target_pb2_grpc.py +++ /dev/null @@ -1,3 +0,0 @@ -# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! -import grpc - diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/subscribe/subscribe.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/subscribe/subscribe.go deleted file mode 100644 index 2de78f689..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/subscribe/subscribe.go +++ /dev/null @@ -1,483 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 subscribe implements the gnmi.proto Subscribe service API. -package subscribe - -import ( - "context" - "errors" - "io" - "time" - - log "github.com/golang/glog" - "github.com/golang/protobuf/proto" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/peer" - "google.golang.org/grpc/status" - "github.com/openconfig/gnmi/cache" - "github.com/openconfig/gnmi/client" - "github.com/openconfig/gnmi/coalesce" - "github.com/openconfig/gnmi/ctree" - "github.com/openconfig/gnmi/match" - "github.com/openconfig/gnmi/path" - "github.com/openconfig/gnmi/unimplemented" - "github.com/openconfig/gnmi/value" - - pb "github.com/openconfig/gnmi/proto/gnmi" -) - -var ( - // Value overridden in tests to simulate flow control. - flowControlTest = func() {} - // Timeout specifies how long a send can be pending before the RPC is closed. - Timeout = time.Minute - // SubscriptionLimit specifies how many queries can be processing simultaneously. - // This number includes Once queries, Polling subscriptions, and Streaming - // subscriptions that have not yet synced. Once a streaming subscription has - // synced, it no longer counts against the limit. A polling subscription - // counts against the limit during each polling cycle while it is processed. - SubscriptionLimit = 0 - // Value overridden in tests to evaluate SubscriptionLimit enforcement. - subscriptionLimitTest = func() {} -) - -type aclStub struct{} - -func (a *aclStub) Check(string) bool { - return true -} - -// RPCACL is per RPC ACL interface -type RPCACL interface { - Check(string) bool -} - -// ACL is server ACL interface -type ACL interface { - NewRPCACL(context.Context) (RPCACL, error) - Check(string, string) bool -} - -// Server is the implementation of the gNMI Subcribe API. -type Server struct { - unimplemented.Server // Stub out all RPCs except Subscribe. - - c *cache.Cache // The cache queries are performed against. - m *match.Match // Structure to match updates against active subscriptions. - a ACL // server ACL. - // subscribeSlots is a channel of size SubscriptionLimit to restrict how many - // queries are in flight. - subscribeSlots chan struct{} - timeout time.Duration -} - -// NewServer instantiates server to handle client queries. The cache should be -// already instantiated. -func NewServer(c *cache.Cache) (*Server, error) { - s := &Server{c: c, m: match.New(), timeout: Timeout} - if SubscriptionLimit > 0 { - s.subscribeSlots = make(chan struct{}, SubscriptionLimit) - } - return s, nil -} - -// SetACL sets server ACL. This method is called before server starts to run. -func (s *Server) SetACL(a ACL) { - s.a = a -} - -// Update passes a streaming update to registered clients. -func (s *Server) Update(n *ctree.Leaf) { - switch v := n.Value().(type) { - case client.Delete: - s.m.Update(n, v.Path) - case client.Update: - s.m.Update(n, v.Path) - case *pb.Notification: - p := path.ToStrings(v.Prefix, true) - if len(v.Update) > 0 { - p = append(p, path.ToStrings(v.Update[0].Path, false)...) - } else if len(v.Delete) > 0 { - p = append(p, path.ToStrings(v.Delete[0], false)...) - } - // If neither update nor delete notification exists, - // just go with the path in the prefix - s.m.Update(n, p) - default: - log.Errorf("update is not a known type; type is %T", v) - } -} - -// addSubscription registers all subscriptions for this client for update matching. -func addSubscription(m *match.Match, s *pb.SubscriptionList, c *matchClient) (remove func()) { - var removes []func() - prefix := path.ToStrings(s.Prefix, true) - for _, p := range s.Subscription { - if p.Path == nil { - continue - } - // TODO(yusufsn) : Origin field in the Path may need to be included - path := append(prefix, path.ToStrings(p.Path, false)...) - removes = append(removes, m.AddQuery(path, c)) - } - return func() { - for _, remove := range removes { - remove() - } - } -} - -// Subscribe is the entry point for the external RPC request of the same name -// defined in gnmi.proto. -func (s *Server) Subscribe(stream pb.GNMI_SubscribeServer) error { - c := streamClient{stream: stream, acl: &aclStub{}} - var err error - if s.a != nil { - a, err := s.a.NewRPCACL(stream.Context()) - if err != nil { - log.Errorf("NewRPCACL fails due to %v", err) - return status.Error(codes.Unauthenticated, "no authentication/authorization for requested operation") - } - c.acl = a - } - c.sr, err = stream.Recv() - - switch { - case err == io.EOF: - return nil - case err != nil: - return err - case c.sr.GetSubscribe() == nil: - return status.Errorf(codes.InvalidArgument, "request must contain a subscription %#v", c.sr) - case c.sr.GetSubscribe().GetPrefix() == nil: - return status.Errorf(codes.InvalidArgument, "request must contain a prefix %#v", c.sr) - case c.sr.GetSubscribe().GetPrefix().GetTarget() == "": - return status.Error(codes.InvalidArgument, "missing target") - } - - c.target = c.sr.GetSubscribe().GetPrefix().GetTarget() - if !s.c.HasTarget(c.target) { - return status.Errorf(codes.NotFound, "no such target: %q", c.target) - } - peer, _ := peer.FromContext(stream.Context()) - mode := c.sr.GetSubscribe().Mode - - log.Infof("peer: %v target: %q subscription: %s", peer.Addr, c.target, c.sr) - defer log.Infof("peer: %v target %q subscription: end: %q", peer.Addr, c.target, c.sr) - - c.queue = coalesce.NewQueue() - defer c.queue.Close() - - // reject single device subscription if not allowed by ACL - if c.target != "*" && !c.acl.Check(c.target) { - return status.Errorf(codes.PermissionDenied, "not authorized for target %q", c.target) - } - // This error channel is buffered to accept errors from all goroutines spawned - // for this RPC. Only the first is ever read and returned causing the RPC to - // terminate. - errC := make(chan error, 3) - c.errC = errC - - switch mode { - case pb.SubscriptionList_ONCE: - go func() { - s.processSubscription(&c) - c.queue.Close() - }() - case pb.SubscriptionList_POLL: - go s.processPollingSubscription(&c) - case pb.SubscriptionList_STREAM: - if c.sr.GetSubscribe().GetUpdatesOnly() { - c.queue.Insert(syncMarker{}) - } - remove := addSubscription(s.m, c.sr.GetSubscribe(), - &matchClient{acl: c.acl, q: c.queue}) - defer remove() - if !c.sr.GetSubscribe().GetUpdatesOnly() { - go s.processSubscription(&c) - } - default: - return status.Errorf(codes.InvalidArgument, "Subscription mode %v not recognized", mode) - } - - go s.sendStreamingResults(&c) - - return <-errC -} - -type resp struct { - stream pb.GNMI_SubscribeServer - n *ctree.Leaf - dup uint32 - t *time.Timer // Timer used to timout the subscription. -} - -// sendSubscribeResponse populates and sends a single response returned on -// the Subscription RPC output stream. Streaming queries send responses for the -// initial walk of the results as well as streamed updates and use a queue to -// ensure order. -func (s *Server) sendSubscribeResponse(r *resp, c *streamClient) error { - notification, err := MakeSubscribeResponse(r.n.Value(), r.dup) - if err != nil { - return status.Errorf(codes.Unknown, err.Error()) - } - - if pre := notification.GetUpdate().GetPrefix(); pre != nil { - if !c.acl.Check(pre.GetTarget()) { - // reaching here means notification is denied for sending. - // return with no error. function caller can continue for next one. - return nil - } - } - - // Start the timeout before attempting to send. - r.t.Reset(s.timeout) - // Clear the timeout upon sending. - defer r.t.Stop() - // An empty function in production, replaced in test to simulate flow control - // by blocking before send. - flowControlTest() - return r.stream.Send(notification) -} - -// subscribeSync is a response indicating that a Subscribe RPC has successfully -// returned all matching nodes once for ONCE and POLLING queries and at least -// once for STREAMING queries. -var subscribeSync = &pb.SubscribeResponse{Response: &pb.SubscribeResponse_SyncResponse{true}} - -type syncMarker struct{} - -// cacheClient implements match.Client interface. -type matchClient struct { - acl RPCACL - q *coalesce.Queue - err error -} - -// Update implements the match.Client Update interface for coalesce.Queue. -func (c matchClient) Update(n interface{}) { - // Stop processing updates on error. - if c.err != nil { - return - } - _, c.err = c.q.Insert(n) -} - -type streamClient struct { - acl RPCACL - target string - sr *pb.SubscribeRequest - queue *coalesce.Queue - stream pb.GNMI_SubscribeServer - errC chan<- error -} - -// processSubscription walks the cache tree and inserts all of the matching -// nodes into the coalesce queue followed by a subscriptionSync response. -func (s *Server) processSubscription(c *streamClient) { - var err error - log.V(2).Infof("start processSubscription for %p", c) - // Close the cache client queue on error. - defer func() { - if err != nil { - log.Error(err) - c.queue.Close() - c.errC <- err - } - log.V(2).Infof("end processSubscription for %p", c) - }() - if s.subscribeSlots != nil { - select { - // Register a subscription in the channel, which will block if SubscriptionLimit queries - // are already in flight. - case s.subscribeSlots <- struct{}{}: - default: - log.V(2).Infof("subscription %s delayed waiting for 1 of %d subscription slots.", c.sr, len(s.subscribeSlots)) - s.subscribeSlots <- struct{}{} - log.V(2).Infof("subscription %s resumed", c.sr) - } - // Remove subscription from the channel upon completion. - defer func() { - // Artificially hold subscription processing in tests to synchronously test limit. - subscriptionLimitTest() - <-s.subscribeSlots - }() - } - if !c.sr.GetSubscribe().GetUpdatesOnly() { - for _, subscription := range c.sr.GetSubscribe().Subscription { - var fullPath []string - fullPath, err = path.CompletePath(c.sr.GetSubscribe().GetPrefix(), subscription.GetPath()) - if err != nil { - return - } - // Note that fullPath doesn't contain target name as the first element. - s.c.Query(c.target, fullPath, func(_ []string, l *ctree.Leaf, _ interface{}) { - // Stop processing query results on error. - if err != nil { - return - } - _, err = c.queue.Insert(l) - }) - if err != nil { - return - } - } - } - - _, err = c.queue.Insert(syncMarker{}) -} - -// processPollingSubscription handles the POLL mode Subscription RPC. -func (s *Server) processPollingSubscription(c *streamClient) { - s.processSubscription(c) - log.Infof("polling subscription: first complete response: %q", c.sr) - for { - if c.queue.IsClosed() { - return - } - // Subsequent receives are only triggers to poll again. The contents of the - // request are completely ignored. - _, err := c.stream.Recv() - if err == io.EOF { - return - } - if err != nil { - log.Error(err) - c.errC <- err - return - } - log.Infof("polling subscription: repoll: %q", c.sr) - s.processSubscription(c) - log.Infof("polling subscription: repoll complete: %q", c.sr) - } -} - -// sendStreamingResults forwards all streaming updates to a given streaming -// Subscription RPC client. -func (s *Server) sendStreamingResults(c *streamClient) { - ctx := c.stream.Context() - peer, _ := peer.FromContext(ctx) - t := time.NewTimer(s.timeout) - // Make sure the timer doesn't expire waiting for a value to send, only - // waiting to send. - t.Stop() - done := make(chan struct{}) - defer close(done) - // If a send doesn't occur within the timeout, close the stream. - go func() { - select { - case <-t.C: - err := errors.New("subscription timed out while sending") - c.errC <- err - log.Errorf("%v : %v", peer, err) - case <-done: - } - }() - for { - item, dup, err := c.queue.Next(ctx) - if coalesce.IsClosedQueue(err) { - c.errC <- nil - return - } - if err != nil { - c.errC <- err - return - } - - // s.processSubscription will send a sync marker, handle it separately. - if _, ok := item.(syncMarker); ok { - if err = c.stream.Send(subscribeSync); err != nil { - c.errC <- err - return - } - continue - } - - n, ok := item.(*ctree.Leaf) - if !ok || n == nil { - c.errC <- status.Errorf(codes.Internal, "invalid cache node: %#v", item) - return - } - - if err = s.sendSubscribeResponse(&resp{ - stream: c.stream, - n: n, - dup: dup, - t: t, - }, c); err != nil { - c.errC <- err - return - } - // If the only target being subscribed was deleted, stop streaming. - if cache.IsTargetDelete(n) && c.target != "*" { - log.Infof("Target %q was deleted. Closing stream.", c.target) - c.errC <- nil - return - } - } -} - -// MakeSubscribeResponse produces a gnmi_proto.SubscribeResponse from either -// client.Notification or gnmi_proto.Notification -// -// This function modifies the message to set the duplicate count if it is -// greater than 0. The function clones the gnmi notification if the duplicate count needs to be set. -// You have to be working on a cloned message if you need to modify the message in any way. -func MakeSubscribeResponse(n interface{}, dup uint32) (*pb.SubscribeResponse, error) { - var notification *pb.Notification - switch cache.Type { - case cache.GnmiNoti: - var ok bool - notification, ok = n.(*pb.Notification) - if !ok { - return nil, status.Errorf(codes.Internal, "invalid notification type: %#v", n) - } - - // There may be multiple updates in a notification. Since duplicate count is just - // an indicator that coalescion is happening, not a critical data, just the first - // update is set with duplicate count to be on the side of efficiency. - // Only attempt to set the duplicate count if it is greater than 0. The default - // value in the message is already 0. - if dup > 0 && len(notification.Update) > 0 { - // We need a copy of the cached notification before writing a client specific - // duplicate count as the notification is shared across all clients. - notification = proto.Clone(notification).(*pb.Notification) - notification.Update[0].Duplicates = dup - } - case cache.ClientLeaf: - notification = &pb.Notification{} - switch v := n.(type) { - case client.Delete: - notification.Delete = []*pb.Path{{Element: v.Path}} - notification.Timestamp = v.TS.UnixNano() - case client.Update: - typedVal, err := value.FromScalar(v.Val) - if err != nil { - return nil, err - } - notification.Update = []*pb.Update{{Path: &pb.Path{Element: v.Path}, Val: typedVal, Duplicates: dup}} - notification.Timestamp = v.TS.UnixNano() - } - } - response := &pb.SubscribeResponse{ - Response: &pb.SubscribeResponse_Update{ - Update: notification, - }, - } - - return response, nil -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/subscribe/subscribe_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/subscribe/subscribe_test.go deleted file mode 100644 index 4fad22503..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/subscribe/subscribe_test.go +++ /dev/null @@ -1,1797 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 subscribe - -import ( - "context" - "crypto/tls" - "errors" - "fmt" - "io" - "net" - "strings" - "sync" - "testing" - "time" - - "github.com/golang/protobuf/proto" - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "google.golang.org/grpc" - "google.golang.org/grpc/peer" - "github.com/openconfig/gnmi/cache" - "github.com/openconfig/gnmi/client" - gnmiclient "github.com/openconfig/gnmi/client/gnmi" - "github.com/openconfig/gnmi/path" - "github.com/openconfig/gnmi/testing/fake/testing/grpc/config" - "github.com/openconfig/gnmi/value" - - pb "github.com/openconfig/gnmi/proto/gnmi" -) - -func startServer(targets []string) (string, *cache.Cache, func(), error) { - c := cache.New(targets) - p, err := NewServer(c) - if err != nil { - return "", nil, nil, fmt.Errorf("NewServer: %v", err) - } - c.SetClient(p.Update) - lis, err := net.Listen("tcp", "") - if err != nil { - return "", nil, nil, fmt.Errorf("net.Listen: %v", err) - } - opt, err := config.WithSelfTLSCert() - if err != nil { - return "", nil, nil, fmt.Errorf("config.WithSelfCert: %v", err) - } - srv := grpc.NewServer(opt) - pb.RegisterGNMIServer(srv, p) - go srv.Serve(lis) - return lis.Addr().String(), p.c, func() { - lis.Close() - }, nil -} - -func TestOnce(t *testing.T) { - addr, cache, teardown, err := startServer(client.Path{"dev1"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - paths := []client.Path{ - {"dev1", "a", "b"}, - {"dev1", "a", "c"}, - {"dev1", "e", "f"}, - {"dev1", "f", "b"}, - } - var timestamp time.Time - sendUpdates(t, cache, paths, ×tamp) - - testCases := []struct { - dev string - query client.Path - count int - err bool - }{ - // These cases will be found. - {"dev1", client.Path{"a", "b"}, 1, false}, - {"dev1", client.Path{"a"}, 2, false}, - {"dev1", client.Path{"e"}, 1, false}, - {"dev1", client.Path{"*", "b"}, 2, false}, - // This case is not found. - {"dev1", client.Path{"b"}, 0, false}, - // This target doesn't even exist, and will return an error. - {"dev2", client.Path{"a"}, 0, true}, - } - for _, tt := range testCases { - t.Run(fmt.Sprintf("target: %q query: %q", tt.dev, tt.query), func(t *testing.T) { - sync := 0 - count := 0 - q := client.Query{ - Addrs: []string{addr}, - Target: tt.dev, - Queries: []client.Path{tt.query}, - Type: client.Once, - NotificationHandler: func(n client.Notification) error { - switch n.(type) { - case client.Update: - count++ - case client.Sync: - sync++ - case client.Connected: - default: - t.Fatalf("unexpected notification %#v", n) - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - c := client.BaseClient{} - err := c.Subscribe(context.Background(), q, gnmiclient.Type) - defer c.Close() - if err != nil && !tt.err { - t.Fatalf("unexpected error: %v", err) - } - if err == nil && tt.err { - t.Fatal("didn't get expected error") - } - if tt.err { - return - } - if sync != 1 { - t.Errorf("got %d sync messages, want 1", sync) - } - if count != tt.count { - t.Errorf("got %d updates, want %d", count, tt.count) - } - }) - } -} - -func TestOriginInSubscribeRequest(t *testing.T) { - cache.Type = cache.GnmiNoti - defer func() { - cache.Type = cache.ClientLeaf - }() - addr, cache, teardown, err := startServer(client.Path{"dev1"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - paths := []client.Path{ - {"dev1", "a", "b", "c", "d"}, - {"dev1", "a", "b", "d", "e"}, - {"dev1", "a", "c", "d", "e"}, - } - var timestamp time.Time - sendUpdates(t, cache, paths, ×tamp) - - tests := []struct { - desc string - inPrefix *pb.Path - inPath *pb.Path - wantCount int - wantErr bool - }{ - { - desc: "no origin set", - inPrefix: &pb.Path{Target: "dev1", Elem: []*pb.PathElem{{Name: "a"}}}, - inPath: &pb.Path{Elem: []*pb.PathElem{}}, - wantCount: 3, - }, - { - desc: "origin set in prefix", - inPrefix: &pb.Path{Target: "dev1", Origin: "a", Elem: []*pb.PathElem{{Name: "b"}}}, - inPath: &pb.Path{Elem: []*pb.PathElem{}}, - wantCount: 2, - }, - { - desc: "origin set in path with path elements in prefix", - inPrefix: &pb.Path{Target: "dev1", Elem: []*pb.PathElem{{Name: "a"}}}, - inPath: &pb.Path{Origin: "b"}, - wantErr: true, - }, - { - desc: "origin set in path", - inPrefix: &pb.Path{Target: "dev1"}, - inPath: &pb.Path{Origin: "a", Elem: []*pb.PathElem{{Name: "b"}}}, - wantCount: 2, - }, - { - desc: "origin set in path and prefix", - inPrefix: &pb.Path{Target: "dev1", Origin: "a", Elem: []*pb.PathElem{{Name: "b"}}}, - inPath: &pb.Path{Origin: "c"}, - wantErr: true, - }, - } - - for _, tt := range tests { - t.Run(fmt.Sprintf("%s: prefix %v and path %v", tt.desc, tt.inPrefix, tt.inPath), func(t *testing.T) { - sync := 0 - count := 0 - q, err := client.NewQuery(&pb.SubscribeRequest{ - Request: &pb.SubscribeRequest_Subscribe{ - Subscribe: &pb.SubscriptionList{ - Prefix: tt.inPrefix, - Subscription: []*pb.Subscription{{Path: tt.inPath}}, - Mode: pb.SubscriptionList_ONCE, - }, - }, - }) - if err != nil { - t.Fatalf("failed to initialize a client.Query: %v", err) - } - q.ProtoHandler = func(msg proto.Message) error { - resp, ok := msg.(*pb.SubscribeResponse) - if !ok { - return fmt.Errorf("failed to type assert message %#v", msg) - } - switch v := resp.Response.(type) { - case *pb.SubscribeResponse_Update: - count++ - case *pb.SubscribeResponse_Error: - return fmt.Errorf("error in response: %s", v) - case *pb.SubscribeResponse_SyncResponse: - sync++ - default: - return fmt.Errorf("unknown response %T: %s", v, v) - } - - return nil - } - q.TLS = &tls.Config{InsecureSkipVerify: true} - q.Addrs = []string{addr} - - c := client.BaseClient{} - err = c.Subscribe(context.Background(), q, gnmiclient.Type) - defer c.Close() - if tt.wantErr { - if err == nil { - t.Fatal("got nil, want err") - } - return - } - if err != nil { - t.Fatalf("got %v, want no error", err) - } - if sync != 1 { - t.Errorf("got %d sync messages, want 1", sync) - } - if count != tt.wantCount { - t.Errorf("got %d updates, want %d", count, tt.wantCount) - } - }) - } -} - -func TestGNMIOnce(t *testing.T) { - cache.Type = cache.GnmiNoti - defer func() { - cache.Type = cache.ClientLeaf - }() - addr, cache, teardown, err := startServer(client.Path{"dev1"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - paths := []client.Path{ - {"dev1", "a", "b"}, - {"dev1", "a", "c"}, - {"dev1", "e", "f"}, - {"dev1", "f", "b"}, - } - var timestamp time.Time - sendUpdates(t, cache, paths, ×tamp) - - testCases := []struct { - dev string - query client.Path - count int - err bool - }{ - // These cases will be found. - {"dev1", client.Path{"a", "b"}, 1, false}, - {"dev1", client.Path{"a"}, 2, false}, - {"dev1", client.Path{"e"}, 1, false}, - {"dev1", client.Path{"*", "b"}, 2, false}, - // This case is not found. - {"dev1", client.Path{"b"}, 0, false}, - // This target doesn't even exist, and will return an error. - {"dev2", client.Path{"a"}, 0, true}, - } - for _, tt := range testCases { - t.Run(fmt.Sprintf("target: %q query: %q", tt.dev, tt.query), func(t *testing.T) { - sync := 0 - count := 0 - q := client.Query{ - Addrs: []string{addr}, - Target: tt.dev, - Queries: []client.Path{tt.query}, - Type: client.Once, - ProtoHandler: func(msg proto.Message) error { - resp, ok := msg.(*pb.SubscribeResponse) - if !ok { - return fmt.Errorf("failed to type assert message %#v", msg) - } - switch v := resp.Response.(type) { - case *pb.SubscribeResponse_Update: - count++ - case *pb.SubscribeResponse_Error: - return fmt.Errorf("error in response: %s", v) - case *pb.SubscribeResponse_SyncResponse: - sync++ - default: - return fmt.Errorf("unknown response %T: %s", v, v) - } - - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - c := client.BaseClient{} - err := c.Subscribe(context.Background(), q, gnmiclient.Type) - defer c.Close() - if err != nil && !tt.err { - t.Fatalf("unexpected error: %v", err) - } - if err == nil && tt.err { - t.Fatal("didn't get expected error") - } - if tt.err { - return - } - if sync != 1 { - t.Errorf("got %d sync messages, want 1", sync) - } - if count != tt.count { - t.Errorf("got %d updates, want %d", count, tt.count) - } - }) - } -} - -// sendUpdates generates an update for each supplied path incrementing the -// timestamp and value for each. -func sendUpdates(t *testing.T, c *cache.Cache, paths []client.Path, timestamp *time.Time) { - t.Helper() - switch cache.Type { - case cache.ClientLeaf: - for _, path := range paths { - *timestamp = timestamp.Add(time.Nanosecond) - if err := c.Update(client.Update{Path: path, Val: timestamp.UnixNano(), TS: *timestamp}); err != nil { - t.Errorf("streamUpdate: %v", err) - } - } - case cache.GnmiNoti: - for _, path := range paths { - *timestamp = timestamp.Add(time.Nanosecond) - sv, err := value.FromScalar(timestamp.UnixNano()) - if err != nil { - t.Errorf("Scalar value err %v", err) - continue - } - noti := &pb.Notification{ - Prefix: &pb.Path{Target: path[0]}, - Timestamp: timestamp.UnixNano(), - Update: []*pb.Update{ - { - Path: &pb.Path{Element: path[1:]}, - Val: sv, - }, - }, - } - if err := c.GnmiUpdate(noti); err != nil { - t.Errorf("streamUpdate: %v", err) - } - } - } -} - -func TestPoll(t *testing.T) { - addr, cache, teardown, err := startServer([]string{"dev1", "dev2"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - paths := []client.Path{ - {"dev1", "a", "b"}, - {"dev1", "a", "c"}, - {"dev1", "e", "f"}, - {"dev2", "a", "b"}, - } - var timestamp time.Time - sendUpdates(t, cache, paths, ×tamp) - - m := map[string]time.Time{} - sync := 0 - count := 0 - c := client.BaseClient{} - q := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Poll, - NotificationHandler: func(n client.Notification) error { - switch u := n.(type) { - case client.Update: - count++ - v, ts := strings.Join(u.Path, "/"), u.TS - want1, want2 := "dev1/a/b", "dev1/a/c" - if v != want1 && v != want2 { - t.Fatalf("#%d: got %q, want one of (%q, %q)", count, v, want1, want2) - } - if ts.Before(m[v]) { - t.Fatalf("#%d: got timestamp %s, want >= %s for value %q", count, ts, m[v], v) - } - m[v] = ts - case client.Sync: - if count != 2 { - t.Fatalf("did not receive initial updates before sync, got %d, want 2", count) - } - count = 0 - sync++ - if sync == 3 { - c.Close() - } else { - sendUpdates(t, cache, paths, ×tamp) - c.Poll() - } - case client.Connected: - default: - t.Fatalf("#%d: unexpected notification %#v", count, n) - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - err = c.Subscribe(context.Background(), q, gnmiclient.Type) - if err != nil { - t.Error(err) - } -} - -func TestGNMIPoll(t *testing.T) { - cache.Type = cache.GnmiNoti - defer func() { - cache.Type = cache.ClientLeaf - }() - addr, cache, teardown, err := startServer([]string{"dev1", "dev2"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - paths := []client.Path{ - {"dev1", "a", "b"}, - {"dev1", "a", "c"}, - {"dev1", "e", "f"}, - {"dev2", "a", "b"}, - } - var timestamp time.Time - sendUpdates(t, cache, paths, ×tamp) - - // The streaming Updates change only the timestamp, so the value is used as - // a key. - m := map[string]time.Time{} - sync := 0 - count := 0 - c := client.BaseClient{} - q := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Poll, - ProtoHandler: func(msg proto.Message) error { - resp, ok := msg.(*pb.SubscribeResponse) - if !ok { - return fmt.Errorf("failed to type assert message %#v", msg) - } - switch r := resp.Response.(type) { - case *pb.SubscribeResponse_Update: - count++ - ts := time.Unix(0, r.Update.GetTimestamp()) - v := strings.Join(path.ToStrings(r.Update.Update[0].Path, false), "/") - if ts.Before(m[v]) { - t.Fatalf("#%d: got timestamp %s, want >= %s for value %q", count, ts, m[v], v) - } - m[v] = ts - case *pb.SubscribeResponse_Error: - return fmt.Errorf("error in response: %s", r) - case *pb.SubscribeResponse_SyncResponse: - if count != 2 { - t.Fatalf("did not receive initial updates before sync, got %d, want 2", count) - } - count = 0 - sync++ - if sync == 3 { - c.Close() - } else { - sendUpdates(t, cache, paths, ×tamp) - c.Poll() - } - default: - return fmt.Errorf("unknown response %T: %s", r, r) - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - err = c.Subscribe(context.Background(), q, gnmiclient.Type) - if err != nil { - t.Error(err) - } -} - -func TestStream(t *testing.T) { - addr, cache, teardown, err := startServer([]string{"dev1", "dev2"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - paths := []client.Path{ - {"dev1", "a", "b"}, - {"dev1", "a", "c"}, - {"dev1", "e", "f"}, - {"dev2", "a", "b"}, - } - var timestamp time.Time - sendUpdates(t, cache, paths, ×tamp) - - m := map[string]time.Time{} - sync := false - count := 0 - c := client.BaseClient{} - q := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - NotificationHandler: func(n client.Notification) error { - switch u := n.(type) { - case client.Update: - count++ - // The total updates received should be 4, 2 before sync, 2 after. - if count == 4 { - c.Close() - } - v, ts := strings.Join(u.Path, "/"), u.TS - want1, want2 := "dev1/a/b", "dev1/a/c" - if v != want1 && v != want2 { - t.Fatalf("#%d: got %q, want one of (%q, %q)", count, v, want1, want2) - } - if ts.Before(m[v]) { - t.Fatalf("#%d: got timestamp %s, want >= %s for value %q", count, ts, m[v], v) - } - m[v] = ts - case client.Sync: - if sync { - t.Fatal("received more than one sync message") - } - if count < 2 { - t.Fatalf("did not receive initial updates before sync, got %d, want > 2", count) - } - sync = true - // Send some updates after the sync occurred. - sendUpdates(t, cache, paths, ×tamp) - case client.Connected: - default: - t.Fatalf("#%d: unexpected notification %#v", count, n) - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - err = c.Subscribe(context.Background(), q, gnmiclient.Type) - if err != nil { - t.Error(err) - } - if !sync { - t.Error("streaming query did not send sync message") - } -} - -func TestGNMIStream(t *testing.T) { - cache.Type = cache.GnmiNoti - defer func() { - cache.Type = cache.ClientLeaf - }() - addr, cache, teardown, err := startServer([]string{"dev1", "dev2"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - paths := []client.Path{ - {"dev1", "a", "b"}, - {"dev1", "a", "c"}, - {"dev1", "e", "f"}, - {"dev2", "a", "b"}, - } - var timestamp time.Time - sendUpdates(t, cache, paths, ×tamp) - - m := map[string]time.Time{} - sync := false - count := 0 - c := client.BaseClient{} - q := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - ProtoHandler: func(msg proto.Message) error { - resp, ok := msg.(*pb.SubscribeResponse) - if !ok { - return fmt.Errorf("failed to type assert message %#v", msg) - } - switch r := resp.Response.(type) { - case *pb.SubscribeResponse_Update: - count++ - // The total updates received should be 4, 2 before sync, 2 after. - if count == 4 { - c.Close() - } - v := strings.Join(path.ToStrings(r.Update.Update[0].Path, false), "/") - ts := time.Unix(0, r.Update.GetTimestamp()) - if ts.Before(m[v]) { - t.Fatalf("#%d: got timestamp %s, want >= %s for value %q", count, ts, m[v], v) - } - m[v] = ts - case *pb.SubscribeResponse_Error: - return fmt.Errorf("error in response: %s", r) - case *pb.SubscribeResponse_SyncResponse: - if sync { - t.Fatal("received more than one sync message") - } - if count < 2 { - t.Fatalf("did not receive initial updates before sync, got %d, want > 2", count) - } - sync = true - // Send some updates after the sync occurred. - sendUpdates(t, cache, paths, ×tamp) - default: - return fmt.Errorf("unknown response %T: %s", r, r) - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - err = c.Subscribe(context.Background(), q, gnmiclient.Type) - if err != nil { - t.Error(err) - } - if !sync { - t.Error("streaming query did not send sync message") - } -} - -func TestStreamNewUpdates(t *testing.T) { - addr, cache, teardown, err := startServer([]string{"dev1", "dev2"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - paths := []client.Path{ - {"dev1", "e", "f"}, - {"dev2", "a", "b"}, - } - var timestamp time.Time - sendUpdates(t, cache, paths, ×tamp) - - newpaths := []client.Path{ - {"dev1", "b", "d"}, - {"dev2", "a", "x"}, - {"dev1", "a", "x"}, // The update we want to see. - } - - sync := false - c := client.BaseClient{} - q := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - NotificationHandler: func(n client.Notification) error { - switch u := n.(type) { - case client.Update: - v, want := strings.Join(u.Path, "/"), "dev1/a/x" - if v != want { - t.Fatalf("got update %q, want only %q", v, want) - } - c.Close() - case client.Sync: - if sync { - t.Fatal("received more than one sync message") - } - sync = true - // Stream new updates only after sync which should have had 0 - // updates. - sendUpdates(t, cache, newpaths, ×tamp) - case client.Connected: - default: - t.Fatalf("unexpected notification %#v", n) - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - err = c.Subscribe(context.Background(), q, gnmiclient.Type) - if err != nil { - t.Error(err) - } - if !sync { - t.Error("streaming query did not send sync message") - } -} - -func TestGNMIStreamNewUpdates(t *testing.T) { - cache.Type = cache.GnmiNoti - defer func() { - cache.Type = cache.ClientLeaf - }() - addr, cache, teardown, err := startServer([]string{"dev1", "dev2"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - paths := []client.Path{ - {"dev1", "e", "f"}, - {"dev2", "a", "b"}, - } - var timestamp time.Time - sendUpdates(t, cache, paths, ×tamp) - - newpaths := []client.Path{ - {"dev1", "b", "d"}, - {"dev2", "a", "x"}, - {"dev1", "a", "x"}, // The update we want to see. - } - - sync := false - c := client.BaseClient{} - q := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - ProtoHandler: func(msg proto.Message) error { - resp, ok := msg.(*pb.SubscribeResponse) - if !ok { - return fmt.Errorf("failed to type assert message %#v", msg) - } - switch r := resp.Response.(type) { - case *pb.SubscribeResponse_Update: - v, want := strings.Join(path.ToStrings(r.Update.Update[0].Path, false), "/"), "a/x" - if v != want { - t.Fatalf("got update %q, want only %q", v, want) - } - c.Close() - case *pb.SubscribeResponse_SyncResponse: - if sync { - t.Fatal("received more than one sync message") - } - sync = true - // Stream new updates only after sync which should have had 0 - // updates. - sendUpdates(t, cache, newpaths, ×tamp) - default: - return fmt.Errorf("unknown response %T: %s", r, r) - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - err = c.Subscribe(context.Background(), q, gnmiclient.Type) - if err != nil { - t.Error(err) - } - if !sync { - t.Error("streaming query did not send sync message") - } -} - -func TestUpdatesOnly(t *testing.T) { - addr, cache, teardown, err := startServer([]string{"dev1", "dev2"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - paths := []client.Path{ - {"dev1", "a", "b"}, - } - var timestamp time.Time - sendUpdates(t, cache, paths, ×tamp) - - sync := false - c := client.BaseClient{} - q := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - NotificationHandler: func(n client.Notification) error { - switch u := n.(type) { - case client.Update: - if !sync { - t.Errorf("got update %v before sync", u) - } - c.Close() - case client.Sync: - sync = true - sendUpdates(t, cache, paths, ×tamp) - case client.Connected: - default: - t.Fatalf("unexpected notification %#v", n) - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - UpdatesOnly: true, - } - err = c.Subscribe(context.Background(), q, gnmiclient.Type) - if err != nil { - t.Error(err) - } -} - -func TestGNMIUpdatesOnly(t *testing.T) { - cache.Type = cache.GnmiNoti - defer func() { - cache.Type = cache.ClientLeaf - }() - addr, cache, teardown, err := startServer([]string{"dev1", "dev2"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - paths := []client.Path{ - {"dev1", "a", "b"}, - } - var timestamp time.Time - sendUpdates(t, cache, paths, ×tamp) - - sync := false - c := client.BaseClient{} - q := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - ProtoHandler: func(msg proto.Message) error { - resp, ok := msg.(*pb.SubscribeResponse) - if !ok { - return fmt.Errorf("failed to type assert message %#v", msg) - } - switch r := resp.Response.(type) { - case *pb.SubscribeResponse_Update: - if !sync { - t.Errorf("got update %v before sync", r) - } - c.Close() - case *pb.SubscribeResponse_SyncResponse: - sync = true - sendUpdates(t, cache, paths, ×tamp) - default: - return fmt.Errorf("unknown response %T: %s", r, r) - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - UpdatesOnly: true, - } - err = c.Subscribe(context.Background(), q, gnmiclient.Type) - if err != nil { - t.Error(err) - } -} - -// If a client doesn't read any of the responses, it should not affect other -// clients querying the same target. -func TestSubscribeUnresponsiveClient(t *testing.T) { - addr, cache, teardown, err := startServer([]string{"dev1"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - paths := []client.Path{ - {"dev1", "a", "b"}, - {"dev1", "a", "c"}, - {"dev1", "e", "f"}, - } - sendUpdates(t, cache, paths, &time.Time{}) - - // Start the first client and do *not* read any responses. - started := make(chan struct{}) - stall := make(chan struct{}) - defer close(stall) - client1 := client.BaseClient{} - defer client1.Close() - q1 := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - NotificationHandler: func(n client.Notification) error { - select { - case <-started: - default: - close(started) - } - <-stall - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - ctx := context.Background() - go client1.Subscribe(ctx, q1, gnmiclient.Type) - // Wait for client1 to start. - <-started - - // Start the second client for the same target and actually accept - // responses. - count := 0 - client2 := client.BaseClient{} - q2 := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - NotificationHandler: func(n client.Notification) error { - switch n.(type) { - case client.Update: - count++ - case client.Sync: - client2.Close() - case client.Connected: - default: - t.Fatalf("unexpected notification %#v", n) - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - if err := client2.Subscribe(ctx, q2, gnmiclient.Type); err != nil { - t.Errorf("client2.Subscribe: %v", err) - } - if count != 2 { - t.Errorf("client2.Subscribe got %d updates, want 2", count) - } -} - -// If a client doesn't read any of the responses, it should not affect other -// clients querying the same target. -func TestGNMISubscribeUnresponsiveClient(t *testing.T) { - cache.Type = cache.GnmiNoti - defer func() { - cache.Type = cache.ClientLeaf - }() - addr, cache, teardown, err := startServer([]string{"dev1"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - paths := []client.Path{ - {"dev1", "a", "b"}, - {"dev1", "a", "c"}, - {"dev1", "e", "f"}, - } - sendUpdates(t, cache, paths, &time.Time{}) - - // Start the first client and do *not* read any responses. - started := make(chan struct{}) - stall := make(chan struct{}) - defer close(stall) - client1 := client.BaseClient{} - defer client1.Close() - q1 := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - ProtoHandler: func(msg proto.Message) error { - select { - case <-started: - default: - close(started) - } - <-stall - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - ctx := context.Background() - go client1.Subscribe(ctx, q1, gnmiclient.Type) - // Wait for client1 to start. - <-started - - // Start the second client for the same target and actually accept - // responses. - count := 0 - client2 := client.BaseClient{} - q2 := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - ProtoHandler: func(msg proto.Message) error { - resp, ok := msg.(*pb.SubscribeResponse) - if !ok { - return fmt.Errorf("failed to type assert message %#v", msg) - } - switch r := resp.Response.(type) { - case *pb.SubscribeResponse_Update: - count++ - case *pb.SubscribeResponse_SyncResponse: - client2.Close() - default: - return fmt.Errorf("unknown response %T: %s", r, r) - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - if err := client2.Subscribe(ctx, q2, gnmiclient.Type); err != nil { - t.Errorf("client2.Subscribe: %v", err) - } - if count != 2 { - t.Errorf("client2.Subscribe got %d updates, want 2", count) - } -} - -func TestDeletedTargetMessage(t *testing.T) { - addr, cache, teardown, err := startServer([]string{"dev1", "dev2"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - paths := []client.Path{ - {"dev1", "a", "b"}, - {"dev1", "a", "c"}, - {"dev1", "e", "f"}, - {"dev2", "a", "b"}, - } - sendUpdates(t, cache, paths, &time.Time{}) - - deleted := false - c := client.BaseClient{} - q := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - NotificationHandler: func(n client.Notification) error { - switch v := n.(type) { - case client.Update: - case client.Sync: - cache.Remove("dev1") - case client.Delete: - // Want to see a target delete message. No need to call c.Close() - // because the server should close the connection if the target is - // removed. - if len(v.Path) == 1 && v.Path[0] == "dev1" { - deleted = true - } - case client.Connected: - default: - t.Fatalf("unexpected notification %#v", n) - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - if err := c.Subscribe(context.Background(), q, gnmiclient.Type); err != nil { - t.Errorf("c.Subscribe: %v", err) - } - if !deleted { - t.Error("Target delete not sent.") - } -} - -func TestGNMIDeletedTargetMessage(t *testing.T) { - cache.Type = cache.GnmiNoti - defer func() { - cache.Type = cache.ClientLeaf - }() - addr, ch, teardown, err := startServer([]string{"dev1", "dev2"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - paths := []client.Path{ - {"dev1", "a", "b"}, - {"dev1", "a", "c"}, - {"dev1", "e", "f"}, - {"dev2", "a", "b"}, - } - sendUpdates(t, ch, paths, &time.Time{}) - - deleted := false - c := client.BaseClient{} - q := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - ProtoHandler: func(msg proto.Message) error { - resp, ok := msg.(*pb.SubscribeResponse) - if !ok { - return fmt.Errorf("failed to type assert message %#v", msg) - } - switch r := resp.Response.(type) { - case *pb.SubscribeResponse_Update: - if len(r.Update.Delete) > 0 { - // Want to see a target delete message. No need to call c.Close() - // because the server should close the connection if the target is - // removed. - if r.Update.Prefix.GetTarget() == "dev1" { - deleted = true - } - } - case *pb.SubscribeResponse_SyncResponse: - ch.Remove("dev1") - default: - return fmt.Errorf("unknown response %T: %s", r, r) - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - if err := c.Subscribe(context.Background(), q, gnmiclient.Type); err != nil { - t.Errorf("c.Subscribe: %v", err) - } - if !deleted { - t.Error("Target delete not sent.") - } -} - -func TestCoalescedDupCount(t *testing.T) { - // Inject a simulated flow control to block sends and induce coalescing. - flowControlTest = func() { time.Sleep(100 * time.Microsecond) } - addr, cache, teardown, err := startServer([]string{"dev1"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - stall := make(chan struct{}) - done := make(chan struct{}) - coalesced := uint32(0) - count := 0 - c := client.BaseClient{} - q := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - NotificationHandler: func(n client.Notification) error { - switch u := n.(type) { - case client.Update: - count++ - if u.Dups > 0 { - coalesced = u.Dups - } - switch count { - case 1: - close(stall) - case 2: - close(done) - } - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - go c.Subscribe(ctx, q, gnmiclient.Type) - - paths := []client.Path{ - {"dev1", "a"}, - {"dev1", "a"}, - {"dev1", "a"}, - {"dev1", "a"}, - {"dev1", "a"}, - } - var timestamp time.Time - sendUpdates(t, cache, paths[0:1], ×tamp) - <-stall - sendUpdates(t, cache, paths, ×tamp) - <-done - - if want := uint32(len(paths) - 1); coalesced != want { - t.Errorf("got coalesced count %d, want %d", coalesced, want) - } -} - -func TestGNMICoalescedDupCount(t *testing.T) { - cache.Type = cache.GnmiNoti - defer func() { - cache.Type = cache.ClientLeaf - }() - // Inject a simulated flow control to block sends and induce coalescing. - flowControlTest = func() { time.Sleep(100 * time.Microsecond) } - addr, cache, teardown, err := startServer([]string{"dev1"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - stall := make(chan struct{}) - done := make(chan struct{}) - coalesced := uint32(0) - count := 0 - c := client.BaseClient{} - q := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - ProtoHandler: func(msg proto.Message) error { - resp, ok := msg.(*pb.SubscribeResponse) - if !ok { - return fmt.Errorf("failed to type assert message %#v", msg) - } - switch r := resp.Response.(type) { - case *pb.SubscribeResponse_Update: - count++ - if r.Update.Update[0].GetDuplicates() > 0 { - coalesced = r.Update.Update[0].GetDuplicates() - } - switch count { - case 1: - close(stall) - case 2: - close(done) - } - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - go c.Subscribe(ctx, q, gnmiclient.Type) - - paths := []client.Path{ - {"dev1", "a"}, - {"dev1", "a"}, - {"dev1", "a"}, - {"dev1", "a"}, - {"dev1", "a"}, - } - var timestamp time.Time - sendUpdates(t, cache, paths[0:1], ×tamp) - <-stall - sendUpdates(t, cache, paths, ×tamp) - <-done - - if want := uint32(len(paths) - 1); coalesced != want { - t.Errorf("got coalesced count %d, want %d", coalesced, want) - } -} - -func TestSubscribeTimeout(t *testing.T) { - // Set a low timeout that is below the induced flowControl delay. - Timeout = 100 * time.Millisecond - // Cause query to hang indefinitely to induce timeout. - flowControlTest = func() { select {} } - // Reset the global variables so as not to interfere with other tests. - defer func() { - Timeout = time.Minute - flowControlTest = func() {} - }() - - addr, cache, teardown, err := startServer([]string{"dev1", "dev2"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - paths := []client.Path{ - {"dev1", "a", "b"}, - {"dev1", "a", "c"}, - {"dev1", "e", "f"}, - {"dev2", "a", "b"}, - } - sendUpdates(t, cache, paths, &time.Time{}) - - c := client.BaseClient{} - q := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - NotificationHandler: func(n client.Notification) error { - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - if err := c.Subscribe(context.Background(), q, gnmiclient.Type); err == nil { - t.Error("c.Subscribe got nil, wanted a timeout err") - } -} - -func TestGNMISubscribeTimeout(t *testing.T) { - cache.Type = cache.GnmiNoti - defer func() { - cache.Type = cache.ClientLeaf - }() - // Set a low timeout that is below the induced flowControl delay. - Timeout = 100 * time.Millisecond - // Cause query to hang indefinitely to induce timeout. - flowControlTest = func() { select {} } - // Reset the global variables so as not to interfere with other tests. - defer func() { - Timeout = time.Minute - flowControlTest = func() {} - }() - - addr, cache, teardown, err := startServer([]string{"dev1", "dev2"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - paths := []client.Path{ - {"dev1", "a", "b"}, - {"dev1", "a", "c"}, - {"dev1", "e", "f"}, - {"dev2", "a", "b"}, - } - sendUpdates(t, cache, paths, &time.Time{}) - - c := client.BaseClient{} - q := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - ProtoHandler: func(msg proto.Message) error { - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - if err := c.Subscribe(context.Background(), q, gnmiclient.Type); err == nil { - t.Error("c.Subscribe got nil, wanted a timeout err") - } -} - -func TestSubscriptionLimit(t *testing.T) { - totalQueries := 20 - SubscriptionLimit = 7 - causeLimit := make(chan struct{}) - subscriptionLimitTest = func() { - <-causeLimit - } - // Clear the global variables so as not to interfere with other tests. - defer func() { - SubscriptionLimit = 0 - subscriptionLimitTest = func() {} - }() - - addr, _, teardown, err := startServer([]string{"dev1", "dev2"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - fc := make(chan struct{}) - q := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - NotificationHandler: func(n client.Notification) error { - switch n.(type) { - case client.Sync: - fc <- struct{}{} - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - - // Launch parallel queries. - for i := 0; i < totalQueries; i++ { - c := client.BaseClient{} - go c.Subscribe(context.Background(), q, gnmiclient.Type) - } - - timeout := time.After(500 * time.Millisecond) - finished := 0 -firstQueries: - for { - select { - case <-fc: - finished++ - case <-timeout: - break firstQueries - } - } - if finished != SubscriptionLimit { - t.Fatalf("got %d finished queries, want %d", finished, SubscriptionLimit) - } - - close(causeLimit) - timeout = time.After(time.Second) -remainingQueries: - for { - select { - case <-fc: - if finished++; finished == totalQueries { - break remainingQueries - } - case <-timeout: - t.Errorf("Remaining queries did not proceed after limit removed. got %d, want %d", finished, totalQueries) - } - } -} - -func TestGNMISubscriptionLimit(t *testing.T) { - cache.Type = cache.GnmiNoti - defer func() { - cache.Type = cache.ClientLeaf - }() - totalQueries := 20 - SubscriptionLimit = 7 - causeLimit := make(chan struct{}) - subscriptionLimitTest = func() { - <-causeLimit - } - // Clear the global variables so as not to interfere with other tests. - defer func() { - SubscriptionLimit = 0 - subscriptionLimitTest = func() {} - }() - - addr, _, teardown, err := startServer([]string{"dev1", "dev2"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - - fc := make(chan struct{}) - q := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Once, - ProtoHandler: func(msg proto.Message) error { - resp, ok := msg.(*pb.SubscribeResponse) - if !ok { - return fmt.Errorf("failed to type assert message %#v", msg) - } - switch resp.Response.(type) { - case *pb.SubscribeResponse_SyncResponse: - fc <- struct{}{} - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - - // Launch parallel queries. - for i := 0; i < totalQueries; i++ { - c := client.BaseClient{} - go c.Subscribe(context.Background(), q, gnmiclient.Type) - } - - timeout := time.After(500 * time.Millisecond) - finished := 0 -firstQueries: - for { - select { - case <-fc: - finished++ - case <-timeout: - break firstQueries - } - } - if finished != SubscriptionLimit { - t.Fatalf("got %d finished queries, want %d", finished, SubscriptionLimit) - } - - close(causeLimit) - timeout = time.After(time.Second) -remainingQueries: - for { - select { - case <-fc: - if finished++; finished == totalQueries { - break remainingQueries - } - case <-timeout: - t.Errorf("Remaining queries did not proceed after limit removed. got %d, want %d", finished, totalQueries) - } - } -} - -func TestGNMIMultipleSubscriberCoalescion(t *testing.T) { - cache.Type = cache.GnmiNoti - defer func() { - cache.Type = cache.ClientLeaf - }() - // Inject a simulated flow control to block sends and induce coalescing. - flowControlTest = func() { time.Sleep(time.Second) } - addr, cache, teardown, err := startServer([]string{"dev1"}) - if err != nil { - t.Fatal(err) - } - defer teardown() - var wg sync.WaitGroup - sc := 5 - wg.Add(sc) - cr := make([]uint32, 0, sc) - var mux sync.Mutex - for i := 0; i < sc; i++ { - c := client.BaseClient{} - q := client.Query{ - Addrs: []string{addr}, - Target: "dev1", - Queries: []client.Path{{"a"}}, - Type: client.Stream, - ProtoHandler: func(msg proto.Message) error { - resp, ok := msg.(*pb.SubscribeResponse) - if !ok { - return fmt.Errorf("failed to type assert message %#v", msg) - } - switch r := resp.Response.(type) { - case *pb.SubscribeResponse_Update: - mux.Lock() - if r.Update.Update[0].GetDuplicates() > 0 { - cr = append(cr, r.Update.Update[0].GetDuplicates()) - } - mux.Unlock() - wg.Done() - } - return nil - }, - TLS: &tls.Config{InsecureSkipVerify: true}, - } - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - go c.Subscribe(ctx, q, gnmiclient.Type) - } - - paths := []client.Path{ - {"dev1", "a"}, - {"dev1", "a"}, - } - var timestamp time.Time - sendUpdates(t, cache, paths[0:1], ×tamp) - wg.Wait() - wg.Add(sc) - sendUpdates(t, cache, paths, ×tamp) - wg.Wait() - for i, d := range cr { - if d != uint32(len(paths)-1) { - t.Errorf("#%d got %d, expect %d duplicate count", i, d, uint32(len(paths)-1)) - } - } -} - -type fakeRPCACL struct { - user string - acl ACL -} - -func (r *fakeRPCACL) Check(dev string) bool { - return r.acl.Check(r.user, dev) -} - -type fakeACL struct { - allow int - deny int - check int -} -type fakeNet struct{} - -func (n *fakeNet) Network() string { - return "fake network" -} -func (n *fakeNet) String() string { - return "127.0.0.1" -} - -type userKey int - -var uk userKey - -func (a *fakeACL) NewRPCACL(ctx context.Context) (RPCACL, error) { - u, ok := ctx.Value(uk).(string) - if !ok { - return nil, errors.New("no user field in ctx") - } - r := &fakeRPCACL{user: u, acl: a} - return r, nil -} - -func (a *fakeACL) Check(user string, dev string) bool { - a.check++ - m := map[string]map[string]bool{ - "dev-pii": {"user1": true, "user2": false}, - "dev-no-pii": {"user1": true, "user2": true}, - } - if v, ok := m[dev]; ok { - if v2, ok := v[user]; ok { - if v2 { - a.allow++ - } else { - a.deny++ - } - return v2 - } - } - a.deny++ - return false -} - -type fakeSubServer struct { - user string - ctx context.Context - req chan *pb.SubscribeRequest - rsp chan *pb.SubscribeResponse - grpc.ServerStream -} - -func (s *fakeSubServer) Send(rsp *pb.SubscribeResponse) error { - select { - case <-s.ctx.Done(): - return io.ErrClosedPipe - default: - } - s.rsp <- rsp - return nil -} - -func (s *fakeSubServer) Recv() (*pb.SubscribeRequest, error) { - select { - case <-s.ctx.Done(): - return <-s.req, io.EOF - default: - } - return <-s.req, nil -} - -func (s *fakeSubServer) Context() context.Context { - return s.ctx -} - -func TestGNMIACL(t *testing.T) { - targets := []string{"dev-pii", "dev-no-pii"} - cache.Type = cache.GnmiNoti - defer func() { - cache.Type = cache.ClientLeaf - }() - c := cache.New(targets) - p, err := NewServer(c) - if err != nil { - t.Errorf("NewServer: %v", err) - return - } - paths := []client.Path{ - {"dev-pii", "a", "b"}, - {"dev-pii", "a", "c"}, - {"dev-no-pii", "e", "f"}, - {"dev-no-pii", "a", "b"}, - } - var timestamp time.Time - sendUpdates(t, c, paths, ×tamp) - tests := []struct { - name string - user string - dev string - mode pb.SubscriptionList_Mode - wantErr string - wantCnt *fakeACL - }{ - { - name: "user1 once with pii allow", - user: "user1", - dev: "dev-pii", - mode: pb.SubscriptionList_ONCE, - wantErr: "", - wantCnt: &fakeACL{allow: 3, deny: 0, check: 3}, - }, - { - name: "user2 once with pii deny", - user: "user2", - dev: "dev-pii", - mode: pb.SubscriptionList_ONCE, - wantErr: "rpc error: code = PermissionDenied desc = not authorized for target \"dev-pii\"", - wantCnt: &fakeACL{allow: 0, deny: 1, check: 1}, - }, - { - name: "user1 once all devices with pii allow", - user: "user1", - dev: "*", - mode: pb.SubscriptionList_ONCE, - wantErr: "", - wantCnt: &fakeACL{allow: 3, deny: 0, check: 3}, - }, - { - name: "user2 once all devices with pii deny", - user: "user2", - dev: "*", - mode: pb.SubscriptionList_ONCE, - wantErr: "", - wantCnt: &fakeACL{allow: 1, deny: 2, check: 3}, - }, - { - name: "user2 poll with pii deny", - user: "user2", - dev: "dev-pii", - mode: pb.SubscriptionList_POLL, - wantErr: "rpc error: code = PermissionDenied desc = not authorized for target \"dev-pii\"", - wantCnt: &fakeACL{allow: 0, deny: 1, check: 1}, - }, - { - name: "user2 stream with pii deny", - user: "user2", - dev: "dev-pii", - mode: pb.SubscriptionList_STREAM, - wantErr: "rpc error: code = PermissionDenied desc = not authorized for target \"dev-pii\"", - wantCnt: &fakeACL{allow: 0, deny: 1, check: 1}, - }, - } - - for _, test := range tests { - facl := &fakeACL{} - p.SetACL(facl) - var cancel context.CancelFunc - subSvr := &fakeSubServer{user: test.user, - req: make(chan *pb.SubscribeRequest, 2), - rsp: make(chan *pb.SubscribeResponse, len(paths)+1)} - ctx := peer.NewContext(context.Background(), &peer.Peer{Addr: &fakeNet{}}) - subSvr.ctx = context.WithValue(ctx, uk, test.user) - subSvr.ctx, cancel = context.WithCancel(subSvr.ctx) - subSvr.req <- &pb.SubscribeRequest{ - Request: &pb.SubscribeRequest_Subscribe{ - Subscribe: &pb.SubscriptionList{ - Prefix: &pb.Path{ - Target: test.dev, - }, - Subscription: []*pb.Subscription{ - &pb.Subscription{ - Path: &pb.Path{ - Element: []string{"a"}, - Elem: []*pb.PathElem{ - &pb.PathElem{ - Name: "a", - }, - }, - }, - }, - }, - Mode: test.mode, - }, - }, - } - - errCh := make(chan error) - go func() { - errCh <- p.Subscribe(subSvr) - }() - - select { - case err := <-errCh: - got := fmt.Sprint(err) - if diff := cmp.Diff(got, test.wantErr, cmpopts.EquateEmpty()); diff != "" { - t.Errorf("%v returned unexpected result:\n got %v\n want %v\n diff %v", test.name, got, test.wantErr, diff) - } - case <-time.After(5 * time.Second): - } - cancel() - - if diff := cmp.Diff(facl, test.wantCnt, cmpopts.EquateEmpty(), cmp.AllowUnexported(fakeACL{})); diff != "" { - t.Errorf("%v returned unexpected result:\n got %v\n want %v\n diff %v", test.name, facl, test.wantCnt, diff) - } - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/target/target.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/target/target.go deleted file mode 100644 index f3450bda3..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/target/target.go +++ /dev/null @@ -1,177 +0,0 @@ -/* -Copyright 2018 Google Inc. - -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 target has utility functions for working with target configuration -// proto messages in target.proto. -package target - -import ( - "errors" - "fmt" - "sync" - - "github.com/golang/protobuf/proto" - - gpb "github.com/openconfig/gnmi/proto/gnmi" - pb "github.com/openconfig/gnmi/proto/target" -) - -// Update describes a single target configuration. -type Update struct { - Name string - Request *gpb.SubscribeRequest - Target *pb.Target -} - -// Handler defines callbacks to be synchronously invoked in response to -// configuration changes. -type Handler struct { - // Add handles addition of a new target. - Add func(Update) - // Update handles target modification, including subscription request changes. - Update func(Update) - // Delete handles a target being removed. - Delete func(name string) -} - -// Config handles configuration file changes and contains configuration state. -type Config struct { - h Handler - mu sync.Mutex - configuration *pb.Configuration -} - -// NewConfig creates a new Config that can process configuration changes. -func NewConfig(h Handler) *Config { - return &Config{ - h: h, - } -} - -// Current returns a copy of the current configuration. -func (c *Config) Current() *pb.Configuration { - c.mu.Lock() - defer c.mu.Unlock() - return proto.Clone(c.configuration).(*pb.Configuration) -} - -// Load updates the current configuration and invokes Handler callbacks for -// detected changes. An error is returned when loading fails, or the new revision -// is not strictly increasing. -func (c *Config) Load(config *pb.Configuration) error { - if config == nil { - return fmt.Errorf("attempted to load nil configuration") - } - if err := Validate(config); err != nil { - return fmt.Errorf("invalid configuration: %v", err) - } - - c.mu.Lock() - defer c.mu.Unlock() - if err := c.checkRevision(config); err != nil { - return err - } - // Diff before setting new state. - c.handleDiffs(config) - c.configuration = config - - return nil -} - -func (c *Config) checkRevision(cf *pb.Configuration) error { - switch { - case c.configuration == nil: - return nil - case cf.Revision <= c.configuration.GetRevision(): - return fmt.Errorf("revision %v is not strictly greater than %v", cf.Revision, c.configuration.GetRevision()) - } - return nil -} - -// handleDiffs should be called while locking c. It performs a read-only diff on -// state in c against the new configuration. -func (c *Config) handleDiffs(config *pb.Configuration) { - requestChanged := map[string]bool{} - for k, new := range config.Request { - if old, ok := c.configuration.GetRequest()[k]; ok { - if !proto.Equal(old, new) { - requestChanged[k] = true - } - } - } - - // Make a copy of new targets so we can safely modify the map. - newTargets := make(map[string]*pb.Target) - for k, t := range config.GetTarget() { - newTargets[k] = t - } - - for k, t := range c.configuration.GetTarget() { - nt := newTargets[k] - switch { - case nt == nil: - if c.h.Delete != nil { - c.h.Delete(k) - } - case !requestChanged[t.GetRequest()] && proto.Equal(t, nt): - delete(newTargets, k) - default: - if c.h.Update != nil { - r := config.GetRequest()[nt.GetRequest()] - c.h.Update(Update{ - Name: k, - Request: r, - Target: nt, - }) - } - delete(newTargets, k) - } - } - - // Anything left in newTargets must be a new target. - for k, t := range newTargets { - r := config.GetRequest()[t.GetRequest()] - if c.h.Add != nil { - c.h.Add(Update{ - Name: k, - Request: r, - Target: t, - }) - } - } -} - -// Validate confirms that the configuration is valid. -func Validate(config *pb.Configuration) error { - for name, target := range config.Target { - if name == "" { - return errors.New("target with empty name") - } - if target == nil { - return fmt.Errorf("missing target configuration for %q", name) - } - if len(target.Addresses) == 0 { - return fmt.Errorf("target %q missing address", name) - } - if target.Request == "" { - return fmt.Errorf("target %q missing request", name) - } - if _, ok := config.Request[target.Request]; !ok { - return fmt.Errorf("missing request %q for target %q", target.Request, name) - } - } - return nil -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/target/target_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/target/target_test.go deleted file mode 100644 index d2e8d28b6..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/target/target_test.go +++ /dev/null @@ -1,433 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 target - -import ( - "reflect" - "sort" - "testing" - - "github.com/golang/protobuf/proto" - "github.com/google/go-cmp/cmp" - gpb "github.com/openconfig/gnmi/proto/gnmi" - pb "github.com/openconfig/gnmi/proto/target" -) - -type record struct { - adds []Update - updates []Update - deletes []string -} - -func (r *record) assertLast(t *testing.T, desc string, wantAdd, wantUpdate []Update, wantDelete []string) { - sort.Slice(r.adds, func(i int, j int) bool { return r.adds[i].Name < r.adds[j].Name }) - sort.Slice(r.updates, func(i int, j int) bool { return r.updates[i].Name < r.updates[j].Name }) - sort.Strings(r.deletes) - switch { - case !reflect.DeepEqual(r.adds, wantAdd): - t.Errorf("%v: Mismatched adds: got %v, want %+v", desc, r.adds, wantAdd) - case !reflect.DeepEqual(r.updates, wantUpdate): - t.Errorf("%v: Mismatched updates: got %v, want %+v", desc, r.updates, wantUpdate) - case !reflect.DeepEqual(r.deletes, wantDelete): - t.Errorf("%v: Mismatched deletes: got %v, want %v", desc, r.deletes, wantDelete) - } - r.adds = nil - r.updates = nil - r.deletes = nil -} - -func TestLoad(t *testing.T) { - for _, tt := range []struct { - desc string - initial *pb.Configuration - toLoad *pb.Configuration - wantAdd []string - wantUpdate []string - wantDelete []string - err bool - }{ - { - desc: "nil Config", - toLoad: nil, - err: true, - }, { - desc: "bad config", - toLoad: &pb.Configuration{ - Target: map[string]*pb.Target{ - "dev1": {}, - }, - Revision: 1, - }, - err: true, - }, { - desc: "old Config", - initial: &pb.Configuration{}, - toLoad: &pb.Configuration{ - Revision: -1, - }, - err: true, - }, { - desc: "add targets", - toLoad: &pb.Configuration{ - Request: map[string]*gpb.SubscribeRequest{ - "sub1": &gpb.SubscribeRequest{ - Request: &gpb.SubscribeRequest_Subscribe{}, - }, - }, - Target: map[string]*pb.Target{ - "dev1": { - Request: "sub1", - Addresses: []string{"11.111.111.11:11111"}, - }, - "dev2": { - Request: "sub1", - Addresses: []string{"11.111.111.11:11111"}, - }, - }, - Revision: 1, - }, - wantAdd: []string{"dev1", "dev2"}, - }, { - desc: "modify targets", - initial: &pb.Configuration{ - Request: map[string]*gpb.SubscribeRequest{ - "sub1": &gpb.SubscribeRequest{}, - }, - Target: map[string]*pb.Target{ - "dev1": { - Request: "sub1", - Addresses: []string{"11.111.111.11:11111"}, - }, - "dev3": { - Request: "sub1", - Addresses: []string{"33.333.333.33:33333"}, - }, - }, - Revision: 0, - }, - toLoad: &pb.Configuration{ - Request: map[string]*gpb.SubscribeRequest{ - "sub1": &gpb.SubscribeRequest{}, - }, - Target: map[string]*pb.Target{ - "dev1": { - Request: "sub1", - Addresses: []string{"11.111.111.11:11111", "12.111.111.11:11111"}, - }, - "dev2": { - Request: "sub1", - Addresses: []string{"22.222.222.22:22222"}, - }, - }, - Revision: 1, - }, - wantAdd: []string{"dev2"}, - wantUpdate: []string{"dev1"}, - wantDelete: []string{"dev3"}, - }, { - desc: "modify subscription", - initial: &pb.Configuration{ - Request: map[string]*gpb.SubscribeRequest{ - "sub1": &gpb.SubscribeRequest{}, - "sub3": &gpb.SubscribeRequest{}, - }, - Target: map[string]*pb.Target{ - "dev1": { - Request: "sub1", - Addresses: []string{"11.111.111.11:11111"}, - }, - "dev2": { - Request: "sub1", - Addresses: []string{"22.222.222.22:22222"}, - }, - "dev3": { - Request: "sub3", - Addresses: []string{"33.333.333.33:33333"}, - }, - }, - Revision: 0, - }, - toLoad: &pb.Configuration{ - Request: map[string]*gpb.SubscribeRequest{ - "sub1": &gpb.SubscribeRequest{ - Request: &gpb.SubscribeRequest_Subscribe{ - &gpb.SubscriptionList{ - Subscription: []*gpb.Subscription{ - { - Path: &gpb.Path{ - Elem: []*gpb.PathElem{{Name: "path2"}}, - }, - }, - }, - }, - }, - }, - "sub3": &gpb.SubscribeRequest{}, - }, - Target: map[string]*pb.Target{ - "dev1": { - Request: "sub1", - Addresses: []string{"11.111.111.11:11111"}, - }, - "dev2": { - Request: "sub1", - Addresses: []string{"22.222.222.22:22222"}, - }, - "dev3": { - Request: "sub3", - Addresses: []string{"33.333.333.33:33333"}, - }, - }, - Revision: 1, - }, - wantUpdate: []string{"dev1", "dev2"}, - }, { - desc: "modify subscription key", - initial: &pb.Configuration{ - Request: map[string]*gpb.SubscribeRequest{ - "sub1": &gpb.SubscribeRequest{ - Request: &gpb.SubscribeRequest_Subscribe{ - &gpb.SubscriptionList{ - Subscription: []*gpb.Subscription{ - { - Path: &gpb.Path{ - Elem: []*gpb.PathElem{{Name: "path2"}}, - }, - }, - }, - }, - }, - }, - "sub3": &gpb.SubscribeRequest{}, - }, - Target: map[string]*pb.Target{ - "dev1": { - Request: "sub1", - Addresses: []string{"11.111.111.11:11111"}, - }, - "dev2": { - Request: "sub1", - Addresses: []string{"22.222.222.22:22222"}, - }, - "dev3": { - Request: "sub3", - Addresses: []string{"33.333.333.33:33333"}, - }, - }, - Revision: 0, - }, - toLoad: &pb.Configuration{ - Request: map[string]*gpb.SubscribeRequest{ - "sub1": &gpb.SubscribeRequest{ - Request: &gpb.SubscribeRequest_Subscribe{ - &gpb.SubscriptionList{ - Subscription: []*gpb.Subscription{ - { - Path: &gpb.Path{ - Elem: []*gpb.PathElem{{Name: "path2"}}, - }, - }, - }, - }, - }, - }, - "sub3": &gpb.SubscribeRequest{}, - }, - Target: map[string]*pb.Target{ - "dev1": { - Request: "sub1", - Addresses: []string{"11.111.111.11:11111"}, - }, - "dev2": { - Request: "sub3", - Addresses: []string{"22.222.222.22:22222"}, - }, - "dev3": { - Request: "sub3", - Addresses: []string{"33.333.333.33:33333"}, - }, - }, - Revision: 1, - }, - wantUpdate: []string{"dev2"}, - }, - } { - r := &record{} - h := Handler{ - Add: func(c Update) { - r.adds = append(r.adds, Update{c.Name, c.Request, c.Target}) - }, - Update: func(c Update) { - r.updates = append(r.updates, Update{c.Name, c.Request, c.Target}) - }, - Delete: func(s string) { - r.deletes = append(r.deletes, s) - }, - } - c := NewConfig(h) - c.configuration = tt.initial - err := c.Load(tt.toLoad) - switch { - case err == nil && !tt.err: - if diff := cmp.Diff(tt.toLoad, c.Current(), cmp.Comparer(proto.Equal)); diff != "" { - t.Errorf("%v: wrong state: (-want +got)\n%s", tt.desc, diff) - } - updates := func(want []string, c *pb.Configuration) []Update { - if want == nil { - return nil - } - u := []Update{} - for _, n := range want { - ta := c.GetTarget()[n] - u = append(u, Update{ - Name: n, - Request: c.GetRequest()[ta.GetRequest()], - Target: ta, - }) - } - return u - } - r.assertLast(t, tt.desc, updates(tt.wantAdd, tt.toLoad), updates(tt.wantUpdate, tt.toLoad), tt.wantDelete) - case err == nil: - t.Errorf("%v: did not get expected error", tt.desc) - case !tt.err: - t.Errorf("%v: unexpected error %v", tt.desc, err) - } - } -} - -func TestValidate(t *testing.T) { - tests := []struct { - desc string - valid bool - config *pb.Configuration - }{{ - desc: "valid configuration with multiple targets", - valid: true, - config: &pb.Configuration{ - Request: map[string]*gpb.SubscribeRequest{ - "interfaces": &gpb.SubscribeRequest{}, - }, - Target: map[string]*pb.Target{ - "target1": &pb.Target{ - Addresses: []string{"192.168.0.10:10162"}, - Request: "interfaces", - }, - "target2": &pb.Target{ - Addresses: []string{"192.168.0.11:10162"}, - Request: "interfaces", - }, - }, - }, - }, { - desc: "empty configuration", - valid: true, - config: &pb.Configuration{}, - }, { - desc: "request but no targets", - valid: true, - config: &pb.Configuration{ - Request: map[string]*gpb.SubscribeRequest{ - "interfaces": &gpb.SubscribeRequest{}, - }, - }, - }, { - desc: "target with empty name", - valid: false, - config: &pb.Configuration{ - Request: map[string]*gpb.SubscribeRequest{ - "interfaces": &gpb.SubscribeRequest{}, - }, - Target: map[string]*pb.Target{ - "": &pb.Target{ - Addresses: []string{"192.168.0.10:10162"}, - Request: "interfaces", - }, - "target2": &pb.Target{ - Addresses: []string{"192.168.0.11:10162"}, - Request: "interfaces", - }, - }, - }, - }, { - desc: "missing target configuration", - valid: false, - config: &pb.Configuration{ - Request: map[string]*gpb.SubscribeRequest{ - "interfaces": &gpb.SubscribeRequest{}, - }, - Target: map[string]*pb.Target{ - "target1": nil, - "target2": &pb.Target{ - Addresses: []string{"192.168.0.11:10162"}, - Request: "interfaces", - }, - }, - }, - }, { - desc: "missing target address", - valid: false, - config: &pb.Configuration{ - Request: map[string]*gpb.SubscribeRequest{ - "interfaces": &gpb.SubscribeRequest{}, - }, - Target: map[string]*pb.Target{ - "target1": &pb.Target{ - Request: "interfaces", - }, - }, - }, - }, { - desc: "missing target request", - valid: false, - config: &pb.Configuration{ - Request: map[string]*gpb.SubscribeRequest{ - "interfaces": &gpb.SubscribeRequest{}, - }, - Target: map[string]*pb.Target{ - "target1": &pb.Target{ - Addresses: []string{"192.168.0.10:10162"}, - }, - }, - }, - }, { - desc: "invalid target request", - valid: false, - config: &pb.Configuration{ - Request: map[string]*gpb.SubscribeRequest{ - "interfaces": &gpb.SubscribeRequest{}, - }, - Target: map[string]*pb.Target{ - "target1": &pb.Target{ - Addresses: []string{"192.168.0.10:10162"}, - Request: "qos", - }, - }, - }, - }} - for _, test := range tests { - t.Run(test.desc, func(t *testing.T) { - err := Validate(test.config) - switch { - case test.valid && err != nil: - t.Errorf("got error %v, want nil for configuration: %s", err, test.config.String()) - case !test.valid && err == nil: - t.Errorf("got nit, want error for configuration: %s", test.config.String()) - } - }) - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/agent.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/agent.go deleted file mode 100644 index 1e80e93b9..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/agent.go +++ /dev/null @@ -1,173 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 gnmi implements a gRPC gNMI agent for testing against a -// collector implementation. Each agent will generate a set of Value protocol -// buffer messages that create a queue of updates to be streamed from a -// synthetic device. -package gnmi - -import ( - "errors" - "fmt" - "net" - "strings" - "sync" - - log "github.com/golang/glog" - "google.golang.org/grpc" - "google.golang.org/grpc/reflection" - "github.com/openconfig/gnmi/unimplemented" - - gnmipb "github.com/openconfig/gnmi/proto/gnmi" - fpb "github.com/openconfig/gnmi/testing/fake/proto" -) - -// Agent manages a single gNMI agent implementation. Each client that connects -// via Subscribe or Get will receive a stream of updates based on the requested -// path and the provided initial configuration. -type Agent struct { - unimplemented.Server - mu sync.Mutex - s *grpc.Server - lis net.Listener - target string - state fpb.State - config *fpb.Config - // cMu protects clients. - cMu sync.Mutex - clients map[string]*Client -} - -// New returns an initialized fake agent. -func New(config *fpb.Config, opts []grpc.ServerOption) (*Agent, error) { - if config == nil { - return nil, errors.New("config not provided") - } - s := grpc.NewServer(opts...) - reflection.Register(s) - - return NewFromServer(s, config) -} - -// NewFromServer returns a new initialized fake agent from provided server. -func NewFromServer(s *grpc.Server, config *fpb.Config) (*Agent, error) { - a := &Agent{ - s: s, - state: fpb.State_INIT, - config: config, - clients: map[string]*Client{}, - target: config.Target, - } - var err error - if a.config.Port < 0 { - a.config.Port = 0 - } - a.lis, err = net.Listen("tcp", fmt.Sprintf(":%d", a.config.Port)) - if err != nil { - return nil, fmt.Errorf("failed to open listener port %d: %v", a.config.Port, err) - } - gnmipb.RegisterGNMIServer(a.s, a) - log.V(1).Infof("Created Agent: %s on %s", a.target, a.Address()) - go a.serve() - return a, nil -} - -// serve will start the agent serving and block until closed. -func (a *Agent) serve() error { - a.mu.Lock() - a.state = fpb.State_RUNNING - s := a.s - a.mu.Unlock() - if s == nil { - return fmt.Errorf("Serve() failed: not initialized") - } - return a.s.Serve(a.lis) -} - -// Target returns the target name the agent is faking. -func (a *Agent) Target() string { - return a.target -} - -// Type returns the target type the agent is faking. -func (a *Agent) Type() string { - return a.config.ClientType.String() -} - -// Address returns the port the agent is listening to. -func (a *Agent) Address() string { - addr := a.lis.Addr().String() - return strings.Replace(addr, "[::]", "localhost", 1) -} - -// State returns the current state of the agent. -func (a *Agent) State() fpb.State { - a.mu.Lock() - defer a.mu.Unlock() - return a.state -} - -// Close shuts down the agent and closes all clients currently connected to the -// agent. -func (a *Agent) Close() { - a.mu.Lock() - defer a.mu.Unlock() - a.Clear() - a.state = fpb.State_STOPPED - if a.s == nil { - return - } - a.s.Stop() - a.lis.Close() - a.s = nil - a.lis = nil -} - -// Clear closes all currently connected clients of the agent. -func (a *Agent) Clear() { - a.cMu.Lock() - defer a.cMu.Unlock() - var wg sync.WaitGroup - for k, v := range a.clients { - log.V(1).Infof("Closing client: %s", k) - wg.Add(1) - go func(name string, c *Client) { - c.Close() - log.V(1).Infof("Client %s closed", name) - wg.Done() - }(k, v) - } - wg.Wait() - a.clients = map[string]*Client{} -} - -// Subscribe implements the gNMI Subscribe RPC. -func (a *Agent) Subscribe(stream gnmipb.GNMI_SubscribeServer) error { - c := NewClient(a.config) - - a.cMu.Lock() - a.clients[c.String()] = c - a.cMu.Unlock() - - err := c.Run(stream) - - a.cMu.Lock() - delete(a.clients, c.String()) - a.cMu.Unlock() - - return err -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/client.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/client.go deleted file mode 100644 index fadff602e..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/client.go +++ /dev/null @@ -1,321 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 gnmi - -import ( - "fmt" - "io" - "sync" - "time" - - log "github.com/golang/glog" - "github.com/kylelemons/godebug/pretty" - "google.golang.org/grpc/codes" - "google.golang.org/grpc" - "github.com/openconfig/gnmi/testing/fake/queue" - - gpb "github.com/openconfig/gnmi/proto/gnmi" - fpb "github.com/openconfig/gnmi/testing/fake/proto" -) - -// Client contains information about a client that has connected to the fake. -type Client struct { - sendMsg int64 - recvMsg int64 - errors int64 - cTime time.Time - cCount int64 - config *fpb.Config - polled chan struct{} - mu sync.RWMutex - canceled bool - q queue.Queue - subscribe *gpb.SubscriptionList -} - -// NewClient returns a new initialized client. -func NewClient(config *fpb.Config) *Client { - return &Client{ - config: config, - polled: make(chan struct{}), - } -} - -// String returns the target the client is querying. -func (c *Client) String() string { - return c.config.Target -} - -// Run starts the client. The first message received must be a -// SubscriptionList. Once the client is started, it will run until the stream -// is closed or the schedule completes. For Poll queries the Run will block -// internally after sync until a Poll request is made to the server. This is -// important as the test may look like a deadlock since it can cause a timeout. -// Also if you Reset the client the change will not take effect until after the -// previous queue has been drained of notifications. -func (c *Client) Run(stream gpb.GNMI_SubscribeServer) (err error) { - if c.config == nil { - return grpc.Errorf(codes.FailedPrecondition, "cannot start client: config is nil") - } - if stream == nil { - return grpc.Errorf(codes.FailedPrecondition, "cannot start client: stream is nil") - } - - defer func() { - if err != nil { - c.errors++ - } - }() - - query, err := stream.Recv() - c.cTime = time.Now() - c.cCount++ - c.recvMsg++ - if err != nil { - if err == io.EOF { - return grpc.Errorf(codes.Aborted, "stream EOF received before init") - } - return grpc.Errorf(grpc.Code(err), "received error from client") - } - log.V(1).Infof("Client %s recieved initial query: %v", c, query) - - c.subscribe = query.GetSubscribe() - if c.subscribe == nil { - return grpc.Errorf(codes.InvalidArgument, "first message must be SubscriptionList: %q", query) - } - // Initialize the queue used between send and recv. - if err = c.reset(); err != nil { - return grpc.Errorf(codes.Aborted, "failed to initialize the queue: %v", err) - } - - log.V(1).Infof("Client %s running", c) - go c.recv(stream) - c.send(stream) - log.V(1).Infof("Client %s shutdown", c) - return nil -} - -// Close will cancel the client context and will cause the send and recv goroutines to exit. -func (c *Client) Close() { - c.mu.Lock() - defer c.mu.Unlock() - c.canceled = true -} - -// Config returns the current config of the client. -func (c *Client) Config() *fpb.Config { - return c.config -} - -var syncResp = &gpb.SubscribeResponse{ - Response: &gpb.SubscribeResponse_SyncResponse{ - SyncResponse: true, - }, -} - -func (c *Client) recv(stream gpb.GNMI_SubscribeServer) { - for { - event, err := stream.Recv() - c.recvMsg++ - switch err { - default: - log.V(1).Infof("Client %s received error: %v", c, err) - c.Close() - return - case io.EOF: - log.V(1).Infof("Client %s received io.EOF", c) - return - case nil: - } - if c.subscribe.Mode == gpb.SubscriptionList_POLL { - log.V(1).Infof("Client %s received Poll event: %v", c, event) - if _, ok := event.Request.(*gpb.SubscribeRequest_Poll); !ok { - log.V(1).Infof("Client %s received invalid Poll event: %v", c, event) - c.Close() - return - } - if err = c.reset(); err != nil { - c.Close() - return - } - c.polled <- struct{}{} - continue - } - log.V(1).Infof("Client %s received invalid event: %s", c, event) - } -} - -// processQueue makes a copy of q then will process values in the queue until -// the queue is complete or an error. Each value is converted into a gNMI -// notification and sent on stream. -func (c *Client) processQueue(stream gpb.GNMI_SubscribeServer) error { - c.mu.RLock() - q := c.q - c.mu.RUnlock() - if q == nil { - return fmt.Errorf("nil client queue nothing to do") - } - for { - c.mu.RLock() - canceled := c.canceled - c.mu.RUnlock() - if canceled { - return fmt.Errorf("client canceled") - } - event, err := q.Next() - c.sendMsg++ - if err != nil { - c.errors++ - return fmt.Errorf("unexpected queue Next(): %v", err) - } - if event == nil { - switch { - case c.subscribe.Mode == gpb.SubscriptionList_POLL: - <-c.polled - log.V(1).Infof("Client %s received poll", c) - return nil - case c.config.DisableEof: - return fmt.Errorf("send exiting due to disabled EOF") - } - return fmt.Errorf("end of updates") - } - var resp *gpb.SubscribeResponse - switch v := event.(type) { - case *fpb.Value: - if resp, err = valToResp(v); err != nil { - c.errors++ - return err - } - case *gpb.SubscribeResponse: - resp = v - } - // If the subscription request specified a target explicitly... - if sp := c.subscribe.GetPrefix(); sp != nil { - if target := sp.Target; target != "" { - // and the message is an update... - if update := resp.GetUpdate(); update != nil { - // then set target in the prefix. - if update.Prefix == nil { - update.Prefix = &gpb.Path{} - } - update.Prefix.Target = target - } - } - } - log.V(1).Infof("Client %s sending:\n%v", c, resp) - err = stream.Send(resp) - if err != nil { - c.errors++ - return err - } - } -} - -// send runs until process Queue returns an error. Each loop is meant to allow -// for a reset of the sending queue based on query type. -func (c *Client) send(stream gpb.GNMI_SubscribeServer) { - for { - if err := c.processQueue(stream); err != nil { - log.Errorf("Client %s error: %v", c, err) - return - } - } -} - -// SetConfig will replace the current configuration of the Client. If the client -// is running then the change will not take effect until the queue is drained -// of notifications. -func (c *Client) SetConfig(config *fpb.Config) { - c.mu.Lock() - defer c.mu.Unlock() - c.config = config -} - -func (c *Client) reset() error { - c.mu.Lock() - defer c.mu.Unlock() - log.V(1).Infof("Client %s using config:\n%s", c, pretty.Sprint(c.config)) - switch { - default: - q := queue.New(c.config.GetEnableDelay(), c.config.Seed, c.config.Values) - // Inject sync message after latest provided update in the config. - if !c.config.DisableSync { - q.Add(&fpb.Value{ - Timestamp: &fpb.Timestamp{Timestamp: q.Latest()}, - Repeat: 1, - Value: &fpb.Value_Sync{uint64(1)}, - }) - } - c.q = q - case c.config.GetFixed() != nil: - q := queue.NewFixed(c.config.GetFixed().Responses, c.config.EnableDelay) - // Inject sync message after latest provided update in the config. - if !c.config.DisableSync { - q.Add(syncResp) - } - c.q = q - } - return nil -} - -// valToResp converts a fake_proto Value to its corresponding gNMI proto stream -// response type. -// fake_proto sync values are converted to gNMI subscribe responses containing -// SyncResponses. -// All other fake_proto values are assumed to be gNMI subscribe responses -// containing Updates. -func valToResp(val *fpb.Value) (*gpb.SubscribeResponse, error) { - switch val.GetValue().(type) { - case *fpb.Value_Delete: - return &gpb.SubscribeResponse{ - Response: &gpb.SubscribeResponse_Update{ - Update: &gpb.Notification{ - Timestamp: val.Timestamp.Timestamp, - Delete: []*gpb.Path{{Element: val.Path}}, - }, - }, - }, nil - case *fpb.Value_Sync: - var sync bool - if queue.ValueOf(val).(uint64) > 0 { - sync = true - } - return &gpb.SubscribeResponse{ - Response: &gpb.SubscribeResponse_SyncResponse{ - SyncResponse: sync, - }, - }, nil - default: - tv := queue.TypedValueOf(val) - if tv == nil { - return nil, fmt.Errorf("failed to get TypedValue of %s", val) - } - return &gpb.SubscribeResponse{ - Response: &gpb.SubscribeResponse_Update{ - Update: &gpb.Notification{ - Timestamp: val.Timestamp.Timestamp, - Update: []*gpb.Update{ - { - Path: &gpb.Path{Element: val.Path}, - Val: tv, - }, - }, - }, - }, - }, nil - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/cmd/fake_server/README.md b/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/cmd/fake_server/README.md deleted file mode 100644 index 074fef73f..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/cmd/fake_server/README.md +++ /dev/null @@ -1,30 +0,0 @@ -## Running the fake gNMI target - -First create a config file (text protobuf from `testing/fake/proto/fake.proto`). - -You can use a `gen_fake_config` tool in this repo (modify -`../gen_fake_config/gen_config.go` as needed and `go run -../gen_fake_config/gen_config.go`). - -Next, compile the server binary (`go build` or `go install`). - -Make sure you have TLS key pair for the server (a self-signed pair is fine). - -Finally, run: - -``` -$ fake_server --config config.pb.txt --text --port 8080 --server_crt --server_key --allow_no_client_auth --logtostderr -``` - -(replace binary and config paths as needed). - -If you wish to verify client TLS authentication, don't use -`--allow_no_client_auth` and set `--ca_crt` to CA certificate path. - -To verify your server is running, try: - -``` -$ gnmi_cli -a localhost:8080 -q '*' -logtostderr -insecure -qt s -``` - -Check the `./server --help` output for full flag set. diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/cmd/fake_server/example-config.pb.txt b/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/cmd/fake_server/example-config.pb.txt deleted file mode 100755 index d925a3361..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/cmd/fake_server/example-config.pb.txt +++ /dev/null @@ -1,2 +0,0 @@ -target: "insert-target-name-here" -client_type: GRPC_GNMI diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/cmd/fake_server/server.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/cmd/fake_server/server.go deleted file mode 100644 index f25cde4a6..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/cmd/fake_server/server.go +++ /dev/null @@ -1,120 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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. -*/ - -// The fake_server is a simple gRPC gnmi agent implementation which will take a -// configuration and start a listening service for the configured target. -package main - -import ( - "crypto/tls" - "crypto/x509" - "fmt" - "io/ioutil" - - "flag" - - log "github.com/golang/glog" - "github.com/golang/protobuf/proto" - "google.golang.org/grpc/credentials" - "google.golang.org/grpc" - "github.com/openconfig/gnmi/testing/fake/gnmi" - - fpb "github.com/openconfig/gnmi/testing/fake/proto" -) - -var ( - configFile = flag.String("config", "", "configuration file to load") - text = flag.Bool("text", false, "use text configuration file") - port = flag.Int("port", -1, "port to listen on") - // Certificate files. - caCert = flag.String("ca_crt", "", "CA certificate for client certificate validation. Optional.") - serverCert = flag.String("server_crt", "", "TLS server certificate") - serverKey = flag.String("server_key", "", "TLS server private key") - allowNoClientCert = flag.Bool("allow_no_client_auth", false, "When set, fake_server will request but not require a client certificate.") -) - -func loadConfig(fileName string) (*fpb.Config, error) { - in, err := ioutil.ReadFile(fileName) - if err != nil { - return nil, err - } - cfg := &fpb.Config{} - if *text { - if err := proto.UnmarshalText(string(in), cfg); err != nil { - return nil, fmt.Errorf("failed to parse text file %s: %v", fileName, err) - } - } else { - if err := proto.Unmarshal(in, cfg); err != nil { - return nil, fmt.Errorf("failed to parse %s: %v", fileName, err) - } - } - return cfg, nil -} - -func main() { - flag.Parse() - switch { - case *configFile == "": - log.Errorf("config must be set.") - return - case *port < 0: - log.Errorf("port must be >= 0.") - return - } - cfg, err := loadConfig(*configFile) - if err != nil { - log.Errorf("Failed to load %s: %v", *configFile, err) - return - } - - certificate, err := tls.LoadX509KeyPair(*serverCert, *serverKey) - if err != nil { - log.Exitf("could not load server key pair: %s", err) - } - tlsCfg := &tls.Config{ - ClientAuth: tls.RequireAndVerifyClientCert, - Certificates: []tls.Certificate{certificate}, - } - if *allowNoClientCert { - // RequestClientCert will ask client for a certificate but won't - // require it to proceed. If certificate is provided, it will be - // verified. - tlsCfg.ClientAuth = tls.RequestClientCert - } - - if *caCert != "" { - ca, err := ioutil.ReadFile(*caCert) - if err != nil { - log.Exitf("could not read CA certificate: %s", err) - } - certPool := x509.NewCertPool() - if ok := certPool.AppendCertsFromPEM(ca); !ok { - log.Exit("failed to append CA certificate") - } - tlsCfg.ClientCAs = certPool - } - - opts := []grpc.ServerOption{grpc.Creds(credentials.NewTLS(tlsCfg))} - cfg.Port = int32(*port) - a, err := gnmi.New(cfg, opts) - if err != nil { - log.Errorf("Failed to create gNMI server: %v", err) - return - } - - log.Infof("Starting RPC server on address: %s", a.Address()) - select {} // block forever -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/cmd/gen_fake_config/gen_config.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/cmd/gen_fake_config/gen_config.go deleted file mode 100644 index b44684897..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/cmd/gen_fake_config/gen_config.go +++ /dev/null @@ -1,63 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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. -*/ - -// The gen_fake_config command converts a hardcoded fake.proto message into a -// textual protobuf. The source code is intended to be modified manually to -// generate a valid text proto, instead of writing it by hand. -package main - -import ( - "io/ioutil" - "os" - - log "github.com/golang/glog" - "github.com/golang/protobuf/proto" - - fpb "github.com/openconfig/gnmi/testing/fake/proto" -) - -// Modify the config below to change generated output. -var ( - outputPath = "config.pb.txt" - - config = &fpb.Config{ - Target: "fake target name", - Seed: 12345, - Values: []*fpb.Value{ - { - Path: []string{"a", "b"}, - Repeat: 3, - Value: &fpb.Value_IntValue{&fpb.IntValue{Value: 4}}, - }, - { - Path: []string{"b", "c"}, - Repeat: 5, - Value: &fpb.Value_StringValue{&fpb.StringValue{Value: "foo"}}, - }, - }, - DisableSync: false, - DisableEof: false, - EnableDelay: false, - ClientType: fpb.Config_GRPC_GNMI, - } -) - -func main() { - out := proto.MarshalTextString(config) - if err := ioutil.WriteFile(outputPath, []byte(out), os.ModePerm); err != nil { - log.Exit(err) - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/gnmi_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/gnmi_test.go deleted file mode 100644 index 802681c86..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/gnmi/gnmi_test.go +++ /dev/null @@ -1,459 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 gnmi - -import ( - "golang.org/x/net/context" - "crypto/tls" - "errors" - "fmt" - "io" - "strings" - "sync" - "testing" - - "github.com/kylelemons/godebug/pretty" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/credentials" - "google.golang.org/grpc" - "github.com/openconfig/gnmi/testing/fake/testing/grpc/config" - - gnmipb "github.com/openconfig/gnmi/proto/gnmi" - fpb "github.com/openconfig/gnmi/testing/fake/proto" -) - -type direction string - -const ( - sendDirection direction = "Send" - recvDirection direction = "Recv" - noneDirection direction = "None" -) - -type event interface { - Direction() direction - String() string -} - -type cancelEvent struct { - d direction -} - -func (c *cancelEvent) String() string { return fmt.Sprintf("%s: Cancel Event", c.d) } -func (c *cancelEvent) Direction() direction { return c.d } - -type errorEvent struct { - d direction - err error -} - -func (e *errorEvent) String() string { - if e.err == nil { - return fmt.Sprintf("%s: no error", e.d) - } - return fmt.Sprintf("%s: %s", e.d, e.err.Error()) -} -func (e *errorEvent) Direction() direction { return e.d } - -type receiveEvent struct { - d direction - e *gnmipb.SubscribeRequest -} - -func (r *receiveEvent) String() string { return fmt.Sprintf("%s: Event\n%s", r.d, r.e) } -func (r *receiveEvent) Direction() direction { return r.d } - -type fakeStream struct { - grpc.ServerStream - curr int - events []event - recv []*gnmipb.SubscribeResponse - ctx context.Context - Cancel func() - rEvent chan event - sEvent chan event - mu sync.Mutex - synced int -} - -func newFakeStream(events []event) *fakeStream { - ctx, cancel := context.WithCancel(context.Background()) - f := &fakeStream{ - events: events, - ctx: ctx, - recv: []*gnmipb.SubscribeResponse{}, - Cancel: cancel, - rEvent: make(chan event), - sEvent: make(chan event), - } - go func() { - for _, e := range events { - switch e.Direction() { - default: - switch e.(type) { - case *cancelEvent: - f.Cancel() - return - } - case sendDirection: - f.sEvent <- e - case recvDirection: - f.rEvent <- e - } - } - f.Cancel() - }() - go func() { - <-f.ctx.Done() - close(f.sEvent) - close(f.rEvent) - }() - return f -} - -func (f *fakeStream) Send(resp *gnmipb.SubscribeResponse) (err error) { - if resp.GetSyncResponse() { - f.mu.Lock() - f.synced = 1 - f.mu.Unlock() - } - f.recv = append(f.recv, resp) - _, ok := <-f.sEvent - if !ok { - return io.EOF - } - return nil -} - -func (f *fakeStream) Recv() (resp *gnmipb.SubscribeRequest, err error) { - e, ok := <-f.rEvent - if !ok { - return nil, io.EOF - } - switch v := e.(type) { - default: - return nil, io.EOF - case *receiveEvent: - return v.e, nil - case *errorEvent: - return nil, v.err - } -} - -func (f *fakeStream) Context() context.Context { - return f.ctx -} - -func TestClientCreate(t *testing.T) { - defaultConfig := &fpb.Config{ - Target: "arista", - Port: -1, - Values: []*fpb.Value{{ - Path: []string{"interfaces", "interface[name=Port-Channel1]", "state", "counters", "in-octets"}, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 0, - Distribution: &fpb.IntValue_Range{ - &fpb.IntRange{ - Minimum: 0, - Maximum: 10000000, - DeltaMax: 100, - DeltaMin: 0, - }}}}, - }}, - } - tests := []struct { - config *fpb.Config - events []event - err codes.Code - }{{ - config: nil, - err: codes.FailedPrecondition, - }, { - config: defaultConfig, - err: codes.Aborted, - }, { - config: defaultConfig, - events: []event{ - &cancelEvent{d: "None"}, - }, - err: codes.Aborted, - }, { - config: defaultConfig, - events: []event{ - &receiveEvent{d: "Recv"}, - }, - err: codes.InvalidArgument, - }, { - config: defaultConfig, - events: []event{ - &receiveEvent{d: "Recv", e: &gnmipb.SubscribeRequest{ - Request: &gnmipb.SubscribeRequest_Subscribe{}, - }}, - &receiveEvent{d: "Recv"}, - }, - err: codes.InvalidArgument, - }, { - config: defaultConfig, - events: []event{ - &receiveEvent{d: "Recv", e: &gnmipb.SubscribeRequest{ - Request: &gnmipb.SubscribeRequest_Subscribe{ - Subscribe: &gnmipb.SubscriptionList{}, - }, - }}, - &receiveEvent{d: "Recv"}, - &errorEvent{d: "Recv", err: errors.New("cancelable error")}, - }, - err: codes.OK, - }, { - config: &fpb.Config{ - Target: "arista", - Port: -1, - Values: []*fpb.Value{{ - Path: []string{"interfaces", "interface[name=Port-Channel1]", "state", "counters", "in-octets"}, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 0, - Distribution: &fpb.IntValue_Range{ - &fpb.IntRange{ - Minimum: 0, - Maximum: 10000000, - DeltaMax: 100, - DeltaMin: 0, - }}}}, - Repeat: 2, - }}, - }, - events: []event{ - &receiveEvent{d: "Recv", e: &gnmipb.SubscribeRequest{ - Request: &gnmipb.SubscribeRequest_Subscribe{ - Subscribe: &gnmipb.SubscriptionList{}, - }, - }}, - &receiveEvent{d: "Recv"}, - &receiveEvent{d: "Recv"}, - }, - err: codes.OK, - }} - pp := pretty.Config{ - IncludeUnexported: true, - PrintStringers: true, - } - for i, tt := range tests { - t.Run(fmt.Sprintf("Test case %d", i+1), func(t *testing.T) { - c := NewClient(tt.config) - s := newFakeStream(tt.events) - gotErr := c.Run(s) - if gotErr != nil { - if got, want := grpc.Code(gotErr), tt.err; got != want { - t.Errorf("Test:\n%s\nRun() unexpected error %s: got %s, want %s", pp.Sprint(tt), gotErr.Error(), got, want) - } - return - } - if tt.err != codes.OK { - t.Errorf("Test:\n%s\nRun() expected error %s: got nil", pp.Sprint(tt), tt.err) - } - }) - } -} - -func festClientSend(t *testing.T) { - defaultConfig := &fpb.Config{ - Target: "arista", - Port: -1, - Values: []*fpb.Value{}, - } - tests := []struct { - config *fpb.Config - wantErr string - events []event - }{{ - config: defaultConfig, - wantErr: "invalid configuration", - events: []event{ - &receiveEvent{d: "Send"}, - }, - }, { - config: &fpb.Config{ - Target: "arista", - Port: -1, - Values: []*fpb.Value{{ - Path: []string{"interfaces", "interface[name=Port-Channel1]", "state", "counters", "in-octets"}, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 0, - Distribution: &fpb.IntValue_Range{ - &fpb.IntRange{ - Minimum: 0, - Maximum: 10000000, - DeltaMax: 100, - DeltaMin: 0, - }}}}, - Repeat: 2, - }}, - }, - events: []event{ - &receiveEvent{d: "Send"}, - &receiveEvent{d: "Send"}, - &receiveEvent{d: "Send"}, - }, - }} - pp := pretty.Config{ - IncludeUnexported: true, - PrintStringers: true, - } - for _, tt := range tests { - c := NewClient(tt.config) - s := newFakeStream(tt.events) - defer s.Cancel() - c.subscribe = &gnmipb.SubscriptionList{Mode: gnmipb.SubscriptionList_ONCE} - err := c.reset() - switch { - case err == nil && tt.wantErr != "": - t.Fatalf("reset() failed: got %v, want %v", err, tt.wantErr) - case err != nil && !strings.HasPrefix(err.Error(), tt.wantErr): - t.Fatalf("reset() failed: got %q, want %q", err, tt.wantErr) - } - c.send(s) - t.Logf("Received Events:\n%s\n", pp.Sprint(s.recv)) - if c.errors != 0 { - t.Fatalf("send(%s) errored", pp.Sprint(tt.events)) - } - s.mu.Lock() - synced := s.synced - s.mu.Unlock() - if synced == 0 { - t.Fatalf("send(%s) failed to sync stream", pp.Sprint(tt.events)) - } - } -} - -func TestNewAgent(t *testing.T) { - tests := []struct { - config *fpb.Config - err error - }{{ - config: nil, - err: fmt.Errorf("config not provided"), - }, { - config: &fpb.Config{}, - err: fmt.Errorf("config not provided"), - }, { - config: &fpb.Config{ - Target: "arista", - }, - err: nil, - }, { - config: &fpb.Config{ - Target: "arista", - Port: 0, - }, - err: nil, - }, { - config: &fpb.Config{ - Target: "arista", - Port: -1, - }, - err: nil, - }, { - config: &fpb.Config{ - Target: "arista", - Port: -1, - }, - err: nil, - }, { - config: &fpb.Config{ - Target: "arista", - Port: -1, - Values: []*fpb.Value{{ - Path: []string{"interfaces", "interface[name=Port-Channel1]", "state", "counters", "in-octets"}, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 0, - Distribution: &fpb.IntValue_Range{ - &fpb.IntRange{ - Minimum: 0, - Maximum: 10000000, - DeltaMax: 100, - DeltaMin: 0, - }}}}, - }}, - }, - err: nil, - }, { - config: &fpb.Config{ - Target: "arista", - Port: -1, - DisableSync: true, - Values: []*fpb.Value{{ - Path: []string{"interfaces", "interface[name=Port-Channel1]", "state", "counters", "in-octets"}, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 0, - Distribution: &fpb.IntValue_Range{ - &fpb.IntRange{ - Minimum: 0, - Maximum: 10000000, - DeltaMax: 100, - DeltaMin: 0, - }}}}, - }, { - Value: &fpb.Value_Sync{uint64(1)}, - }}, - }, - err: nil, - }} - certOpt, err := config.WithSelfTLSCert() - if err != nil { - t.Fatal(err) - } - for _, tc := range tests { - t.Run(fmt.Sprintf("Test case %+v", tc.config), func(t *testing.T) { - a, err := New(tc.config, []grpc.ServerOption{certOpt}) - if err != nil { - if tc.err == nil || tc.err.Error() != err.Error() { - t.Fatalf("New(%q) error return: got %v, want %v", tc.config, err, tc.err) - } - return - } - conn, err := grpc.Dial(a.Address(), grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{ - InsecureSkipVerify: true, - }))) - if err != nil { - t.Fatalf("New(%q) failed to dial server: %s", tc.config, err) - } - c := gnmipb.NewGNMIClient(conn) - s, err := c.Subscribe(context.Background()) - if err != nil { - t.Fatalf("New(%q).Subscribe() failed: %v", tc.config, err) - } - sub := &gnmipb.SubscribeRequest{ - Request: &gnmipb.SubscribeRequest_Subscribe{ - Subscribe: &gnmipb.SubscriptionList{}, - }, - } - if err := s.Send(sub); err != nil { - t.Fatalf("New(%q).Send(%q) failed: got %s", tc.config, sub, err) - } - if _, err = s.Recv(); err != nil { - t.Fatalf("New(%q).Recv() failed: got %s", tc.config, err) - } - if got, want := a.State(), fpb.State_RUNNING; got != want { - t.Errorf("New(%q).State() failed: got %q, want %q", tc.config, got, want) - } - a.Close() - if got, want := a.State(), fpb.State_STOPPED; got != want { - t.Errorf("New(%q).Close() failed: got %q, want %q", tc.config, got, want) - } - }) - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/proto/fake.pb.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/proto/fake.pb.go deleted file mode 100644 index 80570bd39..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/proto/fake.pb.go +++ /dev/null @@ -1,1514 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: testing/fake/proto/fake.proto - -package gnmi_fake - -import ( - fmt "fmt" - proto "github.com/golang/protobuf/proto" - any "github.com/golang/protobuf/ptypes/any" - gnmi "github.com/openconfig/gnmi/proto/gnmi" - math "math" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -type State int32 - -const ( - State_STOPPED State = 0 - State_INIT State = 1 - State_RUNNING State = 2 -) - -var State_name = map[int32]string{ - 0: "STOPPED", - 1: "INIT", - 2: "RUNNING", -} - -var State_value = map[string]int32{ - "STOPPED": 0, - "INIT": 1, - "RUNNING": 2, -} - -func (x State) String() string { - return proto.EnumName(State_name, int32(x)) -} - -func (State) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{0} -} - -type Config_ClientType int32 - -const ( - Config_GRPC Config_ClientType = 0 - Config_STUBBY Config_ClientType = 1 - Config_GRPC_GNMI Config_ClientType = 2 - Config_GRPC_GNMI_PROD Config_ClientType = 3 -) - -var Config_ClientType_name = map[int32]string{ - 0: "GRPC", - 1: "STUBBY", - 2: "GRPC_GNMI", - 3: "GRPC_GNMI_PROD", -} - -var Config_ClientType_value = map[string]int32{ - "GRPC": 0, - "STUBBY": 1, - "GRPC_GNMI": 2, - "GRPC_GNMI_PROD": 3, -} - -func (x Config_ClientType) String() string { - return proto.EnumName(Config_ClientType_name, int32(x)) -} - -func (Config_ClientType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{2, 0} -} - -// Configuration is used to store all agent configuration for the fake agent -// server. Each config describes a single agent hosted on the server. -type Configuration struct { - // Repeated list of targets to emulate. - Config []*Config `protobuf:"bytes,1,rep,name=config,proto3" json:"config,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Configuration) Reset() { *m = Configuration{} } -func (m *Configuration) String() string { return proto.CompactTextString(m) } -func (*Configuration) ProtoMessage() {} -func (*Configuration) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{0} -} - -func (m *Configuration) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Configuration.Unmarshal(m, b) -} -func (m *Configuration) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Configuration.Marshal(b, m, deterministic) -} -func (m *Configuration) XXX_Merge(src proto.Message) { - xxx_messageInfo_Configuration.Merge(m, src) -} -func (m *Configuration) XXX_Size() int { - return xxx_messageInfo_Configuration.Size(m) -} -func (m *Configuration) XXX_DiscardUnknown() { - xxx_messageInfo_Configuration.DiscardUnknown(m) -} - -var xxx_messageInfo_Configuration proto.InternalMessageInfo - -func (m *Configuration) GetConfig() []*Config { - if m != nil { - return m.Config - } - return nil -} - -type Credentials struct { - Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` - Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Credentials) Reset() { *m = Credentials{} } -func (m *Credentials) String() string { return proto.CompactTextString(m) } -func (*Credentials) ProtoMessage() {} -func (*Credentials) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{1} -} - -func (m *Credentials) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Credentials.Unmarshal(m, b) -} -func (m *Credentials) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Credentials.Marshal(b, m, deterministic) -} -func (m *Credentials) XXX_Merge(src proto.Message) { - xxx_messageInfo_Credentials.Merge(m, src) -} -func (m *Credentials) XXX_Size() int { - return xxx_messageInfo_Credentials.Size(m) -} -func (m *Credentials) XXX_DiscardUnknown() { - xxx_messageInfo_Credentials.DiscardUnknown(m) -} - -var xxx_messageInfo_Credentials proto.InternalMessageInfo - -func (m *Credentials) GetUsername() string { - if m != nil { - return m.Username - } - return "" -} - -func (m *Credentials) GetPassword() string { - if m != nil { - return m.Password - } - return "" -} - -// Config is a collection of values that together represent the update streams -// for one or more fake devices. -type Config struct { - // The target for which the fake will publish values for. - Target string `protobuf:"bytes,1,opt,name=target,proto3" json:"target,omitempty"` - // Port for the agent to listen on. If 0 or unset the agent will pick a port - // for this agent. - Port int32 `protobuf:"varint,2,opt,name=port,proto3" json:"port,omitempty"` - // A global random seed used in generating subsequent values. Set to have - // reproducible results. - Seed int64 `protobuf:"varint,6,opt,name=seed,proto3" json:"seed,omitempty"` // Deprecated: Do not use. - // The list of values generated. Each value will contain its corresponding - // target as the first string in the event.GetValue().path meaning that it is - // possible to generate streams that will be rejected by the cache for testing - // purposes. - Values []*Value `protobuf:"bytes,3,rep,name=values,proto3" json:"values,omitempty"` // Deprecated: Do not use. - // Setting disable sync will keep the configured client from autogenerating a - // sync message. This allows negative testing on sync handling. - DisableSync bool `protobuf:"varint,4,opt,name=disable_sync,json=disableSync,proto3" json:"disable_sync,omitempty"` - // Type of client to fake either Stubby or GRPC based fake. - ClientType Config_ClientType `protobuf:"varint,5,opt,name=client_type,json=clientType,proto3,enum=gnmi.fake.Config_ClientType" json:"client_type,omitempty"` - // Disable EOF will hold open the subscription and not automagically close - // the stream once the value queue is empty. - DisableEof bool `protobuf:"varint,7,opt,name=disable_eof,json=disableEof,proto3" json:"disable_eof,omitempty"` - // Per RPC credentials for the agent. If not set no per RPC auth will be used. - Credentials *Credentials `protobuf:"bytes,8,opt,name=credentials,proto3" json:"credentials,omitempty"` - // TLS cert for use on the agent. If not set the transport will not be TLS. - Cert []byte `protobuf:"bytes,9,opt,name=cert,proto3" json:"cert,omitempty"` - // Honor the delay between events in the generated value streams. Default will - // play events as fast as the can be streamed. - EnableDelay bool `protobuf:"varint,10,opt,name=enable_delay,json=enableDelay,proto3" json:"enable_delay,omitempty"` - // Generator for value series for the target. - // - // Types that are valid to be assigned to Generator: - // *Config_Custom - // *Config_Random - // *Config_Fixed - Generator isConfig_Generator `protobuf_oneof:"generator"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Config) Reset() { *m = Config{} } -func (m *Config) String() string { return proto.CompactTextString(m) } -func (*Config) ProtoMessage() {} -func (*Config) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{2} -} - -func (m *Config) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Config.Unmarshal(m, b) -} -func (m *Config) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Config.Marshal(b, m, deterministic) -} -func (m *Config) XXX_Merge(src proto.Message) { - xxx_messageInfo_Config.Merge(m, src) -} -func (m *Config) XXX_Size() int { - return xxx_messageInfo_Config.Size(m) -} -func (m *Config) XXX_DiscardUnknown() { - xxx_messageInfo_Config.DiscardUnknown(m) -} - -var xxx_messageInfo_Config proto.InternalMessageInfo - -func (m *Config) GetTarget() string { - if m != nil { - return m.Target - } - return "" -} - -func (m *Config) GetPort() int32 { - if m != nil { - return m.Port - } - return 0 -} - -// Deprecated: Do not use. -func (m *Config) GetSeed() int64 { - if m != nil { - return m.Seed - } - return 0 -} - -// Deprecated: Do not use. -func (m *Config) GetValues() []*Value { - if m != nil { - return m.Values - } - return nil -} - -func (m *Config) GetDisableSync() bool { - if m != nil { - return m.DisableSync - } - return false -} - -func (m *Config) GetClientType() Config_ClientType { - if m != nil { - return m.ClientType - } - return Config_GRPC -} - -func (m *Config) GetDisableEof() bool { - if m != nil { - return m.DisableEof - } - return false -} - -func (m *Config) GetCredentials() *Credentials { - if m != nil { - return m.Credentials - } - return nil -} - -func (m *Config) GetCert() []byte { - if m != nil { - return m.Cert - } - return nil -} - -func (m *Config) GetEnableDelay() bool { - if m != nil { - return m.EnableDelay - } - return false -} - -type isConfig_Generator interface { - isConfig_Generator() -} - -type Config_Custom struct { - Custom *any.Any `protobuf:"bytes,100,opt,name=custom,proto3,oneof"` -} - -type Config_Random struct { - Random *RandomGenerator `protobuf:"bytes,101,opt,name=random,proto3,oneof"` -} - -type Config_Fixed struct { - Fixed *FixedGenerator `protobuf:"bytes,102,opt,name=fixed,proto3,oneof"` -} - -func (*Config_Custom) isConfig_Generator() {} - -func (*Config_Random) isConfig_Generator() {} - -func (*Config_Fixed) isConfig_Generator() {} - -func (m *Config) GetGenerator() isConfig_Generator { - if m != nil { - return m.Generator - } - return nil -} - -func (m *Config) GetCustom() *any.Any { - if x, ok := m.GetGenerator().(*Config_Custom); ok { - return x.Custom - } - return nil -} - -func (m *Config) GetRandom() *RandomGenerator { - if x, ok := m.GetGenerator().(*Config_Random); ok { - return x.Random - } - return nil -} - -func (m *Config) GetFixed() *FixedGenerator { - if x, ok := m.GetGenerator().(*Config_Fixed); ok { - return x.Fixed - } - return nil -} - -// XXX_OneofWrappers is for the internal use of the proto package. -func (*Config) XXX_OneofWrappers() []interface{} { - return []interface{}{ - (*Config_Custom)(nil), - (*Config_Random)(nil), - (*Config_Fixed)(nil), - } -} - -type FixedGenerator struct { - Responses []*gnmi.SubscribeResponse `protobuf:"bytes,1,rep,name=responses,proto3" json:"responses,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *FixedGenerator) Reset() { *m = FixedGenerator{} } -func (m *FixedGenerator) String() string { return proto.CompactTextString(m) } -func (*FixedGenerator) ProtoMessage() {} -func (*FixedGenerator) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{3} -} - -func (m *FixedGenerator) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_FixedGenerator.Unmarshal(m, b) -} -func (m *FixedGenerator) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_FixedGenerator.Marshal(b, m, deterministic) -} -func (m *FixedGenerator) XXX_Merge(src proto.Message) { - xxx_messageInfo_FixedGenerator.Merge(m, src) -} -func (m *FixedGenerator) XXX_Size() int { - return xxx_messageInfo_FixedGenerator.Size(m) -} -func (m *FixedGenerator) XXX_DiscardUnknown() { - xxx_messageInfo_FixedGenerator.DiscardUnknown(m) -} - -var xxx_messageInfo_FixedGenerator proto.InternalMessageInfo - -func (m *FixedGenerator) GetResponses() []*gnmi.SubscribeResponse { - if m != nil { - return m.Responses - } - return nil -} - -type RandomGenerator struct { - Seed int64 `protobuf:"varint,1,opt,name=seed,proto3" json:"seed,omitempty"` - Values []*Value `protobuf:"bytes,2,rep,name=values,proto3" json:"values,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *RandomGenerator) Reset() { *m = RandomGenerator{} } -func (m *RandomGenerator) String() string { return proto.CompactTextString(m) } -func (*RandomGenerator) ProtoMessage() {} -func (*RandomGenerator) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{4} -} - -func (m *RandomGenerator) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_RandomGenerator.Unmarshal(m, b) -} -func (m *RandomGenerator) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_RandomGenerator.Marshal(b, m, deterministic) -} -func (m *RandomGenerator) XXX_Merge(src proto.Message) { - xxx_messageInfo_RandomGenerator.Merge(m, src) -} -func (m *RandomGenerator) XXX_Size() int { - return xxx_messageInfo_RandomGenerator.Size(m) -} -func (m *RandomGenerator) XXX_DiscardUnknown() { - xxx_messageInfo_RandomGenerator.DiscardUnknown(m) -} - -var xxx_messageInfo_RandomGenerator proto.InternalMessageInfo - -func (m *RandomGenerator) GetSeed() int64 { - if m != nil { - return m.Seed - } - return 0 -} - -func (m *RandomGenerator) GetValues() []*Value { - if m != nil { - return m.Values - } - return nil -} - -// Delete will cause the value to be deleted at the Value's path. -type DeleteValue struct { - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *DeleteValue) Reset() { *m = DeleteValue{} } -func (m *DeleteValue) String() string { return proto.CompactTextString(m) } -func (*DeleteValue) ProtoMessage() {} -func (*DeleteValue) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{5} -} - -func (m *DeleteValue) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_DeleteValue.Unmarshal(m, b) -} -func (m *DeleteValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_DeleteValue.Marshal(b, m, deterministic) -} -func (m *DeleteValue) XXX_Merge(src proto.Message) { - xxx_messageInfo_DeleteValue.Merge(m, src) -} -func (m *DeleteValue) XXX_Size() int { - return xxx_messageInfo_DeleteValue.Size(m) -} -func (m *DeleteValue) XXX_DiscardUnknown() { - xxx_messageInfo_DeleteValue.DiscardUnknown(m) -} - -var xxx_messageInfo_DeleteValue proto.InternalMessageInfo - -// Value is the main message that will trigger a stream of updates for a given -// path. A file containing a list of values can be used to simulate a network -// device for integration tests. -type Value struct { - // The device specific, or OpenConfig path corresponding to a value. - Path []string `protobuf:"bytes,1,rep,name=path,proto3" json:"path,omitempty"` - // The initial timestamp and configuration on how the timestamp will change - // for subsequent values. If timestamp is not set the default will assume to - // be the current system time. - Timestamp *Timestamp `protobuf:"bytes,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"` - // If set, repeat indicates that the value should be repeated this many times, - // otherwise it is repeated indefinitely. - Repeat int32 `protobuf:"varint,6,opt,name=repeat,proto3" json:"repeat,omitempty"` - // A local random seed used in generating subsequent values for this path. If - // not set, will share the global random source with seed defined in Config. - Seed int64 `protobuf:"varint,7,opt,name=seed,proto3" json:"seed,omitempty"` - // The initial value of the chosen type including configuration on how the - // value will mutate for subsequent updates. - // - // Types that are valid to be assigned to Value: - // *Value_IntValue - // *Value_DoubleValue - // *Value_StringValue - // *Value_Sync - // *Value_Delete - // *Value_BoolValue - Value isValue_Value `protobuf_oneof:"value"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Value) Reset() { *m = Value{} } -func (m *Value) String() string { return proto.CompactTextString(m) } -func (*Value) ProtoMessage() {} -func (*Value) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{6} -} - -func (m *Value) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Value.Unmarshal(m, b) -} -func (m *Value) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Value.Marshal(b, m, deterministic) -} -func (m *Value) XXX_Merge(src proto.Message) { - xxx_messageInfo_Value.Merge(m, src) -} -func (m *Value) XXX_Size() int { - return xxx_messageInfo_Value.Size(m) -} -func (m *Value) XXX_DiscardUnknown() { - xxx_messageInfo_Value.DiscardUnknown(m) -} - -var xxx_messageInfo_Value proto.InternalMessageInfo - -func (m *Value) GetPath() []string { - if m != nil { - return m.Path - } - return nil -} - -func (m *Value) GetTimestamp() *Timestamp { - if m != nil { - return m.Timestamp - } - return nil -} - -func (m *Value) GetRepeat() int32 { - if m != nil { - return m.Repeat - } - return 0 -} - -func (m *Value) GetSeed() int64 { - if m != nil { - return m.Seed - } - return 0 -} - -type isValue_Value interface { - isValue_Value() -} - -type Value_IntValue struct { - IntValue *IntValue `protobuf:"bytes,100,opt,name=int_value,json=intValue,proto3,oneof"` -} - -type Value_DoubleValue struct { - DoubleValue *DoubleValue `protobuf:"bytes,101,opt,name=double_value,json=doubleValue,proto3,oneof"` -} - -type Value_StringValue struct { - StringValue *StringValue `protobuf:"bytes,102,opt,name=string_value,json=stringValue,proto3,oneof"` -} - -type Value_Sync struct { - Sync uint64 `protobuf:"varint,103,opt,name=sync,proto3,oneof"` -} - -type Value_Delete struct { - Delete *DeleteValue `protobuf:"bytes,104,opt,name=delete,proto3,oneof"` -} - -type Value_BoolValue struct { - BoolValue *BoolValue `protobuf:"bytes,105,opt,name=bool_value,json=boolValue,proto3,oneof"` -} - -func (*Value_IntValue) isValue_Value() {} - -func (*Value_DoubleValue) isValue_Value() {} - -func (*Value_StringValue) isValue_Value() {} - -func (*Value_Sync) isValue_Value() {} - -func (*Value_Delete) isValue_Value() {} - -func (*Value_BoolValue) isValue_Value() {} - -func (m *Value) GetValue() isValue_Value { - if m != nil { - return m.Value - } - return nil -} - -func (m *Value) GetIntValue() *IntValue { - if x, ok := m.GetValue().(*Value_IntValue); ok { - return x.IntValue - } - return nil -} - -func (m *Value) GetDoubleValue() *DoubleValue { - if x, ok := m.GetValue().(*Value_DoubleValue); ok { - return x.DoubleValue - } - return nil -} - -func (m *Value) GetStringValue() *StringValue { - if x, ok := m.GetValue().(*Value_StringValue); ok { - return x.StringValue - } - return nil -} - -func (m *Value) GetSync() uint64 { - if x, ok := m.GetValue().(*Value_Sync); ok { - return x.Sync - } - return 0 -} - -func (m *Value) GetDelete() *DeleteValue { - if x, ok := m.GetValue().(*Value_Delete); ok { - return x.Delete - } - return nil -} - -func (m *Value) GetBoolValue() *BoolValue { - if x, ok := m.GetValue().(*Value_BoolValue); ok { - return x.BoolValue - } - return nil -} - -// XXX_OneofWrappers is for the internal use of the proto package. -func (*Value) XXX_OneofWrappers() []interface{} { - return []interface{}{ - (*Value_IntValue)(nil), - (*Value_DoubleValue)(nil), - (*Value_StringValue)(nil), - (*Value_Sync)(nil), - (*Value_Delete)(nil), - (*Value_BoolValue)(nil), - } -} - -type Timestamp struct { - // Initial timestamp for the corresponding value, nanoseconds since epoch. - // This value need have no relation to absolute real-time as the stream of - // of updates is generated without regard to the real clock and can be run - // repeatably at any time if the seed is set in the corresponding Value. - Timestamp int64 `protobuf:"varint,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` - // These values will vary the change in the timestamp for subsequent outputs - // by a value between delta_min and delta_max. Set to the same value to force - // a set periodic interval. - DeltaMin int64 `protobuf:"varint,2,opt,name=delta_min,json=deltaMin,proto3" json:"delta_min,omitempty"` - DeltaMax int64 `protobuf:"varint,3,opt,name=delta_max,json=deltaMax,proto3" json:"delta_max,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Timestamp) Reset() { *m = Timestamp{} } -func (m *Timestamp) String() string { return proto.CompactTextString(m) } -func (*Timestamp) ProtoMessage() {} -func (*Timestamp) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{7} -} - -func (m *Timestamp) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Timestamp.Unmarshal(m, b) -} -func (m *Timestamp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Timestamp.Marshal(b, m, deterministic) -} -func (m *Timestamp) XXX_Merge(src proto.Message) { - xxx_messageInfo_Timestamp.Merge(m, src) -} -func (m *Timestamp) XXX_Size() int { - return xxx_messageInfo_Timestamp.Size(m) -} -func (m *Timestamp) XXX_DiscardUnknown() { - xxx_messageInfo_Timestamp.DiscardUnknown(m) -} - -var xxx_messageInfo_Timestamp proto.InternalMessageInfo - -func (m *Timestamp) GetTimestamp() int64 { - if m != nil { - return m.Timestamp - } - return 0 -} - -func (m *Timestamp) GetDeltaMin() int64 { - if m != nil { - return m.DeltaMin - } - return 0 -} - -func (m *Timestamp) GetDeltaMax() int64 { - if m != nil { - return m.DeltaMax - } - return 0 -} - -type IntValue struct { - // If distribution is IntRange, value is used as the initial value - // inside [minimum, maximum] and hold the value as it mutates. - // If distribution is IntList, value is only used to hold the value as it - // mutates. - // If no distribution is set, value is used as it mutates, i.e. constant - // update. - Value int64 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"` - // Types that are valid to be assigned to Distribution: - // *IntValue_Range - // *IntValue_List - Distribution isIntValue_Distribution `protobuf_oneof:"distribution"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *IntValue) Reset() { *m = IntValue{} } -func (m *IntValue) String() string { return proto.CompactTextString(m) } -func (*IntValue) ProtoMessage() {} -func (*IntValue) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{8} -} - -func (m *IntValue) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_IntValue.Unmarshal(m, b) -} -func (m *IntValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_IntValue.Marshal(b, m, deterministic) -} -func (m *IntValue) XXX_Merge(src proto.Message) { - xxx_messageInfo_IntValue.Merge(m, src) -} -func (m *IntValue) XXX_Size() int { - return xxx_messageInfo_IntValue.Size(m) -} -func (m *IntValue) XXX_DiscardUnknown() { - xxx_messageInfo_IntValue.DiscardUnknown(m) -} - -var xxx_messageInfo_IntValue proto.InternalMessageInfo - -func (m *IntValue) GetValue() int64 { - if m != nil { - return m.Value - } - return 0 -} - -type isIntValue_Distribution interface { - isIntValue_Distribution() -} - -type IntValue_Range struct { - Range *IntRange `protobuf:"bytes,2,opt,name=range,proto3,oneof"` -} - -type IntValue_List struct { - List *IntList `protobuf:"bytes,3,opt,name=list,proto3,oneof"` -} - -func (*IntValue_Range) isIntValue_Distribution() {} - -func (*IntValue_List) isIntValue_Distribution() {} - -func (m *IntValue) GetDistribution() isIntValue_Distribution { - if m != nil { - return m.Distribution - } - return nil -} - -func (m *IntValue) GetRange() *IntRange { - if x, ok := m.GetDistribution().(*IntValue_Range); ok { - return x.Range - } - return nil -} - -func (m *IntValue) GetList() *IntList { - if x, ok := m.GetDistribution().(*IntValue_List); ok { - return x.List - } - return nil -} - -// XXX_OneofWrappers is for the internal use of the proto package. -func (*IntValue) XXX_OneofWrappers() []interface{} { - return []interface{}{ - (*IntValue_Range)(nil), - (*IntValue_List)(nil), - } -} - -type IntRange struct { - // The range of the value allowed. - Minimum int64 `protobuf:"varint,1,opt,name=minimum,proto3" json:"minimum,omitempty"` - Maximum int64 `protobuf:"varint,2,opt,name=maximum,proto3" json:"maximum,omitempty"` - // If set, the value is cumulative and the subsequent value is value + delta - // where delta is randomly chosen between delta_min and delta_max. The range - // minimum and maximum are still respected and values will saturate at the - // boundaries if they are exceeded. If not set subsequent value is a value - // randomly chosen between minimum and maximum. - DeltaMin int64 `protobuf:"varint,3,opt,name=delta_min,json=deltaMin,proto3" json:"delta_min,omitempty"` - DeltaMax int64 `protobuf:"varint,4,opt,name=delta_max,json=deltaMax,proto3" json:"delta_max,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *IntRange) Reset() { *m = IntRange{} } -func (m *IntRange) String() string { return proto.CompactTextString(m) } -func (*IntRange) ProtoMessage() {} -func (*IntRange) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{9} -} - -func (m *IntRange) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_IntRange.Unmarshal(m, b) -} -func (m *IntRange) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_IntRange.Marshal(b, m, deterministic) -} -func (m *IntRange) XXX_Merge(src proto.Message) { - xxx_messageInfo_IntRange.Merge(m, src) -} -func (m *IntRange) XXX_Size() int { - return xxx_messageInfo_IntRange.Size(m) -} -func (m *IntRange) XXX_DiscardUnknown() { - xxx_messageInfo_IntRange.DiscardUnknown(m) -} - -var xxx_messageInfo_IntRange proto.InternalMessageInfo - -func (m *IntRange) GetMinimum() int64 { - if m != nil { - return m.Minimum - } - return 0 -} - -func (m *IntRange) GetMaximum() int64 { - if m != nil { - return m.Maximum - } - return 0 -} - -func (m *IntRange) GetDeltaMin() int64 { - if m != nil { - return m.DeltaMin - } - return 0 -} - -func (m *IntRange) GetDeltaMax() int64 { - if m != nil { - return m.DeltaMax - } - return 0 -} - -type IntList struct { - // The set of values which can be used. - Options []int64 `protobuf:"varint,1,rep,packed,name=options,proto3" json:"options,omitempty"` - // Set to true to randomize selection of value from options. If false, the - // values are cycled in order, starting at index 0. - Random bool `protobuf:"varint,2,opt,name=random,proto3" json:"random,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *IntList) Reset() { *m = IntList{} } -func (m *IntList) String() string { return proto.CompactTextString(m) } -func (*IntList) ProtoMessage() {} -func (*IntList) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{10} -} - -func (m *IntList) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_IntList.Unmarshal(m, b) -} -func (m *IntList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_IntList.Marshal(b, m, deterministic) -} -func (m *IntList) XXX_Merge(src proto.Message) { - xxx_messageInfo_IntList.Merge(m, src) -} -func (m *IntList) XXX_Size() int { - return xxx_messageInfo_IntList.Size(m) -} -func (m *IntList) XXX_DiscardUnknown() { - xxx_messageInfo_IntList.DiscardUnknown(m) -} - -var xxx_messageInfo_IntList proto.InternalMessageInfo - -func (m *IntList) GetOptions() []int64 { - if m != nil { - return m.Options - } - return nil -} - -func (m *IntList) GetRandom() bool { - if m != nil { - return m.Random - } - return false -} - -type DoubleValue struct { - // If distribution is DoubleRange, value is used as the initial value - // inside [minimum, maximum] and hold the value as it mutates. - // If distribution is DoubleList, value is only used to hold the value as it - // mutates. - // If no distribution is set, value is used as it mutates, i.e. constant - // update. - Value float64 `protobuf:"fixed64,1,opt,name=value,proto3" json:"value,omitempty"` - // Types that are valid to be assigned to Distribution: - // *DoubleValue_Range - // *DoubleValue_List - Distribution isDoubleValue_Distribution `protobuf_oneof:"distribution"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *DoubleValue) Reset() { *m = DoubleValue{} } -func (m *DoubleValue) String() string { return proto.CompactTextString(m) } -func (*DoubleValue) ProtoMessage() {} -func (*DoubleValue) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{11} -} - -func (m *DoubleValue) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_DoubleValue.Unmarshal(m, b) -} -func (m *DoubleValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_DoubleValue.Marshal(b, m, deterministic) -} -func (m *DoubleValue) XXX_Merge(src proto.Message) { - xxx_messageInfo_DoubleValue.Merge(m, src) -} -func (m *DoubleValue) XXX_Size() int { - return xxx_messageInfo_DoubleValue.Size(m) -} -func (m *DoubleValue) XXX_DiscardUnknown() { - xxx_messageInfo_DoubleValue.DiscardUnknown(m) -} - -var xxx_messageInfo_DoubleValue proto.InternalMessageInfo - -func (m *DoubleValue) GetValue() float64 { - if m != nil { - return m.Value - } - return 0 -} - -type isDoubleValue_Distribution interface { - isDoubleValue_Distribution() -} - -type DoubleValue_Range struct { - Range *DoubleRange `protobuf:"bytes,2,opt,name=range,proto3,oneof"` -} - -type DoubleValue_List struct { - List *DoubleList `protobuf:"bytes,3,opt,name=list,proto3,oneof"` -} - -func (*DoubleValue_Range) isDoubleValue_Distribution() {} - -func (*DoubleValue_List) isDoubleValue_Distribution() {} - -func (m *DoubleValue) GetDistribution() isDoubleValue_Distribution { - if m != nil { - return m.Distribution - } - return nil -} - -func (m *DoubleValue) GetRange() *DoubleRange { - if x, ok := m.GetDistribution().(*DoubleValue_Range); ok { - return x.Range - } - return nil -} - -func (m *DoubleValue) GetList() *DoubleList { - if x, ok := m.GetDistribution().(*DoubleValue_List); ok { - return x.List - } - return nil -} - -// XXX_OneofWrappers is for the internal use of the proto package. -func (*DoubleValue) XXX_OneofWrappers() []interface{} { - return []interface{}{ - (*DoubleValue_Range)(nil), - (*DoubleValue_List)(nil), - } -} - -type DoubleRange struct { - // The range of the value allowed. - Minimum float64 `protobuf:"fixed64,1,opt,name=minimum,proto3" json:"minimum,omitempty"` - Maximum float64 `protobuf:"fixed64,2,opt,name=maximum,proto3" json:"maximum,omitempty"` - // If set, the value is cumulative and the subsequent value is value + delta - // where delta is randomly chosen between delta_min and delta_max. The range - // minimum and maximum are still respected. If not set subsequent value is a - // value randomly chosen between minimum and maximum. - DeltaMin float64 `protobuf:"fixed64,3,opt,name=delta_min,json=deltaMin,proto3" json:"delta_min,omitempty"` - DeltaMax float64 `protobuf:"fixed64,4,opt,name=delta_max,json=deltaMax,proto3" json:"delta_max,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *DoubleRange) Reset() { *m = DoubleRange{} } -func (m *DoubleRange) String() string { return proto.CompactTextString(m) } -func (*DoubleRange) ProtoMessage() {} -func (*DoubleRange) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{12} -} - -func (m *DoubleRange) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_DoubleRange.Unmarshal(m, b) -} -func (m *DoubleRange) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_DoubleRange.Marshal(b, m, deterministic) -} -func (m *DoubleRange) XXX_Merge(src proto.Message) { - xxx_messageInfo_DoubleRange.Merge(m, src) -} -func (m *DoubleRange) XXX_Size() int { - return xxx_messageInfo_DoubleRange.Size(m) -} -func (m *DoubleRange) XXX_DiscardUnknown() { - xxx_messageInfo_DoubleRange.DiscardUnknown(m) -} - -var xxx_messageInfo_DoubleRange proto.InternalMessageInfo - -func (m *DoubleRange) GetMinimum() float64 { - if m != nil { - return m.Minimum - } - return 0 -} - -func (m *DoubleRange) GetMaximum() float64 { - if m != nil { - return m.Maximum - } - return 0 -} - -func (m *DoubleRange) GetDeltaMin() float64 { - if m != nil { - return m.DeltaMin - } - return 0 -} - -func (m *DoubleRange) GetDeltaMax() float64 { - if m != nil { - return m.DeltaMax - } - return 0 -} - -type DoubleList struct { - // The set of values which can be used. - Options []float64 `protobuf:"fixed64,1,rep,packed,name=options,proto3" json:"options,omitempty"` - // Set to true to randomize selection of value from options. If false, the - // values are cycled in order. - Random bool `protobuf:"varint,2,opt,name=random,proto3" json:"random,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *DoubleList) Reset() { *m = DoubleList{} } -func (m *DoubleList) String() string { return proto.CompactTextString(m) } -func (*DoubleList) ProtoMessage() {} -func (*DoubleList) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{13} -} - -func (m *DoubleList) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_DoubleList.Unmarshal(m, b) -} -func (m *DoubleList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_DoubleList.Marshal(b, m, deterministic) -} -func (m *DoubleList) XXX_Merge(src proto.Message) { - xxx_messageInfo_DoubleList.Merge(m, src) -} -func (m *DoubleList) XXX_Size() int { - return xxx_messageInfo_DoubleList.Size(m) -} -func (m *DoubleList) XXX_DiscardUnknown() { - xxx_messageInfo_DoubleList.DiscardUnknown(m) -} - -var xxx_messageInfo_DoubleList proto.InternalMessageInfo - -func (m *DoubleList) GetOptions() []float64 { - if m != nil { - return m.Options - } - return nil -} - -func (m *DoubleList) GetRandom() bool { - if m != nil { - return m.Random - } - return false -} - -type StringValue struct { - // If distribution is StringList, value is used to hold the value as it - // mutates. - // If no distribution is set, value is used as it mutates, i.e. constant - // update. - Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` - // Types that are valid to be assigned to Distribution: - // *StringValue_List - Distribution isStringValue_Distribution `protobuf_oneof:"distribution"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *StringValue) Reset() { *m = StringValue{} } -func (m *StringValue) String() string { return proto.CompactTextString(m) } -func (*StringValue) ProtoMessage() {} -func (*StringValue) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{14} -} - -func (m *StringValue) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_StringValue.Unmarshal(m, b) -} -func (m *StringValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_StringValue.Marshal(b, m, deterministic) -} -func (m *StringValue) XXX_Merge(src proto.Message) { - xxx_messageInfo_StringValue.Merge(m, src) -} -func (m *StringValue) XXX_Size() int { - return xxx_messageInfo_StringValue.Size(m) -} -func (m *StringValue) XXX_DiscardUnknown() { - xxx_messageInfo_StringValue.DiscardUnknown(m) -} - -var xxx_messageInfo_StringValue proto.InternalMessageInfo - -func (m *StringValue) GetValue() string { - if m != nil { - return m.Value - } - return "" -} - -type isStringValue_Distribution interface { - isStringValue_Distribution() -} - -type StringValue_List struct { - List *StringList `protobuf:"bytes,2,opt,name=list,proto3,oneof"` -} - -func (*StringValue_List) isStringValue_Distribution() {} - -func (m *StringValue) GetDistribution() isStringValue_Distribution { - if m != nil { - return m.Distribution - } - return nil -} - -func (m *StringValue) GetList() *StringList { - if x, ok := m.GetDistribution().(*StringValue_List); ok { - return x.List - } - return nil -} - -// XXX_OneofWrappers is for the internal use of the proto package. -func (*StringValue) XXX_OneofWrappers() []interface{} { - return []interface{}{ - (*StringValue_List)(nil), - } -} - -type StringList struct { - // The set of strings which can be used. - Options []string `protobuf:"bytes,1,rep,name=options,proto3" json:"options,omitempty"` - // Set to true to randomize selection of value from options. If false, the - // values are cycled in order, starting at index 0. - Random bool `protobuf:"varint,2,opt,name=random,proto3" json:"random,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *StringList) Reset() { *m = StringList{} } -func (m *StringList) String() string { return proto.CompactTextString(m) } -func (*StringList) ProtoMessage() {} -func (*StringList) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{15} -} - -func (m *StringList) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_StringList.Unmarshal(m, b) -} -func (m *StringList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_StringList.Marshal(b, m, deterministic) -} -func (m *StringList) XXX_Merge(src proto.Message) { - xxx_messageInfo_StringList.Merge(m, src) -} -func (m *StringList) XXX_Size() int { - return xxx_messageInfo_StringList.Size(m) -} -func (m *StringList) XXX_DiscardUnknown() { - xxx_messageInfo_StringList.DiscardUnknown(m) -} - -var xxx_messageInfo_StringList proto.InternalMessageInfo - -func (m *StringList) GetOptions() []string { - if m != nil { - return m.Options - } - return nil -} - -func (m *StringList) GetRandom() bool { - if m != nil { - return m.Random - } - return false -} - -type BoolValue struct { - // If distribution is BoolList, value is only used to hold the value as it - // mutates. - // If no distribution is set, value is used as it mutates, i.e. constant - // update. - Value bool `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"` - // Types that are valid to be assigned to Distribution: - // *BoolValue_List - Distribution isBoolValue_Distribution `protobuf_oneof:"distribution"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *BoolValue) Reset() { *m = BoolValue{} } -func (m *BoolValue) String() string { return proto.CompactTextString(m) } -func (*BoolValue) ProtoMessage() {} -func (*BoolValue) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{16} -} - -func (m *BoolValue) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_BoolValue.Unmarshal(m, b) -} -func (m *BoolValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_BoolValue.Marshal(b, m, deterministic) -} -func (m *BoolValue) XXX_Merge(src proto.Message) { - xxx_messageInfo_BoolValue.Merge(m, src) -} -func (m *BoolValue) XXX_Size() int { - return xxx_messageInfo_BoolValue.Size(m) -} -func (m *BoolValue) XXX_DiscardUnknown() { - xxx_messageInfo_BoolValue.DiscardUnknown(m) -} - -var xxx_messageInfo_BoolValue proto.InternalMessageInfo - -func (m *BoolValue) GetValue() bool { - if m != nil { - return m.Value - } - return false -} - -type isBoolValue_Distribution interface { - isBoolValue_Distribution() -} - -type BoolValue_List struct { - List *BoolList `protobuf:"bytes,2,opt,name=list,proto3,oneof"` -} - -func (*BoolValue_List) isBoolValue_Distribution() {} - -func (m *BoolValue) GetDistribution() isBoolValue_Distribution { - if m != nil { - return m.Distribution - } - return nil -} - -func (m *BoolValue) GetList() *BoolList { - if x, ok := m.GetDistribution().(*BoolValue_List); ok { - return x.List - } - return nil -} - -// XXX_OneofWrappers is for the internal use of the proto package. -func (*BoolValue) XXX_OneofWrappers() []interface{} { - return []interface{}{ - (*BoolValue_List)(nil), - } -} - -type BoolList struct { - // The set of values which can be used. - Options []bool `protobuf:"varint,1,rep,packed,name=options,proto3" json:"options,omitempty"` - // Set to true to randomize selection of value from options. If false, the - // values are cycled in order, starting at index 0. - Random bool `protobuf:"varint,2,opt,name=random,proto3" json:"random,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *BoolList) Reset() { *m = BoolList{} } -func (m *BoolList) String() string { return proto.CompactTextString(m) } -func (*BoolList) ProtoMessage() {} -func (*BoolList) Descriptor() ([]byte, []int) { - return fileDescriptor_0c8aeeab0e585ec7, []int{17} -} - -func (m *BoolList) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_BoolList.Unmarshal(m, b) -} -func (m *BoolList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_BoolList.Marshal(b, m, deterministic) -} -func (m *BoolList) XXX_Merge(src proto.Message) { - xxx_messageInfo_BoolList.Merge(m, src) -} -func (m *BoolList) XXX_Size() int { - return xxx_messageInfo_BoolList.Size(m) -} -func (m *BoolList) XXX_DiscardUnknown() { - xxx_messageInfo_BoolList.DiscardUnknown(m) -} - -var xxx_messageInfo_BoolList proto.InternalMessageInfo - -func (m *BoolList) GetOptions() []bool { - if m != nil { - return m.Options - } - return nil -} - -func (m *BoolList) GetRandom() bool { - if m != nil { - return m.Random - } - return false -} - -func init() { - proto.RegisterEnum("gnmi.fake.State", State_name, State_value) - proto.RegisterEnum("gnmi.fake.Config_ClientType", Config_ClientType_name, Config_ClientType_value) - proto.RegisterType((*Configuration)(nil), "gnmi.fake.Configuration") - proto.RegisterType((*Credentials)(nil), "gnmi.fake.Credentials") - proto.RegisterType((*Config)(nil), "gnmi.fake.Config") - proto.RegisterType((*FixedGenerator)(nil), "gnmi.fake.FixedGenerator") - proto.RegisterType((*RandomGenerator)(nil), "gnmi.fake.RandomGenerator") - proto.RegisterType((*DeleteValue)(nil), "gnmi.fake.DeleteValue") - proto.RegisterType((*Value)(nil), "gnmi.fake.Value") - proto.RegisterType((*Timestamp)(nil), "gnmi.fake.Timestamp") - proto.RegisterType((*IntValue)(nil), "gnmi.fake.IntValue") - proto.RegisterType((*IntRange)(nil), "gnmi.fake.IntRange") - proto.RegisterType((*IntList)(nil), "gnmi.fake.IntList") - proto.RegisterType((*DoubleValue)(nil), "gnmi.fake.DoubleValue") - proto.RegisterType((*DoubleRange)(nil), "gnmi.fake.DoubleRange") - proto.RegisterType((*DoubleList)(nil), "gnmi.fake.DoubleList") - proto.RegisterType((*StringValue)(nil), "gnmi.fake.StringValue") - proto.RegisterType((*StringList)(nil), "gnmi.fake.StringList") - proto.RegisterType((*BoolValue)(nil), "gnmi.fake.BoolValue") - proto.RegisterType((*BoolList)(nil), "gnmi.fake.BoolList") -} - -func init() { proto.RegisterFile("testing/fake/proto/fake.proto", fileDescriptor_0c8aeeab0e585ec7) } - -var fileDescriptor_0c8aeeab0e585ec7 = []byte{ - // 1114 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x56, 0xdf, 0x6e, 0xe3, 0xc4, - 0x17, 0xae, 0xf3, 0xdf, 0xc7, 0x6d, 0x7f, 0xf9, 0xcd, 0x96, 0xe2, 0x2d, 0x8b, 0x08, 0xbe, 0xca, - 0x52, 0x94, 0x2e, 0x81, 0x95, 0x10, 0x0b, 0x2b, 0x35, 0x6d, 0x69, 0x2b, 0xd1, 0x3f, 0x9a, 0x74, - 0x91, 0x90, 0x90, 0xc2, 0x24, 0x9e, 0xb8, 0x16, 0xf1, 0x4c, 0x64, 0x4f, 0x96, 0x46, 0x3c, 0x00, - 0xb7, 0xdc, 0xf3, 0x14, 0x3c, 0x0f, 0x2f, 0x83, 0xe6, 0x78, 0x1c, 0x3b, 0xc9, 0x92, 0xee, 0xdd, - 0x9c, 0x73, 0xbe, 0x73, 0xe6, 0x9b, 0x6f, 0xbe, 0x89, 0x03, 0x1f, 0x2b, 0x9e, 0xa8, 0x50, 0x04, - 0x47, 0x63, 0xf6, 0x2b, 0x3f, 0x9a, 0xc6, 0x52, 0x49, 0x5c, 0x76, 0x70, 0x49, 0xec, 0x40, 0x44, - 0x61, 0x47, 0x27, 0x0e, 0x9e, 0x06, 0x52, 0x06, 0x13, 0x83, 0x19, 0xce, 0xc6, 0x47, 0x4c, 0xcc, - 0x53, 0xd4, 0xc1, 0x8b, 0x20, 0x54, 0xf7, 0xb3, 0x61, 0x67, 0x24, 0xa3, 0x23, 0x39, 0xe5, 0x62, - 0x24, 0xc5, 0x38, 0x0c, 0x8e, 0x74, 0xaf, 0x19, 0x89, 0x4b, 0x9c, 0x85, 0xb1, 0xf7, 0x0d, 0xec, - 0x9c, 0x20, 0x68, 0x16, 0x33, 0x15, 0x4a, 0x41, 0x9e, 0x43, 0x2d, 0xed, 0x72, 0xad, 0x56, 0xb9, - 0xed, 0x74, 0xff, 0xdf, 0x59, 0xec, 0xdc, 0x49, 0x91, 0xd4, 0x00, 0xbc, 0x33, 0x70, 0x4e, 0x62, - 0xee, 0x73, 0xa1, 0x42, 0x36, 0x49, 0xc8, 0x01, 0x34, 0x66, 0x09, 0x8f, 0x05, 0x8b, 0xb8, 0x6b, - 0xb5, 0xac, 0xb6, 0x4d, 0x17, 0xb1, 0xae, 0x4d, 0x59, 0x92, 0xfc, 0x26, 0x63, 0xdf, 0x2d, 0xa5, - 0xb5, 0x2c, 0xf6, 0xfe, 0xa9, 0x40, 0x2d, 0x9d, 0x4c, 0xf6, 0xa1, 0xa6, 0x58, 0x1c, 0x70, 0x65, - 0x06, 0x98, 0x88, 0x10, 0xa8, 0x4c, 0x65, 0xac, 0xb0, 0xb5, 0x4a, 0x71, 0x4d, 0xf6, 0xa1, 0x92, - 0x70, 0xee, 0xbb, 0xb5, 0x96, 0xd5, 0x2e, 0xf7, 0x4a, 0xae, 0x45, 0x31, 0x26, 0x9f, 0x43, 0xed, - 0x2d, 0x9b, 0xcc, 0x78, 0xe2, 0x96, 0xf1, 0x00, 0xcd, 0xc2, 0x01, 0x7e, 0xd4, 0x05, 0xc4, 0x1a, - 0x0c, 0xf9, 0x14, 0xb6, 0xfd, 0x30, 0x61, 0xc3, 0x09, 0x1f, 0x24, 0x73, 0x31, 0x72, 0x2b, 0x2d, - 0xab, 0xdd, 0xa0, 0x8e, 0xc9, 0xf5, 0xe7, 0x62, 0x44, 0xbe, 0x03, 0x67, 0x34, 0x09, 0xb9, 0x50, - 0x03, 0x35, 0x9f, 0x72, 0xb7, 0xda, 0xb2, 0xda, 0xbb, 0xdd, 0x67, 0x6b, 0xb2, 0x74, 0x4e, 0x10, - 0x74, 0x37, 0x9f, 0x72, 0x0a, 0xa3, 0xc5, 0x9a, 0x7c, 0x02, 0xd9, 0xb4, 0x01, 0x97, 0x63, 0xb7, - 0x8e, 0x1b, 0x80, 0x49, 0x9d, 0xc9, 0x31, 0xf9, 0x1a, 0x9c, 0x51, 0x2e, 0xa3, 0xdb, 0x68, 0x59, - 0x6d, 0xa7, 0xbb, 0x5f, 0x9c, 0x9f, 0x57, 0x69, 0x11, 0xaa, 0x65, 0x19, 0xf1, 0x58, 0xb9, 0x76, - 0xcb, 0x6a, 0x6f, 0x53, 0x5c, 0xeb, 0x03, 0x71, 0x81, 0xbb, 0xf9, 0x7c, 0xc2, 0xe6, 0x2e, 0xa4, - 0x07, 0x4a, 0x73, 0xa7, 0x3a, 0x45, 0x3a, 0x50, 0x1b, 0xcd, 0x12, 0x25, 0x23, 0xd7, 0xc7, 0xbd, - 0xf6, 0x3a, 0xa9, 0xa3, 0x3a, 0x99, 0xa3, 0x3a, 0xc7, 0x62, 0x7e, 0xb1, 0x45, 0x0d, 0x8a, 0x7c, - 0x05, 0xb5, 0x98, 0x09, 0x5f, 0x46, 0x2e, 0x47, 0xfc, 0x41, 0x81, 0x1b, 0xc5, 0xc2, 0x39, 0x17, - 0x3c, 0x66, 0x4a, 0xc6, 0xba, 0x2b, 0xc5, 0x92, 0x2f, 0xa0, 0x3a, 0x0e, 0x1f, 0xb8, 0xef, 0x8e, - 0xb1, 0xe9, 0x69, 0xa1, 0xe9, 0x7b, 0x9d, 0x2f, 0xf6, 0xa4, 0x48, 0xef, 0x0c, 0x20, 0x17, 0x91, - 0x34, 0xa0, 0x72, 0x4e, 0x6f, 0x4f, 0x9a, 0x5b, 0x04, 0xa0, 0xd6, 0xbf, 0x7b, 0xd3, 0xeb, 0xfd, - 0xd4, 0xb4, 0xc8, 0x0e, 0xd8, 0x3a, 0x3b, 0x38, 0xbf, 0xbe, 0xba, 0x6c, 0x96, 0x08, 0x81, 0xdd, - 0x45, 0x38, 0xb8, 0xa5, 0x37, 0xa7, 0xcd, 0x72, 0xcf, 0x01, 0x3b, 0xc8, 0x86, 0x7b, 0xe7, 0xb0, - 0xbb, 0xbc, 0x1d, 0x79, 0x09, 0x76, 0xcc, 0x93, 0xa9, 0x14, 0x09, 0x4f, 0x8c, 0xc9, 0x3f, 0x4c, - 0xc9, 0xf5, 0x67, 0xc3, 0x64, 0x14, 0x87, 0x43, 0x4e, 0x4d, 0x9d, 0xe6, 0x48, 0xef, 0x06, 0xfe, - 0xb7, 0x72, 0x58, 0xad, 0x3f, 0x5a, 0x50, 0x9b, 0xb5, 0x6c, 0xec, 0xd7, 0x5e, 0xd8, 0xaf, 0xf4, - 0x6e, 0xfb, 0x65, 0xd6, 0xf3, 0x76, 0xc0, 0x39, 0xe5, 0x13, 0xae, 0x38, 0xa6, 0xbd, 0xbf, 0xcb, - 0x50, 0xc5, 0x15, 0xba, 0x9d, 0xa9, 0x7b, 0xe4, 0x66, 0x53, 0x5c, 0x93, 0x2e, 0xd8, 0x2a, 0x8c, - 0x78, 0xa2, 0x58, 0x34, 0xc5, 0x67, 0x80, 0xd7, 0xb6, 0x98, 0x7c, 0x97, 0xd5, 0x68, 0x0e, 0xd3, - 0xaf, 0x29, 0xe6, 0x53, 0xce, 0x14, 0xbe, 0x91, 0x2a, 0x35, 0xd1, 0x82, 0x76, 0xbd, 0x40, 0xbb, - 0x0b, 0x76, 0x28, 0xd4, 0x00, 0xa9, 0x19, 0x5b, 0x3c, 0x29, 0xcc, 0xbf, 0x14, 0x0a, 0xb9, 0x5d, - 0x6c, 0xd1, 0x46, 0x68, 0xd6, 0xe4, 0x15, 0x6c, 0xfb, 0x72, 0xa6, 0xad, 0x96, 0xb6, 0xf1, 0x35, - 0xe7, 0x9e, 0x62, 0x39, 0xeb, 0x74, 0xfc, 0x3c, 0xd4, 0xcd, 0x89, 0x8a, 0x43, 0x11, 0x98, 0xe6, - 0xf1, 0x5a, 0x73, 0x1f, 0xcb, 0x8b, 0xe6, 0x24, 0x0f, 0xc9, 0x1e, 0x54, 0xf0, 0xb5, 0x06, 0x2d, - 0xab, 0x5d, 0xb9, 0xd8, 0xa2, 0x18, 0x91, 0x17, 0x50, 0xf3, 0x51, 0x50, 0xf7, 0x7e, 0x9d, 0x49, - 0xae, 0xb4, 0xf6, 0x68, 0x8a, 0x23, 0x2f, 0x01, 0x86, 0x52, 0x4e, 0x0c, 0x85, 0x70, 0x4d, 0xd6, - 0x9e, 0x94, 0x93, 0xac, 0xc7, 0x1e, 0x66, 0x41, 0xaf, 0x0e, 0x55, 0xec, 0xf0, 0x46, 0x60, 0x2f, - 0x94, 0x27, 0xcf, 0x8a, 0x57, 0x94, 0x5a, 0xa2, 0x70, 0x19, 0x1f, 0x81, 0xed, 0xf3, 0x89, 0x62, - 0x83, 0x28, 0x14, 0x78, 0x81, 0x65, 0xda, 0xc0, 0xc4, 0x55, 0x28, 0x0a, 0x45, 0xf6, 0xe0, 0x96, - 0x8b, 0x45, 0xf6, 0xe0, 0xfd, 0x61, 0x41, 0x23, 0xd3, 0x9f, 0xec, 0x99, 0xad, 0xcd, 0x06, 0x69, - 0x40, 0x0e, 0xa1, 0x1a, 0x33, 0x11, 0x70, 0xe3, 0x8c, 0x95, 0x9b, 0xa3, 0xba, 0xa4, 0x5f, 0x19, - 0x62, 0x48, 0x1b, 0x2a, 0x93, 0x30, 0x51, 0xb8, 0x8f, 0xd3, 0x25, 0xcb, 0xd8, 0x1f, 0xc2, 0x44, - 0x69, 0x41, 0x35, 0xa2, 0xb7, 0x8b, 0x3f, 0x8e, 0x2a, 0x0e, 0x87, 0x33, 0xfd, 0x6d, 0xf0, 0x1e, - 0x90, 0x08, 0x8e, 0x23, 0x2e, 0xd4, 0xa3, 0x50, 0x84, 0xd1, 0x2c, 0x32, 0x54, 0xb2, 0x10, 0x2b, - 0xec, 0x01, 0x2b, 0x25, 0x53, 0x49, 0xc3, 0x65, 0x0d, 0xca, 0x9b, 0x34, 0xa8, 0xac, 0x68, 0xf0, - 0x0a, 0xea, 0x86, 0x9c, 0x1e, 0x2f, 0xa7, 0x9a, 0x4e, 0xfa, 0x78, 0xcb, 0x34, 0x0b, 0xd1, 0xef, - 0xe9, 0xef, 0x54, 0x09, 0x7f, 0xf4, 0x4c, 0xe4, 0xfd, 0x69, 0x81, 0x53, 0x70, 0xe2, 0xb2, 0x86, - 0x56, 0xa6, 0x61, 0x67, 0x59, 0xc3, 0x75, 0x1b, 0xaf, 0xc8, 0x78, 0xb8, 0x24, 0xe3, 0x07, 0x6b, - 0xf0, 0x8d, 0x4a, 0xfe, 0x9e, 0x31, 0x7a, 0xa7, 0x98, 0xd6, 0x7f, 0x8a, 0x69, 0x6d, 0x10, 0xd3, - 0xda, 0x24, 0xa6, 0x55, 0x10, 0xf3, 0x35, 0x40, 0x4e, 0x71, 0x55, 0x4f, 0xeb, 0x71, 0x3d, 0x7f, - 0x01, 0xa7, 0xbf, 0xf4, 0x18, 0x0b, 0x72, 0xda, 0xb9, 0x25, 0x53, 0x79, 0x4a, 0x6b, 0xf2, 0xa4, - 0xbd, 0x1b, 0xe5, 0x79, 0x0d, 0x90, 0xa3, 0x56, 0x19, 0xda, 0x8f, 0x33, 0xfc, 0x19, 0xec, 0xc5, - 0xd3, 0x5d, 0xe6, 0xd7, 0xc8, 0xf8, 0x3d, 0x5f, 0xe2, 0xf7, 0x64, 0xe5, 0xd1, 0x6f, 0x64, 0xf7, - 0x2d, 0x34, 0x32, 0xcc, 0x2a, 0xb7, 0xc6, 0xa3, 0xdc, 0x3e, 0x3b, 0x84, 0x6a, 0x5f, 0x31, 0xc5, - 0x89, 0x03, 0xf5, 0xfe, 0xdd, 0xcd, 0xed, 0xed, 0xd9, 0x69, 0x73, 0x4b, 0x7f, 0xec, 0x2e, 0xaf, - 0x2f, 0xef, 0x9a, 0x96, 0x4e, 0xd3, 0x37, 0xd7, 0xd7, 0x97, 0xd7, 0xe7, 0xcd, 0x52, 0xf7, 0x2f, - 0x0b, 0xb6, 0x8f, 0x03, 0x2e, 0xd4, 0x15, 0x13, 0x2c, 0xe0, 0x31, 0x39, 0x84, 0xf2, 0xb1, 0xef, - 0x93, 0xf5, 0x7f, 0x65, 0x07, 0xeb, 0x29, 0xfd, 0xa1, 0xa7, 0x3c, 0x92, 0x6f, 0xf9, 0xfb, 0xe3, - 0x35, 0xb5, 0x59, 0xf2, 0x7e, 0xf8, 0x61, 0x0d, 0xff, 0x30, 0x7c, 0xf9, 0x6f, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xaf, 0x6d, 0xfc, 0x30, 0xbc, 0x0a, 0x00, 0x00, -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/proto/fake.proto b/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/proto/fake.proto deleted file mode 100644 index 64becb06e..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/proto/fake.proto +++ /dev/null @@ -1,241 +0,0 @@ -// fake.proto describes the message format for creating integration tests for -// streaming telemetry components by generating a reproducible stream of -// updates from fake targets. -syntax = "proto3"; - -import "google/protobuf/any.proto"; -import "github.com/openconfig/gnmi/proto/gnmi/gnmi.proto"; - -package gnmi.fake; - -service AgentManager { - // Add adds an agent to the server. - rpc Add(Config) returns (Config); - // Remove removes an agent from the server. - rpc Remove(Config) returns (Config); - // Status returns the current status of an agent on the server. - rpc Status(Config) returns (Config); -} - -enum State { - STOPPED = 0; - INIT = 1; - RUNNING = 2; -} - -// Configuration is used to store all agent configuration for the fake agent -// server. Each config describes a single agent hosted on the server. -message Configuration { - // Repeated list of targets to emulate. - repeated Config config = 1; -} - -message Credentials { - string username =1; - string password = 2; -} - -// Config is a collection of values that together represent the update streams -// for one or more fake devices. -message Config { - enum ClientType { - GRPC = 0; - STUBBY = 1; - GRPC_GNMI = 2; - GRPC_GNMI_PROD = 3; - } - // The target for which the fake will publish values for. - string target = 1; - // Port for the agent to listen on. If 0 or unset the agent will pick a port - // for this agent. - int32 port = 2; - // A global random seed used in generating subsequent values. Set to have - // reproducible results. - int64 seed = 6 [deprecated=true]; - // The list of values generated. Each value will contain its corresponding - // target as the first string in the event.GetValue().path meaning that it is - // possible to generate streams that will be rejected by the cache for testing - // purposes. - repeated Value values = 3 [deprecated=true]; - // Setting disable sync will keep the configured client from autogenerating a - // sync message. This allows negative testing on sync handling. - bool disable_sync = 4; - // Type of client to fake either Stubby or GRPC based fake. - ClientType client_type = 5; - // Disable EOF will hold open the subscription and not automagically close - // the stream once the value queue is empty. - bool disable_eof = 7; - // Per RPC credentials for the agent. If not set no per RPC auth will be used. - Credentials credentials = 8; - // TLS cert for use on the agent. If not set the transport will not be TLS. - bytes cert = 9; - // Honor the delay between events in the generated value streams. Default will - // play events as fast as the can be streamed. - bool enable_delay = 10; - // Generator for value series for the target. - oneof generator { - google.protobuf.Any custom = 100; - RandomGenerator random = 101; - FixedGenerator fixed = 102; - } -} - -message FixedGenerator { - repeated gnmi.SubscribeResponse responses = 1; -} - -message RandomGenerator { - int64 seed = 1; - repeated Value values = 2; -} - -// Delete will cause the value to be deleted at the Value's path. -message DeleteValue{} - -// Value is the main message that will trigger a stream of updates for a given -// path. A file containing a list of values can be used to simulate a network -// device for integration tests. -message Value { - // The device specific, or OpenConfig path corresponding to a value. - repeated string path = 1; - // The initial timestamp and configuration on how the timestamp will change - // for subsequent values. If timestamp is not set the default will assume to - // be the current system time. - Timestamp timestamp = 2; - // If set, repeat indicates that the value should be repeated this many times, - // otherwise it is repeated indefinitely. - int32 repeat = 6; - // A local random seed used in generating subsequent values for this path. If - // not set, will share the global random source with seed defined in Config. - int64 seed = 7; - // The initial value of the chosen type including configuration on how the - // value will mutate for subsequent updates. - oneof value { - IntValue int_value = 100; - DoubleValue double_value = 101; - StringValue string_value = 102; - uint64 sync = 103; - DeleteValue delete = 104; - BoolValue bool_value = 105; - } -} - -message Timestamp { - // Initial timestamp for the corresponding value, nanoseconds since epoch. - // This value need have no relation to absolute real-time as the stream of - // of updates is generated without regard to the real clock and can be run - // repeatably at any time if the seed is set in the corresponding Value. - int64 timestamp = 1; - // These values will vary the change in the timestamp for subsequent outputs - // by a value between delta_min and delta_max. Set to the same value to force - // a set periodic interval. - int64 delta_min = 2; - int64 delta_max = 3; -} - -message IntValue { - // If distribution is IntRange, value is used as the initial value - // inside [minimum, maximum] and hold the value as it mutates. - // If distribution is IntList, value is only used to hold the value as it - // mutates. - // If no distribution is set, value is used as it mutates, i.e. constant - // update. - int64 value = 1; - oneof distribution { - IntRange range = 2; - IntList list = 3; - } -} - -message IntRange { - // The range of the value allowed. - int64 minimum = 1; - int64 maximum = 2; - // If set, the value is cumulative and the subsequent value is value + delta - // where delta is randomly chosen between delta_min and delta_max. The range - // minimum and maximum are still respected and values will saturate at the - // boundaries if they are exceeded. If not set subsequent value is a value - // randomly chosen between minimum and maximum. - int64 delta_min = 3; - int64 delta_max = 4; -} - -message IntList { - // The set of values which can be used. - repeated int64 options = 1; - // Set to true to randomize selection of value from options. If false, the - // values are cycled in order, starting at index 0. - bool random = 2; -} - -message DoubleValue { - // If distribution is DoubleRange, value is used as the initial value - // inside [minimum, maximum] and hold the value as it mutates. - // If distribution is DoubleList, value is only used to hold the value as it - // mutates. - // If no distribution is set, value is used as it mutates, i.e. constant - // update. - double value = 1; - oneof distribution { - DoubleRange range = 2; - DoubleList list = 3; - } -} - -message DoubleRange { - // The range of the value allowed. - double minimum = 1; - double maximum = 2; - // If set, the value is cumulative and the subsequent value is value + delta - // where delta is randomly chosen between delta_min and delta_max. The range - // minimum and maximum are still respected. If not set subsequent value is a - // value randomly chosen between minimum and maximum. - double delta_min = 3; - double delta_max = 4; -} - -message DoubleList { - // The set of values which can be used. - repeated double options = 1; - // Set to true to randomize selection of value from options. If false, the - // values are cycled in order. - bool random = 2; -} - -message StringValue { - // If distribution is StringList, value is used to hold the value as it - // mutates. - // If no distribution is set, value is used as it mutates, i.e. constant - // update. - string value = 1; - oneof distribution { - StringList list = 2; - } -} - -message StringList { - // The set of strings which can be used. - repeated string options = 1; - // Set to true to randomize selection of value from options. If false, the - // values are cycled in order, starting at index 0. - bool random = 2; -} - -message BoolValue { - // If distribution is BoolList, value is only used to hold the value as it - // mutates. - // If no distribution is set, value is used as it mutates, i.e. constant - // update. - bool value = 1; - oneof distribution { - BoolList list = 2; - } -} - -message BoolList { - // The set of values which can be used. - repeated bool options = 1; - // Set to true to randomize selection of value from options. If false, the - // values are cycled in order, starting at index 0. - bool random = 2; -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/proto/fake_pb2.py b/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/proto/fake_pb2.py deleted file mode 100644 index 04674e2c8..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/proto/fake_pb2.py +++ /dev/null @@ -1,1208 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: testing/fake/proto/fake.proto - -import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) -from google.protobuf.internal import enum_type_wrapper -from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection -from google.protobuf import symbol_database as _symbol_database -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - -from google.protobuf import any_pb2 as google_dot_protobuf_dot_any__pb2 -from github.com.openconfig.gnmi.proto.gnmi import gnmi_pb2 as github_dot_com_dot_openconfig_dot_gnmi_dot_proto_dot_gnmi_dot_gnmi__pb2 - - -DESCRIPTOR = _descriptor.FileDescriptor( - name='testing/fake/proto/fake.proto', - package='gnmi.fake', - syntax='proto3', - serialized_options=None, - serialized_pb=_b('\n\x1dtesting/fake/proto/fake.proto\x12\tgnmi.fake\x1a\x19google/protobuf/any.proto\x1a\x30github.com/openconfig/gnmi/proto/gnmi/gnmi.proto\"2\n\rConfiguration\x12!\n\x06\x63onfig\x18\x01 \x03(\x0b\x32\x11.gnmi.fake.Config\"1\n\x0b\x43redentials\x12\x10\n\x08username\x18\x01 \x01(\t\x12\x10\n\x08password\x18\x02 \x01(\t\"\xe3\x03\n\x06\x43onfig\x12\x0e\n\x06target\x18\x01 \x01(\t\x12\x0c\n\x04port\x18\x02 \x01(\x05\x12\x10\n\x04seed\x18\x06 \x01(\x03\x42\x02\x18\x01\x12$\n\x06values\x18\x03 \x03(\x0b\x32\x10.gnmi.fake.ValueB\x02\x18\x01\x12\x14\n\x0c\x64isable_sync\x18\x04 \x01(\x08\x12\x31\n\x0b\x63lient_type\x18\x05 \x01(\x0e\x32\x1c.gnmi.fake.Config.ClientType\x12\x13\n\x0b\x64isable_eof\x18\x07 \x01(\x08\x12+\n\x0b\x63redentials\x18\x08 \x01(\x0b\x32\x16.gnmi.fake.Credentials\x12\x0c\n\x04\x63\x65rt\x18\t \x01(\x0c\x12\x14\n\x0c\x65nable_delay\x18\n \x01(\x08\x12&\n\x06\x63ustom\x18\x64 \x01(\x0b\x32\x14.google.protobuf.AnyH\x00\x12,\n\x06random\x18\x65 \x01(\x0b\x32\x1a.gnmi.fake.RandomGeneratorH\x00\x12*\n\x05\x66ixed\x18\x66 \x01(\x0b\x32\x19.gnmi.fake.FixedGeneratorH\x00\"E\n\nClientType\x12\x08\n\x04GRPC\x10\x00\x12\n\n\x06STUBBY\x10\x01\x12\r\n\tGRPC_GNMI\x10\x02\x12\x12\n\x0eGRPC_GNMI_PROD\x10\x03\x42\x0b\n\tgenerator\"<\n\x0e\x46ixedGenerator\x12*\n\tresponses\x18\x01 \x03(\x0b\x32\x17.gnmi.SubscribeResponse\"A\n\x0fRandomGenerator\x12\x0c\n\x04seed\x18\x01 \x01(\x03\x12 \n\x06values\x18\x02 \x03(\x0b\x32\x10.gnmi.fake.Value\"\r\n\x0b\x44\x65leteValue\"\xd5\x02\n\x05Value\x12\x0c\n\x04path\x18\x01 \x03(\t\x12\'\n\ttimestamp\x18\x02 \x01(\x0b\x32\x14.gnmi.fake.Timestamp\x12\x0e\n\x06repeat\x18\x06 \x01(\x05\x12\x0c\n\x04seed\x18\x07 \x01(\x03\x12(\n\tint_value\x18\x64 \x01(\x0b\x32\x13.gnmi.fake.IntValueH\x00\x12.\n\x0c\x64ouble_value\x18\x65 \x01(\x0b\x32\x16.gnmi.fake.DoubleValueH\x00\x12.\n\x0cstring_value\x18\x66 \x01(\x0b\x32\x16.gnmi.fake.StringValueH\x00\x12\x0e\n\x04sync\x18g \x01(\x04H\x00\x12(\n\x06\x64\x65lete\x18h \x01(\x0b\x32\x16.gnmi.fake.DeleteValueH\x00\x12*\n\nbool_value\x18i \x01(\x0b\x32\x14.gnmi.fake.BoolValueH\x00\x42\x07\n\x05value\"D\n\tTimestamp\x12\x11\n\ttimestamp\x18\x01 \x01(\x03\x12\x11\n\tdelta_min\x18\x02 \x01(\x03\x12\x11\n\tdelta_max\x18\x03 \x01(\x03\"s\n\x08IntValue\x12\r\n\x05value\x18\x01 \x01(\x03\x12$\n\x05range\x18\x02 \x01(\x0b\x32\x13.gnmi.fake.IntRangeH\x00\x12\"\n\x04list\x18\x03 \x01(\x0b\x32\x12.gnmi.fake.IntListH\x00\x42\x0e\n\x0c\x64istribution\"R\n\x08IntRange\x12\x0f\n\x07minimum\x18\x01 \x01(\x03\x12\x0f\n\x07maximum\x18\x02 \x01(\x03\x12\x11\n\tdelta_min\x18\x03 \x01(\x03\x12\x11\n\tdelta_max\x18\x04 \x01(\x03\"*\n\x07IntList\x12\x0f\n\x07options\x18\x01 \x03(\x03\x12\x0e\n\x06random\x18\x02 \x01(\x08\"|\n\x0b\x44oubleValue\x12\r\n\x05value\x18\x01 \x01(\x01\x12\'\n\x05range\x18\x02 \x01(\x0b\x32\x16.gnmi.fake.DoubleRangeH\x00\x12%\n\x04list\x18\x03 \x01(\x0b\x32\x15.gnmi.fake.DoubleListH\x00\x42\x0e\n\x0c\x64istribution\"U\n\x0b\x44oubleRange\x12\x0f\n\x07minimum\x18\x01 \x01(\x01\x12\x0f\n\x07maximum\x18\x02 \x01(\x01\x12\x11\n\tdelta_min\x18\x03 \x01(\x01\x12\x11\n\tdelta_max\x18\x04 \x01(\x01\"-\n\nDoubleList\x12\x0f\n\x07options\x18\x01 \x03(\x01\x12\x0e\n\x06random\x18\x02 \x01(\x08\"S\n\x0bStringValue\x12\r\n\x05value\x18\x01 \x01(\t\x12%\n\x04list\x18\x02 \x01(\x0b\x32\x15.gnmi.fake.StringListH\x00\x42\x0e\n\x0c\x64istribution\"-\n\nStringList\x12\x0f\n\x07options\x18\x01 \x03(\t\x12\x0e\n\x06random\x18\x02 \x01(\x08\"O\n\tBoolValue\x12\r\n\x05value\x18\x01 \x01(\x08\x12#\n\x04list\x18\x02 \x01(\x0b\x32\x13.gnmi.fake.BoolListH\x00\x42\x0e\n\x0c\x64istribution\"+\n\x08\x42oolList\x12\x0f\n\x07options\x18\x01 \x03(\x08\x12\x0e\n\x06random\x18\x02 \x01(\x08*+\n\x05State\x12\x0b\n\x07STOPPED\x10\x00\x12\x08\n\x04INIT\x10\x01\x12\x0b\n\x07RUNNING\x10\x02\x32\x9b\x01\n\x0c\x41gentManager\x12+\n\x03\x41\x64\x64\x12\x11.gnmi.fake.Config\x1a\x11.gnmi.fake.Config\x12.\n\x06Remove\x12\x11.gnmi.fake.Config\x1a\x11.gnmi.fake.Config\x12.\n\x06Status\x12\x11.gnmi.fake.Config\x1a\x11.gnmi.fake.Configb\x06proto3') - , - dependencies=[google_dot_protobuf_dot_any__pb2.DESCRIPTOR,github_dot_com_dot_openconfig_dot_gnmi_dot_proto_dot_gnmi_dot_gnmi__pb2.DESCRIPTOR,]) - -_STATE = _descriptor.EnumDescriptor( - name='State', - full_name='gnmi.fake.State', - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name='STOPPED', index=0, number=0, - serialized_options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='INIT', index=1, number=1, - serialized_options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='RUNNING', index=2, number=2, - serialized_options=None, - type=None), - ], - containing_type=None, - serialized_options=None, - serialized_start=2031, - serialized_end=2074, -) -_sym_db.RegisterEnumDescriptor(_STATE) - -State = enum_type_wrapper.EnumTypeWrapper(_STATE) -STOPPED = 0 -INIT = 1 -RUNNING = 2 - - -_CONFIG_CLIENTTYPE = _descriptor.EnumDescriptor( - name='ClientType', - full_name='gnmi.fake.Config.ClientType', - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name='GRPC', index=0, number=0, - serialized_options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='STUBBY', index=1, number=1, - serialized_options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='GRPC_GNMI', index=2, number=2, - serialized_options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='GRPC_GNMI_PROD', index=3, number=3, - serialized_options=None, - type=None), - ], - containing_type=None, - serialized_options=None, - serialized_start=626, - serialized_end=695, -) -_sym_db.RegisterEnumDescriptor(_CONFIG_CLIENTTYPE) - - -_CONFIGURATION = _descriptor.Descriptor( - name='Configuration', - full_name='gnmi.fake.Configuration', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='config', full_name='gnmi.fake.Configuration.config', index=0, - number=1, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=121, - serialized_end=171, -) - - -_CREDENTIALS = _descriptor.Descriptor( - name='Credentials', - full_name='gnmi.fake.Credentials', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='username', full_name='gnmi.fake.Credentials.username', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='password', full_name='gnmi.fake.Credentials.password', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=173, - serialized_end=222, -) - - -_CONFIG = _descriptor.Descriptor( - name='Config', - full_name='gnmi.fake.Config', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='target', full_name='gnmi.fake.Config.target', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='port', full_name='gnmi.fake.Config.port', index=1, - number=2, type=5, cpp_type=1, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='seed', full_name='gnmi.fake.Config.seed', index=2, - number=6, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=_b('\030\001'), file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='values', full_name='gnmi.fake.Config.values', index=3, - number=3, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=_b('\030\001'), file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='disable_sync', full_name='gnmi.fake.Config.disable_sync', index=4, - number=4, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='client_type', full_name='gnmi.fake.Config.client_type', index=5, - number=5, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='disable_eof', full_name='gnmi.fake.Config.disable_eof', index=6, - number=7, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='credentials', full_name='gnmi.fake.Config.credentials', index=7, - number=8, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='cert', full_name='gnmi.fake.Config.cert', index=8, - number=9, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='enable_delay', full_name='gnmi.fake.Config.enable_delay', index=9, - number=10, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='custom', full_name='gnmi.fake.Config.custom', index=10, - number=100, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='random', full_name='gnmi.fake.Config.random', index=11, - number=101, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='fixed', full_name='gnmi.fake.Config.fixed', index=12, - number=102, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - _CONFIG_CLIENTTYPE, - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - _descriptor.OneofDescriptor( - name='generator', full_name='gnmi.fake.Config.generator', - index=0, containing_type=None, fields=[]), - ], - serialized_start=225, - serialized_end=708, -) - - -_FIXEDGENERATOR = _descriptor.Descriptor( - name='FixedGenerator', - full_name='gnmi.fake.FixedGenerator', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='responses', full_name='gnmi.fake.FixedGenerator.responses', index=0, - number=1, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=710, - serialized_end=770, -) - - -_RANDOMGENERATOR = _descriptor.Descriptor( - name='RandomGenerator', - full_name='gnmi.fake.RandomGenerator', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='seed', full_name='gnmi.fake.RandomGenerator.seed', index=0, - number=1, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='values', full_name='gnmi.fake.RandomGenerator.values', index=1, - number=2, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=772, - serialized_end=837, -) - - -_DELETEVALUE = _descriptor.Descriptor( - name='DeleteValue', - full_name='gnmi.fake.DeleteValue', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=839, - serialized_end=852, -) - - -_VALUE = _descriptor.Descriptor( - name='Value', - full_name='gnmi.fake.Value', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='path', full_name='gnmi.fake.Value.path', index=0, - number=1, type=9, cpp_type=9, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='timestamp', full_name='gnmi.fake.Value.timestamp', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='repeat', full_name='gnmi.fake.Value.repeat', index=2, - number=6, type=5, cpp_type=1, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='seed', full_name='gnmi.fake.Value.seed', index=3, - number=7, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='int_value', full_name='gnmi.fake.Value.int_value', index=4, - number=100, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='double_value', full_name='gnmi.fake.Value.double_value', index=5, - number=101, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='string_value', full_name='gnmi.fake.Value.string_value', index=6, - number=102, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='sync', full_name='gnmi.fake.Value.sync', index=7, - number=103, type=4, cpp_type=4, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='delete', full_name='gnmi.fake.Value.delete', index=8, - number=104, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='bool_value', full_name='gnmi.fake.Value.bool_value', index=9, - number=105, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - _descriptor.OneofDescriptor( - name='value', full_name='gnmi.fake.Value.value', - index=0, containing_type=None, fields=[]), - ], - serialized_start=855, - serialized_end=1196, -) - - -_TIMESTAMP = _descriptor.Descriptor( - name='Timestamp', - full_name='gnmi.fake.Timestamp', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='timestamp', full_name='gnmi.fake.Timestamp.timestamp', index=0, - number=1, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='delta_min', full_name='gnmi.fake.Timestamp.delta_min', index=1, - number=2, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='delta_max', full_name='gnmi.fake.Timestamp.delta_max', index=2, - number=3, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1198, - serialized_end=1266, -) - - -_INTVALUE = _descriptor.Descriptor( - name='IntValue', - full_name='gnmi.fake.IntValue', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='value', full_name='gnmi.fake.IntValue.value', index=0, - number=1, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='range', full_name='gnmi.fake.IntValue.range', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='list', full_name='gnmi.fake.IntValue.list', index=2, - number=3, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - _descriptor.OneofDescriptor( - name='distribution', full_name='gnmi.fake.IntValue.distribution', - index=0, containing_type=None, fields=[]), - ], - serialized_start=1268, - serialized_end=1383, -) - - -_INTRANGE = _descriptor.Descriptor( - name='IntRange', - full_name='gnmi.fake.IntRange', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='minimum', full_name='gnmi.fake.IntRange.minimum', index=0, - number=1, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='maximum', full_name='gnmi.fake.IntRange.maximum', index=1, - number=2, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='delta_min', full_name='gnmi.fake.IntRange.delta_min', index=2, - number=3, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='delta_max', full_name='gnmi.fake.IntRange.delta_max', index=3, - number=4, type=3, cpp_type=2, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1385, - serialized_end=1467, -) - - -_INTLIST = _descriptor.Descriptor( - name='IntList', - full_name='gnmi.fake.IntList', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='options', full_name='gnmi.fake.IntList.options', index=0, - number=1, type=3, cpp_type=2, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='random', full_name='gnmi.fake.IntList.random', index=1, - number=2, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1469, - serialized_end=1511, -) - - -_DOUBLEVALUE = _descriptor.Descriptor( - name='DoubleValue', - full_name='gnmi.fake.DoubleValue', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='value', full_name='gnmi.fake.DoubleValue.value', index=0, - number=1, type=1, cpp_type=5, label=1, - has_default_value=False, default_value=float(0), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='range', full_name='gnmi.fake.DoubleValue.range', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='list', full_name='gnmi.fake.DoubleValue.list', index=2, - number=3, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - _descriptor.OneofDescriptor( - name='distribution', full_name='gnmi.fake.DoubleValue.distribution', - index=0, containing_type=None, fields=[]), - ], - serialized_start=1513, - serialized_end=1637, -) - - -_DOUBLERANGE = _descriptor.Descriptor( - name='DoubleRange', - full_name='gnmi.fake.DoubleRange', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='minimum', full_name='gnmi.fake.DoubleRange.minimum', index=0, - number=1, type=1, cpp_type=5, label=1, - has_default_value=False, default_value=float(0), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='maximum', full_name='gnmi.fake.DoubleRange.maximum', index=1, - number=2, type=1, cpp_type=5, label=1, - has_default_value=False, default_value=float(0), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='delta_min', full_name='gnmi.fake.DoubleRange.delta_min', index=2, - number=3, type=1, cpp_type=5, label=1, - has_default_value=False, default_value=float(0), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='delta_max', full_name='gnmi.fake.DoubleRange.delta_max', index=3, - number=4, type=1, cpp_type=5, label=1, - has_default_value=False, default_value=float(0), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1639, - serialized_end=1724, -) - - -_DOUBLELIST = _descriptor.Descriptor( - name='DoubleList', - full_name='gnmi.fake.DoubleList', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='options', full_name='gnmi.fake.DoubleList.options', index=0, - number=1, type=1, cpp_type=5, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='random', full_name='gnmi.fake.DoubleList.random', index=1, - number=2, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1726, - serialized_end=1771, -) - - -_STRINGVALUE = _descriptor.Descriptor( - name='StringValue', - full_name='gnmi.fake.StringValue', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='value', full_name='gnmi.fake.StringValue.value', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='list', full_name='gnmi.fake.StringValue.list', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - _descriptor.OneofDescriptor( - name='distribution', full_name='gnmi.fake.StringValue.distribution', - index=0, containing_type=None, fields=[]), - ], - serialized_start=1773, - serialized_end=1856, -) - - -_STRINGLIST = _descriptor.Descriptor( - name='StringList', - full_name='gnmi.fake.StringList', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='options', full_name='gnmi.fake.StringList.options', index=0, - number=1, type=9, cpp_type=9, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='random', full_name='gnmi.fake.StringList.random', index=1, - number=2, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1858, - serialized_end=1903, -) - - -_BOOLVALUE = _descriptor.Descriptor( - name='BoolValue', - full_name='gnmi.fake.BoolValue', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='value', full_name='gnmi.fake.BoolValue.value', index=0, - number=1, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='list', full_name='gnmi.fake.BoolValue.list', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - _descriptor.OneofDescriptor( - name='distribution', full_name='gnmi.fake.BoolValue.distribution', - index=0, containing_type=None, fields=[]), - ], - serialized_start=1905, - serialized_end=1984, -) - - -_BOOLLIST = _descriptor.Descriptor( - name='BoolList', - full_name='gnmi.fake.BoolList', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='options', full_name='gnmi.fake.BoolList.options', index=0, - number=1, type=8, cpp_type=7, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='random', full_name='gnmi.fake.BoolList.random', index=1, - number=2, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1986, - serialized_end=2029, -) - -_CONFIGURATION.fields_by_name['config'].message_type = _CONFIG -_CONFIG.fields_by_name['values'].message_type = _VALUE -_CONFIG.fields_by_name['client_type'].enum_type = _CONFIG_CLIENTTYPE -_CONFIG.fields_by_name['credentials'].message_type = _CREDENTIALS -_CONFIG.fields_by_name['custom'].message_type = google_dot_protobuf_dot_any__pb2._ANY -_CONFIG.fields_by_name['random'].message_type = _RANDOMGENERATOR -_CONFIG.fields_by_name['fixed'].message_type = _FIXEDGENERATOR -_CONFIG_CLIENTTYPE.containing_type = _CONFIG -_CONFIG.oneofs_by_name['generator'].fields.append( - _CONFIG.fields_by_name['custom']) -_CONFIG.fields_by_name['custom'].containing_oneof = _CONFIG.oneofs_by_name['generator'] -_CONFIG.oneofs_by_name['generator'].fields.append( - _CONFIG.fields_by_name['random']) -_CONFIG.fields_by_name['random'].containing_oneof = _CONFIG.oneofs_by_name['generator'] -_CONFIG.oneofs_by_name['generator'].fields.append( - _CONFIG.fields_by_name['fixed']) -_CONFIG.fields_by_name['fixed'].containing_oneof = _CONFIG.oneofs_by_name['generator'] -_FIXEDGENERATOR.fields_by_name['responses'].message_type = github_dot_com_dot_openconfig_dot_gnmi_dot_proto_dot_gnmi_dot_gnmi__pb2._SUBSCRIBERESPONSE -_RANDOMGENERATOR.fields_by_name['values'].message_type = _VALUE -_VALUE.fields_by_name['timestamp'].message_type = _TIMESTAMP -_VALUE.fields_by_name['int_value'].message_type = _INTVALUE -_VALUE.fields_by_name['double_value'].message_type = _DOUBLEVALUE -_VALUE.fields_by_name['string_value'].message_type = _STRINGVALUE -_VALUE.fields_by_name['delete'].message_type = _DELETEVALUE -_VALUE.fields_by_name['bool_value'].message_type = _BOOLVALUE -_VALUE.oneofs_by_name['value'].fields.append( - _VALUE.fields_by_name['int_value']) -_VALUE.fields_by_name['int_value'].containing_oneof = _VALUE.oneofs_by_name['value'] -_VALUE.oneofs_by_name['value'].fields.append( - _VALUE.fields_by_name['double_value']) -_VALUE.fields_by_name['double_value'].containing_oneof = _VALUE.oneofs_by_name['value'] -_VALUE.oneofs_by_name['value'].fields.append( - _VALUE.fields_by_name['string_value']) -_VALUE.fields_by_name['string_value'].containing_oneof = _VALUE.oneofs_by_name['value'] -_VALUE.oneofs_by_name['value'].fields.append( - _VALUE.fields_by_name['sync']) -_VALUE.fields_by_name['sync'].containing_oneof = _VALUE.oneofs_by_name['value'] -_VALUE.oneofs_by_name['value'].fields.append( - _VALUE.fields_by_name['delete']) -_VALUE.fields_by_name['delete'].containing_oneof = _VALUE.oneofs_by_name['value'] -_VALUE.oneofs_by_name['value'].fields.append( - _VALUE.fields_by_name['bool_value']) -_VALUE.fields_by_name['bool_value'].containing_oneof = _VALUE.oneofs_by_name['value'] -_INTVALUE.fields_by_name['range'].message_type = _INTRANGE -_INTVALUE.fields_by_name['list'].message_type = _INTLIST -_INTVALUE.oneofs_by_name['distribution'].fields.append( - _INTVALUE.fields_by_name['range']) -_INTVALUE.fields_by_name['range'].containing_oneof = _INTVALUE.oneofs_by_name['distribution'] -_INTVALUE.oneofs_by_name['distribution'].fields.append( - _INTVALUE.fields_by_name['list']) -_INTVALUE.fields_by_name['list'].containing_oneof = _INTVALUE.oneofs_by_name['distribution'] -_DOUBLEVALUE.fields_by_name['range'].message_type = _DOUBLERANGE -_DOUBLEVALUE.fields_by_name['list'].message_type = _DOUBLELIST -_DOUBLEVALUE.oneofs_by_name['distribution'].fields.append( - _DOUBLEVALUE.fields_by_name['range']) -_DOUBLEVALUE.fields_by_name['range'].containing_oneof = _DOUBLEVALUE.oneofs_by_name['distribution'] -_DOUBLEVALUE.oneofs_by_name['distribution'].fields.append( - _DOUBLEVALUE.fields_by_name['list']) -_DOUBLEVALUE.fields_by_name['list'].containing_oneof = _DOUBLEVALUE.oneofs_by_name['distribution'] -_STRINGVALUE.fields_by_name['list'].message_type = _STRINGLIST -_STRINGVALUE.oneofs_by_name['distribution'].fields.append( - _STRINGVALUE.fields_by_name['list']) -_STRINGVALUE.fields_by_name['list'].containing_oneof = _STRINGVALUE.oneofs_by_name['distribution'] -_BOOLVALUE.fields_by_name['list'].message_type = _BOOLLIST -_BOOLVALUE.oneofs_by_name['distribution'].fields.append( - _BOOLVALUE.fields_by_name['list']) -_BOOLVALUE.fields_by_name['list'].containing_oneof = _BOOLVALUE.oneofs_by_name['distribution'] -DESCRIPTOR.message_types_by_name['Configuration'] = _CONFIGURATION -DESCRIPTOR.message_types_by_name['Credentials'] = _CREDENTIALS -DESCRIPTOR.message_types_by_name['Config'] = _CONFIG -DESCRIPTOR.message_types_by_name['FixedGenerator'] = _FIXEDGENERATOR -DESCRIPTOR.message_types_by_name['RandomGenerator'] = _RANDOMGENERATOR -DESCRIPTOR.message_types_by_name['DeleteValue'] = _DELETEVALUE -DESCRIPTOR.message_types_by_name['Value'] = _VALUE -DESCRIPTOR.message_types_by_name['Timestamp'] = _TIMESTAMP -DESCRIPTOR.message_types_by_name['IntValue'] = _INTVALUE -DESCRIPTOR.message_types_by_name['IntRange'] = _INTRANGE -DESCRIPTOR.message_types_by_name['IntList'] = _INTLIST -DESCRIPTOR.message_types_by_name['DoubleValue'] = _DOUBLEVALUE -DESCRIPTOR.message_types_by_name['DoubleRange'] = _DOUBLERANGE -DESCRIPTOR.message_types_by_name['DoubleList'] = _DOUBLELIST -DESCRIPTOR.message_types_by_name['StringValue'] = _STRINGVALUE -DESCRIPTOR.message_types_by_name['StringList'] = _STRINGLIST -DESCRIPTOR.message_types_by_name['BoolValue'] = _BOOLVALUE -DESCRIPTOR.message_types_by_name['BoolList'] = _BOOLLIST -DESCRIPTOR.enum_types_by_name['State'] = _STATE -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -Configuration = _reflection.GeneratedProtocolMessageType('Configuration', (_message.Message,), dict( - DESCRIPTOR = _CONFIGURATION, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.Configuration) - )) -_sym_db.RegisterMessage(Configuration) - -Credentials = _reflection.GeneratedProtocolMessageType('Credentials', (_message.Message,), dict( - DESCRIPTOR = _CREDENTIALS, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.Credentials) - )) -_sym_db.RegisterMessage(Credentials) - -Config = _reflection.GeneratedProtocolMessageType('Config', (_message.Message,), dict( - DESCRIPTOR = _CONFIG, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.Config) - )) -_sym_db.RegisterMessage(Config) - -FixedGenerator = _reflection.GeneratedProtocolMessageType('FixedGenerator', (_message.Message,), dict( - DESCRIPTOR = _FIXEDGENERATOR, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.FixedGenerator) - )) -_sym_db.RegisterMessage(FixedGenerator) - -RandomGenerator = _reflection.GeneratedProtocolMessageType('RandomGenerator', (_message.Message,), dict( - DESCRIPTOR = _RANDOMGENERATOR, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.RandomGenerator) - )) -_sym_db.RegisterMessage(RandomGenerator) - -DeleteValue = _reflection.GeneratedProtocolMessageType('DeleteValue', (_message.Message,), dict( - DESCRIPTOR = _DELETEVALUE, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.DeleteValue) - )) -_sym_db.RegisterMessage(DeleteValue) - -Value = _reflection.GeneratedProtocolMessageType('Value', (_message.Message,), dict( - DESCRIPTOR = _VALUE, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.Value) - )) -_sym_db.RegisterMessage(Value) - -Timestamp = _reflection.GeneratedProtocolMessageType('Timestamp', (_message.Message,), dict( - DESCRIPTOR = _TIMESTAMP, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.Timestamp) - )) -_sym_db.RegisterMessage(Timestamp) - -IntValue = _reflection.GeneratedProtocolMessageType('IntValue', (_message.Message,), dict( - DESCRIPTOR = _INTVALUE, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.IntValue) - )) -_sym_db.RegisterMessage(IntValue) - -IntRange = _reflection.GeneratedProtocolMessageType('IntRange', (_message.Message,), dict( - DESCRIPTOR = _INTRANGE, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.IntRange) - )) -_sym_db.RegisterMessage(IntRange) - -IntList = _reflection.GeneratedProtocolMessageType('IntList', (_message.Message,), dict( - DESCRIPTOR = _INTLIST, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.IntList) - )) -_sym_db.RegisterMessage(IntList) - -DoubleValue = _reflection.GeneratedProtocolMessageType('DoubleValue', (_message.Message,), dict( - DESCRIPTOR = _DOUBLEVALUE, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.DoubleValue) - )) -_sym_db.RegisterMessage(DoubleValue) - -DoubleRange = _reflection.GeneratedProtocolMessageType('DoubleRange', (_message.Message,), dict( - DESCRIPTOR = _DOUBLERANGE, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.DoubleRange) - )) -_sym_db.RegisterMessage(DoubleRange) - -DoubleList = _reflection.GeneratedProtocolMessageType('DoubleList', (_message.Message,), dict( - DESCRIPTOR = _DOUBLELIST, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.DoubleList) - )) -_sym_db.RegisterMessage(DoubleList) - -StringValue = _reflection.GeneratedProtocolMessageType('StringValue', (_message.Message,), dict( - DESCRIPTOR = _STRINGVALUE, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.StringValue) - )) -_sym_db.RegisterMessage(StringValue) - -StringList = _reflection.GeneratedProtocolMessageType('StringList', (_message.Message,), dict( - DESCRIPTOR = _STRINGLIST, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.StringList) - )) -_sym_db.RegisterMessage(StringList) - -BoolValue = _reflection.GeneratedProtocolMessageType('BoolValue', (_message.Message,), dict( - DESCRIPTOR = _BOOLVALUE, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.BoolValue) - )) -_sym_db.RegisterMessage(BoolValue) - -BoolList = _reflection.GeneratedProtocolMessageType('BoolList', (_message.Message,), dict( - DESCRIPTOR = _BOOLLIST, - __module__ = 'testing.fake.proto.fake_pb2' - # @@protoc_insertion_point(class_scope:gnmi.fake.BoolList) - )) -_sym_db.RegisterMessage(BoolList) - - -_CONFIG.fields_by_name['seed']._options = None -_CONFIG.fields_by_name['values']._options = None - -_AGENTMANAGER = _descriptor.ServiceDescriptor( - name='AgentManager', - full_name='gnmi.fake.AgentManager', - file=DESCRIPTOR, - index=0, - serialized_options=None, - serialized_start=2077, - serialized_end=2232, - methods=[ - _descriptor.MethodDescriptor( - name='Add', - full_name='gnmi.fake.AgentManager.Add', - index=0, - containing_service=None, - input_type=_CONFIG, - output_type=_CONFIG, - serialized_options=None, - ), - _descriptor.MethodDescriptor( - name='Remove', - full_name='gnmi.fake.AgentManager.Remove', - index=1, - containing_service=None, - input_type=_CONFIG, - output_type=_CONFIG, - serialized_options=None, - ), - _descriptor.MethodDescriptor( - name='Status', - full_name='gnmi.fake.AgentManager.Status', - index=2, - containing_service=None, - input_type=_CONFIG, - output_type=_CONFIG, - serialized_options=None, - ), -]) -_sym_db.RegisterServiceDescriptor(_AGENTMANAGER) - -DESCRIPTOR.services_by_name['AgentManager'] = _AGENTMANAGER - -# @@protoc_insertion_point(module_scope) diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/proto/fake_pb2_grpc.py b/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/proto/fake_pb2_grpc.py deleted file mode 100644 index e644a3c62..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/proto/fake_pb2_grpc.py +++ /dev/null @@ -1,80 +0,0 @@ -# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! -import grpc - -from testing.fake.proto import fake_pb2 as testing_dot_fake_dot_proto_dot_fake__pb2 - - -class AgentManagerStub(object): - # missing associated documentation comment in .proto file - pass - - def __init__(self, channel): - """Constructor. - - Args: - channel: A grpc.Channel. - """ - self.Add = channel.unary_unary( - '/gnmi.fake.AgentManager/Add', - request_serializer=testing_dot_fake_dot_proto_dot_fake__pb2.Config.SerializeToString, - response_deserializer=testing_dot_fake_dot_proto_dot_fake__pb2.Config.FromString, - ) - self.Remove = channel.unary_unary( - '/gnmi.fake.AgentManager/Remove', - request_serializer=testing_dot_fake_dot_proto_dot_fake__pb2.Config.SerializeToString, - response_deserializer=testing_dot_fake_dot_proto_dot_fake__pb2.Config.FromString, - ) - self.Status = channel.unary_unary( - '/gnmi.fake.AgentManager/Status', - request_serializer=testing_dot_fake_dot_proto_dot_fake__pb2.Config.SerializeToString, - response_deserializer=testing_dot_fake_dot_proto_dot_fake__pb2.Config.FromString, - ) - - -class AgentManagerServicer(object): - # missing associated documentation comment in .proto file - pass - - def Add(self, request, context): - """Add adds an agent to the server. - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def Remove(self, request, context): - """Remove removes an agent from the server. - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def Status(self, request, context): - """Status returns the current status of an agent on the server. - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - -def add_AgentManagerServicer_to_server(servicer, server): - rpc_method_handlers = { - 'Add': grpc.unary_unary_rpc_method_handler( - servicer.Add, - request_deserializer=testing_dot_fake_dot_proto_dot_fake__pb2.Config.FromString, - response_serializer=testing_dot_fake_dot_proto_dot_fake__pb2.Config.SerializeToString, - ), - 'Remove': grpc.unary_unary_rpc_method_handler( - servicer.Remove, - request_deserializer=testing_dot_fake_dot_proto_dot_fake__pb2.Config.FromString, - response_serializer=testing_dot_fake_dot_proto_dot_fake__pb2.Config.SerializeToString, - ), - 'Status': grpc.unary_unary_rpc_method_handler( - servicer.Status, - request_deserializer=testing_dot_fake_dot_proto_dot_fake__pb2.Config.FromString, - response_serializer=testing_dot_fake_dot_proto_dot_fake__pb2.Config.SerializeToString, - ), - } - generic_handler = grpc.method_handlers_generic_handler( - 'gnmi.fake.AgentManager', rpc_method_handlers) - server.add_generic_rpc_handlers((generic_handler,)) diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/queue/fixed_queue.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/queue/fixed_queue.go deleted file mode 100644 index 8547927ee..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/queue/fixed_queue.go +++ /dev/null @@ -1,81 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 queue - -import ( - "sync" - "time" - - gpb "github.com/openconfig/gnmi/proto/gnmi" -) - -// FixedQueue provides a strict delivery of provides updates. If checkDelay, -// the Next() will sleep for the duration between the timestamps provided in the -// updates. -type FixedQueue struct { - mu sync.Mutex - resp []*gpb.SubscribeResponse - delay time.Duration - checkDelay bool -} - -// NewFixed creates a new FixedQueue with resp list of updates enqueued for -// iterating through. -func NewFixed(resp []*gpb.SubscribeResponse, delay bool) *FixedQueue { - return &FixedQueue{ - resp: resp, - checkDelay: delay, - } -} - -// Add will append resp to the current tail of the queue. -func (q *FixedQueue) Add(resp *gpb.SubscribeResponse) { - q.mu.Lock() - defer q.mu.Unlock() - q.resp = append(q.resp, resp) -} - -// Next returns the next update in the queue or an error. If the queue is -// exhausted, a nil is returned for the update. The return will always be a -// *gpb.SubscribeResponse for proper type assertion. -func (q *FixedQueue) Next() (interface{}, error) { - q.mu.Lock() - defer q.mu.Unlock() - if len(q.resp) == 0 { - return nil, nil - } - if q.delay != 0 { - time.Sleep(q.delay) - } - resp := q.resp[0] - q.resp = q.resp[1:] - var n *gpb.SubscribeResponse_Update - if len(q.resp) > 0 && q.checkDelay { - var nOk bool - n, nOk = resp.Response.(*gpb.SubscribeResponse_Update) - next, nextOk := q.resp[0].Response.(*gpb.SubscribeResponse_Update) - if !nOk || !nextOk { - q.delay = 0 - } else { - q.delay = time.Duration(next.Update.Timestamp-n.Update.Timestamp) * time.Nanosecond - if q.delay < 0 { - q.delay = 0 - } - } - } - return resp, nil -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/queue/queue.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/queue/queue.go deleted file mode 100644 index 6204dba09..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/queue/queue.go +++ /dev/null @@ -1,406 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 queue implements an update queue for use in testing a telemetry -// stream. -package queue - -import ( - "fmt" - "math/rand" - "sync" - "time" - - "github.com/golang/protobuf/proto" - - gpb "github.com/openconfig/gnmi/proto/gnmi" - fpb "github.com/openconfig/gnmi/testing/fake/proto" -) - -// Queue is a generic interface for getting the next element from either a -// FixedQeueue or UpdateQueue. -type Queue interface { - Next() (interface{}, error) -} - -// UpdateQueue is a structure that orders a set of device updates by their -// timestamps and repeatedly generates new pseudo-random updates based on -// a set of device path configurations. -type UpdateQueue struct { - mu sync.Mutex - delay bool - duration time.Duration - latest int64 - q [][]*value - r *rand.Rand -} - -// New creates a new UpdateQueue. If delay is true, a call to Next() -// will invoke a sleep based on the duration between timestamps of the last -// returned update and the update to be returned by the current call. The -// values are the configuration for the updates stored in the queue. -func New(delay bool, seed int64, values []*fpb.Value) *UpdateQueue { - if seed == 0 { - seed = time.Now().UnixNano() - } - u := &UpdateQueue{delay: delay, r: rand.New(rand.NewSource(seed))} - for _, v := range values { - u.addValue(newValue(v, u.r)) - } - return u -} - -// Add inserts v into the queue in correct timestamp order. -func (u *UpdateQueue) Add(v *fpb.Value) { - u.mu.Lock() - defer u.mu.Unlock() - u.addValue(newValue(v, u.r)) -} - -// Latest returns the maximum timestamp in the queue. -func (u *UpdateQueue) Latest() int64 { - return u.latest -} - -// Next returns the next update in the queue or an error. If the queue is -// exhausted, a nil is returned for the update. The return will always be a -// *fpb.Value for proper type assertion. -func (u *UpdateQueue) Next() (interface{}, error) { - u.mu.Lock() - defer u.mu.Unlock() - if len(u.q) == 0 { - return nil, nil - } - // Incur a real delay if requested. - if u.duration > 0 { - time.Sleep(u.duration) - u.duration = 0 - } - v := u.q[0][0] - // Make a copy of the current proto message to return. - val := v.v - // Update the value. - if err := v.nextValue(); err != nil { - return nil, err - } - var checkDelay bool - // If this is the last update in the queue move to the next update set. - // else move to the next update in the same update set. - if len(u.q[0]) == 1 { - u.q = u.q[1:] - checkDelay = true - } else { - u.q[0] = u.q[0][1:] - } - // Add the updated value to the queue if the repeats are not exhausted. - if v.v != nil { - u.addValue(v) - } - // Set up a delay for the next retrieval if realtime delays are requested. - if u.delay && checkDelay && len(u.q) > 0 { - u.duration = time.Duration(u.q[0][0].v.Timestamp.Timestamp-val.Timestamp.Timestamp) * time.Nanosecond - } - return val, nil -} - -func (u *UpdateQueue) addValue(v *value) { - // If Timestamp was not provided create a default. - if v.v.Timestamp == nil { - v.v.Timestamp = &fpb.Timestamp{} - } - t := v.v.Timestamp.Timestamp - l, r := 0, len(u.q) - if t > u.latest { - u.latest = t - } - // Binary search for sorted placement in queue. - for { - if l == r { - // Insert a new list of updates for a new timestamp. - u.q = append(u.q[:r], append([][]*value{{v}}, u.q[r:]...)...) - return - } - i := (r-l)/2 + l - t2 := u.q[i][0].v.Timestamp.Timestamp - switch { - case t == t2: - // Append update to a list for an existing timestamp. - u.q[i] = append(u.q[i], v) - return - case t < t2: - r = i - case t > t2: - l = i + 1 - } - } -} - -type value struct { - v *fpb.Value // The configuration for a stream of updates for a single value. - r *rand.Rand // The PRNG used to generate subsequent updates for this value. -} - -func (v value) String() string { - return v.v.String() -} - -func newValue(v *fpb.Value, r *rand.Rand) *value { - if v.Seed == 0 { - return &value{v: v, r: r} - } - return &value{v: v, r: rand.New(rand.NewSource(v.Seed))} -} - -func (v *value) updateTimestamp() error { - if v.v.Timestamp == nil { - return fmt.Errorf("timestamp not set for %q", v.v) - } - t := v.v.Timestamp.Timestamp - if t < 0 { - return fmt.Errorf("timestamp must be positive for %q", v.v) - } - min, max := v.v.Timestamp.DeltaMin, v.v.Timestamp.DeltaMax - if min > max || min < 0 { - return fmt.Errorf("invalid delta_min/delta_max on timestamp for %q", v.v) - } - v.v.Timestamp.Timestamp = t + v.r.Int63n(max-min+1) + min - return nil -} - -func (v *value) updateIntValue() error { - val := v.v.GetIntValue() - if val == nil { - return fmt.Errorf("invalid IntValue for %q", v.v) - } - var newval int64 - switch val.Distribution.(type) { - case *fpb.IntValue_Range: - rng := val.GetRange() - if rng.Minimum > rng.Maximum { - return fmt.Errorf("invalid minimum/maximum in IntRange for %q", v.v) - } - if val.Value < rng.Minimum || val.Value > rng.Maximum { - return fmt.Errorf("value not in [minimum, maximum] in IntRange for %q", v.v) - } - - left, right := rng.GetMinimum(), rng.GetMaximum() - if rng.DeltaMin != 0 || rng.DeltaMax != 0 { - if rng.DeltaMin > rng.DeltaMax { - return fmt.Errorf("invalid delta_min/delta_max in IntRange for %q", v.v) - } - left, right = rng.GetDeltaMin(), rng.GetDeltaMax() - newval = val.Value - } - - newval += v.r.Int63n(right-left+1) + left - if newval > rng.Maximum { - newval = rng.Maximum - } - if newval < rng.Minimum { - newval = rng.Minimum - } - case *fpb.IntValue_List: - list := val.GetList() - options := list.GetOptions() - if len(options) == 0 { - return fmt.Errorf("missing options on IntValue_List for %q", v.v) - } - if list.GetRandom() { - newval = options[v.r.Intn(len(options))] - } else { - newval = options[0] - list.Options = append(options[1:], options[0]) - } - default: - newval = val.Value - } - val.Value = newval - return nil -} - -func (v *value) updateDoubleValue() error { - val := v.v.GetDoubleValue() - if val == nil { - return fmt.Errorf("invalid DoubleValue for %q", v.v) - } - var newval float64 - switch val.Distribution.(type) { - case *fpb.DoubleValue_Range: - rng := val.GetRange() - if rng.Minimum > rng.Maximum { - return fmt.Errorf("invalid minimum/maximum on DoubleValue_Range for %q", v.v) - } - if val.Value < rng.Minimum || val.Value > rng.Maximum { - return fmt.Errorf("value not in [minimum, maximum] on DoubleValue_Range for %q", v.v) - } - - left, right := rng.GetMinimum(), rng.GetMaximum() - if rng.DeltaMin != 0 || rng.DeltaMax != 0 { - if rng.DeltaMin > rng.DeltaMax { - return fmt.Errorf("invalid delta_min/delta_max on DoubleValue_Range for %q", v.v) - } - left, right = rng.GetDeltaMin(), rng.GetDeltaMax() - newval = val.Value - } - - newval += v.r.Float64()*(right-left) + left - if newval > rng.Maximum { - newval = rng.Maximum - } - if newval < rng.Minimum { - newval = rng.Minimum - } - case *fpb.DoubleValue_List: - list := val.GetList() - options := list.GetOptions() - if len(options) == 0 { - return fmt.Errorf("missing options on DoubleValue_List for %q", v.v) - } - if list.GetRandom() { - newval = options[v.r.Intn(len(options))] - } else { - newval = options[0] - list.Options = append(options[1:], options[0]) - } - default: - newval = val.Value - } - val.Value = newval - return nil -} - -func (v *value) updateStringValue() error { - val := v.v.GetStringValue() - if val == nil { - return fmt.Errorf("invalid StringValue for %q", v.v) - } - var newval string - switch val.Distribution.(type) { - case *fpb.StringValue_List: - list := val.GetList() - options := list.Options - if len(options) == 0 { - return fmt.Errorf("missing options on StringValue_List for %q", v.v) - } - if list.Random { - newval = options[v.r.Intn(len(options))] - } else { - newval = options[0] - list.Options = append(options[1:], options[0]) - } - default: - newval = val.Value - } - val.Value = newval - return nil -} - -func (v *value) updateBoolValue() error { - val := v.v.GetBoolValue() - if val == nil { - return fmt.Errorf("invalid BoolValue for %q", v.v) - } - var newval bool - switch val.Distribution.(type) { - case *fpb.BoolValue_List: - list := val.GetList() - options := list.Options - if len(options) == 0 { - return fmt.Errorf("missing options on BoolValue_List for %q", v.v) - } - if list.Random { - newval = options[v.r.Intn(len(options))] - } else { - newval = options[0] - list.Options = append(options[1:], options[0]) - } - default: - newval = val.Value - } - val.Value = newval - return nil -} - -func (v *value) nextValue() error { - if v.v.Repeat == 1 { - // This value has exhausted all of its updates, drop it. - v.v = nil - return nil - } - // Make a new proto message for the next value. - v.v = proto.Clone(v.v).(*fpb.Value) - if v.v.Repeat > 1 { - v.v.Repeat-- - } - if err := v.updateTimestamp(); err != nil { - return err - } - switch v.v.GetValue().(type) { - case *fpb.Value_IntValue: - return v.updateIntValue() - case *fpb.Value_DoubleValue: - return v.updateDoubleValue() - case *fpb.Value_StringValue: - return v.updateStringValue() - case *fpb.Value_BoolValue: - return v.updateBoolValue() - case *fpb.Value_Sync: - return nil - case *fpb.Value_Delete: - return nil - default: - return fmt.Errorf("value type not found in %q", v.v) - } -} - -// ValueOf returns the concrete value of v. -func ValueOf(v *fpb.Value) interface{} { - switch val := v.GetValue().(type) { - case *fpb.Value_IntValue: - return val.IntValue.Value - case *fpb.Value_DoubleValue: - return val.DoubleValue.Value - case *fpb.Value_StringValue: - return val.StringValue.Value - case *fpb.Value_BoolValue: - return val.BoolValue.Value - case *fpb.Value_Sync: - return val.Sync - case *fpb.Value_Delete: - return val.Delete - default: - return nil - } -} - -// TypedValueOf returns the gNMI TypedValue of v. If v is a Sync or Delete, -// TypedValueOf returns nil. -func TypedValueOf(v *fpb.Value) *gpb.TypedValue { - tv := &gpb.TypedValue{} - switch val := v.GetValue().(type) { - case *fpb.Value_IntValue: - tv.Value = &gpb.TypedValue_IntVal{val.IntValue.Value} - case *fpb.Value_DoubleValue: - tv.Value = &gpb.TypedValue_FloatVal{float32(val.DoubleValue.Value)} - case *fpb.Value_StringValue: - tv.Value = &gpb.TypedValue_StringVal{val.StringValue.Value} - case *fpb.Value_BoolValue: - tv.Value = &gpb.TypedValue_BoolVal{val.BoolValue.Value} - default: - return nil - } - return tv -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/queue/queue_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/queue/queue_test.go deleted file mode 100644 index 61494d976..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/queue/queue_test.go +++ /dev/null @@ -1,1081 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 queue - -import ( - "math/rand" - "reflect" - "testing" - "time" - - "github.com/kylelemons/godebug/pretty" - "github.com/openconfig/gnmi/errdiff" - - gpb "github.com/openconfig/gnmi/proto/gnmi" - fpb "github.com/openconfig/gnmi/testing/fake/proto" -) - -var seed = int64(100) - -func TestUpdateTimestamp(t *testing.T) { - tests := []struct { - desc string - in *fpb.Value - want *fpb.Timestamp - err string - }{{ - desc: "No timestamp", - in: &fpb.Value{}, - err: "timestamp not set", - }, { - desc: "Negative timestamp", - in: &fpb.Value{Timestamp: &fpb.Timestamp{Timestamp: -1}}, - err: "timestamp must be positive", - }, { - desc: "Invalid timestamp", - in: &fpb.Value{Timestamp: &fpb.Timestamp{Timestamp: 1234, DeltaMin: 2, DeltaMax: 1}}, - err: "invalid delta_min/delta_max on timestamp", - }, { - desc: "Valid timestamp", - in: &fpb.Value{ - Timestamp: &fpb.Timestamp{Timestamp: 1234, DeltaMin: 1, DeltaMax: 1}}, - want: &fpb.Timestamp{Timestamp: 1235, DeltaMin: 1, DeltaMax: 1}, - }, { - desc: "Using global seed", - in: &fpb.Value{ - Timestamp: &fpb.Timestamp{Timestamp: 1234, DeltaMin: 1, DeltaMax: 10}}, - want: &fpb.Timestamp{Timestamp: 1243, DeltaMin: 1, DeltaMax: 10}, - }, { - desc: "Using local seed", - in: &fpb.Value{ - Seed: 10, - Timestamp: &fpb.Timestamp{Timestamp: 1234, DeltaMin: 1, DeltaMax: 10}}, - want: &fpb.Timestamp{Timestamp: 1240, DeltaMin: 1, DeltaMax: 10}}, - } - - for _, tc := range tests { - t.Run(tc.desc, func(t *testing.T) { - v := newValue(tc.in, rand.New(rand.NewSource(seed))) - err := v.updateTimestamp() - if diff := errdiff.Substring(err, tc.err); diff != "" { - t.Errorf("newValue(%q).updateTimestamp() %v", tc.in, diff) - } - if diff := pretty.Compare(v.v.GetTimestamp(), tc.want); err == nil && diff != "" { - t.Errorf("newValue(%q).updateTimestamp() %v", tc.in, diff) - } - }) - } -} - -func TestUpdateIntValue(t *testing.T) { - tests := []struct { - desc string - value *fpb.Value - want *fpb.Value - err string - }{{ - desc: "Nil value", - value: &fpb.Value{}, - err: "invalid IntValue", - }, { - desc: "Invalid min/max in range", - value: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 50, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{Minimum: 100, Maximum: 0}}}}}, - err: "invalid minimum/maximum in IntRange", - }, { - desc: "Invalid init value (value < min) in range", - value: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: -100, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{Minimum: 0, Maximum: 100}}}}}, - err: "value not in [minimum, maximum] in IntRange", - }, { - desc: "Invalid init value (value > max) in range", - value: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 200, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{Minimum: 0, Maximum: 100}}}}}, - err: "value not in [minimum, maximum] in IntRange", - }, { - desc: "Invalid delta_min/delta_max in range", - value: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 50, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{Minimum: 0, Maximum: 100, DeltaMin: 10, DeltaMax: 5}}}}}, - err: "invalid delta_min/delta_max in IntRange", - }, { - desc: "Non-empty value, non-cumulative in range, using global seed", - value: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 50, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{Minimum: 0, Maximum: 100}}}}}, - want: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 65, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{Minimum: 0, Maximum: 100}}}}}, - }, { - desc: "Non-empty value, non-cumulative in range, using local seed", - value: &fpb.Value{ - Seed: 10, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 50, Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{Minimum: 0, Maximum: 100}}}}}, - want: &fpb.Value{ - Seed: 10, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 69, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{Minimum: 0, Maximum: 100}}}}}, - }, { - desc: "Non-empty value, cumulative in range", - value: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 50, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{Minimum: 0, Maximum: 100, DeltaMin: 10, DeltaMax: 10}}}}}, - want: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 60, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{Minimum: 0, Maximum: 100, DeltaMin: 10, DeltaMax: 10}}}}}, - }, { - desc: "Non-empty value, cumulative, maximum capped in range", - value: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 50, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{Minimum: 0, Maximum: 51, DeltaMin: 10, DeltaMax: 10}}}}}, - want: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 51, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{Minimum: 0, Maximum: 51, DeltaMin: 10, DeltaMax: 10}}}}}, - }, { - desc: "Non-empty value, cumulative, minimum capped in range", - value: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 50, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{Minimum: 45, Maximum: 60, DeltaMin: -10, DeltaMax: -10}}}}}, - want: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 45, - Distribution: &fpb.IntValue_Range{ - Range: &fpb.IntRange{Minimum: 45, Maximum: 60, DeltaMin: -10, DeltaMax: -10}}}}}, - }, { - desc: "no options, random in list", - value: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{Distribution: &fpb.IntValue_List{ - List: &fpb.IntList{Random: true}}}}}, - err: "missing options on IntValue_List", - }, { - desc: "four options, random in list", - value: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{Distribution: &fpb.IntValue_List{ - List: &fpb.IntList{Options: []int64{100, 200, 300, 400}, Random: true}}}}}, - want: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 400, - Distribution: &fpb.IntValue_List{ - List: &fpb.IntList{Options: []int64{100, 200, 300, 400}, Random: true}}}}}, - }, { - desc: "four options, non-random in list", - value: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{Distribution: &fpb.IntValue_List{ - List: &fpb.IntList{Options: []int64{100, 200, 300, 400}, Random: false}}}}}, - want: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 100, - Distribution: &fpb.IntValue_List{ - List: &fpb.IntList{Options: []int64{200, 300, 400, 100}, Random: false}}}}}, - }, { - desc: "constant", - value: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{Value: 100}}}, - want: &fpb.Value{ - Value: &fpb.Value_IntValue{&fpb.IntValue{Value: 100}}}, - }} - for _, tc := range tests { - t.Run(tc.desc, func(t *testing.T) { - v := newValue(tc.value, rand.New(rand.NewSource(seed))) - err := v.updateIntValue() - if diff := errdiff.Substring(err, tc.err); diff != "" { - t.Errorf("newValue(%q).updateIntValue() %v", tc.value, diff) - } - if diff := pretty.Compare(v.v, tc.want); err == nil && diff != "" { - t.Errorf("newValue(%q).updatedIntValue() %v", tc.value, diff) - } - }) - } -} - -func TestUpdateDoubleValue(t *testing.T) { - tests := []struct { - desc string - value *fpb.Value - want *fpb.Value - err string - }{{ - desc: "Nil Value", - value: &fpb.Value{}, - err: "invalid DoubleValue", - }, { - desc: "Invalid min/max in range", - value: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{ - Value: 50, - Distribution: &fpb.DoubleValue_Range{Range: &fpb.DoubleRange{Minimum: 100, Maximum: 0}}}}}, - err: "invalid minimum/maximum on DoubleValue_Range", - }, { - desc: "Invalid init value (value > max) in range", - value: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{ - Value: 200, - Distribution: &fpb.DoubleValue_Range{Range: &fpb.DoubleRange{Minimum: 0, Maximum: 100}}}}}, - err: "value not in [minimum, maximum] on DoubleValue_Range", - }, { - desc: "Invalid delta_min/delta_max in range", - value: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{ - Value: 50, - Distribution: &fpb.DoubleValue_Range{Range: &fpb.DoubleRange{Minimum: 0, Maximum: 100, DeltaMin: 10, DeltaMax: 5}}}}}, - err: "invalid delta_min/delta_max on DoubleValue_Range", - }, { - desc: "Non-empty value, non-cumulative in range, using global seed", - value: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{ - Value: 50, - Distribution: &fpb.DoubleValue_Range{Range: &fpb.DoubleRange{Minimum: 0, Maximum: 100}}}}}, - want: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{ - Value: 81.65026937796166, - Distribution: &fpb.DoubleValue_Range{Range: &fpb.DoubleRange{Minimum: 0, Maximum: 100}}}}}, - }, { - desc: "Non-empty value, non-cumulative in range, using local seed", - value: &fpb.Value{ - Seed: 10, - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{ - Value: 50, - Distribution: &fpb.DoubleValue_Range{Range: &fpb.DoubleRange{Minimum: 0, Maximum: 100}}}}}, - want: &fpb.Value{ - Seed: 10, - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{ - Value: 56.60920659323543, - Distribution: &fpb.DoubleValue_Range{ - Range: &fpb.DoubleRange{Minimum: 0, Maximum: 100}}}}}, - }, { - desc: "Non-empty value, cumulative in range", - value: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{ - Value: 50, - Distribution: &fpb.DoubleValue_Range{Range: &fpb.DoubleRange{Minimum: 0, Maximum: 100, DeltaMin: 10, DeltaMax: 10}}}}}, - want: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{ - Value: 60, - Distribution: &fpb.DoubleValue_Range{ - Range: &fpb.DoubleRange{Minimum: 0, Maximum: 100, DeltaMin: 10, DeltaMax: 10}}}}}, - }, { - desc: "Non-empty value, cumulative, maximum capped in range", - value: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{ - Value: 50, - Distribution: &fpb.DoubleValue_Range{Range: &fpb.DoubleRange{Minimum: 0, Maximum: 51, DeltaMin: 10, DeltaMax: 10}}}}}, - want: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{ - Value: 51, - Distribution: &fpb.DoubleValue_Range{ - Range: &fpb.DoubleRange{Minimum: 0, Maximum: 51, DeltaMin: 10, DeltaMax: 10}}}}}, - }, { - desc: "Non-empty value, cumulative, minimum capped in range", - value: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{ - Value: 50, - Distribution: &fpb.DoubleValue_Range{Range: &fpb.DoubleRange{Minimum: 45, Maximum: 60, DeltaMin: -10, DeltaMax: -10}}}}}, - want: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{ - Value: 45, - Distribution: &fpb.DoubleValue_Range{ - Range: &fpb.DoubleRange{Minimum: 45, Maximum: 60, DeltaMin: -10, DeltaMax: -10}}}}}, - }, { - desc: "no options, random in list", - value: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{Distribution: &fpb.DoubleValue_List{ - List: &fpb.DoubleList{Random: true}}}}}, - err: "missing options on DoubleValue_List", - }, { - desc: "four options, random in list, using global seed", - value: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{Distribution: &fpb.DoubleValue_List{ - List: &fpb.DoubleList{Options: []float64{100, 200, 300, 400}, Random: true}}}}}, - want: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{ - Value: 400, - Distribution: &fpb.DoubleValue_List{ - List: &fpb.DoubleList{Options: []float64{100, 200, 300, 400}, Random: true}}}}}, - }, { - desc: "four options, non-random in list, using global seed", - value: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{Distribution: &fpb.DoubleValue_List{ - List: &fpb.DoubleList{Options: []float64{100, 200, 300, 400}, Random: false}}}}}, - want: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{ - Value: 100, - Distribution: &fpb.DoubleValue_List{ - List: &fpb.DoubleList{Options: []float64{200, 300, 400, 100}, Random: false}}}}}, - }, { - desc: "constant", - value: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{Value: 100}}}, - want: &fpb.Value{ - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{Value: 100}}}, - }} - for _, tc := range tests { - t.Run(tc.desc, func(t *testing.T) { - v := newValue(tc.value, rand.New(rand.NewSource(seed))) - err := v.updateDoubleValue() - if diff := errdiff.Substring(err, tc.err); diff != "" { - t.Errorf("newValue(%q).updateDoubleValue() %v", tc.value, diff) - } - if err != nil { - return - } - if diff := pretty.Compare(v.v, tc.want); diff != "" { - t.Errorf("newValue(%q).updatedDoubleValue() %v", tc.value, diff) - } - }) - } -} - -func TestUpdateBoolValue(t *testing.T) { - tests := []struct { - desc string - value *fpb.Value - want *fpb.Value - err string - }{{ - desc: "Nil Value", - value: &fpb.Value{}, - err: "invalid BoolValue", - }, { - desc: "no options, random in list", - value: &fpb.Value{ - Value: &fpb.Value_BoolValue{&fpb.BoolValue{Distribution: &fpb.BoolValue_List{ - List: &fpb.BoolList{Random: true}}}}}, - err: "missing options on BoolValue_List", - }, { - desc: "Four options, random in list, using global seed", - value: &fpb.Value{ - Value: &fpb.Value_BoolValue{&fpb.BoolValue{Distribution: &fpb.BoolValue_List{ - List: &fpb.BoolList{Options: []bool{true, true, false, false}, Random: true}}}}}, - want: &fpb.Value{ - Value: &fpb.Value_BoolValue{&fpb.BoolValue{ - Value: false, - Distribution: &fpb.BoolValue_List{ - List: &fpb.BoolList{ - Options: []bool{true, true, false, false}, Random: true}}}}}, - }, { - desc: "Four options, random in list, using local seed", - value: &fpb.Value{ - Seed: 10, - Value: &fpb.Value_BoolValue{&fpb.BoolValue{Distribution: &fpb.BoolValue_List{ - List: &fpb.BoolList{Random: true, Options: []bool{true, true, false, false}}}}}}, - want: &fpb.Value{ - Seed: 10, - Value: &fpb.Value_BoolValue{&fpb.BoolValue{ - Value: false, - Distribution: &fpb.BoolValue_List{ - List: &fpb.BoolList{Random: true, Options: []bool{true, true, false, false}}}}}}, - }, { - desc: "Four options, non-random in list", - value: &fpb.Value{ - Value: &fpb.Value_BoolValue{&fpb.BoolValue{Distribution: &fpb.BoolValue_List{ - List: &fpb.BoolList{Random: false, Options: []bool{true, true, false, false}}}}}}, - want: &fpb.Value{ - Value: &fpb.Value_BoolValue{&fpb.BoolValue{ - Value: true, - Distribution: &fpb.BoolValue_List{ - List: &fpb.BoolList{Random: false, Options: []bool{true, false, false, true}}}}}}, - }, { - desc: "constant", - value: &fpb.Value{ - Value: &fpb.Value_BoolValue{&fpb.BoolValue{Value: true}}}, - want: &fpb.Value{ - Value: &fpb.Value_BoolValue{&fpb.BoolValue{Value: true}}}, - }} - for _, tc := range tests { - t.Run(tc.desc, func(t *testing.T) { - v := newValue(tc.value, rand.New(rand.NewSource(seed))) - err := v.updateBoolValue() - if diff := errdiff.Substring(err, tc.err); diff != "" { - t.Errorf("newValue(%q).updateBoolValue() %v", tc.value, diff) - } - if diff := pretty.Compare(v.v, tc.want); err == nil && diff != "" { - t.Errorf("newValue(%q).updatedBoolValue() %v", tc.value, diff) - } - }) - } -} - -func TestUpdateStringValue(t *testing.T) { - tests := []struct { - desc string - value *fpb.Value - want *fpb.Value - err string - }{{ - desc: "Nil Value", - value: &fpb.Value{}, - err: "invalid StringValue", - }, { - desc: "no options, random in list", - value: &fpb.Value{ - Value: &fpb.Value_StringValue{&fpb.StringValue{Distribution: &fpb.StringValue_List{ - List: &fpb.StringList{Random: true}}}}}, - err: "missing options on StringValue_List", - }, { - desc: "Four options, random in list, using global seed", - value: &fpb.Value{ - Value: &fpb.Value_StringValue{&fpb.StringValue{Distribution: &fpb.StringValue_List{ - List: &fpb.StringList{Options: []string{"a", "b", "c", "d"}, Random: true}}}}}, - want: &fpb.Value{ - Value: &fpb.Value_StringValue{&fpb.StringValue{ - Value: "d", - Distribution: &fpb.StringValue_List{ - List: &fpb.StringList{ - Options: []string{"a", "b", "c", "d"}, Random: true}}}}}, - }, { - desc: "Four options, random in list, using local seed", - value: &fpb.Value{ - Seed: 10, - Value: &fpb.Value_StringValue{&fpb.StringValue{Distribution: &fpb.StringValue_List{ - List: &fpb.StringList{Random: true, Options: []string{"a", "b", "c", "d"}}}}}}, - want: &fpb.Value{ - Seed: 10, - Value: &fpb.Value_StringValue{&fpb.StringValue{ - Value: "c", - Distribution: &fpb.StringValue_List{ - List: &fpb.StringList{Random: true, Options: []string{"a", "b", "c", "d"}}}}}}, - }, { - desc: "Four options, non-random in list", - value: &fpb.Value{ - Value: &fpb.Value_StringValue{&fpb.StringValue{Distribution: &fpb.StringValue_List{ - List: &fpb.StringList{Random: false, Options: []string{"a", "b", "c", "d"}}}}}}, - want: &fpb.Value{ - Value: &fpb.Value_StringValue{&fpb.StringValue{ - Value: "a", - Distribution: &fpb.StringValue_List{ - List: &fpb.StringList{Random: false, Options: []string{"b", "c", "d", "a"}}}}}}, - }, { - desc: "constant", - value: &fpb.Value{ - Value: &fpb.Value_StringValue{&fpb.StringValue{Value: "a"}}}, - want: &fpb.Value{ - Value: &fpb.Value_StringValue{&fpb.StringValue{Value: "a"}}}, - }} - for _, tc := range tests { - t.Run(tc.desc, func(t *testing.T) { - v := newValue(tc.value, rand.New(rand.NewSource(seed))) - err := v.updateStringValue() - if diff := errdiff.Substring(err, tc.err); diff != "" { - t.Errorf("newValue(%q).updateStringValue() %v", tc.value, diff) - } - if diff := pretty.Compare(v.v, tc.want); err == nil && diff != "" { - t.Errorf("newValue(%q).updatedStringValue() %v", tc.value, diff) - } - }) - } -} - -func TestNextValue(t *testing.T) { - tests := []struct { - desc string - in *fpb.Value - want *fpb.Value - err string - }{{ - desc: "Empty value", - in: &fpb.Value{}, - want: &fpb.Value{}, - err: "timestamp not set", - }, { - desc: "Just timestamp", - in: &fpb.Value{Timestamp: &fpb.Timestamp{Timestamp: 1234, DeltaMin: 1, DeltaMax: 1}}, - want: &fpb.Value{Timestamp: &fpb.Timestamp{Timestamp: 1235, DeltaMin: 1, DeltaMax: 1}}, - err: "value type not found", - }, { - desc: "Indefinite updates", - in: &fpb.Value{ - Timestamp: &fpb.Timestamp{Timestamp: 1234, DeltaMin: 1, DeltaMax: 1}, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 50, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{Minimum: 0, Maximum: 100}}}}}, - want: &fpb.Value{ - Timestamp: &fpb.Timestamp{Timestamp: 1235, DeltaMin: 1, DeltaMax: 1}, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 80, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{Minimum: 0, Maximum: 100}}}}}, - }, { - desc: "Repeat", - in: &fpb.Value{ - Repeat: 5, - Timestamp: &fpb.Timestamp{Timestamp: 1234, DeltaMin: 1, DeltaMax: 1}, - Value: &fpb.Value_IntValue{&fpb.IntValue{Distribution: &fpb.IntValue_List{List: &fpb.IntList{Options: []int64{10, 20, 30}, Random: false}}}}}, - want: &fpb.Value{ - Repeat: 4, - Timestamp: &fpb.Timestamp{Timestamp: 1235, DeltaMin: 1, DeltaMax: 1}, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 10, - Distribution: &fpb.IntValue_List{List: &fpb.IntList{Options: []int64{20, 30, 10}, Random: false}}}}}, - }, { - desc: "Repeat with constant double value", - in: &fpb.Value{ - Repeat: 5, - Timestamp: &fpb.Timestamp{Timestamp: 1234, DeltaMin: 1, DeltaMax: 1}, - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{Value: 50.1}}, - }, - want: &fpb.Value{ - Repeat: 4, - Timestamp: &fpb.Timestamp{Timestamp: 1235, DeltaMin: 1, DeltaMax: 1}, - Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{Value: 50.1}}, - }, - }, { - desc: "Last repeat", - in: &fpb.Value{ - Repeat: 1, - Timestamp: &fpb.Timestamp{Timestamp: 1234, DeltaMin: 1, DeltaMax: 1}, - Value: &fpb.Value_IntValue{&fpb.IntValue{Value: 50}}, - }, - }, { - desc: "Last repeat with constant string value", - in: &fpb.Value{ - Repeat: 1, - Timestamp: &fpb.Timestamp{Timestamp: 1234, DeltaMin: 1, DeltaMax: 1}, - Value: &fpb.Value_StringValue{&fpb.StringValue{Value: "a"}}, - }, - }, { - desc: "String value", - in: &fpb.Value{ - Repeat: 2, - Timestamp: &fpb.Timestamp{Timestamp: 1234}, - Value: &fpb.Value_StringValue{&fpb.StringValue{Value: "a"}}, - }, - want: &fpb.Value{ - Repeat: 1, - Timestamp: &fpb.Timestamp{Timestamp: 1234}, - Value: &fpb.Value_StringValue{&fpb.StringValue{Value: "a"}}, - }, - }, { - desc: "Sync value", - in: &fpb.Value{ - Repeat: 2, - Timestamp: &fpb.Timestamp{Timestamp: 1234}, - Value: &fpb.Value_Sync{uint64(1)}, - }, - want: &fpb.Value{ - Repeat: 1, - Timestamp: &fpb.Timestamp{Timestamp: 1234}, - Value: &fpb.Value_Sync{uint64(1)}, - }, - }, { - desc: "Delete value", - in: &fpb.Value{ - Repeat: 2, - Timestamp: &fpb.Timestamp{Timestamp: 1234}, - Value: &fpb.Value_Delete{&fpb.DeleteValue{}}, - }, - want: &fpb.Value{ - Repeat: 1, - Timestamp: &fpb.Timestamp{Timestamp: 1234}, - Value: &fpb.Value_Delete{&fpb.DeleteValue{}}, - }, - }} - for _, tc := range tests { - t.Run(tc.desc, func(t *testing.T) { - v := newValue(tc.in, rand.New(rand.NewSource(seed))) - err := v.nextValue() - if diff := errdiff.Substring(err, tc.err); diff != "" { - t.Errorf("newValue(%q).nextValue() %v", tc.in, diff) - } - if diff := pretty.Compare(v.v, tc.want); err == nil && diff != "" { - t.Errorf("value of newValue(%q).nextValue() %v", tc.in, diff) - } - }) - } -} - -func TestEmptyQueue(t *testing.T) { - q := New(false, seed, nil) - u, err := q.Next() - if err != nil { - t.Fatalf("New(false, nil).Next() unexpected error: got %q, want nil", err) - } - if u != nil { - t.Errorf("New(false, nil).Next() got %v, want nil", u) - } -} - -func TestQueueFiniteUpdates(t *testing.T) { - for _, x := range []int{1, 5, 100} { - in := &fpb.Value{ - Repeat: int32(x), - Timestamp: &fpb.Timestamp{ - Timestamp: 1234, - DeltaMin: 1, - DeltaMax: 1, - }, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 50, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{ - Minimum: 0, - Maximum: 100, - }}}}, - } - q := New(false, seed, []*fpb.Value{in}) - for i := 0; i < x; i++ { - u, err := q.Next() - if err != nil { - continue - } - if u == nil { - t.Errorf("New(false, %q).Next() got nil, expected an update %d of %d", in, i, x) - } - } - // Try one more time to valid nil next value. - u, err := q.Next() - if err != nil { - t.Errorf("New(false, %q).Next() unexpected error: got %q for %d updates", in, err, x) - } - if u != nil { - t.Errorf("New(false, %q).Next() got update %v, want nil for %d updates", in, u, x) - } - } -} - -func TestQueueInfiniteUpdates(t *testing.T) { - in := &fpb.Value{ - Timestamp: &fpb.Timestamp{ - Timestamp: 1234, - DeltaMin: 1, - DeltaMax: 1, - }, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 50, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{ - Minimum: 0, - Maximum: 100, - }}}}, - } - q := New(false, seed, []*fpb.Value{in}) - // Not really infinite testing, but without repeat set as above, should - // continue indefinitely. We check a large definite number as a proxy. - for i := 0; i < 10000; i++ { - u, err := q.Next() - if err != nil { - t.Errorf("New(false, %q).Next() unexpected error: got %q trying to receive update %d from an infinite queue", in, err, i) - continue - } - if u == nil { - t.Errorf("New(false, %q).Next() got nil, want update %d from an infinite queue", in, i) - } - } -} - -func TestQueueDelay(t *testing.T) { - in := &fpb.Value{ - Timestamp: &fpb.Timestamp{ - Timestamp: 1234, - DeltaMin: 250 * time.Millisecond.Nanoseconds(), - DeltaMax: 250 * time.Millisecond.Nanoseconds(), - }, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 50, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{ - Minimum: 0, - Maximum: 100, - }}}}, - } - q := New(true, seed, []*fpb.Value{in}) - // No delay to get the first value. - if _, err := q.Next(); err != nil { - t.Errorf("New(true, %q).Next() unexpected error: got %q receiving a value from an infinite queue", in, err) - } - b := time.Now() - // Second value should be delayed 250ms. - if _, err := q.Next(); err != nil { - t.Errorf("New(true, %q).Next() unexpected error: got %q receiving a value from an infinite queue", in, err) - } - if e := time.Since(b); e < 250*time.Millisecond { - t.Errorf("New(true, %q).Next() got delayed %dms, want delay >= 250ms", in, e/time.Millisecond) - } -} - -func TestQueueAddValue(t *testing.T) { - in := []*fpb.Value{{ - Repeat: 1, - Timestamp: &fpb.Timestamp{ - Timestamp: 2, - }, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 50, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{ - Minimum: 0, - Maximum: 100, - }}}}, - }, { - Repeat: 1, - Timestamp: &fpb.Timestamp{ - Timestamp: 1, - }, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 50, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{ - Minimum: 0, - Maximum: 100, - }}}}, - }, { - Repeat: 1, - Timestamp: &fpb.Timestamp{ - Timestamp: 3, - }, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 50, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{ - Minimum: 0, - Maximum: 100, - }}}}, - }, { - Repeat: 1, - Timestamp: &fpb.Timestamp{ - Timestamp: 3, - }, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 60, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{ - Minimum: 0, - Maximum: 100, - }}}}, - }, { - Repeat: 1, - Timestamp: &fpb.Timestamp{ - Timestamp: 1, - }, - Value: &fpb.Value_IntValue{&fpb.IntValue{ - Value: 60, - Distribution: &fpb.IntValue_Range{Range: &fpb.IntRange{ - Minimum: 0, - Maximum: 100, - }}}}, - }} - q := New(true, seed, in) - if got, want := q.Latest(), int64(3); got != want { - t.Errorf("New(true, %q) unexpected Latest(): got %q, want %q", in, got, want) - } - if len(q.q) != 3 { - t.Errorf("New(true, %q) unexpected value set: got %q, want %q", in, q.q, in) - } - for i, q := range q.q { - t.Logf("queue:%d %q", i, q[0].v) - if q[0].v.Timestamp.Timestamp != int64(i+1) { - t.Errorf("New(true, %q) unexpected value set: got %q, want Timestamp=%d", in, q[0].v, i+1) - } - } - for i := 0; i < len(in); i++ { - if _, err := q.Next(); err != nil { - t.Errorf("New(true, %q).Next() unexpected error: got %q, want nil", in, err) - } - } - u, err := q.Next() - if err != nil { - t.Errorf("New(true, %q).Next() unexpected error: got %q, want nil", in, u) - } - if u != nil { - t.Errorf("New(true, %q).Next() unexpected update: got %q, want nil", in, u) - } -} - -func TestValueOf(t *testing.T) { - tests := []struct { - desc string - in *fpb.Value - want interface{} - }{{ - desc: "string value", - in: &fpb.Value{Value: &fpb.Value_StringValue{&fpb.StringValue{Value: "UP"}}}, - want: "UP", - }, { - desc: "int value", - in: &fpb.Value{Value: &fpb.Value_IntValue{&fpb.IntValue{Value: 100}}}, - want: int64(100), - }, { - desc: "double value", - in: &fpb.Value{Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{Value: float64(101)}}}, - want: float64(101), - }, { - desc: "Delete value", - in: &fpb.Value{Value: &fpb.Value_Delete{&fpb.DeleteValue{}}}, - want: &fpb.DeleteValue{}, - }, { - desc: "Sync value", - in: &fpb.Value{Value: &fpb.Value_Sync{uint64(1)}}, - want: uint64(1), - }, { - desc: "Bool value", - in: &fpb.Value{Value: &fpb.Value_BoolValue{&fpb.BoolValue{Value: true}}}, - want: true, - }} - for _, tc := range tests { - t.Run(tc.desc, func(t *testing.T) { - if got, want := ValueOf(tc.in), tc.want; !reflect.DeepEqual(got, want) { - t.Errorf("ValueOf(%q) failed: got %q, want %q", tc.in, got, want) - } - }) - } -} - -func TestFixedQueue(t *testing.T) { - tests := []struct { - desc string - in []*gpb.SubscribeResponse - delay bool - want *gpb.TypedValue - updates []*gpb.SubscribeResponse - }{{ - desc: "empty notifications", - }, { - desc: "single sync", - in: []*gpb.SubscribeResponse{{ - Response: &gpb.SubscribeResponse_SyncResponse{ - SyncResponse: true, - }, - }}, - }, { - desc: "sync then updates", - in: []*gpb.SubscribeResponse{{ - Response: &gpb.SubscribeResponse_SyncResponse{ - SyncResponse: true, - }, - }, { - Response: &gpb.SubscribeResponse_Update{ - Update: &gpb.Notification{ - Timestamp: 1, - Update: []*gpb.Update{{ - Path: &gpb.Path{Element: []string{"a", "b"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 1}}, - }, { - Path: &gpb.Path{Element: []string{"a", "c"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 2}}, - }}, - }, - }, - }}, - }, { - desc: "sync then updates with add", - in: []*gpb.SubscribeResponse{{ - Response: &gpb.SubscribeResponse_SyncResponse{ - SyncResponse: true, - }, - }, { - Response: &gpb.SubscribeResponse_Update{ - Update: &gpb.Notification{ - Timestamp: 1, - Update: []*gpb.Update{{ - Path: &gpb.Path{Element: []string{"a", "b"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 1}}, - }, { - Path: &gpb.Path{Element: []string{"a", "c"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 2}}, - }}, - }, - }, - }}, - updates: []*gpb.SubscribeResponse{{ - Response: &gpb.SubscribeResponse_Update{ - Update: &gpb.Notification{ - Timestamp: 100, - Update: []*gpb.Update{{ - Path: &gpb.Path{Element: []string{"a", "b"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 10}}, - }, { - Path: &gpb.Path{Element: []string{"a", "c"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 20}}, - }}, - }, - }, - }}, - }, { - desc: "multi update sync", - in: []*gpb.SubscribeResponse{{ - Response: &gpb.SubscribeResponse_SyncResponse{ - SyncResponse: true, - }, - }, { - Response: &gpb.SubscribeResponse_Update{ - Update: &gpb.Notification{ - Timestamp: 1, - Update: []*gpb.Update{{ - Path: &gpb.Path{Element: []string{"a", "b"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 1}}, - }, { - Path: &gpb.Path{Element: []string{"a", "c"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 2}}, - }}, - }, - }, - }, { - Response: &gpb.SubscribeResponse_Update{ - Update: &gpb.Notification{ - Timestamp: 2, - Update: []*gpb.Update{{ - Path: &gpb.Path{Element: []string{"a", "b"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 10}}, - }, { - Path: &gpb.Path{Element: []string{"a", "c"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 20}}, - }}, - }, - }, - }}, - }, { - desc: "multi update sync with delay", - delay: true, - in: []*gpb.SubscribeResponse{{ - Response: &gpb.SubscribeResponse_SyncResponse{ - SyncResponse: true, - }, - }, { - Response: &gpb.SubscribeResponse_Update{ - Update: &gpb.Notification{ - Timestamp: 1, - Update: []*gpb.Update{{ - Path: &gpb.Path{Element: []string{"a", "b"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 1}}, - }, { - Path: &gpb.Path{Element: []string{"a", "c"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 2}}, - }}, - }, - }, - }, { - Response: &gpb.SubscribeResponse_Update{ - Update: &gpb.Notification{ - Timestamp: 2, - Update: []*gpb.Update{{ - Path: &gpb.Path{Element: []string{"a", "b"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 10}}, - }, { - Path: &gpb.Path{Element: []string{"a", "c"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 20}}, - }}, - }, - }, - }}, - }, { - desc: "multi update sync with delay ", - delay: true, - in: []*gpb.SubscribeResponse{{ - Response: &gpb.SubscribeResponse_SyncResponse{ - SyncResponse: true, - }, - }, { - Response: &gpb.SubscribeResponse_Update{ - Update: &gpb.Notification{ - Timestamp: 2, - Update: []*gpb.Update{{ - Path: &gpb.Path{Element: []string{"a", "b"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 1}}, - }, { - Path: &gpb.Path{Element: []string{"a", "c"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 2}}, - }}, - }, - }, - }, { - Response: &gpb.SubscribeResponse_Update{ - Update: &gpb.Notification{ - Timestamp: 1, - Update: []*gpb.Update{{ - Path: &gpb.Path{Element: []string{"a", "b"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 10}}, - }, { - Path: &gpb.Path{Element: []string{"a", "c"}}, - Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 20}}, - }}, - }, - }, - }}, - }} - for _, tc := range tests { - t.Run(tc.desc, func(t *testing.T) { - want := make([]*gpb.SubscribeResponse, len(tc.in)) - copy(want, tc.in) - q := NewFixed(want, tc.delay) - for _, u := range tc.updates { - q.Add(u) - want = append(want, u) - } - var got []*gpb.SubscribeResponse - Loop: - for { - v, err := q.Next() - switch { - case err != nil: - t.Fatalf("NewFixed(%q, %v).Next() unexpected error: got %q, want nil", want, tc.delay, err) - case v == nil: - break Loop - } - got = append(got, v.(*gpb.SubscribeResponse)) - } - if gotL, wantL := len(got), len(want); gotL != wantL { - t.Fatalf("q.Next() failed: got length(%d), want length(%d): %v", gotL, wantL, got) - } - }) - } -} - -func TestTypedValueOf(t *testing.T) { - tests := []struct { - desc string - in *fpb.Value - want *gpb.TypedValue - }{{ - desc: "string value", - in: &fpb.Value{Value: &fpb.Value_StringValue{&fpb.StringValue{Value: "UP"}}}, - want: &gpb.TypedValue{Value: &gpb.TypedValue_StringVal{"UP"}}, - }, { - desc: "int value", - in: &fpb.Value{Value: &fpb.Value_IntValue{&fpb.IntValue{Value: 100}}}, - want: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{int64(100)}}, - }, { - desc: "double value", - in: &fpb.Value{Value: &fpb.Value_DoubleValue{&fpb.DoubleValue{Value: float64(101)}}}, - want: &gpb.TypedValue{Value: &gpb.TypedValue_FloatVal{float32(101)}}, - }, { - desc: "delete value", - in: &fpb.Value{Value: &fpb.Value_Delete{&fpb.DeleteValue{}}}, - want: nil, - }, { - desc: "sync value", - in: &fpb.Value{Value: &fpb.Value_Sync{uint64(1)}}, - want: nil, - }, { - desc: "bool value", - in: &fpb.Value{Value: &fpb.Value_BoolValue{&fpb.BoolValue{Value: true}}}, - want: &gpb.TypedValue{Value: &gpb.TypedValue_BoolVal{true}}, - }} - for _, tc := range tests { - t.Run(tc.desc, func(t *testing.T) { - if got, want := TypedValueOf(tc.in), tc.want; !reflect.DeepEqual(got, want) { - t.Errorf("TypedValueOf(%q) failed: got %q, want %q", tc.in, got, want) - } - }) - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/testing/grpc/config/config_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/testing/grpc/config/config_test.go deleted file mode 100644 index f3a63795b..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/testing/grpc/config/config_test.go +++ /dev/null @@ -1,28 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 ( - "testing" -) - -func TestWithSelfTLSCert(t *testing.T) { - _, err := WithSelfTLSCert() - if err != nil { - t.Fatalf("WithSelfTLSCert() failed: %v", err) - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/testing/grpc/config/server_option.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/testing/grpc/config/server_option.go deleted file mode 100644 index 253505aff..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/testing/grpc/config/server_option.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 provides gRPC configuration methods used by tests to -// facilitate easier setup of gRPC clients and servers. -package config - -import ( - "crypto/tls" - - "google.golang.org/grpc/credentials" - "google.golang.org/grpc" - - gtls "github.com/openconfig/gnmi/testing/fake/testing/tls" -) - -// WithSelfTLSCert generates a new self-signed in-memory TLS certificate and -// returns a grpc.ServerOption containing it. This is only for use in tests. -func WithSelfTLSCert() (grpc.ServerOption, error) { - cert, err := gtls.NewCert() - if err != nil { - return nil, err - } - return grpc.Creds(credentials.NewTLS(&tls.Config{ - Certificates: []tls.Certificate{cert}, - })), nil -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/unimplemented/unimplemented.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/unimplemented/unimplemented.go deleted file mode 100644 index adbd2c9f6..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/unimplemented/unimplemented.go +++ /dev/null @@ -1,77 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 unimplemented provides a convenience type to stub out unimplemented -// gNMI RPCs. -package unimplemented - -import ( - "context" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc" - "google.golang.org/grpc/status" - - pb "github.com/openconfig/gnmi/proto/gnmi" -) - -// Server is a type that can be embedded anonymously in a gNMI server to stub -// out all RPCs that are not implemented with a proper return code. -type Server struct{} - -// Capabilities satisfies the gNMI service definition. -func (*Server) Capabilities(context.Context, *pb.CapabilityRequest) (*pb.CapabilityResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "Unimplemented") -} - -// Get satisfies the gNMI service definition. -func (*Server) Get(context.Context, *pb.GetRequest) (*pb.GetResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "Unimplemented") -} - -// Set satisfies the gNMI service definition. -func (*Server) Set(context.Context, *pb.SetRequest) (*pb.SetResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "Unimplemented") -} - -// Subscribe satisfies the gNMI service definition. -func (s *Server) Subscribe(stream pb.GNMI_SubscribeServer) error { - return status.Errorf(codes.Unimplemented, "Unimplemented") -} - -// Client is a type that can be embedded anonymously in a gNMI client to stub -// out all RPCs that are not implemented with a proper return code. -type Client struct{} - -// Capabilities satisfies the gNMI client definition. -func (*Client) Capabilities(ctx context.Context, in *pb.CapabilityRequest, opts ...grpc.CallOption) (*pb.CapabilityResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "Unimplemented") -} - -// Get satisfies the gNMI client definition. -func (*Client) Get(ctx context.Context, in *pb.GetRequest, opts ...grpc.CallOption) (*pb.GetResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "Unimplemented") -} - -// Set satisfies the gNMI client definition. -func (*Client) Set(ctx context.Context, in *pb.SetRequest, opts ...grpc.CallOption) (*pb.SetResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "Unimplemented") -} - -// Subscribe satisfies the gNMI client definition. -func (*Client) Subscribe(ctx context.Context, opts ...grpc.CallOption) (pb.GNMI_SubscribeClient, error) { - return nil, status.Errorf(codes.Unimplemented, "Unimplemented") -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/value/value.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/value/value.go deleted file mode 100644 index f4de35188..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/value/value.go +++ /dev/null @@ -1,199 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 value provides utility functions for working with gNMI TypedValue -// messages. -package value - -import ( - "fmt" - "math" - "unicode/utf8" - - pb "github.com/openconfig/gnmi/proto/gnmi" -) - -// FromScalar will convert common scalar types to their TypedValue equivalent. -// It will return an error if the type cannot be mapped to a scalar value. -func FromScalar(i interface{}) (*pb.TypedValue, error) { - tv := &pb.TypedValue{} - switch v := i.(type) { - case string: - if utf8.ValidString(v) { - tv.Value = &pb.TypedValue_StringVal{v} - } else { - return nil, fmt.Errorf("string %q contains non-UTF-8 bytes", v) - } - case int: - tv.Value = &pb.TypedValue_IntVal{int64(v)} - case int8: - tv.Value = &pb.TypedValue_IntVal{int64(v)} - case int16: - tv.Value = &pb.TypedValue_IntVal{int64(v)} - case int32: - tv.Value = &pb.TypedValue_IntVal{int64(v)} - case int64: - tv.Value = &pb.TypedValue_IntVal{v} - case uint: - tv.Value = &pb.TypedValue_UintVal{uint64(v)} - case uint8: - tv.Value = &pb.TypedValue_UintVal{uint64(v)} - case uint16: - tv.Value = &pb.TypedValue_UintVal{uint64(v)} - case uint32: - tv.Value = &pb.TypedValue_UintVal{uint64(v)} - case uint64: - tv.Value = &pb.TypedValue_UintVal{v} - case float32: - tv.Value = &pb.TypedValue_FloatVal{v} - case float64: - tv.Value = &pb.TypedValue_FloatVal{float32(v)} - case bool: - tv.Value = &pb.TypedValue_BoolVal{v} - case []string: - sa := &pb.ScalarArray{Element: make([]*pb.TypedValue, len(v))} - for x, s := range v { - sa.Element[x] = &pb.TypedValue{Value: &pb.TypedValue_StringVal{s}} - } - tv.Value = &pb.TypedValue_LeaflistVal{sa} - case []byte: - tv.Value = &pb.TypedValue_BytesVal{v} - case []interface{}: - sa := &pb.ScalarArray{Element: make([]*pb.TypedValue, len(v))} - var err error - for x, intf := range v { - sa.Element[x], err = FromScalar(intf) - if err != nil { - return nil, fmt.Errorf("in []interface{}: %v", err) - } - } - tv.Value = &pb.TypedValue_LeaflistVal{sa} - default: - return nil, fmt.Errorf("non-scalar type %+v", i) - } - return tv, nil -} - -// ToScalar will convert TypedValue scalar types to a Go native type. It will -// return an error if the TypedValue does not contain a scalar type. -func ToScalar(tv *pb.TypedValue) (interface{}, error) { - var i interface{} - switch tv.Value.(type) { - case *pb.TypedValue_DecimalVal: - i = decimalToFloat(tv.GetDecimalVal()) - case *pb.TypedValue_StringVal: - i = tv.GetStringVal() - case *pb.TypedValue_IntVal: - i = tv.GetIntVal() - case *pb.TypedValue_UintVal: - i = tv.GetUintVal() - case *pb.TypedValue_BoolVal: - i = tv.GetBoolVal() - case *pb.TypedValue_FloatVal: - i = tv.GetFloatVal() - case *pb.TypedValue_LeaflistVal: - elems := tv.GetLeaflistVal().GetElement() - ss := make([]interface{}, len(elems)) - for x, e := range elems { - v, err := ToScalar(e) - if err != nil { - return nil, fmt.Errorf("ToScalar for ScalarArray %+v: %v", e.Value, err) - } - ss[x] = v - } - i = ss - case *pb.TypedValue_BytesVal: - i = tv.GetBytesVal() - case *pb.TypedValue_JsonIetfVal: - i = string(tv.GetJsonIetfVal()) - default: - return nil, fmt.Errorf("non-scalar type %+v", tv.Value) - } - return i, nil -} - -// decimalToFloat converts a *gnmi_proto.Decimal64 to a float32. Downcasting to -// float32 is performed as the precision of a float64 is not required. -func decimalToFloat(d *pb.Decimal64) float32 { - return float32(float64(d.Digits) / math.Pow(10, float64(d.Precision))) -} - -// Equal returns true if the values in a and b are the same. This method -// handles only the primitive types and ScalarArrays and returns false for all -// other types. -func Equal(a, b *pb.TypedValue) bool { - switch av := a.Value.(type) { - case *pb.TypedValue_StringVal: - bv, ok := b.Value.(*pb.TypedValue_StringVal) - if !ok { - return false - } - return av.StringVal == bv.StringVal - case *pb.TypedValue_IntVal: - bv, ok := b.Value.(*pb.TypedValue_IntVal) - if !ok { - return false - } - return av.IntVal == bv.IntVal - case *pb.TypedValue_UintVal: - bv, ok := b.Value.(*pb.TypedValue_UintVal) - if !ok { - return false - } - return av.UintVal == bv.UintVal - case *pb.TypedValue_BoolVal: - bv, ok := b.Value.(*pb.TypedValue_BoolVal) - if !ok { - return false - } - return av.BoolVal == bv.BoolVal - case *pb.TypedValue_BytesVal: - bv, ok := b.Value.(*pb.TypedValue_BytesVal) - if !ok { - return false - } - return string(av.BytesVal) == string(bv.BytesVal) - case *pb.TypedValue_FloatVal: - bv, ok := b.Value.(*pb.TypedValue_FloatVal) - if !ok { - return false - } - return av.FloatVal == bv.FloatVal - case *pb.TypedValue_DecimalVal: - bv, ok := b.Value.(*pb.TypedValue_DecimalVal) - if !ok { - return false - } - return av.DecimalVal.Digits == bv.DecimalVal.Digits && av.DecimalVal.Precision == bv.DecimalVal.Precision - case *pb.TypedValue_LeaflistVal: - bv, ok := b.Value.(*pb.TypedValue_LeaflistVal) - if !ok { - return false - } - ae, be := av.LeaflistVal.Element, bv.LeaflistVal.Element - if len(ae) != len(be) { - return false - } - for i := range ae { - if !Equal(ae[i], be[i]) { - return false - } - } - return true - } - // Types that are not primitive or ScalarArray are not considered. - return false -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/value/value_test.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/value/value_test.go deleted file mode 100644 index 63605af6f..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/value/value_test.go +++ /dev/null @@ -1,338 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 value - -import ( - "reflect" - "testing" - - "github.com/golang/protobuf/proto" - "github.com/golang/protobuf/ptypes" - pb "github.com/openconfig/gnmi/proto/gnmi" -) - -type scalarTest struct { - intf interface{} - msg *pb.TypedValue - err bool -} - -func TestFromScalar(t *testing.T) { - tests := []scalarTest{ - {intf: "foo", msg: &pb.TypedValue{Value: &pb.TypedValue_StringVal{"foo"}}}, - {intf: "a longer multiword string", msg: &pb.TypedValue{Value: &pb.TypedValue_StringVal{"a longer multiword string"}}}, - {intf: 500, msg: &pb.TypedValue{Value: &pb.TypedValue_IntVal{500}}}, - {intf: int8(50), msg: &pb.TypedValue{Value: &pb.TypedValue_IntVal{50}}}, - {intf: int16(500), msg: &pb.TypedValue{Value: &pb.TypedValue_IntVal{500}}}, - {intf: int32(500), msg: &pb.TypedValue{Value: &pb.TypedValue_IntVal{500}}}, - {intf: int64(500), msg: &pb.TypedValue{Value: &pb.TypedValue_IntVal{500}}}, - {intf: uint(500), msg: &pb.TypedValue{Value: &pb.TypedValue_UintVal{500}}}, - {intf: uint8(50), msg: &pb.TypedValue{Value: &pb.TypedValue_UintVal{50}}}, - {intf: uint16(500), msg: &pb.TypedValue{Value: &pb.TypedValue_UintVal{500}}}, - {intf: uint32(500), msg: &pb.TypedValue{Value: &pb.TypedValue_UintVal{500}}}, - {intf: uint64(500), msg: &pb.TypedValue{Value: &pb.TypedValue_UintVal{500}}}, - {intf: float32(3.5), msg: &pb.TypedValue{Value: &pb.TypedValue_FloatVal{3.5}}}, - {intf: true, msg: &pb.TypedValue{Value: &pb.TypedValue_BoolVal{true}}}, - {intf: false, msg: &pb.TypedValue{Value: &pb.TypedValue_BoolVal{false}}}, - {intf: float64(3.5), msg: &pb.TypedValue{Value: &pb.TypedValue_FloatVal{3.5}}}, - {intf: []byte("foo"), msg: &pb.TypedValue{Value: &pb.TypedValue_BytesVal{[]byte("foo")}}}, - {intf: "a non-utf-8 string \377", err: true}, - { - intf: []string{"a", "b"}, - msg: &pb.TypedValue{Value: &pb.TypedValue_LeaflistVal{&pb.ScalarArray{ - Element: []*pb.TypedValue{ - {Value: &pb.TypedValue_StringVal{"a"}}, - {Value: &pb.TypedValue_StringVal{"b"}}, - }, - }}}, - }, - { - intf: []string{}, - msg: &pb.TypedValue{Value: &pb.TypedValue_LeaflistVal{&pb.ScalarArray{}}}, - }, - { - intf: []interface{}{"a", "b"}, - msg: &pb.TypedValue{Value: &pb.TypedValue_LeaflistVal{&pb.ScalarArray{ - Element: []*pb.TypedValue{ - {Value: &pb.TypedValue_StringVal{"a"}}, - {Value: &pb.TypedValue_StringVal{"b"}}, - }, - }}}, - }, - { - intf: []interface{}{}, - msg: &pb.TypedValue{Value: &pb.TypedValue_LeaflistVal{&pb.ScalarArray{}}}, - }, - { - intf: []interface{}{"a", 1}, - msg: &pb.TypedValue{Value: &pb.TypedValue_LeaflistVal{&pb.ScalarArray{ - Element: []*pb.TypedValue{ - {Value: &pb.TypedValue_StringVal{"a"}}, - {Value: &pb.TypedValue_IntVal{1}}, - }, - }}}, - }, - } - for _, tt := range tests { - v, err := FromScalar(tt.intf) - switch { - case tt.err: - if err == nil { - t.Errorf("FromScalar(%v): got nil, wanted err", tt.intf) - } - case err != nil: - t.Errorf("FromScalar(%v): got error %v, want %s", tt.intf, err, tt.msg) - case !proto.Equal(v, tt.msg): - t.Errorf("FromScalar(%v): got %s, want %s", tt.intf, v, tt.msg) - } - } -} - -func TestToScalar(t *testing.T) { - tests := []scalarTest{ - {intf: "foo", msg: &pb.TypedValue{Value: &pb.TypedValue_StringVal{"foo"}}}, - {intf: "a longer multiword string", msg: &pb.TypedValue{Value: &pb.TypedValue_StringVal{"a longer multiword string"}}}, - {intf: int64(500), msg: &pb.TypedValue{Value: &pb.TypedValue_IntVal{500}}}, - {intf: uint64(500), msg: &pb.TypedValue{Value: &pb.TypedValue_UintVal{500}}}, - {intf: float32(3.5), msg: &pb.TypedValue{Value: &pb.TypedValue_FloatVal{3.5}}}, - {intf: true, msg: &pb.TypedValue{Value: &pb.TypedValue_BoolVal{true}}}, - {intf: false, msg: &pb.TypedValue{Value: &pb.TypedValue_BoolVal{false}}}, - { - msg: &pb.TypedValue{Value: &pb.TypedValue_LeaflistVal{&pb.ScalarArray{ - Element: []*pb.TypedValue{ - {Value: &pb.TypedValue_StringVal{"a"}}, - {Value: &pb.TypedValue_StringVal{"b"}}, - }, - }}}, - intf: []interface{}{"a", "b"}, - }, - { - msg: &pb.TypedValue{Value: &pb.TypedValue_LeaflistVal{&pb.ScalarArray{}}}, - intf: []interface{}{}, - }, - { - msg: &pb.TypedValue{Value: &pb.TypedValue_LeaflistVal{}}, - intf: []interface{}{}, - }, - { - msg: &pb.TypedValue{Value: &pb.TypedValue_LeaflistVal{&pb.ScalarArray{ - Element: []*pb.TypedValue{ - {Value: &pb.TypedValue_StringVal{"a"}}, - {Value: &pb.TypedValue_IntVal{1}}, - {Value: &pb.TypedValue_UintVal{1}}, - }, - }}}, - intf: []interface{}{"a", int64(1), uint64(1)}, - }, - {intf: []byte("foo"), msg: &pb.TypedValue{Value: &pb.TypedValue_BytesVal{[]byte("foo")}}}, - { - msg: &pb.TypedValue{ - Value: &pb.TypedValue_DecimalVal{ - DecimalVal: &pb.Decimal64{ - Digits: 312, - Precision: 1, - }, - }, - }, - intf: float32(31.2), - }, - { - msg: &pb.TypedValue{ - Value: &pb.TypedValue_DecimalVal{ - DecimalVal: &pb.Decimal64{ - Digits: 5, - }, - }, - }, - intf: float32(5), - }, - { - msg: &pb.TypedValue{ - Value: &pb.TypedValue_DecimalVal{ - DecimalVal: &pb.Decimal64{ - Digits: 5678, - Precision: 18, - }, - }, - }, - intf: float32(.000000000000005678), - }, - {msg: &pb.TypedValue{Value: &pb.TypedValue_AnyVal{}}, err: true}, - {msg: &pb.TypedValue{Value: &pb.TypedValue_JsonVal{}}, err: true}, - {msg: &pb.TypedValue{Value: &pb.TypedValue_JsonIetfVal{}}, err: true}, - {msg: &pb.TypedValue{Value: &pb.TypedValue_AsciiVal{}}, err: true}, - } - for _, tt := range tests { - v, err := ToScalar(tt.msg) - switch { - case tt.err: - if err == nil { - t.Errorf("ToScalar(%v): got nil, wanted err", tt.msg) - } - case err != nil: - t.Errorf("ToScalar(%v): got error %v, want %+v", tt.msg, err, tt.intf) - case !reflect.DeepEqual(v, tt.intf): - t.Errorf("ToScalar(%v): got %#v, want %#v", tt.msg, v, tt.intf) - } - } -} - -func TestEqual(t *testing.T) { - anyVal, err := ptypes.MarshalAny(&pb.TypedValue{Value: &pb.TypedValue_StringVal{"any val"}}) - if err != nil { - t.Errorf("MarshalAny: %v", err) - } - for _, test := range []struct { - name string - a, b *pb.TypedValue - want bool - }{ - // Equality is true. - { - name: "String equal", - a: &pb.TypedValue{Value: &pb.TypedValue_StringVal{"foo"}}, - b: &pb.TypedValue{Value: &pb.TypedValue_StringVal{"foo"}}, - want: true, - }, { - name: "Int equal", - a: &pb.TypedValue{Value: &pb.TypedValue_IntVal{1234}}, - b: &pb.TypedValue{Value: &pb.TypedValue_IntVal{1234}}, - want: true, - }, { - name: "Uint equal", - a: &pb.TypedValue{Value: &pb.TypedValue_UintVal{1234}}, - b: &pb.TypedValue{Value: &pb.TypedValue_UintVal{1234}}, - want: true, - }, { - name: "Bool equal", - a: &pb.TypedValue{Value: &pb.TypedValue_BoolVal{true}}, - b: &pb.TypedValue{Value: &pb.TypedValue_BoolVal{true}}, - want: true, - }, { - name: "Bytes equal", - a: &pb.TypedValue{Value: &pb.TypedValue_BytesVal{[]byte{1, 2, 3}}}, - b: &pb.TypedValue{Value: &pb.TypedValue_BytesVal{[]byte{1, 2, 3}}}, - want: true, - }, { - name: "Float equal", - a: &pb.TypedValue{Value: &pb.TypedValue_FloatVal{1234.56789}}, - b: &pb.TypedValue{Value: &pb.TypedValue_FloatVal{1234.56789}}, - want: true, - }, { - name: "Decimal equal", - a: &pb.TypedValue{Value: &pb.TypedValue_DecimalVal{&pb.Decimal64{Digits: 1234, Precision: 10}}}, - b: &pb.TypedValue{Value: &pb.TypedValue_DecimalVal{&pb.Decimal64{Digits: 1234, Precision: 10}}}, - want: true, - }, { - name: "Leaflist equal", - a: &pb.TypedValue{Value: &pb.TypedValue_LeaflistVal{&pb.ScalarArray{Element: []*pb.TypedValue{{Value: &pb.TypedValue_StringVal{"one"}}, {Value: &pb.TypedValue_StringVal{"two"}}, {Value: &pb.TypedValue_StringVal{"three"}}}}}}, - b: &pb.TypedValue{Value: &pb.TypedValue_LeaflistVal{&pb.ScalarArray{Element: []*pb.TypedValue{{Value: &pb.TypedValue_StringVal{"one"}}, {Value: &pb.TypedValue_StringVal{"two"}}, {Value: &pb.TypedValue_StringVal{"three"}}}}}}, - want: true, - }, - // Equality is false. - { - name: "String not equal", - a: &pb.TypedValue{Value: &pb.TypedValue_StringVal{"foo"}}, - b: &pb.TypedValue{Value: &pb.TypedValue_StringVal{"bar"}}, - }, { - name: "Int not equal", - a: &pb.TypedValue{Value: &pb.TypedValue_IntVal{1234}}, - b: &pb.TypedValue{Value: &pb.TypedValue_IntVal{123456789}}, - }, { - name: "Uint not equal", - a: &pb.TypedValue{Value: &pb.TypedValue_UintVal{1234}}, - b: &pb.TypedValue{Value: &pb.TypedValue_UintVal{123456789}}, - }, { - name: "Bool not equal", - a: &pb.TypedValue{Value: &pb.TypedValue_BoolVal{false}}, - b: &pb.TypedValue{Value: &pb.TypedValue_BoolVal{true}}, - }, { - name: "Bytes not equal", - a: &pb.TypedValue{Value: &pb.TypedValue_BytesVal{[]byte{2, 3}}}, - b: &pb.TypedValue{Value: &pb.TypedValue_BytesVal{[]byte{1, 2, 3}}}, - }, { - name: "Float not equal", - a: &pb.TypedValue{Value: &pb.TypedValue_FloatVal{12340.56789}}, - b: &pb.TypedValue{Value: &pb.TypedValue_FloatVal{1234.56789}}, - }, { - name: "Decimal not equal", - a: &pb.TypedValue{Value: &pb.TypedValue_DecimalVal{&pb.Decimal64{Digits: 1234, Precision: 11}}}, - b: &pb.TypedValue{Value: &pb.TypedValue_DecimalVal{&pb.Decimal64{Digits: 1234, Precision: 10}}}, - }, { - name: "Leaflist not equal", - a: &pb.TypedValue{Value: &pb.TypedValue_LeaflistVal{&pb.ScalarArray{Element: []*pb.TypedValue{{Value: &pb.TypedValue_StringVal{"one"}}, {Value: &pb.TypedValue_StringVal{"two"}}, {Value: &pb.TypedValue_StringVal{"three"}}}}}}, - b: &pb.TypedValue{Value: &pb.TypedValue_LeaflistVal{&pb.ScalarArray{Element: []*pb.TypedValue{{Value: &pb.TypedValue_StringVal{"one"}}, {Value: &pb.TypedValue_StringVal{"two"}}, {Value: &pb.TypedValue_StringVal{"four"}}}}}}, - }, { - name: "Types not equal - String", - a: &pb.TypedValue{Value: &pb.TypedValue_StringVal{"foo"}}, - b: &pb.TypedValue{Value: &pb.TypedValue_DecimalVal{&pb.Decimal64{Digits: 1234, Precision: 10}}}, - }, { - name: "Types not equal - Int", - a: &pb.TypedValue{Value: &pb.TypedValue_IntVal{5}}, - b: &pb.TypedValue{Value: &pb.TypedValue_DecimalVal{&pb.Decimal64{Digits: 1234, Precision: 10}}}, - }, { - name: "Types not equal - Uint", - a: &pb.TypedValue{Value: &pb.TypedValue_UintVal{5}}, - b: &pb.TypedValue{Value: &pb.TypedValue_DecimalVal{&pb.Decimal64{Digits: 1234, Precision: 10}}}, - }, { - name: "Types not equal - Bool", - a: &pb.TypedValue{Value: &pb.TypedValue_BoolVal{true}}, - b: &pb.TypedValue{Value: &pb.TypedValue_DecimalVal{&pb.Decimal64{Digits: 1234, Precision: 10}}}, - }, { - name: "Types not equal - Float", - a: &pb.TypedValue{Value: &pb.TypedValue_FloatVal{5.25}}, - b: &pb.TypedValue{Value: &pb.TypedValue_DecimalVal{&pb.Decimal64{Digits: 1234, Precision: 10}}}, - }, { - name: "Types not equal - Decimal", - a: &pb.TypedValue{Value: &pb.TypedValue_DecimalVal{&pb.Decimal64{Digits: 1234, Precision: 10}}}, - b: &pb.TypedValue{Value: &pb.TypedValue_IntVal{5}}, - }, { - name: "Types not equal - Leaflist", - a: &pb.TypedValue{Value: &pb.TypedValue_LeaflistVal{&pb.ScalarArray{Element: []*pb.TypedValue{{Value: &pb.TypedValue_StringVal{"one"}}, {Value: &pb.TypedValue_StringVal{"two"}}, {Value: &pb.TypedValue_StringVal{"three"}}}}}}, - b: &pb.TypedValue{Value: &pb.TypedValue_IntVal{5}}, - }, - // Equality is not checked, expect false. - { - name: "Empty values not compared", - a: &pb.TypedValue{}, - b: &pb.TypedValue{}, - }, { - name: "Proto values not compared", - a: &pb.TypedValue{Value: &pb.TypedValue_AnyVal{anyVal}}, - b: &pb.TypedValue{Value: &pb.TypedValue_AnyVal{anyVal}}, - }, { - name: "JSON values not compared", - a: &pb.TypedValue{Value: &pb.TypedValue_JsonVal{[]byte("5")}}, - b: &pb.TypedValue{Value: &pb.TypedValue_JsonVal{[]byte("5")}}, - }, { - name: "JSON IETF values not compared", - a: &pb.TypedValue{Value: &pb.TypedValue_JsonIetfVal{[]byte("10.5")}}, - b: &pb.TypedValue{Value: &pb.TypedValue_JsonIetfVal{[]byte("10.5")}}, - }, { - name: "ASCII values not compared", - a: &pb.TypedValue{Value: &pb.TypedValue_AsciiVal{"foo"}}, - b: &pb.TypedValue{Value: &pb.TypedValue_AsciiVal{"foo"}}, - }, - } { - t.Run(test.name, func(t *testing.T) { - got := Equal(test.a, test.b) - if got != test.want { - t.Errorf("got: %t, want: %t", got, test.want) - } - }) - } -} diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/watch/watch.go b/src/gnmi_clients/src/github.com/openconfig/gnmi/watch/watch.go deleted file mode 100644 index 06edab46d..000000000 --- a/src/gnmi_clients/src/github.com/openconfig/gnmi/watch/watch.go +++ /dev/null @@ -1,56 +0,0 @@ -/* -Copyright 2019 Google Inc. -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 watch detects raw changes to files. The interpretation of a file is -// filesystem-specific. -package watch - -import ( - "context" -) - -// Watcher watches files at the given paths for changes. -type Watcher interface { - // Read blocks and returns the next update for a file. - // - // An error is returned when there is an underyling issue in the Watcher - // preventing Read, or ctx is cancelled. The returned error may indicate a - // fatal issue requiring a new Watcher to be created. - // - // Subsequent calls block until the underlying - // contents or error changes. When multiple updates have occurred for a file, - // Read coalesces and returns the latest update. - Read(ctx context.Context) (Update, error) - - // Add causes Watcher to monitor an additional path. The format is - // filesystem-specific. If Close has been called, this has no effect. - Add(path string) error - - // Remove causes Watcher to stop monitoring a path. The path must match one - // already monitored in the same format. The format is filesystem-specific. - Remove(path string) error - - // Close causes Watcher to stop watching all files and release its resources. - Close() -} - -// Update represents contents for a file. Path can represent fan-out on -// individual files when watching a path that contains multiple files. -// Update contains an error reflecting path-specific problems. -type Update struct { - Path string - Contents []byte - Err error -} diff --git a/src/testdata/tls/tls.go b/src/testdata/tls/tls.go deleted file mode 100644 index e4247f77f..000000000 --- a/src/testdata/tls/tls.go +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 tls provides helpers for generation of local tls.Certificates for -// use in testing. -package tls - -import ( - "bytes" - "crypto/rand" - "crypto/rsa" - "crypto/tls" - "crypto/x509" - "crypto/x509/pkix" - "encoding/pem" - "math/big" - "time" -) - -// NewCert will create a new tls.Certificate for use in testing. -// This cert is self signed and must not be used in production code. -func NewCert() (tls.Certificate, error) { - notBefore := time.Now() - notAfter := notBefore.Add(time.Hour) - - serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) - serialNumber, err := rand.Int(rand.Reader, serialNumberLimit) - if err != nil { - return tls.Certificate{}, err - } - template := x509.Certificate{ - SerialNumber: serialNumber, - Subject: pkix.Name{ - Organization: []string{"Example Co"}, - }, - DNSNames: []string{"example.com"}, - NotBefore: notBefore, - NotAfter: notAfter, - - KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, - ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, - BasicConstraintsValid: true, - } - - priv, err := rsa.GenerateKey(rand.Reader, 4096) - if err != nil { - return tls.Certificate{}, err - } - derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv) - if err != nil { - return tls.Certificate{}, err - } - - certBuf := &bytes.Buffer{} - pem.Encode(certBuf, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}) - keyBuf := &bytes.Buffer{} - pem.Encode(keyBuf, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)}) - - return tls.X509KeyPair(certBuf.Bytes(), keyBuf.Bytes()) -} diff --git a/src/testdata/tls/tls_test.go b/src/testdata/tls/tls_test.go deleted file mode 100644 index 8e01a8001..000000000 --- a/src/testdata/tls/tls_test.go +++ /dev/null @@ -1,60 +0,0 @@ -/* -Copyright 2017 Google Inc. - -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 tls - -import ( - "crypto/tls" - "fmt" - "io" - "io/ioutil" - "testing" -) - -func TestGenCert(t *testing.T) { - // Check that generation works at all. - cert, err := NewCert() - if err != nil { - t.Fatal(err) - } - // Check that cert is valid by making a dummy connection. - l, err := tls.Listen("tcp", fmt.Sprint(":0"), &tls.Config{ - Certificates: []tls.Certificate{cert}, - }) - if err != nil { - t.Fatal(err) - } - defer l.Close() - go func() { - // Just accept the connection to unblock Dial below. - con, err := l.Accept() - if err != nil { - t.Error(err) - } - io.Copy(ioutil.Discard, con) - }() - - con, err := tls.Dial("tcp", l.Addr().String(), &tls.Config{ - InsecureSkipVerify: true, - }) - if err != nil { - t.Error(err) - } - - if err := con.Handshake(); err != nil { - t.Error(err) - } -} diff --git a/src/telemetry/telemetry.go b/telemetry/telemetry.go similarity index 100% rename from src/telemetry/telemetry.go rename to telemetry/telemetry.go diff --git a/src/testdata/CONFIG_PFCWD_PORTS.txt b/testdata/CONFIG_PFCWD_PORTS.txt similarity index 100% rename from src/testdata/CONFIG_PFCWD_PORTS.txt rename to testdata/CONFIG_PFCWD_PORTS.txt diff --git a/src/testdata/COUNTERS:Ethernet1.txt b/testdata/COUNTERS:Ethernet1.txt similarity index 100% rename from src/testdata/COUNTERS:Ethernet1.txt rename to testdata/COUNTERS:Ethernet1.txt diff --git a/src/testdata/COUNTERS:Ethernet68.txt b/testdata/COUNTERS:Ethernet68.txt similarity index 100% rename from src/testdata/COUNTERS:Ethernet68.txt rename to testdata/COUNTERS:Ethernet68.txt diff --git a/src/testdata/COUNTERS:Ethernet68:Pfcwd.txt b/testdata/COUNTERS:Ethernet68:Pfcwd.txt similarity index 100% rename from src/testdata/COUNTERS:Ethernet68:Pfcwd.txt rename to testdata/COUNTERS:Ethernet68:Pfcwd.txt diff --git a/src/testdata/COUNTERS:Ethernet68:Pfcwd_alias.txt b/testdata/COUNTERS:Ethernet68:Pfcwd_alias.txt similarity index 100% rename from src/testdata/COUNTERS:Ethernet68:Pfcwd_alias.txt rename to testdata/COUNTERS:Ethernet68:Pfcwd_alias.txt diff --git a/src/testdata/COUNTERS:Ethernet68:Queues.txt b/testdata/COUNTERS:Ethernet68:Queues.txt similarity index 100% rename from src/testdata/COUNTERS:Ethernet68:Queues.txt rename to testdata/COUNTERS:Ethernet68:Queues.txt diff --git a/src/testdata/COUNTERS:Ethernet68:Queues_alias.txt b/testdata/COUNTERS:Ethernet68:Queues_alias.txt similarity index 100% rename from src/testdata/COUNTERS:Ethernet68:Queues_alias.txt rename to testdata/COUNTERS:Ethernet68:Queues_alias.txt diff --git a/src/testdata/COUNTERS:Ethernet_wildcard.txt b/testdata/COUNTERS:Ethernet_wildcard.txt similarity index 100% rename from src/testdata/COUNTERS:Ethernet_wildcard.txt rename to testdata/COUNTERS:Ethernet_wildcard.txt diff --git a/src/testdata/COUNTERS:Ethernet_wildcard_PFC_7_RX.txt b/testdata/COUNTERS:Ethernet_wildcard_PFC_7_RX.txt similarity index 100% rename from src/testdata/COUNTERS:Ethernet_wildcard_PFC_7_RX.txt rename to testdata/COUNTERS:Ethernet_wildcard_PFC_7_RX.txt diff --git a/src/testdata/COUNTERS:Ethernet_wildcard_PFC_7_RX_alias.txt b/testdata/COUNTERS:Ethernet_wildcard_PFC_7_RX_alias.txt similarity index 100% rename from src/testdata/COUNTERS:Ethernet_wildcard_PFC_7_RX_alias.txt rename to testdata/COUNTERS:Ethernet_wildcard_PFC_7_RX_alias.txt diff --git a/src/testdata/COUNTERS:Ethernet_wildcard_Pfcwd_alias.txt b/testdata/COUNTERS:Ethernet_wildcard_Pfcwd_alias.txt similarity index 100% rename from src/testdata/COUNTERS:Ethernet_wildcard_Pfcwd_alias.txt rename to testdata/COUNTERS:Ethernet_wildcard_Pfcwd_alias.txt diff --git a/src/testdata/COUNTERS:Ethernet_wildcard_Queues.txt b/testdata/COUNTERS:Ethernet_wildcard_Queues.txt similarity index 100% rename from src/testdata/COUNTERS:Ethernet_wildcard_Queues.txt rename to testdata/COUNTERS:Ethernet_wildcard_Queues.txt diff --git a/src/testdata/COUNTERS:Ethernet_wildcard_Queues_alias.txt b/testdata/COUNTERS:Ethernet_wildcard_Queues_alias.txt similarity index 100% rename from src/testdata/COUNTERS:Ethernet_wildcard_Queues_alias.txt rename to testdata/COUNTERS:Ethernet_wildcard_Queues_alias.txt diff --git a/src/testdata/COUNTERS:Ethernet_wildcard_alias.txt b/testdata/COUNTERS:Ethernet_wildcard_alias.txt similarity index 100% rename from src/testdata/COUNTERS:Ethernet_wildcard_alias.txt rename to testdata/COUNTERS:Ethernet_wildcard_alias.txt diff --git a/src/testdata/COUNTERS:oid:0x1500000000091c.txt b/testdata/COUNTERS:oid:0x1500000000091c.txt similarity index 100% rename from src/testdata/COUNTERS:oid:0x1500000000091c.txt rename to testdata/COUNTERS:oid:0x1500000000091c.txt diff --git a/src/testdata/COUNTERS:oid:0x1500000000091e.txt b/testdata/COUNTERS:oid:0x1500000000091e.txt similarity index 100% rename from src/testdata/COUNTERS:oid:0x1500000000091e.txt rename to testdata/COUNTERS:oid:0x1500000000091e.txt diff --git a/src/testdata/COUNTERS:oid:0x1500000000091f.txt b/testdata/COUNTERS:oid:0x1500000000091f.txt similarity index 100% rename from src/testdata/COUNTERS:oid:0x1500000000091f.txt rename to testdata/COUNTERS:oid:0x1500000000091f.txt diff --git a/src/testdata/COUNTERS:oid:0x1500000000092a.txt b/testdata/COUNTERS:oid:0x1500000000092a.txt similarity index 100% rename from src/testdata/COUNTERS:oid:0x1500000000092a.txt rename to testdata/COUNTERS:oid:0x1500000000092a.txt diff --git a/src/testdata/COUNTERS_PORT_ALIAS_MAP.txt b/testdata/COUNTERS_PORT_ALIAS_MAP.txt similarity index 100% rename from src/testdata/COUNTERS_PORT_ALIAS_MAP.txt rename to testdata/COUNTERS_PORT_ALIAS_MAP.txt diff --git a/src/testdata/COUNTERS_PORT_NAME_MAP.txt b/testdata/COUNTERS_PORT_NAME_MAP.txt similarity index 100% rename from src/testdata/COUNTERS_PORT_NAME_MAP.txt rename to testdata/COUNTERS_PORT_NAME_MAP.txt diff --git a/src/testdata/COUNTERS_QUEUE_NAME_MAP.txt b/testdata/COUNTERS_QUEUE_NAME_MAP.txt similarity index 100% rename from src/testdata/COUNTERS_QUEUE_NAME_MAP.txt rename to testdata/COUNTERS_QUEUE_NAME_MAP.txt diff --git a/src/testdata/check_interface_mtu_set.json b/testdata/check_interface_mtu_set.json similarity index 100% rename from src/testdata/check_interface_mtu_set.json rename to testdata/check_interface_mtu_set.json diff --git a/src/testdata/interfaces.json b/testdata/interfaces.json similarity index 100% rename from src/testdata/interfaces.json rename to testdata/interfaces.json diff --git a/src/testdata/json_tests/README.md b/testdata/json_tests/README.md similarity index 100% rename from src/testdata/json_tests/README.md rename to testdata/json_tests/README.md diff --git a/src/testdata/json_tests/data_vrf.json b/testdata/json_tests/data_vrf.json similarity index 100% rename from src/testdata/json_tests/data_vrf.json rename to testdata/json_tests/data_vrf.json diff --git a/src/testdata/json_tests/interface_ipv4.json b/testdata/json_tests/interface_ipv4.json similarity index 100% rename from src/testdata/json_tests/interface_ipv4.json rename to testdata/json_tests/interface_ipv4.json diff --git a/src/testdata/json_tests/interface_mtu.json b/testdata/json_tests/interface_mtu.json similarity index 100% rename from src/testdata/json_tests/interface_mtu.json rename to testdata/json_tests/interface_mtu.json diff --git a/src/testdata/json_tests/mgmt_vrf.json b/testdata/json_tests/mgmt_vrf.json similarity index 100% rename from src/testdata/json_tests/mgmt_vrf.json rename to testdata/json_tests/mgmt_vrf.json diff --git a/src/testdata/json_tests/vrf_intf_bind.json b/testdata/json_tests/vrf_intf_bind.json similarity index 100% rename from src/testdata/json_tests/vrf_intf_bind.json rename to testdata/json_tests/vrf_intf_bind.json diff --git a/src/testdata/set_interface_ipv4.json b/testdata/set_interface_ipv4.json similarity index 100% rename from src/testdata/set_interface_ipv4.json rename to testdata/set_interface_ipv4.json diff --git a/src/testdata/set_interface_mtu.json b/testdata/set_interface_mtu.json similarity index 100% rename from src/testdata/set_interface_mtu.json rename to testdata/set_interface_mtu.json diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/testing/tls/tls.go b/testdata/tls/tls.go similarity index 100% rename from src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/testing/tls/tls.go rename to testdata/tls/tls.go diff --git a/src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/testing/tls/tls_test.go b/testdata/tls/tls_test.go similarity index 100% rename from src/gnmi_clients/src/github.com/openconfig/gnmi/testing/fake/testing/tls/tls_test.go rename to testdata/tls/tls_test.go diff --git a/src/transl_utils/transl_utils.go b/transl_utils/transl_utils.go similarity index 100% rename from src/transl_utils/transl_utils.go rename to transl_utils/transl_utils.go From 359dd6f7cd015f3cf2dde61b8af0786aebc5f20e Mon Sep 17 00:00:00 2001 From: Eric Seifert Date: Wed, 26 Feb 2020 13:58:15 -0800 Subject: [PATCH 02/13] Remove test dir --- test/01_create_MyACL1_MyACL2.json | 343 --------------------- test/acl_get.result | 27 -- test/acl_get.test | 1 - test/acl_set.result | 22 -- test/acl_set.test | 1 - test/ethernet_oper_status_subscribe.result | 13 - test/ethernet_oper_status_subscribe.test | 1 - test/interface_get.result | 41 --- test/interface_get.test | 1 - test/interfaces_get.result | 27 -- test/interfaces_get.test | 1 - test/lldp_neighbor_subscribe.result | 11 - test/lldp_neighbor_subscribe.test | 1 - 13 files changed, 490 deletions(-) delete mode 100644 test/01_create_MyACL1_MyACL2.json delete mode 100644 test/acl_get.result delete mode 100644 test/acl_get.test delete mode 100644 test/acl_set.result delete mode 100644 test/acl_set.test delete mode 100644 test/ethernet_oper_status_subscribe.result delete mode 100644 test/ethernet_oper_status_subscribe.test delete mode 100644 test/interface_get.result delete mode 100644 test/interface_get.test delete mode 100644 test/interfaces_get.result delete mode 100644 test/interfaces_get.test delete mode 100644 test/lldp_neighbor_subscribe.result delete mode 100644 test/lldp_neighbor_subscribe.test diff --git a/test/01_create_MyACL1_MyACL2.json b/test/01_create_MyACL1_MyACL2.json deleted file mode 100644 index be3becbd4..000000000 --- a/test/01_create_MyACL1_MyACL2.json +++ /dev/null @@ -1,343 +0,0 @@ -{ - "acl-sets": { - "acl-set": [ - { - "name": "MyACL1", - "type": "ACL_IPV4", - "config": { - "name": "MyACL1", - "type": "ACL_IPV4", - "description": "Description for MyACL1" - }, - "acl-entries": { - "acl-entry": [ - { - "sequence-id": 1, - "config": { - "sequence-id": 1, - "description": "Description for MyACL1 Rule Seq 1" - }, - "ipv4": { - "config": { - "source-address": "11.1.1.1/32", - "destination-address": "21.1.1.1/32", - "dscp": 1, - "protocol": "IP_TCP" - } - }, - "transport": { - "config": { - "source-port": 101, - "destination-port": 201 - } - }, - "actions": { - "config": { - "forwarding-action": "ACCEPT" - } - } - }, - { - "sequence-id": 2, - "config": { - "sequence-id": 2, - "description": "Description for MyACL1 Rule Seq 2" - }, - "ipv4": { - "config": { - "source-address": "11.1.1.2/32", - "destination-address": "21.1.1.2/32", - "dscp": 2, - "protocol": "IP_TCP" - } - }, - "transport": { - "config": { - "source-port": 102, - "destination-port": 202 - } - }, - "actions": { - "config": { - "forwarding-action": "DROP" - } - } - }, - { - "sequence-id": 3, - "config": { - "sequence-id": 3, - "description": "Description for MyACL1 Rule Seq 3" - }, - "ipv4": { - "config": { - "source-address": "11.1.1.3/32", - "destination-address": "21.1.1.3/32", - "dscp": 3, - "protocol": "IP_TCP" - } - }, - "transport": { - "config": { - "source-port": 103, - "destination-port": 203 - } - }, - "actions": { - "config": { - "forwarding-action": "ACCEPT" - } - } - }, - { - "sequence-id": 4, - "config": { - "sequence-id": 4, - "description": "Description for MyACL1 Rule Seq 4" - }, - "ipv4": { - "config": { - "source-address": "11.1.1.4/32", - "destination-address": "21.1.1.4/32", - "dscp": 4, - "protocol": "IP_TCP" - } - }, - "transport": { - "config": { - "source-port": 104, - "destination-port": 204 - } - }, - "actions": { - "config": { - "forwarding-action": "DROP" - } - } - }, - { - "sequence-id": 5, - "config": { - "sequence-id": 5, - "description": "Description for MyACL1 Rule Seq 5" - }, - "ipv4": { - "config": { - "source-address": "11.1.1.5/32", - "destination-address": "21.1.1.5/32", - "dscp": 5, - "protocol": "IP_TCP" - } - }, - "transport": { - "config": { - "source-port": 105, - "destination-port": 205 - } - }, - "actions": { - "config": { - "forwarding-action": "ACCEPT" - } - } - } - ] - } - }, - { - "name": "MyACL2", - "type": "ACL_IPV4", - "config": { - "name": "MyACL2", - "type": "ACL_IPV4", - "description": "Description for MyACL2" - }, - "acl-entries": { - "acl-entry": [ - { - "sequence-id": 1, - "config": { - "sequence-id": 1, - "description": "Description for Rule Seq 1" - }, - "ipv4": { - "config": { - "source-address": "12.1.1.1/32", - "destination-address": "22.1.1.1/32", - "dscp": 1, - "protocol": "IP_TCP" - } - }, - "transport": { - "config": { - "source-port": 101, - "destination-port": 201 - } - }, - "actions": { - "config": { - "forwarding-action": "ACCEPT" - } - } - }, - { - "sequence-id": 2, - "config": { - "sequence-id": 2, - "description": "Description for Rule Seq 2" - }, - "ipv4": { - "config": { - "source-address": "12.1.1.2/32", - "destination-address": "22.1.1.2/32", - "dscp": 2, - "protocol": "IP_TCP" - } - }, - "transport": { - "config": { - "source-port": 102, - "destination-port": 202 - } - }, - "actions": { - "config": { - "forwarding-action": "ACCEPT" - } - } - }, - { - "sequence-id": 3, - "config": { - "sequence-id": 3, - "description": "Description for Rule Seq 3" - }, - "ipv4": { - "config": { - "source-address": "12.1.1.3/32", - "destination-address": "22.1.1.3/32", - "dscp": 3, - "protocol": "IP_TCP" - } - }, - "transport": { - "config": { - "source-port": 103, - "destination-port": 203 - } - }, - "actions": { - "config": { - "forwarding-action": "ACCEPT" - } - } - }, - { - "sequence-id": 4, - "config": { - "sequence-id": 4, - "description": "Description for Rule Seq 4" - }, - "ipv4": { - "config": { - "source-address": "12.1.1.4/32", - "destination-address": "22.1.1.4/32", - "dscp": 4, - "protocol": "IP_TCP" - } - }, - "transport": { - "config": { - "source-port": 104, - "destination-port": 204 - } - }, - "actions": { - "config": { - "forwarding-action": "ACCEPT" - } - } - }, - { - "sequence-id": 5, - "config": { - "sequence-id": 5, - "description": "Description for Rule Seq 5" - }, - "ipv4": { - "config": { - "source-address": "12.1.1.5/32", - "destination-address": "22.1.1.5/32", - "dscp": 5, - "protocol": "IP_TCP" - } - }, - "transport": { - "config": { - "source-port": 105, - "destination-port": 205 - } - }, - "actions": { - "config": { - "forwarding-action": "ACCEPT" - } - } - } - ] - } - } - ] - }, - "interfaces": { - "interface": [ - { - "id": "Ethernet0", - "config": { - "id": "Ethernet0" - }, - "interface-ref": { - "config": { - "interface": "Ethernet0" - } - }, - "ingress-acl-sets": { - "ingress-acl-set": [ - { - "set-name": "MyACL1", - "type": "ACL_IPV4", - "config": { - "set-name": "MyACL1", - "type": "ACL_IPV4" - } - } - ] - } - }, - { - "id": "Ethernet4", - "config": { - "id": "Ethernet4" - }, - "interface-ref": { - "config": { - "interface": "Ethernet4" - } - }, - "ingress-acl-sets": { - "ingress-acl-set": [ - { - "set-name": "MyACL2", - "type": "ACL_IPV4", - "config": { - "set-name": "MyACL2", - "type": "ACL_IPV4" - } - } - ] - } - } - ] - } -} - diff --git a/test/acl_get.result b/test/acl_get.result deleted file mode 100644 index e97137554..000000000 --- a/test/acl_get.result +++ /dev/null @@ -1,27 +0,0 @@ -== getRequest: -prefix: < -> -path: < - elem: < - name: "openconfig-acl:acl" - > -> -encoding: JSON_IETF - -== getResponse: -notification: < - timestamp: 1566513462512458848 - prefix: < - > - update: < - path: < - elem: < - name: "openconfig-acl:acl" - > - > - val: < - json_ietf_val: "{\"openconfig-acl:acl\":{\"acl-sets\":{\"acl-set\":[{\"acl-entries\":{\"acl-entry\":[{\"actions\":{\"config\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"},\"state\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"}},\"config\":{\"sequence-id\":1},\"ipv4\":{\"config\":{\"destination-address\":\"21.1.1.1/32\",\"dscp\":1,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"11.1.1.1/32\"},\"state\":{\"destination-address\":\"21.1.1.1/32\",\"dscp\":1,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"11.1.1.1/32\"}},\"sequence-id\":1,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":1},\"transport\":{\"config\":{\"destination-port\":201,\"source-port\":101},\"state\":{\"destination-port\":201,\"source-port\":101}}},{\"actions\":{\"config\":{\"forwarding-action\":\"openconfig-acl:DROP\"},\"state\":{\"forwarding-action\":\"openconfig-acl:DROP\"}},\"config\":{\"sequence-id\":2},\"ipv4\":{\"config\":{\"destination-address\":\"21.1.1.2/32\",\"dscp\":2,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"11.1.1.2/32\"},\"state\":{\"destination-address\":\"21.1.1.2/32\",\"dscp\":2,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"11.1.1.2/32\"}},\"sequence-id\":2,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":2},\"transport\":{\"config\":{\"destination-port\":202,\"source-port\":102},\"state\":{\"destination-port\":202,\"source-port\":102}}},{\"actions\":{\"config\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"},\"state\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"}},\"config\":{\"sequence-id\":3},\"ipv4\":{\"config\":{\"destination-address\":\"21.1.1.3/32\",\"dscp\":3,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"11.1.1.3/32\"},\"state\":{\"destination-address\":\"21.1.1.3/32\",\"dscp\":3,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"11.1.1.3/32\"}},\"sequence-id\":3,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":3},\"transport\":{\"config\":{\"destination-port\":203,\"source-port\":103},\"state\":{\"destination-port\":203,\"source-port\":103}}},{\"actions\":{\"config\":{\"forwarding-action\":\"openconfig-acl:DROP\"},\"state\":{\"forwarding-action\":\"openconfig-acl:DROP\"}},\"config\":{\"sequence-id\":4},\"ipv4\":{\"config\":{\"destination-address\":\"21.1.1.4/32\",\"dscp\":4,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"11.1.1.4/32\"},\"state\":{\"destination-address\":\"21.1.1.4/32\",\"dscp\":4,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"11.1.1.4/32\"}},\"sequence-id\":4,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":4},\"transport\":{\"config\":{\"destination-port\":204,\"source-port\":104},\"state\":{\"destination-port\":204,\"source-port\":104}}},{\"actions\":{\"config\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"},\"state\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"}},\"config\":{\"sequence-id\":5},\"ipv4\":{\"config\":{\"destination-address\":\"21.1.1.5/32\",\"dscp\":5,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"11.1.1.5/32\"},\"state\":{\"destination-address\":\"21.1.1.5/32\",\"dscp\":5,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"11.1.1.5/32\"}},\"sequence-id\":5,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":5},\"transport\":{\"config\":{\"destination-port\":205,\"source-port\":105},\"state\":{\"destination-port\":205,\"source-port\":105}}}]},\"config\":{\"description\":\"Description for MyACL1\",\"name\":\"MyACL1\",\"type\":\"openconfig-acl:ACL_IPV4\"},\"name\":\"MyACL1\",\"state\":{\"description\":\"Description for MyACL1\",\"name\":\"MyACL1\",\"type\":\"openconfig-acl:ACL_IPV4\"},\"type\":\"openconfig-acl:ACL_IPV4\"},{\"acl-entries\":{\"acl-entry\":[{\"actions\":{\"config\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"},\"state\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"}},\"config\":{\"sequence-id\":1},\"ipv4\":{\"config\":{\"destination-address\":\"22.1.1.1/32\",\"dscp\":1,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"12.1.1.1/32\"},\"state\":{\"destination-address\":\"22.1.1.1/32\",\"dscp\":1,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"12.1.1.1/32\"}},\"sequence-id\":1,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":1},\"transport\":{\"config\":{\"destination-port\":201,\"source-port\":101},\"state\":{\"destination-port\":201,\"source-port\":101}}},{\"actions\":{\"config\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"},\"state\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"}},\"config\":{\"sequence-id\":2},\"ipv4\":{\"config\":{\"destination-address\":\"22.1.1.2/32\",\"dscp\":2,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"12.1.1.2/32\"},\"state\":{\"destination-address\":\"22.1.1.2/32\",\"dscp\":2,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"12.1.1.2/32\"}},\"sequence-id\":2,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":2},\"transport\":{\"config\":{\"destination-port\":202,\"source-port\":102},\"state\":{\"destination-port\":202,\"source-port\":102}}},{\"actions\":{\"config\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"},\"state\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"}},\"config\":{\"sequence-id\":3},\"ipv4\":{\"config\":{\"destination-address\":\"22.1.1.3/32\",\"dscp\":3,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"12.1.1.3/32\"},\"state\":{\"destination-address\":\"22.1.1.3/32\",\"dscp\":3,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"12.1.1.3/32\"}},\"sequence-id\":3,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":3},\"transport\":{\"config\":{\"destination-port\":203,\"source-port\":103},\"state\":{\"destination-port\":203,\"source-port\":103}}},{\"actions\":{\"config\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"},\"state\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"}},\"config\":{\"sequence-id\":4},\"ipv4\":{\"config\":{\"destination-address\":\"22.1.1.4/32\",\"dscp\":4,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"12.1.1.4/32\"},\"state\":{\"destination-address\":\"22.1.1.4/32\",\"dscp\":4,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"12.1.1.4/32\"}},\"sequence-id\":4,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":4},\"transport\":{\"config\":{\"destination-port\":204,\"source-port\":104},\"state\":{\"destination-port\":204,\"source-port\":104}}},{\"actions\":{\"config\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"},\"state\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"}},\"config\":{\"sequence-id\":5},\"ipv4\":{\"config\":{\"destination-address\":\"22.1.1.5/32\",\"dscp\":5,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"12.1.1.5/32\"},\"state\":{\"destination-address\":\"22.1.1.5/32\",\"dscp\":5,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"12.1.1.5/32\"}},\"sequence-id\":5,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":5},\"transport\":{\"config\":{\"destination-port\":205,\"source-port\":105},\"state\":{\"destination-port\":205,\"source-port\":105}}}]},\"config\":{\"description\":\"Description for MyACL2\",\"name\":\"MyACL2\",\"type\":\"openconfig-acl:ACL_IPV4\"},\"name\":\"MyACL2\",\"state\":{\"description\":\"Description for MyACL2\",\"name\":\"MyACL2\",\"type\":\"openconfig-acl:ACL_IPV4\"},\"type\":\"openconfig-acl:ACL_IPV4\"}]},\"interfaces\":{\"interface\":[{\"config\":{\"id\":\"Ethernet0\"},\"id\":\"Ethernet0\",\"ingress-acl-sets\":{\"ingress-acl-set\":[{\"acl-entries\":{\"acl-entry\":[{\"sequence-id\":1,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":1}},{\"sequence-id\":2,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":2}},{\"sequence-id\":3,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":3}},{\"sequence-id\":4,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":4}},{\"sequence-id\":5,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":5}}]},\"config\":{\"set-name\":\"MyACL1\",\"type\":\"openconfig-acl:ACL_IPV4\"},\"set-name\":\"MyACL1\",\"state\":{\"set-name\":\"MyACL1\",\"type\":\"openconfig-acl:ACL_IPV4\"},\"type\":\"openconfig-acl:ACL_IPV4\"}]},\"state\":{\"id\":\"Ethernet0\"}},{\"config\":{\"id\":\"Ethernet4\"},\"id\":\"Ethernet4\",\"ingress-acl-sets\":{\"ingress-acl-set\":[{\"acl-entries\":{\"acl-entry\":[{\"sequence-id\":1,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":1}},{\"sequence-id\":2,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":2}},{\"sequence-id\":3,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":3}},{\"sequence-id\":4,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":4}},{\"sequence-id\":5,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":5}}]},\"config\":{\"set-name\":\"MyACL2\",\"type\":\"openconfig-acl:ACL_IPV4\"},\"set-name\":\"MyACL2\",\"state\":{\"set-name\":\"MyACL2\",\"type\":\"openconfig-acl:ACL_IPV4\"},\"type\":\"openconfig-acl:ACL_IPV4\"}]},\"state\":{\"id\":\"Ethernet4\"}}]}}}" - > - > -> - diff --git a/test/acl_get.test b/test/acl_get.test deleted file mode 100644 index 38d3ce654..000000000 --- a/test/acl_get.test +++ /dev/null @@ -1 +0,0 @@ -./gnmi_get -xpath /openconfig-acl:acl/ -target_addr 127.0.0.1:8080 -insecure diff --git a/test/acl_set.result b/test/acl_set.result deleted file mode 100644 index 586ff2c0a..000000000 --- a/test/acl_set.result +++ /dev/null @@ -1,22 +0,0 @@ -== setRequest: -replace: < - path: < - elem: < - name: "openconfig-acl:acl" - > - > - val: < - json_ietf_val: "{\n \"acl-sets\": {\n \"acl-set\": [\n {\n \"name\": \"MyACL1\",\n \"type\": \"ACL_IPV4\",\n \"config\": {\n \"name\": \"MyACL1\",\n \"type\": \"ACL_IPV4\",\n \"description\": \"Description for MyACL1\"\n },\n \"acl-entries\": {\n \"acl-entry\": [\n {\n \"sequence-id\": 1,\n \"config\": {\n \"sequence-id\": 1,\n \"description\": \"Description for MyACL1 Rule Seq 1\"\n },\n \"ipv4\": {\n \"config\": {\n \"source-address\": \"11.1.1.1/32\",\n \"destination-address\": \"21.1.1.1/32\",\n \"dscp\": 1,\n \"protocol\": \"IP_TCP\"\n }\n },\n \"transport\": {\n \"config\": {\n \"source-port\": 101,\n \"destination-port\": 201\n }\n },\n \"actions\": {\n \"config\": {\n \"forwarding-action\": \"ACCEPT\"\n }\n }\n },\n {\n \"sequence-id\": 2,\n \"config\": {\n \"sequence-id\": 2,\n \"description\": \"Description for MyACL1 Rule Seq 2\"\n },\n \"ipv4\": {\n \"config\": {\n \"source-address\": \"11.1.1.2/32\",\n \"destination-address\": \"21.1.1.2/32\",\n \"dscp\": 2,\n \"protocol\": \"IP_TCP\"\n }\n },\n \"transport\": {\n \"config\": {\n \"source-port\": 102,\n \"destination-port\": 202\n }\n },\n \"actions\": {\n \"config\": {\n \"forwarding-action\": \"DROP\"\n }\n }\n },\n {\n \"sequence-id\": 3,\n \"config\": {\n \"sequence-id\": 3,\n \"description\": \"Description for MyACL1 Rule Seq 3\"\n },\n \"ipv4\": {\n \"config\": {\n \"source-address\": \"11.1.1.3/32\",\n \"destination-address\": \"21.1.1.3/32\",\n \"dscp\": 3,\n \"protocol\": \"IP_TCP\"\n }\n },\n \"transport\": {\n \"config\": {\n \"source-port\": 103,\n \"destination-port\": 203\n }\n },\n \"actions\": {\n \"config\": {\n \"forwarding-action\": \"ACCEPT\"\n }\n }\n },\n {\n \"sequence-id\": 4,\n \"config\": {\n \"sequence-id\": 4,\n \"description\": \"Description for MyACL1 Rule Seq 4\"\n },\n \"ipv4\": {\n \"config\": {\n \"source-address\": \"11.1.1.4/32\",\n \"destination-address\": \"21.1.1.4/32\",\n \"dscp\": 4,\n \"protocol\": \"IP_TCP\"\n }\n },\n \"transport\": {\n \"config\": {\n \"source-port\": 104,\n \"destination-port\": 204\n }\n },\n \"actions\": {\n \"config\": {\n \"forwarding-action\": \"DROP\"\n }\n }\n },\n {\n \"sequence-id\": 5,\n \"config\": {\n \"sequence-id\": 5,\n \"description\": \"Description for MyACL1 Rule Seq 5\"\n },\n \"ipv4\": {\n \"config\": {\n \"source-address\": \"11.1.1.5/32\",\n \"destination-address\": \"21.1.1.5/32\",\n \"dscp\": 5,\n \"protocol\": \"IP_TCP\"\n }\n },\n \"transport\": {\n \"config\": {\n \"source-port\": 105,\n \"destination-port\": 205\n }\n },\n \"actions\": {\n \"config\": {\n \"forwarding-action\": \"ACCEPT\"\n }\n }\n }\n ]\n }\n },\n {\n \"name\": \"MyACL2\",\n \"type\": \"ACL_IPV4\",\n \"config\": {\n \"name\": \"MyACL2\",\n \"type\": \"ACL_IPV4\",\n \"description\": \"Description for MyACL2\"\n },\n \"acl-entries\": {\n \"acl-entry\": [\n {\n \"sequence-id\": 1,\n \"config\": {\n \"sequence-id\": 1,\n \"description\": \"Description for Rule Seq 1\"\n },\n \"ipv4\": {\n \"config\": {\n \"source-address\": \"12.1.1.1/32\",\n \"destination-address\": \"22.1.1.1/32\",\n \"dscp\": 1,\n \"protocol\": \"IP_TCP\"\n }\n },\n \"transport\": {\n \"config\": {\n \"source-port\": 101,\n \"destination-port\": 201\n }\n },\n \"actions\": {\n \"config\": {\n \"forwarding-action\": \"ACCEPT\"\n }\n }\n },\n {\n \"sequence-id\": 2,\n \"config\": {\n \"sequence-id\": 2,\n \"description\": \"Description for Rule Seq 2\"\n },\n \"ipv4\": {\n \"config\": {\n \"source-address\": \"12.1.1.2/32\",\n \"destination-address\": \"22.1.1.2/32\",\n \"dscp\": 2,\n \"protocol\": \"IP_TCP\"\n }\n },\n \"transport\": {\n \"config\": {\n \"source-port\": 102,\n \"destination-port\": 202\n }\n },\n \"actions\": {\n \"config\": {\n \"forwarding-action\": \"ACCEPT\"\n }\n }\n },\n {\n \"sequence-id\": 3,\n \"config\": {\n \"sequence-id\": 3,\n \"description\": \"Description for Rule Seq 3\"\n },\n \"ipv4\": {\n \"config\": {\n \"source-address\": \"12.1.1.3/32\",\n \"destination-address\": \"22.1.1.3/32\",\n \"dscp\": 3,\n \"protocol\": \"IP_TCP\"\n }\n },\n \"transport\": {\n \"config\": {\n \"source-port\": 103,\n \"destination-port\": 203\n }\n },\n \"actions\": {\n \"config\": {\n \"forwarding-action\": \"ACCEPT\"\n }\n }\n },\n {\n \"sequence-id\": 4,\n \"config\": {\n \"sequence-id\": 4,\n \"description\": \"Description for Rule Seq 4\"\n },\n \"ipv4\": {\n \"config\": {\n \"source-address\": \"12.1.1.4/32\",\n \"destination-address\": \"22.1.1.4/32\",\n \"dscp\": 4,\n \"protocol\": \"IP_TCP\"\n }\n },\n \"transport\": {\n \"config\": {\n \"source-port\": 104,\n \"destination-port\": 204\n }\n },\n \"actions\": {\n \"config\": {\n \"forwarding-action\": \"ACCEPT\"\n }\n }\n },\n {\n \"sequence-id\": 5,\n \"config\": {\n \"sequence-id\": 5,\n \"description\": \"Description for Rule Seq 5\"\n },\n \"ipv4\": {\n \"config\": {\n \"source-address\": \"12.1.1.5/32\",\n \"destination-address\": \"22.1.1.5/32\",\n \"dscp\": 5,\n \"protocol\": \"IP_TCP\"\n }\n },\n \"transport\": {\n \"config\": {\n \"source-port\": 105,\n \"destination-port\": 205\n }\n },\n \"actions\": {\n \"config\": {\n \"forwarding-action\": \"ACCEPT\"\n }\n }\n }\n ]\n }\n }\n ]\n },\n \"interfaces\": {\n \"interface\": [\n {\n \"id\": \"Ethernet0\",\n \"config\": {\n \"id\": \"Ethernet0\"\n },\n \"interface-ref\": {\n \"config\": {\n \"interface\": \"Ethernet0\"\n }\n },\n \"ingress-acl-sets\": {\n \"ingress-acl-set\": [\n {\n \"set-name\": \"MyACL1\",\n \"type\": \"ACL_IPV4\",\n \"config\": {\n \"set-name\": \"MyACL1\",\n \"type\": \"ACL_IPV4\"\n }\n }\n ]\n }\n },\n {\n \"id\": \"Ethernet4\",\n \"config\": {\n \"id\": \"Ethernet4\"\n },\n \"interface-ref\": {\n \"config\": {\n \"interface\": \"Ethernet4\"\n }\n },\n \"ingress-acl-sets\": {\n \"ingress-acl-set\": [\n {\n \"set-name\": \"MyACL2\",\n \"type\": \"ACL_IPV4\",\n \"config\": {\n \"set-name\": \"MyACL2\",\n \"type\": \"ACL_IPV4\"\n }\n }\n ]\n }\n }\n ]\n }\n}" - > -> - -== getResponse: -response: < - path: < - elem: < - name: "openconfig-acl:acl" - > - > - op: REPLACE -> - diff --git a/test/acl_set.test b/test/acl_set.test deleted file mode 100644 index db5e51611..000000000 --- a/test/acl_set.test +++ /dev/null @@ -1 +0,0 @@ -./gnmi_set -replace /openconfig-acl:acl/:@./test/01_create_MyACL1_MyACL2.json -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty diff --git a/test/ethernet_oper_status_subscribe.result b/test/ethernet_oper_status_subscribe.result deleted file mode 100644 index 161c95ea7..000000000 --- a/test/ethernet_oper_status_subscribe.result +++ /dev/null @@ -1,13 +0,0 @@ -{ - "OC-YANG": { - "openconfig-interfaces:interfaces": { - "interface": { - "Ethernet0": { - "state": { - "oper-status": "{\"openconfig-interfaces:oper-status\":\"DOWN\"}" - } - } - } - } - } -} diff --git a/test/ethernet_oper_status_subscribe.test b/test/ethernet_oper_status_subscribe.test deleted file mode 100644 index 708a6f814..000000000 --- a/test/ethernet_oper_status_subscribe.test +++ /dev/null @@ -1 +0,0 @@ -./gnmi_cli -insecure -logtostderr -address 127.0.0.1:8080 -query_type s -streaming_type ON_CHANGE -q /openconfig-interfaces:interfaces/interface[name=Ethernet0]/state/oper-status -v 0 -target OC-YANG diff --git a/test/interface_get.result b/test/interface_get.result deleted file mode 100644 index 9b2f49a6f..000000000 --- a/test/interface_get.result +++ /dev/null @@ -1,41 +0,0 @@ -== getRequest: -prefix: < -> -path: < - elem: < - name: "openconfig-interfaces:interfaces" - > - elem: < - name: "interface" - key: < - key: "name" - value: "Ethernet0" - > - > -> -encoding: JSON_IETF - -== getResponse: -notification: < - timestamp: 1566513579657003179 - prefix: < - > - update: < - path: < - elem: < - name: "openconfig-interfaces:interfaces" - > - elem: < - name: "interface" - key: < - key: "name" - value: "Ethernet0" - > - > - > - val: < - json_ietf_val: "{\"openconfig-interfaces:interface\":[{\"config\":{\"mtu\":9100,\"name\":\"Ethernet0\"},\"name\":\"Ethernet0\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet0\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.0\",\"prefix-length\":31},\"ip\":\"10.0.0.0\",\"state\":{\"ip\":\"10.0.0.0\",\"prefix-length\":31}}]}}}]}}]}" - > - > -> - diff --git a/test/interface_get.test b/test/interface_get.test deleted file mode 100644 index fd71d6946..000000000 --- a/test/interface_get.test +++ /dev/null @@ -1 +0,0 @@ -./gnmi_get -xpath /openconfig-interfaces:interfaces/interface[name=Ethernet0] -target_addr 127.0.0.1:8080 -insecure diff --git a/test/interfaces_get.result b/test/interfaces_get.result deleted file mode 100644 index 5d8544c6e..000000000 --- a/test/interfaces_get.result +++ /dev/null @@ -1,27 +0,0 @@ -== getRequest: -prefix: < -> -path: < - elem: < - name: "openconfig-interfaces:interfaces" - > -> -encoding: JSON_IETF - -== getResponse: -notification: < - timestamp: 1566513540117075554 - prefix: < - > - update: < - path: < - elem: < - name: "openconfig-interfaces:interfaces" - > - > - val: < - json_ietf_val: "{\"openconfig-interfaces:interfaces\":{\"interface\":[{\"config\":{\"mtu\":9100,\"name\":\"Ethernet0\"},\"name\":\"Ethernet0\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet0\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.0\",\"prefix-length\":31},\"ip\":\"10.0.0.0\",\"state\":{\"ip\":\"10.0.0.0\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet100\"},\"name\":\"Ethernet100\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet100\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.50\",\"prefix-length\":31},\"ip\":\"10.0.0.50\",\"state\":{\"ip\":\"10.0.0.50\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet104\"},\"name\":\"Ethernet104\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet104\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.52\",\"prefix-length\":31},\"ip\":\"10.0.0.52\",\"state\":{\"ip\":\"10.0.0.52\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet108\"},\"name\":\"Ethernet108\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet108\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.54\",\"prefix-length\":31},\"ip\":\"10.0.0.54\",\"state\":{\"ip\":\"10.0.0.54\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet112\"},\"name\":\"Ethernet112\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet112\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.56\",\"prefix-length\":31},\"ip\":\"10.0.0.56\",\"state\":{\"ip\":\"10.0.0.56\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet116\"},\"name\":\"Ethernet116\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet116\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.58\",\"prefix-length\":31},\"ip\":\"10.0.0.58\",\"state\":{\"ip\":\"10.0.0.58\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet12\"},\"name\":\"Ethernet12\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet12\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.6\",\"prefix-length\":31},\"ip\":\"10.0.0.6\",\"state\":{\"ip\":\"10.0.0.6\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet120\"},\"name\":\"Ethernet120\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet120\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.60\",\"prefix-length\":31},\"ip\":\"10.0.0.60\",\"state\":{\"ip\":\"10.0.0.60\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet124\"},\"name\":\"Ethernet124\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet124\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.62\",\"prefix-length\":31},\"ip\":\"10.0.0.62\",\"state\":{\"ip\":\"10.0.0.62\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet16\"},\"name\":\"Ethernet16\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet16\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.8\",\"prefix-length\":31},\"ip\":\"10.0.0.8\",\"state\":{\"ip\":\"10.0.0.8\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet20\"},\"name\":\"Ethernet20\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet20\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.10\",\"prefix-length\":31},\"ip\":\"10.0.0.10\",\"state\":{\"ip\":\"10.0.0.10\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet24\"},\"name\":\"Ethernet24\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet24\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.12\",\"prefix-length\":31},\"ip\":\"10.0.0.12\",\"state\":{\"ip\":\"10.0.0.12\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet28\"},\"name\":\"Ethernet28\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet28\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.14\",\"prefix-length\":31},\"ip\":\"10.0.0.14\",\"state\":{\"ip\":\"10.0.0.14\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet32\"},\"name\":\"Ethernet32\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet32\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.16\",\"prefix-length\":31},\"ip\":\"10.0.0.16\",\"state\":{\"ip\":\"10.0.0.16\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet36\"},\"name\":\"Ethernet36\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet36\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.18\",\"prefix-length\":31},\"ip\":\"10.0.0.18\",\"state\":{\"ip\":\"10.0.0.18\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet4\"},\"name\":\"Ethernet4\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet4\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.2\",\"prefix-length\":31},\"ip\":\"10.0.0.2\",\"state\":{\"ip\":\"10.0.0.2\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet40\"},\"name\":\"Ethernet40\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet40\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.20\",\"prefix-length\":31},\"ip\":\"10.0.0.20\",\"state\":{\"ip\":\"10.0.0.20\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet44\"},\"name\":\"Ethernet44\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet44\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.22\",\"prefix-length\":31},\"ip\":\"10.0.0.22\",\"state\":{\"ip\":\"10.0.0.22\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet48\"},\"name\":\"Ethernet48\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet48\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.24\",\"prefix-length\":31},\"ip\":\"10.0.0.24\",\"state\":{\"ip\":\"10.0.0.24\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet52\"},\"name\":\"Ethernet52\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet52\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.26\",\"prefix-length\":31},\"ip\":\"10.0.0.26\",\"state\":{\"ip\":\"10.0.0.26\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet56\"},\"name\":\"Ethernet56\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet56\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.28\",\"prefix-length\":31},\"ip\":\"10.0.0.28\",\"state\":{\"ip\":\"10.0.0.28\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet60\"},\"name\":\"Ethernet60\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet60\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.30\",\"prefix-length\":31},\"ip\":\"10.0.0.30\",\"state\":{\"ip\":\"10.0.0.30\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet64\"},\"name\":\"Ethernet64\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet64\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.32\",\"prefix-length\":31},\"ip\":\"10.0.0.32\",\"state\":{\"ip\":\"10.0.0.32\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet68\"},\"name\":\"Ethernet68\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet68\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.34\",\"prefix-length\":31},\"ip\":\"10.0.0.34\",\"state\":{\"ip\":\"10.0.0.34\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet72\"},\"name\":\"Ethernet72\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet72\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.36\",\"prefix-length\":31},\"ip\":\"10.0.0.36\",\"state\":{\"ip\":\"10.0.0.36\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet76\"},\"name\":\"Ethernet76\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet76\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.38\",\"prefix-length\":31},\"ip\":\"10.0.0.38\",\"state\":{\"ip\":\"10.0.0.38\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet8\"},\"name\":\"Ethernet8\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet8\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.4\",\"prefix-length\":31},\"ip\":\"10.0.0.4\",\"state\":{\"ip\":\"10.0.0.4\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet80\"},\"name\":\"Ethernet80\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet80\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.40\",\"prefix-length\":31},\"ip\":\"10.0.0.40\",\"state\":{\"ip\":\"10.0.0.40\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet84\"},\"name\":\"Ethernet84\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet84\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.42\",\"prefix-length\":31},\"ip\":\"10.0.0.42\",\"state\":{\"ip\":\"10.0.0.42\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet88\"},\"name\":\"Ethernet88\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet88\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.44\",\"prefix-length\":31},\"ip\":\"10.0.0.44\",\"state\":{\"ip\":\"10.0.0.44\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet92\"},\"name\":\"Ethernet92\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet92\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.46\",\"prefix-length\":31},\"ip\":\"10.0.0.46\",\"state\":{\"ip\":\"10.0.0.46\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"mtu\":9100,\"name\":\"Ethernet96\"},\"name\":\"Ethernet96\",\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"mtu\":9100,\"name\":\"Ethernet96\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.48\",\"prefix-length\":31},\"ip\":\"10.0.0.48\",\"state\":{\"ip\":\"10.0.0.48\",\"prefix-length\":31}}]}}}]}},{\"config\":{\"name\":\"PortConfigDone\"},\"name\":\"PortConfigDone\",\"state\":{\"name\":\"PortConfigDone\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0}]}},{\"config\":{\"name\":\"PortInitDone\"},\"name\":\"PortInitDone\",\"state\":{\"name\":\"PortInitDone\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0}]}}]}}" - > - > -> - diff --git a/test/interfaces_get.test b/test/interfaces_get.test deleted file mode 100644 index 9a8658e28..000000000 --- a/test/interfaces_get.test +++ /dev/null @@ -1 +0,0 @@ -./gnmi_get -xpath /openconfig-interfaces:interfaces -target_addr 127.0.0.1:8080 -insecure diff --git a/test/lldp_neighbor_subscribe.result b/test/lldp_neighbor_subscribe.result deleted file mode 100644 index 3e3d1de3e..000000000 --- a/test/lldp_neighbor_subscribe.result +++ /dev/null @@ -1,11 +0,0 @@ -{ - "OC-YANG": { - "openconfig-lldp:lldp": { - "interfaces": { - "interface": { - "Ethernet0": "{\"openconfig-lldp:interface\":[{\"name\":\"Ethernet0\",\"neighbors\":{\"neighbor\":[{\"capabilities\":{\"capability\":[{\"name\":\"openconfig-lldp-types:MAC_BRIDGE\",\"state\":{\"enabled\":true,\"name\":\"openconfig-lldp-types:MAC_BRIDGE\"}},{\"name\":\"openconfig-lldp-types:REPEATER\",\"state\":{\"enabled\":true,\"name\":\"openconfig-lldp-types:REPEATER\"}},{\"name\":\"openconfig-lldp-types:ROUTER\",\"state\":{\"enabled\":true,\"name\":\"openconfig-lldp-types:ROUTER\"}}]},\"id\":\"Ethernet0\",\"state\":{\"chassis-id\":\"34:17:eb:2c:d7:00\",\"chassis-id-type\":\"MAC_ADDRESS\",\"id\":\"2\",\"management-address\":\"\",\"port-description\":\"ethernet1/1/1:1\",\"port-id\":\"ethernet1/1/1:1\",\"port-id-type\":\"INTERFACE_NAME\",\"system-description\":\"Dell EMC Networking OS10 Enterprise.\\r\\nCopyright (c) 1999-2019 by Dell Inc. All Rights Reserved.\\r\\nSystem Description: OS10 Enterprise.\\r\\nOS Version: 10.4.9999EX.\\r\\nSystem Type: Z9100-ON\",\"system-name\":\"OS10\",\"ttl\":19532}}]}}]}" - } - } - } - } -} diff --git a/test/lldp_neighbor_subscribe.test b/test/lldp_neighbor_subscribe.test deleted file mode 100644 index 321710dbd..000000000 --- a/test/lldp_neighbor_subscribe.test +++ /dev/null @@ -1 +0,0 @@ -./gnmi_cli -insecure -logtostderr -address 127.0.0.1:8080 -query_type s -streaming_type ON_CHANGE -q /openconfig-lldp:lldp/interfaces/interface[name=Ethernet0] -v 0 -target OC-YANG From b1cbfb549429fbc2a1b32b2d48d605e02724c625 Mon Sep 17 00:00:00 2001 From: Eric Seifert Date: Wed, 26 Feb 2020 14:53:44 -0800 Subject: [PATCH 03/13] wip --- debian/control | 4 +- dialout/dialout_client/dialout_client.go | 15 +- dialout/dialout_client/dialout_client_test.go | 18 +- .../dialout_client_cli/dialout_client_cli.go | 2 +- dialout/dialout_server/dialout_server.go | 2 +- .../dialout_server_cli/dialout_server_cli.go | 4 +- doc/grpc_telemetry.md | 2 +- gnmi_clients/gnmi_get.go | 147 ---------- gnmi_clients/gnmi_set.go | 195 ------------- gnmi_clients/gnoi_client.go | 274 ------------------ gnmi_server/run_gnmi_server_test.sh | 3 - go.mod | 35 +++ go.sum | 115 ++++++++ patches/gnmi_cli.all.patch | 72 +++++ 14 files changed, 245 insertions(+), 643 deletions(-) delete mode 100644 gnmi_clients/gnmi_get.go delete mode 100644 gnmi_clients/gnmi_set.go delete mode 100644 gnmi_clients/gnoi_client.go delete mode 100644 gnmi_server/run_gnmi_server_test.sh create mode 100644 go.mod create mode 100644 go.sum create mode 100644 patches/gnmi_cli.all.patch diff --git a/debian/control b/debian/control index 1f26c8b1b..932a1b844 100644 --- a/debian/control +++ b/debian/control @@ -4,8 +4,8 @@ Priority: optional Maintainer: Jipan Yang Build-Depends: debhelper (>= 8.0.0), Standards-Version: 3.9.3 -Homepage: https://github.com/project-arlo/sonic-telemetry -XS-Go-Import-Path: github.com/project-arlo/sonic-telemetry +Homepage: https://github.com/Azure/sonic-telemetry +XS-Go-Import-Path: github.com/Azure/sonic-telemetry Package: sonic-telemetry Architecture: any diff --git a/dialout/dialout_client/dialout_client.go b/dialout/dialout_client/dialout_client.go index 9fd7339eb..451a4c10c 100644 --- a/dialout/dialout_client/dialout_client.go +++ b/dialout/dialout_client/dialout_client.go @@ -5,8 +5,9 @@ import ( "crypto/tls" "errors" "fmt" - spb "proto" - sdc "sonic_data_client" + spb "github.com/Azure/sonic-telemetry/proto" + sdc "github.com/Azure/sonic-telemetry/sonic_data_client" + sdcfg "github.com/Azure/sonic-telemetry/sonic_db_config" "github.com/go-redis/redis" log "github.com/golang/glog" gpb "github.com/openconfig/gnmi/proto/gnmi" @@ -641,23 +642,23 @@ func processTelemetryClientConfig(ctx context.Context, redisDb *redis.Client, ke // read configDB data for telemetry client and start publishing service for client subscription func DialOutRun(ctx context.Context, ccfg *ClientConfig) error { clientCfg = ccfg - dbn := spb.Target_value["CONFIG_DB"] + dbn := sdcfg.GetDbId("CONFIG_DB") var redisDb *redis.Client if sdc.UseRedisLocalTcpPort == false { redisDb = redis.NewClient(&redis.Options{ Network: "unix", - Addr: sdc.Default_REDIS_UNIXSOCKET, + Addr: sdcfg.GetDbSock("CONFIG_DB"), Password: "", // no password set - DB: int(dbn), + DB: dbn, DialTimeout: 0, }) } else { redisDb = redis.NewClient(&redis.Options{ Network: "tcp", - Addr: sdc.Default_REDIS_LOCAL_TCP_PORT, + Addr: sdcfg.GetDbTcpAddr("CONFIG_DB"), Password: "", // no password set - DB: int(dbn), + DB: dbn, DialTimeout: 0, }) } diff --git a/dialout/dialout_client/dialout_client_test.go b/dialout/dialout_client/dialout_client_test.go index 91ca67f97..1a8b76ebd 100644 --- a/dialout/dialout_client/dialout_client_test.go +++ b/dialout/dialout_client/dialout_client_test.go @@ -8,7 +8,7 @@ import ( "encoding/json" "github.com/go-redis/redis" //"github.com/golang/protobuf/proto" - testcert "testdata/tls" + testcert "github.com/Azure/sonic-telemetry/testdata/tls" //"github.com/kylelemons/godebug/pretty" //"github.com/openconfig/gnmi/client" @@ -28,9 +28,9 @@ import ( "testing" "time" - sds "dialout/dialout_server" - spb "proto" - sdc "sonic_data_client" + sds "github.com/Azure/sonic-telemetry/dialout/dialout_server" + sdc "github.com/Azure/sonic-telemetry/sonic_data_client" + sdcfg "github.com/Azure/sonic-telemetry/sonic_db_config" gclient "github.com/openconfig/gnmi/client/gnmi" ) @@ -95,12 +95,11 @@ func runServer(t *testing.T, s *sds.Server) { } func getRedisClient(t *testing.T) *redis.Client { - dbn := spb.Target_value["COUNTERS_DB"] rclient := redis.NewClient(&redis.Options{ Network: "tcp", - Addr: "localhost:6379", + Addr: sdcfg.GetDbTcpAddr("COUNTERS_DB"), Password: "", // no password set - DB: int(dbn), + DB: sdcfg.GetDbId("COUNTERS_DB"), DialTimeout: 0, }) _, err := rclient.Ping().Result() @@ -125,12 +124,11 @@ func exe_cmd(t *testing.T, cmd string) { } func getConfigDbClient(t *testing.T) *redis.Client { - dbn := spb.Target_value["CONFIG_DB"] rclient := redis.NewClient(&redis.Options{ Network: "tcp", - Addr: "localhost:6379", + Addr: sdcfg.GetDbTcpAddr("CONFIG_DB"), Password: "", // no password set - DB: int(dbn), + DB: sdcfg.GetDbId("CONFIG_DB"), DialTimeout: 0, }) _, err := rclient.Ping().Result() diff --git a/dialout/dialout_client_cli/dialout_client_cli.go b/dialout/dialout_client_cli/dialout_client_cli.go index 6da86a8b7..d8d9014da 100644 --- a/dialout/dialout_client_cli/dialout_client_cli.go +++ b/dialout/dialout_client_cli/dialout_client_cli.go @@ -4,7 +4,7 @@ package main import ( "crypto/tls" "flag" - dc "dialout/dialout_client" + dc "github.com/Azure/sonic-telemetry/dialout/dialout_client" log "github.com/golang/glog" gpb "github.com/openconfig/gnmi/proto/gnmi" "golang.org/x/net/context" diff --git a/dialout/dialout_server/dialout_server.go b/dialout/dialout_server/dialout_server.go index 9d781cfd5..f5d34d0be 100644 --- a/dialout/dialout_server/dialout_server.go +++ b/dialout/dialout_server/dialout_server.go @@ -3,7 +3,7 @@ package dialout_server import ( "errors" "fmt" - spb "proto" + spb "github.com/Azure/sonic-telemetry/proto" log "github.com/golang/glog" "github.com/google/gnxi/utils" gpb "github.com/openconfig/gnmi/proto/gnmi" diff --git a/dialout/dialout_server_cli/dialout_server_cli.go b/dialout/dialout_server_cli/dialout_server_cli.go index 88cf1d7cc..02b9cee06 100644 --- a/dialout/dialout_server_cli/dialout_server_cli.go +++ b/dialout/dialout_server_cli/dialout_server_cli.go @@ -10,8 +10,8 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials" - ds "dialout/dialout_server" - testcert "testdata/tls" + ds "github.com/Azure/sonic-telemetry/dialout/dialout_server" + testcert "github.com/Azure/sonic-telemetry/testdata/tls" ) var ( diff --git a/doc/grpc_telemetry.md b/doc/grpc_telemetry.md index ba04a4e34..6dd6c2b7c 100644 --- a/doc/grpc_telemetry.md +++ b/doc/grpc_telemetry.md @@ -61,7 +61,7 @@ Within each DB, the data usually is organized in hierarchy of Table, key, field ``` Some data like COUNTERS table in COUNTERS_DB doesn't have key, but field and value are stored directly under COUNTERS table. -Refer to [SONiC data schema](https://github.com/project-arlo/sonic-swss-common/blob/master/common/schema.h) for more info about DB and table. +Refer to [SONiC data schema](https://github.com/Azure/sonic-swss-common/blob/master/common/schema.h) for more info about DB and table. For data not available in DBs, Target name "OTHERS" is designated for that category of data, paths like platform/cpu or proc/loadavg under "OTHERS" target may be used get/subscribe the data. diff --git a/gnmi_clients/gnmi_get.go b/gnmi_clients/gnmi_get.go deleted file mode 100644 index 2feac44e6..000000000 --- a/gnmi_clients/gnmi_get.go +++ /dev/null @@ -1,147 +0,0 @@ -/* Copyright 2017 Google Inc. - -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 - - https://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. -*/ - -// Binary gnmi_get performs a get request against a gNMI target. -package main - -import ( - "flag" - "fmt" - "strings" - "time" - - log "github.com/golang/glog" - "github.com/golang/protobuf/proto" - "golang.org/x/net/context" - "google.golang.org/grpc" - - "github.com/google/gnxi/utils" - "github.com/google/gnxi/utils/credentials" - "github.com/jipanyang/gnxi/utils/xpath" - "google.golang.org/grpc/metadata" - pb "github.com/openconfig/gnmi/proto/gnmi" -) - -type arrayFlags []string - -func (i *arrayFlags) String() string { - return "my string representation" -} - -func (i *arrayFlags) Set(value string) error { - *i = append(*i, value) - return nil -} - -func parseModelData(s *string) (*pb.ModelData, error) { - pbModelData := new(pb.ModelData) - modelDataVars := strings.Split(*s, ",") - if len(modelDataVars) != 3 { - return pbModelData, fmt.Errorf("Unable to parse string") - } - pbModelData = &pb.ModelData{ - Name: modelDataVars[0], - Organization: modelDataVars[1], - Version: modelDataVars[2], - } - return pbModelData, nil -} - -var ( - xPathFlags arrayFlags - pbPathFlags arrayFlags - pbModelDataFlags arrayFlags - pathTarget = flag.String("xpath_target", "", "name of the target for which the path is a member") - targetAddr = flag.String("target_addr", "localhost:10161", "The target address in the format of host:port") - targetName = flag.String("target_name", "hostname.com", "The target name use to verify the hostname returned by TLS handshake") - timeOut = flag.Duration("time_out", 10*time.Second, "Timeout for the Get request, 10 seconds by default") - encodingName = flag.String("encoding", "JSON_IETF", "value encoding format to be used") - jwtToken = flag.String("jwt_token", "", "JWT Token if required") -) - -func main() { - flag.Var(&xPathFlags, "xpath", "xpath of the config node to be fetched") - flag.Var(&pbPathFlags, "pbpath", "protobuf format path of the config node to be fetched") - flag.Var(&pbModelDataFlags, "model_data", "Data models to be used by the target in the format of 'name,organization,version'") - flag.Parse() - - opts := credentials.ClientCredentials(*targetName) - conn, err := grpc.Dial(*targetAddr, opts...) - if err != nil { - log.Exitf("Dialing to %q failed: %v", *targetAddr, err) - } - defer conn.Close() - - cli := pb.NewGNMIClient(conn) - - ctx, cancel := context.WithTimeout(context.Background(), *timeOut) - defer cancel() - - if len(*jwtToken) > 0 { - ctx = metadata.AppendToOutgoingContext(ctx, "access_token", *jwtToken) - } - - encoding, ok := pb.Encoding_value[*encodingName] - if !ok { - var gnmiEncodingList []string - for _, name := range pb.Encoding_name { - gnmiEncodingList = append(gnmiEncodingList, name) - } - log.Exitf("Supported encodings: %s", strings.Join(gnmiEncodingList, ", ")) - } - - var prefix pb.Path - prefix.Target = *pathTarget - var pbPathList []*pb.Path - var pbModelDataList []*pb.ModelData - for _, xPath := range xPathFlags { - pbPath, err := xpath.ToGNMIPath(xPath) - if err != nil { - log.Exitf("error in parsing xpath %q to gnmi path, %v", xPath, err) - } - pbPathList = append(pbPathList, pbPath) - } - for _, textPbPath := range pbPathFlags { - var pbPath pb.Path - if err := proto.UnmarshalText(textPbPath, &pbPath); err != nil { - log.Exitf("error in unmarshaling %q to gnmi Path", textPbPath) - } - pbPathList = append(pbPathList, &pbPath) - } - for _, textPbModelData := range pbModelDataFlags { - pbModelData, err := parseModelData(&textPbModelData) - if err == nil { - pbModelDataList = append(pbModelDataList, pbModelData) - } - } - - getRequest := &pb.GetRequest{ - Prefix: &prefix, - Encoding: pb.Encoding(encoding), - Path: pbPathList, - UseModels: pbModelDataList, - } - - fmt.Println("== getRequest:") - utils.PrintProto(getRequest) - - getResponse, err := cli.Get(ctx, getRequest) - if err != nil { - log.Exitf("Get failed: %v", err) - } - - fmt.Println("== getResponse:") - utils.PrintProto(getResponse) -} diff --git a/gnmi_clients/gnmi_set.go b/gnmi_clients/gnmi_set.go deleted file mode 100644 index d2c852201..000000000 --- a/gnmi_clients/gnmi_set.go +++ /dev/null @@ -1,195 +0,0 @@ -/* Copyright 2017 Google Inc. - -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 - - https://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. -*/ - -// Binary gnmi_set performs a set request against a gNMI target with the specified config file. -package main - -import ( - "bytes" - "flag" - "fmt" - "io/ioutil" - "strconv" - "strings" - "time" - - log "github.com/golang/glog" - "golang.org/x/net/context" - "google.golang.org/grpc" - - "github.com/google/gnxi/utils" - "github.com/google/gnxi/utils/credentials" - //"github.com/google/gnxi/utils/xpath" - "github.com/jipanyang/gnxi/utils/xpath" - "google.golang.org/grpc/metadata" - pb "github.com/openconfig/gnmi/proto/gnmi" -) - -type arrayFlags []string - -func (i *arrayFlags) String() string { - return "my string representation" -} - -func (i *arrayFlags) Set(value string) error { - *i = append(*i, value) - return nil -} - -var ( - deleteOpt arrayFlags - replaceOpt arrayFlags - updateOpt arrayFlags - targetAddr = flag.String("target_addr", "localhost:10161", "The target address in the format of host:port") - targetName = flag.String("target_name", "hostname.com", "The target name use to verify the hostname returned by TLS handshake") - timeOut = flag.Duration("time_out", 10*time.Second, "Timeout for the Get request, 10 seconds by default") - pathTarget = flag.String("xpath_target", "", "name of the target for which the path is a member") - jwtToken = flag.String("jwt_token", "", "JWT Token if required") -) - -func buildPbUpdateList(pathValuePairs []string) []*pb.Update { - var pbUpdateList []*pb.Update - for _, item := range pathValuePairs { - modName := strings.SplitN(item, "/", 3) - - pathValuePair := make([]string, 2) - lc := strings.LastIndex(modName[2],":") - - if lc == -1 { - log.Exitf("invalid path-value pair: %v", item) - } - pathValuePair_r := strings.SplitN(modName[2], ":", 2) - // pathValuePair[0] = modName[2][0:lc] - - pathValuePair[0] = "/" + modName[1] + "/" + pathValuePair_r[0] - - pathValuePair[1] = modName[2][lc+1:] - fmt.Println(pathValuePair[0]) - fmt.Println(pathValuePair[1]) - - - if len(pathValuePair) != 2 || len(pathValuePair[1]) == 0 { - log.Exitf("invalid path-value pair: %v", item) - log.Exitf("invalid path-value pair: %v", modName) - } - - - pbPath, err := xpath.ToGNMIPath(pathValuePair[0]) - if err != nil { - log.Exitf("error in parsing xpath %q to gnmi path", pathValuePair[0]) - } - var pbVal *pb.TypedValue - if pathValuePair[1][0] == '@' { - jsonFile := pathValuePair[1][1:] - jsonConfig, err := ioutil.ReadFile(jsonFile) - if err != nil { - log.Exitf("cannot read data from file %v", jsonFile) - } - jsonConfig = bytes.Trim(jsonConfig, " \r\n\t") - pbVal = &pb.TypedValue{ - Value: &pb.TypedValue_JsonIetfVal{ - JsonIetfVal: jsonConfig, - }, - } - } else { - if strVal, err := strconv.Unquote(pathValuePair[1]); err == nil { - pbVal = &pb.TypedValue{ - Value: &pb.TypedValue_StringVal{ - StringVal: strVal, - }, - } - } else { - if intVal, err := strconv.ParseInt(pathValuePair[1], 10, 64); err == nil { - pbVal = &pb.TypedValue{ - Value: &pb.TypedValue_IntVal{ - IntVal: intVal, - }, - } - } else if floatVal, err := strconv.ParseFloat(pathValuePair[1], 32); err == nil { - pbVal = &pb.TypedValue{ - Value: &pb.TypedValue_FloatVal{ - FloatVal: float32(floatVal), - }, - } - } else if boolVal, err := strconv.ParseBool(pathValuePair[1]); err == nil { - pbVal = &pb.TypedValue{ - Value: &pb.TypedValue_BoolVal{ - BoolVal: boolVal, - }, - } - } else { - pbVal = &pb.TypedValue{ - Value: &pb.TypedValue_StringVal{ - StringVal: pathValuePair[1], - }, - } - } - } - } - pbUpdateList = append(pbUpdateList, &pb.Update{Path: pbPath, Val: pbVal}) - } - return pbUpdateList -} - -func main() { - flag.Var(&deleteOpt, "delete", "xpath to be deleted.") - flag.Var(&replaceOpt, "replace", "xpath:value pair to be replaced. Value can be numeric, boolean, string, or IETF JSON file (. starts with '@').") - flag.Var(&updateOpt, "update", "xpath:value pair to be updated. Value can be numeric, boolean, string, or IETF JSON file (. starts with '@').") - flag.Parse() - - opts := credentials.ClientCredentials(*targetName) - conn, err := grpc.Dial(*targetAddr, opts...) - if err != nil { - log.Exitf("Dialing to %q failed: %v", *targetAddr, err) - } - defer conn.Close() - - var deleteList []*pb.Path - for _, xPath := range deleteOpt { - pbPath, err := xpath.ToGNMIPath(xPath) - if err != nil { - log.Exitf("error in parsing xpath %q to gnmi path", xPath) - } - deleteList = append(deleteList, pbPath) - } - replaceList := buildPbUpdateList(replaceOpt) - updateList := buildPbUpdateList(updateOpt) - var prefix pb.Path - prefix.Target = *pathTarget - setRequest := &pb.SetRequest{ - Prefix: &prefix, - Delete: deleteList, - Replace: replaceList, - Update: updateList, - } - - fmt.Println("== setRequest:") - utils.PrintProto(setRequest) - - cli := pb.NewGNMIClient(conn) - ctx, cancel := context.WithTimeout(context.Background(), *timeOut) - defer cancel() - - if len(*jwtToken) > 0 { - ctx = metadata.AppendToOutgoingContext(ctx, "access_token", *jwtToken) - } - setResponse, err := cli.Set(ctx, setRequest) - if err != nil { - log.Exitf("Set failed: %v", err) - } - - fmt.Println("== setResponse:") - utils.PrintProto(setResponse) -} diff --git a/gnmi_clients/gnoi_client.go b/gnmi_clients/gnoi_client.go deleted file mode 100644 index 94d39034d..000000000 --- a/gnmi_clients/gnoi_client.go +++ /dev/null @@ -1,274 +0,0 @@ -package main - -import ( - "google.golang.org/grpc" - gnoi_system_pb "github.com/openconfig/gnoi/system" - spb "proto/gnoi" - "context" - "os" - "os/signal" - "fmt" - "flag" - "google.golang.org/grpc/metadata" - "github.com/google/gnxi/utils/credentials" - "encoding/json" -) - -var ( - module = flag.String("module", "System", "gNOI Module") - rpc = flag.String("rpc", "Time", "rpc call in specified module to call") - target = flag.String("target", "localhost:8080", "Address:port of gNOI Server") - args = flag.String("jsonin", "", "RPC Arguments in json format") - jwtToken = flag.String("jwt_token", "", "JWT Token if required") - targetName = flag.String("target_name", "hostname.com", "The target name use to verify the hostname returned by TLS handshake") -) -func setUserCreds(ctx context.Context) context.Context { - if len(*jwtToken) > 0 { - ctx = metadata.AppendToOutgoingContext(ctx, "access_token", *jwtToken) - } - return ctx -} -func main() { - flag.Parse() - opts := credentials.ClientCredentials(*targetName) - - ctx, cancel := context.WithCancel(context.Background()) - go func() { - c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt) - <-c - cancel() - }() - conn, err := grpc.Dial(*target, opts...) - if err != nil { - panic(err.Error()) - } - - switch *module { - case "System": - sc := gnoi_system_pb.NewSystemClient(conn) - switch *rpc { - case "Time": - systemTime(sc, ctx) - default: - panic("Invalid RPC Name") - } - case "Sonic": - sc := spb.NewSonicServiceClient(conn) - switch *rpc { - case "showtechsupport": - sonicShowTechSupport(sc, ctx) - case "sum": - sonicSum(sc, ctx) - case "copyConfig": - copyConfig(sc, ctx) - case "authenticate": - authenticate(sc, ctx) - case "imageInstall": - imageInstall(sc, ctx) - case "imageDefault": - imageDefault(sc, ctx) - case "imageRemove": - imageRemove(sc, ctx) - case "refresh": - refresh(sc, ctx) - case "clearNeighbors": - clearNeighbors(sc, ctx) - default: - panic("Invalid RPC Name") - } - default: - panic("Invalid Module Name") - } - -} - -func systemTime(sc gnoi_system_pb.SystemClient, ctx context.Context) { - fmt.Println("System Time") - ctx = setUserCreds(ctx) - resp,err := sc.Time(ctx, new(gnoi_system_pb.TimeRequest)) - if err != nil { - panic(err.Error()) - } - respstr, err := json.Marshal(resp) - if err != nil { - panic(err.Error()) - } - fmt.Println(string(respstr)) -} -func sonicShowTechSupport(sc spb.SonicServiceClient, ctx context.Context) { - fmt.Println("Sonic ShowTechsupport") - ctx = setUserCreds(ctx) - req := &spb.TechsupportRequest { - Input: &spb.TechsupportRequest_Input{ - - }, - } - - json.Unmarshal([]byte(*args), req) - - resp,err := sc.ShowTechsupport(ctx, req) - if err != nil { - panic(err.Error()) - } - respstr, err := json.Marshal(resp) - if err != nil { - panic(err.Error()) - } - fmt.Println(string(respstr)) -} -func sonicSum(sc spb.SonicServiceClient, ctx context.Context) { - fmt.Println("Sonic Sum") - ctx = setUserCreds(ctx) - req := &spb.SumRequest{ - Input: &spb.SumRequest_Input{}, - } - - json.Unmarshal([]byte(*args), req) - - resp,err := sc.Sum(ctx, req) - - if err != nil { - panic(err.Error()) - } - respstr, err := json.Marshal(resp) - if err != nil { - panic(err.Error()) - } - fmt.Println(string(respstr)) -} - -func copyConfig(sc spb.SonicServiceClient, ctx context.Context) { - fmt.Println("Sonic CopyConfig") - ctx = setUserCreds(ctx) - req := &spb.CopyConfigRequest{ - Input: &spb.CopyConfigRequest_Input{}, - } - json.Unmarshal([]byte(*args), req) - - resp,err := sc.CopyConfig(ctx, req) - - if err != nil { - panic(err.Error()) - } - respstr, err := json.Marshal(resp) - if err != nil { - panic(err.Error()) - } - fmt.Println(string(respstr)) -} - -func imageInstall(sc spb.SonicServiceClient, ctx context.Context) { - fmt.Println("Sonic ImageInstall") - ctx = setUserCreds(ctx) - req := &spb.ImageInstallRequest{ - Input: &spb.ImageInstallRequest_Input{}, - } - json.Unmarshal([]byte(*args), req) - - resp,err := sc.ImageInstall(ctx, req) - - if err != nil { - panic(err.Error()) - } - respstr, err := json.Marshal(resp) - if err != nil { - panic(err.Error()) - } - fmt.Println(string(respstr)) -} -func imageRemove(sc spb.SonicServiceClient, ctx context.Context) { - fmt.Println("Sonic ImageRemove") - ctx = setUserCreds(ctx) - req := &spb.ImageRemoveRequest{ - Input: &spb.ImageRemoveRequest_Input{}, - } - json.Unmarshal([]byte(*args), req) - - resp,err := sc.ImageRemove(ctx, req) - - if err != nil { - panic(err.Error()) - } - respstr, err := json.Marshal(resp) - if err != nil { - panic(err.Error()) - } - fmt.Println(string(respstr)) -} - -func imageDefault(sc spb.SonicServiceClient, ctx context.Context) { - fmt.Println("Sonic ImageDefault") - ctx = setUserCreds(ctx) - req := &spb.ImageDefaultRequest{ - Input: &spb.ImageDefaultRequest_Input{}, - } - json.Unmarshal([]byte(*args), req) - - resp,err := sc.ImageDefault(ctx, req) - - if err != nil { - panic(err.Error()) - } - respstr, err := json.Marshal(resp) - if err != nil { - panic(err.Error()) - } - fmt.Println(string(respstr)) -} - -func authenticate(sc spb.SonicServiceClient, ctx context.Context) { - fmt.Println("Sonic Authenticate") - ctx = setUserCreds(ctx) - req := &spb.AuthenticateRequest {} - - json.Unmarshal([]byte(*args), req) - - resp,err := sc.Authenticate(ctx, req) - if err != nil { - panic(err.Error()) - } - respstr, err := json.Marshal(resp) - if err != nil { - panic(err.Error()) - } - fmt.Println(string(respstr)) -} - -func refresh(sc spb.SonicServiceClient, ctx context.Context) { - fmt.Println("Sonic Refresh") - ctx = setUserCreds(ctx) - req := &spb.RefreshRequest {} - - json.Unmarshal([]byte(*args), req) - - resp,err := sc.Refresh(ctx, req) - if err != nil { - panic(err.Error()) - } - respstr, err := json.Marshal(resp) - if err != nil { - panic(err.Error()) - } - fmt.Println(string(respstr)) -} - -func clearNeighbors(sc spb.SonicServiceClient, ctx context.Context) { - fmt.Println("Sonic ClearNeighbors") - ctx = setUserCreds(ctx) - req := &spb.ClearNeighborsRequest{ - Input: &spb.ClearNeighborsRequest_Input{}, - } - json.Unmarshal([]byte(*args), req) - - resp,err := sc.ClearNeighbors(ctx, req) - - if err != nil { - panic(err.Error()) - } - respstr, err := json.Marshal(resp) - if err != nil { - panic(err.Error()) - } - fmt.Println(string(respstr)) -} diff --git a/gnmi_server/run_gnmi_server_test.sh b/gnmi_server/run_gnmi_server_test.sh deleted file mode 100644 index 46e899e7b..000000000 --- a/gnmi_server/run_gnmi_server_test.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -GOPATH=$PWD/../sonic-mgmt-framework:$PWD/../sonic-mgmt-framework/gopkgs:$PWD:$HOME/go go test -v -cover -json gnmi_server | tparse -smallscreen -all - diff --git a/go.mod b/go.mod new file mode 100644 index 000000000..177693637 --- /dev/null +++ b/go.mod @@ -0,0 +1,35 @@ +module github.com/Azure/sonic-telemetry + +go 1.12 + +require ( + github.com/Workiva/go-datastructures v1.0.50 + github.com/antchfx/jsonquery v1.1.0 + github.com/antchfx/xmlquery v1.2.1 + github.com/antchfx/xpath v1.1.2 // indirect + github.com/c9s/goprocinfo v0.0.0-20191125144613-4acdd056c72d + github.com/go-redis/redis v6.15.6+incompatible + github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b + github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 // indirect + github.com/golang/protobuf v1.3.2 + github.com/google/gnxi v0.0.0-20191016182648-6697a080bc2d + github.com/jipanyang/gnmi v0.0.0-20180820232453-cb4d464fa018 + github.com/jipanyang/gnxi v0.0.0-20181221084354-f0a90cca6fd0 // indirect + github.com/kylelemons/godebug v1.1.0 + github.com/onsi/ginkgo v1.10.3 // indirect + github.com/onsi/gomega v1.7.1 // indirect + github.com/openconfig/gnmi v0.0.0-20190823184014-89b2bf29312c + github.com/openconfig/goyang v0.0.0-20190924211109-064f9690516f + github.com/openconfig/ygot v0.6.1-0.20190723223108-724a6b18a922 + github.com/pborman/getopt v0.0.0-20190409184431-ee0cd42419d3 // indirect + github.com/stretchr/testify v1.4.0 // indirect + golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 // indirect + golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect + golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 + golang.org/x/text v0.3.0 + golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 // indirect + google.golang.org/grpc v1.25.1 + honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc // indirect +) + +replace github.com/Azure/sonic-mgmt-framework => ../sonic-mgmt-framework diff --git a/go.sum b/go.sum new file mode 100644 index 000000000..e63e0ce1c --- /dev/null +++ b/go.sum @@ -0,0 +1,115 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/Workiva/go-datastructures v1.0.50 h1:slDmfW6KCHcC7U+LP3DDBbm4fqTwZGn1beOFPfGaLvo= +github.com/Workiva/go-datastructures v1.0.50/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA= +github.com/antchfx/jsonquery v1.1.0 h1:ZeqeHheI8WsEN5blUqZXZ30w2jrbFvlQIq5B7X7Z86E= +github.com/antchfx/jsonquery v1.1.0/go.mod h1:h7950pvPrUZzJIflNqsELgDQovTpPNa0rAHf8NwjegY= +github.com/antchfx/xmlquery v1.2.1 h1:wE4xjHrqOScP440wdv23Xkg0Gr8JryW0ptqodPH+y2U= +github.com/antchfx/xmlquery v1.2.1/go.mod h1:/+CnyD/DzHRnv2eRxrVbieRU/FIF6N0C+7oTtyUtCKk= +github.com/antchfx/xpath v1.1.2 h1:YziPrtM0gEJBnhdUGxYcIVYXZ8FXbtbovxOi+UW/yWQ= +github.com/antchfx/xpath v1.1.2/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk= +github.com/c9s/goprocinfo v0.0.0-20191125144613-4acdd056c72d h1:MQGrhPHSxg08x+LKgQTOnnjfXt+p+128WCECqAYXJsU= +github.com/c9s/goprocinfo v0.0.0-20191125144613-4acdd056c72d/go.mod h1:uEyr4WpAH4hio6LFriaPkL938XnrvLpNPmQHBdrmbIE= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/go-redis/redis v6.15.6+incompatible h1:H9evprGPLI8+ci7fxQx6WNZHJSb7be8FqJQRhdQZ5Sg= +github.com/go-redis/redis v6.15.6+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 h1:uHTyIjqVhYRhLbJ8nIiOJHkEZZ+5YoOsAbD3sk82NiE= +github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/gnxi v0.0.0-20191016182648-6697a080bc2d h1:OtErLAncPdsEEhOI4ueR48dr6uThRIPkwWcOAdQ4LyI= +github.com/google/gnxi v0.0.0-20191016182648-6697a080bc2d/go.mod h1:6kkMbKS62iZMyk1q0zukcqkEJwnIhcbgg/hmoFmRDZk= +github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/jipanyang/gnmi v0.0.0-20180820232453-cb4d464fa018 h1:M++7b2XCTGqQwqu+AB0B3XzXiV+vVawnXJ4tvxUMrTU= +github.com/jipanyang/gnmi v0.0.0-20180820232453-cb4d464fa018/go.mod h1:+aiusdWGFuKzi7B8/Y75kTlIA3UDF+sUBfY5+1e2NLs= +github.com/jipanyang/gnxi v0.0.0-20181221084354-f0a90cca6fd0 h1:Dr/hrfbZxVlT/VvLfv8glHZAf9dLfuTSCJQq7cRGydo= +github.com/jipanyang/gnxi v0.0.0-20181221084354-f0a90cca6fd0/go.mod h1:vL9tMB3I625wwTPrEWmJ+kWrsHHFN/J79IEQD9knVi0= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.10.3 h1:OoxbjfXVZyod1fmWYhI7SEyaD8B00ynP3T+D5GiyHOY= +github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/openconfig/gnmi v0.0.0-20190823184014-89b2bf29312c h1:a380JP+B7xlMbEQOlha1buKhzBPXFqgFXplyWCEIGEY= +github.com/openconfig/gnmi v0.0.0-20190823184014-89b2bf29312c/go.mod h1:t+O9It+LKzfOAhKTT5O0ehDix+MTqbtT0T9t+7zzOvc= +github.com/openconfig/goyang v0.0.0-20190924211109-064f9690516f h1:BaekRUaWpfaRBP3mShDZaNi4+EHbdli7D6YXc/TP3lo= +github.com/openconfig/goyang v0.0.0-20190924211109-064f9690516f/go.mod h1:dhXaV0JgHJzdrHi2l+w0fZrwArtXL7jEFoiqLEdmkvU= +github.com/openconfig/ygot v0.6.0 h1:kJJFPBrczC6TDnz/HMlFTJEdW2CuyUftV13XveIukg0= +github.com/openconfig/ygot v0.6.1-0.20190723223108-724a6b18a922 h1:zBLb75mrLMxabjsAhPk/2qxbht+BwHKFWBvRAB4Fd2U= +github.com/openconfig/ygot v0.6.1-0.20190723223108-724a6b18a922/go.mod h1:o30svNf7O0xK+R35tlx95odkDmZWS9JyWWQSmIhqwAs= +github.com/openconfig/ygot v0.6.1-0.20191216180356-029bc88c228c h1:Ow7KYdHwjrPrRozqmYGtEEdEX5/owpE4dgRUvxmbSsI= +github.com/openconfig/ygot v0.6.1-0.20191216180356-029bc88c228c/go.mod h1:o30svNf7O0xK+R35tlx95odkDmZWS9JyWWQSmIhqwAs= +github.com/pborman/getopt v0.0.0-20190409184431-ee0cd42419d3 h1:YtFkrqsMEj7YqpIhRteVxJxCeC3jJBieuLr0d4C4rSA= +github.com/pborman/getopt v0.0.0-20190409184431-ee0cd42419d3/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 h1:ULYEB3JvPRE/IfO+9uO7vKV/xzVTO7XPAwm8xbf4w2g= +golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1 h1:wdKvqQk7IttEw92GoRyKG2IDrUIpgpj6H6m81yfeMW0= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/patches/gnmi_cli.all.patch b/patches/gnmi_cli.all.patch new file mode 100644 index 000000000..bc5b5b666 --- /dev/null +++ b/patches/gnmi_cli.all.patch @@ -0,0 +1,72 @@ +--- ./github.com/openconfig/gnmi/client/gnmi/client.go 2019-11-22 14:03:29.839103602 -0800 ++++ ./github.com/openconfig/gnmi/client/gnmi/client.go 2019-10-11 13:48:49.226145599 -0700 +@@ -257,7 +257,7 @@ + if err != nil { + return nil, fmt.Errorf("invalid query path %q: %v", qq, err) + } +- s.Subscribe.Subscription = append(s.Subscribe.Subscription, &gpb.Subscription{Path: pp}) ++ s.Subscribe.Subscription = append(s.Subscribe.Subscription, &gpb.Subscription{Path: pp, Mode: q.Streaming_type, SampleInterval: q.Streaming_sample_int, HeartbeatInterval: q.Heartbeat_int, SuppressRedundant: q.Suppress_redundant}) + } + return &gpb.SubscribeRequest{Request: s}, nil + } +--- ./github.com/openconfig/gnmi/cmd/gnmi_cli/gnmi_cli.go 2019-11-22 14:03:29.839103602 -0800 ++++ ./github.com/openconfig/gnmi/cmd/gnmi_cli/gnmi_cli.go 2019-11-21 09:30:52.453893674 -0800 +@@ -76,6 +76,11 @@ + caCert = flag.String("ca_crt", "", "CA certificate file. Used to verify server TLS certificate.") + clientCert = flag.String("client_crt", "", "Client certificate file. Used for client certificate-based authentication.") + clientKey = flag.String("client_key", "", "Client private key file. Used for client certificate-based authentication.") ++ //Subscribe Options ++ streaming_type = flag.String("streaming_type", "TARGET_DEFINED", "One of TARGET_DEFINED, ON_CHANGE or SAMPLE") ++ streaming_sample_int = flag.Uint("streaming_sample_interval", 0, "Streaming sample inteval seconds, 0 means lowest supported.") ++ heartbeat_int = flag.Uint("heartbeat_interval", 0, "Heartbeat inteval seconds.") ++ suppress_redundant = flag.Bool("suppress_redundant", false, "Suppress Redundant Subscription Updates") + ) + + func init() { +@@ -278,6 +283,22 @@ + if len(*queryFlag) == 0 { + return errors.New("--query must be set") + } ++ if *streaming_type == "TARGET_DEFINED" { ++ q.Streaming_type = gpb.SubscriptionMode(0) ++ } else if *streaming_type == "ON_CHANGE" { ++ q.Streaming_type = gpb.SubscriptionMode(1) ++ } else if *streaming_type == "SAMPLE" { ++ q.Streaming_type = gpb.SubscriptionMode(2) ++ } else { ++ return errors.New("-streaming_type must be one of: (TARGET_DEFINED, ON_CHANGE, SAMPLE)") ++ } ++ q.Streaming_sample_int = uint64(*streaming_sample_int)*uint64(time.Second) ++ if *queryType == "streaming" || *queryType == "s" { ++ q.Heartbeat_int = uint64(*heartbeat_int)*uint64(time.Second) ++ } else if *heartbeat_int > 0 { ++ return errors.New("-heartbeat_interval only valid with streaming query type") ++ } ++ q.Suppress_redundant = bool(*suppress_redundant) + for _, path := range *queryFlag { + query, err := parseQuery(path, cfg.Delimiter) + if err != nil { +--- ./github.com/openconfig/gnmi/client/query.go 2019-11-22 14:03:29.839103602 -0800 ++++ ./github.com/openconfig/gnmi/client/query.go 2019-10-11 13:48:49.226145599 -0700 +@@ -172,6 +172,10 @@ + // SubReq is an optional field. If not nil, gnmi client implementation uses + // it rather than generating from client.Query while sending gnmi Subscribe RPC. + SubReq *gpb.SubscribeRequest ++ Streaming_type gpb.SubscriptionMode ++ Streaming_sample_int uint64 ++ Heartbeat_int uint64 ++ Suppress_redundant bool + } + + // Destination extracts a Destination instance out of Query fields. +--- ./github.com/openconfig/gnmi/value/value.go 2019-11-22 14:03:29.847103498 -0800 ++++ ./github.com/openconfig/gnmi/value/value.go 2019-10-11 13:48:49.234145530 -0700 +@@ -117,6 +117,8 @@ + i = ss + case *pb.TypedValue_BytesVal: + i = tv.GetBytesVal() ++ case *pb.TypedValue_JsonIetfVal: ++ i = string(tv.GetJsonIetfVal()) + default: + return nil, fmt.Errorf("non-scalar type %+v", tv.Value) + } From 08f251fb964683099dfd834486f84d18d7e3bbf0 Mon Sep 17 00:00:00 2001 From: Eric Seifert Date: Wed, 26 Feb 2020 14:58:35 -0800 Subject: [PATCH 04/13] Change gnmi server package name back to gnmi --- gnmi_server/basicAuth.go | 2 +- gnmi_server/clientCertAuth.go | 2 +- gnmi_server/client_subscribe.go | 2 +- gnmi_server/gnoi.go | 2 +- gnmi_server/jwtAuth.go | 2 +- gnmi_server/pamAuth.go | 2 +- gnmi_server/server.go | 2 +- gnmi_server/server_test.go | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/gnmi_server/basicAuth.go b/gnmi_server/basicAuth.go index 177d6f667..4df195881 100644 --- a/gnmi_server/basicAuth.go +++ b/gnmi_server/basicAuth.go @@ -1,4 +1,4 @@ -package gnmi_server +package gnmi import ( "common_utils" diff --git a/gnmi_server/clientCertAuth.go b/gnmi_server/clientCertAuth.go index 175c507d9..b131b08cb 100644 --- a/gnmi_server/clientCertAuth.go +++ b/gnmi_server/clientCertAuth.go @@ -1,4 +1,4 @@ -package gnmi_server +package gnmi import ( "common_utils" diff --git a/gnmi_server/client_subscribe.go b/gnmi_server/client_subscribe.go index a47a4a16d..d4d0f6e30 100644 --- a/gnmi_server/client_subscribe.go +++ b/gnmi_server/client_subscribe.go @@ -1,4 +1,4 @@ -package gnmi_server +package gnmi import ( "fmt" diff --git a/gnmi_server/gnoi.go b/gnmi_server/gnoi.go index a3807b625..2edcab0c8 100644 --- a/gnmi_server/gnoi.go +++ b/gnmi_server/gnoi.go @@ -1,4 +1,4 @@ -package gnmi_server +package gnmi import ( "context" diff --git a/gnmi_server/jwtAuth.go b/gnmi_server/jwtAuth.go index f0fed4587..dd540a2d8 100644 --- a/gnmi_server/jwtAuth.go +++ b/gnmi_server/jwtAuth.go @@ -1,4 +1,4 @@ -package gnmi_server +package gnmi import ( "common_utils" diff --git a/gnmi_server/pamAuth.go b/gnmi_server/pamAuth.go index 1431a1cb7..c111cdc02 100644 --- a/gnmi_server/pamAuth.go +++ b/gnmi_server/pamAuth.go @@ -1,4 +1,4 @@ -package gnmi_server +package gnmi import ( "common_utils" diff --git a/gnmi_server/server.go b/gnmi_server/server.go index ba9b934ac..bfb8e6933 100644 --- a/gnmi_server/server.go +++ b/gnmi_server/server.go @@ -1,4 +1,4 @@ -package gnmi_server +package gnmi import ( "errors" diff --git a/gnmi_server/server_test.go b/gnmi_server/server_test.go index 28128fe91..a53910d30 100644 --- a/gnmi_server/server_test.go +++ b/gnmi_server/server_test.go @@ -1,4 +1,4 @@ -package gnmi_server +package gnmi // server_test covers gNMI get, subscribe (stream and poll) test // Prerequisite: redis-server should be running. From 833951d9eb6cfd7d146e507addf634392e2f3ed8 Mon Sep 17 00:00:00 2001 From: Eric Seifert Date: Wed, 26 Feb 2020 15:12:33 -0800 Subject: [PATCH 05/13] Fix imports and some code changes --- gnmi_server/basicAuth.go | 2 +- gnmi_server/clientCertAuth.go | 2 +- gnmi_server/client_subscribe.go | 5 ++--- gnmi_server/gnoi.go | 4 ++-- gnmi_server/jwtAuth.go | 4 ++-- gnmi_server/pamAuth.go | 2 +- gnmi_server/server.go | 18 +++++++++--------- gnmi_server/server_test.go | 10 +++++----- sonic_data_client/db_client.go | 13 +++---------- sonic_data_client/non_db_client.go | 2 +- sonic_data_client/transl_data_client.go | 6 +++--- telemetry/telemetry.go | 4 ++-- transl_utils/transl_utils.go | 4 ++-- 13 files changed, 34 insertions(+), 42 deletions(-) diff --git a/gnmi_server/basicAuth.go b/gnmi_server/basicAuth.go index 4df195881..97be2bc9c 100644 --- a/gnmi_server/basicAuth.go +++ b/gnmi_server/basicAuth.go @@ -1,7 +1,7 @@ package gnmi import ( - "common_utils" + "github.com/Azure/sonic-telemetry/common_utils" "github.com/golang/glog" "golang.org/x/net/context" "google.golang.org/grpc/codes" diff --git a/gnmi_server/clientCertAuth.go b/gnmi_server/clientCertAuth.go index b131b08cb..b25fb5cec 100644 --- a/gnmi_server/clientCertAuth.go +++ b/gnmi_server/clientCertAuth.go @@ -1,7 +1,7 @@ package gnmi import ( - "common_utils" + "github.com/Azure/sonic-telemetry/common_utils" "github.com/golang/glog" "golang.org/x/net/context" "google.golang.org/grpc/codes" diff --git a/gnmi_server/client_subscribe.go b/gnmi_server/client_subscribe.go index d4d0f6e30..db8427dac 100644 --- a/gnmi_server/client_subscribe.go +++ b/gnmi_server/client_subscribe.go @@ -11,8 +11,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" - //spb "github.com/project-arlo/sonic-telemetry/proto" - sdc "sonic_data_client" + sdc "github.com/Azure/sonic-telemetry/sonic_data_client" gnmipb "github.com/openconfig/gnmi/proto/gnmi" ) @@ -121,7 +120,7 @@ func (c *Client) Run(stream gnmipb.GNMI_SubscribeServer) (err error) { if target == "OTHERS" { dc, err = sdc.NewNonDbClient(paths, prefix) - } else if target == "APP_DB" || target == "CONFIG_DB" || target == "COUNTERS_DB" { + } else if isTargetDb(target) == true { dc, err = sdc.NewDbClient(paths, prefix) } else { /* For any other target or no target create new Transl Client. */ diff --git a/gnmi_server/gnoi.go b/gnmi_server/gnoi.go index 2edcab0c8..42b6892f4 100644 --- a/gnmi_server/gnoi.go +++ b/gnmi_server/gnoi.go @@ -5,8 +5,8 @@ import ( gnoi_system_pb "github.com/openconfig/gnoi/system" log "github.com/golang/glog" "time" - spb "proto/gnoi" - transutil "transl_utils" + spb "github.com/Azure/sonic-telemetry/proto/gnoi" + transutil "github.com/Azure/sonic-telemetry/transl_utils" "google.golang.org/grpc/status" "google.golang.org/grpc/codes" "encoding/json" diff --git a/gnmi_server/jwtAuth.go b/gnmi_server/jwtAuth.go index dd540a2d8..4a43d2083 100644 --- a/gnmi_server/jwtAuth.go +++ b/gnmi_server/jwtAuth.go @@ -1,7 +1,7 @@ package gnmi import ( - "common_utils" + "github.com/Azure/sonic-telemetry/common_utils" "crypto/rand" jwt "github.com/dgrijalva/jwt-go" "github.com/golang/glog" @@ -9,7 +9,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" - spb "proto/gnoi" + spb "github.com/Azure/sonic-telemetry/proto/gnoi" "time" ) diff --git a/gnmi_server/pamAuth.go b/gnmi_server/pamAuth.go index c111cdc02..3e31d6edc 100644 --- a/gnmi_server/pamAuth.go +++ b/gnmi_server/pamAuth.go @@ -1,7 +1,7 @@ package gnmi import ( - "common_utils" + "github.com/Azure/sonic-telemetry/common_utils" "errors" "github.com/golang/glog" "github.com/msteinert/pam" diff --git a/gnmi_server/server.go b/gnmi_server/server.go index bfb8e6933..9af255582 100644 --- a/gnmi_server/server.go +++ b/gnmi_server/server.go @@ -16,9 +16,9 @@ import ( "google.golang.org/grpc/status" // "github.com/msteinert/pam" gnoi_system_pb "github.com/openconfig/gnoi/system" - sdc "sonic_data_client" + sdc "github.com/Azure/sonic-telemetry/sonic_data_client" gnmipb "github.com/openconfig/gnmi/proto/gnmi" - spb "proto/gnoi" + spb "github.com/Azure/sonic-telemetry/proto/gnoi" "bytes" ) @@ -257,8 +257,8 @@ func (s *Server) checkEncodingAndModel(encoding gnmipb.Encoding, models []*gnmip } // Get implements the Get RPC in gNMI spec. -func (srv *Server) Get(ctx context.Context, req *gnmipb.GetRequest) (*gnmipb.GetResponse, error) { - ctx, err := authenticate(srv.config.UserAuth, ctx) +func (s *Server) Get(ctx context.Context, req *gnmipb.GetRequest) (*gnmipb.GetResponse, error) { + ctx, err := authenticate(s.config.UserAuth, ctx) if err != nil { return nil, err } @@ -267,7 +267,7 @@ func (srv *Server) Get(ctx context.Context, req *gnmipb.GetRequest) (*gnmipb.Get return nil, status.Errorf(codes.Unimplemented, "unsupported request type: %s", gnmipb.GetRequest_DataType_name[int32(req.GetType())]) } - if err = srv.checkEncodingAndModel(req.GetEncoding(), req.GetUseModels()); err != nil { + if err = s.checkEncodingAndModel(req.GetEncoding(), req.GetUseModels()); err != nil { return nil, status.Error(codes.Unimplemented, err.Error()) } @@ -314,8 +314,8 @@ func (srv *Server) Get(ctx context.Context, req *gnmipb.GetRequest) (*gnmipb.Get } // Set method is not implemented. Refer to gnxi for examples with openconfig integration -func (srv *Server) Set(ctx context.Context,req *gnmipb.SetRequest) (*gnmipb.SetResponse, error) { - ctx, err := authenticate(srv.config.UserAuth, ctx) +func (s *Server) Set(ctx context.Context,req *gnmipb.SetRequest) (*gnmipb.SetResponse, error) { + ctx, err := authenticate(s.config.UserAuth, ctx) if err != nil { return nil, err } @@ -394,8 +394,8 @@ func (srv *Server) Set(ctx context.Context,req *gnmipb.SetRequest) (*gnmipb.SetR } // Capabilities method is not implemented. Refer to gnxi for examples with openconfig integration -func (srv *Server) Capabilities(ctx context.Context, req *gnmipb.CapabilityRequest) (*gnmipb.CapabilityResponse, error) { - ctx, err := authenticate(srv.config.UserAuth, ctx) +func (s *Server) Capabilities(ctx context.Context, req *gnmipb.CapabilityRequest) (*gnmipb.CapabilityResponse, error) { + ctx, err := authenticate(s.config.UserAuth, ctx) if err != nil { return nil, err } diff --git a/gnmi_server/server_test.go b/gnmi_server/server_test.go index a53910d30..fcf7fa542 100644 --- a/gnmi_server/server_test.go +++ b/gnmi_server/server_test.go @@ -6,7 +6,7 @@ package gnmi import ( "crypto/tls" "encoding/json" - testcert "testdata/tls" + testcert "github.com/Azure/sonic-telemetry/testdata/tls" "github.com/go-redis/redis" "github.com/golang/protobuf/proto" "path/filepath" @@ -22,15 +22,15 @@ import ( "io/ioutil" "os" "os/exec" - // "reflect" "testing" "time" "fmt" "github.com/xeipuuv/gojsonschema" // Register supported client types. - spb "proto" - sgpb "proto/gnoi" - sdc "sonic_data_client" + spb "github.com/Azure/sonic-telemetry/proto" + sgpb "github.com/Azure/sonic-telemetry/proto/gnoi" + sdc "github.com/Azure/sonic-telemetry/sonic_data_client" + sdcfg "github.com/Azure/sonic-telemetry/sonic_db_config" gclient "github.com/jipanyang/gnmi/client/gnmi" "github.com/jipanyang/gnxi/utils/xpath" gnoi_system_pb "github.com/openconfig/gnoi/system" diff --git a/sonic_data_client/db_client.go b/sonic_data_client/db_client.go index 2847fda0a..2ec78a855 100644 --- a/sonic_data_client/db_client.go +++ b/sonic_data_client/db_client.go @@ -14,7 +14,8 @@ import ( log "github.com/golang/glog" - spb "proto" + spb "github.com/Azure/sonic-telemetry/proto" + sdcfg "github.com/Azure/sonic-telemetry/sonic_db_config" "github.com/go-redis/redis" gnmipb "github.com/openconfig/gnmi/proto/gnmi" "github.com/Workiva/go-datastructures/queue" @@ -313,15 +314,7 @@ func GetTableKeySeparator(target string) (string, error) { return "", fmt.Errorf("%v not a valid path target", target) } - var separator string - switch target { - case "CONFIG_DB": - separator = "|" - case "STATE_DB": - separator = "|" - default: - separator = ":" - } + var separator string = sdcfg.GetDbSeparator(target) return separator, nil } diff --git a/sonic_data_client/non_db_client.go b/sonic_data_client/non_db_client.go index 061d6dc71..85bcd206a 100644 --- a/sonic_data_client/non_db_client.go +++ b/sonic_data_client/non_db_client.go @@ -3,7 +3,7 @@ package client import ( "encoding/json" "fmt" - spb "proto" + spb "github.com/Azure/sonic-telemetry/proto" linuxproc "github.com/c9s/goprocinfo/linux" log "github.com/golang/glog" gnmipb "github.com/openconfig/gnmi/proto/gnmi" diff --git a/sonic_data_client/transl_data_client.go b/sonic_data_client/transl_data_client.go index 64a15f1bd..5d48403b4 100644 --- a/sonic_data_client/transl_data_client.go +++ b/sonic_data_client/transl_data_client.go @@ -2,8 +2,8 @@ package client import ( - spb "proto" - transutil "transl_utils" + spb "github.com/Azure/sonic-telemetry/proto" + transutil "github.com/Azure/sonic-telemetry/transl_utils" log "github.com/golang/glog" gnmipb "github.com/openconfig/gnmi/proto/gnmi" "github.com/Workiva/go-datastructures/queue" @@ -11,7 +11,7 @@ import ( "time" "fmt" "reflect" - "translib" + "github.com/Azure/sonic-telemetry/translib" "bytes" "encoding/json" "context" diff --git a/telemetry/telemetry.go b/telemetry/telemetry.go index 306c56871..2e1b6f111 100644 --- a/telemetry/telemetry.go +++ b/telemetry/telemetry.go @@ -10,8 +10,8 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials" - gnmi "gnmi_server" - testcert "testdata/tls" + gnmi "github.com/Azure/sonic-telemetry/gnmi_server" + testcert "github.com/Azure/sonic-telemetry/testdata/tls" ) var ( diff --git a/transl_utils/transl_utils.go b/transl_utils/transl_utils.go index dad967796..dc3626984 100644 --- a/transl_utils/transl_utils.go +++ b/transl_utils/transl_utils.go @@ -7,8 +7,8 @@ import ( "fmt" log "github.com/golang/glog" gnmipb "github.com/openconfig/gnmi/proto/gnmi" - "translib" - "common_utils" + "github.com/Azure/sonic-telemetry/translib" + "github.com/Azure/sonic-telemetry/common_utils" "context" ) From b3d86f9e7d9097bbada7efd7206c5401b187f6ee Mon Sep 17 00:00:00 2001 From: Eric Seifert Date: Wed, 26 Feb 2020 15:20:23 -0800 Subject: [PATCH 06/13] More import and code fixes --- gnmi_server/server.go | 16 +++++++++++----- transl_utils/transl_utils.go | 2 -- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/gnmi_server/server.go b/gnmi_server/server.go index 9af255582..650e8bd3b 100644 --- a/gnmi_server/server.go +++ b/gnmi_server/server.go @@ -6,7 +6,7 @@ import ( "net" "strings" "sync" - "common_utils" + "github.com/Azure/sonic-telemetry/common_utils" log "github.com/golang/glog" "golang.org/x/net/context" "google.golang.org/grpc" @@ -14,7 +14,6 @@ import ( "google.golang.org/grpc/peer" "google.golang.org/grpc/reflection" "google.golang.org/grpc/status" - // "github.com/msteinert/pam" gnoi_system_pb "github.com/openconfig/gnoi/system" sdc "github.com/Azure/sonic-telemetry/sonic_data_client" gnmipb "github.com/openconfig/gnmi/proto/gnmi" @@ -115,7 +114,6 @@ func NewServer(config *Config, opts []grpc.ServerOption) (*Server, error) { } s := grpc.NewServer(opts...) - reflection.Register(s) srv := &Server{ @@ -135,7 +133,6 @@ func NewServer(config *Config, opts []grpc.ServerOption) (*Server, error) { gnoi_system_pb.RegisterSystemServer(srv.s, srv) spb.RegisterSonicServiceServer(srv.s, srv) log.V(1).Infof("Created Server on %s", srv.Address()) - return srv, nil } @@ -273,8 +270,17 @@ func (s *Server) Get(ctx context.Context, req *gnmipb.GetRequest) (*gnmipb.GetRe var target string prefix := req.GetPrefix() + if prefix == nil { + return nil, status.Error(codes.Unimplemented, "No target specified in prefix") + } else { + target = prefix.GetTarget() + if target == "" { + return nil, status.Error(codes.Unimplemented, "Empty target data not supported yet") + } + } + paths := req.GetPath() - target = prefix.GetTarget() + target = prefix.GetTarget() log.V(5).Infof("GetRequest paths: %v", paths) var dc sdc.Client diff --git a/transl_utils/transl_utils.go b/transl_utils/transl_utils.go index dc3626984..0e40bd651 100644 --- a/transl_utils/transl_utils.go +++ b/transl_utils/transl_utils.go @@ -221,5 +221,3 @@ func isTranslibSuccess(err error) bool { return true } - - From 510d74c943b3b8f658c76e4d43a9eef8f09bea1f Mon Sep 17 00:00:00 2001 From: Eric Seifert Date: Thu, 27 Feb 2020 14:15:54 -0800 Subject: [PATCH 07/13] More fixes, now build is working, just need to fix/merge tests --- Makefile | 12 +- gnmi_server/server_test.go | 2 +- go.mod | 36 +- go.sum | 66 + sonic_db_config/db_config.go | 135 + testdata/database_config.json | 57 + testdata/db_dump.json | 7163 +++++++++++++++++++++++++++++++++ testdata/get_interface.json | 1 + 8 files changed, 7462 insertions(+), 10 deletions(-) create mode 100644 sonic_db_config/db_config.go create mode 100644 testdata/database_config.json create mode 100644 testdata/db_dump.json create mode 100644 testdata/get_interface.json diff --git a/Makefile b/Makefile index f0a64b0e7..b6562622e 100644 --- a/Makefile +++ b/Makefile @@ -39,8 +39,10 @@ mgmt-deps: $(GO) get github.com/openconfig/goyang@064f9690516f4f72db189f4690b84622c13b7296 $(GO) get golang.org/x/crypto/ssh/terminal@e9b2fee46413 $(GO) get github.com/jipanyang/gnxi@f0a90cca6fd0041625bcce561b71f849c9b65a8d - $(GO) install github.com/openconfig/ygot/generator - $(GO) get -x github.com/golang/glog@23def4e6c14b4da8ac2ed8007337bc5eb5007998 + $(GO) get github.com/godbus/dbus + $(GO) get github.com/golang/glog@23def4e6c14b4da8ac2ed8007337bc5eb5007998 + $(GO) get github.com/antchfx/xpath@d9ad276609987dd73ce5cd7d6265fe82189b10b6 + $(GO) get github.com/antchfx/xmlquery@fe009d4cc63c3011f05e1dfa75a27899acccdf11 rm -rf vendor $(GO) mod vendor ln -s vendor src @@ -48,11 +50,17 @@ mgmt-deps: cp -r $(GOPATH)/pkg/mod/github.com/openconfig/goyang@v0.0.0-20190924211109-064f9690516f/* vendor/github.com/openconfig/goyang/ cp -r $(GOPATH)/pkg/mod/github.com/openconfig/ygot@v0.6.1-0.20190723223108-724a6b18a922/* vendor/github.com/openconfig/ygot/ cp -r $(GOPATH)/pkg/mod/golang.org/x/crypto@v0.0.0-20191206172530-e9b2fee46413 vendor/golang.org/x/crypto + cp -r $(GOPATH)/pkg/mod/github.com/antchfx/xpath@v1.1.2/* vendor/github.com/antchfx/xpath/ + cp -r $(GOPATH)/pkg/mod/github.com/antchfx/xmlquery@v1.1.1-0.20191015122529-fe009d4cc63c/* vendor/github.com/antchfx/xmlquery/ chmod -R u+w vendor patch -d vendor -p0 Date: Thu, 5 Mar 2020 11:33:48 -0800 Subject: [PATCH 08/13] Add patches for gnmi_get and set, fix build --- Makefile | 11 +- gnoi_client/gnoi_client.go | 274 +++++++++++++++++++++++++++++++++++++ go.mod | 23 ++-- go.sum | 1 + patches/gnmi_get.patch | 36 +++++ patches/gnmi_set.patch | 86 ++++++++++++ 6 files changed, 414 insertions(+), 17 deletions(-) create mode 100644 gnoi_client/gnoi_client.go create mode 100644 patches/gnmi_get.patch create mode 100644 patches/gnmi_set.patch diff --git a/Makefile b/Makefile index b6562622e..3e52ea886 100644 --- a/Makefile +++ b/Makefile @@ -49,11 +49,14 @@ mgmt-deps: cp -r $(GOPATH)/pkg/mod/github.com/openconfig/gnmi@v0.0.0-20190823184014-89b2bf29312c/* vendor/github.com/openconfig/gnmi/ cp -r $(GOPATH)/pkg/mod/github.com/openconfig/goyang@v0.0.0-20190924211109-064f9690516f/* vendor/github.com/openconfig/goyang/ cp -r $(GOPATH)/pkg/mod/github.com/openconfig/ygot@v0.6.1-0.20190723223108-724a6b18a922/* vendor/github.com/openconfig/ygot/ - cp -r $(GOPATH)/pkg/mod/golang.org/x/crypto@v0.0.0-20191206172530-e9b2fee46413 vendor/golang.org/x/crypto + cp -r $(GOPATH)/pkg/mod/golang.org/x/crypto@v0.0.0-20191206172530-e9b2fee46413/* vendor/golang.org/x/crypto/ cp -r $(GOPATH)/pkg/mod/github.com/antchfx/xpath@v1.1.2/* vendor/github.com/antchfx/xpath/ cp -r $(GOPATH)/pkg/mod/github.com/antchfx/xmlquery@v1.1.1-0.20191015122529-fe009d4cc63c/* vendor/github.com/antchfx/xmlquery/ + cp -r $(GOPATH)/pkg/mod/github.com/jipanyang/gnxi@v0.0.0-20181221084354-f0a90cca6fd0/* vendor/github.com/jipanyang/gnxi/ chmod -R u+w vendor patch -d vendor -p0 0 { + ctx = metadata.AppendToOutgoingContext(ctx, "access_token", *jwtToken) + } + return ctx +} +func main() { + flag.Parse() + opts := credentials.ClientCredentials(*targetName) + + ctx, cancel := context.WithCancel(context.Background()) + go func() { + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt) + <-c + cancel() + }() + conn, err := grpc.Dial(*target, opts...) + if err != nil { + panic(err.Error()) + } + + switch *module { + case "System": + sc := gnoi_system_pb.NewSystemClient(conn) + switch *rpc { + case "Time": + systemTime(sc, ctx) + default: + panic("Invalid RPC Name") + } + case "Sonic": + sc := spb.NewSonicServiceClient(conn) + switch *rpc { + case "showtechsupport": + sonicShowTechSupport(sc, ctx) + case "sum": + sonicSum(sc, ctx) + case "copyConfig": + copyConfig(sc, ctx) + case "authenticate": + authenticate(sc, ctx) + case "imageInstall": + imageInstall(sc, ctx) + case "imageDefault": + imageDefault(sc, ctx) + case "imageRemove": + imageRemove(sc, ctx) + case "refresh": + refresh(sc, ctx) + case "clearNeighbors": + clearNeighbors(sc, ctx) + default: + panic("Invalid RPC Name") + } + default: + panic("Invalid Module Name") + } + +} + +func systemTime(sc gnoi_system_pb.SystemClient, ctx context.Context) { + fmt.Println("System Time") + ctx = setUserCreds(ctx) + resp,err := sc.Time(ctx, new(gnoi_system_pb.TimeRequest)) + if err != nil { + panic(err.Error()) + } + respstr, err := json.Marshal(resp) + if err != nil { + panic(err.Error()) + } + fmt.Println(string(respstr)) +} +func sonicShowTechSupport(sc spb.SonicServiceClient, ctx context.Context) { + fmt.Println("Sonic ShowTechsupport") + ctx = setUserCreds(ctx) + req := &spb.TechsupportRequest { + Input: &spb.TechsupportRequest_Input{ + + }, + } + + json.Unmarshal([]byte(*args), req) + + resp,err := sc.ShowTechsupport(ctx, req) + if err != nil { + panic(err.Error()) + } + respstr, err := json.Marshal(resp) + if err != nil { + panic(err.Error()) + } + fmt.Println(string(respstr)) +} +func sonicSum(sc spb.SonicServiceClient, ctx context.Context) { + fmt.Println("Sonic Sum") + ctx = setUserCreds(ctx) + req := &spb.SumRequest{ + Input: &spb.SumRequest_Input{}, + } + + json.Unmarshal([]byte(*args), req) + + resp,err := sc.Sum(ctx, req) + + if err != nil { + panic(err.Error()) + } + respstr, err := json.Marshal(resp) + if err != nil { + panic(err.Error()) + } + fmt.Println(string(respstr)) +} + +func copyConfig(sc spb.SonicServiceClient, ctx context.Context) { + fmt.Println("Sonic CopyConfig") + ctx = setUserCreds(ctx) + req := &spb.CopyConfigRequest{ + Input: &spb.CopyConfigRequest_Input{}, + } + json.Unmarshal([]byte(*args), req) + + resp,err := sc.CopyConfig(ctx, req) + + if err != nil { + panic(err.Error()) + } + respstr, err := json.Marshal(resp) + if err != nil { + panic(err.Error()) + } + fmt.Println(string(respstr)) +} + +func imageInstall(sc spb.SonicServiceClient, ctx context.Context) { + fmt.Println("Sonic ImageInstall") + ctx = setUserCreds(ctx) + req := &spb.ImageInstallRequest{ + Input: &spb.ImageInstallRequest_Input{}, + } + json.Unmarshal([]byte(*args), req) + + resp,err := sc.ImageInstall(ctx, req) + + if err != nil { + panic(err.Error()) + } + respstr, err := json.Marshal(resp) + if err != nil { + panic(err.Error()) + } + fmt.Println(string(respstr)) +} +func imageRemove(sc spb.SonicServiceClient, ctx context.Context) { + fmt.Println("Sonic ImageRemove") + ctx = setUserCreds(ctx) + req := &spb.ImageRemoveRequest{ + Input: &spb.ImageRemoveRequest_Input{}, + } + json.Unmarshal([]byte(*args), req) + + resp,err := sc.ImageRemove(ctx, req) + + if err != nil { + panic(err.Error()) + } + respstr, err := json.Marshal(resp) + if err != nil { + panic(err.Error()) + } + fmt.Println(string(respstr)) +} + +func imageDefault(sc spb.SonicServiceClient, ctx context.Context) { + fmt.Println("Sonic ImageDefault") + ctx = setUserCreds(ctx) + req := &spb.ImageDefaultRequest{ + Input: &spb.ImageDefaultRequest_Input{}, + } + json.Unmarshal([]byte(*args), req) + + resp,err := sc.ImageDefault(ctx, req) + + if err != nil { + panic(err.Error()) + } + respstr, err := json.Marshal(resp) + if err != nil { + panic(err.Error()) + } + fmt.Println(string(respstr)) +} + +func authenticate(sc spb.SonicServiceClient, ctx context.Context) { + fmt.Println("Sonic Authenticate") + ctx = setUserCreds(ctx) + req := &spb.AuthenticateRequest {} + + json.Unmarshal([]byte(*args), req) + + resp,err := sc.Authenticate(ctx, req) + if err != nil { + panic(err.Error()) + } + respstr, err := json.Marshal(resp) + if err != nil { + panic(err.Error()) + } + fmt.Println(string(respstr)) +} + +func refresh(sc spb.SonicServiceClient, ctx context.Context) { + fmt.Println("Sonic Refresh") + ctx = setUserCreds(ctx) + req := &spb.RefreshRequest {} + + json.Unmarshal([]byte(*args), req) + + resp,err := sc.Refresh(ctx, req) + if err != nil { + panic(err.Error()) + } + respstr, err := json.Marshal(resp) + if err != nil { + panic(err.Error()) + } + fmt.Println(string(respstr)) +} + +func clearNeighbors(sc spb.SonicServiceClient, ctx context.Context) { + fmt.Println("Sonic ClearNeighbors") + ctx = setUserCreds(ctx) + req := &spb.ClearNeighborsRequest{ + Input: &spb.ClearNeighborsRequest_Input{}, + } + json.Unmarshal([]byte(*args), req) + + resp,err := sc.ClearNeighbors(ctx, req) + + if err != nil { + panic(err.Error()) + } + respstr, err := json.Marshal(resp) + if err != nil { + panic(err.Error()) + } + fmt.Println(string(respstr)) +} diff --git a/go.mod b/go.mod index 245d7aa12..0772a49aa 100644 --- a/go.mod +++ b/go.mod @@ -7,12 +7,11 @@ require ( github.com/antchfx/jsonquery v1.1.0 github.com/antchfx/xmlquery v1.1.1-0.20191015122529-fe009d4cc63c github.com/antchfx/xpath v1.1.2 - github.com/bgentry/speakeasy v0.1.0 + github.com/bgentry/speakeasy v0.1.0 // indirect github.com/c9s/goprocinfo v0.0.0-20191125144613-4acdd056c72d github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb - github.com/go-playground/locales v0.13.0 - github.com/go-playground/universal-translator v0.17.0 + github.com/go-playground/universal-translator v0.17.0 // indirect github.com/go-redis/redis v6.15.6+incompatible github.com/godbus/dbus v4.1.0+incompatible github.com/gogo/protobuf v1.3.1 @@ -20,11 +19,10 @@ require ( github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 // indirect github.com/golang/protobuf v1.3.2 github.com/google/gnxi v0.0.0-20191016182648-6697a080bc2d - github.com/google/go-cmp v0.2.0 github.com/jipanyang/gnmi v0.0.0-20180820232453-cb4d464fa018 github.com/jipanyang/gnxi v0.0.0-20181221084354-f0a90cca6fd0 github.com/kylelemons/godebug v1.1.0 - github.com/leodido/go-urn v1.2.0 + github.com/leodido/go-urn v1.2.0 // indirect github.com/msteinert/pam v0.0.0-20190215180659-f29b9f28d6f9 github.com/onsi/ginkgo v1.10.3 // indirect github.com/onsi/gomega v1.7.1 // indirect @@ -32,25 +30,22 @@ require ( github.com/openconfig/gnoi v0.0.0-20191206155121-b4d663a26026 github.com/openconfig/goyang v0.0.0-20190924211109-064f9690516f github.com/openconfig/ygot v0.6.1-0.20190723223108-724a6b18a922 - github.com/pborman/getopt v0.0.0-20190409184431-ee0cd42419d3 + github.com/pborman/getopt v0.0.0-20190409184431-ee0cd42419d3 // indirect github.com/philhofer/fwd v1.0.0 // indirect github.com/philopon/go-toposort v0.0.0-20170620085441-9be86dbd762f github.com/pkg/profile v1.4.0 - github.com/pmezard/go-difflib v1.0.0 - github.com/stretchr/testify v1.4.0 - github.com/tinylib/msgp v1.1.1 - github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb + github.com/tinylib/msgp v1.1.1 // indirect + github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect github.com/xeipuuv/gojsonschema v1.2.0 golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 golang.org/x/text v0.3.2 golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 // indirect - gonum.org/v1/plot v0.0.0-20200226011204-b25252b0d522 - google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 + gonum.org/v1/plot v0.0.0-20200226011204-b25252b0d522 // indirect google.golang.org/grpc v1.25.1 - gopkg.in/go-playground/assert.v1 v1.2.1 - gopkg.in/go-playground/validator.v9 v9.31.0 + gopkg.in/go-playground/assert.v1 v1.2.1 // indirect + gopkg.in/go-playground/validator.v9 v9.31.0 // indirect honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc // indirect ) diff --git a/go.sum b/go.sum index 4c613dc66..0f3e2ed20 100644 --- a/go.sum +++ b/go.sum @@ -77,6 +77,7 @@ github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/openconfig/gnmi v0.0.0-20190823184014-89b2bf29312c h1:a380JP+B7xlMbEQOlha1buKhzBPXFqgFXplyWCEIGEY= github.com/openconfig/gnmi v0.0.0-20190823184014-89b2bf29312c/go.mod h1:t+O9It+LKzfOAhKTT5O0ehDix+MTqbtT0T9t+7zzOvc= +github.com/openconfig/gnmi v0.0.0-20200305011855-a29e253c3557 h1:qxGfaZg8rm7grrsYUEIM1DoAi9lHPOR8zlU6UvzisMM= github.com/openconfig/gnoi v0.0.0-20191206155121-b4d663a26026 h1:LqWmMvsOBxqjWmW+EWSS3kxEGE3mh771zAx69549IoI= github.com/openconfig/gnoi v0.0.0-20191206155121-b4d663a26026/go.mod h1:i43VWfb9tMz9b6MzLxTztJeBP4U0AAqscMSX7o507jk= github.com/openconfig/goyang v0.0.0-20190924211109-064f9690516f h1:BaekRUaWpfaRBP3mShDZaNi4+EHbdli7D6YXc/TP3lo= diff --git a/patches/gnmi_get.patch b/patches/gnmi_get.patch new file mode 100644 index 000000000..5d27653fc --- /dev/null +++ b/patches/gnmi_get.patch @@ -0,0 +1,36 @@ +--- ./github.com/jipanyang/gnxi/gnmi_get/gnmi_get.go 2019-11-26 15:44:07.303598063 -0800 ++++ ./github.com/jipanyang/gnxi/gnmi_get/gnmi_get.go 2019-12-19 19:56:11.364223008 -0800 +@@ -30,7 +30,7 @@ + "github.com/google/gnxi/utils" + "github.com/google/gnxi/utils/credentials" + "github.com/jipanyang/gnxi/utils/xpath" +- ++ "google.golang.org/grpc/metadata" + pb "github.com/openconfig/gnmi/proto/gnmi" + ) + +@@ -63,11 +63,12 @@ + xPathFlags arrayFlags + pbPathFlags arrayFlags + pbModelDataFlags arrayFlags +- pathTarget = flag.String("xpath_target", "CONFIG_DB", "name of the target for which the path is a member") ++ pathTarget = flag.String("xpath_target", "", "name of the target for which the path is a member") + targetAddr = flag.String("target_addr", "localhost:10161", "The target address in the format of host:port") + targetName = flag.String("target_name", "hostname.com", "The target name use to verify the hostname returned by TLS handshake") + timeOut = flag.Duration("time_out", 10*time.Second, "Timeout for the Get request, 10 seconds by default") + encodingName = flag.String("encoding", "JSON_IETF", "value encoding format to be used") ++ jwtToken = flag.String("jwt_token", "", "JWT Token if required") + ) + + func main() { +@@ -88,6 +89,10 @@ + ctx, cancel := context.WithTimeout(context.Background(), *timeOut) + defer cancel() + ++ if len(*jwtToken) > 0 { ++ ctx = metadata.AppendToOutgoingContext(ctx, "access_token", *jwtToken) ++ } ++ + encoding, ok := pb.Encoding_value[*encodingName] + if !ok { + var gnmiEncodingList []string diff --git a/patches/gnmi_set.patch b/patches/gnmi_set.patch new file mode 100644 index 000000000..48b3c31f6 --- /dev/null +++ b/patches/gnmi_set.patch @@ -0,0 +1,86 @@ +--- ./github.com/jipanyang/gnxi/gnmi_set/gnmi_set.go 2019-11-26 15:44:07.303598063 -0800 ++++ ./github.com/jipanyang/gnxi/gnmi_set/gnmi_set.go 2020-02-12 10:13:46.247988021 -0800 +@@ -31,8 +31,9 @@ + + "github.com/google/gnxi/utils" + "github.com/google/gnxi/utils/credentials" +- "github.com/google/gnxi/utils/xpath" +- ++ //"github.com/google/gnxi/utils/xpath" ++ "github.com/jipanyang/gnxi/utils/xpath" ++ "google.golang.org/grpc/metadata" + pb "github.com/openconfig/gnmi/proto/gnmi" + ) + +@@ -54,16 +55,37 @@ + targetAddr = flag.String("target_addr", "localhost:10161", "The target address in the format of host:port") + targetName = flag.String("target_name", "hostname.com", "The target name use to verify the hostname returned by TLS handshake") + timeOut = flag.Duration("time_out", 10*time.Second, "Timeout for the Get request, 10 seconds by default") ++ pathTarget = flag.String("xpath_target", "", "name of the target for which the path is a member") ++ jwtToken = flag.String("jwt_token", "", "JWT Token if required") + ) + + func buildPbUpdateList(pathValuePairs []string) []*pb.Update { + var pbUpdateList []*pb.Update + for _, item := range pathValuePairs { +- pathValuePair := strings.SplitN(item, ":", 2) +- // TODO (leguo): check if any path attribute contains ':' ++ modName := strings.SplitN(item, "/", 3) ++ ++ pathValuePair := make([]string, 2) ++ lc := strings.LastIndex(modName[2],":") ++ ++ if lc == -1 { ++ log.Exitf("invalid path-value pair: %v", item) ++ } ++ pathValuePair_r := strings.SplitN(modName[2], ":", 2) ++ // pathValuePair[0] = modName[2][0:lc] ++ ++ pathValuePair[0] = "/" + modName[1] + "/" + pathValuePair_r[0] ++ ++ pathValuePair[1] = modName[2][lc+1:] ++ fmt.Println(pathValuePair[0]) ++ fmt.Println(pathValuePair[1]) ++ ++ + if len(pathValuePair) != 2 || len(pathValuePair[1]) == 0 { + log.Exitf("invalid path-value pair: %v", item) ++ log.Exitf("invalid path-value pair: %v", modName) + } ++ ++ + pbPath, err := xpath.ToGNMIPath(pathValuePair[0]) + if err != nil { + log.Exitf("error in parsing xpath %q to gnmi path", pathValuePair[0]) +@@ -144,8 +166,10 @@ + } + replaceList := buildPbUpdateList(replaceOpt) + updateList := buildPbUpdateList(updateOpt) +- ++ var prefix pb.Path ++ prefix.Target = *pathTarget + setRequest := &pb.SetRequest{ ++ Prefix: &prefix, + Delete: deleteList, + Replace: replaceList, + Update: updateList, +@@ -155,11 +179,17 @@ + utils.PrintProto(setRequest) + + cli := pb.NewGNMIClient(conn) +- setResponse, err := cli.Set(context.Background(), setRequest) ++ ctx, cancel := context.WithTimeout(context.Background(), *timeOut) ++ defer cancel() ++ ++ if len(*jwtToken) > 0 { ++ ctx = metadata.AppendToOutgoingContext(ctx, "access_token", *jwtToken) ++ } ++ setResponse, err := cli.Set(ctx, setRequest) + if err != nil { + log.Exitf("Set failed: %v", err) + } + +- fmt.Println("== getResponse:") ++ fmt.Println("== setResponse:") + utils.PrintProto(setResponse) + } From ee175a56dfd98c03d447acea25e4bde6c2e93cc3 Mon Sep 17 00:00:00 2001 From: Eric Seifert Date: Fri, 20 Mar 2020 09:42:00 -0700 Subject: [PATCH 09/13] Fix for ygot dependency --- Makefile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 56f5094d1..733d15d62 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ deps: $(BUILD_DIR)/.deps $(BUILD_DIR)/.deps: $(MAKEFILE_LIST) GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/Workiva/go-datastructures/queue GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/goyang - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/ygot/ygot + GOPATH=$(GO_DEP_PATH) $(GO) get -d github.com/openconfig/ygot/ygot GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/golang/glog GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/go-redis/redis GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/c9s/goprocinfo/linux @@ -42,19 +42,21 @@ $(BUILD_DIR)/.deps: $(MAKEFILE_LIST) GOPATH=$(GO_DEP_PATH) $(GO) get -u golang.org/x/net/context GOPATH=$(GO_DEP_PATH) $(GO) get -u google.golang.org/grpc GOPATH=$(GO_DEP_PATH) $(GO) get -u google.golang.org/grpc/credentials - GOPATH=$(GO_DEP_PATH) $(GO) get -u gopkg.in/go-playground/validator.v9 - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/gorilla/mux - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/goyang - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/ygot/ygot GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/google/gnxi/utils GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/jipanyang/gnxi/utils/xpath - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/jipanyang/gnmi/client/gnmi + GOPATH=$(GO_DEP_PATH) $(GO) get -d github.com/jipanyang/gnmi/client/gnmi GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/xeipuuv/gojsonschema GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/gnoi/system GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/msteinert/pam GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/dgrijalva/jwt-go GOPATH=$(GO_DEP_PATH) $(GO) get -u gopkg.in/godbus/dbus.v5 GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/gogo/protobuf/gogoproto + + cd $(GO_DEP_PATH)/src/github.com/openconfig/ygot/; git reset --hard HEAD;git clean -f -d;git checkout 724a6b18a9224343ef04fe49199dfb6020ce132a 2>/dev/null ; true; \ +GOPATH=$(GO_DEP_PATH) $(GO) install -v -gcflags "-N -l" $(GO_DEP_PATH)/src/github.com/openconfig/ygot/ygot + cd $(GO_DEP_PATH)/src/github.com/jipanyang/gnmi/client/gnmi; git reset --hard HEAD;git clean -f -d;git checkout cb4d464fa018c29eadab98281448000bee4dcc3d 2>/dev/null ; true; \ +GOPATH=$(GO_DEP_PATH) $(GO) install -v -gcflags "-N -l" $(GO_DEP_PATH)/src/github.com/jipanyang/gnmi/client/gnmi + touch $@ telemetry:$(BUILD_DIR)/telemetry $(BUILD_DIR)/dialout_client_cli $(BUILD_DIR)/gnmi_get $(BUILD_DIR)/gnmi_set $(BUILD_DIR)/gnmi_cli $(BUILD_DIR)/gnoi_client From 81ba4df563684853dc82eee1de9b35531a6542f7 Mon Sep 17 00:00:00 2001 From: Nirenjan Krishnan Date: Fri, 27 Mar 2020 22:24:41 -0700 Subject: [PATCH 10/13] Use a known good version of openconfig/gnmi This change checks out a known good version of openconfig/gnmi in order to avoid the issue where the embedded generated code requires ProtoPackageIsVersion4 symbol in the protobuf/proto library. --- Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 733d15d62..9534b6035 100644 --- a/Makefile +++ b/Makefile @@ -38,12 +38,12 @@ $(BUILD_DIR)/.deps: $(MAKEFILE_LIST) GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/go-redis/redis GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/c9s/goprocinfo/linux GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/golang/protobuf/proto - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/gnmi/proto/gnmi + GOPATH=$(GO_DEP_PATH) $(GO) get -d github.com/openconfig/gnmi/proto/gnmi GOPATH=$(GO_DEP_PATH) $(GO) get -u golang.org/x/net/context GOPATH=$(GO_DEP_PATH) $(GO) get -u google.golang.org/grpc GOPATH=$(GO_DEP_PATH) $(GO) get -u google.golang.org/grpc/credentials GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/google/gnxi/utils - GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/jipanyang/gnxi/utils/xpath + GOPATH=$(GO_DEP_PATH) $(GO) get -d github.com/jipanyang/gnxi/utils/xpath GOPATH=$(GO_DEP_PATH) $(GO) get -d github.com/jipanyang/gnmi/client/gnmi GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/xeipuuv/gojsonschema GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/gnoi/system @@ -52,8 +52,11 @@ $(BUILD_DIR)/.deps: $(MAKEFILE_LIST) GOPATH=$(GO_DEP_PATH) $(GO) get -u gopkg.in/godbus/dbus.v5 GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/gogo/protobuf/gogoproto + cd $(GO_DEP_PATH)/src/github.com/openconfig/gnmi/proto/gnmi/; git reset --hard HEAD;git clean -f -d;git checkout e7106f7f5493a9fa152d28ab314f2cc734244ed8 2>/dev/null; true; \ + GOPATH=$(GO_DEP_PATH) $(GO) install -v -gcflags "-N -l" $(GO_DEP_PATH)/src/github.com/openconfig/gnmi/proto/gnmi cd $(GO_DEP_PATH)/src/github.com/openconfig/ygot/; git reset --hard HEAD;git clean -f -d;git checkout 724a6b18a9224343ef04fe49199dfb6020ce132a 2>/dev/null ; true; \ GOPATH=$(GO_DEP_PATH) $(GO) install -v -gcflags "-N -l" $(GO_DEP_PATH)/src/github.com/openconfig/ygot/ygot + GOPATH=$(GO_DEP_PATH) $(GO) install -v -gcflags "-N -l" $(GO_DEP_PATH)/src/github.com/jipanyang/gnxi/utils/xpath cd $(GO_DEP_PATH)/src/github.com/jipanyang/gnmi/client/gnmi; git reset --hard HEAD;git clean -f -d;git checkout cb4d464fa018c29eadab98281448000bee4dcc3d 2>/dev/null ; true; \ GOPATH=$(GO_DEP_PATH) $(GO) install -v -gcflags "-N -l" $(GO_DEP_PATH)/src/github.com/jipanyang/gnmi/client/gnmi From 76a6459c51e9955f8834bff11b2d4302364b6462 Mon Sep 17 00:00:00 2001 From: Eric Seifert Date: Thu, 9 Apr 2020 08:05:23 -0700 Subject: [PATCH 11/13] Fix build to account for mgmt-framework change to gomodules as well --- Makefile | 57 ++++--------------------- go.mod | 30 +++---------- go.sum | 36 ++++++++++++++++ sonic_data_client/transl_data_client.go | 2 +- transl_utils/transl_utils.go | 2 +- 5 files changed, 53 insertions(+), 74 deletions(-) diff --git a/Makefile b/Makefile index 3e52ea886..111aa9d42 100644 --- a/Makefile +++ b/Makefile @@ -16,61 +16,22 @@ TEST_FILES=$(wildcard *_test.go) TELEMETRY_TEST_DIR = $(GO_MGMT_PATH)/build/tests/gnmi_server TELEMETRY_TEST_BIN = $(TELEMETRY_TEST_DIR)/server.test -.phony: mgmt-deps - all: sonic-telemetry $(TELEMETRY_TEST_BIN) go.mod: /usr/local/go/bin/go mod init github.com/Azure/sonic-telemetry -mgmt-deps: - rm -rf cvl - rm -rf translib - cp -r ../sonic-mgmt-framework/src/cvl ./ - cp -r ../sonic-mgmt-framework/src/translib ./ - find cvl -name \*\.go -exec sed -i -e 's/\"translib/\"github.com\/Azure\/sonic-telemetry\/translib/g' {} \; - find translib -name \*\.go -exec sed -i -e 's/\"translib/\"github.com\/Azure\/sonic-telemetry\/translib/g' {} \; - find cvl -name \*\.go -exec sed -i -e 's/\"cvl/\"github.com\/Azure\/sonic-telemetry\/cvl/g' {} \; - find translib -name \*\.go -exec sed -i -e 's/\"cvl/\"github.com\/Azure\/sonic-telemetry\/cvl/g' {} \; - sed -i -e 's/\.\.\/\.\.\/\.\.\/models\/yang/\.\.\/\.\.\/\.\.\/sonic-mgmt-framework\/models\/yang/' translib/ocbinds/oc.go - sed -i -e 's/\$$GO run \$$BUILD_GOPATH\/src\/github.com\/openconfig\/ygot\/generator\/generator.go/generator/' translib/ocbinds/oc.go - $(GO) get github.com/openconfig/gnmi@89b2bf29312cda887da916d0f3a32c1624b7935f - $(GO) get github.com/openconfig/ygot@724a6b18a9224343ef04fe49199dfb6020ce132a - $(GO) get github.com/openconfig/goyang@064f9690516f4f72db189f4690b84622c13b7296 - $(GO) get github.com/openconfig/goyang@064f9690516f4f72db189f4690b84622c13b7296 - $(GO) get golang.org/x/crypto/ssh/terminal@e9b2fee46413 - $(GO) get github.com/jipanyang/gnxi@f0a90cca6fd0041625bcce561b71f849c9b65a8d - $(GO) get github.com/godbus/dbus - $(GO) get github.com/golang/glog@23def4e6c14b4da8ac2ed8007337bc5eb5007998 - $(GO) get github.com/antchfx/xpath@d9ad276609987dd73ce5cd7d6265fe82189b10b6 - $(GO) get github.com/antchfx/xmlquery@fe009d4cc63c3011f05e1dfa75a27899acccdf11 - rm -rf vendor + +sonic-telemetry: go.mod $(GO) mod vendor - ln -s vendor src - cp -r $(GOPATH)/pkg/mod/github.com/openconfig/gnmi@v0.0.0-20190823184014-89b2bf29312c/* vendor/github.com/openconfig/gnmi/ - cp -r $(GOPATH)/pkg/mod/github.com/openconfig/goyang@v0.0.0-20190924211109-064f9690516f/* vendor/github.com/openconfig/goyang/ - cp -r $(GOPATH)/pkg/mod/github.com/openconfig/ygot@v0.6.1-0.20190723223108-724a6b18a922/* vendor/github.com/openconfig/ygot/ - cp -r $(GOPATH)/pkg/mod/golang.org/x/crypto@v0.0.0-20191206172530-e9b2fee46413/* vendor/golang.org/x/crypto/ - cp -r $(GOPATH)/pkg/mod/github.com/antchfx/xpath@v1.1.2/* vendor/github.com/antchfx/xpath/ - cp -r $(GOPATH)/pkg/mod/github.com/antchfx/xmlquery@v1.1.1-0.20191015122529-fe009d4cc63c/* vendor/github.com/antchfx/xmlquery/ + cp -r $(GO_MGMT_PATH)/vendor/github.com/antchfx ./vendor/github.com/ + cp -r $(GO_MGMT_PATH)/vendor/github.com/openconfig ./vendor/github.com/ cp -r $(GOPATH)/pkg/mod/github.com/jipanyang/gnxi@v0.0.0-20181221084354-f0a90cca6fd0/* vendor/github.com/jipanyang/gnxi/ + cp -r $(GOPATH)/pkg/mod/golang.org/x/crypto@v0.0.0-20200302210943-78000ba7a073/* vendor/golang.org/x/crypto/ chmod -R u+w vendor patch -d vendor -p0 ../sonic-mgmt-framework diff --git a/go.sum b/go.sum index 0f3e2ed20..0b828e7c1 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,12 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Workiva/go-datastructures v1.0.50 h1:slDmfW6KCHcC7U+LP3DDBbm4fqTwZGn1beOFPfGaLvo= github.com/Workiva/go-datastructures v1.0.50/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA= +github.com/Workiva/go-datastructures v1.0.52 h1:PLSK6pwn8mYdaoaCZEMsXBpBotr4HHn9abU0yMQt0NI= +github.com/Workiva/go-datastructures v1.0.52/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af h1:wVe6/Ea46ZMeNkQjjBW6xcqyQA/j5e0D6GytH95g0gQ= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= +github.com/antchfx/jsonquery v1.0.0 h1:1Yhk496SrCoY6fJkFZqpXEqbwOw5sFtLns9la4NoK3I= +github.com/antchfx/jsonquery v1.0.0/go.mod h1:h7950pvPrUZzJIflNqsELgDQovTpPNa0rAHf8NwjegY= github.com/antchfx/jsonquery v1.1.0 h1:ZeqeHheI8WsEN5blUqZXZ30w2jrbFvlQIq5B7X7Z86E= github.com/antchfx/jsonquery v1.1.0/go.mod h1:h7950pvPrUZzJIflNqsELgDQovTpPNa0rAHf8NwjegY= github.com/antchfx/xmlquery v1.1.1-0.20191015122529-fe009d4cc63c h1:7PNiWdkjxIpDv6dqsTYbczOgPmiloDTV9qNeP8v66I8= @@ -16,6 +20,7 @@ github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/c9s/goprocinfo v0.0.0-20191125144613-4acdd056c72d h1:MQGrhPHSxg08x+LKgQTOnnjfXt+p+128WCECqAYXJsU= github.com/c9s/goprocinfo v0.0.0-20191125144613-4acdd056c72d/go.mod h1:uEyr4WpAH4hio6LFriaPkL938XnrvLpNPmQHBdrmbIE= +github.com/cenkalti/backoff/v4 v4.0.0/go.mod h1:eEew/i+1Q6OrCDZh3WiXYv3+nJwBASZ8Bog/87DQnVg= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= @@ -23,6 +28,7 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb h1:IT4JYU7k4ikYg1SCxNI1/Tieq/NFvh6dzLdgi7eu0tM= github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb/go.mod h1:bH6Xx7IW64qjjJq8M2u4dxNaBiDfKK+z/3eGDpXEQhc= @@ -36,8 +42,12 @@ github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD87 github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-redis/redis v6.15.6+incompatible h1:H9evprGPLI8+ci7fxQx6WNZHJSb7be8FqJQRhdQZ5Sg= github.com/go-redis/redis v6.15.6+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= +github.com/go-redis/redis/v7 v7.0.0-beta.3.0.20190824101152-d19aba07b476 h1:WNSiFp8Ww4ZP7XUzW56zDYv5roKQ4VfsdHCLoh8oDj4= +github.com/go-redis/redis/v7 v7.0.0-beta.3.0.20190824101152-d19aba07b476/go.mod h1:xhhSbUMTsleRPur+Vgx9sUHtyN33bdjxY+9/0n9Ig8s= github.com/godbus/dbus v4.1.0+incompatible h1:WqqLRTsQic3apZUK9qC5sGNfXthmPXzUZ7nQPrNITa4= github.com/godbus/dbus v4.1.0+incompatible/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw= +github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME= +github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= @@ -50,10 +60,20 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4 h1:+EOh4OY6tjM6ZueeUKinl1f0U2820HzQOuf1iqMnsks= +github.com/golang/protobuf v1.4.0-rc.4/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/google/gnxi v0.0.0-20191016182648-6697a080bc2d h1:OtErLAncPdsEEhOI4ueR48dr6uThRIPkwWcOAdQ4LyI= github.com/google/gnxi v0.0.0-20191016182648-6697a080bc2d/go.mod h1:6kkMbKS62iZMyk1q0zukcqkEJwnIhcbgg/hmoFmRDZk= github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/protobuf v3.11.4+incompatible/go.mod h1:lUQ9D1ePzbH2PrIS7ob/bjm9HXyH5WHB0Akwh7URreM= +github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/jipanyang/gnmi v0.0.0-20180820232453-cb4d464fa018 h1:M++7b2XCTGqQwqu+AB0B3XzXiV+vVawnXJ4tvxUMrTU= @@ -71,8 +91,10 @@ github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgx github.com/msteinert/pam v0.0.0-20190215180659-f29b9f28d6f9 h1:ZivaaKmjs9q90zi6I4gTLW6tbVGtlBjellr3hMYaly0= github.com/msteinert/pam v0.0.0-20190215180659-f29b9f28d6f9/go.mod h1:np1wUFZ6tyoke22qDJZY40URn9Ae51gX7ljIWXN5TJs= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.10.3 h1:OoxbjfXVZyod1fmWYhI7SEyaD8B00ynP3T+D5GiyHOY= github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/openconfig/gnmi v0.0.0-20190823184014-89b2bf29312c h1:a380JP+B7xlMbEQOlha1buKhzBPXFqgFXplyWCEIGEY= @@ -115,6 +137,8 @@ github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 h1:ULYEB3JvPRE/IfO+9uO7vKV/xzVTO7XPAwm8xbf4w2g= golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -131,6 +155,8 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8= golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -152,6 +178,7 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= gonum.org/v1/plot v0.0.0-20200226011204-b25252b0d522 h1:7v47ToNmC/q9Mpz3f8TbmGSAIC5V++C3MLF/ZMUlhJw= gonum.org/v1/plot v0.0.0-20200226011204-b25252b0d522/go.mod h1:2wtU6YrrdQAhAF9+MTd5tOQjrov/zF70b1i99Npjvgo= @@ -164,6 +191,14 @@ google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1 h1:wdKvqQk7IttEw92GoRyKG2IDrUIpgpj6H6m81yfeMW0= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.1 h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.20.1 h1:ESRXHgpUBG5D2I5mmsQIyYxB/tQIZfSZ8wLyFDf/N/U= +google.golang.org/protobuf v1.20.1/go.mod h1:KqelGeouBkcbcuB3HCk4/YH2tmNLk6YSWA5LIWeI/lY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= @@ -174,6 +209,7 @@ gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+a gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/sonic_data_client/transl_data_client.go b/sonic_data_client/transl_data_client.go index 5d48403b4..90bc7f907 100644 --- a/sonic_data_client/transl_data_client.go +++ b/sonic_data_client/transl_data_client.go @@ -11,7 +11,7 @@ import ( "time" "fmt" "reflect" - "github.com/Azure/sonic-telemetry/translib" + "github.com/Azure/sonic-mgmt-framework/translib" "bytes" "encoding/json" "context" diff --git a/transl_utils/transl_utils.go b/transl_utils/transl_utils.go index 0e40bd651..93de6636d 100644 --- a/transl_utils/transl_utils.go +++ b/transl_utils/transl_utils.go @@ -7,7 +7,7 @@ import ( "fmt" log "github.com/golang/glog" gnmipb "github.com/openconfig/gnmi/proto/gnmi" - "github.com/Azure/sonic-telemetry/translib" + "github.com/Azure/sonic-mgmt-framework/translib" "github.com/Azure/sonic-telemetry/common_utils" "context" ) From 88082b47117c37f444fd6ceeaa56fc1e9aab5f38 Mon Sep 17 00:00:00 2001 From: Eric Seifert Date: Thu, 9 Apr 2020 09:46:11 -0700 Subject: [PATCH 12/13] Remove prefix target check for get request --- gnmi_server/server.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/gnmi_server/server.go b/gnmi_server/server.go index 650e8bd3b..258625c1a 100644 --- a/gnmi_server/server.go +++ b/gnmi_server/server.go @@ -270,15 +270,6 @@ func (s *Server) Get(ctx context.Context, req *gnmipb.GetRequest) (*gnmipb.GetRe var target string prefix := req.GetPrefix() - if prefix == nil { - return nil, status.Error(codes.Unimplemented, "No target specified in prefix") - } else { - target = prefix.GetTarget() - if target == "" { - return nil, status.Error(codes.Unimplemented, "Empty target data not supported yet") - } - } - paths := req.GetPath() target = prefix.GetTarget() log.V(5).Infof("GetRequest paths: %v", paths) From a1a9c5ba4cb80be4eb4c27d5abb2152373cd7b73 Mon Sep 17 00:00:00 2001 From: Eric Seifert Date: Thu, 9 Apr 2020 13:49:47 -0700 Subject: [PATCH 13/13] Makefile fix --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 111aa9d42..2c4fe80b4 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ check: -$(GO) test -mod=vendor -v github.com/Azure/sonic-telemetry/dialout/dialout_client clean: -# rm -rf vendor + rm -rf vendor chmod -f -R u+w $(GOPATH)/pkg || true rm -rf $(GOPATH) rm -f src @@ -76,5 +76,6 @@ deinstall: rm $(DESTDIR)/usr/sbin/dialout_client_cli rm $(DESTDIR)/usr/sbin/gnmi_get rm $(DESTDIR)/usr/sbin/gnmi_set + rm $(DESTDIR)/usr/sbin/gnoi_client