Skip to content
MEC application.ipynb 102 KiB
Newer Older
    "    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.id + '/subscriptions'\n",
    "        logger.debug('send_subscribe_termination: url: ' + url)\n",
    "        header_params = {}\n",
    "        # HTTP header `Accept`\n",
    "        header_params['Accept'] = service_api.select_header_accept(['application/json'])  # noqa: E501\n",
    "        # HTTP header `Content-Type`\n",
    "        header_params['Content-Type'] = service_api.select_header_accept(['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",
    "        body = json.dumps(dict_body)\n",
    "        logger.debug('send_subscribe_termination: body: ' + str(body))\n",
    "        (result, status, headers) = service_api.call_api(url, 'POST', header_params=header_params, body=str(body), async_req=False)\n",
    "        logger.debug('send_subscribe_termination: headers: ' + str(headers))\n",
    "        return extract_sub_id(url, 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"
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "def extract_sub_id(base_url: str, resource_url: str) -> str:\n",
    "    global logger\n",
    "\n",
    "    logger.debug('>>> extract_sub_id: base_url: ' + base_url)\n",
    "    logger.debug('>>> extract_sub_id: resource_url: ' + resource_url)\n",
    "\n",
    "    e = re.compile(re.escape(base_url) + '/(?P<sub_id>.*)', re.DOTALL | re.VERBOSE)\n",
    "    m = e.match(resource_url)\n",
    "    if m:\n",
    "        if m.groupdict() != None:\n",
    "            if 'sub_id' in m.groupdict():\n",
    "                return m.groupdict()['sub_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",
    "    logger.debug('>>> delete_subscribe_termination: ' + app_inst_id.id)\n",
    "        url = '/' + sandbox_name + '/' + MEC_PLTF + '/mec_app_support/v2/applications/' + app_inst_id.id + '/subscriptions/' + sub_id\n",
    "        logger.debug('delete_subscribe_termination: url: ' + url)\n",
    "        header_params = {}\n",
    "        # HTTP header `Accept`\n",
    "        header_params['Accept'] = service_api.select_header_accept(['application/json'])  # noqa: E501\n",
    "        # HTTP header `Content-Type`\n",
    "        header_params['Content-Type'] = service_api.select_header_accept(['application/json'])  # noqa: E501\n",
    "        service_api.call_api(url, '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_subscribe_termination"
Yann Garcia's avatar
Yann Garcia committed
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now, it is time now to create the our third iteration of our MEC application.\n",
Yann Garcia's avatar
Yann Garcia committed
    "\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",
Yann Garcia's avatar
Yann Garcia committed
    "- Send READY confirmation\n",
    "- Subscribe to AppTerminationNotificationSubscription\n",
    "- Check list of services\n",
    "- Delete AppTerminationNotification subscription\n",
    "- Delete our application instance identifier\n",
Yann Garcia's avatar
Yann Garcia committed
    "- Deactivate a network scenario\n",
    "- Logout\n",
    "- Check that logout is effective\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
Yann Garcia's avatar
Yann Garcia committed
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-09-26 18:39:25,473 - __main__ - DEBUG - Starting at 20240926-183925\n",
      "2024-09-26 18:39:25,474 - __main__ - DEBUG - \t pwd= /home/yann/dev/jupyter/Sandbox/mecapp\n",
      "2024-09-26 18:39:25,475 - __main__ - DEBUG - >>> process_login\n",
      "2024-09-26 18:39:25,476 DEBUG Starting new HTTPS connection (1): mec-platform2.etsi.org:443\n",
      "/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host 'mec-platform2.etsi.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n",
      "  warnings.warn(\n",
      "2024-09-26 18:39:25,684 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/login?provider=Jupyter2024 HTTP/1.1\" 201 48\n",
      "2024-09-26 18:39:25,686 DEBUG response body: b'{\"user_code\":\"sbx292dvej\",\"verification_uri\":\"\"}'\n",
      "2024-09-26 18:39:25,687 - __main__ - DEBUG - process_login (step1): oauth: {'user_code': 'sbx292dvej', 'verification_uri': ''}\n",
      "2024-09-26 18:39:25,688 - __main__ - DEBUG - =======================> DO AUTHORIZATION WITH CODE : sbx292dvej\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, 26 Sep 2024 16:39: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": [
      "/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host 'mec-platform2.etsi.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n",
      "  warnings.warn(\n",
      "2024-09-26 18:39:28,718 DEBUG https://mec-platform2.etsi.org:443 \"GET /sandbox-api/v1/namespace?user_code=sbx292dvej HTTP/1.1\" 200 29\n",
      "2024-09-26 18:39:28,719 DEBUG response body: b'{\"sandbox_name\":\"sbx292dvej\"}'\n",
      "2024-09-26 18:39:28,721 - __main__ - DEBUG - process_login (step2): result: {'sandbox_name': 'sbx292dvej'}\n",
      "2024-09-26 18:39:28,724 - __main__ - INFO - Sandbox created: sbx292dvej\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "send: b'GET /sandbox-api/v1/namespace?user_code=sbx292dvej 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, 26 Sep 2024 16:39:27 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-09-26 18:39:34,732 - __main__ - DEBUG - >>> get_network_scenarios: sandbox=sbx292dvej\n",
      "2024-09-26 18:39:34,735 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n",
      "/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host 'mec-platform2.etsi.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n",
      "  warnings.warn(\n",
      "2024-09-26 18:39:34,939 DEBUG https://mec-platform2.etsi.org:443 \"GET /sandbox-api/v1/sandboxNetworkScenarios?sandbox_name=sbx292dvej HTTP/1.1\" 200 157\n",
      "2024-09-26 18:39:34,941 DEBUG response body: b'[{\"id\":\"4g-5g-macro-v2x\"},{\"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-09-26 18:39:34,944 - __main__ - DEBUG - get_network_scenarios: result: [{'id': '4g-5g-macro-v2x'}, {'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-09-26 18:39:34,945 - __main__ - INFO - nw_scenarios: <class 'swagger_client.models.sandbox_network_scenario.SandboxNetworkScenario'>\n",
      "2024-09-26 18:39:34,947 - __main__ - INFO - nw_scenarios: [{'id': '4g-5g-macro-v2x'}, {'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=sbx292dvej 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, 26 Sep 2024 16:39:33 GMT\n",
      "header: Content-Type: application/json; charset=UTF-8\n",
      "header: Content-Length: 157\n",
      "header: Connection: keep-alive\n",
      "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-09-26 18:39:40,954 - __main__ - DEBUG - >>> activate_network_scenario: sbx292dvej\n",
      "/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host 'mec-platform2.etsi.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n",
      "  warnings.warn(\n",
      "2024-09-26 18:39:41,033 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/sandboxNetworkScenarios/sbx292dvej?network_scenario_id=4g-5g-macro-v2x HTTP/1.1\" 204 0\n",
      "2024-09-26 18:39:41,034 DEBUG response body: b''\n",
      "2024-09-26 18:39:41,035 - __main__ - DEBUG - activate_network_scenario: result: None\n",
      "2024-09-26 18:39:41,036 - __main__ - INFO - Network scenario activated: 4g-5g-macro-v2x\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "send: b'POST /sandbox-api/v1/sandboxNetworkScenarios/sbx292dvej?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, 26 Sep 2024 16:39: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-09-26 18:39:47,043 - __main__ - DEBUG - >>> request_application_instance_id: sbx292dvej\n",
      "2024-09-26 18:39:47,047 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n",
      "/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host 'mec-platform2.etsi.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'id': '35576902-5303-454e-afc5-c5d81f3df077',\n",
      " 'name': 'JupyterMecApp',\n",
      " 'node_name': 'mep1',\n",
      " 'persist': None,\n",
      " 'type': 'USER'}\n",
      "send: b'POST /sandbox-api/v1/sandboxAppInstances/sbx292dvej 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\": \"35576902-5303-454e-afc5-c5d81f3df077\", \"name\": \"JupyterMecApp\", \"nodeName\": \"mep1\", \"type\": \"USER\"}'\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-09-26 18:39:47,290 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/sandboxAppInstances/sbx292dvej HTTP/1.1\" 201 100\n",
      "2024-09-26 18:39:47,292 DEBUG response body: b'{\"id\":\"35576902-5303-454e-afc5-c5d81f3df077\",\"name\":\"JupyterMecApp\",\"nodeName\":\"mep1\",\"type\":\"USER\"}'\n",
      "2024-09-26 18:39:47,295 - __main__ - DEBUG - request_application_instance_id: result: {'id': '35576902-5303-454e-afc5-c5d81f3df077',\n",
      " 'name': 'JupyterMecApp',\n",
      " 'node_name': 'mep1',\n",
      " 'persist': None,\n",
      " 'type': 'USER'}\n",
      "2024-09-26 18:39:47,297 - __main__ - INFO - app_inst_id: {'id': '35576902-5303-454e-afc5-c5d81f3df077',\n",
      " 'name': 'JupyterMecApp',\n",
      " 'node_name': 'mep1',\n",
      " 'persist': None,\n",
      " 'type': 'USER'}\n",
      "2024-09-26 18:39:47,299 - __main__ - INFO - >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n",
      "2024-09-26 18:39:47,301 - __main__ - DEBUG - >>> send_ready_confirmation: 35576902-5303-454e-afc5-c5d81f3df077\n",
      "2024-09-26 18:39:47,303 - __main__ - DEBUG - send_ready_confirmation: url: /sbx292dvej/mep1/mec_app_support/v2/applications/35576902-5303-454e-afc5-c5d81f3df077/confirm_ready\n",
      "2024-09-26 18:39:47,305 - __main__ - DEBUG - send_ready_confirmation: body: {\"indication\": \"READY\"}\n",
      "2024-09-26 18:39:47,311 DEBUG Starting new HTTPS connection (1): mec-platform2.etsi.org:443\n",
      "2024-09-26 18:39:47,427 DEBUG https://mec-platform2.etsi.org:443 \"POST /sbx292dvej/mep1/mec_app_support/v2/applications/35576902-5303-454e-afc5-c5d81f3df077/confirm_ready HTTP/1.1\" 401 172\n",
      "2024-09-26 18:39:47,428 DEBUG response body: b'<html>\\r\\n<head><title>401 Authorization Required</title></head>\\r\\n<body>\\r\\n<center><h1>401 Authorization Required</h1></center>\\r\\n<hr><center>nginx</center>\\r\\n</body>\\r\\n</html>\\r\\n'\n",
      "2024-09-26 18:39:47,429 - __main__ - ERROR - Exception when calling call_api: (401)\n",
      "Reason: Unauthorized\n",
      "HTTP response headers: HTTPHeaderDict({'Date': 'Thu, 26 Sep 2024 16:39:46 GMT', 'Content-Type': 'text/html', 'Content-Length': '172', 'Connection': 'keep-alive', 'Strict-Transport-Security': 'max-age=15724800; includeSubDomains'})\n",
      "HTTP response body: b'<html>\\r\\n<head><title>401 Authorization Required</title></head>\\r\\n<body>\\r\\n<center><h1>401 Authorization Required</h1></center>\\r\\n<hr><center>nginx</center>\\r\\n</body>\\r\\n</html>\\r\\n'\n",
      "\n",
      "\n",
      "2024-09-26 18:39:47,429 - __main__ - ERROR - Failed to send confirm_ready\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "reply: 'HTTP/1.1 201 Created\\r\\n'\n",
      "header: Date: Thu, 26 Sep 2024 16:39:46 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",
      "send: b'POST /sbx292dvej/mep1/mec_app_support/v2/applications/35576902-5303-454e-afc5-c5d81f3df077/confirm_ready HTTP/1.1\\r\\nHost: mec-platform2.etsi.org\\r\\nAccept-Encoding: identity\\r\\nContent-Length: 29\\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 401 Unauthorized\\r\\n'\n",
      "header: Date: Thu, 26 Sep 2024 16:39:46 GMT\n",
      "header: Content-Type: text/html\n",
      "header: Content-Length: 172\n",
      "header: Connection: keep-alive\n",
      "header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-09-26 18:39:53,435 - __main__ - INFO - ***************************************************************************************\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "curl --verbose -X POST \"https://mec-platform2.etsi.org/sbx292dvej/mep1/mec_app_support/v2/applications/35576902-5303-454e-afc5-c5d81f3df077/confirm_ready\" -H\"Accept: application/json\" -H\"Content-Type: application/json\" -d\"{\\\"indication\\\": \\\"READY\\\"}\"\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-09-26 18:40:53,497 - __main__ - INFO - ***************************************************************************************\n",
      "2024-09-26 18:40:53,499 - __main__ - DEBUG - >>> delete_application_instance_id: sbx292dvej\n",
      "2024-09-26 18:40:53,501 - __main__ - DEBUG - >>> delete_application_instance_id: 35576902-5303-454e-afc5-c5d81f3df077\n",
      "2024-09-26 18:40:53,504 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n",
      "/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host 'mec-platform2.etsi.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n",
      "  warnings.warn(\n",
      "2024-09-26 18:40:53,691 DEBUG https://mec-platform2.etsi.org:443 \"DELETE /sandbox-api/v1/sandboxAppInstances/sbx292dvej/35576902-5303-454e-afc5-c5d81f3df077 HTTP/1.1\" 204 0\n",
      "2024-09-26 18:40:53,693 DEBUG response body: b''\n",
      "2024-09-26 18:40:53,695 - __main__ - DEBUG - delete_application_instance_id: result: None\n",
      "2024-09-26 18:40:53,697 - __main__ - INFO - app_inst_id deleted: 35576902-5303-454e-afc5-c5d81f3df077\n",
      "2024-09-26 18:40:53,699 - __main__ - DEBUG - >>> deactivate_network_scenario: sbx292dvej\n",
      "/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host 'mec-platform2.etsi.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n",
      "  warnings.warn(\n",
      "2024-09-26 18:40:53,737 DEBUG https://mec-platform2.etsi.org:443 \"DELETE /sandbox-api/v1/sandboxNetworkScenarios/sbx292dvej/4g-5g-macro-v2x HTTP/1.1\" 204 0\n",
      "2024-09-26 18:40:53,738 DEBUG response body: b''\n",
      "2024-09-26 18:40:53,739 - __main__ - DEBUG - deactivate_network_scenario: result: None\n",
      "2024-09-26 18:40:53,740 - __main__ - INFO - Network scenario deactivated: 4g-5g-macro-v2x\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "send: b'DELETE /sandbox-api/v1/sandboxAppInstances/sbx292dvej/35576902-5303-454e-afc5-c5d81f3df077 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, 26 Sep 2024 16:40:52 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/sbx292dvej/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, 26 Sep 2024 16:40:52 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-09-26 18:40:59,747 - __main__ - DEBUG - >>> process_logout: sandbox=sbx292dvej\n",
      "2024-09-26 18:40:59,750 DEBUG Resetting dropped connection: mec-platform2.etsi.org\n",
      "/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host 'mec-platform2.etsi.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n",
      "  warnings.warn(\n",
      "2024-09-26 18:40:59,885 DEBUG https://mec-platform2.etsi.org:443 \"POST /sandbox-api/v1/logout?sandbox_name=sbx292dvej HTTP/1.1\" 204 0\n",
      "2024-09-26 18:40:59,886 DEBUG response body: b''\n",
      "2024-09-26 18:40:59,886 - __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-09-26 18:40:59,887 - __main__ - DEBUG - Stopped at 20240926-184059\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "send: b'POST /sandbox-api/v1/logout?sandbox_name=sbx292dvej 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, 26 Sep 2024 16:40:58 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"
     ]
    }
   ],
