Skip to content

Commit

Permalink
Merge pull request #2679 from abdhaleegit/iperf-mac
Browse files Browse the repository at this point in the history
io/net: add support for mac id as input
  • Loading branch information
PraveenPenguin authored Aug 30, 2023
2 parents d401e72 + e332586 commit 43b8258
Show file tree
Hide file tree
Showing 16 changed files with 173 additions and 132 deletions.
27 changes: 17 additions & 10 deletions io/net/Network_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# network configuration includes speed,
# driver name, businfo, hardware address

import os
import netifaces
from avocado import Test
from avocado.utils.software_manager.manager import SoftwareManager
Expand All @@ -37,17 +38,22 @@ def setUp(self):
'''
To check and install dependencies for the test
'''
local = LocalHost()
interfaces = os.listdir('/sys/class/net')
sm = SoftwareManager()
for pkg in ["ethtool", "net-tools"]:
if not sm.check_installed(pkg) and not sm.install(pkg):
self.cancel("%s package is need to test" % pkg)
interfaces = netifaces.interfaces()
self.iface = self.params.get("interface")
if self.iface not in interfaces:
self.cancel("%s interface is not available" % self.iface)
device = self.params.get("interface", default=None)
if device in interfaces:
self.iface = device
elif local.validate_mac_addr(device) and device in local.get_all_hwaddr():
self.iface = local.get_interface_by_hwaddr(device).name
else:
self.iface = None
self.cancel("%s interface is not available" % device)
self.ipaddr = self.params.get("host_ip", default="")
self.netmask = self.params.get("netmask", default="")
local = LocalHost()
self.networkinterface = NetworkInterface(self.iface, local)
try:
self.networkinterface.add_ipaddr(self.ipaddr, self.netmask)
Expand Down Expand Up @@ -162,8 +168,9 @@ def tearDown(self):
'''
unset ip for host interface
'''
self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask)
try:
self.networkinterface.restore_from_backup()
except Exception:
self.log.info("backup file not availbale, could not restore file.")
if self.iface:
self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask)
try:
self.networkinterface.restore_from_backup()
except Exception:
self.log.info("backup file not availbale, could not restore file.")
2 changes: 1 addition & 1 deletion io/net/Network_config.py.data/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This Program to check network configuration details like speed, driver name, bu
-----------------------------
Inputs Needed To Run Tests:
-----------------------------
interface --> host interface to perform test
interface --> test interface name eth2 or mac addr 02:5d:c7:xx:xx:03
host-IP --> Specify host-IP for ip configuration.
netmask --> specify netmask for ip configuration.
-----------------------
Expand Down
63 changes: 34 additions & 29 deletions io/net/iperf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"""

import os
import netifaces
from avocado import Test
from avocado.utils.software_manager.manager import SoftwareManager
from avocado.utils import build
Expand All @@ -43,19 +42,24 @@ def setUp(self):
"""
To check and install dependencies for the test
"""
localhost = LocalHost()
self.peer_user = self.params.get("peer_user", default="root")
self.peer_ip = self.params.get("peer_ip", default="")
self.peer_public_ip = self.params.get("peer_public_ip", default="")
self.peer_password = self.params.get("peer_password", '*',
default=None)
interfaces = netifaces.interfaces()
self.iface = self.params.get("interface", default="")
if self.iface not in interfaces:
self.cancel("%s interface is not available" % self.iface)
interfaces = os.listdir('/sys/class/net')
device = self.params.get("interface", default="")
if device in interfaces:
self.iface = device
elif localhost.validate_mac_addr(device) and device in localhost.get_all_hwaddr():
self.iface = localhost.get_interface_by_hwaddr(device).name
else:
self.iface = None
self.cancel("%s interface is not available" % device)
self.ipaddr = self.params.get("host_ip", default="")
self.netmask = self.params.get("netmask", default="")
self.hbond = self.params.get("hbond", default=False)
localhost = LocalHost()
if self.hbond:
self.networkinterface = NetworkInterface(self.iface, localhost,
if_type='Bond')
Expand Down Expand Up @@ -217,26 +221,27 @@ def tearDown(self):
"""
Killing Iperf process in peer machine
"""
cmd = "pkill iperf; rm -rf /tmp/%s" % self.version
output = self.session.cmd(cmd)
if not output.exit_status == 0:
self.fail("Either the ssh to peer machine machine\
failed or iperf process was not killed")
self.obj.stop()
if self.networkinterface.set_mtu('1500') is not None:
self.cancel("Failed to set mtu in host")
try:
self.peer_networkinterface.set_mtu('1500')
except Exception:
self.peer_public_networkinterface.set_mtu('1500')
self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask)
try:
self.networkinterface.restore_from_backup()
except Exception:
self.networkinterface.remove_cfg_file()
self.log.info("backup file not availbale, could not restore file.")
if self.hbond:
self.networkinterface.restore_slave_cfg_file()
self.remotehost.remote_session.quit()
self.remotehost_public.remote_session.quit()
self.session.quit()
if self.iface:
cmd = "pkill iperf; rm -rf /tmp/%s" % self.version
output = self.session.cmd(cmd)
if not output.exit_status == 0:
self.fail("Either the ssh to peer machine machine\
failed or iperf process was not killed")
self.obj.stop()
if self.networkinterface.set_mtu('1500') is not None:
self.cancel("Failed to set mtu in host")
try:
self.peer_networkinterface.set_mtu('1500')
except Exception:
self.peer_public_networkinterface.set_mtu('1500')
self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask)
try:
self.networkinterface.restore_from_backup()
except Exception:
self.networkinterface.remove_cfg_file()
self.log.info("backup file not availbale, could not restore file.")
if self.hbond:
self.networkinterface.restore_slave_cfg_file()
self.remotehost.remote_session.quit()
self.remotehost_public.remote_session.quit()
self.session.quit()
2 changes: 1 addition & 1 deletion io/net/iperf_test.py.data/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ bandwidth on IP networks.

Inputs Needed To Run Tests:
---------------------------
interface - interface on which test run
interface - interface name eth1 or interface mac 02:5d:xx:xx:0x:00
peer_ip - IP of the Peer interface to be tested
peer_user - Username in Peer system to be used
IPERF_SERVER_RUN - Whether to run iperf server in peer or not (1 to run, 0 to not run)
Expand Down
60 changes: 33 additions & 27 deletions io/net/multicast.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# then ping from peer to multicast group


import netifaces
import os
from avocado import Test
from avocado.utils.software_manager.manager import SoftwareManager
from avocado.utils.ssh import Session
Expand All @@ -39,18 +39,23 @@ def setUp(self):
'''
To check and install dependencies for the test
'''
local = LocalHost()
interfaces = os.listdir('/sys/class/net')
self.peer = self.params.get("peer_ip", default="")
self.user = self.params.get("user_name", default="root")
self.peer_password = self.params.get("peer_password",
'*', default="None")
interfaces = netifaces.interfaces()
self.iface = self.params.get("interface", default="")
if self.iface not in interfaces:
self.cancel("%s interface is not available" % self.iface)
device = self.params.get("interface", default=None)
if device in interfaces:
self.iface = device
elif local.validate_mac_addr(device) and device in local.get_all_hwaddr():
self.iface = local.get_interface_by_hwaddr(device).name
else:
self.iface = None
self.cancel("%s interface is not available" % device)
self.ipaddr = self.params.get("host_ip", default="")
self.netmask = self.params.get("netmask", default="")
self.hbond = self.params.get("hbond", default=False)
local = LocalHost()
if self.hbond:
self.networkinterface = NetworkInterface(self.iface, local,
if_type='Bond')
Expand Down Expand Up @@ -121,24 +126,25 @@ def tearDown(self):
'''
delete multicast route and turn off multicast option
'''
cmd = "ip route del 224.0.0.0/4"
output = self.session.cmd(cmd)
if not output.exit_status == 0:
self.log.info("Unable to delete multicast route added for peer")
cmd = "echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts"
if process.system(cmd, shell=True, verbose=True,
ignore_status=True) != 0:
self.log.info("unable to unset all mulicast option")
cmd = "ip link set %s allmulticast off" % self.iface
if process.system(cmd, shell=True, verbose=True,
ignore_status=True) != 0:
self.log.info("unable to unset all mulicast option")
self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask)
try:
self.networkinterface.restore_from_backup()
except Exception:
self.networkinterface.remove_cfg_file()
self.log.info("backup file not availbale, could not restore file.")
if self.hbond:
self.networkinterface.restore_slave_cfg_file()
self.session.quit()
if self.iface:
cmd = "ip route del 224.0.0.0/4"
output = self.session.cmd(cmd)
if not output.exit_status == 0:
self.log.info("Unable to delete multicast route added for peer")
cmd = "echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts"
if process.system(cmd, shell=True, verbose=True,
ignore_status=True) != 0:
self.log.info("unable to unset all mulicast option")
cmd = "ip link set %s allmulticast off" % self.iface
if process.system(cmd, shell=True, verbose=True,
ignore_status=True) != 0:
self.log.info("unable to unset all mulicast option")
self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask)
try:
self.networkinterface.restore_from_backup()
except Exception:
self.networkinterface.remove_cfg_file()
self.log.info("backup file not availbale, could not restore file.")
if self.hbond:
self.networkinterface.restore_slave_cfg_file()
self.session.quit()
2 changes: 1 addition & 1 deletion io/net/multicast.py.data/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Inputs Needed To Run Tests:
-----------------------------
peerip ---> IP of the Peer interface to be tested
user_name---> name of the user
interface --> host interface through which we get host_ip
interface --> host test interface name eth1 or mac address 02:5d:xx:xx:xx:xx
host-IP ---> Specify host-IP for ip configuration.
netmask ---> specify netmask for ip configuration.
-----------------------
Expand Down
53 changes: 29 additions & 24 deletions io/net/netperf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@


import os
import netifaces
from avocado import Test
from avocado.utils.software_manager.manager import SoftwareManager
from avocado.utils import distro
Expand All @@ -45,18 +44,23 @@ def setUp(self):
"""
To check and install dependencies for the test
"""
local = LocalHost()
interfaces = os.listdir('/sys/class/net')
self.peer_user = self.params.get("peer_user", default="root")
self.peer_public_ip = self.params.get("peer_public_ip", default="")
self.peer_ip = self.params.get("peer_ip", default="")
self.peer_password = self.params.get("peer_password", '*',
default="None")
interfaces = netifaces.interfaces()
self.iface = self.params.get("interface", default="")
if self.iface not in interfaces:
self.cancel("%s interface is not available" % self.iface)
device = self.params.get("interface", default=None)
if device in interfaces:
self.iface = device
elif local.validate_mac_addr(device) and device in local.get_all_hwaddr():
self.iface = local.get_interface_by_hwaddr(device).name
else:
self.iface = None
self.cancel("%s interface is not available" % device)
self.ipaddr = self.params.get("host_ip", default="")
self.netmask = self.params.get("netmask", default="")
local = LocalHost()
self.networkinterface = NetworkInterface(self.iface, local)
try:
self.networkinterface.add_ipaddr(self.ipaddr, self.netmask)
Expand Down Expand Up @@ -185,21 +189,22 @@ def tearDown(self):
"""
removing the data in peer machine
"""
cmd = "pkill netserver; rm -rf /tmp/%s" % self.version
output = self.session.cmd(cmd)
if not output.exit_status == 0:
self.fail("test failed because peer sys not connected")
if self.networkinterface.set_mtu('1500') is not None:
self.cancel("Failed to set mtu in host")
try:
self.peer_networkinterface.set_mtu('1500')
except Exception:
self.peer_public_networkinterface.set_mtu('1500')
self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask)
try:
self.networkinterface.restore_from_backup()
except Exception:
self.log.info("backup file not availbale, could not restore file.")
self.remotehost.remote_session.quit()
self.remotehost_public.remote_session.quit()
self.session.quit()
if self.iface:
cmd = "pkill netserver; rm -rf /tmp/%s" % self.version
output = self.session.cmd(cmd)
if not output.exit_status == 0:
self.fail("test failed because peer sys not connected")
if self.networkinterface.set_mtu('1500') is not None:
self.cancel("Failed to set mtu in host")
try:
self.peer_networkinterface.set_mtu('1500')
except Exception:
self.peer_public_networkinterface.set_mtu('1500')
self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask)
try:
self.networkinterface.restore_from_backup()
except Exception:
self.log.info("backup file not availbale, could not restore file.")
self.remotehost.remote_session.quit()
self.remotehost_public.remote_session.quit()
self.session.quit()
1 change: 1 addition & 0 deletions io/net/netperf_test.py.data/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ unidirectional throughput, and end-to-end latency.

Inputs Needed To Run Tests:
-----------------------------
interface - test interface name eth2 or mac addr 02:5d:c7:xx:xx:03
PEERIP - IP of the Peer interface to be tested
PEERUSER - Username in Peer system to be used
Iface - interface on which test run
Expand Down
19 changes: 10 additions & 9 deletions io/net/switch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
test lro and gro and interface
"""

