> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/smc/3.14/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/components/smc/3.14/operation/traffic-capture.md).

# Traffic capturing and exposure

You can configure Session Management Controller (SMC) to capture and send traffic packets as PCAP files. To do so, you must configure dedicated containers to capture traffic in the `values.yaml` files. Then, the `rclone` service can send these data to further destinations.

The following example sets up PCAP captures with a shared storage of 30GB, acting on the `sx` and `rf` interfaces with different options:

```yaml
pcap:
  dirSize: 30Gi
  interfaces:
    sx:
      FILENAME: sx.pcap
      FILTER: "port 8805"
      IFACE: "sx"
      INTERVAL: 900
      MAXFILENUM: 672
    rf:
      FILENAME: rf.pcap
      FILTER: "port 3868"
      IFACE: "rf"
      INTERVAL: 900
      MAXFILENUM: 672
```

## PCAP capturing setup

For each of the `{NAME}` interfaces in the `pcap.interfaces` property, the Helm chart sets up a separate container to gather PCAP files. You can customize it using the `pcap.interfaces.{NAME}.{ENV_KEY}` environment variables as mentioned in the [configuration reference](https://docs.cennso.com/components/smc/3.14/installation/chart-configuration.generated.md).

> [!NOTE]
> Each PCAP container takes a maximum of 0.1 CPU and 128 MB memory.

## `rclone` setup

To publish traffic captured by the PCAP container, enable `rclone` and `pcap`, and configure them using environment variables. Use `RCLONE_REMOTE_NAME` to specify the remote endpoint and `RCLONE_REMOTE_PATH` to specify the destination path.

`rclone` is defined generically through the container environment. To find the name of the environment variable that corresponds to a command line option or a config file entry, take the long option name, strip the leading --, change - to _, make upper case, and prepend `RCLONE_` or `RCLONE_CONFIG_`, as explained in the [rclone documentation](https://rclone.org/docs/#environment-variables).

All available endpoints are described in the [official rclone documentation](https://rclone.org/commands/rclone_move/). The [inotify](https://linux.die.net/man/1/inotifywait) pattern watches for captures and moves them from the `/data/finished` directory.

This container example-configuration enables authorisation for SFTP through username and password:

```yaml
rclone:
  enabled: true
  env:
    RCLONE_REMOTE_NAME: "sftp" # Mandatory, when defining multiple devices, this is your selector.
    RCLONE_CONFIG_SFTP_TYPE: "sftp"
    RCLONE_CONFIG_SFTP_HOST: "host.com" # hostname or ip of sftp-server
    RCLONE_CONFIG_SFTP_USER: "name"
    RCLONE_CONFIG_SFTP_PORT: "22"
    RCLONE_CONFIG_SFTP_PASS: "password" # Encoded "password". Leave blank to use ssh-agent
```

SFTP can also be authorised using private keys. Setting `useSSHkeyFile` will look for the secret which name is configured by `.Values.rclone.secretName` in the appropriate namespace and mount it to `/etc/ssh` in the container's filesystem. Rclone will look for the file using `RCLONE_CONFIG_SFTP_KEY_FILE` - environment variable.

```yaml
rclone:
  enabled: true
  useSSHkeyFile: true
  env:
    RCLONE_REMOTE_PATH: "name/directory"
    RCLONE_REMOTE_NAME: "sftp" # Mandatory,
    RCLONE_CONFIG_SFTP_TYPE: "sftp"
    RCLONE_CONFIG_SFTP_HOST: "host.com" # hostname or ip of sftp-server
    RCLONE_CONFIG_SFTP_USER: "name"
    RCLONE_CONFIG_SFTP_PORT: "22"
    RCLONE_CONFIG_SFTP_PASS: "" # Encoded, blank for agent.
    RCLONE_CONFIG_SFTP_KEY_FILE: "/etc/ssh/key.pem"
```
Note that this secret `.Values.rclone.secretName` is not created automatically when deploying this helm chart, but needs to be manually prepared by the user like so:

```bash
kubectl create secret generic rclone-ssh-key --from-file=/path/to/key.pem -n {NAMESPACE}
```

This container example-configuration enables authorisation for s3 through access-key and secret-access-key:

```yaml
rclone:
  enabled: true
  env:
    RCLONE_CONFIG_S3_TYPE: "s3"
    RCLONE_CONFIG_S3_ENV_AUTH: "false"
    RCLONE_CONFIG_S3_ACCESS_KEY_ID: "<sensitive>"
    RCLONE_CONFIG_S3_SECRET_ACCESS_KEY: "<sensitive>"
    RCLONE_CONFIG_S3_REGION: "s3-<region>"
    RCLONE_CONFIG_S3_ACL: "private"
    RCLONE_CONFIG_S3_FORCE_PATH_STYLE: "false"
```

Note that using `rclone_move` implies that transferred files will be removed from the source path `data/finished`. This keeps the container's memory-footprint manageable and enables file-cycling. If the process crashes during transfer no garbage data will remain on the destination address and you will notice a `Terminated` in the container logs. When attempting to push duplicate files they will be removed from the source path but not overwritten/modified on the destination if [MD5/SHA](https://github.com/ncw/rclone#features) checksums and file-name are the same on both ends. Be aware this can cause data loss, if you were to lose the access to the data at the destination. Consider testing first using the `--dry-run` flag.
