Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
Documentation and prefix changes (#12)
Browse files Browse the repository at this point in the history
- prefixes changed in fuzzing, withdraw e2e and cndp where necessary
- updates ReadMe in root, e2e and fuzz.
- uds_fuzz.go changes prefix for pod validation
  • Loading branch information
patrickog11 authored Apr 26, 2022
1 parent 956104e commit b044286
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 62 deletions.
38 changes: 4 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,8 @@ Under normal circumstances the device plugin config is set as part of a config m

The device plugin binary can also be run manually on the host for development and testing purposes. In these scenarios the device plugin will search for a `config.json` file in its current directory, or the device plugin can be pointed to a config file using the `-config` flag followed by a filepath.

### Default Behaviour
If no config is given, the default behaviour of the device plugin is to discover AF_XDP capable devices on the node and create device pools based on driver type.
For example, a host with a single 4-port X710 NIC will result in 4 devices being added to the `cndp/i40e` pool.

### Driver Pools
It is possible to have multiple driver types in a single device pool. The example below will result in a pool named `cndp/intel` that contains all the x710 and all E810 devices on the node.
It is possible to have multiple driver types in a single device pool. The example below will result in a pool named `afxdp/intel` that contains all the x710 and all E810 devices on the node.

```
{
Expand All @@ -124,7 +120,7 @@ It is possible to have multiple driver types in a single device pool. The exampl
```

### Device Pools
It is possible to assign individual devices to a pool. The example below will generate a pool named `cndp/test` with the two listed devices.
It is possible to assign individual devices to a pool. The example below will generate a pool named `afxdp/test` with the two listed devices.
This is not scalable over many nodes and is intended only for development and testing purposes.

```
Expand All @@ -151,7 +147,7 @@ A log file and log level can be configured for the device plugin. As above, thes
```
{
"logLevel": "debug",
"logFile": "/var/log/afxdp-k8s-plugins/cndp-dp.log",
"logFile": "/var/log/afxdp-k8s-plugins/afxdp-dp.log",
"timeout": 30,
"pools" : [
{
Expand Down Expand Up @@ -181,34 +177,8 @@ Mode setting for device plugin is set via the `config.json` file. Please see exa
}
```

Mode setting for CNI is set via the network-attachment-definition(NAD) file `NAD.yml`. Please see example below:
Mode setting for CNI is set via the network-attachment-definition(NAD) file `NAD.yml`. Please see mode example: [examples/network-attachment-definition.yaml](./examples/network-attachment-definition.yaml)

```
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: cndp-e2e-test
annotations:
k8s.v1.cni.cncf.io/resourceName: cndp/e2e
spec:
config: '{
"cniVersion": "0.3.0",
"type": "cndp-e2e",
"mode": "cndp",
"logFile": "/var/log/afxdp-k8s-plugins/cndp-cni-e2e.log",
"logLevel": "debug",
"ipam": {
"type": "host-local",
"subnet": "192.168.1.0/24",
"rangeStart": "192.168.1.200",
"rangeEnd": "192.168.1.216",
"routes": [
{ "dst": "0.0.0.0/0" }
],
"gateway": "192.168.1.1"
}
}
```

### Timeout
The device plugin includes a timeout action for the unix domain sockets(UDS).
Expand Down
6 changes: 3 additions & 3 deletions deployments/daemonset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ data:
{
"mode": "cndp",
"logLevel": "debug",
"logFile": "/var/log/afxdp-k8s-plugins/cndp-dp-e2e.log",
"logFile": "/var/log/afxdp-k8s-plugins/cndp-dp.log",
"pools" : [
{
"name" : "e2e",
"name" : "intel",
"drivers" : ["i40e"]
}
]
Expand All @@ -27,7 +27,7 @@ metadata:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: kube-afxdp-device-plugin-e2e
name: kube-afxdp-device-plugin
namespace: kube-system
labels:
tier: node
Expand Down
4 changes: 2 additions & 2 deletions internal/uds/uds_fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ func (f *fuzzHandler) Read() (string, int, error) {
var fd int = 0

if firstCall {
fuzzResponse = "/connect, cndp-e2e-test"

fuzzResponse = "/connect, afxdp-fuzz-test"
} else {

f := fuzz.New()
f.Fuzz(&fuzzResponse)
}
Expand Down
23 changes: 23 additions & 0 deletions test/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,33 @@ Response: /fin_ack
```

### Timeout
The device plugin includes a timeout action for the unix domain sockets(UDS).
Once the timeout is invoked, the UDS is closed and disconnected.

The timeout can be set to a minimum of 30 seconds and a maximum of 300 seconds. If no timeout is configured, the plugin will default to the minimum 30.

The timeout value is set in the `config.json` file. Please see example below.

```
{
"timeout": 30,
"pools" : [
{
"name" : "i40e",
"drivers" : ["i40e"]
}
]
}
```


## Extended Test
The e2e test script can also do an extended run. In addition to the single container single device test, the script will go on to create:
- A pod with a single container requesting 2 devices
- A pod with 2 containers, each requesting a single device
- Timeout before the UDS connection
- Timeout after the UDS connection

To do the full extended run, add the flag -f or --full when calling the script:
`./e2e-test.sh --full`
57 changes: 51 additions & 6 deletions test/fuzz/cni/README.md → test/fuzz/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
# CNI Fuzz Test
# Fuzz Tests

There are two fuzzing packages used to conduct the four fuzz tests which are as follows:

| Component | Function/Package Under-Test | Fuzzing Package |
| :---: | :---: | :---: |
| CNI | Network Config | go-fuzz |
| Device Plugin | GetConfig | go-fuzz |
| Device Plugin | UDS | go-fuzz |
| Device Plugin | CNDP | google/gofuzz |

Note: the following information is regarding the go-fuzz testes. As CNDP fuzz test uses google/gofuzz package a different procedure applies, please see [CNDP Fuzz Test](#cndp-fuzz-test)

To start fuzz testing, proceed to the function/package you wish to test and run `./fuzz.sh`. `Ctrl + C` will stop the test from running.


To start the CNI fuzz test run `./fuzz.sh`. `Ctrl + C` will stop the test from running.

The `fuzz.sh` script will:

- Install [go-fuzz](https://github.com/dvyukov/go-fuzz) if necessary.
- Build a test program that is capable of testing our CNI functions CmdAdd and CmdDel.
- Create a test network namespace to test the CNI against.
- Execute 2 test programs simultaneously, testing both CNI functions in parallel.
- Cleans up the test network namespace after the tests.
- Build a test program that is capable of testing.
- Execute the test programs against the function under-test.
- Remove any remaining network namespace, logfiles and UDS sockets after the tests.

**CAUTION:** Fuzzing will result in the CNI placing a lot of randomly named log files under `/var/log/afxdp-k8s-plugins/`. These will need to be manually cleaned. The CNI has input validation that should ensure log files cannot be generated anywhere outside of this directory. Nonetheless caution is advised, and fuzzing should not be performed on a production system.

## Files and directories

This CNI fuzz test explanation will also apply to the additional tests using the go-fuzz package.

- `fuzz.sh` a script to conveniently perform all the fuzzing steps.
- `cni.go` contains a small amount of Go code capable of calling our CNI functions under test. Returns values based on outcome.
- `cni-fuzz.zip` is a go-fuzz archive created during the building of the test program.
Expand Down Expand Up @@ -78,3 +92,34 @@ Output columns as described in the go-fuzz [documentation](https://github.com/dv
2021/10/11 15:29:26 workers: 88, corpus: 769 (1s ago), crashers: 0, restarts: 1/9247, execs: 16932634 (34206/sec), cover: 1808, uptime: 8m15s
2021/10/11 15:29:26 workers: 88, corpus: 791 (2m5s ago), crashers: 0, restarts: 1/9926, execs: 153329901 (309745/sec), cover: 1484, uptime: 8m15s
```

## CNDP Fuzz Test

For CNDP fuzz testing, [google/goFuzz](https://github.com/google/gofuzz) package is utilised.

To start the CNDP fuzz test:
- CNI and Device Plugin binaries must be created, from the root of the directory run `make build`.
- Navigate to the [/deviceplugin/cndp](./deviceplugin/cndp) directory, open `config.json` file and set `cndpFuzz` field as `true`, see example below:
```
{
"logLevel": "debug",
"mode": "cndp",
"cndpFuzz": true,
"pools" : [
{
"name" : "fuzz",
"drivers" : ["i40e"]
}
]
}
```
- Run `./fuzz.sh`. `Ctrl + C` will stop the test from running.


The `fuzz.sh` script will:

- Run both the CNI and Device Plugin.
- Deploy test pod `afxdp-fuzz-pod`.
- Execute the fuzzHandler in `internal/uds/uds_fuzz.go`.
- The fuzzHandler will call the imported google/gofuzz package.
- Execute generated fuzzed data to the function under-test in the CNDP application.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
apiVersion: v1
kind: Pod
metadata:
name: cndp-e2e-test
name: afxdp-fuzz-test
annotations:
k8s.v1.cni.cncf.io/networks: cndp-e2e-test
k8s.v1.cni.cncf.io/networks: afxdp-fuzz-test
spec:
containers:
- name: cndp
image: cndp-e2e-test:latest
- name: afxdp
image: afxdp-fuzz-test:latest
imagePullPolicy: Never
command: ["tail", "-f", "/dev/null"]
resources:
requests:
cndp/e2e: '1'
cndp/fuzz: '1'
limits:
cndp/e2e: '1'
cndp/fuzz: '1'
restartPolicy: Never
3 changes: 2 additions & 1 deletion test/fuzz/deviceplugin/cndp/config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"logLevel": "debug",
"mode": "cndp",
"cndpFuzz": true,
"pools" : [
{
"name" : "e2e",
"name" : "fuzz",
"drivers" : ["i40e"]
}
]
Expand Down
12 changes: 6 additions & 6 deletions test/fuzz/deviceplugin/cndp/fuzz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ cleanup() {
echo "* Cleanup *"
echo "*****************************************************"
echo "Delete Pod"
kubectl delete pod --grace-period 0 --ignore-not-found=true cndp-e2e-test &> /dev/null
kubectl delete pod --grace-period 0 --ignore-not-found=true afxdp-fuzz-test &> /dev/null
echo "Delete CNI"
rm -f /opt/cni/bin/afxdp-e2e &> /dev/null
rm -f /opt/cni/bin/afxdp-fuzz &> /dev/null
echo "Delete Network Attachment Definition"
kubectl delete network-attachment-definition --ignore-not-found=true cndp-e2e-test &> /dev/null
kubectl delete network-attachment-definition --ignore-not-found=true afxdp-fuzz-test &> /dev/null
echo "Delete Docker Image"
docker 2>/dev/null rmi cndp-e2e-test || true
docker 2>/dev/null rmi afxdp-fuzz-test || true
echo "Stop Device Plugin on host (if running)"
if [ ${#pids[@]} -eq 0 ]; then
echo "No Device Plugin PID found on host"
Expand All @@ -46,7 +46,7 @@ build() {
echo "* Build and Install *"
echo "*****************************************************"
echo "***** CNI Install *****"
cp ./../../../../bin/afxdp /opt/cni/bin/afxdp-e2e
cp ./../../../../bin/afxdp /opt/cni/bin/afxdp-fuzz
echo "***** Network Attachment Definition *****"
kubectl create -f ./nad.yaml
}
Expand All @@ -64,7 +64,7 @@ run() {
echo "* Run Pod: 1 container, 1 device *"
echo "*****************************************************"
echo "CNDP fuzz testing will be executed after pod is created..."
kubectl create -f pod-1c1d.yaml
kubectl create -f afxdp-fuzz-pod.yaml
}

cleanup
Expand Down
8 changes: 4 additions & 4 deletions test/fuzz/deviceplugin/cndp/nad.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: cndp-e2e-test
name: afxdp-fuzz-test
annotations:
k8s.v1.cni.cncf.io/resourceName: cndp/e2e
k8s.v1.cni.cncf.io/resourceName: cndp/fuzz
spec:
config: '{
"cniVersion": "0.3.0",
"type": "afxdp-e2e",
"type": "afxdp-fuzz",
"mode": "cndp",
"logFile": "/var/log/afxdp-k8s-plugins/cndp-cni-e2e.log",
"logFile": "/var/log/afxdp-k8s-plugins/afxdp-cni-fuzz.log",
"logLevel": "debug",
"ipam": {
"type": "host-local",
Expand Down

0 comments on commit b044286

Please sign in to comment.