Commit e728dc1c authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch 'pr-p4-r5-test' into 'develop'

test: P4 fabric-v1model scenario with INT, routing, and ACL rules

See merge request !314
parents 5cf273cc c084e0b3
Loading
Loading
Loading
Loading
+129 −0
Original line number Diff line number Diff line
# Tests for P4 routing, ACL, and In-Band Network Telemetry functions

This directory contains the necessary scripts and configurations to run tests atop a Stratum-based P4 whitebox that performs a set of network functions, including routing, access control list (ACL), and In-Band Network Telemetry (INT).

## Prerequisites

You need Python3, which should already be installed while preparing for a TFS build.
Additionally, `pytest` is also mandatory as it is used by our tests below.
Aliasing python with python3 will also help bridging issues between older and newer python versions.

```shell
alias python='python3'
pip3 install pytest
pip3 install grpclib protobuf
pip3 install grpcio-tools
```

The versions used for this test are:
- `protobuf` 3.20.3
- `grpclib` 0.4.4
- `grpcio` 1.47.5
- `grpcio-tools` 1.47.5

After the installation of `grpclib`, protoc-gen-grpclib_python binary is in /home/$USER/.local/bin/
First we copy it to /usr/local/bin/:

```shell
  sudo cp /home/$USER/.local/bin/protoc-gen-grpclib_python /usr/local/bin/
```

Then, we include this path to the PYTHONPATH:
```shell
export PYTHONPATH="${PYTHONPATH}:/usr/local/bin/protoc-gen-grpclib_python"
```


You need to build and deploy a software-based Stratum switch, before being able to use TFS to control it.
To do so, follow the instructions in the `./topology` folder.

## Steps to setup and run a TFS program atop Stratum

To conduct this test, follow the steps below.

### TFS re-deploy

```shell
cd ~/tfs-ctrl/
source my_deploy.sh && source tfs_runtime_env_vars.sh
./deploy/all.sh
```

### Path setup

Ensure that `PATH` variable contains the parent project directory, e.g., "home/$USER/tfs-ctrl".

Ensure that `PYTHONPATH` variable contains the source code directory of TFS, e.g., "home/$USER/tfs-ctrl/src"

## Topology setup

In the `./topology/` directory there are scripts that allow to build Stratum on a target machine (e.g., a VM) and then deploy a P4 switch atop this machine.
This test assumes a Stratum P4 switch with 2 network interfaces used as a data plane (routing traffic from one to another) as well as another network interface used to send telemetry information to an external telemetry collector.

## P4 artifacts

In the `./p4src/` directory there are compiled P4 artifacts of the pipeline that will be pushed to the P4 switch, along with the P4-runtime definitions.
The `./setup.sh` script copies from this directory. If you need to change the P4 program, make sure to put the compiled artifacts there.

## Tests

The following tests are implemented.
For each of these tests, an auxiliary bash script allows to run it with less typing.

|                 Test                 |              Bash Runner           |                Purpose             |
| ------------------------------------ | ---------------------------------- | ---------------------------------- |
| -                                    | setup.sh                           | Copy P4 artifacts into the SBI pod |
| test_functional_bootstrap.py         | run_test_01_bootstrap.sh           | Connect TFS to the P4 switch       |
| test_functional_rules_provision.py   | run_test_02_rules_provision.sh     | Install rules on the P4 switch     |
| test_functional_rules_deprovision.py | run_test_03_rules_deprovision.sh   | Uninstall rules from the P4 switch |
| test_functional_cleanup.py           | run_test_04_cleanup.sh             | Disconnect TFS from the P4 switch  |

Each of the tests above is described in detail below.

### Step 1: Copy the necessary P4 artifacts into the TFS SBI service pod

The setup script copies the necessary artifacts to the SBI service pod.
It should be run just once, after a fresh install of TFS.
If you `deploy/all.sh` again, you need to repeat this step.

