Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for ping flood and to get device_IPI names of network … #5689

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions avocado/utils/network/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
import json
import logging
import os
import re
import shutil
import subprocess
from ipaddress import IPv4Address, ip_interface

from avocado.utils import process
from avocado.utils.distro import detect as distro_detect
from avocado.utils.network.common import run_command
from avocado.utils.network.exceptions import NWException
Expand Down Expand Up @@ -781,3 +784,65 @@ def validate_ipv4_netmask_format(self, netmask):
return False
first_bit = False
return True

def ping_flood(self, int_name, peer_ip, ping_count):
"""
Function to start ping to remote machine with "-f" [ flood ] option,
on given interface.

Also this function enables to track the live data to determine the
ping flood failure, in case of failure the program will exit.

:param int_name: source interface name.
:param peer_ip: Peer IP address (IPv4 or IPv6)
:param ping_count: How many ICMP echo packets to send.
:return : returns True on successful ping flood.
returns False on ping flood failure.
:rtype : boolean
"""
cmd = f"ping -I {int_name} {peer_ip} -c {ping_count} -f "
FarooqAbdulla01 marked this conversation as resolved.
Show resolved Hide resolved
ping_process = subprocess.Popen(
cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
)
pattern = r"\.{10}"
while True:
char = ping_process.stdout.read(100)
match = re.search(pattern, char)
if match:
ping_process.terminate()
msg = "ping flood failed to remote machine, Please check the logs"
LOG.debug(msg)
return False
return True
ping_process.stdout.close()
ping_process.wait()

def get_device_IPI_name(self):
"""
Function to convert IO device name to device_ipi names according to
"/proc/interrupts" context.
Ex: vnic@30000009 to vnic-30000009

:return : A converted Network device according to device_ipi name.
:rtype : string
"""

if self.is_vnic():
cmd = (
f"cat /sys/class/net/{self.name}/device/devspec | "
f"awk -F/ '{{print $3}}'"
)
interface_type = process.run(cmd, shell=True, ignore_status=True).decode(
"utf-8"
)
cmd = f"echo {interface_type} | sed 's/@/-/' "
interface_type = process.system_output(
cmd, shell=True, ignore_status=True
).decode("utf-8")
return interface_type
elif self.is_veth():
return self.name
Loading