From 8bd028f5ff7dd64a06a2e266d94649fe911004e8 Mon Sep 17 00:00:00 2001 From: IWASE Yusuke Date: Thu, 18 Jan 2018 10:21:43 +0900 Subject: 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 --- test/lib/exabgp.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) 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': , + # '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', -- cgit v1.2.3