summaryrefslogtreecommitdiffhomepage
path: root/test/scenario_test/lib
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-08-05 17:16:31 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-08-08 20:56:46 +0900
commita01b549fffd428f075b8732fde244c47baf28ecd (patch)
tree9f4d6a8c56d9ab068fd1bb5b85ca9fa59e0ba1e2 /test/scenario_test/lib
parentbd912231e5509829bdb6b892344d4b14ca0b3b29 (diff)
*: kill protobuf path structure
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'test/scenario_test/lib')
-rw-r--r--test/scenario_test/lib/base.py1
-rw-r--r--test/scenario_test/lib/gobgp.py29
2 files changed, 25 insertions, 5 deletions
diff --git a/test/scenario_test/lib/base.py b/test/scenario_test/lib/base.py
index 274a68cf..7bb7b79f 100644
--- a/test/scenario_test/lib/base.py
+++ b/test/scenario_test/lib/base.py
@@ -36,6 +36,7 @@ BGP_ATTR_TYPE_AS_PATH = 2
BGP_ATTR_TYPE_NEXT_HOP = 3
BGP_ATTR_TYPE_MULTI_EXIT_DISC = 4
BGP_ATTR_TYPE_LOCAL_PREF = 5
+BGP_ATTR_TYPE_MP_REACH_NLRI = 14
BGP_ATTR_TYPE_EXTENDED_COMMUNITIES = 16
diff --git a/test/scenario_test/lib/gobgp.py b/test/scenario_test/lib/gobgp.py
index c7a9631e..e1da72c8 100644
--- a/test/scenario_test/lib/gobgp.py
+++ b/test/scenario_test/lib/gobgp.py
@@ -51,11 +51,17 @@ class GoBGPContainer(BGPContainer):
def _get_as_path(self, path):
asps = (p['as_paths'] for p in path['attrs'] if
- p['type'] == BGP_ATTR_TYPE_AS_PATH and 'as_paths' in p)
+ p['type'] == BGP_ATTR_TYPE_AS_PATH and 'as_paths' in p
+ and p['as_paths'] != None)
asps = chain.from_iterable(asps)
asns = (asp['asns'] for asp in asps)
return list(chain.from_iterable(asns))
+ def _get_nexthop(self, path):
+ for p in path['attrs']:
+ if p['type'] == BGP_ATTR_TYPE_NEXT_HOP or p['type'] == BGP_ATTR_TYPE_MP_REACH_NLRI:
+ return p['nexthop']
+
def _trigger_peer_cmd(self, cmd, peer):
if peer not in self.peers:
raise Exception('not found peer {0}'.format(peer.router_id))
@@ -75,13 +81,22 @@ class GoBGPContainer(BGPContainer):
peer_addr = self.peers[peer]['neigh_addr'].split('/')[0]
cmd = 'gobgp -j neighbor {0} local -a {1}'.format(peer_addr, rf)
output = self.local(cmd, capture=True)
- n = json.loads(output)
- return n
+ ret = json.loads(output)
+ for d in ret:
+ for p in d["paths"]:
+ p["nexthop"] = self._get_nexthop(p)
+ p["as_path"] = self._get_as_path(p)
+ return ret
def get_global_rib(self, prefix='', rf='ipv4'):
cmd = 'gobgp -j global rib {0} -a {1}'.format(prefix, rf)
output = self.local(cmd, capture=True)
- return json.loads(output)
+ ret = json.loads(output)
+ for d in ret:
+ for p in d["paths"]:
+ p["nexthop"] = self._get_nexthop(p)
+ p["as_path"] = self._get_as_path(p)
+ return ret
def _get_adj_rib(self, adj_type, peer, prefix='', rf='ipv4'):
if peer not in self.peers:
@@ -91,7 +106,11 @@ class GoBGPContainer(BGPContainer):
adj_type,
prefix, rf)
output = self.local(cmd, capture=True)
- return json.loads(output)
+ ret = [p["paths"][0] for p in json.loads(output)]
+ for p in ret:
+ p["nexthop"] = self._get_nexthop(p)
+ p["as_path"] = self._get_as_path(p)
+ return ret
def get_adj_rib_in(self, peer, prefix='', rf='ipv4'):
return self._get_adj_rib('in', peer, prefix, rf)