diff options
author | Satoshi Fujimoto <satoshi.fujimoto7@gmail.com> | 2017-10-02 13:36:28 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-11-07 21:53:46 +0900 |
commit | 002dca7e3b3c509ed6741343d5fecfeb183e19d2 (patch) | |
tree | 55bc8b159a2cb126ddece18fe8ecadb75a2c1d4d /test/lib | |
parent | 88defeba0f13bde7ab3de37047a95f5a611306a9 (diff) |
test/lib: Enhancement on Get Rib library on Quagga
For Quagga containers, currently, when we use get_global_rib()
without specifying prefix, we cannot get AS_PATH and other attributes.
And when we use get_global_rib() with prefix,
we can get only one path even if there is multiple paths for a destination.
This commit fixes these problems by refining test/lib/quagga.py.
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
Diffstat (limited to 'test/lib')
-rw-r--r-- | test/lib/quagga.py | 74 |
1 files changed, 32 insertions, 42 deletions
diff --git a/test/lib/quagga.py b/test/lib/quagga.py index 51433d30..86a468d8 100644 --- a/test/lib/quagga.py +++ b/test/lib/quagga.py @@ -14,6 +14,7 @@ # limitations under the License. from __future__ import absolute_import +import re from fabric import colors from fabric.utils import indent @@ -56,34 +57,14 @@ class QuaggaBGPContainer(BGPContainer): if out.startswith('No BGP network exists'): return rib - read_next = False + for line in out.split('\n')[6:-2]: + line = line[3:] - for line in out.split('\n'): - ibgp = False - if line[:2] == '*>': - line = line[2:] - ibgp = False - if line[0] == 'i': - line = line[1:] - ibgp = True - elif not read_next: + p = line.split()[0] + if '/' not in p: continue - elems = line.split() - - if len(elems) == 1: - read_next = True - prefix = elems[0] - continue - elif read_next: - nexthop = elems[0] - else: - prefix = elems[0] - nexthop = elems[1] - read_next = False - - rib.append({'prefix': prefix, 'nexthop': nexthop, - 'ibgp': ibgp}) + rib.extend(self.get_global_rib_with_prefix(p, rf)) return rib @@ -104,23 +85,32 @@ class QuaggaBGPContainer(BGPContainer): else: raise Exception('unknown output format {0}'.format(lines)) - if lines[0] == 'Local': - aspath = [] - else: - 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, 'attrs': attrs}) + while len(lines) > 0: + if lines[0] == 'Local': + aspath = [] + else: + aspath = [int(re.sub('\D', '', asn)) for asn in lines[0].split()] + + nexthop = lines[1].split()[0].strip() + info = [s.strip(',') for s in lines[2].split()] + attrs = [] + ibgp = False + best = False + 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)}) + if 'internal' in info: + ibgp = True + if 'best' in info: + best = True + + rib.append({'prefix': prefix, 'nexthop': nexthop, + 'aspath': aspath, 'attrs': attrs, 'ibgp': ibgp, 'best': best}) + + lines = lines[5:] return rib |