capturing_traffic_generator - Base Capturing TG ABC

Traffic generator that can capture packets.

In functional testing, we need to interrogate received packets to check their validity. The module defines the interface common to all traffic generators capable of capturing traffic.

class PacketFilteringConfig

Bases: object

The supported filtering options for CapturingTrafficGenerator.

no_lldp

If True, LLDP packets will be filtered out when capturing.

Type:

bool

no_arp

If True, ARP packets will be filtered out when capturing.

Type:

bool

__init__(no_lldp: bool = True, no_arp: bool = True) None
class CapturingTrafficGenerator

Bases: TrafficGenerator

Capture packets after sending traffic.

The intermediary interface which enables a packet generator to declare that it can capture packets and return them to the user.

Similarly to TrafficGenerator, this class exposes the public methods specific to capturing traffic generators and defines a private method that must implement the traffic generation and capturing logic in subclasses.

The methods of capturing traffic generators obey the following workflow:

  1. send packets

  2. capture packets

  3. write the capture to a .pcap file

  4. return the received packets

property is_capturing: bool

This traffic generator can capture traffic.

send_packets_and_capture(packets: list[scapy.packet.Packet], send_port: Port, receive_port: Port, filter_config: PacketFilteringConfig, duration: float, capture_name: str = '13cab69c-eba3-426c-ad3b-2d6edc77c1bd') list[scapy.packet.Packet]

Send packets and capture received traffic.

Send packets on send_port and then return all traffic captured on receive_port for the given duration.

The captured traffic is recorded in the capture_name.pcap file. The target directory can be configured with the --output-dir command line argument or the DTS_OUTPUT_DIR environment variable.

Parameters:
  • packets (list[scapy.packet.Packet]) – The packets to send.

  • send_port (Port) – The egress port on the TG node.

  • receive_port (Port) – The ingress port in the TG node.

  • filter_config (PacketFilteringConfig) – Filters to apply when capturing packets.

  • duration (float) – Capture traffic for this amount of time after sending the packets.

  • capture_name (str) – The name of the .pcap file where to store the capture.

Returns:

The received packets. May be empty if no packets are captured.

Return type:

list[scapy.packet.Packet]