Skip to content
Snippets Groups Projects
Commit d54e917a authored by Georgios Katsikas's avatar Georgios Katsikas
Browse files

Merge branch 'pr-p4-acl' into 'pr-p4-integration'

feat: P4 ACL service handler

See merge request !337
parents 50980366 e532fd15
No related branches found
No related tags found
1 merge request!337feat: P4 ACL service handler
Showing
with 849 additions and 0 deletions
......@@ -29,6 +29,7 @@ from .p4_dummy_l1.p4_dummy_l1_service_handler import P4DummyL1ServiceHandler
from .p4_fabric_tna_int.p4_fabric_tna_int_service_handler import P4FabricINTServiceHandler
from .p4_fabric_tna_l2_simple.p4_fabric_tna_l2_simple_service_handler import P4FabricL2SimpleServiceHandler
from .p4_fabric_tna_l3.p4_fabric_tna_l3_service_handler import P4FabricL3ServiceHandler
from .p4_fabric_tna_acl.p4_fabric_tna_acl_service_handler import P4FabricACLServiceHandler
from .tapi_tapi.TapiServiceHandler import TapiServiceHandler
from .tapi_xr.TapiXrServiceHandler import TapiXrServiceHandler
from .e2e_orch.E2EOrchestratorServiceHandler import E2EOrchestratorServiceHandler
......@@ -132,6 +133,12 @@ SERVICE_HANDLERS = [
FilterFieldEnum.DEVICE_DRIVER: DeviceDriverEnum.DEVICEDRIVER_P4,
}
]),
(P4FabricACLServiceHandler, [
{
FilterFieldEnum.SERVICE_TYPE: ServiceTypeEnum.SERVICETYPE_ACL,
FilterFieldEnum.DEVICE_DRIVER: DeviceDriverEnum.DEVICEDRIVER_P4,
}
]),
(L2NM_IETFL2VPN_ServiceHandler, [
{
FilterFieldEnum.SERVICE_TYPE : ServiceTypeEnum.SERVICETYPE_L2NM,
......
# 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.
# 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.
"""
Common objects and methods for In-band Network Telemetry (INT) dataplane
based on the SD-Fabric dataplane model.
This dataplane covers both software based and hardware-based Stratum-enabled P4 switches,
such as the BMv2 software switch and Intel's Tofino/Tofino-2 switches.
SD-Fabric repo: https://github.com/stratum/fabric-tna
SD-Fabric docs: https://docs.sd-fabric.org/master/index.html
"""
import logging
from service.service.service_handlers.p4_fabric_tna_commons.p4_fabric_tna_commons import *
LOGGER = logging.getLogger(__name__)
# ACL service handler settings
ACL = "acl"
ACTION = "action"
ACTION_DROP = "drop"
ACTION_ALLOW = "allow"
ACTION_LIST = [ACTION_ALLOW, ACTION_DROP]
def is_valid_acl_action(action : str) -> bool:
return action in ACTION_LIST
......@@ -153,6 +153,20 @@ cd ~/tfs-ctrl/
bash src/tests/p4-fabric-tna/run_test_04b_service_deprovision_l3.sh
```
#### Provision ACL network service via the Service API
```shell
cd ~/tfs-ctrl/
bash src/tests/p4-fabric-tna/run_test_05a_service_provision_acl.sh
```
#### Deprovision ACL network service via the Service API
```shell
cd ~/tfs-ctrl/
bash src/tests/p4-fabric-tna/run_test_05b_service_deprovision_acl.sh
```
#### Provision INT service via the Service API
```shell
......
{
"services": [
{
"service_id": {
"context_id": {"context_uuid": {"uuid": "admin"}}, "service_uuid": {"uuid": "p4-service-acl"}
},
"name": "p4-service-acl",
"service_type": "SERVICETYPE_ACL",
"service_status": {"service_status": "SERVICESTATUS_PLANNED"},
"service_endpoint_ids": [
{
"device_id": {"device_uuid": {"uuid": "p4-sw1"}},
"endpoint_uuid": {"uuid": "1"}
},
{
"device_id": {"device_uuid": {"uuid": "p4-sw1"}},
"endpoint_uuid": {"uuid": "2"}
}
],
"service_config": {
"config_rules": [
{
"action": "CONFIGACTION_SET",
"custom": {
"resource_key": "/settings",
"resource_value": {
"switch_info": {
"p4-sw1": {
"arch": "v1model",
"dpid": 1,
"acl": [
{
"port_id": 1,
"trn_port_dst": 8080,
"action": "drop"
},
{
"port_id": 1,
"trn_port_src": 12345,
"action": "drop"
},
{
"port_id": 1,
"ipv4_dst": "172.16.10.10",
"ipv4_prefix_len": 32,
"action": "drop"
},
{
"port_id": 2,
"ipv4_src": "172.16.10.10",
"ipv4_prefix_len": 32,
"action": "drop"
}
]
}
}
}
}
}
]
},
"service_constraints": []
}
]
}
#!/bin/bash
# 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.
source tfs_runtime_env_vars.sh
python3 -m pytest --verbose src/tests/p4-fabric-tna/tests-service/test_functional_service_provision_acl.py
#!/bin/bash
# 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.
source tfs_runtime_env_vars.sh
python3 -m pytest --verbose src/tests/p4-fabric-tna/tests-service/test_functional_service_deprovision_acl.py
# 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.
import logging
from common.proto.context_pb2 import ServiceId, ServiceStatusEnum, ServiceTypeEnum
from common.tools.grpc.Tools import grpc_message_to_json_string
from common.tools.object_factory.Service import json_service_id
from context.client.ContextClient import ContextClient
from service.client.ServiceClient import ServiceClient
from tests.Fixtures import context_client, service_client # pylint: disable=unused-import
from tests.tools.test_tools_p4 import *
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)
def test_service_deletion_acl(
context_client : ContextClient, # pylint: disable=redefined-outer-name
service_client : ServiceClient # pylint: disable=redefined-outer-name
) -> None:
# Get the current number of devices
response = context_client.ListDevices(ADMIN_CONTEXT_ID)
LOGGER.warning('Devices[{:d}] = {:s}'.format(len(response.devices), grpc_message_to_json_string(response)))
# Total devices
dev_nb = len(response.devices)
assert dev_nb == DEV_NB
# P4 devices
p4_dev_nb = identify_number_of_p4_devices(response.devices)
assert p4_dev_nb == P4_DEV_NB
# Get the current number of rules in the P4 devices
p4_rules_before_deletion = get_number_of_rules(response.devices)
# Get the current number of services
response = context_client.ListServices(ADMIN_CONTEXT_ID)
services_nb_before_deletion = len(response.services)
assert verify_active_service_type(response.services, ServiceTypeEnum.SERVICETYPE_ACL)
for service in response.services:
# Ignore services of other types
if service.service_type != ServiceTypeEnum.SERVICETYPE_ACL:
continue
service_id = service.service_id
assert service_id
service_uuid = service_id.service_uuid.uuid
context_uuid = service_id.context_id.context_uuid.uuid
assert service.service_status.service_status == ServiceStatusEnum.SERVICESTATUS_ACTIVE
# Delete ACL service
service_client.DeleteService(ServiceId(**json_service_id(service_uuid, json_context_id(context_uuid))))
# Get an updated view of the services
response = context_client.ListServices(ADMIN_CONTEXT_ID)
services_nb_after_deletion = len(response.services)
assert services_nb_after_deletion == services_nb_before_deletion - 1, "Exactly one new service must be deleted"
# Get an updated view of the devices
response = context_client.ListDevices(ADMIN_CONTEXT_ID)
p4_rules_after_deletion = get_number_of_rules(response.devices)
rules_diff = p4_rules_before_deletion - p4_rules_after_deletion
assert p4_rules_after_deletion < p4_rules_before_deletion, "ACL service must contain some rules"
assert rules_diff == P4_DEV_NB * ACL_RULES, "ACL service must contain {} rules per device".format(ACL_RULES)
# 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.
import logging
from common.proto.context_pb2 import ServiceStatusEnum, ServiceTypeEnum
from common.tools.descriptor.Loader import DescriptorLoader, check_descriptor_load_results
from common.tools.grpc.Tools import grpc_message_to_json_string
from context.client.ContextClient import ContextClient
from device.client.DeviceClient import DeviceClient
from service.client.ServiceClient import ServiceClient
from tests.Fixtures import context_client, device_client, service_client # pylint: disable=unused-import
from tests.tools.test_tools_p4 import *
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)
def test_service_creation_acl(
context_client : ContextClient, # pylint: disable=redefined-outer-name
device_client : DeviceClient, # pylint: disable=redefined-outer-name
service_client : ServiceClient # pylint: disable=redefined-outer-name
) -> None:
# Get the current number of services
response = context_client.ListServices(ADMIN_CONTEXT_ID)
services_nb_before = len(response.services)
# Get the current number of devices
response = context_client.ListDevices(ADMIN_CONTEXT_ID)
LOGGER.warning('Devices[{:d}] = {:s}'.format(len(response.devices), grpc_message_to_json_string(response)))
# Total devices
dev_nb = len(response.devices)
assert dev_nb == DEV_NB
# P4 devices
p4_dev_nb = identify_number_of_p4_devices(response.devices)
assert p4_dev_nb == P4_DEV_NB
# Get the current number of rules in the P4 devices
p4_rules_before = get_number_of_rules(response.devices)
# Load service
descriptor_loader = DescriptorLoader(
descriptors_file=DESC_FILE_SERVICE_CREATE_ACL,
context_client=context_client, device_client=device_client, service_client=service_client
)
results = descriptor_loader.process()
check_descriptor_load_results(results, descriptor_loader)
# Get an updated view of the services
response = context_client.ListServices(ADMIN_CONTEXT_ID)
services_nb_after = len(response.services)
assert services_nb_after == services_nb_before + 1, "Exactly one new service must be in place"
assert verify_active_service_type(response.services, ServiceTypeEnum.SERVICETYPE_ACL)
# Get an updated view of the devices
response = context_client.ListDevices(ADMIN_CONTEXT_ID)
p4_rules_after = get_number_of_rules(response.devices)
rules_diff = p4_rules_after - p4_rules_before
assert p4_rules_after > p4_rules_before, "ACL service must install some rules"
assert rules_diff == P4_DEV_NB * ACL_RULES, "ACL service must install {} rules per device".format(ACL_RULES)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment