diff --git a/.gitignore b/.gitignore index f16afd3e9872853782cdc698ce567780da54c857..d4f18656d89df0abc25f8d93dcf2336fce662355 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ swagger/__pycache__/ src/__pycache__/ venv/ .env - +slice.db diff --git a/src/mapper/main.py b/src/mapper/main.py index 84be5720b12d6c4987094c1ca37b0e29c1cc568b..b7389356ba436ffa6a72afa04b9433eb8dfbe308 100644 --- a/src/mapper/main.py +++ b/src/mapper/main.py @@ -43,7 +43,6 @@ def mapper(ietf_intent): # Extract Service Level Objectives (SLOs) from the intent slos = ietf_intent["ietf-network-slice-service:network-slice-services"]["slo-sle-templates"]["slo-sle-template"][0]["slo-policy"]["metric-bound"] - print(f"SLOs: {slos}") if slos: # Find candidate NRPs that can meet the SLO requirements candidates = [ diff --git a/src/realizer/main.py b/src/realizer/main.py index 2bd898363176c2931629e32314aad15a59a22274..e1f08a0ae6c6c899f6d7784cee1fd50e69a5eb45 100644 --- a/src/realizer/main.py +++ b/src/realizer/main.py @@ -12,10 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -# This file is an original contribution from Telefonica Innovación Digital S.L. +# This file includes original contributions from Telefonica Innovación Digital S.L. +import logging from .select_way import select_way from .nrp_handler import nrp_handler +from src.utils.safe_get import safe_get def realizer(ietf_intent, need_nrp=False, order=None, nrp=None, controller_type=None, response=None): """ @@ -37,7 +39,6 @@ def realizer(ietf_intent, need_nrp=False, order=None, nrp=None, controller_type= return nrp_view else: # Select slice service method - way = ietf_intent["ietf-network-slice-service:network-slice-services"]["slice-service"][0]["service-tags"]["tag-type"]["value"] - way = "L2VPN" + way = safe_get(ietf_intent, ['ietf-network-slice-service:network-slice-services', 'slice-service', 0, 'service-tags', 'tag-type', 0, 'tag-type-value', 0]) request = select_way(controller=controller_type, way=way, ietf_intent=ietf_intent, response=response) return request diff --git a/src/realizer/tfs/main.py b/src/realizer/tfs/main.py index 9e1233eb6ba593ee861ffc612d5e9134f40648b1..2975127272d181620d623b33092f70e158f015e5 100644 --- a/src/realizer/tfs/main.py +++ b/src/realizer/tfs/main.py @@ -19,11 +19,11 @@ from .service_types.tfs_l2vpn import tfs_l2vpn from .service_types.tfs_l3vpn import tfs_l3vpn def tfs(ietf_intent, way=None, response=None): - if way == "L2VPN": + if way == "L2": realizing_request = tfs_l2vpn(ietf_intent, response) - elif way == "L3VPN": + elif way == "L3": realizing_request = tfs_l3vpn(ietf_intent, response) else: - logging.warning(f"Unsupported way: {way}. Defaulting to L2VPN realization.") + logging.warning(f"Unsupported way: {way}. Defaulting to L2 realization.") realizing_request = tfs_l2vpn(ietf_intent, response) return realizing_request \ No newline at end of file diff --git a/src/templates/ietf_template_empty.json b/src/templates/ietf_template_empty.json index cdaf66cdad3fbd7f01c09a7987cf8729600952b0..c484a4a2991e0b34ce691ee14125c2fddb00fa41 100644 --- a/src/templates/ietf_template_empty.json +++ b/src/templates/ietf_template_empty.json @@ -29,10 +29,14 @@ "id":"5GSliceMapping", "description":"example 5G Slice mapping", "service-tags":{ - "tag-type":{ - "tag-type":"", - "value":"" + "tag-type": [ + { + "tag-type": "", + "tag-type-value": [ + "" + ] } + ] }, "slo-sle-policy":{ "slo-sle-template":"" diff --git a/src/utils/safe_get.py b/src/utils/safe_get.py new file mode 100644 index 0000000000000000000000000000000000000000..a12d885dbe770800165eee603a45c2fa716041a7 --- /dev/null +++ b/src/utils/safe_get.py @@ -0,0 +1,26 @@ +# Copyright 2022-2025 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. + +# This file is an original contribution from Telefonica Innovación Digital S.L. + +def safe_get(dct, keys): + """Safely get a nested value from a dictionary or list.""" + for key in keys: + if isinstance(dct, dict) and key in dct: + dct = dct[key] + elif isinstance(dct, list) and isinstance(key, int) and key < len(dct): + dct = dct[key] + else: + return None + return dct