X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=nfvbench%2Ftraffic_gen%2Ftrex.py;h=7d64f0f2bf827233fbff3809407e237675d6309d;hb=b996e6a2f7094c9746138aa9776a5e98c93c9ad2;hp=e42afceaeaddb804d4b9733a4c0d091f7436a59e;hpb=f07e562c36549f45b643d730de3990b0f850bfe0;p=nfvbench.git diff --git a/nfvbench/traffic_gen/trex.py b/nfvbench/traffic_gen/trex.py index e42afce..7d64f0f 100644 --- a/nfvbench/traffic_gen/trex.py +++ b/nfvbench/traffic_gen/trex.py @@ -48,6 +48,8 @@ from trex_stl_lib.api import STLVmFlowVarRepetableRandom from trex_stl_lib.api import STLVmWrFlowVar from trex_stl_lib.api import UDP from trex_stl_lib.services.trex_stl_service_arp import STLServiceARP + + # pylint: enable=import-error @@ -64,6 +66,8 @@ class TRex(AbstractTrafficGenerator): self.streamblock = defaultdict(list) self.rates = [] self.arps = {} + self.capture_id = None + self.packet_list = [] def get_version(self): return self.client.get_server_version() @@ -136,14 +140,16 @@ class TRex(AbstractTrafficGenerator): return result def create_pkt(self, stream_cfg, l2frame_size): - # 46 = 14 (Ethernet II) + 4 (CRC Checksum) + 20 (IPv4) + 8 (UDP) - payload = 'x' * (max(64, int(l2frame_size)) - 46) pkt_base = Ether(src=stream_cfg['mac_src'], dst=stream_cfg['mac_dst']) - if stream_cfg['vlan_tag'] is not None: + # 50 = 14 (Ethernet II) + 4 (Vlan tag) + 4 (CRC Checksum) + 20 (IPv4) + 8 (UDP) pkt_base /= Dot1Q(vlan=stream_cfg['vlan_tag']) - + l2payload_size = int(l2frame_size) - 50 + else: + # 46 = 14 (Ethernet II) + 4 (CRC Checksum) + 20 (IPv4) + 8 (UDP) + l2payload_size = int(l2frame_size) - 46 + payload = 'x' * l2payload_size udp_args = {} if stream_cfg['udp_src_port']: udp_args['sport'] = int(stream_cfg['udp_src_port']) @@ -198,6 +204,8 @@ class TRex(AbstractTrafficGenerator): idx_lat = None streams = [] if l2frame == 'IMIX': + min_size = 64 if stream_cfg['vlan_tag'] is None else 68 + self.adjust_imix_min_size(min_size) for t, (ratio, l2_frame_size) in enumerate(zip(self.imix_ratios, self.imix_l2_sizes)): pkt = self.create_pkt(stream_cfg, l2_frame_size) streams.append(STLStream(packet=pkt, @@ -318,7 +326,7 @@ class TRex(AbstractTrafficGenerator): def __start_server(self): server = TRexTrafficServer() - server.run_server(self.config.generator_config) + server.run_server(self.config.generator_config, self.config.vlan_tagging) def resolve_arp(self): self.client.set_service_mode(ports=self.port_handle) @@ -450,6 +458,24 @@ class TRex(AbstractTrafficGenerator): def stop_traffic(self): self.client.stop(ports=self.port_handle) + def start_capture(self): + if self.capture_id: + self.stop_capture() + self.client.set_service_mode(ports=self.port_handle) + self.capture_id = self.client.start_capture(rx_ports=self.port_handle) + + def fetch_capture_packets(self): + if self.capture_id: + self.packet_list = [] + self.client.fetch_capture_packets(capture_id=self.capture_id['id'], + output=self.packet_list) + + def stop_capture(self): + if self.capture_id: + self.client.stop_capture(capture_id=self.capture_id['id']) + self.capture_id = None + self.client.set_service_mode(ports=self.port_handle, enabled=False) + def cleanup(self): if self.client: try: