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

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

feat: P4 In-band Network Telemetry (INT) service handler

See merge request !334
parents 482b2d0c b63be543
No related branches found
No related tags found
1 merge request!334feat: P4 In-band Network Telemetry (INT) service handler
Showing
with 1169 additions and 0 deletions
......@@ -26,6 +26,7 @@ from .l3nm_nce.L3NMNCEServiceHandler import L3NMNCEServiceHandler
from .l3slice_ietfslice.L3SliceIETFSliceServiceHandler import L3NMSliceIETFSliceServiceHandler
from .microwave.MicrowaveServiceHandler import MicrowaveServiceHandler
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 .tapi_tapi.TapiServiceHandler import TapiServiceHandler
from .tapi_xr.TapiXrServiceHandler import TapiXrServiceHandler
from .e2e_orch.E2EOrchestratorServiceHandler import E2EOrchestratorServiceHandler
......@@ -111,6 +112,12 @@ SERVICE_HANDLERS = [
FilterFieldEnum.DEVICE_DRIVER: DeviceDriverEnum.DEVICEDRIVER_P4,
}
]),
(P4FabricINTServiceHandler, [
{
FilterFieldEnum.SERVICE_TYPE: ServiceTypeEnum.SERVICETYPE_INT,
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 typing import List, Tuple
from common.proto.context_pb2 import ConfigActionEnum
from common.tools.object_factory.ConfigRule import json_config_rule
from common.type_checkers.Checkers import chk_address_ipv4, chk_transport_port
from service.service.service_handlers.p4_fabric_tna_commons.p4_fabric_tna_commons import *
LOGGER = logging.getLogger(__name__)
# INT service handler settings
INT_COLLECTOR_INFO = "int_collector_info"
INT_REPORT_MIRROR_ID_LIST = "int_report_mirror_id_list"
PORT_INT = "int_port" # In-band Network Telemetry transport port (of the collector)
# INT tables
TABLE_INT_WATCHLIST = "FabricIngress.int_watchlist.watchlist"
TABLE_INT_EGRESS_REPORT = "FabricEgress.int_egress.report"
# Mirror IDs for INT reports
INT_REPORT_MIRROR_ID_LIST_TNA = [0x200, 0x201, 0x202, 0x203] # Tofino-2 (2-pipe Tofino switches use only the first 2 entries)
INT_REPORT_MIRROR_ID_LIST_V1MODEL = [0x1FA] # Variable V1MODEL_INT_MIRROR_SESSION in p4 source program
# INT report types
INT_REPORT_TYPE_NO_REPORT = 0
INT_REPORT_TYPE_FLOW = 1
INT_REPORT_TYPE_QUEUE = 2
INT_REPORT_TYPE_DROP = 4
def rules_set_up_int_watchlist(action : ConfigActionEnum) -> List [Tuple]: # type: ignore
rule_no = cache_rule(TABLE_INT_WATCHLIST, action)
rules_int_watchlist = []
rules_int_watchlist.append(
json_config_rule(
action,
'/tables/table/'+TABLE_INT_WATCHLIST+'['+str(rule_no)+']',
{
'table-name': TABLE_INT_WATCHLIST,
'match-fields': [
{
'match-field': 'ipv4_valid',
'match-value': '1'
}
],
'action-name': 'FabricIngress.int_watchlist.mark_to_report',
'action-params': [],
'priority': 1
}
)
)
return rules_int_watchlist
def rules_set_up_int_report_collector(
int_collector_ip : str,
action : ConfigActionEnum) -> List [Tuple]: # type: ignore
assert chk_address_ipv4(int_collector_ip), "Invalid INT collector IPv4 address to configure watchlist"
rule_no = cache_rule(TABLE_INT_WATCHLIST, action)
rules_int_col_report = []
rules_int_col_report.append(
json_config_rule(
action,
'/tables/table/'+TABLE_INT_WATCHLIST+'['+str(rule_no)+']',
{
'table-name': TABLE_INT_WATCHLIST,
'match-fields': [
{
'match-field': 'ipv4_valid',
'match-value': '1'
},
{
'match-field': 'ipv4_dst',
'match-value': int_collector_ip+'&&&0xFFFFFFFF'
}
],
'action-name': 'FabricIngress.int_watchlist.no_report_collector',
'action-params': [],
'priority': 10
}
)
)
return rules_int_col_report
def rules_set_up_int_recirculation_ports(
recirculation_port_list : List,
port_type : str,
fwd_type : int,
vlan_id : int,
action : ConfigActionEnum): # type: ignore
rules_list = []
for port in recirculation_port_list:
rules_list.extend(
rules_set_up_port(
port=port,
port_type=port_type,
fwd_type=fwd_type,
vlan_id=vlan_id,
action=action
)
)
LOGGER.debug("INT recirculation ports configured:{}".format(recirculation_port_list))
return rules_list
def rules_set_up_int_report_flow(
switch_id : int,
src_ip : str,
int_collector_ip : str,
int_collector_port : int,
action : ConfigActionEnum) -> List [Tuple]: # type: ignore
assert switch_id > 0, "Invalid switch identifier to configure egress INT report"
assert chk_address_ipv4(src_ip), "Invalid source IPv4 address to configure egress INT report"
assert chk_address_ipv4(int_collector_ip), "Invalid INT collector IPv4 address to configure egress INT report"
assert chk_transport_port(int_collector_port), "Invalid INT collector port number to configure egress INT report"
rule_no = cache_rule(TABLE_INT_EGRESS_REPORT, action)
rules_int_egress = []
# Rule #1
rules_int_egress.append(
json_config_rule(
action,
'/tables/table/'+TABLE_INT_EGRESS_REPORT+'['+str(rule_no)+']',
{
'table-name': TABLE_INT_EGRESS_REPORT,
'match-fields': [
{
'match-field': 'bmd_type',
'match-value': str(BRIDGED_MD_TYPE_INT_INGRESS_DROP)
},
{
'match-field': 'mirror_type',
'match-value': str(MIRROR_TYPE_INVALID)
},
{
'match-field': 'int_report_type',
'match-value': str(INT_REPORT_TYPE_DROP)
}
],
'action-name': 'FabricEgress.int_egress.do_drop_report_encap',
'action-params': [
{
'action-param': 'switch_id',
'action-value': str(switch_id)
},
{
'action-param': 'src_ip',
'action-value': src_ip
},
{
'action-param': 'mon_ip',
'action-value': int_collector_ip
},
{
'action-param': 'mon_port',
'action-value': str(int_collector_port)
}
]
}
)
)
rule_no = cache_rule(TABLE_INT_EGRESS_REPORT, action)
# Rule #2
rules_int_egress.append(
json_config_rule(
action,
'/tables/table/'+TABLE_INT_EGRESS_REPORT+'['+str(rule_no)+']',
{
'table-name': TABLE_INT_EGRESS_REPORT,
'match-fields': [
{
'match-field': 'bmd_type',
'match-value': str(BRIDGED_MD_TYPE_EGRESS_MIRROR)
},
{
'match-field': 'mirror_type',
'match-value': str(MIRROR_TYPE_INT_REPORT)
},
{
'match-field': 'int_report_type',
'match-value': str(INT_REPORT_TYPE_DROP)
}
],
'action-name': 'FabricEgress.int_egress.do_drop_report_encap',
'action-params': [
{
'action-param': 'switch_id',
'action-value': str(switch_id)
},
{
'action-param': 'src_ip',
'action-value': src_ip
},
{
'action-param': 'mon_ip',
'action-value': int_collector_ip
},
{
'action-param': 'mon_port',
'action-value': str(int_collector_port)
}
]
}
)
)
rule_no = cache_rule(TABLE_INT_EGRESS_REPORT, action)
# Rule #3
rules_int_egress.append(
json_config_rule(
action,
'/tables/table/'+TABLE_INT_EGRESS_REPORT+'['+str(rule_no)+']',
{
'table-name': TABLE_INT_EGRESS_REPORT,
'match-fields': [
{
'match-field': 'bmd_type',
'match-value': str(BRIDGED_MD_TYPE_EGRESS_MIRROR)
},
{
'match-field': 'mirror_type',
'match-value': str(MIRROR_TYPE_INT_REPORT)
},
{
'match-field': 'int_report_type',
'match-value': str(INT_REPORT_TYPE_FLOW)
}
],
'action-name': 'FabricEgress.int_egress.do_local_report_encap',
'action-params': [
{
'action-param': 'switch_id',
'action-value': str(switch_id)
},
{
'action-param': 'src_ip',
'action-value': src_ip
},
{
'action-param': 'mon_ip',
'action-value': int_collector_ip
},
{
'action-param': 'mon_port',
'action-value': str(int_collector_port)
}
]
}
)
)
rule_no = cache_rule(TABLE_INT_EGRESS_REPORT, action)
# Rule #4
rules_int_egress.append(
json_config_rule(
action,
'/tables/table/'+TABLE_INT_EGRESS_REPORT+'['+str(rule_no)+']',
{
'table-name': TABLE_INT_EGRESS_REPORT,
'match-fields': [
{
'match-field': 'bmd_type',
'match-value': str(BRIDGED_MD_TYPE_DEFLECTED)
},
{
'match-field': 'mirror_type',
'match-value': str(MIRROR_TYPE_INVALID)
},
{
'match-field': 'int_report_type',
'match-value': str(INT_REPORT_TYPE_DROP)
}
],
'action-name': 'FabricEgress.int_egress.do_drop_report_encap',
'action-params': [
{
'action-param': 'switch_id',
'action-value': str(switch_id)
},
{
'action-param': 'src_ip',
'action-value': src_ip
},
{
'action-param': 'mon_ip',
'action-value': int_collector_ip
},
{
'action-param': 'mon_port',
'action-value': str(int_collector_port)
}
]
}
)
)
rule_no = cache_rule(TABLE_INT_EGRESS_REPORT, action)
# Rule #5
rules_int_egress.append(
json_config_rule(
action,
'/tables/table/'+TABLE_INT_EGRESS_REPORT+'['+str(rule_no)+']',
{
'table-name': TABLE_INT_EGRESS_REPORT,
'match-fields': [
{
'match-field': 'bmd_type',
'match-value': str(BRIDGED_MD_TYPE_EGRESS_MIRROR)
},
{
'match-field': 'mirror_type',
'match-value': str(MIRROR_TYPE_INT_REPORT)
},
{
'match-field': 'int_report_type',
'match-value': str(INT_REPORT_TYPE_QUEUE)
}
],
'action-name': 'FabricEgress.int_egress.do_local_report_encap',
'action-params': [
{
'action-param': 'switch_id',
'action-value': str(switch_id)
},
{
'action-param': 'src_ip',
'action-value': src_ip
},
{
'action-param': 'mon_ip',
'action-value': int_collector_ip
},
{
'action-param': 'mon_port',
'action-value': str(int_collector_port)
}
]
}
)
)
rule_no = cache_rule(TABLE_INT_EGRESS_REPORT, action)
# Rule #6
rules_int_egress.append(
json_config_rule(
action,
'/tables/table/'+TABLE_INT_EGRESS_REPORT+'['+str(rule_no)+']',
{
'table-name': TABLE_INT_EGRESS_REPORT,
'match-fields': [
{
'match-field': 'bmd_type',
'match-value': str(BRIDGED_MD_TYPE_EGRESS_MIRROR)
},
{
'match-field': 'mirror_type',
'match-value': str(MIRROR_TYPE_INT_REPORT)
},
{
'match-field': 'int_report_type',
'match-value': str(INT_REPORT_TYPE_QUEUE | INT_REPORT_TYPE_FLOW)
}
],
'action-name': 'FabricEgress.int_egress.do_local_report_encap',
'action-params': [
{
'action-param': 'switch_id',
'action-value': str(switch_id)
},
{
'action-param': 'src_ip',
'action-value': src_ip
},
{
'action-param': 'mon_ip',
'action-value': int_collector_ip
},
{
'action-param': 'mon_port',
'action-value': str(int_collector_port)
}
]
}
)
)
return rules_int_egress
......@@ -120,6 +120,25 @@ cd ~/tfs-ctrl/
bash src/tests/p4-fabric-tna/run_test_02b_sbi_deprovision_int_l2_l3_acl.sh
```
### Step 3: Manage L2, L3, ACL, and INT via the Service API
To avoid interacting with the switch using low-level P4 rules (via the SBI), we created modular network services, which allow users to easily provision L2, L3, ACL, and INT network functions.
These services require users to define the service endpoints as well as some high-level service configuration, while leaving the rest of complexity to tailored service handlers that interact with the SBI on behalf of the user.
#### Provision INT service via the Service API
```shell
cd ~/tfs-ctrl/
bash src/tests/p4-fabric-tna/run_test_06a_service_provision_int.sh
```
#### Deprovision INT service via the Service API
```shell
cd ~/tfs-ctrl/
bash src/tests/p4-fabric-tna/run_test_06b_service_deprovision_int.sh
```
### Step 4: Deprovision topology
Delete all the objects (context, topology, links, devices) from TFS:
......
{
"services": [
{
"service_id": {
"context_id": {"context_uuid": {"uuid": "admin"}}, "service_uuid": {"uuid": "p4-service-int"}
},
"name": "p4-service-int",
"service_type": "SERVICETYPE_INT",
"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,
"mac": "fa:16:3e:93:8c:c0",
"ip": "10.10.10.120",
"int_port": {
"port_id": 3,
"port_type": "host"
}
}
},
"int_collector_info": {
"mac": "fa:16:3e:fb:cf:96",
"ip": "10.10.10.41",
"port": 32766,
"vlan_id": 4094
}
}
}
}
]
},
"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_int.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_int.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_int(
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_INT)
for service in response.services:
# Ignore services of other types
if service.service_type != ServiceTypeEnum.SERVICETYPE_INT:
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 INT 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, "INT service must contain some rules"
assert rules_diff == P4_DEV_NB * INT_RULES, "INT service must contain {} rules per device".format(INT_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 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_int(
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_INT,
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_INT)
# 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, "INT service must install some rules"
assert rules_diff == P4_DEV_NB * INT_RULES, "INT service must install {} rules per device".format(INT_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