Yann Garcia's avatar
Yann Garcia committed
   "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",
Yann Garcia's avatar
Yann Garcia committed
    "        - Send READY confirmation\n",
    "        \n",
    "        - Subscribe to AppTermination Notification\n",
Yann Garcia's avatar
Yann Garcia committed
    "        - Send Termination\n",
    "        - Delete AppTerminationNotification subscription\n",
    "        - Delete our application instance identifier\n",
Yann Garcia's avatar
Yann Garcia committed
    "        - Deactivate a network scenario\n",
    "        - Logout\n",
    "        - Check that logout is effective\n",
    "    \"\"\" \n",
    "    global logger, nw_scenarios\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    logger.debug('Starting at ' + time.strftime('%Y%m%d-%H%M%S'))\n",
    "    logger.debug('\\t pwd= ' + os.getcwd())\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    # Login\n",
    "    sandbox = process_login()\n",
    "    if sandbox is None:\n",
    "        logger.error('Failed to instanciate a MEC Sandbox')\n",
Yann Garcia's avatar
Yann Garcia committed
    "        return\n",
    "\n",
    "    # Print sandbox identifier\n",
    "    logger.info('Sandbox created: ' + sandbox)\n",
Yann Garcia's avatar
Yann Garcia committed
    "    # 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",
Yann Garcia's avatar
Yann Garcia committed
    "    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",
Yann Garcia's avatar
Yann Garcia committed
    "        # 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",
Yann Garcia's avatar
Yann Garcia committed
    "\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",
Yann Garcia's avatar
Yann Garcia committed
    "    else:\n",
    "        logger.info('Network scenario activated: ' + nw_scenarios[nw_scenario_idx].id)\n",
Yann Garcia's avatar
Yann Garcia committed
    "        # Wait for the MEC services are running\n",
    "        time.sleep(STABLE_TIME_OUT) # Wait for k8s pods up and running\n",
    "\n",
    "    # Request for a new application instance identifier\n",
Yann Garcia's avatar
Yann Garcia committed
    "    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",
Yann Garcia's avatar
Yann Garcia committed
    "    else:\n",
    "        logger.info('app_inst_id: %s', str(app_inst_id))\n",
Yann Garcia's avatar
Yann Garcia committed
    "\n",
    "    # Send READY confirmation\n",
    "    logger.info('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')\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",
    "        sub_id = 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('sub_id: %s', sub_id)\n",
    "\n",
    "    # Any processing here\n",
    "    time.sleep(STABLE_TIME_OUT)\n",
    "    logger.info('***************************************************************************************')\n",
    "    print('curl --verbose -X POST \"https://mec-platform2.etsi.org/'+ sandbox + '/mep1/mec_app_support/v2/applications/' + app_inst_id.id + '/confirm_ready\" -H\"Accept: application/json\" -H\"Content-Type: application/json\" -d\"{\\\\\"indication\\\\\": \\\\\"READY\\\\\"}\"')\n",
    "    time.sleep(60) # Sleep for 30 seconds\n",
    "    logger.info('***************************************************************************************')\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",
