1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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()
|