This patch adds two new methods to our API - set_mtu and get_mtu. Names are self-explanatory,
the only drawback these methods have, is that setting MTU to a certain value is persistent
on non-virtual devices. Workaround for this is to store mtu values before the test run
and set them back after the test finished.
I will try to implement persistency toggling in the future.
Signed-off-by: Jiri Prochazka <jprochaz(a)redhat.com>
---
lnst/Controller/Machine.py | 6 ++++++
lnst/Controller/Task.py | 6 ++++++
lnst/Slave/NetTestSlave.py | 12 ++++++++++++
3 files changed, 24 insertions(+)
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index e303c1a..fd4f004 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -696,6 +696,12 @@ class Interface(object):
self._machine._rpc_call("deconfigure_interface", self.get_id())
self._configured = False
+ def set_mtu(self, mtu):
+ self._machine._rpc_call("set_mtu", self.get_id(), mtu)
+
+ def get_mtu(self):
+ return self._machine._rpc_call("get_mtu", self.get_id())
+
class StaticInterface(Interface):
""" Static interface
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py
index be6b5cc..ee0d468 100644
--- a/lnst/Controller/Task.py
+++ b/lnst/Controller/Task.py
@@ -346,6 +346,12 @@ class InterfaceAPI(object):
def get_ip_prefix(self, ip_index):
return VolatileValue(self._if.get_prefix, ip_index)
+ def set_mtu(self, mtu):
+ self._if.set_mtu(mtu)
+
+ def get_mtu(self):
+ return VolatileValue(self._if.get_mtu)
+
class ModuleAPI(object):
""" An API class representing a module. """
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index 8eb1f99..65601a8 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -609,6 +609,18 @@ class SlaveMethods:
device.set_netns(None)
return True
+ def set_mtu(self, if_id, mtu):
+ device = self._if_manager.get_mapped_device(if_id)
+ dev_name = device.get_name()
+ exec_cmd("ip link set dev %s mtu %s" % (dev_name, mtu))
+ return True
+
+ def get_mtu(self, if_id):
+ device = self._if_manager.get_mapped_device(if_id)
+ dev_name = device.get_name()
+ mtu, _ = exec_cmd("cat /sys/class/net/%s/mtu" % dev_name, log_outputs=False)
+ return mtu
+
class ServerHandler(ConnectionHandler):
def __init__(self, addr):
super(ServerHandler, self).__init__()
--
2.1.0