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@mellanox.com Signed-off-by: Jiri Pirko jiri@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:
The LinkNeg test module allows one to test the link negotiation of two interfaces. By changing the administrative state of one interface (using the new 'set_link_up' / 'set_link_down' interface methods) a change in the operational state of the corresponding interface should be observed. By performing this test multiple times hardware or firmware bugs may be detected.
Changes in V2: * Resolve mandatory parameters at the beginning of the test module * Add an optional parameter for watchdog timer * Rename 'CarrierWait' to 'LinkNeg'
Signed-off-by: Ido Schimmel idosch@mellanox.com Signed-off-by: Jiri Pirko jiri@mellanox.com --- setup.py | 3 ++- test_modules/LinkNeg.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 test_modules/LinkNeg.py
diff --git a/setup.py b/setup.py index 4033d4a..3057ba1 100755 --- a/setup.py +++ b/setup.py @@ -121,7 +121,8 @@ TEST_MODULES = [ "test_modules/Netperf.py", "test_modules/PacketAssert.py", "test_modules/PktCounter.py", - "test_modules/PktgenTx.py"] + "test_modules/PktgenTx.py", + "test_modules/LinkNeg.py"] ) ]
diff --git a/test_modules/LinkNeg.py b/test_modules/LinkNeg.py new file mode 100644 index 0000000..f7d3a16 --- /dev/null +++ b/test_modules/LinkNeg.py @@ -0,0 +1,42 @@ +""" +This module defines the link negotiation test +""" + +__author__ = """ +idosch@mellanox.com (Ido Schimmel) +""" + +import logging +from lnst.Common.TestsCommon import TestGeneric +from lnst.Common.Utils import bool_it +from pyroute2 import IPDB + + +class LinkNeg(TestGeneric): + def _cb(self, ipdb, msg, action): + if action == 'RTM_NEWLINK': + self.oper_state = msg.get_attr('IFLA_OPERSTATE', '') + + def run(self): + logging.info('Started LinkNeg...') + iface = self.get_mopt('iface') + state = bool_it(self.get_mopt('state')) + timeout = self.get_opt('timeout', default=10) + + ip = IPDB() + self.oper_state = ip.interfaces[iface]['operstate'] + wd = ip.watchdog(ifname=iface) + cuid = ip.register_callback(self._cb) + + wd.wait(timeout=timeout) + ip.unregister_callback(cuid) + ip.release() + + admin_state = 'UP' if state else 'DOWN' + oper_state = self.oper_state + res_data = {'admin_state': admin_state, 'oper_state': oper_state} + + if admin_state == oper_state: + self.set_pass(res_data) + else: + self.set_fail(res_data)
On Tue, Aug 25, 2015 at 11:05:23AM +0300, Ido Schimmel wrote:
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@mellanox.com Signed-off-by: Jiri Pirko jiri@mellanox.com
ack to both patches
Acked-by: Ondrej Lichtner olichtne@redhat.com
lnst-developers@lists.fedorahosted.org