Yann Garcia's avatar
Yann Garcia committed
    "\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",
Yann Garcia's avatar
Yann Garcia committed
    "    else:\n",
    "        logger.info('app_inst_id deleted: ' + app_inst_id.id)\n",
Yann Garcia's avatar
Yann Garcia committed
    "\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",
Yann Garcia's avatar
Yann Garcia committed
    "    else:\n",
    "        logger.info('Network scenario deactivated: ' + nw_scenarios[nw_scenario_idx].id)\n",
Yann Garcia's avatar
Yann Garcia committed
    "        # Wait for the MEC services are terminated\n",
    "        time.sleep(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",
Yann Garcia's avatar
Yann Garcia committed
    "  \n",
    "    logger.debug('Stopped at ' + time.strftime('%Y%m%d-%H%M%S'))\n",
Yann Garcia's avatar
Yann Garcia committed
    "    # End of function process_main\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    process_main()\n"
   ]
  },
   "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",
    "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": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def mec_app_setup():\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",
    "\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",
    "        logger.info('Network scenario activated: ' + nw_scenarios[nw_scenario_idx].id)\n",
    "        # Wait for the MEC services are running\n",
    "        time.sleep(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",
    "        logger.info('app_inst_id: %s', str(type(app_inst_id)))\n",
    "        logger.info('app_inst_id: %s', str(app_inst_id))\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",
    "        sub_id = 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('sub_id: %s', sub_id)\n",
    "\n",
    "    # Subscribe to AppTerminationNotificationSubscription\n",
    "    sub_id = send_subscribe_termination(sandbox, app_inst_id)\n",
    "    if sub_id == None:\n",
    "        logger.error('Failed to do the subscription')\n",
    "        logger.info('sub_id: %s', sub_id)\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 provide the steps to terminate a MEC application.\n",
    "\n",
    "NOTE: All subscriptions done outsid to the mec_app_setup function are not deleted."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "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",
    "        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",
    "        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",
    "        logger.info('Network scenario deactivated: ' + nw_scenarios[nw_scenario_idx].id)\n",
    "        # Wait for the MEC services are terminated\n",
    "        time.sleep(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",
    "    # End of function mec_app_termination"
   ]
  },
  {
   "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 appliction 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 V2X message distribution server (ETSI GS MEC 030 Clause 5.5.7)\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": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def send_uu_unicast_provisioning_info(sandbox_name: str, ecgi: str) -> int:\n",
    "    global MEC_SANDBOX_URL, MEC_PLTF, logger\n",
    "\n",
    "    try:\n",
    "        url = MEC_SANDBOX_URL + '/' + sandbox_name + '/' + MEC_PLTF + '/vis/v2/queries/uu_unicast_provisioning_info?location_info=ecgi,' + ecgi\n",
    "        logger.debug('send_uu_unicast_provisioning_info: url: ' + url)\n",
    "        header_params = {}\n",
    "        # HTTP header `Accept`\n",
    "        header_params['Accept'] = service_api.select_header_accept(['application/json'])  # noqa: E501\n",
    "        # HTTP header `Content-Type`\n",
    "        header_params['Content-Type'] = service_api.select_header_accept(['application/json'])  # noqa: E501\n",
    "        result = service_api.call_api(url, 'POST', header_params=header_params, async_req=False)\n",
    "        logger.debug('send_uu_unicast_provisioning_info: result\" + result)\n",
    "        return result\n",
    "    except ApiException as e:\n",
    "        logger.error('Exception when calling call_api: %s\\n' % e)\n",
    "    return Node\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"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "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",
    "    # Login\n",
    "    (sandbox, app_inst_id, sub_id) = mec_app_setup()\n",
    "\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: \", result)\n",
    "\n",
    "    mec_app_termination(sandbox, 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": [
    "### 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": null,
   "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 = 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 = 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 = seconds\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",
  {
   "cell_type": "code",
   "execution_count": null,
   "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",