[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lnst-developers
Subject:    [PATCH lnst 4/8] InterfaceAPI: Adding nexthop route support
From:       Elad Raz <e () eladraz ! com>
Date:       2016-08-29 8:14:40
Message-ID: 1472458484-5386-5-git-send-email-e () eladraz ! com
[Download RAW message or body]

Adding the ability to add ECMP routes with a list of nexthops.

Signed-off-by: Elad Raz <eladr@mellanox.com>
---
 lnst/Controller/Machine.py     |  8 ++++++++
 lnst/Slave/InterfaceManager.py | 12 ++++++++++++
 lnst/Slave/NetTestSlave.py     | 16 ++++++++++++++++
 3 files changed, 36 insertions(+)

diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index dd9d5ec..12bb34b 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -767,6 +767,14 @@ class Interface(object):
         self._machine._rpc_call_x(self._netns, "del_route",
                                   self._id, dest, ipv6)
 
+    def add_nhs_route(self, dest, nhs, ipv6 = False):
+        self._machine._rpc_call_x(self._netns, "add_nhs_route",
+                                  self._id, dest, nhs, ipv6)
+
+    def del_nhs_route(self, dest, nhs, ipv6 = False):
+        self._machine._rpc_call_x(self._netns, "del_nhs_route",
+                                  self._id, dest, nhs, ipv6)
+
     def update_from_slave(self):
         if_data = self._machine._rpc_call_x(self._netns, "get_if_data",
                                             self._id)
diff --git a/lnst/Slave/InterfaceManager.py b/lnst/Slave/InterfaceManager.py
index f8da5eb..2c599d6 100644
--- a/lnst/Slave/InterfaceManager.py
+++ b/lnst/Slave/InterfaceManager.py
@@ -660,6 +660,18 @@ class Device(object):
     def del_route(self, dest, ipv6):
         exec_cmd("ip %s route del %s dev %s" % ("-6" if ipv6 else "", dest, self._name))
 
+    def route_cmd(self, cmd, dest, nhs, ipv6):
+        cmd = "ip %s route %s %s" % ("-6" if ipv6 else "", cmd, dest)
+        for ns in nhs:
+            cmd = cmd + (" \\\n   nexthop via %s" % ns)
+        exec_cmd(cmd)
+
+    def add_nhs_route(self, dest, nhs, ipv6):
+        self.route_cmd("add", dest, nhs, ipv6)
+
+    def del_nhs_route(self, dest, nhs, ipv6):
+        self.route_cmd("del", dest, nhs, ipv6)
+
     def set_netns(self, netns):
         self._netns = netns
         return
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index 47202d3..f0b3183 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -224,6 +224,22 @@ class SlaveMethods:
         dev.del_route(dest, ipv6)
         return True
 
+    def add_nhs_route(self, if_id, dest, nhs, ipv6):
+        dev = self._if_manager.get_mapped_device(if_id)
+        if dev is None:
+            logging.error("Device with id '%s' not found." % if_id)
+            return False
+        dev.add_nhs_route(dest, nhs, ipv6)
+        return True
+
+    def del_nhs_route(self, if_id, dest, nhs, ipv6):
+        dev = self._if_manager.get_mapped_device(if_id)
+        if dev is None:
+            logging.error("Device with id '%s' not found." % if_id)
+            return False
+        dev.del_nhs_route(dest, nhs, ipv6)
+        return True
+
     def set_device_up(self, if_id):
         dev = self._if_manager.get_mapped_device(if_id)
         dev.up()
-- 
2.4.3
_______________________________________________
LNST-developers mailing list
lnst-developers@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/lnst-developers@lists.fedorahosted.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic