Newer
Older
},
{
"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",
"- Subscribe to AppTerminationNotificationSubscription\n",
"- Get MEC services\n",
"- Check list of services \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",
" - Send READY confirmation\n",
" - Get MEC services\n",
" - Send Termination\n",
" - Delete our application instance identifier\n",
" - Deactivate a network scenario\n",
" - Logout\n",
" - Check that logout is effective\n",
" \"\"\" \n",
" global PROVIDER, MEC_SANDBOX_API_URL, 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",
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
" # 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(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",
" # Send READY confirmation\n",
" send_ready_confirmation(app_inst_id)\n",
"\n",
" # Subscribe to AppTerminationNotificationSubscription\n",
" send_subscribe_termination(sandbox, app_inst_id)\n",
"\n",
" # Delete the application instance identifier\n",
" if delete_application_instance_id(sandbox) == -1:\n",
" logger.error(\"Failed to delete the application instance identifier\")\n",
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
" 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(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"
]
},
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"## How to use MEC Services\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": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"### Getting UU unicast provisioning information"
]
},
{
"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",
" header_params = {}\n",
" # HTTP header `Accept`\n",
" header_params['Accept'] = self.api_client.select_header_accept(['application/json']) # noqa: E501\n",
" # HTTP header `Content-Type`\n",
" header_params['Content-Type'] = self.api_client.select_header_accept(['application/json']) # noqa: E501\n",
" result = api.call_api(url, 'POST', header_params=header_params, async_req=False)\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": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"let's create the our new 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",
"- Get UU unicast provisioning information (ETSI GS MEC 030 Clause 5.5.1)\n",
"- Delete our application instance identifier\n",
"- Deactivate a network scenario\n",
"- Logout\n",
"- Check that logout is effective"
]
},
{
"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",
" - Send READY confirmation\n",
" - Get MEC services\n",
" - Send Termination\n",
" - Delete our application instance identifier\n",
" - Deactivate a network scenario\n",
" - Logout\n",
" - Check that logout is effective\n",
" \"\"\" \n",
" global PROVIDER, MEC_SANDBOX_API_URL, 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(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",
" ecgi = \"C33139970001614,33139971112725\" # 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",
" # Delete the application instance identifier\n",
" if delete_application_instance_id(sandbox) == -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(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": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"### Subscribing to V2X message distribution server\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
"\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": null,
"metadata": {},
"outputs": [],
"source": [
"class HTTPRequestHandler(BaseHTTPRequestHandler):\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",
" print(\"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": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def process():\n",
" # Start notification server in a daemonized thread\n",
" notification_server = threading.Thread(name='notification_server', target=start_server, 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"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Annexes\n",
"\n",
"## Annex A: How to use an existing MEC sandbox instance\n",
"\n",
"TODO\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\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",
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
"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. [The Wiki MEC web site](https://www.etsi.org/technologies/multi-access-edge-computing)\n",
"17. "
]
}
],
"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
}