-
Notifications
You must be signed in to change notification settings - Fork 1k
[PFC] Test if PFC can pause lossless priorities #1386
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1ee604e
Add a PFC pause test
baiwei0427 3cb1b2d
Remove starlab info
baiwei0427 e5f19cb
Add function config_intf_ip_mac & Minor changes
baiwei0427 3380351
Refactor function interfaces
baiwei0427 1245ac8
Add a test case to see if all the priorities can forward packets in t…
baiwei0427 f1cf3eb
Avoid space between '=' & Specify import functions
baiwei0427 39cc71b
Refactor the code by moving testbed configuration to qos_helpers
baiwei0427 36b11a4
Let DUT learn MAC addresses before test
baiwei0427 54c23b7
Refactor PFC test code
baiwei0427 9677c68
Minor updates
baiwei0427 c5d50a0
Move setup_testbed function to qos_helpers
baiwei0427 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| import ipaddress | ||
| import logging | ||
| import random | ||
| import socket | ||
| import sys | ||
| import struct | ||
| import ipaddress | ||
| import re | ||
|
|
||
| import ptf | ||
| import ptf.packet as scapy | ||
| import ptf.dataplane as dataplane | ||
|
|
||
| from ptf import config | ||
| from ptf.base_tests import BaseTest | ||
| from ptf.mask import Mask | ||
| from ptf.testutils import add_filter, reset_filters, dp_poll, simple_udp_packet, send_packet, test_params_get | ||
|
|
||
| def udp_filter(pkt_str): | ||
| try: | ||
| pkt = scapy.Ether(pkt_str) | ||
| return scapy.UDP in pkt | ||
|
|
||
| except: | ||
| return False | ||
|
|
||
| def capture_matched_packets(test, exp_packet, port, device_number=0, timeout=1): | ||
| """ | ||
| Receive all packets on the port and return all the received packets. | ||
| As soon as the packets stop arriving, the function waits for the timeout value and returns the received packets. Therefore, this function requires a positive timeout value. | ||
| """ | ||
| 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) | ||
| if isinstance(result, test.dataplane.PollSuccess): | ||
| if ptf.dataplane.match_exp_pkt(exp_packet, result.packet): | ||
| pkts.append(result.packet) | ||
| else: | ||
| break | ||
|
|
||
| return pkts | ||
|
|
||
| class PfcPauseTest(BaseTest): | ||
| def __init__(self): | ||
| BaseTest.__init__(self) | ||
| self.test_params = test_params_get() | ||
|
|
||
| def setUp(self): | ||
| add_filter(udp_filter) | ||
| self.dataplane = ptf.dataplane_instance | ||
| 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.port_src = int(self.test_params['port_src']) | ||
| self.port_dst = self.test_params['port_dst'] | ||
| self.ip_src = self.test_params['ip_src'] | ||
| self.ip_dst = self.test_params['ip_dst'] | ||
| self.dscp = self.test_params['dscp'] | ||
| """ DSCP for background traffic """ | ||
| self.dscp_bg = self.test_params['dscp_bg'] | ||
| self.queue_paused = self.test_params['queue_paused'] | ||
| """ if DUT has MAC information """ | ||
| self.dut_has_mac = self.test_params['dut_has_mac'] | ||
|
|
||
| def runTest(self): | ||
| pass_cnt = 0 | ||
| tos = self.dscp<<2 | ||
| tos_bg = self.dscp_bg<<2 | ||
|
|
||
| """ If DUT needs to learn MAC addresses """ | ||
| 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, | ||
| ip_src=self.ip_src, | ||
| ip_dst=self.ip_dst, | ||
| ip_tos=tos, | ||
| udp_sport=sport, | ||
| udp_dport=dport, | ||
| ip_ttl=64) | ||
|
|
||
| pkt_bg = simple_udp_packet( | ||
| eth_dst=self.mac_dst, | ||
| eth_src=self.mac_src, | ||
| ip_src=self.ip_src, | ||
| ip_dst=self.ip_dst, | ||
| ip_tos=tos_bg, | ||
| 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) | ||
|
|
||
| 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) | ||
neethajohn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| print "Passes: %d / %d" % (pass_cnt, self.pkt_count) | ||
|
|
||
| def tearDown(self): | ||
| reset_filters() | ||
| BaseTest.tearDown(self) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.