VPP interface traffic capturing
You can use the MEMCAP plugin for traffic capturing.
MEMCAP is a framework that defines and implements a protocol for offloading the traffic capturing process using the memory-mapped interface. This approach reduces the operational overhead on the capturing component. Captured data is subsequently collected and processed by the MEMCAP Sink sub-component. By delegating resource-intensive tasks, such as I/O processing and system upgrades, to separate components, MEMCAP reduces resource requirements and improves scalability.
The Fast Path Provider (FPP) pod acts as a traffic collector and communicates with the MEMCAP Sink pod using a shared memory interface. Multiple FPP-based instances, such as FPP, Connectivity Gateway (CGW) or User Plane Gateway (UPG), located on a single node communicate with a single MEMCAP Sink pod located on the same node.
MEMCAP allows for collecting PCAP files in a single place using NATSOpens in a new tab to aggregate traffic streams. You can configure the MEMCAP Sink component to send formatted PCAP data to the NATS server, either in publisher-subscriber (NATS CoreOpens in a new tab) mode or in the JetStreamOpens in a new tab mode. The MEMCAP Consumer component retrieves these PCAPs from the NATS server and merges traffic streams into one PCAP file. It can run in the same cluster or a central cluster to gather traffic from multiple Core Clusters. This setup provides a single access point for all PCAPs.
Terminology
Here's the terminology used within this document:
- Collector - FPP pod which provides capture streams. It can provide multiple PCAP streams in parallel.
- Sink - a component that receives data from collectors, processes it, and either saves it as a local
.pcapngfile or sends it as a NATS message. - Consumer - a component that connects to the NATS server, converts PCAP data from NATS messages into a
.pcapngfile, and provides an HTTP stream for traffic. - Class - a traffic class which allows for different processing in MEMCAP Sink. For example,
hw_iface_l2is a VPP interface-based L2 traffic capturing, andupf_session_ipis a UPG IMSI-based IP traffic capturing. - Target - an arbitrary name used to direct traffic capture streams to destinations. On the collector side, different traffic capture streams can use the same target name. On the MEMCAP Sink side, different destinations can use the same target name as well. Target names can be chosen arbitrarily and do not require provisioning in advance.
- Stream - an instance of active traffic capture. For example, a stream of interface
eth0to targeteth-ifwith classhw_iface_l2. - Destination - the endpoint for a PCAP stream, which can be a file, an HTTP stream, or a NATS cluster.
MEMCAP consists of the following sub-components:
-
VPP MEMCAP plugin implements the collector side of the MEMCAP connection. It implements the
hw_iface_l2collector, which allows you to collect traffic from L2 VPP interfaces. It also provides a framework for easy integration with other VPP plugins. -
MEMCAP Sink manages connections to collectors and processes the captured traffic data. It outputs the data in the
.pcapngfile format, which you can send over NATS or save to a disk with options for compression and rotation. Additionally, it allows streaming of.pcapngfiles over an HTTP connection for real-time analysis. -
MEMCAP Consumer connects to the NATS server, listens for PCAP data sent as NATS message payload, and combines traffic from multiple MEMCAP Sinks into a single
.pcapngfile. It provides a single access point for users to view aggregated data from one or more Core Clusters. It also offers an HTTP endpoint for real-time analysis.
This is a sample operational workflow:
A packet stream is generated inside a VPP instance (FPP node, CGW, or UPG) and identified by its target name (tag). The MEMCAP Sink aggregates traffic from multiple streams based on their target names (tags), converts it to PCAP, and forwards it to destinations, such as a local PCAP file, a NATS subject, or an HTTP endpoint for Wireshark attachment.
For a NATS destination, MEMCAP Sink sends the formatted PCAP as a NATS message payload using a subject. MEMCAP Consumer listens on a specific subject and saves the data to a PCAP file. End users can also connect to the HTTP endpoint with Wireshark.
Installation
VPP MEMCAP plugin
The MEMCAP plugin is included in FPP 2.4.0 or newer images. You must install the FPP deployment using at least 2.4.0 chart. It automatically enables the VPP traffic capturing with MEMCAP Sink running on the worker node. You can use the feature using VPPCTL after the deployment.
Note
When using FPP operator version v2.3.1 or older, you can install FPP-based deployment using the 2.4.0 or newer chart, which enables communication with MEMCAP by default.
MEMCAP Sink and Consumer
MEMCAP is installed as a regular Helm chart. The chart includes MEMCAP Sink, running as a DaemonSet on all nodes with FPP workloads, and MEMCAP Consumer, deployed as a StatefulSet.
To install it, use the following command:
The -n fpp part of the command specifies a namespace where the MEMCAP sink will be deployed. For more details about the memcap.yaml file, read the Configuration section below.
Configuration
VPP MEMCAP plugin configuration
You can configure the VPP MEMCAP plugin included in the FPP image with these parameters:
- memcapName - adds the name of the MEMCAP collector. It is used to differentiate the source of the traffic stream. By default, it is set to the Kubernetes worker node name.
- memcapSocketPath - configures the MEMCAP Sink socket path used to connect from the plugin to the Sink. By default, it is set to
/run/vppswitch/sink.sock.
See the configuration example in the FPP chart:
It will result in the following VPPDeployment CR:
MEMCAP chart configuration
You can configure MEMCAP using Helm chart configurable parameters. Such configuration allows you to:
- Configure NATS connectivity, including server URL, cluster name, and JetStream management
- Define the stream’s source and destination
- Memif socket and targets
- NATS: subject, server URL override, mode (
jetstreamorpubsub) - PCAP file options: file prefix, rotation options (maximum number of packets, time, or size), and file compression
- Deploy Prometheus services for metrics capturing
- Configure RClone as a side-container for PCAP transferring
These are the general parameters that you can configure:
MEMCAP Sink configuration
You can configure MEMCAP Sink with these chart configuration parameters:
You can reload the MEMCAP Sink configuration at runtime. The configuration is stored in a ConfigMap. When you apply a new configuration, the ConfigMap content is updated inside the MEMCAP pod. It can take up to 1 minute for changes to propagate. MEMCAP checks the local file at regular intervals. If the content has changed since the last update, MEMCAP parses the new configuration and restarts the affected threads to apply the changes.
See the MEMACAP Sink configuration example that creates four threads, one for each pair of source and destination:
In the example above, traffic from the target pgw-pfcp is saved to a PCAP file and sent to NATS. The PCAP file is stored in the MEMCAP Sink pod, in the location specified in the path_prefix field. Each PCAP file can hold 100,000 packets; a new file is created once this limit is reached. Rotation is enabled, so only two files will be kept. When the limit is reached, the older file is deleted. This means that traffic is collected continuously, but data is lost after 200,000 packets. NATS messages are sent with the subject pcaps.test-cluster.pgw-pfcp; the NATS URL is defined in the global configuration memcapSink.nats.url as nats://cdm-local.cennso-system:4222.
Target sgi is sent only through NATS to MEMCAP Consumer.
The last target, cgw-apn, is saved only to the local disk. The PCAP file is stored in the MEMCAP Sink pod at the location specified by the path_prefix field. It will collect up to 100,000 packets; after that, traffic will not be saved.
You can copy a PCAP file from the pod to an external machine for further analysis. For example, you can use this command:
MEMCAP Consumer configuration
You can configure MEMCAP Consumer with these chart configuration parameters:
See the MEMACAP Consumer configuration example that creates one thread for fetching the PCAP data from NATS to the .pcapng file:
MEMCAP Consumer has JetStream management enabled, so it will create a JetStream named pcaps-test-cluster with the following settings:
- Messages sent to the subject
pcaps.test-cluster.>will be stored in the stream. - The maximum size for stored messages is 1 GiB (1,073,741,824 bytes).
The source is configured to use NATS in the JetStream mode, which means that MEMCAP Consumer creates a durable NATS consumerOpens in a new tab. This allows the Consumer to fetch all stored messages from the NATS server, even if the MEMCAP Consumer is offline. In the pubsub mode, the Consumer can only fetch messages sent while it is online, so any previous data is lost.
The source.nats.name is used to identify the HTTP endpoint attachment. The name must be unique in the MEMCAP Consumer configuration; otherwise, only the first matching source will be used when attaching with Wireshark. To live-debug the PCAPs, use Wireshark:
The destination is of file type, typically used to store PCAPs sent over NATS to a file.
NATS subject configuration
MEMCAP Sink supports automatic subject generation based on traffic metadata.
The available metadata:
- VPP name (token {POD}) - Custom name assigned in startup.conf or a pod name if not defined
- Namespace (token {NAMESPACE}) - Namespace of the VPP pod (CGW/FPP/UPG)
- Stream labels (for example token {apn} for
MEMCAP_APN) - Environment variables defined in the VPP pod (CGW/FPP/UPG) starting withMEMCAP_, which are attached to traffic metadata - Filter (token {FILTER}) - Libpcap-based filters that are the same as in the tcpdump utility
- IMSI (token {IMSI}) - IMSI attached to UPG session traffic
- Interface (token {INTERFACE}) - Name of the interface where the traffic is captured
- NWI (token {NWI}) - Name of the network instance for the captured traffic (Available in future MEMCAP release, 0.6.1 or later)
- Target (token {TARGET}) - Traffic tag
Note
To get new metadata, use FPP 2.8.0 and UPG 2.16.0 or newer.
Subjects in the NATS destination configuration can:
- be explicitly defined, using available tokens (
{CLUSTER,{TARGET}, and so on) to generate the subjectpcaps.cluster.{CLUSTER}.{apn}.{TARGET}, where{apn}is defined in the environmental variables in the VPP pod (MEMCAP_APN=test.cennso.com)
- use default subject layout (
com.cennso.memcap.v1alpha1.pcaps.cluster...) with the streams[].destinations[].nats.enabled configuration value- the default subject evaluation is explained below:
If subject is not defined by the user, the default one is used:
This can be extended at the end with an arbitrary key:value pair defined in the CGW/FPP/UPG deployment as an environmental variable or in startup.conf.
If, for example, the CGW/UPG pod contains the MEMCAP_APN="test.cennso.com" environmental variable, the apn:test.cennso.com is attached to the subject. Example of a generated subject:
If, for example, the user has defined a pcaps.{CLUSTER}.{apn}.{TARGET} subject, and it contains the MEMCAP_APN="test.cennso.com" pod environmental variable , the rendered subject is:
INFO: A subject name cannot contain characters such as a space,
.,*, and>. Each forbidden character is replaced by_.
The subject includes thenot_available values if some metadata is unavailable.
Wildcards available for the NATS subjects:
- * - to match a single token, for example
pcaps.*.pfcpwill matchpcaps.test1.pfcpandpcaps.test2.pfcp - > - to match multiple tokens, for example
pcaps.>will matchpcaps.test1.pfcpandpcaps.test2.sgi
Rotation schedule
MEMCAP 0.6 enables the definition of a rotation schedule using cron expressions.
The new configuration adds the schedule field, where the following time rotation periods are available:
schedule: 10- Performs rotation every declared number of seconds after the start of traffic capturing,s schedule: 10s- Performs rotation every declared interval after the start of traffic capturing,(example: 10s, 10.5m, 10h10m) schedule: "@every 1h30m"- Performs PCAP file rotation every declared interval after the start of traffic capturing, @every(example: @every 1h30m) schedule: @hourly- Performs rotation every declared period (@hourly,@daily,@weekly,@monthly,@yearly) at the full minute (xx:00), not aligned with the start of traffic capturing but with the clock timeschedule: "30 * * * "- Performs rotation every hour on the half hour (yy:30), not aligned with the start of traffic capturing but with the clock time
All formats are available in the Cronv3 Golang library documentationOpens in a new tab.
Sample MEMCAP configuration:
The old max_duration parameter is broken in the MEMCAP 0.5 release, but in 0.6, it has the following meaning:
max_duration: 10- Seconds of traffic capturing if the integer is passedmax_duration: 1h- Available values: 10s, 10m, 10h, and so on
Compression formats
MEMCAP 0.6 introduces new compression formats: lz4 and gzip.
The old parameter compressed is still supported, meaning zstd.
The new streams[0].destinations[].file.compress parameter can contain:
- none - no compression
- zstd
- lz4
- gzip
The compression level can also be defined in streams[0].destinations[].file.compressLevel. The integer number can tune the compression algorithms as follows:
- for gzip - available values 1-9:
1- best speed9- best compression
- for zstd - available values 1-20:
1- best speed20- best compression
- for lz4 - available values 1-9:
1- best speed9- best compression
Sample configuration:
Use only MEMCAP Sink
In a cluster where NATS is not enabled, you can configure MEMCAP Sink to store pcaps locally on the Data Plane node.
In this case, memcapSink.streams[].destinations should include only file objects. The MEMCAP Consumer can be disabled by setting memcapConsumer.enabled to false. Sample configuration:
Usage
Enable traffic capturing
To initiate traffic capturing on a specific interface, use this command:
filter {tcpdump filter}- allows you to define libpcap-based filters that are the same as in the tcpdump utility. The filter format is described in the libpcap documentationman pcap-filter. Examples:filter {arp or icmp},filter {src net 192.0.2.0/24 and port 2020}.packet_max_bytesis an optional parameter which allows you to limit the size of collected data to reduce memory usage of a traffic capturerxandtxallow you to specify the direction in which traffic should be collected. Leaving those flags out collects traffic in both directions.
Note that you can create multiple captures for the same interface when using different capture targets. This is useful if you want to simultaneously collect differently filtered traffic to separate files from a single interface.
Each active stream on the interface may slow down the entire interface performance. To reduce performance degradation, it's best to keep the number of streams attached to interfaces low. This can be done by combining filters using the libpcap or operator.
Disable traffic capturing
To disable traffic capturing on a specific interface, use this command:
Monitor traffic capture
To view the created interface captures, use the command:
See the output example:
To view all the created MEMCAP streams from all plugins, use the command:
See the output example:
To view MEMCAP connection state, use the command:
See the output example:
Capture information
You can use the additional metadata provided in a .pcapng file for advanced filters in tools like Wireshark:
Simultaneous streaming through HTTP
Currently, MEMCAP Sink does not support simultaneous streaming from multiple nodes through a single connection. For simultaneous streaming on multiple nodes, you must repeat these steps for every node:
Set up port forwarding to one of MEMCAP Sink pods. The pod must be located on the node where you want to capture traffic.
bashThis command maps port
9999on your local machine, allowing direct access to the streaming service.To start streaming the
.pcapngfile to Wireshark, create an HTTP request and redirect it as a stream to Wireshark. You can specify multiple target names in the URL, separated by commas, to select the traffic capture as required.bashThis command performs the following actions:
curl --compressed- starts a cURL and requests a server to perform the request compression and decompression before writing data to a pipe.localhost:9999/pcap/TARGET1,TARGET2,TARGET3- URL to the forwarded MEMCAP Sink API port with a comma-separated list of target names.-N- disables pipe buffering to ensure real-time updates in Wireshark.| wireshark -k -i -- sends (pipes) the output from curl directly into Wireshark, which starts analyzing the stream immediately.-o 'gui.window_title:memcap-stream'- sets the Wireshark window title for easy identification.-o 'capture.no_interface_load:TRUE'- prevents Wireshark from listing local interfaces, which speeds up the startup.
As a result, you should see live traffic in Wireshark.
Performance impact
Test environment configuration
The System Under Test (SUT) container contains three sequential instances of CGW (FPP instance mode). The capture streams are attached to the left interface of CGW-central.
Hardware configuration:
- CPU: 1x Intel Xeon Gold 6314U Processor 32-Core @ 2.30GHz
- RAM: 512GB RAM
- Net: 4x E810-C 25Gbps
FPP switch resources:
- CPU: 18
- Memory: 4Gi
- Hugepages-2Mi: 9Gi
CGW instances resources:
- CPU: 6
- Memory: 16Gi
- Hugepages-2Mi: 1Gi
Test parameters:
- Benchmark: Throughput Binary Search
- Sessions: 256000
- Acceptable loss: 0.3%
- Traffic profile: PPS, packets from 20 to 24 bytes
Results
It is not recommended to use more than 4 streams simultaneously: