summaryrefslogtreecommitdiffhomepage
path: root/tools/grpc/python/add_path.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/grpc/python/add_path.py')
-rw-r--r--tools/grpc/python/add_path.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/tools/grpc/python/add_path.py b/tools/grpc/python/add_path.py
new file mode 100644
index 00000000..1af4882f
--- /dev/null
+++ b/tools/grpc/python/add_path.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+
+from __future__ import absolute_import
+from __future__ import print_function
+
+import grpc
+from google.protobuf.any_pb2 import Any
+
+import gobgp_pb2
+import gobgp_pb2_grpc
+import attribute_pb2
+
+_TIMEOUT_SECONDS = 1000
+
+
+def run():
+ channel = grpc.insecure_channel('localhost:50051')
+ stub = gobgp_pb2_grpc.GobgpApiStub(channel)
+
+ nlri = Any()
+ nlri.Pack(attribute_pb2.IPAddressPrefix(
+ prefix_len=24,
+ prefix="10.0.0.0",
+ ))
+ origin = Any()
+ origin.Pack(attribute_pb2.OriginAttribute(
+ origin=2, # INCOMPLETE
+ ))
+ as_segment = attribute_pb2.AsSegment(
+ # type=2, # "type" causes syntax error
+ numbers=[100, 200],
+ )
+ as_segment.type = 2 # SEQ
+ as_path = Any()
+ as_path.Pack(attribute_pb2.AsPathAttribute(
+ segments=[as_segment],
+ ))
+ next_hop = Any()
+ next_hop.Pack(attribute_pb2.NextHopAttribute(
+ next_hop="1.1.1.1",
+ ))
+ attributes = [origin, as_path, next_hop]
+
+ stub.AddPath(
+ gobgp_pb2.AddPathRequest(
+ table_type=gobgp_pb2.GLOBAL,
+ path=gobgp_pb2.Path(
+ nlri=nlri,
+ pattrs=attributes,
+ family=gobgp_pb2.Family(afi=gobgp_pb2.Family.AFI_IP, safi=gobgp_pb2.Family.SAFI_UNICAST),
+ )
+ ),
+ _TIMEOUT_SECONDS,
+ )
+
+if __name__ == '__main__':
+ run()