```shell
cd ~/tfs-ctrl/
source my_deploy.sh && source tfs_runtime_env_vars.sh
bash src/tests/p4-int-routing-acl/setup.sh
```

### Step 2: Bootstrap topology

The bootstrap script registers the context, topology, links, and devices to TFS.

```shell
cd ~/tfs-ctrl/
bash src/tests/p4-int-routing-acl/run_test_01_bootstrap.sh
```

### Step 3: Provision rules via the SBI API

Implement routing, ACL, and INT functions by installing P4 rules to the Stratum switch via the TFS SBI API.

```shell
cd ~/tfs-ctrl/
bash src/tests/p4-int-routing-acl/run_test_02_rules_provision.sh
```

### Step 4: Deprovision rules via the SBI API

Deprovision the routing, ACL, and INT network functions by removing the previously installed P4 rules (via the TFS SBI API) from the Stratum switch.

```shell
cd ~/tfs-ctrl/
bash src/tests/p4-int-routing-acl/run_test_03_rules_deprovision.sh
```

### Step 4: Deprovision topology

Delete all the objects (context, topology, links, devices) from TFS:

```shell
cd ~/tfs-ctrl/
bash src/tests/p4-int-routing-acl/run_test_04_cleanup.sh
```
+13 −0
Original line number Diff line number Diff line
# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+39 −0
Original line number Diff line number Diff line
{
	"devices": [
		{
			"device_id": {
				"device_uuid": {
					"uuid": "p4-sw1"
				}
			},
			"name": "p4-sw1",
			"device_operational_status": "DEVICEOPERATIONALSTATUS_ENABLED",
			"device_config": {
				"config_rules": [
					{
						"action": "CONFIGACTION_SET",
						"custom": {
							"resource_key": "/tables/table/FabricIngress.acl.acl[1]",
							"resource_value": {
								"table-name": "FabricIngress.acl.acl",
								"match-fields": [
									{
										"match-field": "ig_port",
										"match-value": "1"
									},
									{
										"match-field": "l4_dport",
										"match-value": "8080"
									}
								],
								"action-name": "FabricIngress.acl.drop",
								"action-params": [],
								"priority": 1
							}
						}
					}
				]
			}
		}
	]
}
 No newline at end of file
