def set_up_all(self): """ Run at the start of each test suite. Whitelist Prerequistites: Two Ports testpmd can normally started """ self.frames_to_send = 1 # Based on h/w type, choose how many ports to use self.dutPorts = self.dut.get_ports() # Verify that enough ports are available self.verify(len(self.dutPorts) >= 1, "Insufficient ports") portMask = dts.create_mask(self.dutPorts[:2]) self.pmdout = PmdOutput(self.dut) self.pmdout.start_testpmd("1S/2C/1T", "--portmask=%s" % portMask) self.dut.send_expect("set verbose 1", "testpmd> ") # get dest address from self.target port out = self.dut.send_expect("show port info %d" % self.dutPorts[0], "testpmd> ") self.dest = self.dut.get_mac_address(self.dutPorts[0]) mac_scanner = r"MAC address: (([\dA-F]{2}:){5}[\dA-F]{2})" ret = dts.regexp(out, mac_scanner) self.verify(ret is not None, "MAC address not found") self.verify(cmp(ret.lower(), self.dest) == 0, "MAC address wrong") self.max_mac_addr = dts.regexp( out, "Maximum number of MAC addresses: ([0-9]+)")
def test_timer_callbacks_verify(self): """ Timer callbacks running on targeted cores """ # get the mask for the first core cores = self.dut.get_core_list('1S/1C/1T') coreMask = dts.create_mask(cores) # run timer on the background cmdline = "./examples/timer/build/app/timer -n 1 -c " + coreMask + " &" self.dut.send_expect(cmdline, "# ", 1) time.sleep(15) out = self.dut.send_expect("killall timer", "# ", 5) # verify timer0 dts.regexp(out, r'timer0_cb\(\) on lcore (\d+)') pat = re.compile(r'timer0_cb\(\) on lcore (\d+)') match = pat.findall(out) self.verify(match or match[0] == 0, "timer0 error") # verify timer1 pat = re.compile(r'timer1_cb\(\) on lcore (\d+)') matchlist = sorted(pat.findall(out)) self.verify(cmp(list(set(matchlist)), cores) == 0, "timer1 error")
def set_up_all(self): """ Run at the start of each test suite. Whitelist Prerequistites: Two Ports testpmd can normally started """ self.frames_to_send = 1 # Based on h/w type, choose how many ports to use self.dutPorts = self.dut.get_ports() # Verify that enough ports are available self.verify(len(self.dutPorts) >= 1, "Insufficient ports") portMask = dts.create_mask(self.dutPorts[:2]) self.pmdout = PmdOutput(self.dut) self.pmdout.start_testpmd("1S/2C/1T", "--portmask=%s" % portMask) self.dut.send_expect("set verbose 1", "testpmd> ") # get dest address from self.target port out = self.dut.send_expect("show port info %d" % self.dutPorts[0], "testpmd> ") self.dest = self.dut.get_mac_address(self.dutPorts[0]) mac_scanner = r"MAC address: (([\dA-F]{2}:){5}[\dA-F]{2})" ret = dts.regexp(out, mac_scanner) self.verify(ret is not None, "MAC address not found") self.verify(cmp(ret.lower(), self.dest) == 0, "MAC address wrong") self.max_mac_addr = dts.regexp(out, "Maximum number of MAC addresses: ([0-9]+)")
def test_whitelist_add_remove_mac_address(self): """ Add mac address and check packet can received Remove mac address and check packet can't received """ # initialise first port without promiscuous mode fake_mac_addr = "01:01:01:00:00:00" portid = self.dutPorts[0] self.dut.send_expect("set promisc %d off" % portid, "testpmd> ") out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") pre_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # send one packet with the portid MAC address self.whitelist_send_packet(portid, self.dest) out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") cur_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # check the packet increase self.verify(int(cur_rxpkt) == int(pre_rxpkt) + self.frames_to_send, "Packet has not been received on default address") # send one packet to a different MAC address # new_mac = self.dut.get_mac_address(portid) self.whitelist_send_packet(portid, fake_mac_addr) pre_rxpkt = cur_rxpkt out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") cur_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # check the packet DO NOT increase self.verify(int(cur_rxpkt) == int(pre_rxpkt), "Packet has been received on a new MAC address that has not been added yet") # add the different MAC address out = self.dut.send_expect("mac_addr add %d" % portid + " %s" % fake_mac_addr, "testpmd>") # send again one packet to a different MAC address self.whitelist_send_packet(portid, fake_mac_addr) pre_rxpkt = cur_rxpkt out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") cur_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # check the packet increase self.verify(int(cur_rxpkt) == int(pre_rxpkt) + self.frames_to_send, "Packet has not been received on a new MAC address that has been added to the port") # remove the fake MAC address out = self.dut.send_expect("mac_addr remove %d" % portid + " %s" % fake_mac_addr, "testpmd>") # send again one packet to a different MAC address self.whitelist_send_packet(portid, fake_mac_addr) pre_rxpkt = cur_rxpkt out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") cur_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # check the packet increase self.verify(int(cur_rxpkt) == int(pre_rxpkt), "Packet has been received on a new MAC address that has been removed from the port") self.dut.send_expect("stop", "testpmd> ")
def test_ieee1588_enable(self): """ IEEE1588 Enable test case. """ self.dut.send_expect("set fwd ieee1588", "testpmd> ") self.dut.send_expect( "start", ">", 5 ) # Waiting for 'testpmd> ' Fails due to log messages, "Received non PTP packet", in the output time.sleep( 1 ) # Allow the output from the "start" command to finish before looking for a regexp in expect # use the first port on that self.nic dutPorts = self.dut.get_ports() port = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(port) self.tester.scapy_background() self.tester.scapy_append('p = sniff(iface="%s", count=2)' % itf) self.tester.scapy_append('RESULT = p[1].summary()') # this is the output of sniff # [<Ether dst=01:1b:19:00:00:00 src=00:00:00:00:00:00 type=0x88f7 |<Raw load='\x00\x02' |>>] self.tester.scapy_foreground() self.tester.scapy_append('nutmac="01:1b:19:00:00:00"') self.tester.scapy_append( 'sendp([Ether(dst=nutmac,type=0x88f7)/"\\x00\\x02"], iface="%s")' % itf) self.tester.scapy_append('time.sleep(1)') self.tester.scapy_execute() out = self.tester.scapy_get_result() self.verify("0x88f7" in out, "Ether type is not PTP") # self.verify("\\x00\\x02" in out, "Payload wrong in PTP") time.sleep(1) out = self.dut.send_expect("stop", "testpmd> ") text = dts.regexp(out, "(.*) by hardware") self.verify("IEEE1588 PTP V2 SYNC" in text, "Not filtered " + text) rx_time = dts.regexp(out, "RX timestamp value (0x[0-9a-fA-F]+)") tx_time = dts.regexp(out, "TX timestamp value (0x[0-9a-fA-F]+)") self.verify(rx_time is not None, "RX timestamp error ") self.verify(tx_time is not None, "TX timestamp error ") self.verify(int(tx_time, 16) > int(rx_time, 16), "Timestamp mismatch")
def check_blacklisted_ports(self, output, ports, blacklisted=False): """ Check if any of the ports in `ports` have been blacklisted, if so, raise exception. If `blacklisted` is True, then raise an exception if any of the ports in `ports` have not been blacklisted. """ for port in ports: # Look for the PCI ID of each card followed by # "Device is blacklisted, not initializing" but avoid to consume more # than one device. if self.env == 'bsdapp': pci = self.dut.ports_info[port]['pci'] regexp_blacklisted_port = self.regexp_blacklisted_port % (int(pci.split(':')[0], 16), pci.split(':')[1]) else: regexp_blacklisted_port = self.regexp_blacklisted_port % self.dut.ports_info[port]['pci'] matching_ports = dts.regexp(output, regexp_blacklisted_port, True) if blacklisted: self.verify(len(matching_ports) == 1, "Blacklisted port is being initialized") else: self.verify(len(matching_ports) == 0, "Not blacklisted port is being blacklisted")
def test_bl_noblacklisted(self): """ Run testpmd with no blacklisted device. """ out = self.pmdout.start_testpmd("all") rexp = r"Link" match_status = dts.regexp(out, rexp, True) self.check_blacklisted_ports(out, self.ports)
def test_bl_noblacklisted(self): """ Run testpmd with no blacklisted device. """ out = self.pmdout.start_testpmd("Default") rexp = r"Link" match_status = dts.regexp(out, rexp, True) self.check_blacklisted_ports(out, self.ports)
def test_ieee1588_enable(self): """ IEEE1588 Enable test case. """ self.dut.send_expect("set fwd ieee1588", "testpmd> ") self.dut.send_expect("start", ">", 5) # Waiting for 'testpmd> ' Fails due to log messages, "Received non PTP packet", in the output time.sleep(1) # Allow the output from the "start" command to finish before looking for a regexp in expect # use the first port on that self.nic dutPorts = self.dut.get_ports() port = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(port) self.tester.scapy_background() self.tester.scapy_append('p = sniff(iface="%s", count=2)' % itf) self.tester.scapy_append('RESULT = p[1].summary()') # this is the output of sniff # [<Ether dst=01:1b:19:00:00:00 src=00:00:00:00:00:00 type=0x88f7 |<Raw load='\x00\x02' |>>] self.tester.scapy_foreground() self.tester.scapy_append('nutmac="01:1b:19:00:00:00"') self.tester.scapy_append('sendp([Ether(dst=nutmac,type=0x88f7)/"\\x00\\x02"], iface="%s")' % itf) self.tester.scapy_append('time.sleep(1)') self.tester.scapy_execute() out = self.tester.scapy_get_result() self.verify("0x88f7" in out, "Ether type is not PTP") # self.verify("\\x00\\x02" in out, "Payload wrong in PTP") time.sleep(1) out = self.dut.send_expect("stop", "testpmd> ") text = dts.regexp(out, "(.*) by hardware") self.verify("IEEE1588 PTP V2 SYNC" in text, "Not filtered " + text) rx_time = dts.regexp(out, "RX timestamp value (0x[0-9a-fA-F]+)") tx_time = dts.regexp(out, "TX timestamp value (0x[0-9a-fA-F]+)") self.verify(rx_time is not None, "RX timestamp error ") self.verify(tx_time is not None, "TX timestamp error ") self.verify(int(tx_time, 16) > int(rx_time, 16), "Timestamp mismatch")
def test_whitelist_add_remove_mac_address(self): """ Add mac address and check packet can received Remove mac address and check packet can't received """ # initialise first port without promiscuous mode fake_mac_addr = "01:01:01:00:00:00" portid = self.dutPorts[0] self.dut.send_expect("set promisc %d off" % portid, "testpmd> ") out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") pre_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # send one packet with the portid MAC address self.whitelist_send_packet(portid, self.dest) out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") cur_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # check the packet increase self.verify( int(cur_rxpkt) == int(pre_rxpkt) + self.frames_to_send, "Packet has not been received on default address") # send one packet to a different MAC address # new_mac = self.dut.get_mac_address(portid) self.whitelist_send_packet(portid, fake_mac_addr) pre_rxpkt = cur_rxpkt out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") cur_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # check the packet DO NOT increase self.verify( int(cur_rxpkt) == int(pre_rxpkt), "Packet has been received on a new MAC address that has not been added yet" ) # add the different MAC address out = self.dut.send_expect( "mac_addr add %d" % portid + " %s" % fake_mac_addr, "testpmd>") # send again one packet to a different MAC address self.whitelist_send_packet(portid, fake_mac_addr) pre_rxpkt = cur_rxpkt out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") cur_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # check the packet increase self.verify( int(cur_rxpkt) == int(pre_rxpkt) + self.frames_to_send, "Packet has not been received on a new MAC address that has been added to the port" ) # remove the fake MAC address out = self.dut.send_expect( "mac_addr remove %d" % portid + " %s" % fake_mac_addr, "testpmd>") # send again one packet to a different MAC address self.whitelist_send_packet(portid, fake_mac_addr) pre_rxpkt = cur_rxpkt out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") cur_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # check the packet increase self.verify( int(cur_rxpkt) == int(pre_rxpkt), "Packet has been received on a new MAC address that has been removed from the port" ) self.dut.send_expect("stop", "testpmd> ")