summaryrefslogtreecommitdiffhomepage
path: root/test/lib
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-12-25 14:46:04 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-01-19 13:25:19 +0900
commit3707b5aedf11e1adc2bd35baba9d05a308ba384b (patch)
treea77e042560c21b42366b79f5dd393001e034a3c6 /test/lib
parent52770785bd2c9b77744ace2a2e2092132b534406 (diff)
test/lib/base: Delete FlowSpec routes with keyword
Currently, in case of the FlowSpec routes, "prefix" value which stored on each container instance is just a keyword and not valid NLRI arguments for adding or deleting routes. So when deleting routes with "route" keyword, it is required to construct the NLRI arguments using "matchs" value. This patch enables to construct the valid NLIR arguments as "prefix" value when adding the FlowSpec routes and enables to delete the FlowSpec routes with "route" keyword. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/base.py12
-rw-r--r--test/lib/exabgp.py8
-rw-r--r--test/lib/gobgp.py2
3 files changed, 16 insertions, 6 deletions
diff --git a/test/lib/base.py b/test/lib/base.py
index d7d33f40..19452896 100644
--- a/test/lib/base.py
+++ b/test/lib/base.py
@@ -409,14 +409,24 @@ class BGPContainer(Container):
def log(self):
return local('cat {0}/*.log'.format(self.config_dir), capture=True)
+ def _extract_routes(self, families):
+ routes = {}
+ for prefix, paths in self.routes.items():
+ if paths and paths[0]['rf'] in families:
+ routes[prefix] = paths
+ return routes
+
def add_route(self, route, rf='ipv4', attribute=None, aspath=None,
community=None, med=None, extendedcommunity=None,
nexthop=None, matchs=None, thens=None,
local_pref=None, identifier=None, reload_config=True):
if route not in self.routes:
self.routes[route] = []
+ prefix = route
+ if 'flowspec' in rf:
+ prefix = ' '.join(['match'] + matchs)
self.routes[route].append({
- 'prefix': route,
+ 'prefix': prefix,
'rf': rf,
'attr': attribute,
'next-hop': nexthop,
diff --git a/test/lib/exabgp.py b/test/lib/exabgp.py
index efc39ac1..3bb9d207 100644
--- a/test/lib/exabgp.py
+++ b/test/lib/exabgp.py
@@ -15,11 +15,11 @@
from __future__ import absolute_import
+from itertools import chain
import time
from fabric import colors
from fabric.api import local
-from itertools import chain
from lib.base import (
BGPContainer,
@@ -124,11 +124,11 @@ class ExaBGPContainer(BGPContainer):
cmd << '{0};'.format(str(r))
cmd << ' }'
- routes = [r for r in chain.from_iterable(self.routes.itervalues()) if 'flowspec' in r['rf']]
- if len(routes) > 0:
+ routes = self._extract_routes(['ipv4-flowspec', 'ipv6-flowspec'])
+ for key, routes in routes.items():
cmd << ' flow {'
for route in routes:
- cmd << ' route {0}{{'.format(route['prefix'])
+ cmd << ' route {0} {{'.format(key)
cmd << ' match {'
for match in route['matchs']:
cmd << ' {0};'.format(match)
diff --git a/test/lib/gobgp.py b/test/lib/gobgp.py
index 6422e79d..f0bff6d7 100644
--- a/test/lib/gobgp.py
+++ b/test/lib/gobgp.py
@@ -559,7 +559,7 @@ class GoBGPContainer(BGPContainer):
cmd = 'gobgp global '\
'rib add match {0} then {1} -a {2}'.format(' '.join(v['matchs']), ' '.join(v['thens']), v['rf'])
else:
- raise Exception('unsupported route faily: {0}'.format(v['rf']))
+ raise Exception('unsupported route family: {0}'.format(v['rf']))
self.local(cmd)
def del_route(self, route, identifier=None, reload_config=True):