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

Add multiple process option for pfc_gen.py #14710

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
39 changes: 23 additions & 16 deletions tests/common/helpers/pfc_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def main():
usage = "usage: %prog [options] arg1 arg2"
parser = optparse.OptionParser(usage=usage)
parser.add_option("-i", "--interface", type="string", dest="interface",
help="Interface list to send packets, seperated by ','", metavar="Interface")
help="Interface list to send packets, separated by ','", metavar="Interface")
parser.add_option('-p', "--priority", type="int", dest="priority",
help="PFC class enable bitmap.", metavar="Priority", default=-1)
parser.add_option("-t", "--time", type="int", dest="time",
Expand All @@ -78,6 +78,8 @@ def main():
help="Send global pause frames (not PFC)", default=False)
parser.add_option("-s", "--send_pfc_frame_interval", type="float", dest="send_pfc_frame_interval",
help="Interval sending pfc frame", metavar="send_pfc_frame_interval", default=0)
parser.add_option("-m", "--multiprocess", action="store_true", dest="multiprocess",
help="Use multiple processes to send packets", default=False)

(options, args) = parser.parse_args()

Expand Down Expand Up @@ -175,21 +177,26 @@ def main():
logger.debug(pre_str + '_STORM_DEBUG')

# Start sending PFC pause frames
senders = []
interface_slices = [[] for i in range(MAX_PROCESS_NUM)]
for i in range(0, len(interfaces)):
interface_slices[i % MAX_PROCESS_NUM].append(interfaces[i])

for interface_slice in interface_slices:
if (interface_slice):
s = PacketSender(interface_slice, packet, options.num, options.send_pfc_frame_interval)
s.start()
senders.append(s)

logger.debug(pre_str + '_STORM_START')
# Wait PFC packets to be sent
for sender in senders:
sender.stop()
if options.multiprocess:
senders = []
interface_slices = [[] for i in range(MAX_PROCESS_NUM)]
for i in range(0, len(interfaces)):
interface_slices[i % MAX_PROCESS_NUM].append(interfaces[i])

for interface_slice in interface_slices:
if interface_slice:
s = PacketSender(interface_slice, packet, options.num, options.send_pfc_frame_interval)
s.start()
senders.append(s)

logger.debug(pre_str + '_STORM_START')
# Wait PFC packets to be sent
for sender in senders:
sender.stop()
else:
sender = PacketSender(interfaces, packet, options.num, options.send_pfc_frame_interval)
logger.debug(pre_str + '_STORM_START')
sender.send_packets()

logger.debug(pre_str + '_STORM_END')

Expand Down
3 changes: 3 additions & 0 deletions tests/common/helpers/pfc_storm.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(self, duthost, fanout_graph_facts, fanouthosts, **kwargs):
self.fanout_info = fanout_graph_facts
self.fanout_hosts = fanouthosts
self.pfc_gen_file = kwargs.pop('pfc_gen_file', "pfc_gen.py")
self.pfc_gen_multiprocess = kwargs.pop('pfc_gen_multiprocess', False)
self.pfc_queue_idx = kwargs.pop('pfc_queue_index', 3)
self.pfc_frames_number = kwargs.pop('pfc_frames_number', 100000)
self.send_pfc_frame_interval = kwargs.pop('send_pfc_frame_interval', 0)
Expand Down Expand Up @@ -183,6 +184,8 @@ def _update_template_args(self):
self.extra_vars.update({"pfc_asym": self.pfc_asym})
if self.fanout_asic_type == 'mellanox' and self.peer_device.os == 'sonic':
self.extra_vars.update({"pfc_fanout_label_port": self._generate_mellanox_label_ports()})
if self.dut.facts['asic_type'] == "mellanox":
self.extra_vars.update({"pfc_gen_multiprocess": True})

