From d63eae3bdbaee7ee1c240b90c353af2d819eaa55 Mon Sep 17 00:00:00 2001 From: Cong Wang Date: Fri, 18 Oct 2024 16:04:48 -0400 Subject: [PATCH 01/14] Add qos_metrics, scheduling, notifications to GET connection request --- sdx_controller/handlers/connection_handler.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sdx_controller/handlers/connection_handler.py b/sdx_controller/handlers/connection_handler.py index b644794..e3f89ac 100644 --- a/sdx_controller/handlers/connection_handler.py +++ b/sdx_controller/handlers/connection_handler.py @@ -367,6 +367,9 @@ def get_connection_status(db, service_id: str): # request for this service_id. name = "unknown" description = "unknown" + qos_metrics = {} + scheduling = {} + notifications = {} request = db.read_from_db("connections", service_id) if not request: @@ -379,6 +382,9 @@ def get_connection_status(db, service_id: str): request_dict = json.loads(request.get(service_id)) name = request_dict.get("name") description = request_dict.get("description") + qos_metrics = request_dict.get("qos_metrics") + scheduling = request_dict.get("scheduling") + notifications = request_dict.get("notifications") # TODO: we're missing many of the attributes in the response here # which have been specified in the provisioning spec, such as: @@ -393,6 +399,14 @@ def get_connection_status(db, service_id: str): "description": description, "endpoints": endpoints, } + if qos_metrics: + response[service_id]["qos_metrics"] = qos_metrics + + if scheduling: + response[service_id]["scheduling"] = scheduling + + if notifications: + response[service_id]["notifications"] = notifications logger.info(f"Formed a response: {response}") From 21d8aafa4a0e9ad301eebe1023cc0c67e2d36a5b Mon Sep 17 00:00:00 2001 From: Cong Wang Date: Fri, 18 Oct 2024 16:06:33 -0400 Subject: [PATCH 02/14] black --- sdx_controller/handlers/connection_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdx_controller/handlers/connection_handler.py b/sdx_controller/handlers/connection_handler.py index e3f89ac..434f23e 100644 --- a/sdx_controller/handlers/connection_handler.py +++ b/sdx_controller/handlers/connection_handler.py @@ -404,7 +404,7 @@ def get_connection_status(db, service_id: str): if scheduling: response[service_id]["scheduling"] = scheduling - + if notifications: response[service_id]["notifications"] = notifications From 07689d1661e6ac107c8ee9f5c4ae3400b232454d Mon Sep 17 00:00:00 2001 From: Yufeng Xin Date: Tue, 22 Oct 2024 07:46:53 -0400 Subject: [PATCH 03/14] using the request endpoints; added current_path in the response --- sdx_controller/handlers/connection_handler.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sdx_controller/handlers/connection_handler.py b/sdx_controller/handlers/connection_handler.py index 434f23e..70ec255 100644 --- a/sdx_controller/handlers/connection_handler.py +++ b/sdx_controller/handlers/connection_handler.py @@ -370,6 +370,7 @@ def get_connection_status(db, service_id: str): qos_metrics = {} scheduling = {} notifications = {} + request_endpoints = [] request = db.read_from_db("connections", service_id) if not request: @@ -385,6 +386,7 @@ def get_connection_status(db, service_id: str): qos_metrics = request_dict.get("qos_metrics") scheduling = request_dict.get("scheduling") notifications = request_dict.get("notifications") + request_endpoints = request_dict.get("endpoints") # TODO: we're missing many of the attributes in the response here # which have been specified in the provisioning spec, such as: @@ -397,7 +399,8 @@ def get_connection_status(db, service_id: str): "service_id": service_id, "name": name, "description": description, - "endpoints": endpoints, + "endpoints": request_endpoints, + "current_path": endpoints, } if qos_metrics: response[service_id]["qos_metrics"] = qos_metrics From 49fb3b7e0f0e1ca19ba6f51e427e203314d7b342 Mon Sep 17 00:00:00 2001 From: Yufeng Xin Date: Tue, 22 Oct 2024 08:03:57 -0400 Subject: [PATCH 04/14] using the request endpoints -> response_endpoints --- sdx_controller/handlers/connection_handler.py | 54 ++++++++++++------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/sdx_controller/handlers/connection_handler.py b/sdx_controller/handlers/connection_handler.py index 70ec255..2c99686 100644 --- a/sdx_controller/handlers/connection_handler.py +++ b/sdx_controller/handlers/connection_handler.py @@ -335,12 +335,32 @@ def get_connection_status(db, service_id: str): # See https://sdx-docs.readthedocs.io/en/latest/specs/provisioning-api-1.0.html#request-format-2 # - response = {} - domains = breakdown.get(service_id) logger.info(f"domains for {service_id}: {domains.keys()}") endpoints = list() + request_endpoints = [] + response_endpoints = [] + + request = db.read_from_db("connections", service_id) + if not request: + logger.error(f"Can't find a connection request for {service_id}") + # TODO: we're in a strange state here. Should we panic? + else: + logger.info(f"Found request for {service_id}: {request}") + # We seem to have saved the original request in the form of a + # string into the DB, not a record. + request_dict = json.loads(request.get(service_id)) + name = request_dict.get("name") + description = request_dict.get("description") + qos_metrics = request_dict.get("qos_metrics") + scheduling = request_dict.get("scheduling") + notifications = request_dict.get("notifications") + request_endpoints = request_dict.get("endpoints") + request_uni_a = request_endpoints[0] + request_uni_z = request_endpoints[1] + + response = {} for domain, breakdown in domains.items(): uni_a_port = breakdown.get("uni_a").get("port_id") @@ -353,6 +373,12 @@ def get_connection_status(db, service_id: str): endpoints.append(endpoint_a) + if request_uni_a.get("port_id") == uni_a_port: + response_endpoints.append(endpoint_a) + + if request_uni_z.get("port_id") == uni_a_port: + response_endpoints.append(endpoint_a) + uni_z_port = breakdown.get("uni_z").get("port_id") uni_z_vlan = breakdown.get("uni_z").get("tag").get("value") @@ -363,6 +389,11 @@ def get_connection_status(db, service_id: str): endpoints.append(endpoint_z) + if request_uni_a.get("port_id") == uni_z_port: + response_endpoints.append(endpoint_z) + if request_uni_z.get("port_id") == uni_z_port: + response_endpoints.append(endpoint_z) + # Find the name and description from the original connection # request for this service_id. name = "unknown" @@ -370,23 +401,6 @@ def get_connection_status(db, service_id: str): qos_metrics = {} scheduling = {} notifications = {} - request_endpoints = [] - - request = db.read_from_db("connections", service_id) - if not request: - logger.error(f"Can't find a connection request for {service_id}") - # TODO: we're in a strange state here. Should we panic? - else: - logger.info(f"Found request for {service_id}: {request}") - # We seem to have saved the original request in the form of a - # string into the DB, not a record. - request_dict = json.loads(request.get(service_id)) - name = request_dict.get("name") - description = request_dict.get("description") - qos_metrics = request_dict.get("qos_metrics") - scheduling = request_dict.get("scheduling") - notifications = request_dict.get("notifications") - request_endpoints = request_dict.get("endpoints") # TODO: we're missing many of the attributes in the response here # which have been specified in the provisioning spec, such as: @@ -399,7 +413,7 @@ def get_connection_status(db, service_id: str): "service_id": service_id, "name": name, "description": description, - "endpoints": request_endpoints, + "endpoints": response_endpoints, "current_path": endpoints, } if qos_metrics: From c81aa76efc17743a16cc970ab3286f2b91b8ab1e Mon Sep 17 00:00:00 2001 From: Yufeng Xin Date: Tue, 22 Oct 2024 08:16:42 -0400 Subject: [PATCH 05/14] port_id, id --- sdx_controller/handlers/connection_handler.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sdx_controller/handlers/connection_handler.py b/sdx_controller/handlers/connection_handler.py index 2c99686..b765cea 100644 --- a/sdx_controller/handlers/connection_handler.py +++ b/sdx_controller/handlers/connection_handler.py @@ -338,6 +338,14 @@ def get_connection_status(db, service_id: str): domains = breakdown.get(service_id) logger.info(f"domains for {service_id}: {domains.keys()}") + # Find the name and description from the original connection + # request for this service_id. + name = "unknown" + description = "unknown" + qos_metrics = {} + scheduling = {} + notifications = {} + endpoints = list() request_endpoints = [] response_endpoints = [] @@ -373,10 +381,10 @@ def get_connection_status(db, service_id: str): endpoints.append(endpoint_a) - if request_uni_a.get("port_id") == uni_a_port: + if request_uni_a.get("id") == uni_a_port: response_endpoints.append(endpoint_a) - if request_uni_z.get("port_id") == uni_a_port: + if request_uni_z.get("id") == uni_a_port: response_endpoints.append(endpoint_a) uni_z_port = breakdown.get("uni_z").get("port_id") @@ -389,19 +397,11 @@ def get_connection_status(db, service_id: str): endpoints.append(endpoint_z) - if request_uni_a.get("port_id") == uni_z_port: + if request_uni_a.get("id") == uni_z_port: response_endpoints.append(endpoint_z) - if request_uni_z.get("port_id") == uni_z_port: + if request_uni_z.get("id") == uni_z_port: response_endpoints.append(endpoint_z) - # Find the name and description from the original connection - # request for this service_id. - name = "unknown" - description = "unknown" - qos_metrics = {} - scheduling = {} - notifications = {} - # TODO: we're missing many of the attributes in the response here # which have been specified in the provisioning spec, such as: # name, description, qos_metrics, notifications, ownership, From 8618614867001f43702dc10a12db6c359433baa2 Mon Sep 17 00:00:00 2001 From: Yufeng Xin Date: Tue, 22 Oct 2024 12:50:57 -0400 Subject: [PATCH 06/14] v1 compitable --- sdx_controller/handlers/connection_handler.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/sdx_controller/handlers/connection_handler.py b/sdx_controller/handlers/connection_handler.py index b765cea..e66035d 100644 --- a/sdx_controller/handlers/connection_handler.py +++ b/sdx_controller/handlers/connection_handler.py @@ -364,9 +364,17 @@ def get_connection_status(db, service_id: str): qos_metrics = request_dict.get("qos_metrics") scheduling = request_dict.get("scheduling") notifications = request_dict.get("notifications") - request_endpoints = request_dict.get("endpoints") - request_uni_a = request_endpoints[0] - request_uni_z = request_endpoints[1] + if request_dict.get("endpoints") is not None: # spec version 2.0.0 + request_endpoints = request_dict.get("endpoints") + request_uni_a = request_endpoints[0] + request_uni_a_id = request_uni_a.get("port_id") + request_uni_z = request_endpoints[1] + request_uni_z_id = request_uni_z.get("port_id") + else: # spec version 1.0.0 + request_uni_a = request_dict.get("ingress_port") + request_uni_a_id = request_uni_a.get("id") + request_uni_z = request_dict.get("egress_port") + request_uni_z_id = request_uni_z.get("id") response = {} @@ -381,10 +389,10 @@ def get_connection_status(db, service_id: str): endpoints.append(endpoint_a) - if request_uni_a.get("id") == uni_a_port: + if request_uni_a_id == uni_a_port: response_endpoints.append(endpoint_a) - if request_uni_z.get("id") == uni_a_port: + if request_uni_z_id == uni_a_port: response_endpoints.append(endpoint_a) uni_z_port = breakdown.get("uni_z").get("port_id") @@ -397,9 +405,9 @@ def get_connection_status(db, service_id: str): endpoints.append(endpoint_z) - if request_uni_a.get("id") == uni_z_port: + if request_uni_a_id == uni_z_port: response_endpoints.append(endpoint_z) - if request_uni_z.get("id") == uni_z_port: + if request_uni_z_id == uni_z_port: response_endpoints.append(endpoint_z) # TODO: we're missing many of the attributes in the response here From 77699d9a050a4853e55f39e70585cf0fa68caebb Mon Sep 17 00:00:00 2001 From: Yufeng Xin Date: Tue, 22 Oct 2024 12:58:52 -0400 Subject: [PATCH 07/14] log --- sdx_controller/handlers/connection_handler.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sdx_controller/handlers/connection_handler.py b/sdx_controller/handlers/connection_handler.py index e66035d..4239b8f 100644 --- a/sdx_controller/handlers/connection_handler.py +++ b/sdx_controller/handlers/connection_handler.py @@ -349,6 +349,8 @@ def get_connection_status(db, service_id: str): endpoints = list() request_endpoints = [] response_endpoints = [] + request_uni_a_id = None + request_uni_z_id = None request = db.read_from_db("connections", service_id) if not request: @@ -410,6 +412,10 @@ def get_connection_status(db, service_id: str): if request_uni_z_id == uni_z_port: response_endpoints.append(endpoint_z) + logger.info( + f"endpoints info: {request_uni_a_id}, {request_uni_z_id}, {uni_a_port}, {uni_z_port}" + ) + # TODO: we're missing many of the attributes in the response here # which have been specified in the provisioning spec, such as: # name, description, qos_metrics, notifications, ownership, From d890e5543b2425902635a9d5300162d551d9da4a Mon Sep 17 00:00:00 2001 From: Yufeng Xin Date: Tue, 22 Oct 2024 13:14:27 -0400 Subject: [PATCH 08/14] print --- sdx_controller/handlers/connection_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdx_controller/handlers/connection_handler.py b/sdx_controller/handlers/connection_handler.py index 4239b8f..4e92fd4 100644 --- a/sdx_controller/handlers/connection_handler.py +++ b/sdx_controller/handlers/connection_handler.py @@ -412,7 +412,7 @@ def get_connection_status(db, service_id: str): if request_uni_z_id == uni_z_port: response_endpoints.append(endpoint_z) - logger.info( + print( f"endpoints info: {request_uni_a_id}, {request_uni_z_id}, {uni_a_port}, {uni_z_port}" ) From 2577a629133d564ffc3c4b7aed98bc99ecbd86c2 Mon Sep 17 00:00:00 2001 From: Yufeng Xin Date: Tue, 22 Oct 2024 13:17:52 -0400 Subject: [PATCH 09/14] debug print --- sdx_controller/handlers/connection_handler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sdx_controller/handlers/connection_handler.py b/sdx_controller/handlers/connection_handler.py index 4e92fd4..3f854eb 100644 --- a/sdx_controller/handlers/connection_handler.py +++ b/sdx_controller/handlers/connection_handler.py @@ -366,6 +366,7 @@ def get_connection_status(db, service_id: str): qos_metrics = request_dict.get("qos_metrics") scheduling = request_dict.get("scheduling") notifications = request_dict.get("notifications") + print(f"request_dict: {request_dict}") if request_dict.get("endpoints") is not None: # spec version 2.0.0 request_endpoints = request_dict.get("endpoints") request_uni_a = request_endpoints[0] From 7abe687c83c18cd97760d0fe63f335034b8b57b8 Mon Sep 17 00:00:00 2001 From: Yufeng Xin Date: Tue, 22 Oct 2024 13:22:56 -0400 Subject: [PATCH 10/14] id or port_id? --- sdx_controller/handlers/connection_handler.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sdx_controller/handlers/connection_handler.py b/sdx_controller/handlers/connection_handler.py index 3f854eb..be329f2 100644 --- a/sdx_controller/handlers/connection_handler.py +++ b/sdx_controller/handlers/connection_handler.py @@ -371,8 +371,12 @@ def get_connection_status(db, service_id: str): request_endpoints = request_dict.get("endpoints") request_uni_a = request_endpoints[0] request_uni_a_id = request_uni_a.get("port_id") + if request_uni_a_id is None: + request_uni_a_id = request_uni_a.get("id") request_uni_z = request_endpoints[1] request_uni_z_id = request_uni_z.get("port_id") + if request_uni_z_id is None: + request_uni_z_id = request_uni_z.get("id") else: # spec version 1.0.0 request_uni_a = request_dict.get("ingress_port") request_uni_a_id = request_uni_a.get("id") From 5649923766ec01314479fa7655e97858a14223d5 Mon Sep 17 00:00:00 2001 From: Yufeng Xin Date: Tue, 22 Oct 2024 13:27:10 -0400 Subject: [PATCH 11/14] id in the test --- sdx_controller/test/test_l2vpn_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdx_controller/test/test_l2vpn_controller.py b/sdx_controller/test/test_l2vpn_controller.py index c344401..9d68cd8 100644 --- a/sdx_controller/test/test_l2vpn_controller.py +++ b/sdx_controller/test/test_l2vpn_controller.py @@ -440,7 +440,7 @@ def test_place_connection_v2_with_any_vlan_in_request(self): # "vlan": "150" # }, # { - # "port_id": "urn:sdx:port:amlight:B1:1", + # "port_id": "urn:sdx:port:amlight:B1:3", # "vlan": "300"} # ], # } From f936a7ef318345e5bbe369d9e1c55fdba54fb3cc Mon Sep 17 00:00:00 2001 From: Yufeng Xin Date: Tue, 22 Oct 2024 13:29:33 -0400 Subject: [PATCH 12/14] id in the test --- sdx_controller/test/test_l2vpn_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdx_controller/test/test_l2vpn_controller.py b/sdx_controller/test/test_l2vpn_controller.py index 9d68cd8..6f23d53 100644 --- a/sdx_controller/test/test_l2vpn_controller.py +++ b/sdx_controller/test/test_l2vpn_controller.py @@ -397,7 +397,7 @@ def test_place_connection_v2_with_any_vlan_in_request(self): "vlan": "any" }, { - "port_id": "urn:sdx:port:amlight:B1:1", + "port_id": "urn:sdx:port:amlight:B1:3", "vlan": "any" } ] From c6470a368d212bbdeca4e0a230f71facf229049c Mon Sep 17 00:00:00 2001 From: Yufeng Xin Date: Tue, 22 Oct 2024 13:42:51 -0400 Subject: [PATCH 13/14] id in the test --- sdx_controller/test/test_l2vpn_controller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdx_controller/test/test_l2vpn_controller.py b/sdx_controller/test/test_l2vpn_controller.py index 6f23d53..f9f54f9 100644 --- a/sdx_controller/test/test_l2vpn_controller.py +++ b/sdx_controller/test/test_l2vpn_controller.py @@ -397,7 +397,7 @@ def test_place_connection_v2_with_any_vlan_in_request(self): "vlan": "any" }, { - "port_id": "urn:sdx:port:amlight:B1:3", + "port_id": "urn:sdx:port:amlight.net:B1:3", "vlan": "any" } ] @@ -440,7 +440,7 @@ def test_place_connection_v2_with_any_vlan_in_request(self): # "vlan": "150" # }, # { - # "port_id": "urn:sdx:port:amlight:B1:3", + # "port_id": "urn:sdx:port:amlight.net:B1:3", # "vlan": "300"} # ], # } From 3e03585be2b32971b6696c2f8b8dcaf6316174c4 Mon Sep 17 00:00:00 2001 From: Yufeng Xin Date: Tue, 22 Oct 2024 21:33:05 -0400 Subject: [PATCH 14/14] keep two endpoints in response --- pyproject.toml | 2 +- sdx_controller/handlers/connection_handler.py | 26 ++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ce9f98a..a689bb9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,7 +67,7 @@ profile = "black" src_paths = ["sdx_controller", "bapm_server"] [tool.pytest.ini_options] -addopts = "--cov=sdx_controller --cov=bapm_server --cov-report html --cov-report term-missing" +addopts = "--cov=sdx_controller --cov=bapm_server" testpaths = [ "sdx_controller/test" ] diff --git a/sdx_controller/handlers/connection_handler.py b/sdx_controller/handlers/connection_handler.py index be329f2..daa81f8 100644 --- a/sdx_controller/handlers/connection_handler.py +++ b/sdx_controller/handlers/connection_handler.py @@ -397,10 +397,17 @@ def get_connection_status(db, service_id: str): endpoints.append(endpoint_a) if request_uni_a_id == uni_a_port: - response_endpoints.append(endpoint_a) - + ( + response_endpoints.append(endpoint_a) + if endpoint_a not in response_endpoints + else None + ) if request_uni_z_id == uni_a_port: - response_endpoints.append(endpoint_a) + ( + response_endpoints.append(endpoint_a) + if endpoint_a not in response_endpoints + else None + ) uni_z_port = breakdown.get("uni_z").get("port_id") uni_z_vlan = breakdown.get("uni_z").get("tag").get("value") @@ -413,10 +420,17 @@ def get_connection_status(db, service_id: str): endpoints.append(endpoint_z) if request_uni_a_id == uni_z_port: - response_endpoints.append(endpoint_z) + ( + response_endpoints.append(endpoint_z) + if endpoint_z not in response_endpoints + else None + ) if request_uni_z_id == uni_z_port: - response_endpoints.append(endpoint_z) - + ( + response_endpoints.append(endpoint_z) + if endpoint_z not in response_endpoints + else None + ) print( f"endpoints info: {request_uni_a_id}, {request_uni_z_id}, {uni_a_port}, {uni_z_port}" )