diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-11-07 19:44:59 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-11-08 05:05:36 -0800 |
commit | 2f6db55c6743cdd568f1555b91017a6f2c09695d (patch) | |
tree | f022bb9bae68b89d3a682edeb2bfcdac7005eedb /test/scenario_test/lib | |
parent | d53a5d11d9f3b0ee762a0510ff6608e69ed595ff (diff) |
scenario_test: test local-pref and med handling
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.py | 4 | ||||
-rw-r--r-- | test/scenario_test/lib/exabgp.py | 2 | ||||
-rw-r--r-- | test/scenario_test/lib/gobgp.py | 23 | ||||
-rw-r--r-- | test/scenario_test/lib/quagga.py | 13 |
4 files changed, 34 insertions, 8 deletions
diff --git a/test/scenario_test/lib/base.py b/test/scenario_test/lib/base.py index 8a81c245..d3cb9bd9 100644 --- a/test/scenario_test/lib/base.py +++ b/test/scenario_test/lib/base.py @@ -286,7 +286,8 @@ class BGPContainer(Container): def add_route(self, route, rf='ipv4', attribute=None, aspath=None, community=None, med=None, extendedcommunity=None, - nexthop=None, matchs=None, thens=None): + nexthop=None, matchs=None, thens=None, + local_pref=None): self.routes[route] = {'prefix': route, 'rf': rf, 'attr': attribute, @@ -294,6 +295,7 @@ class BGPContainer(Container): 'as-path': aspath, 'community': community, 'med': med, + 'local-pref': local_pref, 'extended-community': extendedcommunity, 'matchs': matchs, 'thens' : thens} diff --git a/test/scenario_test/lib/exabgp.py b/test/scenario_test/lib/exabgp.py index af310530..e14a084b 100644 --- a/test/scenario_test/lib/exabgp.py +++ b/test/scenario_test/lib/exabgp.py @@ -93,6 +93,8 @@ class ExaBGPContainer(BGPContainer): r << 'community [{0}]'.format(' '.join(c for c in route['community'])) if route['med']: r << 'med {0}'.format(route['med']) + if route['local-pref']: + r << 'local-preference {0}'.format(route['local-pref']) if route['extended-community']: r << 'extended-community [{0}]'.format(route['extended-community']) if route['attr']: diff --git a/test/scenario_test/lib/gobgp.py b/test/scenario_test/lib/gobgp.py index f126047d..042d6696 100644 --- a/test/scenario_test/lib/gobgp.py +++ b/test/scenario_test/lib/gobgp.py @@ -18,6 +18,11 @@ import json import toml from itertools import chain +def extract_path_attribute(path, typ): + for a in path['attrs']: + if a['type'] == typ: + return a + return None class GoBGPContainer(BGPContainer): @@ -105,7 +110,7 @@ class GoBGPContainer(BGPContainer): for d in ret: for p in d["paths"]: p["nexthop"] = self._get_nexthop(p) - p["as_path"] = self._get_as_path(p) + p["aspath"] = self._get_as_path(p) return ret def get_global_rib(self, prefix='', rf='ipv4'): @@ -115,7 +120,7 @@ class GoBGPContainer(BGPContainer): for d in ret: for p in d["paths"]: p["nexthop"] = self._get_nexthop(p) - p["as_path"] = self._get_as_path(p) + p["aspath"] = self._get_as_path(p) return ret def _get_adj_rib(self, adj_type, peer, prefix='', rf='ipv4'): @@ -129,7 +134,7 @@ class GoBGPContainer(BGPContainer): 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) + p["aspath"] = self._get_as_path(p) return ret def get_adj_rib_in(self, peer, prefix='', rf='ipv4'): @@ -308,8 +313,16 @@ class GoBGPContainer(BGPContainer): self.local(cmd) for v in self.routes.itervalues(): if v['rf'] == 'ipv4' or v['rf'] == 'ipv6': - cmd = 'gobgp global '\ - 'rib add {0} -a {1}'.format(v['prefix'], v['rf']) + r = CmdBuffer(' ') + r << 'gobgp global -a {0}'.format(v['rf']) + r << 'rib add {0}'.format(v['prefix']) + if v['next-hop']: + r << 'nexthop {0}'.format(v['next-hop']) + if v['local-pref']: + r << 'local-pref {0}'.format(v['local-pref']) + if v['med']: + r << 'med {0}'.format(v['med']) + cmd = str(r) elif v['rf'] == 'ipv4-flowspec' or v['rf'] == 'ipv6-flowspec': cmd = 'gobgp global '\ 'rib add match {0} then {1} -a {2}'.format(' '.join(v['matchs']), ' '.join(v['thens']), v['rf']) diff --git a/test/scenario_test/lib/quagga.py b/test/scenario_test/lib/quagga.py index 6001d9a3..17f855a9 100644 --- a/test/scenario_test/lib/quagga.py +++ b/test/scenario_test/lib/quagga.py @@ -108,10 +108,19 @@ class QuaggaBGPContainer(BGPContainer): lines = lines[2:] # other useless lines else: raise Exception('unknown output format {0}'.format(lines)) - nexthop = lines[1].split()[0].strip() aspath = [int(asn) for asn in lines[0].split()] + nexthop = lines[1].split()[0].strip() + info = [s.strip(',') for s in lines[2].split()] + attrs = [] + if 'metric' in info: + med = info[info.index('metric') + 1] + attrs.append({'type': BGP_ATTR_TYPE_MULTI_EXIT_DISC, 'metric': int(med)}) + if 'localpref' in info: + localpref = info[info.index('localpref') + 1] + attrs.append({'type': BGP_ATTR_TYPE_LOCAL_PREF, 'value': int(localpref)}) + rib.append({'prefix': prefix, 'nexthop': nexthop, - 'aspath': aspath}) + 'aspath': aspath, 'attrs': attrs}) return rib def get_neighbor_state(self, peer): |