def _prepare_start_template(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/common/templates/pfc_storm_eos.j2
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
bash
cd /mnt/flash
{% if (pfc_asym is defined) and (pfc_asym == True) %}
{% if pfc_storm_defer_time is defined %} sleep {{pfc_storm_defer_time}} &&{% endif %} sudo python {{pfc_gen_file}} -p {{pfc_queue_index}} -t 65535 -n {{pfc_frames_number}} -i {{pfc_fanout_interface | replace("Ethernet", "et") | replace("/", "_")}} &
{% if pfc_storm_defer_time is defined %} sleep {{pfc_storm_defer_time}} &&{% endif %} sudo python {{pfc_gen_file}} {% if pfc_gen_multiprocess is defined %}-m {% endif %}-p {{pfc_queue_index}} -t 65535 -n {{pfc_frames_number}} -i {{pfc_fanout_interface | replace("Ethernet", "et") | replace("/", "_")}} &
{% else %}
{% if pfc_storm_defer_time is defined %} sleep {{pfc_storm_defer_time}} &&{% endif %} sudo python {{pfc_gen_file}} -p {{(1).__lshift__(pfc_queue_index)}} -t 65535 -n {{pfc_frames_number}} -i {{pfc_fanout_interface | replace("Ethernet", "et") | replace("/", "_")}} -r {{ansible_eth0_ipv4_addr}} &
{% if pfc_storm_defer_time is defined %} sleep {{pfc_storm_defer_time}} &&{% endif %} sudo python {{pfc_gen_file}} {% if pfc_gen_multiprocess is defined %}-m {% endif %}-p {{(1).__lshift__(pfc_queue_index)}} -t 65535 -n {{pfc_frames_number}} -i {{pfc_fanout_interface | replace("Ethernet", "et") | replace("/", "_")}} -r {{ansible_eth0_ipv4_addr}} &
{% endif %}
exit
exit
4 changes: 2 additions & 2 deletions tests/common/templates/pfc_storm_sonic.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cd {{pfc_gen_dir}}
{% if (pfc_asym is defined) and (pfc_asym == True) %}
nohup sh -c "{% if pfc_storm_defer_time is defined %}sleep {{pfc_storm_defer_time}} &&{% endif %} sudo python {{pfc_gen_file}} -p {{pfc_queue_index}} -t 65535 -n {{pfc_frames_number}} -i {{pfc_fanout_interface}}" > /dev/null 2>&1 &
nohup sh -c "{% if pfc_storm_defer_time is defined %}sleep {{pfc_storm_defer_time}} &&{% endif %} sudo python {{pfc_gen_file}} {% if pfc_gen_multiprocess is defined %}-m {% endif %}-p {{pfc_queue_index}} -t 65535 -n {{pfc_frames_number}} -i {{pfc_fanout_interface}}" > /dev/null 2>&1 &
{% else %}
nohup sh -c "{% if pfc_storm_defer_time is defined %}sleep {{pfc_storm_defer_time}} &&{% endif %} sudo python {{pfc_gen_file}} -p {{(1).__lshift__(pfc_queue_index)}} -t 65535 -n {{pfc_frames_number}} -i {{pfc_fanout_interface}} -r {{ansible_eth0_ipv4_addr}}" > /dev/null 2>&1 &
nohup sh -c "{% if pfc_storm_defer_time is defined %}sleep {{pfc_storm_defer_time}} &&{% endif %} sudo python {{pfc_gen_file}} {% if pfc_gen_multiprocess is defined %}-m {% endif %}-p {{(1).__lshift__(pfc_queue_index)}} -t 65535 -n {{pfc_frames_number}} -i {{pfc_fanout_interface}} -r {{ansible_eth0_ipv4_addr}}" > /dev/null 2>&1 &
{% endif %}
4 changes: 2 additions & 2 deletions tests/common/templates/pfc_storm_stop_eos.j2
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
bash
cd /mnt/flash
{% if (pfc_asym is defined) and (pfc_asym == True) %}
{% if pfc_storm_defer_time is defined %} sleep {{pfc_storm_defer_time}} &&{% endif %} sudo pkill -f "python {{pfc_gen_file}} -p {{pfc_queue_index}} -t 65535 -n {{pfc_frames_number}} -i {{pfc_fanout_interface | replace("Ethernet", "et") | replace("/", "_")}}" {{'&' if pfc_storm_stop_defer_time is defined else ''}}
{% if pfc_storm_defer_time is defined %} sleep {{pfc_storm_defer_time}} &&{% endif %} sudo pkill -f "python {{pfc_gen_file}} {% if pfc_gen_multiprocess is defined %}-m {% endif %}-p {{pfc_queue_index}} -t 65535 -n {{pfc_frames_number}} -i {{pfc_fanout_interface | replace("Ethernet", "et") | replace("/", "_")}}" {{'&' if pfc_storm_stop_defer_time is defined else ''}}
{% else %}
{% if pfc_storm_stop_defer_time is defined %} sleep {{pfc_storm_stop_defer_time}} &&{% endif %} sudo pkill -f "python {{pfc_gen_file}} -p {{(1).__lshift__(pfc_queue_index)}} -t 65535 -n {{pfc_frames_number}} -i {{pfc_fanout_interface | replace("Ethernet", "et") | replace("/", "_")}} -r {{ansible_eth0_ipv4_addr}}" {{'&' if pfc_storm_stop_defer_time is defined else ''}}
{% if pfc_storm_stop_defer_time is defined %} sleep {{pfc_storm_stop_defer_time}} &&{% endif %} sudo pkill -f "python {{pfc_gen_file}} {% if pfc_gen_multiprocess is defined %}-m {% endif %}-p {{(1).__lshift__(pfc_queue_index)}} -t 65535 -n {{pfc_frames_number}} -i {{pfc_fanout_interface | replace("Ethernet", "et") | replace("/", "_")}} -r {{ansible_eth0_ipv4_addr}}" {{'&' if pfc_storm_stop_defer_time is defined else ''}}
{% endif %}
exit
exit
4 changes: 2 additions & 2 deletions tests/common/templates/pfc_storm_stop_sonic.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cd {{pfc_gen_dir}}
{% if (pfc_asym is defined) and (pfc_asym == True) %}
nohup sh -c "{% if pfc_storm_stop_defer_time is defined %}sleep {{pfc_storm_stop_defer_time}} &&{% endif %} sudo pkill -f 'python {{pfc_gen_file}} -p {{pfc_queue_index}} -t 65535 -n {{pfc_frames_number}} -i {{pfc_fanout_interface}}'" > /dev/null 2>&1 &
nohup sh -c "{% if pfc_storm_stop_defer_time is defined %}sleep {{pfc_storm_stop_defer_time}} &&{% endif %} sudo pkill -f 'python {{pfc_gen_file}} {% if pfc_gen_multiprocess is defined %}-m {% endif %}-p {{pfc_queue_index}} -t 65535 -n {{pfc_frames_number}} -i {{pfc_fanout_interface}}'" > /dev/null 2>&1 &
{% else %}
nohup sh -c "{% if pfc_storm_stop_defer_time is defined %}sleep {{pfc_storm_stop_defer_time}} &&{% endif %} sudo pkill -f 'python {{pfc_gen_file}} -p {{(1).__lshift__(pfc_queue_index)}} -t 65535 -n {{pfc_frames_number}} -i {{pfc_fanout_interface}} -r {{ansible_eth0_ipv4_addr}}'" > /dev/null 2>&1 &
nohup sh -c "{% if pfc_storm_stop_defer_time is defined %}sleep {{pfc_storm_stop_defer_time}} &&{% endif %} sudo pkill -f 'python {{pfc_gen_file}} {% if pfc_gen_multiprocess is defined %}-m {% endif %}-p {{(1).__lshift__(pfc_queue_index)}} -t 65535 -n {{pfc_frames_number}} -i {{pfc_fanout_interface}} -r {{ansible_eth0_ipv4_addr}}'" > /dev/null 2>&1 &
{% endif %}
Loading