{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How to develop a MEC application using the MEC Sandbox HTTP REST API\n", "This tutorial introduces the step by step procedure to create a basic MEC appcation following ETSI MEC standards.\n", "It uses the ETSI MEC Sandbox simulator.\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## What is a MEC application\n", "\n", "See [The Wiki MEC web site](https://www.etsi.org/technologies/multi-access-edge-computing)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The basics of developing a MEC application\n", "\n", "The developement of a MEC application follows a strict process in order to access the ETSI MEC services and provides valuable services to the customers.\n", "Mainly, this process can be split in several steps:\n", "1. Global initializations (constant, variables...)\n", "2. Create a new instance of a MEC Sandbox (Note that using an existing one could be a solution too (see Annex A)\n", "3. Activate a network scenario in order to access the ETSI MEC services\n", "4. Create a new application identifier\n", "5. Register our MEC application and subscribe to service termination (see MEC 011)\n", "6. Use MEC services in order to provide valuable services to the customers\n", " 6.1. Apply MEC services required subscriptions (e.g. MEC 013 location subscription)\n", "7. Terminate the MEC application\n", " 7.1. Remove MEC services subscriptions\n", " 7.2. Deactivate the current network scenario\n", " 7.3. Delete the instance of the MEC Sandbox\n", "8. Release all the MEC application resources\n", "\n", "NOTE: Several application identifier can be created to address several MEC applications\n", "\n", "## Use the MEC Sandbox HTTP REST API models and code\n", "\n", "The MEC sandbox provides a piece of code (the python sub) that shall be used to develop the MEC application and interact with the MEC Sandbox. This piece of code mainly contains swagger models to serialize/deserialize JSON data structures and HTTP REST API call functions.\n", "The openApi file is availabe [here](https://forge.etsi.org/rep/mec/AdvantEDGE/-/blob/Task2_PoC/go-apps/meep-sandbox-sandbox_api/sandbox_api/swagger.yaml) and the [Swagger editor](https://editor-next.swagger.io/) is used to generate the python sub.\n", "\n", "The project architecture is describe [here](images/project_arch.jpg).\n", "\n", "The sandbox_api folder contains the python implementation of the HTTP REST API definitions introduced by the openApi [file](https://forge.etsi.org/rep/mec/AdvantEDGE/-/blob/Task2_PoC/go-apps/meep-sandbox-sandbox_api/sandbox_api/swagger.yaml).\n", "The model folder contains the python implementation of the data type definitions introduced by the openApi [file](https://forge.etsi.org/rep/mec/AdvantEDGE/-/blob/Task2_PoC/go-apps/meep-sandbox-sandbox_api/sandbox_api/swagger.yaml).\n", "directory:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Before going to create our MEC application skeleton, the following steps shall be done:\n", "1) Change the working directory (see the project architecture)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/yann/dev/jupyter/Sandbox/mecapp\n" ] } ], "source": [ "import os\n", "os.chdir(os.path.join(os.getcwd(), '../mecapp'))\n", "print(os.getcwd())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2) Apply the python imports" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from __future__ import division # Import floating-point division (1/4=0.25) instead of Euclidian division (1/4=0)\n", "\n", "import os\n", "import sys\n", "import re\n", "import logging\n", "import threading\n", "import time\n", "import json\n", "import uuid\n", "\n", "import pprint\n", "\n", "import six\n", "\n", "import swagger_client\n", "from swagger_client.rest import ApiException\n", "\n", "from http import HTTPStatus\n", "from http.server import BaseHTTPRequestHandler, HTTPServer\n", "\n", "try:\n", " import urllib3\n", "except ImportError:\n", " raise ImportError('Swagger python client requires urllib3.')\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "3) Initialize of the global constants (cell 3)" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [], "source": [ "MEC_SANDBOX_URL = 'https://mec-platform2.etsi.org' # MEC Sandbox host/base URL\n", "MEC_SANDBOX_API_URL = 'https://mec-platform2.etsi.org/sandbox-api/v1' # MEC Sandbox API host/base URL\n", "PROVIDER = 'Jupyter2024' # Login provider value - To skip authorization: 'github'\n", "MEC_PLTF = 'mep1' # MEC plateform name. Linked to the network scenario\n", "LOGGER_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' # Logging format\n", "STABLE_TIME_OUT = 6 # Timer to wait for MEC Sndbox reaches its stable state (K8S pods in running state)\n", "LOGIN_TIMEOUT = 3 #30 # Timer to wait for user to authorize from GITHUB\n", "LISTENER_IP = '0.0.0.0' # Listener IPv4 address for notification callback calls\n", "LISTENER_PORT = 36001 # Listener IPv4 port for notification callback calls\n", "CALLBACK_URI = 'http://yanngarcia.ddns.net:36001/jupyter/sandbox/demo6/v1/'\n", " #'https://yanngarcia.ddns.net:' + str(LISTENER_PORT) + '/jupyter/sandbox/demo6/v1/'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "4) Setup the logger instance and the HTTP REST API (cell 4)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# Initialize the logger\n", "logger = logging.getLogger(__name__)\n", "logger.setLevel(logging.DEBUG)\n", "logging.basicConfig(filename='/tmp/' + time.strftime('%Y%m%d-%H%M%S') + '.log')\n", "l = logging.StreamHandler()\n", "l.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))\n", "logger.addHandler(l)\n", "\n", "# Setup the HTTP REST API configuration to be used to send request to MEC Sandbox API \n", "configuration = swagger_client.Configuration()\n", "configuration.host = MEC_SANDBOX_API_URL\n", "configuration.verify_ssl = True\n", "configuration.debug = True\n", "configuration.logger_format = LOGGER_FORMAT\n", "# Create an instance of ApiClient\n", "sandbox_api = swagger_client.ApiClient(configuration, 'Content-Type', 'application/json')\n", "\n", "# Setup the HTTP REST API configuration to be used to send request to MEC Services\n", "configuration1 = swagger_client.Configuration()\n", "configuration1.host = MEC_SANDBOX_URL\n", "configuration1.verify_ssl = True\n", "configuration1.debug = True\n", "configuration1.logger_format = LOGGER_FORMAT\n", "# Create an instance of ApiClient\n", "service_api = swagger_client.ApiClient(configuration1, 'Content-Type', 'application/json')\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "5) Setup the global variables (cell 5)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# Initialize the global variables\n", "nw_scenarios = [] # The list of available network scenarios\n", "nw_scenario_idx = -1 # The network scenario idx to activate (deactivate)\n", "app_inst_id = None # The requested application instance identifier" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create our first MEC application\n", "\n", "The first step to develop a MEC application is to create the application skeleton which contains the minimum steps below:\n", " \n", "- Login to instanciate a MEC Sandbox\n", "- Logout to delete a existing MEC Sandbox" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### First steps: the login/logout\n", "\n", "Here is the first squeleton with the following sequence:\n", "- Login\n", "- Print sandbox identifier\n", "- Logout\n", "- Check that logout is effective\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### The login function\n", "\n", "To log to the MEC Sandbox, \n", "the login process is done in two step. In step 1, a user code is requested to GITHUB. In step 2, the user has to enter this user code to https://github.com/login/device and proceed to the authorization.\n", "Please, pay attention to the log '=======================> DO AUTHORIZATION WITH CODE :' which indicates you the user code to use for the authorization.\n", "\n", "It uses the HTTP POST request with the URL 'POST /sandbox-sandbox_api/v1/login?provide=github' (see PROVIDER constant).\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# Login\n", "def process_login() -> str:\n", " \"\"\"\n", " Authenticate and create a new MEC Sandbox instance.\n", "\n", " :return: The sandbox instance identifier on success, None otherwise\n", " \"\"\" \n", "\n", " global PROVIDER, logger\n", "\n", " logger.debug('>>> process_login')\n", "\n", " try:\n", " auth = swagger_client.AuthorizationApi(sandbox_api)\n", " oauth = auth.login(PROVIDER, async_req = False)\n", " logger.debug('process_login (step1): oauth: ' + str(oauth))\n", " # Wait for the MEC Sandbox is running\n", " logger.debug('=======================> DO AUTHORIZATION WITH CODE : ' + oauth.user_code)\n", " logger.debug('=======================> DO AUTHORIZATION HERE : ' + oauth.verification_uri)\n", " if oauth.verification_uri == \"\":\n", " time.sleep(LOGIN_TIMEOUT) # Skip scecurity, wait for a few seconds\n", " else:\n", " time.sleep(10 * LOGIN_TIMEOUT) # Wait for Authirization from user side\n", " namespace = auth.get_namespace(oauth.user_code)\n", " logger.debug('process_login (step2): result: ' + str(namespace))\n", " return namespace.sandbox_name\n", " except ApiException as e:\n", " logger.error('Exception when calling AuthorizationApi->login: %s\\n' % e)\n", "\n", " return None\n", " # End of function process_login\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### The logout function\n", "\n", "It uses the HTTP POST request with the URL 'POST /sandbox-sandbox_api/v1/logout?sandbox_name={sandbox_name}'.\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "# Logout\n", "def process_logout(sandbox: str) -> int:\n", " \"\"\"\n", " Delete the specified MEC Sandbox instance.\n", "\n", " :param sandbox: The MEC Sandbox to delete\n", " :return: 0 on success, -1 otherwise\n", " \"\"\"\n", "\n", " global logger\n", "\n", " logger.debug('>>> process_logout: sandbox=' + sandbox)\n", "\n", " try:\n", " auth = swagger_client.AuthorizationApi(sandbox_api)\n", " result = auth.logout(sandbox, async_req = False) # noqa: E501\n", " return 0\n", " except ApiException as e:\n", " logger.error('Exception when calling AuthorizationApi->logout: %s\\n' % e)\n", " return -1\n", " # End of function process_logout\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, let put in action our Login/Logout functions:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def process_main():\n", " \"\"\"\n", " This is the skeleton of our MEC application:\n", " - Login\n", " - Print sandbox identifier\n", " - Logout\n", " - Check that logout is effective\n", " This skeleton will be the bas of the next sprint in order to achieve a full implementation of a MEC application\n", " \"\"\" \n", "\n", " global logger\n", "\n", " logger.debug('Starting at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " logger.debug('\\t pwd= ' + os.getcwd())\n", "\n", " # Login\n", " sandbox = process_login()\n", " if sandbox is None:\n", " return\n", "\n", " # Print sandbox identifier\n", " logger.info('Sandbox created: ' + sandbox)\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Logout\n", " process_logout(sandbox)\n", "\n", " # Check that logout is effective\n", " logger.debug('To check that logout is effective, verify on the MEC Sandbox server that the MEC Sandbox is removed (kubectl get pods -A)')\n", " \n", " logger.debug('Stopped at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " # End of function process_main\n", "\n", "if __name__ == '__main__':\n", " process_main()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Second step: Retrieve the list of network scenarios\n", "\n", "Let's go futhur and see how we can retrieve the list of the network scenarios available in order to activate one of them and access the MEC services exposed such as MEC 013 or MEC 030.\n", "\n", "The sequence will be:\n", "- Login\n", "- Print sandbox identifier\n", "- Print available network scenarios\n", "- Logout\n", "- Check that logout is effective\n", "\n", "The login and logout functions are described in cell 3 and 4.\n", "\n", "To retrieve the list of the network scenarios, let's create a new function called 'get_network_scenarios'. It uses the HTTP GET request with the URL '/sandbox-sandbox_api/v1/sandboxNetworkScenarios?sandbox_name={sandbox_name}'." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "def get_network_scenarios(sandbox: str) -> list:\n", " \"\"\"\n", " Retrieve the list of the available network scenarios.\n", "\n", " :param sandbox: The MEC Sandbox instance to use\n", " :return: The list of the available network scenarios on success, None otherwise\n", " \"\"\"\n", "\n", " global PROVIDER, logger, configuration\n", "\n", " logger.debug('>>> get_network_scenarios: sandbox=' + sandbox)\n", "\n", " try:\n", " nw = swagger_client.SandboxNetworkScenariosApi(sandbox_api)\n", " result = nw.sandbox_network_scenarios_get(sandbox, async_req = False) # noqa: E501\n", " logger.debug('get_network_scenarios: result: ' + str(result))\n", " return result\n", " except ApiException as e:\n", " logger.error('Exception when calling SandboxNetworkScenariosApi->sandbox_network_scenarios_get: %s\\n' % e)\n", "\n", " return None\n", " # End of function get_network_scenarios\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Putting everything together:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def process_main():\n", " \"\"\"\n", " This is the first sprint of our skeleton of our MEC application:\n", " - Login\n", " - Print sandbox identifier\n", " - Print available network scenarios\n", " - Logout\n", " - Check that logout is effective\n", " \"\"\" \n", " global logger, nw_scenarios \n", "\n", " logger.debug('Starting at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " logger.debug('\\t pwd= ' + os.getcwd())\n", "\n", " # Login\n", " sandbox = process_login()\n", " if sandbox is None:\n", " logger.error('Failed to instanciate a MEC Sandbox')\n", " return\n", "\n", " # Print sandbox identifier\n", " logger.info('Sandbox created: ' + sandbox)\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Print available network scenarios\n", " nw_scenarios = get_network_scenarios(sandbox)\n", " if nw_scenarios is None:\n", " logger.error('Failed to retrieve the list of network scenarios')\n", " elif len(nw_scenarios) != 0:\n", " logger.info('nw_scenarios: %s', str(type(nw_scenarios[0])))\n", " logger.info('nw_scenarios: %s', str(nw_scenarios))\n", " else:\n", " logger.info('nw_scenarios: No scenario available')\n", "\n", " # Logout\n", " process_logout(sandbox)\n", "\n", " # Check that logout is effective\n", " logger.debug('To check that logout is effective, verify on the MEC Sandbox server that the MEC Sandbox is removed (kubectl get pods -A)')\n", " \n", " logger.debug('Stopped at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " # End of function process_main\n", "\n", "if __name__ == '__main__':\n", " process_main()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Third step: Activate and deactivate a network scenario\n", "\n", "Having a list of network scenarion, the next step is to actvate (and deactivate) a network scenario. This step is mandatory to create a new application instance id and access the MEC services.\n", "\n", "In this section, we will arbitrary activate the network scenario called '4g-5g-macro-v2x', which is at the index 0 of the nw_scenarios. " ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "def select_network_scenario_based_on_criteria(criterias_list: list) -> int:\n", " \"\"\"\n", " Select the network scenario to activate based of the provided list of criterias.\n", "\n", " :param criterias_list: The list of criterias to select the correct network scenario\n", " :return: 0 on success, -1 otherwise\n", " \"\"\"\n", " return 0 # The index of the '4g-5g-macro-v2x' network scenario - Hard coded" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### The activate function\n", "\n", "The process to activate a scenario is based on an HTTP POST request with the URL '/sandboxNetworkScenarios/{sandbox_name}?network_scenario_id={network_scenario_id}'.\n" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "def activate_network_scenario(sandbox: str) -> int:\n", " \"\"\"\n", " Activate the specified network scenario.\n", "\n", " :param sandbox: The MEC Sandbox instance to use\n", " :return: 0 on success, -1 otherwise\n", " \"\"\"\n", "\n", " global logger, configuration, nw_scenarios, nw_scenario_idx\n", "\n", " logger.debug('>>> activate_network_scenario: ' + sandbox)\n", "\n", " nw_scenario_idx = select_network_scenario_based_on_criteria([])\n", " if nw_scenario_idx == -1:\n", " logger.error('activate_network_scenario: Failed to select a network scenarion')\n", " return -1\n", "\n", " try:\n", " nw = swagger_client.SandboxNetworkScenariosApi(sandbox_api)\n", " nw.sandbox_network_scenario_post(sandbox, nw_scenarios[nw_scenario_idx].id, async_req = False) # noqa: E501\n", " return 0\n", " except ApiException as e:\n", " logger.error('Exception when calling SandboxNetworkScenariosApi->activate_network_scenario: %s\\n' % e)\n", "\n", " return -1\n", " # End of function activate_network_scenario\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### The deactivate function\n", "\n", "The process to deactivate a scenario is based on an HTTP DELETE request with the URL '/sandboxNetworkScenarios/{sandbox_name}?network_scenario_id={network_scenario_id}'.\n" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "def deactivate_network_scenario(sandbox: str) -> int:\n", " \"\"\"\n", " Deactivate the current network scenario.\n", "\n", " :param sandbox: The MEC Sandbox instance to use\n", " :return: 0 on success, -1 otherwise\n", " \"\"\"\n", "\n", " global MEC_SANDBOX_API_URL, logger, configuration, nw_scenarios, nw_scenario_idx\n", "\n", " logger.debug('>>> deactivate_network_scenario: ' + sandbox)\n", "\n", " try:\n", " nw = swagger_client.SandboxNetworkScenariosApi(sandbox_api)\n", " nw.sandbox_network_scenario_delete(sandbox, nw_scenarios[nw_scenario_idx].id, async_req = False) # noqa: E501\n", " return 0\n", " except ApiException as e:\n", " logger.error('Exception when calling SandboxNetworkScenariosApi->deactivate_network_scenario: %s\\n' % e)\n", "\n", " return -1\n", " # End of function deactivate_network_scenario\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, it is time to create the second iteration of our MEC application.\n", "\n", "The sequence is the following:\n", "- Login\n", "- Print sandbox identifier\n", "- Print available network scenarios\n", "- Activate a network scenario\n", "- Check that the network scenario is activated and the MEC services are running\n", "- Deactivate a network scenario\n", "- Logout\n", "- Check that logout is effective\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def process_main():\n", " \"\"\"\n", " This is the second sprint of our skeleton of our MEC application:\n", " - Login\n", " - Print sandbox identifier\n", " - Print available network scenarios\n", " - Activate a network scenario\n", " - Check that the network scenario is activated and the MEC services are running\n", " - Deactivate a network scenario\n", " - Logout\n", " - Check that logout is effective\n", " \"\"\" \n", " global logger, nw_scenarios \n", "\n", " logger.debug('Starting at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " logger.debug('\\t pwd= ' + os.getcwd())\n", "\n", " # Login\n", " sandbox = process_login()\n", " if sandbox is None:\n", " logger.error('Failed to instanciate a MEC Sandbox')\n", " return\n", "\n", " # Print sandbox identifier\n", " logger.info('Sandbox created: ' + sandbox)\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Print available network scenarios\n", " nw_scenarios = get_network_scenarios(sandbox)\n", " if nw_scenarios is None:\n", " logger.error('Failed to retrieve the list of network scenarios')\n", " elif len(nw_scenarios) != 0:\n", " logger.info('nw_scenarios: %s', str(type(nw_scenarios[0])))\n", " logger.info('nw_scenarios: %s', str(nw_scenarios))\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", " else:\n", " logger.info('nw_scenarios: No scenario available')\n", "\n", " # Activate a network scenario based on a list of criterias (hard coded!!!)\n", " if activate_network_scenario(sandbox) == -1:\n", " logger.error('Failed to activate network scenario')\n", " else:\n", " logger.info('Network scenario activated: ' + nw_scenarios[nw_scenario_idx].id)\n", " # Wait for the MEC services are running\n", " time.sleep(2 * STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Check that the network scenario is activated and the MEC services are running \n", " logger.info('To check that the network scenario is activated, verify on the MEC Sandbox server that the MEC services are running (kubectl get pods -A)')\n", " time.sleep(30) # Sleep for 30 seconds\n", "\n", " # Deactivate a network scenario based on a list of criterias (hard coded!!!)\n", " if deactivate_network_scenario(sandbox) == -1:\n", " logger.error('Failed to deactivate network scenario')\n", " else:\n", " logger.info('Network scenario deactivated: ' + nw_scenarios[nw_scenario_idx].id)\n", " # Wait for the MEC services are terminated\n", " time.sleep(2 * STABLE_TIME_OUT)\n", "\n", " # Logout\n", " process_logout(sandbox)\n", "\n", " # Check that logout is effective\n", " logger.debug('To check that logout is effective, verify on the MEC Sandbox server that the MEC Sandbox is removed (kubectl get pods -A)')\n", " \n", " logger.debug('Stopped at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " # End of function process_main\n", "\n", "if __name__ == '__main__':\n", " process_main()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Fourth step: Create and delete an appliction instance id\n", "\n", "To enable our MEC application to be part of the activated network scenario, we need to request the MEC sandbox to create a new application instance identifier. Our MEC application will use this identifier to register to the MEC Sandbox according to MEC 011.\n", "\n", "#### The appliction instance id creation function\n", "\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "def request_application_instance_id(sandbox: str) -> swagger_client.models.ApplicationInfo:\n", " \"\"\"\n", " \"\"\"\n", "\n", " global MEC_PLTF, logger, configuration\n", "\n", " logger.debug('>>> request_application_instance_id: ' + sandbox)\n", "\n", " # Create a instance of our MEC application\n", " a = swagger_client.models.ApplicationInfo(id=str(uuid.uuid4()), name='JupyterMecApp', node_name=MEC_PLTF, type='USER') # noqa: E501\n", " print(a)\n", " \n", " try:\n", " nw = swagger_client.SandboxAppInstancesApi(sandbox_api)\n", " result = nw.sandbox_app_instances_post(a, sandbox, async_req = False) # noqa: E501\n", " logger.debug('request_application_instance_id: result: ' + str(result))\n", " return result\n", " except ApiException as e:\n", " logger.error('Exception when calling SandboxAppInstancesApi->sandbox_app_instances_post: %s\\n' % e)\n", "\n", " return None\n", " # End of function request_application_instance_id" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### The appliction instance id deletion function" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "def delete_application_instance_id(sandbox: str, id: str) -> int:\n", " \"\"\"\n", " \"\"\"\n", "\n", " global logger, configuration\n", "\n", " logger.debug('>>> delete_application_instance_id: ' + sandbox)\n", " logger.debug('>>> delete_application_instance_id: ' + id)\n", "\n", " try:\n", " nw = swagger_client.SandboxAppInstancesApi(sandbox_api)\n", " result = nw.sandbox_app_instances_delete(sandbox, id, async_req = False) # noqa: E501\n", " return result\n", " except ApiException as e:\n", " logger.error('Exception when calling SandboxAppInstancesApi->sandbox_app_instances_delete: %s\\n' % e)\n", "\n", " return -1\n", " # End of function deletet_application_instance_id" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Getting the list of applications" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "def get_applications_list(sandbox: str) -> list:\n", " \"\"\"\n", " \"\"\"\n", "\n", " global MEC_SANDBOX_API_URL, logger, configuration\n", "\n", " logger.debug('>>> get_applications_list: ' + sandbox)\n", "\n", " try:\n", " nw = swagger_client.SandboxAppInstancesApi(sandbox_api)\n", " result = nw.sandbox_app_instances_get(sandbox, async_req = False) # noqa: E501\n", " logger.debug('get_applications_list: result: ' + str(result))\n", " return result\n", " except ApiException as e:\n", " logger.error('Exception when calling SandboxAppInstancesApi->get_applications_list: %s\\n' % e)\n", "\n", " return None \n", " # End of function delete_application_instance_id" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is time now to create the our third iteration of our MEC application.\n", "\n", "The sequence is the following:\n", "- Login\n", "- Print sandbox identifier\n", "- Print available network scenarios\n", "- Activate a network scenario\n", "- Request for a new application instance identifier\n", "- Retrieve the list of the applications instance identifier\n", "- Check the demo application is present in the list of applications\n", "- Delete our application instance identifier\n", "- Deactivate a network scenario\n", "- Logout\n", "- Check that logout is effective\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def process_main():\n", " \"\"\"\n", " This is the second sprint of our skeleton of our MEC application:\n", " - Login\n", " - Print sandbox identifier\n", " - Print available network scenarios\n", " - Activate a network scenario\n", " - Request for a new application instance identifier\n", " - Retrieve the list of the applications instance identifier\n", " - Check the demo application is present in the list of applications\n", " - Deactivate a network scenario\n", " - Logout\n", " - Check that logout is effective\n", " \"\"\" \n", " global logger, nw_scenarios\n", "\n", " logger.debug('Starting at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " logger.debug('\\t pwd= ' + os.getcwd())\n", "\n", " # Login\n", " sandbox = process_login()\n", " if sandbox is None:\n", " logger.error('Failed to instanciate a MEC Sandbox')\n", " return\n", "\n", " # Print sandbox identifier\n", " logger.info('Sandbox created: ' + sandbox)\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Print available network scenarios\n", " nw_scenarios = get_network_scenarios(sandbox)\n", " if nw_scenarios is None:\n", " logger.error('Failed to retrieve the list of network scenarios')\n", " elif len(nw_scenarios) != 0:\n", " logger.info('nw_scenarios: %s', str(type(nw_scenarios[0])))\n", " logger.info('nw_scenarios: %s', str(nw_scenarios))\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", " else:\n", " logger.info('nw_scenarios: No scenario available')\n", "\n", " # Activate a network scenario based on a list of criterias (hard coded!!!)\n", " if activate_network_scenario(sandbox) == -1:\n", " logger.error('Failed to activate network scenario')\n", " else:\n", " logger.info('Network scenario activated: ' + nw_scenarios[nw_scenario_idx].id)\n", " # Wait for the MEC services are running\n", " time.sleep(2 * STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Request for a new application instance identifier\n", " app_inst_id = request_application_instance_id(sandbox)\n", " if app_inst_id == None:\n", " logger.error('Failed to request an application instance identifier')\n", " else:\n", " logger.info('app_inst_id: %s', str(type(app_inst_id)))\n", " logger.info('app_inst_id: %s', str(app_inst_id))\n", "\n", " # Check the demo application is present in the list of applications\n", " app_list = get_applications_list(sandbox)\n", " if app_list is None:\n", " logger.error('Failed to request the list of applications')\n", " else:\n", " logger.info('app_list: %s', str(type(app_list)))\n", " logger.info('app_list: %s', str(app_list))\n", " # Check if our application is present in the list of applications\n", " found = False\n", " for item in app_list:\n", " if item.id == app_inst_id.id:\n", " found = True\n", " break\n", " if not found:\n", " logger.error('Failed to retrieve our application instance identifier')\n", "\n", " # Delete the application instance identifier\n", " if delete_application_instance_id(sandbox, app_inst_id.id) == -1:\n", " logger.error('Failed to delete the application instance identifier')\n", " else:\n", " logger.info('app_inst_id deleted: ' + app_inst_id.id)\n", "\n", " # Deactivate a network scenario based on a list of criterias (hard coded!!!)\n", " if deactivate_network_scenario(sandbox) == -1:\n", " logger.error('Failed to deactivate network scenario')\n", " else:\n", " logger.info('Network scenario deactivated: ' + nw_scenarios[nw_scenario_idx].id)\n", " # Wait for the MEC services are terminated\n", " time.sleep(2 * STABLE_TIME_OUT)\n", "\n", " # Logout\n", " process_logout(sandbox)\n", "\n", " # Check that logout is effective\n", " logger.debug('To check that logout is effective, verify on the MEC Sandbox server that the MEC Sandbox is removed (kubectl get pods -A)')\n", " \n", " logger.debug('Stopped at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " # End of function process_main\n", "\n", "if __name__ == '__main__':\n", " process_main()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## MEC Registration and the READY confirmation\n", "\n", "Having an application instance identifier allows us to register with the MEC Sandbox and interact with it (e.g. to send service queries, to subscribe to events and to recieve notifications...).\n", "\n", "The standard MEC 011 Clause 5.2.2 MEC application start-up describes the start up process. Basically, our MEC application has to:\n", "1. Indicates that it is running by sending a Confirm Ready message\n", "2. Retrieve the list of MEC services \n", "\n", "To do so, a MEC application needs to be able to send requests but also to receive notifications (POST requests) and to reply to them." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Fifth step: Send the READY confirmation\n", "\n", "Sending READY confirmation is described by MEC 011 Clause 5.2.2 MEC application start-up.\n" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "def send_ready_confirmation(sandbox_name: str, app_inst_id: swagger_client.models.application_info.ApplicationInfo) -> int:\n", " global MEC_PLTF, logger\n", "\n", " logger.debug('>>> send_ready_confirmation: ' + app_inst_id.id)\n", " try:\n", " url = '/{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/confirm_ready'\n", " logger.debug('send_ready_confirmation: url: ' + url)\n", " path_params = {}\n", " path_params['sandbox_name'] = sandbox_name\n", " path_params['mec_pltf'] = MEC_PLTF\n", " path_params['app_inst_id'] = app_inst_id.id\n", " header_params = {}\n", " # HTTP header `Accept`\n", " header_params['Accept'] = 'application/json' # noqa: E501\n", " # HTTP header `Content-Type`\n", " header_params['Content-Type'] = 'application/json' # noqa: E501\n", " # JSON indication READY\n", " dict_body = {}\n", " dict_body['indication'] = 'READY'\n", " result = service_api.call_api(url, 'POST', header_params=header_params, path_params = path_params, body=dict_body, async_req=False)\n", " return 0\n", " except ApiException as e:\n", " logger.error('Exception when calling call_api: %s\\n' % e)\n", " return -1\n", " # End of function send_ready_confirmation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In addition, our MEC application is registering to AppTerminationNotificationSubscription and it needs to delete its subscription when terminating.\n", "\n", "At this stage, it is important to note that all subscription deletion use the same format: / (see ETSI MEC GS 003 [16]). \n", "In this case, it the AppTerminationNotificationSubscription is 'sub-1234', the URIs to do the susbscription and to delete it are:\n", "- MEC_SANDBOX_URL + '/' + sandbox_name + '/' + MEC_PLTF + '/mec_app_support/v2/applications/' + app_inst_id + '/subscriptions'\n", "- MEC_SANDBOX_URL + '/' + sandbox_name + '/' + MEC_PLTF + '/mec_app_support/v2/applications/' + app_inst_id + '/subscriptions/sub-1234'\n", "\n", "So, it will be usefull to create a small function to extract the subscription identifier from either the HTTP Location header or from the Link field found into the reponse body data structure. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Subscribing to application termination" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "def send_subscribe_termination(sandbox_name: str, app_inst_id: swagger_client.models.application_info.ApplicationInfo) -> object:\n", " global MEC_PLTF, logger\n", "\n", " logger.debug('>>> send_subscribe_termination: ' + app_inst_id.id)\n", " try:\n", " url = '/{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/subscriptions'\n", " logger.debug('send_subscribe_termination: url: ' + url)\n", " path_params = {}\n", " path_params['sandbox_name'] = sandbox_name\n", " path_params['mec_pltf'] = MEC_PLTF\n", " path_params['app_inst_id'] = app_inst_id.id\n", " header_params = {}\n", " # HTTP header `Accept`\n", " header_params['Accept'] = 'application/json' # noqa: E501\n", " # HTTP header `Content-Type`\n", " header_params['Content-Type'] = 'application/json' # noqa: E501\n", " # Body\n", " dict_body = {}\n", " dict_body['subscriptionType'] = 'AppTerminationNotificationSubscription'\n", " dict_body['callbackReference'] = 'http://yanngarcia.ddns.net/mec011/v2/termination' # FIXME To be parameterized\n", " dict_body['appInstanceId'] = app_inst_id.id\n", " (result, status, headers) = service_api.call_api(url, 'POST', header_params=header_params, path_params = path_params, body=dict_body, async_req=False)\n", " return (result, extract_sub_id(headers['Location']), headers['Location'])\n", " except ApiException as e:\n", " logger.error('Exception when calling call_api: %s\\n' % e)\n", " return None\n", " # End of function send_subscribe_termination" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Extracting subscription identifier" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "def extract_sub_id(resource_url: str) -> str:\n", " global logger\n", "\n", " logger.debug('>>> extract_sub_id: resource_url: ' + resource_url)\n", "\n", " res = urllib3.util.parse_url(resource_url)\n", " if res is not None and res.path is not None and res.path != '':\n", " id = res.path.rsplit('/', 1)[-1]\n", " if id is not None:\n", " return id\n", "\n", " return None\n", " # End of function extract_sub_id" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Delete subscription to application termination" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "def delete_subscribe_termination(sandbox_name: str, app_inst_id: swagger_client.models.application_info.ApplicationInfo, sub_id: str) -> int:\n", " global MEC_PLTF, logger\n", "\n", " logger.debug('>>> delete_subscribe_termination: ' + app_inst_id.id)\n", " try:\n", " url = '/{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/subscriptions/{sub_id}'\n", " logger.debug('delete_subscribe_termination: url: ' + url)\n", " path_params = {}\n", " path_params['sandbox_name'] = sandbox_name\n", " path_params['mec_pltf'] = MEC_PLTF\n", " path_params['app_inst_id'] = app_inst_id.id\n", " path_params['sub_id'] = sub_id\n", " header_params = {}\n", " # HTTP header `Accept`\n", " header_params['Accept'] = 'application/json' # noqa: E501\n", " # HTTP header `Content-Type`\n", " header_params['Content-Type'] = 'application/json' # noqa: E501\n", " service_api.call_api(url, 'DELETE', header_params=header_params, path_params = path_params, async_req=False)\n", " return 0\n", " except ApiException as e:\n", " logger.error('Exception when calling call_api: %s\\n' % e)\n", " return -1\n", " # End of function delete_subscribe_termination" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, it is time now to create the our fifth iteration of our MEC application.\n", "\n", "The sequence is the following:\n", "- Login\n", "- Print sandbox identifier\n", "- Print available network scenarios\n", "- Activate a network scenario\n", "- Request for a new application instance identifier\n", "- Send READY confirmation\n", "- Subscribe to AppTerminationNotificationSubscription\n", "- Check list of services\n", "- Delete AppTerminationNotification subscription\n", "- Delete our application instance identifier\n", "- Deactivate a network scenario\n", "- Logout\n", "- Check that logout is effective\n" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:11:22,392 - __main__ - DEBUG - Starting at 20241010-151122\n", "2024-10-10 15:11:22,393 - __main__ - DEBUG - \t pwd= /home/yann/dev/jupyter/Sandbox/mecapp\n", "2024-10-10 15:11:22,395 - __main__ - DEBUG - >>> process_login\n", "2024-10-10 15:11:22,397 DEBUG Starting new HTTPS connection (1): mec-platform2.etsi.org:443\n", "2024-10-10 15:11:22,617 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/login?provider=Jupyter2024 HTTP/1.1\" 201 48\n", "2024-10-10 15:11:22,621 DEBUG response body: b'{\"user_code\":\"sbxbr4pfog\",\"verification_uri\":\"\"}'\n", "2024-10-10 15:11:22,623 - __main__ - DEBUG - process_login (step1): oauth: {'user_code': 'sbxbr4pfog', 'verification_uri': ''}\n", "2024-10-10 15:11:22,625 - __main__ - DEBUG - =======================> DO AUTHORIZATION WITH CODE : sbxbr4pfog\n", "2024-10-10 15:11:22,627 - __main__ - DEBUG - =======================> DO AUTHORIZATION HERE : \n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sandbox-api/v1/login?provider=Jupyter2024 HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 201 Created\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:11:22 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 48\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:11:25,656 DEBUG https://mec-platform2.etsi.org:443 \"GET /sandbox-api/v1/namespace?user_code=sbxbr4pfog HTTP/1.1\" 200 29\n", "2024-10-10 15:11:25,658 DEBUG response body: b'{\"sandbox_name\":\"sbxbr4pfog\"}'\n", "2024-10-10 15:11:25,661 - __main__ - DEBUG - process_login (step2): result: {'sandbox_name': 'sbxbr4pfog'}\n", "2024-10-10 15:11:25,662 - __main__ - INFO - Sandbox created: sbxbr4pfog\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'GET /sandbox-api/v1/namespace?user_code=sbxbr4pfog HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "reply: 'HTTP/1.1 200 OK\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:11:25 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 29\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:11:31,672 - __main__ - DEBUG - >>> get_network_scenarios: sandbox=sbxbr4pfog\n", "2024-10-10 15:11:31,673 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n", "2024-10-10 15:11:31,870 DEBUG https://mec-platform2.etsi.org:443 \"GET /sandbox-api/v1/sandboxNetworkScenarios?sandbox_name=sbxbr4pfog HTTP/1.1\" 200 186\n", "2024-10-10 15:11:31,872 DEBUG response body: b'[{\"id\":\"4g-5g-macro-v2x\"},{\"id\":\"4g-5g-macro-v2x-fed\"},{\"id\":\"4g-5g-wifi-macro\"},{\"id\":\"4g-macro\"},{\"id\":\"4g-wifi-macro\"},{\"id\":\"dual-mep-4g-5g-wifi-macro\"},{\"id\":\"dual-mep-short-path\"}]'\n", "2024-10-10 15:11:31,875 - __main__ - DEBUG - get_network_scenarios: result: [{'id': '4g-5g-macro-v2x'}, {'id': '4g-5g-macro-v2x-fed'}, {'id': '4g-5g-wifi-macro'}, {'id': '4g-macro'}, {'id': '4g-wifi-macro'}, {'id': 'dual-mep-4g-5g-wifi-macro'}, {'id': 'dual-mep-short-path'}]\n", "2024-10-10 15:11:31,877 - __main__ - INFO - nw_scenarios: \n", "2024-10-10 15:11:31,879 - __main__ - INFO - nw_scenarios: [{'id': '4g-5g-macro-v2x'}, {'id': '4g-5g-macro-v2x-fed'}, {'id': '4g-5g-wifi-macro'}, {'id': '4g-macro'}, {'id': '4g-wifi-macro'}, {'id': 'dual-mep-4g-5g-wifi-macro'}, {'id': 'dual-mep-short-path'}]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'GET /sandbox-api/v1/sandboxNetworkScenarios?sandbox_name=sbxbr4pfog HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "reply: 'HTTP/1.1 200 OK\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:11:31 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 186\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:11:37,888 - __main__ - DEBUG - >>> activate_network_scenario: sbxbr4pfog\n", "2024-10-10 15:11:37,970 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/sandboxNetworkScenarios/sbxbr4pfog?network_scenario_id=4g-5g-macro-v2x HTTP/1.1\" 204 0\n", "2024-10-10 15:11:37,972 DEBUG response body: b''\n", "2024-10-10 15:11:37,974 - __main__ - INFO - Network scenario activated: 4g-5g-macro-v2x\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sandbox-api/v1/sandboxNetworkScenarios/sbxbr4pfog?network_scenario_id=4g-5g-macro-v2x HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:11:37 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:11:49,979 - __main__ - DEBUG - >>> request_application_instance_id: sbxbr4pfog\n", "2024-10-10 15:11:49,983 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'id': '8cbaee38-3c41-467d-b915-65887dd6f686',\n", " 'name': 'JupyterMecApp',\n", " 'node_name': 'mep1',\n", " 'persist': None,\n", " 'type': 'USER'}\n", "send: b'POST /sandbox-api/v1/sandboxAppInstances/sbxbr4pfog HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 107\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{\"id\": \"8cbaee38-3c41-467d-b915-65887dd6f686\", \"name\": \"JupyterMecApp\", \"nodeName\": \"mep1\", \"type\": \"USER\"}'\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:11:50,215 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/sandboxAppInstances/sbxbr4pfog HTTP/1.1\" 201 100\n", "2024-10-10 15:11:50,217 DEBUG response body: b'{\"id\":\"8cbaee38-3c41-467d-b915-65887dd6f686\",\"name\":\"JupyterMecApp\",\"nodeName\":\"mep1\",\"type\":\"USER\"}'\n", "2024-10-10 15:11:50,222 - __main__ - DEBUG - request_application_instance_id: result: {'id': '8cbaee38-3c41-467d-b915-65887dd6f686',\n", " 'name': 'JupyterMecApp',\n", " 'node_name': 'mep1',\n", " 'persist': None,\n", " 'type': 'USER'}\n", "2024-10-10 15:11:50,225 - __main__ - INFO - app_inst_id: {'id': '8cbaee38-3c41-467d-b915-65887dd6f686',\n", " 'name': 'JupyterMecApp',\n", " 'node_name': 'mep1',\n", " 'persist': None,\n", " 'type': 'USER'}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "reply: 'HTTP/1.1 201 Created\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:11:50 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 100\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:11:56,234 - __main__ - DEBUG - >>> send_ready_confirmation: 8cbaee38-3c41-467d-b915-65887dd6f686\n", "2024-10-10 15:11:56,236 - __main__ - DEBUG - send_ready_confirmation: url: /{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/confirm_ready\n", "2024-10-10 15:11:56,240 DEBUG Starting new HTTPS connection (1): mec-platform2.etsi.org:443\n", "2024-10-10 15:11:56,389 DEBUG https://mec-platform2.etsi.org:443 \"POST /sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/confirm_ready HTTP/1.1\" 204 0\n", "2024-10-10 15:11:56,391 DEBUG response body: b''\n", "2024-10-10 15:11:56,393 - __main__ - DEBUG - >>> send_subscribe_termination: 8cbaee38-3c41-467d-b915-65887dd6f686\n", "2024-10-10 15:11:56,394 - __main__ - DEBUG - send_subscribe_termination: url: /{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/subscriptions\n", "2024-10-10 15:11:56,417 DEBUG https://mec-platform2.etsi.org:443 \"POST /sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/subscriptions HTTP/1.1\" 201 367\n", "2024-10-10 15:11:56,421 DEBUG response body: b'{\"subscriptionType\":\"AppTerminationNotificationSubscription\",\"callbackReference\":\"http://yanngarcia.ddns.net/mec011/v2/termination\",\"_links\":{\"self\":{\"href\":\"https://mec-platform2.etsi.org/sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/subscriptions/sub-C2pdhFbqIHzPTuiy\"}},\"appInstanceId\":\"8cbaee38-3c41-467d-b915-65887dd6f686\"}'\n", "2024-10-10 15:11:56,424 - __main__ - DEBUG - >>> extract_sub_id: resource_url: https://mec-platform2.etsi.org/sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/subscriptions/sub-C2pdhFbqIHzPTuiy\n", "2024-10-10 15:11:56,427 - __main__ - INFO - result: \n", "2024-10-10 15:11:56,430 - __main__ - INFO - sub_id: sub-C2pdhFbqIHzPTuiy\n", "2024-10-10 15:11:56,432 - __main__ - INFO - data: {'subscriptionType': 'AppTerminationNotificationSubscription', 'callbackReference': 'http://yanngarcia.ddns.net/mec011/v2/termination', '_links': {'self': {'href': 'https://mec-platform2.etsi.org/sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/subscriptions/sub-C2pdhFbqIHzPTuiy'}}, 'appInstanceId': '8cbaee38-3c41-467d-b915-65887dd6f686'}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/confirm_ready HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 23\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{\"indication\": \"READY\"}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:11:56 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n", "send: b'POST /sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/subscriptions HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 192\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{\"subscriptionType\": \"AppTerminationNotificationSubscription\", \"callbackReference\": \"http://yanngarcia.ddns.net/mec011/v2/termination\", \"appInstanceId\": \"8cbaee38-3c41-467d-b915-65887dd6f686\"}'\n", "reply: 'HTTP/1.1 201 Created\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:11:56 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 367\n", "header: Connection: keep-alive\n", "header: Location: https://mec-platform2.etsi.org/sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/subscriptions/sub-C2pdhFbqIHzPTuiy\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:12:02,442 - __main__ - DEBUG - >>> delete_subscribe_termination: 8cbaee38-3c41-467d-b915-65887dd6f686\n", "2024-10-10 15:12:02,445 - __main__ - DEBUG - delete_subscribe_termination: url: /{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/subscriptions/{sub_id}\n", "2024-10-10 15:12:02,471 DEBUG https://mec-platform2.etsi.org:443 \"DELETE /sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/subscriptions/sub-C2pdhFbqIHzPTuiy HTTP/1.1\" 204 0\n", "2024-10-10 15:12:02,473 DEBUG response body: b''\n", "2024-10-10 15:12:02,475 - __main__ - INFO - app_inst_id deleted: 8cbaee38-3c41-467d-b915-65887dd6f686\n", "2024-10-10 15:12:02,479 - __main__ - DEBUG - >>> delete_application_instance_id: sbxbr4pfog\n", "2024-10-10 15:12:02,482 - __main__ - DEBUG - >>> delete_application_instance_id: 8cbaee38-3c41-467d-b915-65887dd6f686\n", "2024-10-10 15:12:02,485 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'DELETE /sbxbr4pfog/mep1/mec_app_support/v2/applications/8cbaee38-3c41-467d-b915-65887dd6f686/subscriptions/sub-C2pdhFbqIHzPTuiy HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:12:02 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n", "send: b'DELETE /sandbox-api/v1/sandboxAppInstances/sbxbr4pfog/8cbaee38-3c41-467d-b915-65887dd6f686 HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:12:02,673 DEBUG https://mec-platform2.etsi.org:443 \"DELETE /sandbox-api/v1/sandboxAppInstances/sbxbr4pfog/8cbaee38-3c41-467d-b915-65887dd6f686 HTTP/1.1\" 204 0\n", "2024-10-10 15:12:02,676 DEBUG response body: b''\n", "2024-10-10 15:12:02,679 - __main__ - INFO - app_inst_id deleted: 8cbaee38-3c41-467d-b915-65887dd6f686\n", "2024-10-10 15:12:02,680 - __main__ - DEBUG - >>> deactivate_network_scenario: sbxbr4pfog\n", "2024-10-10 15:12:02,733 DEBUG https://mec-platform2.etsi.org:443 \"DELETE /sandbox-api/v1/sandboxNetworkScenarios/sbxbr4pfog/4g-5g-macro-v2x HTTP/1.1\" 204 0\n", "2024-10-10 15:12:02,735 DEBUG response body: b''\n", "2024-10-10 15:12:02,737 - __main__ - INFO - Network scenario deactivated: 4g-5g-macro-v2x\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:12:02 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n", "send: b'DELETE /sandbox-api/v1/sandboxNetworkScenarios/sbxbr4pfog/4g-5g-macro-v2x HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:12:02 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:12:14,751 - __main__ - DEBUG - >>> process_logout: sandbox=sbxbr4pfog\n", "2024-10-10 15:12:14,754 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n", "2024-10-10 15:12:14,904 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/logout?sandbox_name=sbxbr4pfog HTTP/1.1\" 204 0\n", "2024-10-10 15:12:14,905 DEBUG response body: b''\n", "2024-10-10 15:12:14,906 - __main__ - DEBUG - To check that logout is effective, verify on the MEC Sandbox server that the MEC Sandbox is removed (kubectl get pods -A)\n", "2024-10-10 15:12:14,907 - __main__ - DEBUG - Stopped at 20241010-151214\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sandbox-api/v1/logout?sandbox_name=sbxbr4pfog HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:12:14 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] } ], "source": [ "def process_main():\n", " \"\"\"\n", " This is the second sprint of our skeleton of our MEC application:\n", " - Login\n", " - Print sandbox identifier\n", " - Print available network scenarios\n", " - Activate a network scenario\n", " - Request for a new application instance identifier\n", " - Send READY confirmation\n", " \n", " - Subscribe to AppTermination Notification\n", " - Send Termination\n", " - Delete AppTerminationNotification subscription\n", " - Delete our application instance identifier\n", " - Deactivate a network scenario\n", " - Logout\n", " - Check that logout is effective\n", " \"\"\" \n", " global logger, nw_scenarios\n", "\n", " logger.debug('Starting at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " logger.debug('\\t pwd= ' + os.getcwd())\n", "\n", " # Login\n", " sandbox = process_login()\n", " if sandbox is None:\n", " logger.error('Failed to instanciate a MEC Sandbox')\n", " return\n", "\n", " # Print sandbox identifier\n", " logger.info('Sandbox created: ' + sandbox)\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Print available network scenarios\n", " nw_scenarios = get_network_scenarios(sandbox)\n", " if nw_scenarios is None:\n", " logger.error('Failed to retrieve the list of network scenarios')\n", " elif len(nw_scenarios) != 0:\n", " logger.info('nw_scenarios: %s', str(type(nw_scenarios[0])))\n", " logger.info('nw_scenarios: %s', str(nw_scenarios))\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", " else:\n", " logger.info('nw_scenarios: No scenario available')\n", "\n", " # Activate a network scenario based on a list of criterias (hard coded!!!)\n", " if activate_network_scenario(sandbox) == -1:\n", " logger.error('Failed to activate network scenario')\n", " else:\n", " logger.info('Network scenario activated: ' + nw_scenarios[nw_scenario_idx].id)\n", " # Wait for the MEC services are running\n", " time.sleep(2 * STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Request for a new application instance identifier\n", " app_inst_id = request_application_instance_id(sandbox)\n", " if app_inst_id == None:\n", " logger.error('Failed to request an application instance identifier')\n", " else:\n", " logger.info('app_inst_id: %s', str(app_inst_id))\n", " time.sleep(STABLE_TIME_OUT)\n", "\n", " # Send READY confirmation\n", " sub_id = None\n", " if send_ready_confirmation(sandbox, app_inst_id) == -1:\n", " logger.error('Failed to send confirm_ready')\n", " else:\n", " # Subscribe to AppTerminationNotificationSubscription\n", " result, sub_id, res_url = send_subscribe_termination(sandbox, app_inst_id)\n", " if sub_id == None:\n", " logger.error('Failed to do the subscription')\n", " else:\n", " logger.info('result: ' + str(result))\n", " logger.info('sub_id: %s', sub_id)\n", " data = json.loads(result.data)\n", " logger.info('data: ' + str(data))\n", "\n", " # Any processing here\n", " time.sleep(STABLE_TIME_OUT)\n", "\n", " # Delete AppTerminationNotification subscription\n", " if sub_id is not None:\n", " if delete_subscribe_termination(sandbox, app_inst_id, sub_id) == -1:\n", " logger.error('Failed to delete the application instance identifier')\n", " else:\n", " logger.info('app_inst_id deleted: ' + app_inst_id.id)\n", "\n", " # Delete the application instance identifier\n", " if delete_application_instance_id(sandbox, app_inst_id.id) == -1:\n", " logger.error('Failed to delete the application instance identifier')\n", " else:\n", " logger.info('app_inst_id deleted: ' + app_inst_id.id)\n", "\n", " # Deactivate a network scenario based on a list of criterias (hard coded!!!)\n", " if deactivate_network_scenario(sandbox) == -1:\n", " logger.error('Failed to deactivate network scenario')\n", " else:\n", " logger.info('Network scenario deactivated: ' + nw_scenarios[nw_scenario_idx].id)\n", " # Wait for the MEC services are terminated\n", " time.sleep(2 * STABLE_TIME_OUT)\n", "\n", " # Logout\n", " process_logout(sandbox)\n", "\n", " # Check that logout is effective\n", " logger.debug('To check that logout is effective, verify on the MEC Sandbox server that the MEC Sandbox is removed (kubectl get pods -A)')\n", " \n", " logger.debug('Stopped at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " # End of function process_main\n", "\n", "if __name__ == '__main__':\n", " process_main()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Conclusion: Create two procedures for the setup and the termination of our MEC application\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### The procedure for the setup of a MEC application\n", "\n", "This function provides the steps to setup a MEC application and to be ready to use the MEC service exposed by the created MEC Sandbox.\n" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "def mec_app_setup():\n", " \"\"\"\n", " This function provides the steps to setup a MEC application:\n", " - Login\n", " - Print sandbox identifier\n", " - Print available network scenarios\n", " - Activate a network scenario\n", " - Request for a new application instance identifier\n", " - Send READY confirmation\n", " - Subscribe to AppTermination Notification\n", " \"\"\"\n", " global logger, nw_scenarios\n", "\n", " # Login\n", " sandbox = process_login()\n", " if sandbox is None:\n", " logger.error('Failed to instanciate a MEC Sandbox')\n", " return\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Print available network scenarios\n", " nw_scenarios = get_network_scenarios(sandbox)\n", " if nw_scenarios is None:\n", " logger.error('Failed to retrieve the list of network scenarios')\n", " elif len(nw_scenarios) != 0:\n", " # Wait for the MEC Sandbox is running\n", " time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n", " else:\n", " logger.info('nw_scenarios: No scenario available')\n", "\n", " # Activate a network scenario based on a list of criterias (hard coded!!!)\n", " if activate_network_scenario(sandbox) == -1:\n", " logger.error('Failed to activate network scenario')\n", " else:\n", " # Wait for the MEC services are running\n", " time.sleep(2 * STABLE_TIME_OUT) # Wait for k8s pods up and running\n", "\n", " # Request for a new application instance identifier\n", " app_inst_id = request_application_instance_id(sandbox)\n", " if app_inst_id == None:\n", " logger.error('Failed to request an application instance identifier')\n", " else:\n", " # Wait for the MEC services are terminated\n", " time.sleep(STABLE_TIME_OUT)\n", "\n", " # Send READY confirmation\n", " sub_id = None\n", " if send_ready_confirmation(sandbox, app_inst_id) == -1:\n", " logger.error('Failed to send confirm_ready')\n", " else:\n", " # Subscribe to AppTerminationNotificationSubscription\n", " result, sub_id, res_url = send_subscribe_termination(sandbox, app_inst_id)\n", " if sub_id == None:\n", " logger.error('Failed to do the subscription')\n", "\n", " return (sandbox, app_inst_id, sub_id)\n", " # End of function mec_app_setup" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### The procedure for the termination of a MEC application\n", "\n", "This function provides the steps to terminate a MEC application.\n", "\n", "NOTE: All subscriptions done outside of the mec_app_setup function are not deleted." ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "def mec_app_termination(sandbox: str, app_inst_id:swagger_client.models.ApplicationInfo, sub_id: str):\n", " \"\"\"\n", " This function provides the steps to setup a MEC application:\n", " - Login\n", " - Print sandbox identifier\n", " - Print available network scenarios\n", " - Activate a network scenario\n", " - Request for a new application instance identifier\n", " - Send READY confirmation\n", " - Subscribe to AppTermination Notification\n", " \"\"\"\n", " # Delete AppTerminationNotification subscription\n", " if sub_id is not None:\n", " if delete_subscribe_termination(sandbox, app_inst_id, sub_id) == -1:\n", " logger.error('Failed to delete the application instance identifier')\n", "\n", " # Delete the application instance identifier\n", " if delete_application_instance_id(sandbox, app_inst_id.id) == -1:\n", " logger.error('Failed to delete the application instance identifier')\n", " else:\n", " # Wait for the MEC services are terminated\n", " time.sleep(STABLE_TIME_OUT)\n", "\n", " # Deactivate a network scenario based on a list of criterias (hard coded!!!)\n", " if deactivate_network_scenario(sandbox) == -1:\n", " logger.error('Failed to deactivate network scenario')\n", " else:\n", " # Wait for the MEC services are terminated\n", " time.sleep(2 * STABLE_TIME_OUT)\n", "\n", " # Logout\n", " process_logout(sandbox)\n", "\n", " # End of function mec_app_termination" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The following cell descrbes the new basic MEC application architecture. It will be used in the rest of this titorial." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def process_main():\n", " \"\"\"\n", " This is the second sprint of our skeleton of our MEC application:\n", " - Mec application setup\n", " - Get UU unicast provisioning information\n", " - Mec application termination\n", " \"\"\" \n", " global logger, nw_scenarios\n", "\n", " logger.debug('Starting at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " logger.debug('\\t pwd= ' + os.getcwd())\n", "\n", " # Setup the MEC application\n", " (sandbox_name, app_inst_id, sub_id) = mec_app_setup()\n", "\n", " # Any processing here\n", " logger.info('sandbox_name: ' + sandbox_name)\n", " logger.info('app_inst_id: ' + app_inst_id.id)\n", " if sub_id is not None:\n", " logger.info('sub_id: ' + sub_id)\n", " time.sleep(STABLE_TIME_OUT)\n", "\n", " # Terminate the MEC application\n", " mec_app_termination(sandbox_name, app_inst_id, sub_id)\n", "\n", " logger.debug('Stopped at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " # End of function process_main\n", "\n", "if __name__ == '__main__':\n", " process_main()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create our second MEC application: how to use MEC Services\n", "\n", "After doing the logging, network scenario activation, MEC application instance creation steps, we are ready to exploit the MEC services exposed by the MEC Sandbox.\n", "\n", "In this clause, we use the following functionalities provided by MEC-030:\n", "- Getting UU unicast provisioning information (ETSI GS MEC 030 Clause 5.5.1)\n", "- Subscribe to the V2X message distribution server (ETSI GS MEC 030 Clause 5.5.7)\n", "- Delete subscription\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Getting UU unicast provisioning information\n", "\n", "The purpose is to query provisioning information for V2X communication over Uu unicast." ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "def send_uu_unicast_provisioning_info(sandbox_name: str, ecgi: str) -> object:\n", " global MEC_PLTF, logger\n", "\n", " logger.debug('>>> send_uu_unicast_provisioning_info: ' + ecgi)\n", " try:\n", " url = '/{sandbox_name}/{mec_pltf}/vis/v2/queries/uu_unicast_provisioning_info'\n", " logger.debug('send_uu_unicast_provisioning_info: url: ' + url)\n", " path_params = {}\n", " path_params['sandbox_name'] = sandbox_name\n", " path_params['mec_pltf'] = MEC_PLTF\n", " query_params = []\n", " query_params.append(('location_info', 'ecgi,' + ecgi))\n", " header_params = {}\n", " # HTTP header `Accept`\n", " header_params['Accept'] = 'application/json' # noqa: E501\n", " # HTTP header `Content-Type`\n", " header_params['Content-Type'] = 'application/json' # noqa: E501\n", " (result, status, header) = service_api.call_api(url, 'GET', header_params=header_params, path_params=path_params, query_params=query_params, async_req=False)\n", " return (result, status, header)\n", " except ApiException as e:\n", " logger.error('Exception when calling call_api: %s\\n' % e)\n", " return None\n", " # End of function send_uu_unicast_provisioning_info" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's create the our second MEC application.\n", "The sequence is the following:\n", "- Mec application setup\n", "- Get UU unicast provisioning information\n", "- Mec application termination\n", "\n", "Note that the UU unicast provisioning information is returned as a JSON string. To de-serialized it into a Python data structure, please refer to clause [Subscribing to V2X message distribution server](#subscribing_to_v2x_message_distribution_server)." ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:20:57,640 - __main__ - DEBUG - Starting at 20241010-152057\n", "2024-10-10 15:20:57,643 - __main__ - DEBUG - \t pwd= /home/yann/dev/jupyter/Sandbox/mecapp\n", "2024-10-10 15:20:57,645 - __main__ - DEBUG - >>> process_login\n", "2024-10-10 15:20:57,649 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n", "2024-10-10 15:20:57,847 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/login?provider=Jupyter2024 HTTP/1.1\" 201 48\n", "2024-10-10 15:20:57,848 DEBUG response body: b'{\"user_code\":\"sbxizaazi8\",\"verification_uri\":\"\"}'\n", "2024-10-10 15:20:57,850 - __main__ - DEBUG - process_login (step1): oauth: {'user_code': 'sbxizaazi8', 'verification_uri': ''}\n", "2024-10-10 15:20:57,851 - __main__ - DEBUG - =======================> DO AUTHORIZATION WITH CODE : sbxizaazi8\n", "2024-10-10 15:20:57,852 - __main__ - DEBUG - =======================> DO AUTHORIZATION HERE : \n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sandbox-api/v1/login?provider=Jupyter2024 HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 201 Created\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:20:57 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 48\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:21:00,880 DEBUG https://mec-platform2.etsi.org:443 \"GET /sandbox-api/v1/namespace?user_code=sbxizaazi8 HTTP/1.1\" 200 29\n", "2024-10-10 15:21:00,883 DEBUG response body: b'{\"sandbox_name\":\"sbxizaazi8\"}'\n", "2024-10-10 15:21:00,886 - __main__ - DEBUG - process_login (step2): result: {'sandbox_name': 'sbxizaazi8'}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'GET /sandbox-api/v1/namespace?user_code=sbxizaazi8 HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "reply: 'HTTP/1.1 200 OK\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:21:00 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 29\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:21:06,893 - __main__ - DEBUG - >>> get_network_scenarios: sandbox=sbxizaazi8\n", "2024-10-10 15:21:06,897 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n", "2024-10-10 15:21:07,050 DEBUG https://mec-platform2.etsi.org:443 \"GET /sandbox-api/v1/sandboxNetworkScenarios?sandbox_name=sbxizaazi8 HTTP/1.1\" 200 186\n", "2024-10-10 15:21:07,053 DEBUG response body: b'[{\"id\":\"4g-5g-macro-v2x\"},{\"id\":\"4g-5g-macro-v2x-fed\"},{\"id\":\"4g-5g-wifi-macro\"},{\"id\":\"4g-macro\"},{\"id\":\"4g-wifi-macro\"},{\"id\":\"dual-mep-4g-5g-wifi-macro\"},{\"id\":\"dual-mep-short-path\"}]'\n", "2024-10-10 15:21:07,056 - __main__ - DEBUG - get_network_scenarios: result: [{'id': '4g-5g-macro-v2x'}, {'id': '4g-5g-macro-v2x-fed'}, {'id': '4g-5g-wifi-macro'}, {'id': '4g-macro'}, {'id': '4g-wifi-macro'}, {'id': 'dual-mep-4g-5g-wifi-macro'}, {'id': 'dual-mep-short-path'}]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'GET /sandbox-api/v1/sandboxNetworkScenarios?sandbox_name=sbxizaazi8 HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "reply: 'HTTP/1.1 200 OK\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:21:06 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 186\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:21:13,059 - __main__ - DEBUG - >>> activate_network_scenario: sbxizaazi8\n", "2024-10-10 15:21:13,152 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/sandboxNetworkScenarios/sbxizaazi8?network_scenario_id=4g-5g-macro-v2x HTTP/1.1\" 204 0\n", "2024-10-10 15:21:13,154 DEBUG response body: b''\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sandbox-api/v1/sandboxNetworkScenarios/sbxizaazi8?network_scenario_id=4g-5g-macro-v2x HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:21:13 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:21:25,169 - __main__ - DEBUG - >>> request_application_instance_id: sbxizaazi8\n", "2024-10-10 15:21:25,172 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'id': '54e0e8fc-efb0-4bff-a9e1-0a1365077934',\n", " 'name': 'JupyterMecApp',\n", " 'node_name': 'mep1',\n", " 'persist': None,\n", " 'type': 'USER'}\n", "send: b'POST /sandbox-api/v1/sandboxAppInstances/sbxizaazi8 HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 107\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{\"id\": \"54e0e8fc-efb0-4bff-a9e1-0a1365077934\", \"name\": \"JupyterMecApp\", \"nodeName\": \"mep1\", \"type\": \"USER\"}'\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:21:25,392 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/sandboxAppInstances/sbxizaazi8 HTTP/1.1\" 201 100\n", "2024-10-10 15:21:25,395 DEBUG response body: b'{\"id\":\"54e0e8fc-efb0-4bff-a9e1-0a1365077934\",\"name\":\"JupyterMecApp\",\"nodeName\":\"mep1\",\"type\":\"USER\"}'\n", "2024-10-10 15:21:25,397 - __main__ - DEBUG - request_application_instance_id: result: {'id': '54e0e8fc-efb0-4bff-a9e1-0a1365077934',\n", " 'name': 'JupyterMecApp',\n", " 'node_name': 'mep1',\n", " 'persist': None,\n", " 'type': 'USER'}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "reply: 'HTTP/1.1 201 Created\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:21:25 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 100\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:21:31,404 - __main__ - DEBUG - >>> send_ready_confirmation: 54e0e8fc-efb0-4bff-a9e1-0a1365077934\n", "2024-10-10 15:21:31,406 - __main__ - DEBUG - send_ready_confirmation: url: /{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/confirm_ready\n", "2024-10-10 15:21:31,410 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n", "2024-10-10 15:21:31,538 DEBUG https://mec-platform2.etsi.org:443 \"POST /sbxizaazi8/mep1/mec_app_support/v2/applications/54e0e8fc-efb0-4bff-a9e1-0a1365077934/confirm_ready HTTP/1.1\" 204 0\n", "2024-10-10 15:21:31,538 DEBUG response body: b''\n", "2024-10-10 15:21:31,539 - __main__ - DEBUG - >>> send_subscribe_termination: 54e0e8fc-efb0-4bff-a9e1-0a1365077934\n", "2024-10-10 15:21:31,540 - __main__ - DEBUG - send_subscribe_termination: url: /{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/subscriptions\n", "2024-10-10 15:21:31,558 DEBUG https://mec-platform2.etsi.org:443 \"POST /sbxizaazi8/mep1/mec_app_support/v2/applications/54e0e8fc-efb0-4bff-a9e1-0a1365077934/subscriptions HTTP/1.1\" 201 367\n", "2024-10-10 15:21:31,558 DEBUG response body: b'{\"subscriptionType\":\"AppTerminationNotificationSubscription\",\"callbackReference\":\"http://yanngarcia.ddns.net/mec011/v2/termination\",\"_links\":{\"self\":{\"href\":\"https://mec-platform2.etsi.org/sbxizaazi8/mep1/mec_app_support/v2/applications/54e0e8fc-efb0-4bff-a9e1-0a1365077934/subscriptions/sub-vEzkyZHev4A7IiHi\"}},\"appInstanceId\":\"54e0e8fc-efb0-4bff-a9e1-0a1365077934\"}'\n", "2024-10-10 15:21:31,559 - __main__ - DEBUG - >>> extract_sub_id: resource_url: https://mec-platform2.etsi.org/sbxizaazi8/mep1/mec_app_support/v2/applications/54e0e8fc-efb0-4bff-a9e1-0a1365077934/subscriptions/sub-vEzkyZHev4A7IiHi\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sbxizaazi8/mep1/mec_app_support/v2/applications/54e0e8fc-efb0-4bff-a9e1-0a1365077934/confirm_ready HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 23\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{\"indication\": \"READY\"}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:21:31 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n", "send: b'POST /sbxizaazi8/mep1/mec_app_support/v2/applications/54e0e8fc-efb0-4bff-a9e1-0a1365077934/subscriptions HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 192\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{\"subscriptionType\": \"AppTerminationNotificationSubscription\", \"callbackReference\": \"http://yanngarcia.ddns.net/mec011/v2/termination\", \"appInstanceId\": \"54e0e8fc-efb0-4bff-a9e1-0a1365077934\"}'\n", "reply: 'HTTP/1.1 201 Created\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:21:31 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 367\n", "header: Connection: keep-alive\n", "header: Location: https://mec-platform2.etsi.org/sbxizaazi8/mep1/mec_app_support/v2/applications/54e0e8fc-efb0-4bff-a9e1-0a1365077934/subscriptions/sub-vEzkyZHev4A7IiHi\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "ename": "ValueError", "evalue": "not enough values to unpack (expected 4, got 3)", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[25], line 37\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[38;5;66;03m# End of function process_main\u001b[39;00m\n\u001b[1;32m 36\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;18m__name__\u001b[39m \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m__main__\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[0;32m---> 37\u001b[0m \u001b[43mprocess_main\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", "Cell \u001b[0;32mIn[25], line 14\u001b[0m, in \u001b[0;36mprocess_main\u001b[0;34m()\u001b[0m\n\u001b[1;32m 11\u001b[0m logger\u001b[38;5;241m.\u001b[39mdebug(\u001b[38;5;124m'\u001b[39m\u001b[38;5;130;01m\\t\u001b[39;00m\u001b[38;5;124m pwd= \u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m+\u001b[39m os\u001b[38;5;241m.\u001b[39mgetcwd())\n\u001b[1;32m 13\u001b[0m \u001b[38;5;66;03m# Setup the MEC application\u001b[39;00m\n\u001b[0;32m---> 14\u001b[0m (sandbox_name, app_inst_id, sub_id) \u001b[38;5;241m=\u001b[39m \u001b[43mmec_app_setup\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 16\u001b[0m \u001b[38;5;66;03m# Get UU unicast provisioning information\u001b[39;00m\n\u001b[1;32m 17\u001b[0m ecgi \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m268708941961,268711972264\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;66;03m# List of ecgi spearated by a ','\u001b[39;00m\n", "Cell \u001b[0;32mIn[24], line 53\u001b[0m, in \u001b[0;36mmec_app_setup\u001b[0;34m()\u001b[0m\n\u001b[1;32m 50\u001b[0m logger\u001b[38;5;241m.\u001b[39merror(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mFailed to send confirm_ready\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 51\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 52\u001b[0m \u001b[38;5;66;03m# Subscribe to AppTerminationNotificationSubscription\u001b[39;00m\n\u001b[0;32m---> 53\u001b[0m result, status, sub_id, res_url \u001b[38;5;241m=\u001b[39m send_subscribe_termination(sandbox, app_inst_id)\n\u001b[1;32m 54\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m sub_id \u001b[38;5;241m==\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 55\u001b[0m logger\u001b[38;5;241m.\u001b[39merror(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mFailed to do the subscription\u001b[39m\u001b[38;5;124m'\u001b[39m)\n", "\u001b[0;31mValueError\u001b[0m: not enough values to unpack (expected 4, got 3)" ] } ], "source": [ "def process_main():\n", " \"\"\"\n", " This is the second sprint of our skeleton of our MEC application:\n", " - Mec application setup\n", " - Get UU unicast provisioning information\n", " - Mec application termination\n", " \"\"\" \n", " global logger, nw_scenarios\n", "\n", " logger.debug('Starting at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " logger.debug('\\t pwd= ' + os.getcwd())\n", "\n", " # Setup the MEC application\n", " (sandbox_name, app_inst_id, sub_id) = mec_app_setup()\n", "\n", " # Get UU unicast provisioning information\n", " ecgi = \"268708941961,268711972264\" # List of ecgi spearated by a ','\n", " result, status, header = send_uu_unicast_provisioning_info(sandbox_name, ecgi)\n", " logger.info('UU unicast provisioning information: status: %s', str(status))\n", " if status != 200:\n", " logger.error('Failed to get UU unicast provisioning information')\n", " else:\n", " logger.info('UU unicast provisioning information: %s', str(result.data))\n", "\n", " # Any processing comes here\n", " logger.info('body: ' + str(result.data))\n", " data = json.loads(result.data)\n", " logger.info('data: ' + str(data))\n", "\n", " # Terminate the MEC application\n", " mec_app_termination(sandbox_name, app_inst_id, sub_id)\n", "\n", " logger.debug('Stopped at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " # End of function process_main\n", "\n", "if __name__ == '__main__':\n", " process_main()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Subscribing to V2X message distribution server\n", "\n", "Here, we need to come back to the MEC 030 standard to create the type V2xMsgSubscription. It involves the creation of a set of basic types described below.\n", "\n", "Note: These new type shall be 'JSON\"serializable. It means that they have to implement the following methods:\n", "```python\n", "to_dict()\n", "to_str()\n", "__repr__()\n", "__eq__()\n", "__ne__()\n", "```\n", "`\r\n", "}\r\n", "\n" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "class LinkType(object):\n", " swagger_types = {'href': 'str'}\n", " attribute_map = {'href': 'href'}\n", " def __init__(self, href=None): # noqa: E501\n", " self._href = None\n", " if href is not None:\n", " self._href = href\n", " @property\n", " def href(self):\n", " return self._href\n", " @href.setter\n", " def href(self, href):\n", " self._href = href\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(\n", " lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,\n", " value\n", " ))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(LinkType, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, LinkType):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class Links(object):\n", " swagger_types = {'self': 'LinkType'}\n", " attribute_map = {'self': 'self'}\n", " def __init__(self, self_=None): # noqa: E501\n", " self._self = None\n", " if self_ is not None:\n", " self._self = self_\n", " @property\n", " def self_(self):\n", " return self._self\n", " @self_.setter\n", " def self_(self, self_):\n", " self._self = self_\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(\n", " lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,\n", " value\n", " ))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(Links, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, Links):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class TimeStamp(object):\n", " swagger_types = {'seconds': 'int', 'nano_seconds': 'int'}\n", " attribute_map = {'seconds': 'seconds', 'nano_seconds': 'nanoSeconds'}\n", " def __init__(self, seconds=None, nano_seconds=None): # noqa: E501\n", " self._seconds = None\n", " self._nano_seconds = None\n", " if seconds is not None:\n", " self._seconds = seconds\n", " if nano_seconds is not None:\n", " self._nano_seconds = nano_seconds\n", " @property\n", " def seconds(self):\n", " return self._seconds\n", " @seconds.setter\n", " def seconds(self, seconds):\n", " self._seconds = seconds\n", " @property\n", " def nano_seconds(self):\n", " return self._nano_seconds\n", " @nano_seconds.setter\n", " def nano_seconds(self, nano_seconds):\n", " self._nano_seconds = nano_seconds\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(\n", " lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,\n", " value\n", " ))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(TimeStamp, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, TimeStamp):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Subscribing to V2X message distribution server\n", "\n", "The cell bellow implements the V2xMsgSubscription data structure.\"`\r\n", "}\r\n", "\n" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "class V2xMsgSubscription(object):\n", " swagger_types = {'links': 'Links', 'callback_reference': 'str', 'filter_criteria': 'V2xMsgSubscriptionFilterCriteria', 'request_test_notification': 'bool', 'subscription_type': 'str'}\n", " attribute_map = {'links': 'Links', 'callback_reference': 'callbackReference', 'filter_criteria': 'filterCriteria', 'request_test_notification': 'requestTestNotification', 'subscription_type': 'subscriptionType'}\n", " def __init__(self, links=None, callback_reference=None, filter_criteria=None, request_test_notification=None): # noqa: E501\n", " self._links = None\n", " self._callback_reference = None\n", " self._filter_criteria = None\n", " self._request_test_notification = None\n", " self._subscription_type = \"V2xMsgSubscription\"\n", " if links is not None:\n", " self.links = links\n", " if callback_reference is not None:\n", " self.callback_reference = callback_reference\n", " if filter_criteria is not None:\n", " self.filter_criteria = filter_criteria\n", " if request_test_notification is not None:\n", " self.request_test_notification = request_test_notification\n", " @property\n", " def links(self):\n", " return self._links\n", " @links.setter\n", " def links(self, links):\n", " self_.links = links\n", " @property\n", " def callback_reference(self):\n", " return self._callback_reference\n", " @callback_reference.setter\n", " def callback_reference(self, callback_reference):\n", " self._callback_reference = callback_reference\n", " @property\n", " def links(self):\n", " return self._links\n", " @links.setter\n", " def links(self, links):\n", " self._links = links\n", " @property\n", " def filter_criteria(self):\n", " return self._filter_criteria\n", " @filter_criteria.setter\n", " def filter_criteria(self, filter_criteria):\n", " self._filter_criteria = filter_criteria\n", " @property\n", " def request_test_notification(self):\n", " return self._request_test_notification\n", " @request_test_notification.setter\n", " def request_test_notification(self, request_test_notification):\n", " self._request_test_notification = request_test_notification\n", " @property\n", " def subscription_type(self):\n", " return self._subscription_type\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(\n", " lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,\n", " value\n", " ))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(V2xMsgSubscription, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, V2xMsgSubscription):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class V2xMsgSubscriptionFilterCriteria(object):\n", " swagger_types = {'msg_type': 'list[str]', 'std_organization': 'str'}\n", " attribute_map = {'msg_type': 'MsgType', 'std_organization': 'stdOrganization'}\n", " def __init__(self, msg_type, std_organization): # noqa: E501\n", " self._msg_type = None\n", " self._std_organization = None\n", " self.msg_type = msg_type\n", " self.std_organization = std_organization\n", " @property\n", " def msg_type(self):\n", " return self._msg_type\n", " @msg_type.setter\n", " def msg_type(self, msg_type):\n", " self._msg_type = msg_type\n", " @property\n", " def std_organization(self):\n", " return self._std_organization\n", " @std_organization.setter\n", " def std_organization(self, std_organization):\n", " self._std_organization = std_organization\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(\n", " lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,\n", " value\n", " ))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(V2xMsgSubscriptionFilterCriteria, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, V2xMsgSubscriptionFilterCriteria):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here is the V2X message subscription function. The body contains a 'JSON' serialized instance of the class V2xMsgSubscription." ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [], "source": [ "def subscribe_v2x_message(sandbox_name: str, v2xMsgSubscription: V2xMsgSubscription) -> object:\n", " global MEC_SANDBOX_URL, MEC_PLTF, CALLBACK_URI, logger\n", "\n", " logger.debug('>>> subscribe_v2x_message: v2xMsgSubscription: ' + str(v2xMsgSubscription))\n", " try:\n", " url = '/{sandbox_name}/{mec_pltf}/vis/v2/subscriptions'\n", " logger.debug('subscribe_v2x_message: url: ' + url)\n", " path_params = {}\n", " path_params['sandbox_name'] = sandbox_name\n", " path_params['mec_pltf'] = MEC_PLTF\n", " header_params = {}\n", " # HTTP header `Accept`\n", " header_params['Accept'] = 'application/json' # noqa: E501\n", " # HTTP header `Content-Type`\n", " header_params['Content-Type'] = 'application/json' # noqa: E501\n", " (result, status, headers) = service_api.call_api(url, 'POST', header_params=header_params, path_params=path_params, body=v2xMsgSubscription, async_req=False)\n", " return (result, status, extract_sub_id(headers['Location']), headers['Location'])\n", " except ApiException as e:\n", " logger.error('Exception when calling call_api: %s\\n' % e)\n", " return None\n", " # End of function subscribe_v2x_message" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here is a generic function to delete any MEC service subscription based on the subscription resource URL provided in the Location header of the subscription creation response." ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "def delete_mec_subscription(resource_url: str) -> int:\n", " global logger\n", "\n", " logger.debug('>>> delete_mec_subscription: resource_url: ' + resource_url)\n", " try:\n", " res = urllib3.util.parse_url(resource_url)\n", " if res is None:\n", " logger.error('delete_mec_subscription: Failed to paerse URL')\n", " return -1\n", " header_params = {}\n", " # HTTP header `Accept`\n", " header_params['Accept'] = 'application/json' # noqa: E501\n", " # HTTP header `Content-Type`\n", " header_params['Content-Type'] = 'application/json' # noqa: E501\n", " service_api.call_api(res.path, 'DELETE', header_params=header_params, async_req=False)\n", " return 0\n", " except ApiException as e:\n", " logger.error('Exception when calling call_api: %s\\n' % e)\n", " return -1\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finaly, here is how to implement the V2X message subscription:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def process_main():\n", " \"\"\"\n", " This is the second sprint of our skeleton of our MEC application:\n", " - Mec application setup\n", " - Subscribe to V2XMessage\n", " - Delete subscription\n", " - Mec application termination\n", " \"\"\" \n", " global MEC_PLTF, CALLBACK_URI, logger\n", "\n", " logger.debug('Starting at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " logger.debug('\\t pwd= ' + os.getcwd())\n", "\n", " # Setup the MEC application\n", " (sandbox_name, app_inst_id, sub_id) = mec_app_setup()\n", "\n", " # Create a V2X message subscritpion\n", " filter_criteria = V2xMsgSubscriptionFilterCriteria(['1', '2'], 'ETSI')\n", " v2xMsgSubscription = V2xMsgSubscription(callback_reference = CALLBACK_URI + '/vis/v2/v2x_msg_notification', filter_criteria = filter_criteria)\n", " result, status, v2x_sub_id, v2x_resource = subscribe_v2x_message(sandbox_name, v2xMsgSubscription)\n", " if status != 201:\n", " logger.error('Failed to create subscription')\n", "\n", " # Any processing here\n", " logger.info('body: ' + str(result.data))\n", " data = json.loads(result.data)\n", " logger.info('data: %s', str(data))\n", " logger.info('app_inst_id: ' + app_inst_id.id)\n", " if sub_id is not None:\n", " logger.info('sub_id: ' + sub_id)\n", " time.sleep(STABLE_TIME_OUT)\n", "\n", " # Delete the V2X message subscritpion\n", " delete_mec_subscription(v2x_resource)\n", "\n", " # Terminate the MEC application\n", " mec_app_termination(sandbox_name, app_inst_id, sub_id)\n", "\n", " logger.debug('Stopped at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " # End of function process_main\n", "\n", "if __name__ == '__main__':\n", " process_main()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Notification support\n", "\n", "To recieve notifcation, our MEC application is required to support an HTTP listenener to recieve POST request from the MEC Sandbox and replto repry to them: this is the notification mechanism.\n", "\n", "The class HTTPRequestHandler (see cell below) provides the suport of such mechanism.\n" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [], "source": [ "class HTTPRequestHandler(BaseHTTPRequestHandler):\n", " global logger\n", "\n", " def do_POST(self):\n", " if re.search(CALLBACK_URI, self.path):\n", " ctype, pdict = _parse_header(self.headers.get('content-type'))\n", " if ctype == \"application/json\":\n", " length = int(self.headers.get('content-length'))\n", " rfile_str = self.rfile.read(length).decode('utf8')\n", " data = parse.parse_qs(rfile_str, keep_blank_values=True)\n", " record_id = self.path.split('/')[-1]\n", " LocalData.records[record_id] = data\n", " logger.info('addrecord %s: %s' % (record_id, data))\n", " self.send_response(HTTPStatus.OK)\n", " else:\n", " self.send_response(HTTPStatus.BAD_REQUEST, 'Only application/json is supported')\n", " else:\n", " self.send_response(HTTPStatus.BAD_REQUEST, 'Unsupported URI')\n", " self.end_headers()\n", "\n", " def do_GET(self):\n", " self.send_response(HTTPStatus.BAD_REQUEST)\n", " self.end_headers()\n", " # End of class HTTPRequestHandler\n", "\n", "class LocalData(object):\n", " records = {}\n", " # End of class LocalData" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Put all together\n", "\n", "let's add a subscription the our previous MEC application.\n", "The sequence is the following:\n", "- Mec application setup\n", "- Get UU unicast provisioning information\n", "- Add subscription\n", "- Mec application termination" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def process_main():\n", " \"\"\"\n", " This is the second sprint of our skeleton of our MEC application:\n", " - Mec application setup\n", " - Get UU unicast provisioning information\n", " - Add subscription\n", " - Mec application termination\n", " \"\"\" \n", " global logger\n", "\n", " logger.debug('Starting at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " logger.debug('\\t pwd= ' + os.getcwd())\n", "\n", " # Setup the MEC application\n", " (sandbox_name, app_inst_id, sub_id) = mec_app_setup()\n", "\n", " # Get UU unicast provisioning information\n", " ecgi = \"268708941961,268711972264\" # List of ecgi spearated by a ','\n", " result = send_uu_unicast_provisioning_info(sandbox_name, ecgi)\n", " if result is None:\n", " logger.error('Failed to get UU unicast provisioning information')\n", " else:\n", " logger.info('UU unicast provisioning information: ', str(result))\n", "\n", " # Start notification server in a daemonized thread\n", " notification_server = threading.Thread(name='notification_server', target=HTTPRequestHandler, args=(LISTENER_IP, LISTENER_PORT))\n", " notification_server.setDaemon(True) # Set as a daemon so it will be killed once the main thread is dead.\n", " notification_server.start()\n", " # Continue\n", "\n", " # Create a V2X message subscritpion\n", " filter_criteria = V2xMsgSubscriptionFilterCriteria(['1', '2'], 'ETSI')\n", " v2xMsgSubscription = V2xMsgSubscription(callback_reference = CALLBACK_URI + '/vis/v2/v2x_msg_notification', filter_criteria = filter_criteria)\n", " result, status, v2x_sub_id, v2x_resource = subscribe_v2x_message(sandbox_name, v2xMsgSubscription)\n", " if status != 201:\n", " logger.error('Failed to create subscription')\n", "\n", " # Any processing here\n", " logger.info('body: ' + str(result.data))\n", " data = json.loads(result.data)\n", " logger.info('data: %s', str(data))\n", " logger.info('v2x_resource: ' + v2x_resource)\n", " if sub_id is not None:\n", " logger.info('sub_id: ' + sub_id)\n", " time.sleep(STABLE_TIME_OUT)\n", "\n", " # Delete the V2X message subscritpion\n", " delete_mec_subscription(v2x_resource)\n", "\n", " # Terminate the MEC application\n", " mec_app_termination(sandbox_name, app_inst_id, sub_id)\n", "\n", " logger.debug('Stopped at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " # End of function process_main\n", "\n", "if __name__ == '__main__':\n", " process_main()\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Create our third MEC application: how to use V2X QoS Prediction\n", "\n", "The MEC Sanbox V2X QoS Prediction is based on a grid Map of Monaco City where areas are categorized into residential, commercial and coastal. \n", "PoA (Point Of Access) s are categorized depending on where they lie in each grid \r\n", "Each category has its own traffic load patterns which are pre-determin. The V2X QoS PredictionPF) will give more accurate values of RSRP and RSRQ based on the diurnal traffic patterns for each z.\n", "The network scenario named \"4g-5g-v2x-macro\" must be used to get access to the V2X QoS Prediction feature.)\n", "b>Not - > The MEC Sanbox V2X QoS Predicti PF is enabled when the PredictedQos.routes.routeInfo.time attribute is present in threquest qu(ETSI GS MEC 030 Clause 6.2.6 Type: Predicd QoSeQo\n", "- Limitations:\n", "1. The Location Granularity is currently not being validated as RSRP/RSRP calculations are done at the exact location provided by the user.\r", ". \n", "Time Granularity is currently not supported by the Prediction Function (design limitations of the minimal, emulated, pre-determined traffic predictio))\n", "3. \r\n", "Upper limit on the number of elements (10 each) in the routes and routeInfo structures (arrays) to not affect user experience and respony\r\n", "\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "The table below describes the excepted Qos with and without the prediction model in deiffrent area and at different time.\n", "\n", "\n", "| Location | Time | PoA | Category | Status | QoS without Prediction Model | QoS with Prediction Model | Expected |\r\n", "| \t | (Unix time in sec) | Standard (GMT) | | | | RSRP | RSRQ | RSRP | RSRQ | |\r\n", "| ------------------- | ----------- | -------------- | ---------------- | ----------- | ------------- | -------------- | ----------- | ----------- | ----------- | -------- |\r\n", "| 43.729416,7.414853 | 1653295620 | 08:47:00 | 4g-macro-cell-2 | Residential | Congested | 63 | 21 | 60 | 20 | Yes |\r\n", "| 43.732456,7.418417 | 1653299220 | 09:47:00 | 4g-macro-cell-3 | Residential | Not Congested | 55 | 13 | 55 | 13 | Yes |\r\n", "| 43.73692,7.4209256 | 1653302820 | 10:47:00 | 4g-macro-cell-6 | Coastal | Not Congested | 68 | 26 | 68 | 26 | Yes |\r\n", "| 43.738007,7.4230533 | 1653305220 | 11:27:00 | 4g-macro-cell-6 | Coastal | Not Congested | 55 | 13 | 55 | 13 | Yes |\r\n", "| 43.739685,7.424881 | 1653308820 | 12:27:00 | 4g-macro-cell-7 | Commercial | Congested | 63 | 21 | 40 | 13 | Yes |\r\n", "| 43.74103,7.425759 | 1653312600 | 13:30:00 | 4g-macro-cell-7 | Commercial | Congested | 56 | 14 | 40 | 8 | Yes |\r\n", "| 43.74258,7.4277945 | 1653315900 | 14:25:00 | 4g-macro-cell-8 | Coastal | Congested | 59 | 17 | 47 | 13 | Yes |\r\n", "| 43.744972,7.4295254 | 1653318900 | 15:15:00 | 4g-macro-cell-8 | Coastal | Congested | 53 | 11 | 40 | 5 | Yes |\r\n", "| 43.74773,7.4320855 | 1653322500 | 16:15:00 | 5g-small-cell-14 | Commercial | Congested | 78 | 69 | 60 | 53 | Yes |\r\n", "| 43.749264,7.435894 | 1653329700 | 18:15:00 | 5g-small-cell-20 | Commercial | Not Congested | 84 | 72 | 84 | 72 | Yes |\t72\t84\t72\tYes\r\n", "\r\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The imge below illustrate the table above: [here](images/V2X Predicted QoS.jpg).\n", "\n", "Here is an example of a basic V2X predicted QoS request based on two point in path at 8am in Residential area:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```json\n", "{\r\n", " \"predictionTarget\": \"SINGLE_UE_PREDICTION\",\r\n", " \"timeGranularity\": null,\r\n", " \"locationGranularity\": \"30\",\r\n", " \"routes\": [\r\n", " {\r\n", " \"routeInfo\": [\r\n", " {\r\n", " \"location\": {\r\n", " \"geoArea\": {\r\n", " \"latitude\": 43.729416,\r\n", " \"longitude\": 7.414853\r\n", " }\r\n", " },\r\n", " \"time\": {\r\n", " \"nanoSeconds\": 0,\r\n", " \"seconds\": 1653295620\r\n", " }\r\n", " },\r\n", " {\r\n", " \"location\": {\r\n", " \"geoArea\": {\r\n", " \"latitude\": 43.732456,\r\n", " \"longitude\": 7.418417\r\n", " }\r\n", " },\r\n", " \"time\": {\r\n", " \"nanoSeconds\": 0,\r\n", " \"seconds\": 1653299220\r\n", "uest based on the JSON ab\n", "ove.\r\n", " ]\r\n", " }\r\n", " ]\r\n", "}```\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let first create the required types before to prepare a V2X Predicted QoS request based on the JSON above.\n" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "class Routes(object):\n", " swagger_types = {'_route_info': 'list[RouteInfo]'}\n", " attribute_map = {'_route_info': 'routeInfo'}\n", " def __init__(self, route_info:list): # noqa: E501\n", " self._route_info = None\n", " self.route_info = route_info\n", " @property\n", " def route_info(self):\n", " return self._route_info\n", " @route_info.setter\n", " def route_info(self, route_info):\n", " if route_info is None:\n", " raise ValueError(\"Invalid value for `route_info`, must not be `None`\") # noqa: E501\n", " self._route_info = route_info\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,value))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(Routes, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, Routes):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class LocationInfo(object):\n", " swagger_types = {'_ecgi': 'Ecgi', '_geo_area': 'LocationInfoGeoArea'}\n", " attribute_map = {'_ecgi': 'ecgi', '_geo_area': 'geoArea'}\n", " def __init__(self, ecgi=None, geo_area=None): # noqa: E501\n", " self._ecgi = None\n", " self._geo_area = None\n", " self.discriminator = None\n", " if ecgi is not None:\n", " self.ecgi = ecgi\n", " if geo_area is not None:\n", " self.geo_area = geo_area\n", " @property\n", " def ecgi(self):\n", " return self._ecgi\n", " @ecgi.setter\n", " def ecgi(self, ecgi):\n", " self._ecgi = ecgi\n", " @property\n", " def geo_area(self):\n", " return self._geo_area\n", " @geo_area.setter\n", " def geo_area(self, geo_area):\n", " self._geo_area = geo_area\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,value))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(LocationInfo, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, LocationInfo):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class RouteInfo(object):\n", " swagger_types = {'_location': 'LocationInfo', '_time_stamp': 'TimeStamp'}\n", " attribute_map = {'_location': 'location', '_time_stamp': 'time'}\n", " def __init__(self, location:LocationInfo, time_stamp=None): # noqa: E501\n", " self._location = None\n", " self.location = location\n", " self._time_stamp = None\n", " if time_stamp is not None:\n", " self.time_stamp = time_stamp\n", " @property\n", " def location(self):\n", " return self._location\n", " @location.setter\n", " def location(self, location):\n", " if location is None:\n", " raise ValueError(\"Invalid value for `location`, must not be `None`\") # noqa: E501\n", " self._location = location\n", " @property\n", " def time_stamp(self):\n", " return self._time_stamp\n", " @time_stamp.setter\n", " def time_stamp(self, time_stamp):\n", " self._time_stamp = time_stamp\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,value))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(RouteInfo, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, RouteInfo):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class LocationInfoGeoArea(object):\n", " swagger_types = {'_latitude': 'float', '_longitude': 'float'}\n", " attribute_map = {'_latitude': 'latitude', '_longitude': 'longitude'}\n", " def __init__(self, latitude, longitude): # noqa: E501\n", " self._latitude = None\n", " self._longitude = None\n", " self.discriminator = None\n", " if latitude is not None:\n", " self.latitude = latitude\n", " if longitude is not None:\n", " self.longitude = longitude\n", " @property\n", " def latitude(self):\n", " return self._latitude\n", " @latitude.setter\n", " def latitude(self, latitude):\n", " if latitude is None:\n", " raise ValueError(\"Invalid value for `latitude`, must not be `None`\") # noqa: E501\n", " self._latitude = latitude\n", " @property\n", " def longitude(self):\n", " return self._longitude\n", " @longitude.setter\n", " def longitude(self, longitude):\n", " if longitude is None:\n", " raise ValueError(\"Invalid value for `longitude`, must not be `None`\") # noqa: E501\n", " self._longitude = longitude\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,value))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(LocationInfoGeoArea, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, LocationInfoGeoArea):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class Ecgi(object):\n", " swagger_types = {'_cellId': 'CellId', '_plmn': 'Plmn'}\n", " attribute_map = {'_cellId': 'cellId', '_plmn': 'plmn'}\n", " def __init__(self, cellId=None, plmn=None): # noqa: E501\n", " self._cellId = None\n", " self._plmn = None\n", " self.discriminator = None\n", " if cellId is not None:\n", " self.cellId = cellId\n", " if plmn is not None:\n", " self.plmn = plmn\n", " @property\n", " def cellId(self):\n", " return self._cellId\n", " @cellId.setter\n", " def cellId(self, cellId):\n", " self._cellId = cellId\n", " @property\n", " def plmn(self):\n", " return self._plmn\n", " @plmn.setter\n", " def plmn(self, plmn):\n", " self._plmn = plmn\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,value))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(Ecgi, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, Ecgi):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class CellId(object):\n", " swagger_types = {'_cellId': 'str'}\n", " attribute_map = {'_cellId': 'cellId'}\n", " def __init__(self, cellId): # noqa: E501\n", " self._cellId = None\n", " self.cellId = cellId\n", " @property\n", " def cellId(self):\n", " return self._cellId\n", " @cellId.setter\n", " def cellId(self, cellId):\n", " if cellId is None:\n", " raise ValueError(\"Invalid value for `cellId`, must not be `None`\") # noqa: E501\n", " self._cellId = cellId\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,value))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(CellId, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, CellId):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class Plmn(object):\n", " swagger_types = {'_mcc': 'str', '_mnc': 'str'}\n", " attribute_map = {'_mcc': 'mcc', '_mnc': 'mnc'}\n", " def __init__(self, mcc:str, mnc:str): # noqa: E501\n", " self.discriminator = None\n", " self._mcc = None\n", " self._mnc = None\n", " self.mcc = mcc\n", " self.mnc = mnc\n", " @property\n", " def mcc(self):\n", " return self._mcc\n", " @mcc.setter\n", " def kpi_nmccame(self, mcc):\n", " if mcc is None:\n", " raise ValueError(\"Invalid value for `mcc`, must not be `None`\") # noqa: E501\n", " self._mcc = mcc\n", " @property\n", " def mnc(self):\n", " return self._mnc\n", " @mnc.setter\n", " def kpi_nmccame(self, mnc):\n", " if mnc is None:\n", " raise ValueError(\"Invalid value for `mnc`, must not be `None`\") # noqa: E501\n", " self._mnc = mnc\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,value))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(Plmn, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, Plmn):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class QosKpi(object):\n", " swagger_types = {'_kpi_name': 'str', '_kpi_value': 'str', '_confidence': 'str'}\n", " attribute_map = {'_kpi_name': 'kpiName', '_kpi_value': 'kpiValue', '_confidence': 'Confidence'}\n", " def __init__(self, kpi_name:str, kpi_value:str, confidence=None): # noqa: E501\n", " self._kpi_name = None\n", " self._kpi_value = None\n", " self._confidence = None\n", " self.kpi_name = kpi_name\n", " self.kpi_value = kpi_value\n", " if confidence is not None:\n", " self.confidences = confidence\n", " @property\n", " def kpi_name(self):\n", " return self._kpi_name\n", " @kpi_name.setter\n", " def kpi_name(self, kpi_name):\n", " if kpi_name is None:\n", " raise ValueError(\"Invalid value for `kpi_name`, must not be `None`\") # noqa: E501\n", " self._kpi_name = kpi_name\n", " @property\n", " def kpi_value(self):\n", " return self._kpi_value\n", " @kpi_value.setter\n", " def kpi_value(self, kpi_value):\n", " if kpi_value is None:\n", " raise ValueError(\"Invalid value for `kpi_value`, must not be `None`\") # noqa: E501\n", " self._kpi_value = kpi_value\n", " @property\n", " def confidence(self):\n", " return self._confidence\n", " @confidence.setter\n", " def confidence(self, confidence):\n", " self._confidence = confidence\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,value))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(QosKpi, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, QosKpi):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class Stream(object):\n", " swagger_types = {'_stream_id': 'str', '_qos_kpi': 'list[QosKpi]'}\n", " attribute_map = {'_stream_id': 'streamId', '_qos_kpi': 'qosKpi'}\n", " def __init__(self, stream_id:str, qos_kpi:list): # noqa: E501\n", " self._stream_id = None\n", " self._qos_kpi = None\n", " self.stream_id = stream_id\n", " self.qos_kpi = qos_kpi\n", " @property\n", " def stream_id(self):\n", " return self._stream_id\n", " @stream_id.setter\n", " def stream_id(self, stream_id):\n", " if stream_id is None:\n", " raise ValueError(\"Invalid value for `stream_id`, must not be `None`\") # noqa: E501\n", " self._stream_id = stream_id\n", " @property\n", " def qos_kpi(self):\n", " return self._qos_kpi\n", " @qos_kpi.setter\n", " def qos_kpi(self, qos_kpi):\n", " if qos_kpi is None:\n", " raise ValueError(\"Invalid value for `qos_kpi`, must not be `None`\") # noqa: E501\n", " self._qos_kpi = qos_kpi\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(\n", " lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,\n", " value\n", " ))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(Stream, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, Stream):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class Qos(object):\n", " swagger_types = {'_stream': 'list[Stream]'}\n", " attribute_map = {'_stream': 'stream'}\n", " def __init__(self, stream:list): # noqa: E501\n", " self._stream = None\n", " self.stream = stream\n", " @property\n", " def stream(self):\n", " return self._stream\n", " @stream.setter\n", " def stream(self, stream):\n", " if stream is None:\n", " raise ValueError(\"Invalid value for `stream`, must not be `None`\") # noqa: E501\n", " self._stream = stream\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(\n", " lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,\n", " value\n", " ))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(Qos, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, Qos):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class PredictedQos(object):\n", " swagger_types = {'_location_granularity': 'str', '_notice_period': 'TimeStamp', '_prediction_area': 'PredictionArea', '_prediction_target': 'str', '_qos': 'Qos', '_routes': 'list[Routes]', '_time_granularity': 'TimeStamp'}\n", " attribute_map = {'_location_granularity': 'locationGranularity', '_notice_period': 'noticePeriod', '_prediction_area': 'predictionArea', '_prediction_target': 'predictionTarget', '_qos': 'qos', '_routes': 'routes', '_time_granularity': 'timeGranularity'}\n", " def __init__(self, prediction_target:str, location_granularity:str, notice_period=None, time_granularity=None, prediction_area=None, routes=None, qos=None): # noqa: E501\n", " self._prediction_target = None\n", " self._time_granularity = None\n", " self._location_granularity = None\n", " self._notice_period = None\n", " self._prediction_area = None\n", " self._routes = None\n", " self._qos = None\n", " self._prediction_target = prediction_target\n", " if time_granularity is not None:\n", " self.time_granularity = time_granularity\n", " self.location_granularity = location_granularity\n", " if notice_period is not None:\n", " self.notice_period = notice_period\n", " if prediction_area is not None:\n", " self.prediction_area = prediction_area\n", " if routes is not None:\n", " self.routes = routes\n", " if qos is not None:\n", " self.qos = qos\n", " @property\n", " def prediction_target(self):\n", " return self._prediction_target\n", " @prediction_target.setter\n", " def prediction_target(self, prediction_target):\n", " if prediction_target is None:\n", " raise ValueError(\"Invalid value for `prediction_target`, must not be `None`\") # noqa: E501\n", " self._prediction_target = prediction_target\n", " @property\n", " def time_granularity(self):\n", " return self._time_granularity\n", " @time_granularity.setter\n", " def time_granularity(self, time_granularity):\n", " self._time_granularity = time_granularity\n", " @property\n", " def location_granularity(self):\n", " return self._location_granularity\n", " @location_granularity.setter\n", " def location_granularity(self, location_granularity):\n", " if location_granularity is None:\n", " raise ValueError(\"Invalid value for `location_granularity`, must not be `None`\") # noqa: E501\n", " self._location_granularity = location_granularity\n", " @property\n", " def notice_period(self):\n", " return self._notice_period\n", " @notice_period.setter\n", " def notice_period(self, notice_period):\n", " self._notice_period = notice_period\n", " @property\n", " def prediction_area(self):\n", " return self._prediction_area\n", " @prediction_area.setter\n", " def prediction_area(self, prediction_area):\n", " self._prediction_area = prediction_area\n", " @property\n", " def routes(self):\n", " return self._routes\n", " @routes.setter\n", " def routes(self, routes):\n", " self._routes = routes\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(\n", " lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,\n", " value\n", " ))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(PredictedQos, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, PredictedQos):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here is the V2X Prediscted QoS:" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [], "source": [ "def get_qos_prediction(sandbox_name: str) -> object:\n", " global MEC_PLTF, logger\n", "\n", " logger.debug('>>> get_qos_prediction: sandbox_name: ' + sandbox_name)\n", " try:\n", " url = '/{sandbox_name}/{mec_pltf}/vis/v2/provide_predicted_qos'\n", " logger.debug('send_uu_unicast_provisioning_info: url: ' + url)\n", " path_params = {}\n", " path_params['sandbox_name'] = sandbox_name\n", " path_params['mec_pltf'] = MEC_PLTF\n", " # HTTP header `Accept`\n", " header_params = {}\n", " header_params['Accept'] = 'application/json' # noqa: E501\n", " # HTTP header `Content-Type`\n", " header_params['Content-Type'] = 'application/json' # noqa: E501\n", " # Body request\n", " loc1 = LocationInfo(geo_area=LocationInfoGeoArea(latitude=43.729416, longitude=7.414853))\n", " loc2 = LocationInfo(geo_area=LocationInfoGeoArea(latitude=43.732456, longitude=7.418417))\n", " routeInfo1 = RouteInfo(loc1, TimeStamp(nano_seconds=0, seconds=1653295620))\n", " routeInfo2 = RouteInfo(loc2, TimeStamp(nano_seconds=0, seconds=1653299220))\n", " routesInfo = [routeInfo1, routeInfo2]\n", " predictedQos = PredictedQos(prediction_target=\"SINGLE_UE_PREDICTION\", location_granularity=\"30\", routes=[Routes(routesInfo)])\n", " (result, status, headers) = service_api.call_api(url, 'POST', header_params=header_params, path_params=path_params, body=predictedQos, async_req=False)\n", " return (result, status, headers)\n", " except ApiException as e:\n", " logger.error('Exception when calling call_api: %s\\n' % e)\n", " return None\n", " # End of function send_uu_unicast_provisioning_info" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Grouping all together provides the process_main funtion.. The sequence is the following:\n", "- Mec application setup\n", "- V2X QoS request\n", "- Mec application termination\n", "\n", "The expected response should be:\n", "- RSRP: 55\n", "- RSRQ: 13" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:28:52,773 - __main__ - DEBUG - Starting at 20241010-152852\n", "2024-10-10 15:28:52,775 - __main__ - DEBUG - \t pwd= /home/yann/dev/jupyter/Sandbox/mecapp\n", "2024-10-10 15:28:52,779 - __main__ - DEBUG - >>> process_login\n", "2024-10-10 15:28:52,781 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n", "2024-10-10 15:28:52,989 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/login?provider=Jupyter2024 HTTP/1.1\" 201 48\n", "2024-10-10 15:28:52,990 DEBUG response body: b'{\"user_code\":\"sbx0gt5amu\",\"verification_uri\":\"\"}'\n", "2024-10-10 15:28:52,991 - __main__ - DEBUG - process_login (step1): oauth: {'user_code': 'sbx0gt5amu', 'verification_uri': ''}\n", "2024-10-10 15:28:52,993 - __main__ - DEBUG - =======================> DO AUTHORIZATION WITH CODE : sbx0gt5amu\n", "2024-10-10 15:28:52,995 - __main__ - DEBUG - =======================> DO AUTHORIZATION HERE : \n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sandbox-api/v1/login?provider=Jupyter2024 HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 201 Created\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:28:52 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 48\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:28:56,039 DEBUG https://mec-platform2.etsi.org:443 \"GET /sandbox-api/v1/namespace?user_code=sbx0gt5amu HTTP/1.1\" 200 29\n", "2024-10-10 15:28:56,042 DEBUG response body: b'{\"sandbox_name\":\"sbx0gt5amu\"}'\n", "2024-10-10 15:28:56,045 - __main__ - DEBUG - process_login (step2): result: {'sandbox_name': 'sbx0gt5amu'}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'GET /sandbox-api/v1/namespace?user_code=sbx0gt5amu HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "reply: 'HTTP/1.1 200 OK\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:28:55 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 29\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:29:02,048 - __main__ - DEBUG - >>> get_network_scenarios: sandbox=sbx0gt5amu\n", "2024-10-10 15:29:02,051 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n", "2024-10-10 15:29:02,229 DEBUG https://mec-platform2.etsi.org:443 \"GET /sandbox-api/v1/sandboxNetworkScenarios?sandbox_name=sbx0gt5amu HTTP/1.1\" 200 186\n", "2024-10-10 15:29:02,231 DEBUG response body: b'[{\"id\":\"4g-5g-macro-v2x\"},{\"id\":\"4g-5g-macro-v2x-fed\"},{\"id\":\"4g-5g-wifi-macro\"},{\"id\":\"4g-macro\"},{\"id\":\"4g-wifi-macro\"},{\"id\":\"dual-mep-4g-5g-wifi-macro\"},{\"id\":\"dual-mep-short-path\"}]'\n", "2024-10-10 15:29:02,232 - __main__ - DEBUG - get_network_scenarios: result: [{'id': '4g-5g-macro-v2x'}, {'id': '4g-5g-macro-v2x-fed'}, {'id': '4g-5g-wifi-macro'}, {'id': '4g-macro'}, {'id': '4g-wifi-macro'}, {'id': 'dual-mep-4g-5g-wifi-macro'}, {'id': 'dual-mep-short-path'}]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'GET /sandbox-api/v1/sandboxNetworkScenarios?sandbox_name=sbx0gt5amu HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "reply: 'HTTP/1.1 200 OK\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:29:02 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 186\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:29:08,239 - __main__ - DEBUG - >>> activate_network_scenario: sbx0gt5amu\n", "2024-10-10 15:29:08,299 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/sandboxNetworkScenarios/sbx0gt5amu?network_scenario_id=4g-5g-macro-v2x HTTP/1.1\" 204 0\n", "2024-10-10 15:29:08,302 DEBUG response body: b''\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sandbox-api/v1/sandboxNetworkScenarios/sbx0gt5amu?network_scenario_id=4g-5g-macro-v2x HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:29:08 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:29:20,316 - __main__ - DEBUG - >>> request_application_instance_id: sbx0gt5amu\n", "2024-10-10 15:29:20,319 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n", "2024-10-10 15:29:20,505 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/sandboxAppInstances/sbx0gt5amu HTTP/1.1\" 201 100\n", "2024-10-10 15:29:20,507 DEBUG response body: b'{\"id\":\"6ea0e588-f421-4c01-8e9e-7c6617e5fba7\",\"name\":\"JupyterMecApp\",\"nodeName\":\"mep1\",\"type\":\"USER\"}'\n", "2024-10-10 15:29:20,510 - __main__ - DEBUG - request_application_instance_id: result: {'id': '6ea0e588-f421-4c01-8e9e-7c6617e5fba7',\n", " 'name': 'JupyterMecApp',\n", " 'node_name': 'mep1',\n", " 'persist': None,\n", " 'type': 'USER'}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'id': '6ea0e588-f421-4c01-8e9e-7c6617e5fba7',\n", " 'name': 'JupyterMecApp',\n", " 'node_name': 'mep1',\n", " 'persist': None,\n", " 'type': 'USER'}\n", "send: b'POST /sandbox-api/v1/sandboxAppInstances/sbx0gt5amu HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 107\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{\"id\": \"6ea0e588-f421-4c01-8e9e-7c6617e5fba7\", \"name\": \"JupyterMecApp\", \"nodeName\": \"mep1\", \"type\": \"USER\"}'\n", "reply: 'HTTP/1.1 201 Created\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:29:20 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 100\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:29:26,518 - __main__ - DEBUG - >>> send_ready_confirmation: 6ea0e588-f421-4c01-8e9e-7c6617e5fba7\n", "2024-10-10 15:29:26,521 - __main__ - DEBUG - send_ready_confirmation: url: /{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/confirm_ready\n", "2024-10-10 15:29:26,524 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n", "2024-10-10 15:29:26,658 DEBUG https://mec-platform2.etsi.org:443 \"POST /sbx0gt5amu/mep1/mec_app_support/v2/applications/6ea0e588-f421-4c01-8e9e-7c6617e5fba7/confirm_ready HTTP/1.1\" 204 0\n", "2024-10-10 15:29:26,659 DEBUG response body: b''\n", "2024-10-10 15:29:26,660 - __main__ - DEBUG - >>> send_subscribe_termination: 6ea0e588-f421-4c01-8e9e-7c6617e5fba7\n", "2024-10-10 15:29:26,660 - __main__ - DEBUG - send_subscribe_termination: url: /{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/subscriptions\n", "2024-10-10 15:29:26,678 DEBUG https://mec-platform2.etsi.org:443 \"POST /sbx0gt5amu/mep1/mec_app_support/v2/applications/6ea0e588-f421-4c01-8e9e-7c6617e5fba7/subscriptions HTTP/1.1\" 201 367\n", "2024-10-10 15:29:26,680 DEBUG response body: b'{\"subscriptionType\":\"AppTerminationNotificationSubscription\",\"callbackReference\":\"http://yanngarcia.ddns.net/mec011/v2/termination\",\"_links\":{\"self\":{\"href\":\"https://mec-platform2.etsi.org/sbx0gt5amu/mep1/mec_app_support/v2/applications/6ea0e588-f421-4c01-8e9e-7c6617e5fba7/subscriptions/sub-biC1jfldf9zjXl8s\"}},\"appInstanceId\":\"6ea0e588-f421-4c01-8e9e-7c6617e5fba7\"}'\n", "2024-10-10 15:29:26,680 - __main__ - DEBUG - >>> extract_sub_id: resource_url: https://mec-platform2.etsi.org/sbx0gt5amu/mep1/mec_app_support/v2/applications/6ea0e588-f421-4c01-8e9e-7c6617e5fba7/subscriptions/sub-biC1jfldf9zjXl8s\n", "2024-10-10 15:29:26,681 - __main__ - DEBUG - >>> get_qos_prediction: sandbox_name: sbx0gt5amu\n", "2024-10-10 15:29:26,682 - __main__ - DEBUG - send_uu_unicast_provisioning_info: url: /{sandbox_name}/{mec_pltf}/vis/v2/provide_predicted_qos\n", "2024-10-10 15:29:26,739 DEBUG https://mec-platform2.etsi.org:443 \"POST /sbx0gt5amu/mep1/vis/v2/provide_predicted_qos HTTP/1.1\" 200 610\n", "2024-10-10 15:29:26,742 DEBUG response body: b'{\"locationGranularity\":\"30\",\"predictionTarget\":\"SINGLE_UE_PREDICTION\",\"qos\":{\"stream\":[{\"streamId\":\"0\",\"qosKpi\":[{\"confidence\":\"1\",\"kpiName\":\"rsrp\",\"kpiValue\":\"60\"},{\"confidence\":\"1\",\"kpiName\":\"rsrq\",\"kpiValue\":\"20\"}]},{\"streamId\":\"1\",\"qosKpi\":[{\"confidence\":\"1\",\"kpiName\":\"rsrp\",\"kpiValue\":\"55\"},{\"confidence\":\"1\",\"kpiName\":\"rsrq\",\"kpiValue\":\"13\"}]}]},\"routes\":[{\"routeInfo\":[{\"location\":{\"geoArea\":{\"latitude\":43.729416,\"longitude\":7.414853}},\"time\":{\"nanoSeconds\":0,\"seconds\":1653295620}},{\"location\":{\"geoArea\":{\"latitude\":43.732456,\"longitude\":7.418417}},\"time\":{\"nanoSeconds\":0,\"seconds\":1653299220}}]}]}'\n", "2024-10-10 15:29:26,744 - __main__ - INFO - UU unicast provisioning information: result: b'{\"locationGranularity\":\"30\",\"predictionTarget\":\"SINGLE_UE_PREDICTION\",\"qos\":{\"stream\":[{\"streamId\":\"0\",\"qosKpi\":[{\"confidence\":\"1\",\"kpiName\":\"rsrp\",\"kpiValue\":\"60\"},{\"confidence\":\"1\",\"kpiName\":\"rsrq\",\"kpiValue\":\"20\"}]},{\"streamId\":\"1\",\"qosKpi\":[{\"confidence\":\"1\",\"kpiName\":\"rsrp\",\"kpiValue\":\"55\"},{\"confidence\":\"1\",\"kpiName\":\"rsrq\",\"kpiValue\":\"13\"}]}]},\"routes\":[{\"routeInfo\":[{\"location\":{\"geoArea\":{\"latitude\":43.729416,\"longitude\":7.414853}},\"time\":{\"nanoSeconds\":0,\"seconds\":1653295620}},{\"location\":{\"geoArea\":{\"latitude\":43.732456,\"longitude\":7.418417}},\"time\":{\"nanoSeconds\":0,\"seconds\":1653299220}}]}]}'\n", "2024-10-10 15:29:26,745 - __main__ - INFO - body: b'{\"locationGranularity\":\"30\",\"predictionTarget\":\"SINGLE_UE_PREDICTION\",\"qos\":{\"stream\":[{\"streamId\":\"0\",\"qosKpi\":[{\"confidence\":\"1\",\"kpiName\":\"rsrp\",\"kpiValue\":\"60\"},{\"confidence\":\"1\",\"kpiName\":\"rsrq\",\"kpiValue\":\"20\"}]},{\"streamId\":\"1\",\"qosKpi\":[{\"confidence\":\"1\",\"kpiName\":\"rsrp\",\"kpiValue\":\"55\"},{\"confidence\":\"1\",\"kpiName\":\"rsrq\",\"kpiValue\":\"13\"}]}]},\"routes\":[{\"routeInfo\":[{\"location\":{\"geoArea\":{\"latitude\":43.729416,\"longitude\":7.414853}},\"time\":{\"nanoSeconds\":0,\"seconds\":1653295620}},{\"location\":{\"geoArea\":{\"latitude\":43.732456,\"longitude\":7.418417}},\"time\":{\"nanoSeconds\":0,\"seconds\":1653299220}}]}]}'\n", "2024-10-10 15:29:26,747 - __main__ - INFO - data: {'locationGranularity': '30', 'predictionTarget': 'SINGLE_UE_PREDICTION', 'qos': {'stream': [{'streamId': '0', 'qosKpi': [{'confidence': '1', 'kpiName': 'rsrp', 'kpiValue': '60'}, {'confidence': '1', 'kpiName': 'rsrq', 'kpiValue': '20'}]}, {'streamId': '1', 'qosKpi': [{'confidence': '1', 'kpiName': 'rsrp', 'kpiValue': '55'}, {'confidence': '1', 'kpiName': 'rsrq', 'kpiValue': '13'}]}]}, 'routes': [{'routeInfo': [{'location': {'geoArea': {'latitude': 43.729416, 'longitude': 7.414853}}, 'time': {'nanoSeconds': 0, 'seconds': 1653295620}}, {'location': {'geoArea': {'latitude': 43.732456, 'longitude': 7.418417}}, 'time': {'nanoSeconds': 0, 'seconds': 1653299220}}]}]}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sbx0gt5amu/mep1/mec_app_support/v2/applications/6ea0e588-f421-4c01-8e9e-7c6617e5fba7/confirm_ready HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 23\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{\"indication\": \"READY\"}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:29:26 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n", "send: b'POST /sbx0gt5amu/mep1/mec_app_support/v2/applications/6ea0e588-f421-4c01-8e9e-7c6617e5fba7/subscriptions HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 192\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{\"subscriptionType\": \"AppTerminationNotificationSubscription\", \"callbackReference\": \"http://yanngarcia.ddns.net/mec011/v2/termination\", \"appInstanceId\": \"6ea0e588-f421-4c01-8e9e-7c6617e5fba7\"}'\n", "reply: 'HTTP/1.1 201 Created\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:29:26 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 367\n", "header: Connection: keep-alive\n", "header: Location: https://mec-platform2.etsi.org/sbx0gt5amu/mep1/mec_app_support/v2/applications/6ea0e588-f421-4c01-8e9e-7c6617e5fba7/subscriptions/sub-biC1jfldf9zjXl8s\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n", "send: b'POST /sbx0gt5amu/mep1/vis/v2/provide_predicted_qos HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 354\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{\"locationGranularity\": \"30\", \"predictionTarget\": \"SINGLE_UE_PREDICTION\", \"routes\": [{\"routeInfo\": [{\"location\": {\"geoArea\": {\"latitude\": 43.729416, \"longitude\": 7.414853}}, \"time\": {\"seconds\": 1653295620, \"nanoSeconds\": 0}}, {\"location\": {\"geoArea\": {\"latitude\": 43.732456, \"longitude\": 7.418417}}, \"time\": {\"seconds\": 1653299220, \"nanoSeconds\": 0}}]}]}'\n", "reply: 'HTTP/1.1 200 OK\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:29:26 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 610\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:29:32,755 - __main__ - DEBUG - >>> delete_subscribe_termination: 6ea0e588-f421-4c01-8e9e-7c6617e5fba7\n", "2024-10-10 15:29:32,757 - __main__ - DEBUG - delete_subscribe_termination: url: /{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/subscriptions/{sub_id}\n", "2024-10-10 15:29:32,807 DEBUG https://mec-platform2.etsi.org:443 \"DELETE /sbx0gt5amu/mep1/mec_app_support/v2/applications/6ea0e588-f421-4c01-8e9e-7c6617e5fba7/subscriptions/sub-biC1jfldf9zjXl8s HTTP/1.1\" 204 0\n", "2024-10-10 15:29:32,810 DEBUG response body: b''\n", "2024-10-10 15:29:32,812 - __main__ - DEBUG - >>> delete_application_instance_id: sbx0gt5amu\n", "2024-10-10 15:29:32,814 - __main__ - DEBUG - >>> delete_application_instance_id: 6ea0e588-f421-4c01-8e9e-7c6617e5fba7\n", "2024-10-10 15:29:32,847 DEBUG https://mec-platform2.etsi.org:443 \"DELETE /sandbox-api/v1/sandboxAppInstances/sbx0gt5amu/6ea0e588-f421-4c01-8e9e-7c6617e5fba7 HTTP/1.1\" 204 0\n", "2024-10-10 15:29:32,850 DEBUG response body: b''\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'DELETE /sbx0gt5amu/mep1/mec_app_support/v2/applications/6ea0e588-f421-4c01-8e9e-7c6617e5fba7/subscriptions/sub-biC1jfldf9zjXl8s HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:29:32 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n", "send: b'DELETE /sandbox-api/v1/sandboxAppInstances/sbx0gt5amu/6ea0e588-f421-4c01-8e9e-7c6617e5fba7 HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:29:32 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:29:38,859 - __main__ - DEBUG - >>> deactivate_network_scenario: sbx0gt5amu\n", "2024-10-10 15:29:38,929 DEBUG https://mec-platform2.etsi.org:443 \"DELETE /sandbox-api/v1/sandboxNetworkScenarios/sbx0gt5amu/4g-5g-macro-v2x HTTP/1.1\" 204 0\n", "2024-10-10 15:29:38,931 DEBUG response body: b''\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'DELETE /sandbox-api/v1/sandboxNetworkScenarios/sbx0gt5amu/4g-5g-macro-v2x HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:29:38 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:29:50,946 - __main__ - DEBUG - >>> process_logout: sandbox=sbx0gt5amu\n", "2024-10-10 15:29:50,949 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n", "2024-10-10 15:29:51,097 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/logout?sandbox_name=sbx0gt5amu HTTP/1.1\" 204 0\n", "2024-10-10 15:29:51,098 DEBUG response body: b''\n", "2024-10-10 15:29:51,098 - __main__ - DEBUG - Stopped at 20241010-152951\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sandbox-api/v1/logout?sandbox_name=sbx0gt5amu HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:29:50 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] } ], "source": [ "def process_main():\n", " \"\"\"\n", " This is the second sprint of our skeleton of our MEC application:\n", " - Mec application setup\n", " - V2X QoS request\n", " - Mec application termination\n", " \"\"\" \n", " global logger\n", "\n", " logger.debug('Starting at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " logger.debug('\\t pwd= ' + os.getcwd())\n", "\n", " # Setup the MEC application\n", " sandbox_name, app_inst_id, sub_id = mec_app_setup()\n", "\n", " # QoS Prediction\n", " (result, status, headers) = get_qos_prediction(sandbox_name)\n", " if status != 200:\n", " logger.error('Failed to get UU unicast provisioning information')\n", " else:\n", " logger.info('UU unicast provisioning information: result: %s', str(result.data))\n", " \n", " # Any processing here\n", " logger.info('body: ' + str(result.data))\n", " data = json.loads(result.data)\n", " logger.info('data: %s', str(data))\n", " time.sleep(STABLE_TIME_OUT)\n", "\n", " # Terminate the MEC application\n", " mec_app_termination(sandbox_name, app_inst_id, sub_id)\n", "\n", " logger.debug('Stopped at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " # End of function process_main\n", "\n", "if __name__ == '__main__':\n", " process_main()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Our third MEC application: how to create a new MEC Services\n", "\n", "The cells below are under develpment\n", "\n", "The purpose of this MEC Service application is to provide a custom MEC service that can be use by other MEC applications. For the purpose of this tutorial, our MEC service is simulating some complex calculation based on a set of data provided by the MEC use. \n", "We will use a second MEC application to exploit the features of our new MEC services.\n", "\n", "In this clause, we use the following functionalities provided by MEC-011:\n", "- Register a new service\n", "- Retrieve the list of the MEC services exposed by the MEC platform\n", "- Check that our new MEC service is present in the list of the MEC platform services\n", "- Execute a request to the MEC service\n", "- Delete the newly created service\n", "\n", "Note: We will use a second MEC application to exploit the features of our new MEC services.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Bases of the creation of a MEC service\n", "\n", "#### Introduction\n", "\n", "From the user perspective, a MEC service provides a set of endpoints which describe the interface of the MEC service (see [HTTP REST APIs \n", "concepts](https://blog.postman.com/rest-api-examples/)). These endpoints come usually with a set of data structures used by the one or more endpoints.\n", "\n", "Our service is really basic: it provide one endpoint:\n", "- GET /statistic/v1/quantity: it computes statistical quantities of a set of data (such as average, max, min, standard deviation)\n", "\n", "The body of this GET method is a list of datas:\n", "```json\n", "{\"time\":20180124,\"data1\":\"[1516752000,11590.6,11616.9,11590.4,11616.9,0.25202387,1516752060,11622.4,11651.7,11622.4,11644.6,1.03977764]\"}\n", "```\n", "\n", "The response body is the list of statistical quantities:\n", "```json\n", "{\"time\":20180124,\"avg\": 0.0,\"max\": 0.0,\"min\": 0.0,\"stddev\": 0.0 }\n", "```\n", "\n", "#### MEC mechanisms to create a new service\n", "\n", "As described in ETSI GS MEC 011 Clause 5.2.4 Service availability update and new service registration, to create a new MEC service, the following information is required:\n", "- A MEC Aplication instance: this is the MEC application providing the new MEC service (ETSI GS MEC 011 V3.2.1 Clause 8.2.6.3.4 POST)\n", "- A ServiceInfo instance which describe the MEC service (ETSI GS MEC 011 V3.2.1 Clause 8.1.2.2 Type: ServiceInfo)\n", "- As part of the ServiceInfo instance, a TransportInfo (ETSI GS MEC 011 V3.2.1 Clause 8.1.2.3 Type: TransportInfo) instance descibes the endpoints to use the MEC service\n", "\n", "When created and available, all the other MEC applications are notified about the existance of this MEC service." ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [], "source": [ "class ServiceInfo(object):\n", " swagger_types = {'ser_instance_id': 'str','ser_name': 'str','ser_category': 'CategoryRef','version': 'str','state': 'str','transport_id': 'str','transport_info': 'TransportInfo','serializer': 'string','scope_of_locality': 'LocalityType','consumed_local_only': 'bool','is_local': 'bool','liveness_interval': 'int','links': 'ServiceInfoLinks'}\n", " attribute_map = {'ser_instance_id': 'serInstanceId','ser_name': 'serName','ser_category': 'serCategory','version': 'version','state': 'state','transport_id': 'transportId','transport_info': 'transportInfo','serializer': 'serializer','scope_of_locality': 'scopeOfLocality','consumed_local_only': 'consumedLocalOnly','is_local': 'isLocal','liveness_interval': 'livenessInterval','links': '_links'}\n", " def __init__(self, ser_instance_id=None, ser_name=None, ser_category=None, version=None, state=None, transport_id=None, transport_info=None, serializer=None, scope_of_locality=None, consumed_local_only=None, is_local=None, liveness_interval=None, links=None): # noqa: E501\n", " self._ser_instance_id = None\n", " self._ser_name = None\n", " self._ser_category = None\n", " self._version = None\n", " self._state = None\n", " self._transport_id = None\n", " self._transport_info = None\n", " self._serializer = None\n", " self._scope_of_locality = None\n", " self._consumed_local_only = None\n", " self._is_local = None\n", " self._liveness_interval = None\n", " self._links = None\n", " self.discriminator = None\n", " if ser_instance_id is not None:\n", " self.ser_instance_id = ser_instance_id\n", " self.ser_name = ser_name\n", " if ser_category is not None:\n", " self.ser_category = ser_category\n", " self.version = version\n", " self.state = state\n", " if transport_id is not None:\n", " self.transport_id = transport_id\n", " self.transport_info = transport_info\n", " self.serializer = serializer\n", " if scope_of_locality is not None:\n", " self.scope_of_locality = scope_of_locality\n", " if consumed_local_only is not None:\n", " self.consumed_local_only = consumed_local_only\n", " if is_local is not None:\n", " self.is_local = is_local\n", " if liveness_interval is not None:\n", " self.liveness_interval = liveness_interval\n", " if links is not None:\n", " self.links = links\n", " @property\n", " def ser_instance_id(self):\n", " return self._ser_instance_id\n", " @ser_instance_id.setter\n", " def ser_instance_id(self, ser_instance_id):\n", " self._ser_instance_id = ser_instance_id\n", " @property\n", " def ser_name(self):\n", " return self._ser_name\n", " @ser_name.setter\n", " def ser_name(self, ser_name):\n", " if ser_name is None:\n", " raise ValueError(\"Invalid value for `ser_name`, must not be `None`\") # noqa: E501\n", " self._ser_name = ser_name\n", " @property\n", " def ser_category(self):\n", " return self._ser_category\n", " @ser_category.setter\n", " def ser_category(self, ser_category):\n", " self._ser_category = ser_category\n", " @property\n", " def version(self):\n", " return self._version\n", " @version.setter\n", " def version(self, version):\n", " if version is None:\n", " raise ValueError(\"Invalid value for `version`, must not be `None`\") # noqa: E501\n", " self._version = version\n", " @property\n", " def state(self):\n", " return self._state\n", " @state.setter\n", " def state(self, state):\n", " if state is None:\n", " raise ValueError(\"Invalid value for `state`, must not be `None`\") # noqa: E501\n", " self._state = state\n", " @property\n", " def transport_id(self):\n", " return self._transport_id\n", " @transport_id.setter\n", " def transport_id(self, transport_id):\n", " self._transport_id = transport_id\n", " @property\n", " def transport_info(self):\n", " return self._transport_info\n", " @transport_info.setter\n", " def transport_info(self, transport_info):\n", " if transport_info is None:\n", " raise ValueError(\"Invalid value for `transport_info`, must not be `None`\") # noqa: E501\n", " self._transport_info = transport_info\n", " @property\n", " def serializer(self):\n", " return self._serializer\n", " @serializer.setter\n", " def serializer(self, serializer):\n", " if serializer is None:\n", " raise ValueError(\"Invalid value for `serializer`, must not be `None`\") # noqa: E501\n", " self._serializer = serializer\n", " @property\n", " def scope_of_locality(self):\n", " return self._scope_of_locality\n", " @scope_of_locality.setter\n", " def scope_of_locality(self, scope_of_locality):\n", " self._scope_of_locality = scope_of_locality\n", " @property\n", " def consumed_local_only(self):\n", " return self._consumed_local_only\n", " @consumed_local_only.setter\n", " def consumed_local_only(self, consumed_local_only):\n", " self._consumed_local_only = consumed_local_only\n", " @property\n", " def is_local(self):\n", " return self._is_local\n", " @is_local.setter\n", " def is_local(self, is_local):\n", " self._is_local = is_local\n", " @property\n", " def liveness_interval(self):\n", " return self._liveness_interval\n", " @liveness_interval.setter\n", " def liveness_interval(self, liveness_interval):\n", " self._liveness_interval = liveness_interval\n", " @property\n", " def links(self):\n", " return self._links\n", " @links.setter\n", " def links(self, links):\n", " self._links = links\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(\n", " lambda x: x.to_dict() if hasattr(x, \"to_dict\") else x,\n", " value\n", " ))\n", " elif hasattr(value, \"to_dict\"):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], \"to_dict\") else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(ServiceInfo, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, ServiceInfo):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class CategoryRef(object):\n", " swagger_types = {'href': 'str','id': 'str','name': 'str','version': 'str'}\n", " attribute_map = {'href': 'href','id': 'id','name': 'name','version': 'version'}\n", " def __init__(self, href=None, id=None, name=None, version=None): # noqa: E501\n", " self._href = None\n", " self._id = None\n", " self._name = None\n", " self._version = None\n", " self.discriminator = None\n", " self.href = href\n", " self.id = id\n", " self.name = name\n", " self.version = version\n", " @property\n", " def href(self):\n", " return self._href\n", " @href.setter\n", " def href(self, href):\n", " if href is None:\n", " raise ValueError(\"Invalid value for `href`, must not be `None`\") # noqa: E501\n", " self._href = href\n", " @property\n", " def id(self):\n", " return self._id\n", " @id.setter\n", " def id(self, id):\n", " if id is None:\n", " raise ValueError(\"Invalid value for `id`, must not be `None`\") # noqa: E501\n", " self._id = id\n", " @property\n", " def name(self):\n", " return self._name\n", " @name.setter\n", " def name(self, name):\n", " if name is None:\n", " raise ValueError(\"Invalid value for `name`, must not be `None`\") # noqa: E501\n", " self._name = name\n", " @property\n", " def version(self):\n", " return self._version\n", " @version.setter\n", " def version(self, version):\n", " if version is None:\n", " raise ValueError(\"Invalid value for `version`, must not be `None`\") # noqa: E501\n", " self._version = version\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(\n", " lambda x: x.to_dict() if hasattr(x, \"to_dict\") else x,\n", " value\n", " ))\n", " elif hasattr(value, \"to_dict\"):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], \"to_dict\") else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(CategoryRef, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, CategoryRef):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class TransportInfo(object):\n", " swagger_types = {\n", " 'id': 'str','name': 'str','description': 'str','type': 'str','protocol': 'str','version': 'str','endpoint': 'OneOfTransportInfoEndpoint','security': 'SecurityInfo','impl_specific_info': 'str'}\n", " attribute_map = {'id': 'id','name': 'name','description': 'description','type': 'type','protocol': 'protocol','version': 'version','endpoint': 'endpoint','security': 'security','impl_specific_info': 'implSpecificInfo'}\n", " def __init__(self, id=None, name=None, description=None, type=None, protocol=None, version=None, endpoint=None, security=None, impl_specific_info=None): # noqa: E501\n", " self._id = None\n", " self._name = None\n", " self._description = None\n", " self._type = None\n", " self._protocol = None\n", " self._version = None\n", " self._endpoint = None\n", " self._security = None\n", " self._impl_specific_info = None\n", " self.discriminator = None\n", " self.id = id\n", " self.name = name\n", " if description is not None:\n", " self.description = description\n", " self.type = type\n", " self.protocol = protocol\n", " self.version = version\n", " self.endpoint = endpoint\n", " self.security = security\n", " if impl_specific_info is not None:\n", " self.impl_specific_info = impl_specific_info\n", " @property\n", " def id(self):\n", " return self._id\n", " @id.setter\n", " def id(self, id):\n", " if id is None:\n", " raise ValueError(\"Invalid value for `id`, must not be `None`\") # noqa: E501\n", " self._id = id\n", " @property\n", " def name(self):\n", " return self._name\n", " @name.setter\n", " def name(self, name):\n", " if name is None:\n", " raise ValueError(\"Invalid value for `name`, must not be `None`\") # noqa: E501\n", " self._name = name\n", " @property\n", " def description(self):\n", " return self._description\n", " @description.setter\n", " def description(self, description):\n", " self._description = description\n", " @property\n", " def type(self):\n", " return self._type\n", " @type.setter\n", " def type(self, type):\n", " if type is None:\n", " raise ValueError(\"Invalid value for `type`, must not be `None`\") # noqa: E501\n", " self._type = type\n", " @property\n", " def protocol(self):\n", " return self._protocol\n", " @protocol.setter\n", " def protocol(self, protocol):\n", " if protocol is None:\n", " raise ValueError(\"Invalid value for `protocol`, must not be `None`\") # noqa: E501\n", " self._protocol = protocol\n", " @property\n", " def version(self):\n", " return self._version\n", " @version.setter\n", " def version(self, version):\n", " if version is None:\n", " raise ValueError(\"Invalid value for `version`, must not be `None`\") # noqa: E501\n", " self._version = version\n", " @property\n", " def endpoint(self):\n", " return self._endpoint\n", " @endpoint.setter\n", " def endpoint(self, endpoint):\n", " if endpoint is None:\n", " raise ValueError(\"Invalid value for `endpoint`, must not be `None`\") # noqa: E501\n", " self._endpoint = endpoint\n", " @property\n", " def security(self):\n", " return self._security\n", " @security.setter\n", " def security(self, security):\n", " if security is None:\n", " raise ValueError(\"Invalid value for `security`, must not be `None`\") # noqa: E501\n", " self._security = security\n", " @property\n", " def impl_specific_info(self):\n", " return self._impl_specific_info\n", " @impl_specific_info.setter\n", " def impl_specific_info(self, impl_specific_info):\n", " self._impl_specific_info = impl_specific_info\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(\n", " lambda x: x.to_dict() if hasattr(x, \"to_dict\") else x,\n", " value\n", " ))\n", " elif hasattr(value, \"to_dict\"):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], \"to_dict\") else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(TransportInfo, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, TransportInfo):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class SecurityInfo(object):\n", " swagger_types = {'o_auth2_info': 'SecurityInfoOAuth2Info'}\n", " attribute_map = {'o_auth2_info': 'oAuth2Info'}\n", " def __init__(self, o_auth2_info=None): # noqa: E501\n", " self._o_auth2_info = None\n", " self.discriminator = None\n", " if o_auth2_info is not None:\n", " self.o_auth2_info = o_auth2_info\n", " @property\n", " def o_auth2_info(self):\n", " return self._o_auth2_info\n", " @o_auth2_info.setter\n", " def o_auth2_info(self, o_auth2_info):\n", " self._o_auth2_info = o_auth2_info\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(\n", " lambda x: x.to_dict() if hasattr(x, \"to_dict\") else x,\n", " value\n", " ))\n", " elif hasattr(value, \"to_dict\"):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], \"to_dict\") else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(SecurityInfo, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, SecurityInfo):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class SecurityInfoOAuth2Info(object):\n", " swagger_types = {'grant_types': 'list[str]','token_endpoint': 'str'}\n", " attribute_map = {'grant_types': 'grantTypes','token_endpoint': 'tokenEndpoint'}\n", " def __init__(self, grant_types=None, token_endpoint=None): # noqa: E501\n", " self._grant_types = None\n", " self._token_endpoint = None\n", " self.discriminator = None\n", " self.grant_types = grant_types\n", " self.token_endpoint = token_endpoint\n", " @property\n", " def grant_types(self):\n", " return self._grant_types\n", " @grant_types.setter\n", " def grant_types(self, grant_types):\n", " if grant_types is None:\n", " raise ValueError(\"Invalid value for `grant_types`, must not be `None`\") # noqa: E501\n", " self._grant_types = grant_types\n", " @property\n", " def token_endpoint(self):\n", " return self._token_endpoint\n", " @token_endpoint.setter\n", " def token_endpoint(self, token_endpoint):\n", " if token_endpoint is None:\n", " raise ValueError(\"Invalid value for `token_endpoint`, must not be `None`\") # noqa: E501\n", " self._token_endpoint = token_endpoint\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(\n", " lambda x: x.to_dict() if hasattr(x, \"to_dict\") else x,\n", " value\n", " ))\n", " elif hasattr(value, \"to_dict\"):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], \"to_dict\") else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(SecurityInfoOAuth2Info, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, SecurityInfoOAuth2Info):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class OneOfTransportInfoEndpoint(object):\n", " swagger_types = {}\n", " attribute_map = {}\n", " def __init__(self): # noqa: E501\n", " self.discriminator = None\n", " @property\n", " def uris(self):\n", " return self._uris\n", " @uris.setter\n", " def uris(self, uris):\n", " self._uris = uris\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(\n", " lambda x: x.to_dict() if hasattr(x, \"to_dict\") else x,\n", " value\n", " ))\n", " elif hasattr(value, \"to_dict\"):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], \"to_dict\") else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(OneOfappInstanceIdServicesBody, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, OneOfTransportInfoEndpoint):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class EndPointInfoUris(object):\n", " swagger_types = {'_uris': 'list[str]'}\n", " attribute_map = {'_uris': 'uris'}\n", " def __init__(self, uris:list): # noqa: E501\n", " self._uris = None\n", " self.uris = uris\n", " @property\n", " def uris(self):\n", " return self._uris\n", " @uris.setter\n", " def uris(self, uris):\n", " self._uris = uris\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,value))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(EndPointInfoUris, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, EndPointInfoUris):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class EndPointInfoFqdn(object):\n", " swagger_types = {'_fqdn': 'list[str]'}\n", " attribute_map = {'_fqdn': 'fqdn'}\n", " def __init__(self, fqdn:list): # noqa: E501\n", " self._fqdn = None\n", " self.fqdn = fqdn\n", " @property\n", " def fqdn(self):\n", " return self._fqdn\n", " @fqdn.setter\n", " def fqdn(self, fqdn):\n", " self._fqdn = fqdn\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,value))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(EndPointInfoFqdn, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, EndPointInfoFqdn):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class EndPointInfoAddress(object):\n", " swagger_types = {'_host': 'str', '_port': 'int'}\n", " attribute_map = {'_host': 'host', '_port': 'port'}\n", " def __init__(self, host:str, port:list): # noqa: E501\n", " self._host = None\n", " self._port = None\n", " self.host = host\n", " self.port = port\n", " @property\n", " def host(self):\n", " return self.host\n", " @host.setter\n", " def host(self, host):\n", " self._host = host\n", " @property\n", " def port(self):\n", " return self._port\n", " @port.setter\n", " def port(self, port):\n", " self._port = qosport_kpi\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(\n", " lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,\n", " value\n", " ))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(EndPointInfoAddress, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, EndPointInfoAddress):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class EndPointInfoAddresses(object):\n", " swagger_types = {'_addresses': 'list[EndPointInfoAddress]'}\n", " attribute_map = {'_addresses': 'addresses'}\n", " def __init__(self, addresses:list): # noqa: E501\n", " self._addresses = None\n", " self.addresses = addresses\n", " @property\n", " def addresses(self):\n", " return self._addresses\n", " @addresses.setter\n", " def addresses(self, addresses):\n", " self._addresses = addresses\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(lambda x: x.to_dict() if hasattr(x, 'to_dict') else x,value))\n", " elif hasattr(value, 'to_dict'):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], 'to_dict') else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(EndPointInfoAddresses, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, EndPointInfoAddresses):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n", "\n", "class EndPointInfoAlternative(object):\n", " swagger_types = {'alternative': 'object'}\n", " attribute_map = {'alternative': 'alternative'}\n", " def __init__(self, alternative=None): # noqa: E501\n", " self._alternative = None\n", " self.discriminator = None\n", " self.alternative = alternative\n", " @property\n", " def alternative(self):\n", " return self._alternative\n", " @alternative.setter\n", " def alternative(self, alternative):\n", " if alternative is None:\n", " raise ValueError(\"Invalid value for `alternative`, must not be `None`\") # noqa: E501\n", " self._alternative = alternative\n", " def to_dict(self):\n", " result = {}\n", " for attr, _ in six.iteritems(self.swagger_types):\n", " value = getattr(self, attr)\n", " if isinstance(value, list):\n", " result[attr] = list(map(\n", " lambda x: x.to_dict() if hasattr(x, \"to_dict\") else x,\n", " value\n", " ))\n", " elif hasattr(value, \"to_dict\"):\n", " result[attr] = value.to_dict()\n", " elif isinstance(value, dict):\n", " result[attr] = dict(map(\n", " lambda item: (item[0], item[1].to_dict())\n", " if hasattr(item[1], \"to_dict\") else item,\n", " value.items()\n", " ))\n", " else:\n", " result[attr] = value\n", " if issubclass(EndPointInfoAlternative, dict):\n", " for key, value in self.items():\n", " result[key] = value\n", " return result\n", " def to_str(self):\n", " return pprint.pformat(self.to_dict())\n", " def __repr__(self):\n", " return self.to_str()\n", " def __eq__(self, other):\n", " if not isinstance(other, EndPointInfoAlternative):\n", " return False\n", " return self.__dict__ == other.__dict__\n", " def __ne__(self, other):\n", " return not self == other\n" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [], "source": [ "def create_mec_service(sandbox_name: str, app_inst_id: swagger_client.models.application_info.ApplicationInfo) -> object:\n", " global MEC_PLTF, CALLBACK_URI, logger\n", "\n", " logger.debug('>>> create_mec_service')\n", " try:\n", " url = '/{sandbox_name}/{mec_pltf}/mec_service_mgmt/v1/applications/{app_inst_id}/services'\n", " logger.debug('create_mec_service: url: ' + url)\n", " path_params = {}\n", " path_params['sandbox_name'] = sandbox_name\n", " path_params['mec_pltf'] = MEC_PLTF\n", " path_params['app_inst_id'] = app_inst_id.id\n", " # HTTP header `Accept`\n", " header_params = {}\n", " header_params['Accept'] = 'application/json' # noqa: E501\n", " # HTTP header `Content-Type`\n", " header_params['Content-Type'] = 'application/json' # noqa: E501\n", " # Body request\n", " callback = CALLBACK_URI + '/statistic/v1/quantity'\n", " transport_info = TransportInfo(id=str(uuid.uuid4()), name='HTTP REST API', type='REST_HTTP', protocol='HTTP', version='2.0', security=SecurityInfo(), endpoint=OneOfTransportInfoEndpoint())\n", " transport_info.endpoint.uris=[EndPointInfoUris(callback)]\n", " category_ref = CategoryRef(href=callback, id=str(uuid.uuid4()), name='Demo', version='1.0.0')\n", " appServiceInfo = ServiceInfo(ser_name='demo6 MEC Service', ser_category=category_ref, version='1.0.0', state='ACTIVE',transport_info=transport_info, serializer='JSON')\n", " (result, status, headers) = service_api.call_api(url, 'POST', header_params=header_params, path_params=path_params, body=appServiceInfo, async_req=False)\n", " return (result, status, headers['Location'])\n", " except ApiException as e:\n", " logger.error('Exception when calling call_api: %s\\n' % e)\n", " return None\n", " # End of function create_mec_service" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [], "source": [ "def delete_mec_service(resource_url: str) -> int:\n", " global logger\n", "\n", " logger.debug('>>> delete_mec_subscription: resource_url: ' + resource_url)\n", " try:\n", " res = urllib3.util.parse_url(resource_url)\n", " if res is None:\n", " logger.error('delete_mec_subscription: Failed to paerse URL')\n", " return -1\n", " header_params = {}\n", " # HTTP header `Accept`\n", " header_params['Accept'] = 'application/json' # noqa: E501\n", " # HTTP header `Content-Type`\n", " header_params['Content-Type'] = 'application/json' # noqa: E501\n", " service_api.call_api(res.path, 'DELETE', header_params=header_params, async_req=False)\n", " return 0\n", " except ApiException as e:\n", " logger.error('Exception when calling call_api: %s\\n' % e)\n", " return -1\n", " # End of function delete_mec_service" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:48:24,836 - __main__ - DEBUG - Starting at 20241010-154824\n", "2024-10-10 15:48:24,839 - __main__ - DEBUG - \t pwd= /home/yann/dev/jupyter/Sandbox/mecapp\n", "/tmp/ipykernel_3112397/3246377199.py:17: DeprecationWarning: setDaemon() is deprecated, set the daemon attribute instead\n", " notification_server.setDaemon(True) # Set as a daemon so it will be killed once the main thread is dead.\n", "Exception in thread notification_server:\n", "Traceback (most recent call last):\n", " File \"/usr/lib/python3.10/threading.py\", line 1016, in _bootstrap_inner\n", "2024-10-10 15:48:24,843 - __main__ - DEBUG - >>> process_login\n", " self.run()\n", " File \"/home/yann/.local/lib/python3.10/site-packages/ipykernel/ipkernel.py\", line 761, in run_closure\n", "2024-10-10 15:48:24,846 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n", " _threading_Thread_run(self)\n", " File \"/usr/lib/python3.10/threading.py\", line 953, in run\n", " self._target(*self._args, **self._kwargs)\n", "TypeError: BaseRequestHandler.__init__() missing 1 required positional argument: 'server'\n", "2024-10-10 15:48:25,047 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/login?provider=Jupyter2024 HTTP/1.1\" 201 48\n", "2024-10-10 15:48:25,048 DEBUG response body: b'{\"user_code\":\"sbxulje0su\",\"verification_uri\":\"\"}'\n", "2024-10-10 15:48:25,049 - __main__ - DEBUG - process_login (step1): oauth: {'user_code': 'sbxulje0su', 'verification_uri': ''}\n", "2024-10-10 15:48:25,050 - __main__ - DEBUG - =======================> DO AUTHORIZATION WITH CODE : sbxulje0su\n", "2024-10-10 15:48:25,051 - __main__ - DEBUG - =======================> DO AUTHORIZATION HERE : \n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sandbox-api/v1/login?provider=Jupyter2024 HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 201 Created\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:48:24 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 48\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:48:28,118 DEBUG https://mec-platform2.etsi.org:443 \"GET /sandbox-api/v1/namespace?user_code=sbxulje0su HTTP/1.1\" 200 29\n", "2024-10-10 15:48:28,120 DEBUG response body: b'{\"sandbox_name\":\"sbxulje0su\"}'\n", "2024-10-10 15:48:28,122 - __main__ - DEBUG - process_login (step2): result: {'sandbox_name': 'sbxulje0su'}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'GET /sandbox-api/v1/namespace?user_code=sbxulje0su HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "reply: 'HTTP/1.1 200 OK\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:48:28 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 29\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:48:34,130 - __main__ - DEBUG - >>> get_network_scenarios: sandbox=sbxulje0su\n", "2024-10-10 15:48:34,133 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'GET /sandbox-api/v1/sandboxNetworkScenarios?sandbox_name=sbxulje0su HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:48:34,578 DEBUG https://mec-platform2.etsi.org:443 \"GET /sandbox-api/v1/sandboxNetworkScenarios?sandbox_name=sbxulje0su HTTP/1.1\" 200 186\n", "2024-10-10 15:48:34,580 DEBUG response body: b'[{\"id\":\"4g-5g-macro-v2x\"},{\"id\":\"4g-5g-macro-v2x-fed\"},{\"id\":\"4g-5g-wifi-macro\"},{\"id\":\"4g-macro\"},{\"id\":\"4g-wifi-macro\"},{\"id\":\"dual-mep-4g-5g-wifi-macro\"},{\"id\":\"dual-mep-short-path\"}]'\n", "2024-10-10 15:48:34,583 - __main__ - DEBUG - get_network_scenarios: result: [{'id': '4g-5g-macro-v2x'}, {'id': '4g-5g-macro-v2x-fed'}, {'id': '4g-5g-wifi-macro'}, {'id': '4g-macro'}, {'id': '4g-wifi-macro'}, {'id': 'dual-mep-4g-5g-wifi-macro'}, {'id': 'dual-mep-short-path'}]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "reply: 'HTTP/1.1 200 OK\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:48:34 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 186\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:48:40,591 - __main__ - DEBUG - >>> activate_network_scenario: sbxulje0su\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sandbox-api/v1/sandboxNetworkScenarios/sbxulje0su?network_scenario_id=4g-5g-macro-v2x HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:48:40,948 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/sandboxNetworkScenarios/sbxulje0su?network_scenario_id=4g-5g-macro-v2x HTTP/1.1\" 204 0\n", "2024-10-10 15:48:40,950 DEBUG response body: b''\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:48:40 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:48:52,964 - __main__ - DEBUG - >>> request_application_instance_id: sbxulje0su\n", "2024-10-10 15:48:52,968 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n", "2024-10-10 15:48:53,151 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/sandboxAppInstances/sbxulje0su HTTP/1.1\" 201 100\n", "2024-10-10 15:48:53,154 DEBUG response body: b'{\"id\":\"a3353a39-6e9e-440a-a34c-1eeeb2973404\",\"name\":\"JupyterMecApp\",\"nodeName\":\"mep1\",\"type\":\"USER\"}'\n", "2024-10-10 15:48:53,156 - __main__ - DEBUG - request_application_instance_id: result: {'id': 'a3353a39-6e9e-440a-a34c-1eeeb2973404',\n", " 'name': 'JupyterMecApp',\n", " 'node_name': 'mep1',\n", " 'persist': None,\n", " 'type': 'USER'}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'id': 'a3353a39-6e9e-440a-a34c-1eeeb2973404',\n", " 'name': 'JupyterMecApp',\n", " 'node_name': 'mep1',\n", " 'persist': None,\n", " 'type': 'USER'}\n", "send: b'POST /sandbox-api/v1/sandboxAppInstances/sbxulje0su HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 107\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{\"id\": \"a3353a39-6e9e-440a-a34c-1eeeb2973404\", \"name\": \"JupyterMecApp\", \"nodeName\": \"mep1\", \"type\": \"USER\"}'\n", "reply: 'HTTP/1.1 201 Created\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:48:53 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 100\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:48:59,163 - __main__ - DEBUG - >>> send_ready_confirmation: a3353a39-6e9e-440a-a34c-1eeeb2973404\n", "2024-10-10 15:48:59,166 - __main__ - DEBUG - send_ready_confirmation: url: /{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/confirm_ready\n", "2024-10-10 15:48:59,169 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n", "2024-10-10 15:48:59,297 DEBUG https://mec-platform2.etsi.org:443 \"POST /sbxulje0su/mep1/mec_app_support/v2/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/confirm_ready HTTP/1.1\" 204 0\n", "2024-10-10 15:48:59,298 DEBUG response body: b''\n", "2024-10-10 15:48:59,298 - __main__ - DEBUG - >>> send_subscribe_termination: a3353a39-6e9e-440a-a34c-1eeeb2973404\n", "2024-10-10 15:48:59,299 - __main__ - DEBUG - send_subscribe_termination: url: /{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/subscriptions\n", "2024-10-10 15:48:59,315 DEBUG https://mec-platform2.etsi.org:443 \"POST /sbxulje0su/mep1/mec_app_support/v2/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/subscriptions HTTP/1.1\" 201 367\n", "2024-10-10 15:48:59,315 DEBUG response body: b'{\"subscriptionType\":\"AppTerminationNotificationSubscription\",\"callbackReference\":\"http://yanngarcia.ddns.net/mec011/v2/termination\",\"_links\":{\"self\":{\"href\":\"https://mec-platform2.etsi.org/sbxulje0su/mep1/mec_app_support/v2/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/subscriptions/sub-r-7lG6iLd34rwhiT\"}},\"appInstanceId\":\"a3353a39-6e9e-440a-a34c-1eeeb2973404\"}'\n", "2024-10-10 15:48:59,316 - __main__ - DEBUG - >>> extract_sub_id: resource_url: https://mec-platform2.etsi.org/sbxulje0su/mep1/mec_app_support/v2/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/subscriptions/sub-r-7lG6iLd34rwhiT\n", "2024-10-10 15:48:59,317 - __main__ - DEBUG - >>> create_mec_service\n", "2024-10-10 15:48:59,317 - __main__ - DEBUG - create_mec_service: url: /{sandbox_name}/{mec_pltf}/mec_service_mgmt/v1/applications/{app_inst_id}/services\n", "2024-10-10 15:48:59,337 DEBUG https://mec-platform2.etsi.org:443 \"POST /sbxulje0su/mep1/mec_service_mgmt/v1/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/services HTTP/1.1\" 201 809\n", "2024-10-10 15:48:59,339 DEBUG response body: b'{\"serInstanceId\":\"10724851-5fde-41b4-af03-edf9630a5b8b\",\"serName\":\"demo6 MEC Service\",\"serCategory\":{\"href\":\"http://yanngarcia.ddns.net:36001/jupyter/sandbox/demo6/v1//statistic/v1/quantity\",\"id\":\"5ce299e8-5651-462a-9eb8-de1397a07257\",\"name\":\"Demo\",\"version\":\"1.0.0\"},\"version\":\"1.0.0\",\"state\":\"ACTIVE\",\"transportInfo\":{\"id\":\"fbd09b4a-9a12-4c73-95b0-7246e458dd04\",\"name\":\"HTTP REST API\",\"type\":\"REST_HTTP\",\"protocol\":\"HTTP\",\"version\":\"2.0\",\"endpoint\":{\"uris\":null,\"fqdn\":null,\"addresses\":null,\"alternative\":null},\"security\":{}},\"serializer\":\"JSON\",\"scopeOfLocality\":\"MEC_HOST\",\"consumedLocalOnly\":true,\"isLocal\":true,\"_links\":{\"self\":{\"href\":\"https://mec-platform2.etsi.org/sbxulje0su/mep1/mec_service_mgmt/v1/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/services/10724851-5fde-41b4-af03-edf9630a5b8b\"}}}'\n", "2024-10-10 15:48:59,340 - __main__ - INFO - mec_service_resource: https://mec-platform2.etsi.org/sbxulje0su/mep1/mec_service_mgmt/v1/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/services/10724851-5fde-41b4-af03-edf9630a5b8b\n", "2024-10-10 15:48:59,341 - __main__ - INFO - body: b'{\"serInstanceId\":\"10724851-5fde-41b4-af03-edf9630a5b8b\",\"serName\":\"demo6 MEC Service\",\"serCategory\":{\"href\":\"http://yanngarcia.ddns.net:36001/jupyter/sandbox/demo6/v1//statistic/v1/quantity\",\"id\":\"5ce299e8-5651-462a-9eb8-de1397a07257\",\"name\":\"Demo\",\"version\":\"1.0.0\"},\"version\":\"1.0.0\",\"state\":\"ACTIVE\",\"transportInfo\":{\"id\":\"fbd09b4a-9a12-4c73-95b0-7246e458dd04\",\"name\":\"HTTP REST API\",\"type\":\"REST_HTTP\",\"protocol\":\"HTTP\",\"version\":\"2.0\",\"endpoint\":{\"uris\":null,\"fqdn\":null,\"addresses\":null,\"alternative\":null},\"security\":{}},\"serializer\":\"JSON\",\"scopeOfLocality\":\"MEC_HOST\",\"consumedLocalOnly\":true,\"isLocal\":true,\"_links\":{\"self\":{\"href\":\"https://mec-platform2.etsi.org/sbxulje0su/mep1/mec_service_mgmt/v1/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/services/10724851-5fde-41b4-af03-edf9630a5b8b\"}}}'\n", "2024-10-10 15:48:59,342 - __main__ - INFO - data: {'serInstanceId': '10724851-5fde-41b4-af03-edf9630a5b8b', 'serName': 'demo6 MEC Service', 'serCategory': {'href': 'http://yanngarcia.ddns.net:36001/jupyter/sandbox/demo6/v1//statistic/v1/quantity', 'id': '5ce299e8-5651-462a-9eb8-de1397a07257', 'name': 'Demo', 'version': '1.0.0'}, 'version': '1.0.0', 'state': 'ACTIVE', 'transportInfo': {'id': 'fbd09b4a-9a12-4c73-95b0-7246e458dd04', 'name': 'HTTP REST API', 'type': 'REST_HTTP', 'protocol': 'HTTP', 'version': '2.0', 'endpoint': {'uris': None, 'fqdn': None, 'addresses': None, 'alternative': None}, 'security': {}}, 'serializer': 'JSON', 'scopeOfLocality': 'MEC_HOST', 'consumedLocalOnly': True, 'isLocal': True, '_links': {'self': {'href': 'https://mec-platform2.etsi.org/sbxulje0su/mep1/mec_service_mgmt/v1/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/services/10724851-5fde-41b4-af03-edf9630a5b8b'}}}\n", "2024-10-10 15:48:59,343 - __main__ - INFO - =============> Execute the command: curl http://yanngarcia.ddns.net:36001/jupyter/sandbox/demo6/v1//statistic/v1/quantity\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sbxulje0su/mep1/mec_app_support/v2/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/confirm_ready HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 23\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{\"indication\": \"READY\"}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:48:59 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n", "send: b'POST /sbxulje0su/mep1/mec_app_support/v2/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/subscriptions HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 192\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{\"subscriptionType\": \"AppTerminationNotificationSubscription\", \"callbackReference\": \"http://yanngarcia.ddns.net/mec011/v2/termination\", \"appInstanceId\": \"a3353a39-6e9e-440a-a34c-1eeeb2973404\"}'\n", "reply: 'HTTP/1.1 201 Created\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:48:59 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 367\n", "header: Connection: keep-alive\n", "header: Location: https://mec-platform2.etsi.org/sbxulje0su/mep1/mec_app_support/v2/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/subscriptions/sub-r-7lG6iLd34rwhiT\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n", "send: b'POST /sbxulje0su/mep1/mec_service_mgmt/v1/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/services HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 465\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{\"serName\": \"demo6 MEC Service\", \"serCategory\": {\"href\": \"http://yanngarcia.ddns.net:36001/jupyter/sandbox/demo6/v1//statistic/v1/quantity\", \"id\": \"5ce299e8-5651-462a-9eb8-de1397a07257\", \"name\": \"Demo\", \"version\": \"1.0.0\"}, \"version\": \"1.0.0\", \"state\": \"ACTIVE\", \"transportInfo\": {\"id\": \"fbd09b4a-9a12-4c73-95b0-7246e458dd04\", \"name\": \"HTTP REST API\", \"type\": \"REST_HTTP\", \"protocol\": \"HTTP\", \"version\": \"2.0\", \"endpoint\": {}, \"security\": {}}, \"serializer\": \"JSON\"}'\n", "reply: 'HTTP/1.1 201 Created\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:48:59 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Content-Length: 809\n", "header: Connection: keep-alive\n", "header: Location: https://mec-platform2.etsi.org/sbxulje0su/mep1/mec_service_mgmt/v1/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/services/10724851-5fde-41b4-af03-edf9630a5b8b\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:49:29,369 - __main__ - DEBUG - >>> delete_mec_subscription: resource_url: https://mec-platform2.etsi.org/sbxulje0su/mep1/mec_service_mgmt/v1/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/services/10724851-5fde-41b4-af03-edf9630a5b8b\n", "2024-10-10 15:49:29,391 DEBUG https://mec-platform2.etsi.org:443 \"DELETE /sbxulje0su/mep1/mec_service_mgmt/v1/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/services/10724851-5fde-41b4-af03-edf9630a5b8b HTTP/1.1\" 204 0\n", "2024-10-10 15:49:29,394 DEBUG response body: b''\n", "2024-10-10 15:49:29,396 - __main__ - DEBUG - >>> delete_subscribe_termination: a3353a39-6e9e-440a-a34c-1eeeb2973404\n", "2024-10-10 15:49:29,397 - __main__ - DEBUG - delete_subscribe_termination: url: /{sandbox_name}/{mec_pltf}/mec_app_support/v2/applications/{app_inst_id}/subscriptions/{sub_id}\n", "2024-10-10 15:49:29,417 DEBUG https://mec-platform2.etsi.org:443 \"DELETE /sbxulje0su/mep1/mec_app_support/v2/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/subscriptions/sub-r-7lG6iLd34rwhiT HTTP/1.1\" 204 0\n", "2024-10-10 15:49:29,419 DEBUG response body: b''\n", "2024-10-10 15:49:29,421 - __main__ - DEBUG - >>> delete_application_instance_id: sbxulje0su\n", "2024-10-10 15:49:29,424 - __main__ - DEBUG - >>> delete_application_instance_id: a3353a39-6e9e-440a-a34c-1eeeb2973404\n", "2024-10-10 15:49:29,474 DEBUG https://mec-platform2.etsi.org:443 \"DELETE /sandbox-api/v1/sandboxAppInstances/sbxulje0su/a3353a39-6e9e-440a-a34c-1eeeb2973404 HTTP/1.1\" 204 0\n", "2024-10-10 15:49:29,478 DEBUG response body: b''\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'DELETE /sbxulje0su/mep1/mec_service_mgmt/v1/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/services/10724851-5fde-41b4-af03-edf9630a5b8b HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:49:29 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n", "send: b'DELETE /sbxulje0su/mep1/mec_app_support/v2/applications/a3353a39-6e9e-440a-a34c-1eeeb2973404/subscriptions/sub-r-7lG6iLd34rwhiT HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nAccept: application/json\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:49:29 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n", "send: b'DELETE /sandbox-api/v1/sandboxAppInstances/sbxulje0su/a3353a39-6e9e-440a-a34c-1eeeb2973404 HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:49:29 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:49:35,486 - __main__ - DEBUG - >>> deactivate_network_scenario: sbxulje0su\n", "2024-10-10 15:49:35,536 DEBUG https://mec-platform2.etsi.org:443 \"DELETE /sandbox-api/v1/sandboxNetworkScenarios/sbxulje0su/4g-5g-macro-v2x HTTP/1.1\" 204 0\n", "2024-10-10 15:49:35,539 DEBUG response body: b''\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'DELETE /sandbox-api/v1/sandboxNetworkScenarios/sbxulje0su/4g-5g-macro-v2x HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:49:35 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2024-10-10 15:49:47,545 - __main__ - DEBUG - >>> process_logout: sandbox=sbxulje0su\n", "2024-10-10 15:49:47,549 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n", "2024-10-10 15:49:47,752 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/logout?sandbox_name=sbxulje0su HTTP/1.1\" 204 0\n", "2024-10-10 15:49:47,754 DEBUG response body: b''\n", "2024-10-10 15:49:47,757 - __main__ - DEBUG - Stopped at 20241010-154947\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "send: b'POST /sandbox-api/v1/logout?sandbox_name=sbxulje0su HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 2\\r\\nContent-Type: application/json\\r\\nUser-Agent: Swagger-Codegen/1.0.0/python\\r\\n\\r\\n'\n", "send: b'{}'\n", "reply: 'HTTP/1.1 204 No Content\\r\\n'\n", "header: Date: Thu, 10 Oct 2024 13:49:47 GMT\n", "header: Content-Type: application/json; charset=UTF-8\n", "header: Connection: keep-alive\n", "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n" ] } ], "source": [ "def process_main():\n", " \"\"\"\n", " This is the second sprint of our skeleton of our MEC application:\n", " - Mec application setup\n", " - Create new MEC service\n", " - Send a request to our MEC service\n", " - Delete newly created MEC service\n", " - Mec application termination\n", " \"\"\" \n", " global LISTENER_IP, LISTENER_PORT, CALLBACK_URI, logger\n", "\n", " logger.debug('Starting at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " logger.debug('\\t pwd= ' + os.getcwd())\n", "\n", " # Start notification server in a daemonized thread\n", " notification_server = threading.Thread(name='notification_server', target=HTTPRequestHandler, args=(LISTENER_IP, LISTENER_PORT))\n", " notification_server.setDaemon(True) # Set as a daemon so it will be killed once the main thread is dead.\n", " notification_server.start()\n", " # Continue\n", "\n", "\n", " # Setup the MEC application\n", " sandbox_name, app_inst_id, sub_id = mec_app_setup()\n", "\n", " # Create the MEC service\n", " result, status, mec_service_resource = create_mec_service(sandbox_name, app_inst_id)\n", " if status != 201:\n", " logger.error('Failed to create MEC service')\n", " else:\n", " logger.info('mec_service_resource: %s', mec_service_resource)\n", "\n", " # Any processing here\n", " logger.info('body: ' + str(result.data))\n", " data = json.loads(result.data)\n", " logger.info('data: %s', str(data))\n", " logger.info('=============> Execute the command: curl %s/statistic/v1/quantity', CALLBACK_URI)\n", " time.sleep(30)\n", "\n", " # Delete the MEC servce\n", " delete_mec_service(mec_service_resource)\n", "\n", " # Terminate the MEC application\n", " mec_app_termination(sandbox_name, app_inst_id, sub_id)\n", "\n", " logger.debug('Stopped at ' + time.strftime('%Y%m%d-%H%M%S'))\n", " # End of function process_main\n", "\n", "if __name__ == '__main__':\n", " process_main()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Annexes\n", "\n", "## Annex A: How to use an existing MEC sandbox instance\n", "\n", "This case is used when the MEC Sandbox API is not used. The procedure is the following:\n", "- Log to the MEC Sandbox using a WEB browser\n", "- Select a network scenario\n", "- Create a new application instance\n", "\n", "When it is done, the newly created application instance is used by your application when required. This application instance is usually passed to your application in the command line or using a configuration file\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Bibliography\n", "\n", "1. ETSI GS MEC 002 (V2.2.1) (01-2022): \"Multi-access Edge Computing (MEC); Phase 2: Use Cases and Requirements\".\n", "2. ETSI GS MEC 010-1 (V1.1.1) (10-2017): \"Mobile Edge Computing (MEC); Mobile Edge Management; Part 1: System, host and platform management\".\n", "3. ETSI GS MEC 010-2 (V2.2.1) (02-2022): \"Multi-access Edge Computing (MEC); MEC Management; Part 2: Application lifecycle, rules and requirements management\".\n", "4. ETSI GS MEC 011 (V3.1.1) (09-2022): \"Multi-access Edge Computing (MEC); Edge Platform Application Enablement\".\n", "5. ETSI GS MEC 012 (V2.2.1) (02-2022): \"Multi-access Edge Computing (MEC); Radio Network Information API\".\n", "6. ETSI GS MEC 013 (V2.2.1) (01-2022): \"Multi-access Edge Computing (MEC); Location API\".\n", "7. ETSI GS MEC 014 (V2.1.1) (03-2021): \"Multi-access Edge Computing (MEC); UE Identity API\".\n", "8. ETSI GS MEC 015 (V2.1.1) (06-2020): \"Multi-Access Edge Computing (MEC); Traffic Management APIs\".\n", "9. ETSI GS MEC 016 (V2.2.1) (04-2020): \"Multi-access Edge Computing (MEC); Device application interface\".\n", "10. ETSI GS MEC 021 (V2.2.1) (02-2022): \"Multi-access Edge Computing (MEC); Application Mobility Service API\".\n", "11. ETSI GS MEC 028 (V2.3.1) (07-2022): \"Multi-access Edge Computing (MEC); WLAN Access Information API\".\n", "12. ETSI GS MEC 029 (V2.2.1) (01-2022): \"Multi-access Edge Computing (MEC); Fixed Access Information API\".\n", "13. ETSI GS MEC 030 (V3.2.1) (05-2022): \"Multi-access Edge Computing (MEC); V2X Information Service API\".\n", "14. ETSI GR MEC-DEC 025 (V2.1.1) (06-2019): \"Multi-access Edge Computing (MEC); MEC Testing Framework\".\n", "15. ETSI GR MEC 001 (V3.1.1) (01-2022): \"Multi-access Edge Computing (MEC); Terminology\".\n", "16. ETSI GR MEC 003 (V3.1.1): Multi-access Edge Computing (MEC); \n", "Framework and Reference Architecture\n", "17. [The Wiki MEC web site](https://www.etsi.org/technologies/multi-access-edge-computing)\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 4 }