In order to test link negotiation it is useful to have methods that can
change the link state of an interface from a task.
Add the 'set_link_up' and 'set_link_down' methods for interfaces.
Unlike existing methods, these methods only change the link state and
nothing else (e.g. setting an address).
Changes in V2:
* Rename 'carrier_on' to 'link_up'
* Rename 'carrier_off' to 'link_down'
Signed-off-by: Ido Schimmel <idosch(a)mellanox.com>
Signed-off-by: Jiri Pirko <jiri(a)mellanox.com>
---
lnst/Controller/Machine.py | 14 ++++++++++++++
lnst/Controller/Task.py | 6 ++++++
lnst/Slave/InterfaceManager.py | 6 ++++++
lnst/Slave/NetTestSlave.py | 18 ++++++++++++++++++
4 files changed, 44 insertions(+)
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index e60e1ea..895397b 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -717,6 +717,20 @@ class Interface(object):
else:
self._machine._rpc_call("set_device_down", self._id)
+ def set_link_up(self):
+ netns = self._netns
+ if netns != None:
+ self._machine._rpc_call_to_netns(netns, "set_link_up", self._id)
+ else:
+ self._machine._rpc_call("set_link_up", self._id)
+
+ def set_link_down(self):
+ netns = self._netns
+ if netns != None:
+ self._machine._rpc_call_to_netns(netns, "set_link_down", self._id)
+ else:
+ self._machine._rpc_call("set_link_down", self._id)
+
def initialize(self):
phys_devs = self._machine._rpc_call("map_if_by_hwaddr",
self._id, self._hwaddr)
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py
index 0d437f3..44c328d 100644
--- a/lnst/Controller/Task.py
+++ b/lnst/Controller/Task.py
@@ -370,6 +370,12 @@ class InterfaceAPI(object):
def set_mtu(self, mtu):
return self._if.set_mtu(mtu)
+ def set_link_up(self):
+ return self._if.set_link_up()
+
+ def set_link_down(self):
+ return self._if.set_link_down()
+
class ModuleAPI(object):
""" An API class representing a module. """
diff --git a/lnst/Slave/InterfaceManager.py b/lnst/Slave/InterfaceManager.py
index 09f3be9..de3adba 100644
--- a/lnst/Slave/InterfaceManager.py
+++ b/lnst/Slave/InterfaceManager.py
@@ -486,6 +486,12 @@ class Device(object):
else:
exec_cmd("ip link set %s down" % self._name)
+ def link_up(self):
+ exec_cmd("ip link set %s up" % self._name)
+
+ def link_down(self):
+ exec_cmd("ip link set %s down" % self._name)
+
def set_netns(self, netns):
self._netns = netns
return
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index 775d4a5..b5d76b9 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -174,6 +174,24 @@ class SlaveMethods:
return False
return True
+ def set_link_up(self, if_id):
+ dev = self._if_manager.get_mapped_device(if_id)
+ if dev is not None:
+ dev.link_up()
+ else:
+ logging.error("Device with id '%s' not found." % if_id)
+ return False
+ return True
+
+ def set_link_down(self, if_id):
+ dev = self._if_manager.get_mapped_device(if_id)
+ if dev is not None:
+ dev.link_down()
+ else:
+ logging.error("Device with id '%s' not found." % if_id)
+ return False
+ return True
+
def set_unmapped_device_down(self, hwaddr):
dev = self._if_manager.get_device_by_hwaddr(hwaddr)
if dev is not None:
--
2.4.6