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

[pfc] Refactor pfc pause test to use existing libs and code cleanup #2863

Merged
merged 4 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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: 42 additions & 23 deletions ansible/roles/test/files/ptftests/pfc_pause_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import datetime
import glob
import ipaddress
import logging
import os
import random
import socket
import sys
Expand All @@ -10,6 +13,7 @@
import ptf
import ptf.packet as scapy
import ptf.dataplane as dataplane
import scapy as sc

from ptf import config
from ptf.base_tests import BaseTest
Expand All @@ -31,7 +35,7 @@ def capture_matched_packets(test, exp_packet, port, device_number=0, timeout=1):
"""
if timeout <= 0:
raise Exception("%s() requires positive timeout value." % sys._getframe().f_code.co_name)

pkts = list()
while True:
result = dp_poll(test, device_number=device_number, port_number=port, timeout=timeout)
Expand All @@ -40,9 +44,9 @@ def capture_matched_packets(test, exp_packet, port, device_number=0, timeout=1):
pkts.append(result.packet)
else:
break
return pkts

return pkts

class PfcPauseTest(BaseTest):
def __init__(self):
BaseTest.__init__(self)
Expand All @@ -54,7 +58,7 @@ def setUp(self):
self.mac_src = self.test_params['mac_src']
self.mac_dst = self.test_params['mac_dst']
self.pkt_count = int(self.test_params['pkt_count'])
self.pkt_intvl = float(self.test_params['pkt_intvl'])
self.pkt_intvl = float(self.test_params['pkt_intvl'])
self.port_src = int(self.test_params['port_src'])
self.port_dst = self.test_params['port_dst']
self.ip_src = self.test_params['ip_src']
Expand All @@ -65,34 +69,42 @@ def setUp(self):
self.queue_paused = self.test_params['queue_paused']
""" if DUT has MAC information """
self.dut_has_mac = self.test_params['dut_has_mac']

self.debug = self.test_params.get('debug', False)

def runTest(self):
pass_cnt = 0
tos = self.dscp<<2
tos_bg = self.dscp_bg<<2

if self.debug:
# remove previous debug files
files = glob.glob("/tmp/pfc_pause_{}*".format(self.dscp))
for file in files:
os.remove(file)
current_time = datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
log_file = open("/tmp/pfc_pause_{}_{}".format(self.dscp, current_time), "w")

""" If DUT needs to learn MAC addresses """
if not self.dut_has_mac:
if not self.dut_has_mac:
pkt = simple_udp_packet(
eth_dst=self.mac_dst,
eth_src=self.mac_src,
ip_src=self.ip_src,
ip_dst=self.ip_dst)

send_packet(self, self.port_src, pkt, 5)

pkt = simple_udp_packet(
eth_dst=self.mac_src,
eth_src=self.mac_dst,
ip_src=self.ip_dst,
ip_dst=self.ip_src)

send_packet(self, self.port_dst, pkt, 5)

for x in range(self.pkt_count):
sport = random.randint(0, 65535)
dport = random.randint(0, 65535)

pkt = simple_udp_packet(
eth_dst=self.mac_dst,
eth_src=self.mac_src,
Expand All @@ -102,7 +114,7 @@ def runTest(self):
udp_sport=sport,
udp_dport=dport,
ip_ttl=64)

pkt_bg = simple_udp_packet(
eth_dst=self.mac_dst,
eth_src=self.mac_src,
Expand All @@ -112,38 +124,45 @@ def runTest(self):
udp_sport=sport,
udp_dport=dport,
ip_ttl=64)

exp_pkt = simple_udp_packet(
ip_src=self.ip_src,
ip_dst=self.ip_dst,
ip_tos=tos_bg,
udp_sport=sport,
udp_dport=dport,
ip_ttl=63)

masked_exp_pkt = Mask(exp_pkt)
masked_exp_pkt.set_do_not_care_scapy(scapy.Ether, "src")
masked_exp_pkt.set_do_not_care_scapy(scapy.Ether, "dst")
masked_exp_pkt.set_do_not_care_scapy(scapy.IP, "ttl")
masked_exp_pkt.set_do_not_care_scapy(scapy.IP, "chksum")
masked_exp_pkt.set_do_not_care_scapy(scapy.IP, "tos")

send_packet(self, self.port_src, pkt, 1)
send_packet(self, self.port_src, pkt_bg, 1)

pkts = capture_matched_packets(self, masked_exp_pkt, self.port_dst)


if self.debug:
for i, pkt in enumerate(pkts):
dump_msg = "Iteration {}:\n Pkt num {}:\n Hex dump: {}\n\n".format(x, i, sc.utils.hexstr(pkt))
log_file.write(dump_msg)

time.sleep(self.pkt_intvl)

""" If the queue is paused, we should only receive the background packet """
if self.queue_paused:
pass_cnt += int(len(pkts) == 1 and scapy.Ether(pkts[0])[scapy.IP].tos == tos_bg)

else:
pass_cnt += int(len(pkts) == 2)


if self.debug:
log_file.close()
print "Passes: %d / %d" % (pass_cnt, self.pkt_count)
def tearDown(self):

def tearDown(self):
reset_filters()
BaseTest.tearDown(self)
Loading