import os
import time
import paramiko
import netifaces
from avocado import Test
from avocado.utils.network.interfaces import NetworkInterface
from avocado.utils.network.hosts import LocalHost
Expand All @@ -36,17 +36,18 @@ def setUp(self):
'''
To get all the parameter for the test
'''
interfaces = netifaces.interfaces()
interface = self.params.get("interface")
local = LocalHost()
self.networkinterface = None
if not interface:
self.cancel("Please specify interface to be used")
if interface not in interfaces:
self.cancel("%s interface is not available" % interface)
self.iface = interface
interfaces = os.listdir('/sys/class/net')
device = self.params.get("interface", default=None)
if device in interfaces:
self.iface = device
elif local.validate_mac_addr(device) and device in local.get_all_hwaddr():
self.iface = local.get_interface_by_hwaddr(device).name
else:
self.cancel("%s interface is not available" % device)
self.ipaddr = self.params.get("host_ip", default="")
self.netmask = self.params.get("netmask", default="")
local = LocalHost()
self.networkinterface = NetworkInterface(self.iface, local)
try:
self.networkinterface.add_ipaddr(self.ipaddr, self.netmask)
Expand Down
2 changes: 1 addition & 1 deletion io/net/switch_test.py.data/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This Program to test switch port enable.
-----------------------------
Inputs Needed To Run Tests:
-----------------------------
interface --> host interface to perform test.
interface --> host interface name eth3 or mac addr 02:5d:c7:xx:xx:03
peer_ip --> peer interface to perform test.
host-IP --> Specify host-IP for ip configuration.
netmask --> specify netmask for ip configuration.
Expand Down
Loading

0 comments on commit 43b8258

Please sign in to comment.