From 7c3e0cc41f55327d6eeb04fe757c6e80064ab28a Mon Sep 17 00:00:00 2001 From: Zdeno Olsovsky Date: Mon, 13 Jun 2016 15:46:07 +0200 Subject: CSIT-158: Tap interface tests Change-Id: I30a4562ea5fca9b839d854118243daa70378b0ae Signed-off-by: Zdeno Olsovsky --- resources/libraries/python/Routing.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'resources/libraries/python/Routing.py') diff --git a/resources/libraries/python/Routing.py b/resources/libraries/python/Routing.py index 199b6de8d5..767fb3aff0 100644 --- a/resources/libraries/python/Routing.py +++ b/resources/libraries/python/Routing.py @@ -15,9 +15,10 @@ from resources.libraries.python.VatExecutor import VatTerminal from resources.libraries.python.topology import Topology - +from resources.libraries.python.ssh import exec_cmd_no_error class Routing(object): + """Routing utilities.""" @staticmethod @@ -93,3 +94,25 @@ class Routing(object): prefix_length=prefix_len, fib_number=fib_id, where=place) + + @staticmethod + def add_route(node, ip, prefix, gw, namespace=None): + """Add route in namespace. + + :param node: Node where to execute command. + :param ip: Route destination IP. + :param prefix: IP prefix. + :param namespace: Execute command in namespace. Optional + :param gw: Gateway. + :type node: dict + :type ip: str + :type prefix: int + :type gw: str + :type namespace: str + """ + if namespace is not None: + cmd = 'ip netns exec {} ip route add {}/{} via {}'.format( + namespace, ip, prefix, gw) + else: + cmd = 'ip route add {}/{} via {}'.format(ip, prefix, gw) + exec_cmd_no_error(node, cmd, sudo=True) -- cgit 1.2.3-korg