aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/Routing.py
diff options
context:
space:
mode:
authorZdeno Olsovsky <zolsovsk@cisco.com>2016-06-13 15:46:07 +0200
committerMatej Klotton <mklotton@cisco.com>2016-07-22 09:25:22 +0000
commit7c3e0cc41f55327d6eeb04fe757c6e80064ab28a (patch)
treece700ba4f130b8f153e3e72a6041f68ddb239f85 /resources/libraries/python/Routing.py
parentdec1188c7f89f5f8f97085b5f68c6f1d918586b8 (diff)
CSIT-158: Tap interface tests
Change-Id: I30a4562ea5fca9b839d854118243daa70378b0ae Signed-off-by: Zdeno Olsovsky <zolsovsk@cisco.com>
Diffstat (limited to 'resources/libraries/python/Routing.py')
-rw-r--r--resources/libraries/python/Routing.py25
1 files changed, 24 insertions, 1 deletions
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)