Newer
Older
]
},
{
"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\n",
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
"\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": null,
"metadata": {},
"outputs": [],
"source": [
"def send_uu_unicast_provisioning_info(sandbox_name: str, ecgi: str) -> object:\n",
" \"\"\"\n",
" Request for V2X communication over Uu unicast information\n",
" :param sandbox_name: The MEC Sandbox instance to use\n",
" :param ecgi: Comma separated list of locations to identify a cell of a base station or a particular geographical area\n",
" :return The Uu unicast provisioning information on success, None otherwise\n",
" :see ETSI GS MEC 030 V3.2.1 (2024-02) Clause 5.5.1 Sending a request for provisioning information for V2X communication over Uu unicast\n",
" \"\"\"\n",
" global MEC_PLTF, logger, service_api\n",
" logger.debug('>>> send_uu_unicast_provisioning_info: ' + ecgi)\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",
" # 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)."
"execution_count": null,
"outputs": [],
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
"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",
"These new type shall be 'JSON' serializable. It means that they have to implement the following methods:\n",
"\n",
"- to_dict()\n",
"- to_str()\n",
"- \\_\\_repr\\_\\_()\n",
"- \\_\\_eq\\_\\_()\n",
"- \\_\\_ne\\_\\_()\n",
"\n",
"**Reference:** ETSI GS MEC 030 V3.2.1 (2024-02) Clause 6.5.13 Type: LinkType\n"
"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 = 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",
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
" 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",
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
" 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",
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
" 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 below implements the V2xMsgSubscription data structure.\"}\n",
"Reference: ETSI GS MEC 030 V3.2.1 (2024-02) Clause 6.3.5 Type: V2xMsgSubscription\n",
"\n",
{
"cell_type": "code",
"execution_count": null,
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
"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",
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
" 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 HTTP Request message body contains a 'JSON' serialized instance of the class V2xMsgSubscription.\n",
"\n",
"Reference: ETSI GS MEC 030 V3.2.1 (2024-02) Clause 5.5.10 V2X message interoperability\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def subscribe_v2x_message(sandbox_name: str, v2xMsgSubscription: V2xMsgSubscription) -> object:\n",
" \"\"\"\n",
" Request to subscribe the V2X messages which come from different vehicle OEMs or operators\n",
" :param sandbox_name: The MEC Sandbox instance to use\n",
" :param app_inst_id: The MEC application instance identifier\n",
" :param sub_id: The subscription identifier\n",
" :return The HTTP response, the HTTP response status, the subscription identifier and the subscription URL on success, None otherwise\n",
" :see ETSI GS MEC 030 V3.2.1 (2024-02) Clause 5.5.10 V2X message interoperability\n",
" \"\"\"\n",
" global MEC_PLTF, logger, service_api\n",
" logger.debug('>>> subscribe_v2x_message: v2xMsgSubscription: ' + str(v2xMsgSubscription))\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",
" # 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": null,
"metadata": {},
"outputs": [],
"source": [
"def delete_mec_subscription(resource_url: str) -> int:\n",
" \"\"\"\n",
" Delete any existing MEC subscription\n",
" :param resource_url: The subscription URL\n",
" :return 0 on success, -1 otherwise\n",
" \"\"\"\n",
" global MEC_PLTF, logger, service_api\n",
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
"\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",
"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",
" # 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",
" # 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",
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To recieve notifcation, our MEC application is required to support an HTTP listenener to recieve POST requests from the MEC Sandbox and reply to them: this is the notification mechanism.\n",
"\n",
"This minimalistic HTTP server will also be used to implement the endpoints provided by our MEC application service: see chapter [Our third MEC application: how to create a new MEC Services](#our_third_mec_application_how_to_create_a_new_mec_services).\n",
"\n",
"The class HTTPRequestHandler (see cell below) provides the suport of such mechanism.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
"class HTTPServer_RequestHandler(BaseHTTPRequestHandler):\n",
" \"\"\"\n",
" Minimal implementation of an HTTP server (http only).\n",
" \"\"\"\n",
"\n",
" def do_GET(self):\n",
" logger.info('>>> do_GET: ' + self.path)\n",
"\n",
" ctype = self.headers.get('content-type')\n",
" logger.info('do_GET: ' + ctype)\n",
"\n",
" # Send response status code\n",
" self.send_response(HTTPStatus.OK)\n",
"\n",
" # Send message back to client\n",
" message = bytes(str(self.headers) + \"\\n\" +self.requestline +\"\\n\", 'utf8')\n",
"\n",
" # Send headers\n",
" self.send_header('Content-type','text/plain; charset=utf-8')\n",
" self.send_header('Content-length', str(len(message)))\n",
" self.end_headers()\n",
"\n",
" # Write content as utf-8 data\n",
" self.wfile.write(message)\n",
" return\n",
" logger.info('>>> do_POST: ' + self.path)\n",
"\n",
" ctype = self.headers.get('content-type')\n",
" logger.info('do_POST: ' + ctype)\n",
"\n",
" content_len = int(self.headers.get('Content-Length'))\n",
" if content_len != 0:\n",
" body = self.rfile.read(content_len).decode('utf8')\n",
" logger.info('do_POST: body:' + str(type(body)))\n",
" logger.info('do_POST: body:' + str(body))\n",
" data = json.loads(str(body))\n",
" logger.info('do_POST: data: %s', str(data))\n",
"\n",
" self.send_response(HTTPStatus.NOT_IMPLEMENTED)\n",
" def do_PUT(self):\n",
" logger.info('>>> do_PUT: ' + self.path)\n",
"\n",
" ctype = self.headers.get('content-type')\n",
" logger.info('do_PUT: ' + ctype)\n",
"\n",
" self.send_response(HTTPStatus.NOT_IMPLEMENTED)\n",
" self.end_headers()\n",
"\n",
" def do_PATCH(self):\n",
" logger.info('>>> do_PATCH: ' + self.path)\n",
"\n",
" ctype = self.headers.get('content-type')\n",
" logger.info('do_PATCH: ' + ctype)\n",
" \n",
" self.send_response(HTTPStatus.NOT_IMPLEMENTED)\n",
" self.end_headers()\n",
" # End of class HTTPRequestHandler\n",
"\n",
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
" def do_DELETE(self):\n",
" logger.info('>>> do_DELETE: ' + self.path)\n",
"\n",
" ctype = self.headers.get('content-type')\n",
" logger.info('do_DELETE: ' + ctype)\n",
" \n",
" self.send_response(HTTPStatus.NOT_IMPLEMENTED)\n",
" self.end_headers()\n",
" # End of class HTTPRequestHandler\n",
"\n",
"def start_notification_server() -> HTTPServer:\n",
" \"\"\"\n",
" Start the notification server\n",
" :return The instance of the HTTP server\n",
" \"\"\"\n",
" global LISTENER_PORT\n",
"\n",
" server_address = ('', LISTENER_PORT)\n",
" httpd = HTTPServer(server_address, HTTPServer_RequestHandler)\n",
" # Start notification server in a daemonized thread\n",
" notification_server = threading.Thread(target = httpd.serve_forever, name='notification_server')\n",
" notification_server.daemon = True\n",
" notification_server.start()\n",
" return httpd\n",
" # End of function HTTPRequestHandler\n",
"\n",
"def stop_notification_server(httpd: HTTPServer):\n",
" \"\"\"\n",
" Stop the notification server\n",
" :param The instance of the HTTP server\n",
" \"\"\"\n",
" httpd.server_close()\n",
" httpd=None\n",
" # End of function HTTPRequestHandler\n"
]
},
{
"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",
"- Start the notification server\n",
"- Get UU unicast provisioning information\n",
"- Add subscription\n",
"- Stop the notification server\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",
" - Start the notification server\n",
" - Get UU unicast provisioning information\n",
" - Add subscription\n",
" - Stop the notification server\n",
" global 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",
" # 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",
" httpd = start_notification_server()\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",
" # Stop notification server\n",
" stop_notification_server(httpd)\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"
]
},
{
"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",
"PoAs (Point Of Access) are categorized depending on where they lie in each grid. \n",
"Each category has its own traffic load patterns which are pre-determin. The V2X QoS Prediction) will give more accurate values of RSRP and RSRQ based on the diurnal traffic patterns for each. The network scenario named \"4g-5g-v2x-macro\" must be used to get access to the V2X QoS Prediction feature.\n",
"\n",
"**Note:** The MEC Sanbox V2X QoS Prediction is enabled when the PredictedQos.routes.routeInfo.time attribute is present in the request (see ETSI GS MEC 030 V3.2.1 (2024-02) Clause 6.2.6 Type: Preditecd QoS)\n",
"\n",
"Limitations:\n",
"* The Location Granularity is currently not being validated as RSRP/RSRP calculations are done at the exact location provided by the user.\n",
"* Time Granularity is currently not supported by the Prediction Function (design limitations of the minimal, emulated, pre-determined traffic prediction)\n",
"* Upper limit on the number of elements (10 each) in the routes and routeInfo structures (arrays) to not affect user experience and respoy\n",
"\n"
]
},
{
"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",
"| Location | Time | PoA | Category | Status | QoS without Prediction Model | QoS with Prediction Model | Expected |\n",
"| \t | (Unix time in sec) | Standard (GMT) | | | | RSRP | RSRQ | RSRP | RSRQ | |\n",
"| ------------------- | ----------- | -------------- | ---------------- | ----------- | ------------- | -------------- | ----------- | ----------- | ----------- | -------- |\n",
"| 43.729416,7.414853 | 1653295620 | 08:47:00 | 4g-macro-cell-2 | Residential | Congested | 63 | 21 | 60 | 20 | Yes |\n",
"| 43.732456,7.418417 | 1653299220 | 09:47:00 | 4g-macro-cell-3 | Residential | Not Congested | 55 | 13 | 55 | 13 | Yes |\n",
"| 43.73692,7.4209256 | 1653302820 | 10:47:00 | 4g-macro-cell-6 | Coastal | Not Congested | 68 | 26 | 68 | 26 | Yes |\n",
"| 43.738007,7.4230533 | 1653305220 | 11:27:00 | 4g-macro-cell-6 | Coastal | Not Congested | 55 | 13 | 55 | 13 | Yes |\n",
"| 43.739685,7.424881 | 1653308820 | 12:27:00 | 4g-macro-cell-7 | Commercial | Congested | 63 | 21 | 40 | 13 | Yes |\n",
"| 43.74103,7.425759 | 1653312600 | 13:30:00 | 4g-macro-cell-7 | Commercial | Congested | 56 | 14 | 40 | 8 | Yes |\n",
"| 43.74258,7.4277945 | 1653315900 | 14:25:00 | 4g-macro-cell-8 | Coastal | Congested | 59 | 17 | 47 | 13 | Yes |\n",
"| 43.744972,7.4295254 | 1653318900 | 15:15:00 | 4g-macro-cell-8 | Coastal | Congested | 53 | 11 | 40 | 5 | Yes |\n",
"| 43.74773,7.4320855 | 1653322500 | 16:15:00 | 5g-small-cell-14 | Commercial | Congested | 78 | 69 | 60 | 53 | Yes |\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\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The image 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",
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
"{\n",
" \"predictionTarget\": \"SINGLE_UE_PREDICTION\",\n",
" \"timeGranularity\": null,\n",
" \"locationGranularity\": \"30\",\n",
" \"routes\": [\n",
" {\n",
" \"routeInfo\": [\n",
" {\n",
" \"location\": {\n",
" \"geoArea\": {\n",
" \"latitude\": 43.729416,\n",
" \"longitude\": 7.414853\n",
" }\n",
" },\n",
" \"time\": {\n",
" \"nanoSeconds\": 0,\n",
" \"seconds\": 1653295620\n",
" }\n",
" },\n",
" {\n",
" \"location\": {\n",
" \"geoArea\": {\n",
" \"latitude\": 43.732456,\n",
" \"longitude\": 7.418417\n",
" }\n",
" },\n",
" \"time\": {\n",
" \"nanoSeconds\": 0,\n",
" \"seconds\": 1653299220\n",
" ]\n",
" }\n",
" ]\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": null,
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
"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",