+136 −0
Original line number Diff line number Diff line
{
	"devices": [
		{
			"device_id": {
				"device_uuid": {
					"uuid": "p4-sw1"
				}
			},
			"name": "p4-sw1",
			"device_operational_status": "DEVICEOPERATIONALSTATUS_ENABLED",
			"device_config": {
				"config_rules": [
					{
						"action": "CONFIGACTION_SET",
						"custom": {
							"resource_key": "/tables/table/FabricIngress.int_watchlist.watchlist[1]",
							"resource_value": {
								"table-name": "FabricIngress.int_watchlist.watchlist",
								"match-fields": [
									{
										"match-field": "ipv4_valid",
										"match-value": "1"
									}
								],
								"action-name": "FabricIngress.int_watchlist.mark_to_report",
								"action-params": [],
								"priority": 1
							}
						}
					},
					{
						"action": "CONFIGACTION_SET",
						"custom": {
							"resource_key": "/tables/table/FabricIngress.filtering.ingress_port_vlan[1]",
							"resource_value": {
								"table-name": "FabricIngress.filtering.ingress_port_vlan",
								"match-fields": [
									{
										"match-field": "ig_port",
										"match-value": "510"
									},
									{
										"match-field": "vlan_is_valid",
										"match-value": "0"
									}
								],
								"action-name": "FabricIngress.filtering.permit_with_internal_vlan",
								"action-params": [
									{
										"action-param": "vlan_id",
										"action-value": "4094"
									},
									{
										"action-param": "port_type",
										"action-value": "3"
									}
								],
								"priority": 10
							}
						}
					},
					{
						"action": "CONFIGACTION_SET",
						"custom": {
							"resource_key": "/tables/table/FabricEgress.egress_next.egress_vlan[1]",
							"resource_value": {
								"table-name": "FabricEgress.egress_next.egress_vlan",
								"match-fields": [
									{
										"match-field": "vlan_id",
										"match-value": "4094"
									},
									{
										"match-field": "eg_port",
										"match-value": "510"
									}
								],
								"action-name": "FabricEgress.egress_next.pop_vlan",
								"action-params": []
							}
						}
					},
					{
						"action": "CONFIGACTION_SET",
						"custom": {
							"resource_key": "/tables/table/FabricIngress.filtering.fwd_classifier[1]",
							"resource_value": {
								"table-name": "FabricIngress.filtering.fwd_classifier",
								"match-fields": [
									{
										"match-field": "ig_port",
										"match-value": "510"
									},
									{
										"match-field": "ip_eth_type",
										"match-value": "0x0800"
									}
								],
								"action-name": "FabricIngress.filtering.set_forwarding_type",
								"action-params": [
									{
										"action-param": "fwd_type",
										"action-value": "2"
									}
								],
								"priority": 1
							}
						}
					},
					{
						"action": "CONFIGACTION_SET",
						"custom": {
							"resource_key": "/tables/table/FabricIngress.int_watchlist.watchlist[2]",
							"resource_value": {
								"table-name": "FabricIngress.int_watchlist.watchlist",
								"match-fields": [
									{
										"match-field": "ipv4_valid",
										"match-value": "1"
									},
									{
										"match-field": "ipv4_dst",
										"match-value": "10.10.10.41&&&0xFFFFFFFF"
									}
								],
								"action-name": "FabricIngress.int_watchlist.no_report_collector",
								"action-params": [],
								"priority": 10
							}
						}
					}
				]
			}
		}
	]
}
+269 −0
Original line number Diff line number Diff line
{
	"devices": [
		{
			"device_id": {
				"device_uuid": {
					"uuid": "p4-sw1"
				}
			},
			"name": "p4-sw1",
			"device_operational_status": "DEVICEOPERATIONALSTATUS_ENABLED",
			"device_config": {
				"config_rules": [
					{
						"action": "CONFIGACTION_SET",
						"custom": {
							"resource_key": "/tables/table/FabricEgress.int_egress.report[1]",
							"resource_value": {
								"table-name": "FabricEgress.int_egress.report",
								"match-fields": [
									{
										"match-field": "bmd_type",
										"match-value": "4"
									},
									{
										"match-field": "mirror_type",
										"match-value": "0"
									},
									{
										"match-field": "int_report_type",
										"match-value": "4"
									}
								],
								"action-name": "FabricEgress.int_egress.do_drop_report_encap",
								"action-params": [
									{
										"action-param": "src_ip",
										"action-value": "10.10.10.120"
									},
									{
										"action-param": "mon_ip",
										"action-value": "10.10.10.41"
									},
									{
										"action-param": "mon_port",
										"action-value": "32766"
									},
									{
										"action-param": "switch_id",
										"action-value": "1"
									}
								]
							}
						}
					},
					{
						"action": "CONFIGACTION_SET",
						"custom": {
							"resource_key": "/tables/table/FabricEgress.int_egress.report[2]",
							"resource_value": {
								"table-name": "FabricEgress.int_egress.report",
								"match-fields": [
									{
										"match-field": "bmd_type",
										"match-value": "2"
									},
									{
										"match-field": "mirror_type",
										"match-value": "1"
									},
									{
										"match-field": "int_report_type",
										"match-value": "4"
									}
								],
								"action-name": "FabricEgress.int_egress.do_drop_report_encap",
								"action-params": [
									{
										"action-param": "src_ip",
										"action-value": "10.10.10.120"
									},
									{
										"action-param": "mon_ip",
										"action-value": "10.10.10.41"
									},
									{
										"action-param": "mon_port",
										"action-value": "32766"
									},
									{
										"action-param": "switch_id",
										"action-value": "1"
									}
								]
							}
						}
					},
					{
						"action": "CONFIGACTION_SET",
						"custom": {
							"resource_key": "/tables/table/FabricEgress.int_egress.report[3]",
							"resource_value": {
								"table-name": "FabricEgress.int_egress.report",
								"match-fields": [
									{
										"match-field": "bmd_type",
										"match-value": "2"
									},
									{
										"match-field": "mirror_type",
										"match-value": "1"
									},
									{
										"match-field": "int_report_type",
										"match-value": "1"
									}
								],
								"action-name": "FabricEgress.int_egress.do_local_report_encap",
								"action-params": [
									{
										"action-param": "src_ip",
										"action-value": "10.10.10.120"
									},
									{
										"action-param": "mon_ip",
										"action-value": "10.10.10.41"
									},
									{
										"action-param": "mon_port",
										"action-value": "32766"
									},
									{
										"action-param": "switch_id",
										"action-value": "1"
									}
								]
							}
						}
					},
					{
						"action": "CONFIGACTION_SET",
						"custom": {
							"resource_key": "/tables/table/FabricEgress.int_egress.report[4]",
							"resource_value": {
								"table-name": "FabricEgress.int_egress.report",
								"match-fields": [
									{
										"match-field": "bmd_type",
										"match-value": "5"
									},
									{
										"match-field": "mirror_type",
										"match-value": "0"
									},
									{
										"match-field": "int_report_type",
										"match-value": "4"
									}
								],
								"action-name": "FabricEgress.int_egress.do_drop_report_encap",
								"action-params": [
									{
										"action-param": "src_ip",
										"action-value": "10.10.10.120"
									},
									{
										"action-param": "mon_ip",
										"action-value": "10.10.10.41"
									},
									{
										"action-param": "mon_port",
										"action-value": "32766"
									},
									{
										"action-param": "switch_id",
										"action-value": "1"
									}
								]
							}
						}
					},
					{
						"action": "CONFIGACTION_SET",
						"custom": {
							"resource_key": "/tables/table/FabricEgress.int_egress.report[5]",
							"resource_value": {
								"table-name": "FabricEgress.int_egress.report",
								"match-fields": [
									{
										"match-field": "bmd_type",
										"match-value": "2"
									},
									{
										"match-field": "mirror_type",
										"match-value": "1"
									},
									{
										"match-field": "int_report_type",
										"match-value": "2"
									}
								],
								"action-name": "FabricEgress.int_egress.do_local_report_encap",
								"action-params": [
									{
										"action-param": "src_ip",
										"action-value": "10.10.10.120"
									},
									{
										"action-param": "mon_ip",
										"action-value": "10.10.10.41"
									},
									{
										"action-param": "mon_port",
										"action-value": "32766"
									},
									{
										"action-param": "switch_id",
										"action-value": "1"
									}
								]
							}
						}
					},
					{
						"action": "CONFIGACTION_SET",
						"custom": {
							"resource_key": "/tables/table/FabricEgress.int_egress.report[6]",
							"resource_value": {
								"table-name": "FabricEgress.int_egress.report",
								"match-fields": [
									{
										"match-field": "bmd_type",
										"match-value": "2"
									},
									{
										"match-field": "mirror_type",
										"match-value": "1"
									},
									{
										"match-field": "int_report_type",
										"match-value": "3"
									}
								],
								"action-name": "FabricEgress.int_egress.do_local_report_encap",
								"action-params": [
									{
										"action-param": "src_ip",
										"action-value": "10.10.10.120"
									},
									{
										"action-param": "mon_ip",
										"action-value": "10.10.10.41"
									},
									{
										"action-param": "mon_port",
										"action-value": "32766"
									},
									{
										"action-param": "switch_id",
										"action-value": "1"
									}
								]
							}
						}
					}
				]
			}
		}
	]
}
Loading