Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
"2024-06-19 08:33:49,262 - __main__ - DEBUG - >>> process_logout: sandbox=sbx0rphiwx\n",
"2024-06-19 08:33:49,265 DEBUG Resetting dropped connection: mec-platform.etsi.org\n",
"/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host 'mec-platform.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-06-19 08:33:49,416 DEBUG https://mec-platform.etsi.org:443 \"POST /sandbox-api/v1/logout?sandbox_name=sbx0rphiwx HTTP/1.1\" 204 0\n",
"2024-06-19 08:33:49,418 DEBUG response body: b''\n",
"2024-06-19 08:33:49,420 - __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-06-19 08:33:49,421 - __main__ - DEBUG - Stopped at 20240619-083349\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"send: b'POST /sandbox-api/v1/logout?sandbox_name=sbx0rphiwx HTTP/1.1\\r\\nHost: mec-platform.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: Wed, 19 Jun 2024 06:33:48 GMT\n",
"header: Content-Type: application/json; charset=UTF-8\n",
"header: Connection: keep-alive\n",
"header: Strict-Transport-Security: max-age=15724800; includeSubDomains\n"
]
}
],
"source": [
"def process_main():\n",
" \"\"\"\n",
" This is the second sprint of our skeleton of our MEC application:\n",
" - Login\n",
" - Print sandbox identifier\n",
" - Print available network scenarios\n",
" - Activate a network scenario\n",
" - Check that the network scenario is activated and the MEC services are running\n",
" - Deactivate a network scenario\n",
" - Logout\n",
" - Check that logout is effective\n",
" \"\"\" \n",
" global 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",
" 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 identifer\n",
" app_inst_id = request_application_instance_id(sandbox)\n",
" if app_inst_id == None:\n",
" logger.error(\"Failed to request an application instance identifer\")\n",
" else:\n",
" logger.info(\"app_inst_id: %s\", str(type(app_inst_id)))\n",
" logger.info(\"app_inst_id: %s\", str(app_inst_id))\n",
"\n",
" # Check that the network scenario is activated and the MEC services are running \n",
" logger.info(\"To check that the app_inst_id is created, verify on the MEC Sandbox server that the MEC services are running (kubectl get pods -A\")\n",
" time.sleep(3) # Sleep for 3 seconds\n",
"\n",
" # Delete the application instance identifer\n",
" if delete_application_instance_id(sandbox, app_inst_id.id) == -1:\n",
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
" logger.error(\"Failed to delete the application instance identifer\")\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": "markdown",
"metadata": {},
"source": [
"## MEC Registration and the READY confirmation\n",
"\n",
"Having an application instance identifier allows us to register to the MEC Sandbox and interacts with it (e.g. to send service queries, to subscribe to events and to recieve notifications...).\n",
"\n",
"The standard MEC 011 Clause 5.2.2 MEC application start-up describes the start up process. Basically, our MEC application has to:\n",
"1. Indicates that it is running by sending a Confirm Ready message\n",
"2. Retrieve the list of MEC services \n",
"\n",
"To do so, a MEC application need to be able to send request but also to recieve notifications (POST requests) and to reply to them."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Fifth step: Send the READY confirmation\n",
"\n",
"Sending READY confirmation is described by MEC 011 Clause 5.2.2 MEC application start-up.\n",
"\n",
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
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def send_ready_confirmation(app_inst_id: str) -> int:\n",
" global MEC_SANDBOX_URL, MEC_PLTF, logger\n",
"\n",
" try:\n",
" url = MEC_SANDBOX_URL + '/' + MEC_PLTF + '/mec_app_support/v2/applications/' + app_inst_id + '/confirm_ready'\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",
" body = '{\\\"indication\\\":\\\"READY\\\"}'\n",
" result = api.call_api(url, 'POST', header_params=header_params, body=body, async_req=False)\n",
" return 0\n",
" except ApiException as e:\n",
" logger.error(\"Exception when calling AuthorizationApi->logout: %s\\n\" % e)\n",
" return -1\n",
" # End of function send_ready_confirmation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def send_termination() -> int:\n",
" pass"
]
},
{
"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 identifer\n",
"- Send READY confirmation\n",
"- Get MEC services\n",
"- Check list of services \n",
"- Delete our application instance identifer\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 identifer\n",
" - Send READY confirmation\n",
" - Get MEC services\n",
" - Send Termination\n",
" - Delete our application instance identifer\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",
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
1304
1305
1306
1307
1308
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
" # 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 identifer\n",
" app_inst_id = request_application_instance_id(sandbox)\n",
" if app_inst_id == None:\n",
" logger.error(\"Failed to request an application instance identifer\")\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",
" # Check list of services\n",
"\n",
" # Delete the application instance identifer\n",
" if delete_application_instance_id(sandbox) == -1:\n",
" logger.error(\"Failed to delete the application instance identifer\")\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": "markdown",
"metadata": {},
"source": [
"### Notification support\n",
"\n",
"To recieve notifcation, our MEC application is required to support an HTTP listenener to recieve POST request from the MEC Sandbox and replto repry to them: this is the notification mechanism.\n",
"\n",
"The class HTTPRequestHandler (see cell below) provides the suport of such mechanism.\n"
]
},
{
"cell_type": "code",
"execution_count": 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"
]
},
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
{
"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": [
"# Bibliography\n",
"\n",
"1. ETSI GS MEC 002 (V2.2.1) (01-2022): \"Multi-access Edge Computing (MEC); Phase 2: Use Cases and Requirements\".\n",
"2. ETSI GS MEC 010-1 (V1.1.1) (10-2017): \"Mobile Edge Computing (MEC); Mobile Edge Management; Part 1: System, host and platform management\".\n",
"3. ETSI GS MEC 010-2 (V2.2.1) (02-2022): \"Multi-access Edge Computing (MEC); MEC Management; Part 2: Application lifecycle, rules and requirements management\".\n",
"4. ETSI GS MEC 011 (V3.1.1) (09-2022): \"Multi-access Edge Computing (MEC); Edge Platform Application Enablement\".\n",
"5. ETSI GS MEC 012 (V2.2.1) (02-2022): \"Multi-access Edge Computing (MEC); Radio Network Information API\".\n",
"6. ETSI GS MEC 013 (V2.2.1) (01-2022): \"Multi-access Edge Computing (MEC); Location API\".\n",
"7. ETSI GS MEC 014 (V2.1.1) (03-2021): \"Multi-access Edge Computing (MEC); UE Identity API\".\n",
"8. ETSI GS MEC 015 (V2.1.1) (06-2020): \"Multi-Access Edge Computing (MEC); Traffic Management APIs\".\n",
"9. ETSI GS MEC 016 (V2.2.1) (04-2020): \"Multi-access Edge Computing (MEC); Device application interface\".\n",
"10. ETSI GS MEC 021 (V2.2.1) (02-2022): \"Multi-access Edge Computing (MEC); Application Mobility Service API\".\n",
"11. ETSI GS MEC 028 (V2.3.1) (07-2022): \"Multi-access Edge Computing (MEC); WLAN Access Information API\".\n",
"12. ETSI GS MEC 029 (V2.2.1) (01-2022): \"Multi-access Edge Computing (MEC); Fixed Access Information API\".\n",
"13. ETSI GS MEC 030 (V2.2.1) (05-2022): \"Multi-access Edge Computing (MEC); V2X Information Service API\".\n",
"14. ETSI GR MEC-DEC 025 (V2.1.1) (06-2019): \"Multi-access Edge Computing (MEC); MEC Testing Framework\".\n",
"15. ETSI GR MEC 001 (V3.1.1) (01-2022): \"Multi-access Edge Computing (MEC); Terminology\".\n",
"16. [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
}