class TrexTest(BaseTest): """ Base test for setting up and tearing down TRex client instance for linerate tests. """ def setUp(self): super(TrexTest, self).setUp() trex_server_addr = testutils.test_param_get("trex_server_addr") self.trex_client = STLClient(server=trex_server_addr) self.trex_client.connect() self.trex_client.acquire() self.trex_client.reset() # Resets configs from all ports self.trex_client.clear_stats() # Clear status from all ports # Put all ports to promiscuous mode, otherwise they will drop all # incoming packets if the destination mac is not the port mac address. self.trex_client.set_port_attr(self.trex_client.get_all_ports(), promiscuous=True) def tearDown(self): print("Tearing down STLClient...") self.trex_client.stop() self.trex_client.release() self.trex_client.disconnect() super(TrexTest, self).tearDown()
try: udp_payload = "A" * 50 pkt = STLPktBuilder( pkt=Ether() / IP(src="192.168.17.1", dst="192.168.17.2") / UDP(dport=8888, sport=9999, chksum=0) / udp_payload) st = STLStream( name="udp_single_burst", packet=pkt, # Packet group id flow_stats=STLFlowLatencyStats(pg_id=PG_ID), mode=STLTXSingleBurst(total_pkts=TOTAL_PKTS, pps=PPS), ) clt.connect() all_ports = clt.get_all_ports() print("All ports: {}".format(",".join(map(str, all_ports)))) tx_port, rx_port = all_ports print(f"TX port: {tx_port}, RX port: {rx_port}") tx_port_attr = clt.get_port_attr(tx_port) rx_port_attr = clt.get_port_attr(rx_port) assert tx_port_attr["src_ipv4"] == "192.168.17.1" assert rx_port_attr["src_ipv4"] == "192.168.18.1" clt.reset(ports=all_ports) clt.add_streams([st], ports=[tx_port]) print(f"Inject {TOTAL_PKTS} packets on port {all_ports[0]}") ret = rx_interation(clt, tx_port, rx_port, TOTAL_PKTS, pkt.get_pkt_len()) if not ret: passed = False