Skip to content

Commit

Permalink
Merge pull request #341 from atlanticwave-sdx/add-qos_metrics-schedul…
Browse files Browse the repository at this point in the history
…ing-notifications

Add qos_metrics, scheduling, notifications to GET connection request
  • Loading branch information
YufengXin authored Oct 23, 2024
2 parents 5cc5fe8 + 3e03585 commit 30d8616
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down
102 changes: 83 additions & 19 deletions sdx_controller/handlers/connection_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,55 @@ 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()}")

# 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 = []
request_uni_a_id = None
request_uni_z_id = None

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")
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]
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")
request_uni_z = request_dict.get("egress_port")
request_uni_z_id = request_uni_z.get("id")

response = {}

for domain, breakdown in domains.items():
uni_a_port = breakdown.get("uni_a").get("port_id")
Expand All @@ -353,6 +396,19 @@ 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)
if endpoint_a not in response_endpoints
else None
)
if request_uni_z_id == uni_a_port:
(
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")

Expand All @@ -363,22 +419,21 @@ def get_connection_status(db, service_id: str):

endpoints.append(endpoint_z)

# Find the name and description from the original connection
# request for this service_id.
name = "unknown"
description = "unknown"

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")
if request_uni_a_id == uni_z_port:
(
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)
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}"
)

# TODO: we're missing many of the attributes in the response here
# which have been specified in the provisioning spec, such as:
Expand All @@ -391,8 +446,17 @@ def get_connection_status(db, service_id: str):
"service_id": service_id,
"name": name,
"description": description,
"endpoints": endpoints,
"endpoints": response_endpoints,
"current_path": 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}")

Expand Down
4 changes: 2 additions & 2 deletions sdx_controller/test/test_l2vpn_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.net:B1:3",
"vlan": "any"
}
]
Expand Down Expand Up @@ -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.net:B1:3",
# "vlan": "300"}
# ],
# }
Expand Down

0 comments on commit 30d8616

Please sign in to comment.