diff --git a/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/Dockerfile b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..a624152de7d9188067a5828b4a8958b8d3418694 --- /dev/null +++ b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/Dockerfile @@ -0,0 +1,37 @@ +# 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. + +FROM python:3.9-slim + +# Set Python to show logs as they occur +ENV PYTHONUNBUFFERED=0 + +# Get generic Python packages +RUN python3 -m pip install --upgrade pip +RUN python3 -m pip install --upgrade setuptools wheel +RUN python3 -m pip install --upgrade pip-tools + +# Create component sub-folders, and copy content +RUN mkdir -p /var/teraflow/mock_ietf_network_slice_sdn_ctrl +WORKDIR /var/teraflow/mock_ietf_network_slice_sdn_ctrl +COPY . . + +# Get specific Python packages +RUN pip-compile --quiet --output-file=requirements.txt requirements.in +RUN python3 -m pip install -r requirements.txt + +RUN python3 -m pip list + +# Start the service +ENTRYPOINT ["python", "MockIetfNetworkSliceSdnCtrl.py"] diff --git a/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/MockIetfNetworkSliceSdnCtrl.py b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/MockIetfNetworkSliceSdnCtrl.py new file mode 100644 index 0000000000000000000000000000000000000000..59b7f609ee515d2edea6455da6deb03efdb245e3 --- /dev/null +++ b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/MockIetfNetworkSliceSdnCtrl.py @@ -0,0 +1,88 @@ +# 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. + +# Mock IETF ACTN SDN controller +# ----------------------------- +# REST server implementing minimal support for: +# - IETF YANG Data Model for Transport Network Client Signals +# Ref: https://www.ietf.org/archive/id/draft-ietf-ccamp-client-signal-yang-10.html +# - IETF YANG Data Model for Traffic Engineering Tunnels, Label Switched Paths and Interfaces +# Ref: https://www.ietf.org/archive/id/draft-ietf-teas-yang-te-34.html + + +import functools, logging, sys, time +from flask import Flask, jsonify, make_response, request +from flask_restful import Api, Resource +from ResourceNetworkSlices import NetworkSliceService, NetworkSliceServices +from ResourceConnectionGroups import ConnectionGroup + +BIND_ADDRESS = "0.0.0.0" +BIND_PORT = 8443 +BASE_URL = "/restconf/data/ietf-network-slice-service:network-slice-services" +STR_ENDPOINT = "http://{:s}:{:s}{:s}".format( + str(BIND_ADDRESS), str(BIND_PORT), str(BASE_URL) +) +LOG_LEVEL = logging.DEBUG + +logging.basicConfig( + level=LOG_LEVEL, format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s" +) +LOGGER = logging.getLogger(__name__) + +logging.getLogger("werkzeug").setLevel(logging.WARNING) + + +def log_request(logger: logging.Logger, response): + timestamp = time.strftime("[%Y-%b-%d %H:%M]") + logger.info( + "%s %s %s %s %s", + timestamp, + request.remote_addr, + request.method, + request.full_path, + response.status, + ) + return response + + +class Health(Resource): + def get(self): + return make_response(jsonify({}), 200) + + +def main(): + LOGGER.info("Starting...") + + app = Flask(__name__) + app.after_request(functools.partial(log_request, LOGGER)) + + api = Api(app, prefix=BASE_URL) + api.add_resource(Health, "/") + api.add_resource(NetworkSliceServices, BASE_URL) + api.add_resource(NetworkSliceService, BASE_URL + "/slice-service=<string:slice_id>") + api.add_resource( + ConnectionGroup, + BASE_URL + + "/slice-service=<string:slice_id>/connection-groups/connection-group=<string:connection_group_id>", + ) + + LOGGER.info("Listening on {:s}...".format(str(STR_ENDPOINT))) + app.run(debug=True, host=BIND_ADDRESS, port=BIND_PORT, ssl_context="adhoc") + + LOGGER.info("Bye") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/README.md b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e547f719aa19f43c9e7a52c43276efa7f7acc328 --- /dev/null +++ b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/README.md @@ -0,0 +1,31 @@ +# Mock IETF ACTN SDN Controller + +This REST server implements very basic support for the following YANG data models: +- IETF YANG Data Model for Transport Network Client Signals (draft-ietf-ccamp-client-signal-yang-10) + - Ref: https://datatracker.ietf.org/doc/draft-ietf-teas-ietf-network-slice-nbi-yang/ + +The aim of this server is to enable testing ietf netowrk slice service driver and ietf slice service service handler + + +## 1. Install requirements for the Mock IETF Network Slice SDN controller +__NOTE__: if you run the Mock IETF Network Slice SDN controller from the PyEnv used for developing on the TeraFlowSDN +framework and you followed the official steps in +[Development Guide > Configure Environment > Python](https://labs.etsi.org/rep/tfs/controller/-/wikis/2.-Development-Guide/2.1.-Configure-Environment/2.1.1.-Python), +all the requirements are already in place. Install them only if you execute it in a separate/standalone environment. + +Install the required dependencies as follows: +```bash +pip install -r src/tests/tools/mock_ietf_network_slice_sdn_ctrl/requirements.in +``` + +Run the Mock IETF Network Slice SDN Controller as follows: +```bash +python src/tests/tools/mock_ietf_network_slice_sdn_ctrl/MockIetfNetworkSliceSdnCtrl.py +``` + + +## 2. Run the Mock IETF Network Slice SDN controller +Run the Mock IETF Network Slice SDN Controller as follows: +```bash +python src/tests/tools/mock_ietf_network_slice_sdn_ctrl/MockIetfNetworkSliceSdnCtrl.py +``` diff --git a/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/ResourceConnectionGroups.py b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/ResourceConnectionGroups.py new file mode 100644 index 0000000000000000000000000000000000000000..19c84e181a97354940fd3dca8f3d6396c0a50068 --- /dev/null +++ b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/ResourceConnectionGroups.py @@ -0,0 +1,31 @@ +# 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. + +# REST-API resource implementing minimal support for "IETF YANG Data Model for Transport Network Client Signals". +# Ref: https://www.ietf.org/archive/id/draft-ietf-ccamp-client-signal-yang-10.html + +from flask import jsonify, make_response, request +from flask_restful import Resource + +CONNECTION_GROUPS = [] + + +class ConnectionGroup(Resource): + def get(self, slice_id: str, connection_group_id: str): + return make_response(jsonify(CONNECTION_GROUPS), 200) + + def put(self, slice_id: str, connection_group_id: str): + json_request = request.get_json() + CONNECTION_GROUPS.append(json_request) + return make_response(jsonify({}), 200) diff --git a/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/ResourceNetworkSlices.py b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/ResourceNetworkSlices.py new file mode 100644 index 0000000000000000000000000000000000000000..80840f8da13e00af689c7b84e9577e952d9e2adf --- /dev/null +++ b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/ResourceNetworkSlices.py @@ -0,0 +1,39 @@ +# 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. + +# REST-API resource implementing minimal support for "IETF YANG Data Model for Transport Network Client Signals". +# Ref: https://www.ietf.org/archive/id/draft-ietf-ccamp-client-signal-yang-10.html + +from flask import jsonify, make_response, request +from flask_restful import Resource + +NETWORK_SLICES = {} + + +class NetworkSliceServices(Resource): + def get(self): + return make_response(jsonify(NETWORK_SLICES), 200) + + def post(self): + json_request = request.get_json() + name = json_request["network-slice-services"]["slice-service"][0]["id"] + NETWORK_SLICES[name] = json_request + return make_response(jsonify({}), 201) + + +class NetworkSliceService(Resource): + def delete(self, slice_id: str): + slice = NETWORK_SLICES.pop(slice_id, None) + data, status = ({}, 404) if slice is None else (slice, 204) + return make_response(jsonify(data), status) diff --git a/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/__init__.py b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..3ccc21c7db78aac26daa1f8c5ff8e1ffd3f35460 --- /dev/null +++ b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/__init__.py @@ -0,0 +1,14 @@ +# 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. + diff --git a/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/build.sh b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/build.sh new file mode 100755 index 0000000000000000000000000000000000000000..8e4dda34d7c83ef76c9944bcf52475de05d5238d --- /dev/null +++ b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/build.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# 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. + +# Make folder containing the script the root folder for its execution +cd $(dirname $0) + +docker build -t mock-ietf-network-slice-sdn-ctrl:test -f Dockerfile . +docker tag mock-ietf-network-slice-sdn-ctrl:test localhost:32000/tfs/mock-ietf-network-slice-sdn-ctrl:test +docker push localhost:32000/tfs/mock-ietf-network-slice-sdn-ctrl:test diff --git a/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/deploy.sh b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/deploy.sh new file mode 100755 index 0000000000000000000000000000000000000000..6db45be588e4d538e04ecb8922b3350432439a70 --- /dev/null +++ b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/deploy.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# 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. + +kubectl delete namespace mocks +kubectl --namespace mocks apply -f mock-ietf-network-slice-sdn-ctrl.yaml diff --git a/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/mock-ietf-network-slice-sdn-ctrl.yaml b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/mock-ietf-network-slice-sdn-ctrl.yaml new file mode 100644 index 0000000000000000000000000000000000000000..cd5734a5f3087dc36d9a103a75e90f3eb902865d --- /dev/null +++ b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/mock-ietf-network-slice-sdn-ctrl.yaml @@ -0,0 +1,64 @@ +# 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. + +kind: Namespace +apiVersion: v1 +metadata: + name: mocks +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mock-ietf-network-slice-sdn-ctrl +spec: + selector: + matchLabels: + app: mock-ietf-network-slice-sdn-ctrl + replicas: 1 + template: + metadata: + annotations: + config.linkerd.io/skip-inbound-ports: "8443" + labels: + app: mock-ietf-network-slice-sdn-ctrl + spec: + terminationGracePeriodSeconds: 5 + containers: + - name: server + image: localhost:32000/tfs/mock-ietf-network-slice-sdn-ctrl:test + imagePullPolicy: IfNotPresent + ports: + - containerPort: 8443 + resources: + requests: + cpu: 250m + memory: 512Mi + limits: + cpu: 700m + memory: 1024Mi +--- +apiVersion: v1 +kind: Service +metadata: + name: mock-ietf-network-slice-sdn-ctrl + labels: + app: mock-ietf-network-slice-sdn-ctrl +spec: + type: ClusterIP + selector: + app: mock-ietf-network-slice-sdn-ctrl + ports: + - name: http + port: 8443 + targetPort: 8443 diff --git a/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/requirements.in b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/requirements.in new file mode 100644 index 0000000000000000000000000000000000000000..dbb8e95d65cfd0f1ee60d9bb4f840393ac893725 --- /dev/null +++ b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/requirements.in @@ -0,0 +1,22 @@ +# 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. + +cryptography==39.0.1 +pyopenssl==23.0.0 +Flask==2.1.3 +Flask-HTTPAuth==4.5.0 +Flask-RESTful==0.3.9 +jsonschema==4.4.0 +requests==2.27.1 +werkzeug==2.3.7 diff --git a/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/run.sh b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/run.sh new file mode 100755 index 0000000000000000000000000000000000000000..f52b6061b3d89b75504f2b80d77696573a09814d --- /dev/null +++ b/src/tests/tools/mock_ietf_network_slice_sdn_ctrl/run.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# 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. + +# Make folder containing the script the root folder for its execution +cd $(dirname $0) + +python MockIetfNetworkSliceSdnCtrl.py