> For the complete documentation index, see [llms.txt](https://docs.cennso.com/cennso/netcap/latest/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/cennso/netcap/latest/concepts/netcapturejob.md).

# `NetCaptureJob` CR

`NetCaptureJob` CR allows you to define how traffic should be captured from VPP-based components across Core Clusters. It lets you configure all key aspects of a capture job, including source selection, filtering, batching, destination settings, and rotation policies.

The following sections describe all configurable parameters available in the `NetCaptureJob` CR. For a step-by-step guide on how to perform the configuration, see the [Configure PCAP capturing](https://docs.cennso.com/cennso/netcap/latest/guides/pcap-k8s.md) guide.

## Traffic capture time schedule

You can configure traffic capturing to run either once at a specific time or on a recurring schedule.

### One-time traffic capturing

You can define when a traffic capturing should start and end using the **spec.forProvider.schedule.start** and **spec.forProvider.schedule.end** fields in the `NetCaptureJob` resource. The following formats are supported:

- Duration: `10m`, `1h30m`
- Time of day: `14:00`, `14:20:00`, `now`
- Full date and time: `2025-12-16 06:20:00`

If not specified, the traffic stream is collected as long as the `NetCaptureJob` resource exists.

See the configuration example:

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureJob
metadata:
  name: capture-example
spec:
  forProvider:
    # Defines time schedule for traffic capturing
    schedule:
      # Specifies the start time for traffic capturing
      start: now
      # Specifies the end time for traffic capturing
      end: 10m
```

All time periods are provided in UTC. To specify a local time, include a time zone offset. For example: `2026-06-27 16:28:13 +0200` (for CEST). This will be interpreted and shown in the job status as: `scheduledStart: "2026-06-27T14:28:13Z"`.

### Periodic traffic capturing

You can configure a periodic traffic capturing by providing the cron expression and the duration in the **spec.forProvider.schedule.periodic.schedule** and **spec.forProvider.schedule.periodic.duration** fields in the `NetCaptureJob` resource.

Cron expression can be in formats:
- `schedule: "30 * * * *"` – Uses standard cron syntax to schedule captures based on clock time (for example, at the 30th minute of every hour).
- `schedule: "@every 1h30m"` – Schedules captures at a fixed interval after traffic capturing starts (for example, every 1 hour and 30 minutes).
- `schedule: @hourly` – Schedules captures at regular intervals based on the clock time, not the traffic capturing start time. Supported values: `@hourly`, `@daily`, `@weekly`, `@monthly`, `@yearly`.

For all supported formats, refer to the [Cronv3 Golang library documentation](https://pkg.go.dev/github.com/robfig/cron/v3).

Duration can be in formats:
- `duration: 10` – Traffic capture lasts for a specified number of seconds after traffic capturing starts (for example, `10` means every 10 seconds).
- `duration: 10s` – Traffic capture lasts for a specified duration (s, m, h) after traffic capturing starts, for example: `10s`, `10.5m`, `10h10m`.

See the configuration example:

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureJob
metadata:
  name: capture-example
spec:
  forProvider:
    # Defines time schedule for traffic capturing
    schedule:
      # Defines periodic schedule for traffic capturing
      periodic:
        # Configures period for traffic capturing
        schedule: "30 2 * * *"
        # Configures duration for traffic capturing
        duration: "4h"
```

## Sources of traffic capturing

To configure where traffic should be captured, you must specify the target Core Cluster using the **spec.forProvider.streamTemplate.spec.cluster** field. This is a required setting that determines the cluster in which the traffic stream will be captured. Each `NetCaptureJob` can target only one Core Cluster.

Within that cluster, you can narrow down which VPP-based pods should perform the capture by using the **spec.forProvider.streamTemplate.spec.selector** field. This selector allows you to limit the capture scope to a specific VPP pod and namespace, ensuring fine-grained control over PCAP collection.

See the configuration example:

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureJob
metadata:
  name: test-job-gtpc
spec:
  forProvider:
    streamTemplate:
      spec:
        cluster:
          # Name of a Core Cluster to which this configuration should be applied
          name: test-cluster
          # Name of the namespace of the Core Cluster resource
          namespace: cennso-infra
        # Optional setting to select VPP instances to capture traffic from
        selector:
          # Name of the VPPDeployment or Kuberenetes Deployment to capture traffic from
          name: cgw2-grx
          # Namespace of the target VPP deployment
          namespace: pgw-ns
```

The **spec.forProvider.streamTemplate.spec.sources** section lists the traffic sources to be captured. NetCap supports these two sources of traffic capturing:

- Interface
- IMSI

### Interface

To capture traffic based on an interface, specify the **spec.forProvider.streamTemplate.spec.sources[].interface** key in the `NetCaptureJob` CR. For example:

   ```yaml
   apiVersion: netcap.cennso.com/v1alpha1
   kind: NetCaptureJob
   metadata:
     name: sx-upg
   spec:
     forProvider:
       streamTemplate:
         spec:
           cluster:
             name: test-cluster
             namespace: cennso-infra
           sources:
             # Specifies an interface from which to capture traffic
             - interface:
                 name: "sxb"
   ```

The **interface.name** must match the **VPPInterface.spec.ifName**. To get the interface name, run this command in the FPP pod:

```bash
vppctl -s /run/vppswitch/cli.sock show interface
```

On a UPG pod, use:

```bash
vppctl show interface
```

You can also query the Kubernetes API server from a Core Cluster using kubeclt:

```bash
kubectl get vppinterfaces.fpp-manager.cennso.com -o jsonpath='{range.items[*]}{.metadata.name}:{.spec.ifName}{"\n"}{end}' -A
```

Sample the output example:

```console
upg-prox01-55bccff57b-p7x7v-memif-client-39-dtj7h:sxb
upg-prox01-55bccff57b-p7x7v-memif-client-40-9bjnb:grx
upg-prox01-55bccff57b-p7x7v-memif-client-41-l8qff:sgi
```

In the output, the text before the colon (:) is the pod name, and the text after it is the interface name.

### IMSI

To capture traffic based on IMSI, specify the **spec.forProvider.streamTemplate.spec.sources[].imsi** key in the `NetCaptureJob` CR. For example:

   ```yaml
   apiVersion: netcap.cennso.com/v1alpha1
   kind: NetCaptureJob
   metadata:
     name: capture-example
   spec:
     forProvider:
       streamTemplate:
         spec:
           cluster:
             name: test-cluster
             namespace: cennso-infra
           sources:
           # Specifies IMSI for traffic capturing
           - imsi:
               imsi: "901406000520000"
           # Specifies IMSI for traffic capturing
           - imsi:
               imsi: "901406000520001"
           # Specifies IMSI for traffic capturing
           - imsi:
               imsi: "901406000520002"
   ```

>**NOTE:** Capturing traffic based on IMSI is only possible for the UPG pods.

## NATS messaging modes

The **spec.forProvider.streamTemplate.spec.sources[].{imsi|interface}.natsMode** parameter defines how traffic is sent and received over Cennso Data Mesh (CDM). Two messaging modes are available:

- **pubsub** – Use this mode for non-critical or low-priority traffic. In this mode, NATS delivers messages in real time but does not store them, so data can be lost if the consumer is temporarily unavailable. It’s best suited for short-lived streams or monitoring scenarios where occasional loss is acceptable.
- **jetstream** (default) – Use this mode when you need reliable delivery and message persistence. JetStream stores messages and supports replay, making it ideal for long-term captures, high-value traffic, or scenarios where reliability and fault tolerance are important.

See the configuration example:

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureJob
metadata:
  name: capture-example
spec:
  forProvider:
    streamTemplate:
      spec:
        cluster:
          name: test-cluster
          namespace: cennso-infra
        sources:
        - interface:
            name: sgi
            # NATS mode to use for sending and receiving NATS messages
            natsMode: pubsub
```

## Traffic filtering

When collecting traffic from a given interface, you can specify the **spec.forProvider.streamTemplate.spec.sources[].interface.filter** parameter that lets you specify a filter expression compatible with the standard [`tcpdump` syntax](https://www.tcpdump.org/manpages/tcpdump.1.html) to capture only specific types of packets. Applying a filter helps you reduce the amount of captured traffic and ensures only relevant packets are collected.

For example, you can apply such a filter:

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureJob
metadata:
  name: capture-example
spec:
  forProvider:
    streamTemplate:
      spec:
        cluster:
          name: test-cluster
          namespace: cennso-infra
        sources:
        - interface:
            name: sgi
            # TCPDump filter to apply to the traffic capture
            filter: "arp or icmp"
```

In this example, only ARP or ICMP traffic will be captured from the `sgi` interface.

## Packet batching strategy

The **spec.forProvider.streamTemplate.spec.sources[].{imsi|interface}.batchingStrategy** field controls how packets are grouped before sending them to the destination. You can define batching behaviour using three optional parameters:

- **packetsCount** - sets the number of packets to accumulate before sending a batch (default is `10`). Higher values may improve throughput at the cost of latency.
- **duration** - specifies the maximum time interval to wait before sending a batch (default is `3` seconds)
- **packetsBytes** - allows batching based on the total number of bytes collected

See the configuration example:

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureJob
metadata:
  name: capture-example
spec:
  forProvider:
    streamTemplate:
      spec:
        cluster:
          name: test-cluster
          namespace: cennso-infra
        sources:
        - interface:
            name: sgi
            # Specifies packet batching strategy
            batchingStrategy:
              # Number of packets to accumulate before sending a batch of packets. Default value: 10
              packetsCount: 100
              # Time interval before sending a batch of packets. Default value: 3s
              duration: 10s
              # Number of bytes gathered before sending a batch of packets
              packetsBytes: 200
```

## Match labels

The **spec.forProvider.streamTemplate.spec.sources[].{imsi|interface}.match-labels** section defines label-based criteria for selecting FPP or UPG instances from which traffic should be captured. These labels are matched against environment variables set on the target pods. Only instances with environment variables that match all specified key-value pairs will be selected.

For example:

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureJob
metadata:
  name: capture-example
spec:
  forProvider:
    streamTemplate:
      spec:
        cluster:
          name: test-cluster
          namespace: cennso-infra
        sources:
        - interface:
            name: sgi
            # Defines label-based criteria for selecting instances to capture traffic from
            match-labels:
              # Selects FPP/UPG instances that have NETCAP_APN: "test.cennso.com" defined
              apn: "test.cennso.com"
              # Selects FPP/UPG instances that have NETCAP_LANE: "lane-b" defined
              lane: lane-b
```

In this case, only FPP or UPG pods with both `NETCAP_APN="test.cennso.com"` and `NETCAP_LANE="lane-b"` environment variables will be included in the traffic capture.

## PCAP file rotation schedule

To prevent PCAP files from growing indefinitely and consuming too much storage or becoming difficult to process, NetCap supports a PCAP file rotation schedule using cron expressions. PCAP file rotation is disabled by default. To enable it, set the **spec.forProvider.destinationTemplate.spec.destinations.fileParams.rotate** parameter to `true`. Then, configure rotation schedule using the **spec.forProvider.destinationTemplate.spec.destinations.fileParams.schedule** field, which accepts several formats:

- `schedule: 10` – Rotates every specified number of seconds after traffic capturing starts (for example, `10` means every 10 seconds).
- `schedule: 10s` – Rotates at a specified interval after traffic capturing starts, using time units (s, m, h), for example: `10s`, `10.5m`, `10h10m`.
- `schedule: "@every 1h30m"` – Rotates at a fixed interval after traffic capturing starts (for example, every 1 hour and 30 minutes).
- `schedule: @hourly` – Rotates at regular intervals based on the clock time, not the traffic capturing start time. Supported values: `@hourly`, `@daily`, `@weekly`, `@monthly`, `@yearly`.
- `schedule: "30 * * * *"` – Uses standard cron syntax to rotate based on clock time (for example, at the 30th minute of every hour).

For all supported formats, refer to the [Cronv3 Golang library documentation](https://pkg.go.dev/github.com/robfig/cron/v3).

See the configuration example:

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureJob
metadata:
  name: capture-example
spec:
  forProvider:
    destinationTemplate:
      spec:
        destinations:
        # Parameters that define the PCAP file
        - fileParams:
            # Enables file rotation, by default false
            rotate: true
            # Defines the rotation schedule at the beginning of every hour
            schedule: @hourly
            # Maximum bytes per file (before compression)
            max_bytes: 104857600
            # Maximum number of rotated PCAP files to keep.
            # Older files will be deleted once the limit is reached.
            # Leave empty to retain all files without deleting.
            max_files: 10
            # Maximum number of packets per file
            max_packets: 10000
```

In this example, PCAP file rotation is enabled and configured to rotate files at the beginning of every hour.

## Date directories for rotated PCAP files

A capture with a short rotation schedule writes every PCAP file into one directory. That directory becomes slow to browse and list. NetCap can group those files into subdirectories named after the rotation time in UTC. Set the **spec.forProvider.destinationTemplate.spec.destinations.fileParams.dateDirectories** parameter to one of these values:

- `none` – Writes every file directly into the destination directory. This is the default.
- `monthly` – Adds one directory per month, for example `2026-09/`.
- `daily` – Adds one directory per day, for example `2026-09-15/`.
- `hourly` – Adds one directory per day and one per hour, for example `2026-09-15/19/`.

NetCap adds these directories inside the path or prefix that the destination already uses.

See the configuration example:

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureJob
metadata:
  name: capture-example
spec:
  forProvider:
    destinationTemplate:
      spec:
        destinations:
        - fileParams:
            rotate: true
            schedule: @hourly
            # Maximum number of rotated PCAP files to keep
            max_files: 10
            # Groups rotated files into one directory per day
            dateDirectories: daily
```

In this example, NetCap writes a file rotated at `2026-09-15T19:30:00Z` to the `2026-09-15/` directory.

Cleanup of empty date directories depends on the storage type:

- Local storage – NetCap removes an empty date directory. A directory becomes empty when NetCap deletes its last file under the **max_files** limit.
- S3 storage – The date is part of the object key, so there is no directory to remove.
- SFTP storage – Empty date directories stay on the server.

## PCAP file compression

NetCap supports the following compression formats for PCAP files: `zstd`, `lz4`, `gzip`, and `none` (no compression). To configure the format, set the **spec.forProvider.destinationTemplate.spec.destinations.fileParams.compress** parameter to one of these values.

You can fine-tune the compression level using the **spec.forProvider.destinationTemplate.spec.destinations.fileParams.compressLevel** parameter. This is an integer value, where higher values increase compression at the cost of speed:

- `gzip`: values from 1 (fastest) to 9 (best compression but slowest), default 6
- `zstd`: values from 1 (fastest) to 20 (best compression but slowest), default 5
- `lz4`: values from 1 (fastest) to 9 (best compression but slowest), default 1

See the configuration example:

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureJob
metadata:
  name: capture-example
spec:
  forProvider:
    destinationTemplate:
      spec:
        destinations:
        # Parameters that define the PCAP file
        - fileParams:
            # Defines the compression format
            compress: zstd
            # Defines compression level. The value depends on the algorithm defined in `compress`
            compressLevel: 20
```

## Status

NetCap Provider updates the traffic stream status in the `NetCaptureJob` custom resource (CR). This status information is gathered through Cennso Data Mesh (CDM) from multiple NetCap components, including the NetCap Sink, NetCap Collector, Fast Path Provider (FPP), and User Plane Gateway (UPG).

The following statuses provide insights into the state and health of the traffic capturing, including:

- `StreamCreated` - informs that the stream was successfully created by all components
- `PacketSent` - informs that packets were sent from NetCap Collector
- `PacketReceived` - informs that packets were received by the NetCap Sink
- `StreamCollecting` - informs that NetCap VPP Plugin configured traffic capturing in the VPP instance
- `StreamCreateError`, `PacketReceiveError`, `PacketSendError` - inform about errors encountered during stream or destination creation (most commonly due to misconfiguration)

Under the hood, the created resources are validated, and the following checks are executed:

- Validate that multiple storages are not provided.
- Validate that both one-time and periodic schedules are not provided.
- Validate that captures with both IMSI and interface parameters are not provided.

If one of these checks fails, the resource is not processed further, and the `Synced: false` status is set.

To learn how to get the `NetCaptureJob` status, [See the `NetCaptureJob` status](https://docs.cennso.com/cennso/netcap/latest/guides/pcap-k8s.md#see-the-netcapturejob-status) section.
