2 The purpose of this library is communicate with tools which run xmlrpc server.
3 At the moment it is going to be the with the exarpc.py (used with exabgp) and
4 with play.py for bgp functional testing.
5 exa_ methods apply to test/tools/exabgp_files/exarpc.py
6 play_ methods apply to test/tool/fastbgp/play.py (only with --evpn used)
12 class BgpRpcClient(object):
13 """The client for SimpleXMLRPCServer."""
15 def __init__(self, peer_addr):
16 """Setup destination point of the rpc server"""
17 self.proxy = xmlrpclib.ServerProxy("http://{}:8000".format(peer_addr))
19 def exa_announce(self, full_exabgp_cmd):
20 """The full command to be passed to exabgp."""
21 return self.proxy.execute(full_exabgp_cmd)
23 def _exa_get_counter(self, msg_type):
24 """Gets counter form the server of given message type."""
25 return self.proxy.get_counter(msg_type)
27 def exa_get_received_open_count(self):
28 """Gets open messages counter."""
29 return self._exa_get_counter('open')
31 def exa_get_received_keepalive_count(self):
32 """Gets keepalive messages counter."""
33 return self._exa_get_counter('keepalive')
35 def exa_get_received_update_count(self):
36 """Gets update messges counter."""
37 return self._exa_get_counter('update')
39 def exa_get_received_route_refresh_count(self):
40 """Gets route refresh message counter."""
41 return self._exa_get_counter('route_refresh')
43 def _exa_clean_counter(self, msg_type):
44 """Cleans counter on the server of given message type."""
45 return self.proxy.clean_counter(msg_type)
47 def exa_clean_received_open_count(self):
48 """Cleans open message counter."""
49 return self._exa_clean_counter('open')
51 def exa_clean_received_keepalive_count(self):
52 """Cleans keepalive message counter."""
53 return self._exa_clean_counter('keepalive')
55 def exa_clean_received_update_count(self):
56 """Cleans update message counter."""
57 return self._exa_clean_counter('update')
59 def exa_clean_received_route_refresh_count(self):
60 """Cleans route refresh message counter."""
61 return self._exa_clean_counter('route_refresh')
63 def _exa_clean_message(self, msg_type):
64 """Cleans stored message on the server of given message type."""
65 return self.proxy.clean_message(msg_type)
67 def exa_clean_update_message(self):
68 """Cleans update message."""
69 return self._exa_clean_message('update')
71 def _exa_get_message(self, msg_type):
72 """Gets stored message on the server of given message type."""
73 return self.proxy.get_message(msg_type)
75 def exa_get_update_message(self, msg_only=True):
76 """Cleans update message.
78 Exabgp provides more details than just message content (e.g. peer ip,
79 timestamp, ...). msg_only is a flag that we want just message content
82 msg = self._exa_get_message('update')
85 return msg if 'neighbor' not in msg else msg['neighbor']['message']
87 def play_send(self, hexstring):
88 """Sends given hex data, already encoded bgp update message is expected."""
89 return self.proxy.send(hexstring)
91 def play_get(self, what='update'):
92 """Gets the last received (update) mesage as hex string."""
93 return self.proxy.get(what)
95 def play_clean(self, what='update'):
96 """Cleans the message (update) on the server."""
97 return self.proxy.clean(what)