summaryrefslogtreecommitdiffhomepage
path: root/test/lib/exabgp.py
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2018-01-18 10:21:43 +0900
committerIWASE Yusuke <iwase.yusuke0@gmail.com>2018-02-10 21:48:23 +0900
commit8bd028f5ff7dd64a06a2e266d94649fe911004e8 (patch)
tree3c0a62109dc4ceb8be9ada7b253aefd481f0bbdc /test/lib/exabgp.py
parentaae35319a8421705f17e02e1a89aad9486ee713e (diff)
test/lib/exabgp: Enable to get adj-RIB-{in,out}
"exabgpcli" supports to show adj-RIB-in and adj-RIB-out, this patch enables ExaBGPContainer to get these RIBs information. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'test/lib/exabgp.py')
-rw-r--r--test/lib/exabgp.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/lib/exabgp.py b/test/lib/exabgp.py
index 10406b6b..1326dd86 100644
--- a/test/lib/exabgp.py
+++ b/test/lib/exabgp.py
@@ -229,6 +229,60 @@ class ExaBGPContainer(BGPContainer):
self.routes[route] = new_paths
+ def _get_adj_rib(self, peer, rf, in_out='in'):
+ # IPv4 Unicast:
+ # neighbor 172.17.0.2 ipv4 unicast 192.168.100.0/24 path-information 0.0.0.20 next-hop self
+ # IPv6 FlowSpec:
+ # neighbor 172.17.0.2 ipv6 flow flow destination-ipv6 2002:1::/64/0 source-ipv6 2002:2::/64/0 next-header =udp flow-label >100
+ rf_map = {
+ 'ipv4': ['ipv4', 'unicast'],
+ 'ipv6': ['ipv6', 'unicast'],
+ 'ipv4-flowspec': ['ipv4', 'flow'],
+ 'ipv6-flowspec': ['ipv6', 'flow'],
+ }
+ assert rf in rf_map
+ assert in_out in ('in', 'out')
+ peer_addr = self.peer_name(peer)
+ lines = self.local('exabgpcli show adj-rib {0}'.format(in_out), capture=True).split('\n')
+ # rib = {
+ # <nlri>: [
+ # {
+ # 'nlri': <nlri>,
+ # 'next-hop': <next-hop>,
+ # ...
+ # },
+ # ...
+ # ],
+ # }
+ rib = {}
+ for line in lines:
+ if not line:
+ continue
+ values = line.split()
+ if peer_addr != values[1]:
+ continue
+ elif rf is not None and rf_map[rf] != values[2:4]:
+ continue
+ if rf in ('ipv4', 'ipv6'):
+ nlri = values[4]
+ rib.setdefault(nlri, [])
+ path = {k: v for k, v in zip(*[iter(values[5:])] * 2)}
+ path['nlri'] = nlri
+ rib[nlri].append(path)
+ elif rf in ('ipv4-flowspec', 'ipv6-flowspec'):
+ # XXX: Missing path attributes?
+ nlri = ' '.join(values[5:])
+ rib.setdefault(nlri, [])
+ path = {'nlri': nlri}
+ rib[nlri].append(path)
+ return rib
+
+ def get_adj_rib_in(self, peer, rf='ipv4'):
+ return self._get_adj_rib(peer, rf, 'in')
+
+ def get_adj_rib_out(self, peer, rf='ipv4'):
+ return self._get_adj_rib(peer, rf, 'out')
+
class RawExaBGPContainer(ExaBGPContainer):
def __init__(self, name, config, ctn_image_name='osrg/exabgp',