Skip to content

Commit

Permalink
Merge pull request #249 from atlanticwave-sdx/248-vlan-related-issues…
Browse files Browse the repository at this point in the history
…-and-the-error-codes

248 vlan related issues and the error codes
  • Loading branch information
YufengXin authored Jan 17, 2025
2 parents 95db29a + 8082b9f commit d6b5f09
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
21 changes: 15 additions & 6 deletions src/sdx_pce/topology/temanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ def generate_connection_breakdown(
if tagged_breakdown is None:
raise TEError(
f"Can't find a valid vlan breakdown solution for: {connection_request}",
410,
409,
)

if not isinstance(tagged_breakdown, VlanTaggedBreakdowns):
Expand Down Expand Up @@ -943,12 +943,13 @@ def _reserve_vlan_breakdown(
# segment["ingress_vlan"] = ingress_vlan
# segment["egress_vlan"] = egress_vlan
# upstream_o_vlan = egress_vlan

tag_type = 0 if ingress_vlan == "untagged" else 1
port_a = VlanTaggedPort(
VlanTag(value=ingress_vlan, tag_type=1), port_id=ingress_port_id
VlanTag(value=ingress_vlan, tag_type=tag_type), port_id=ingress_port_id
)
tag_type = 0 if egress_vlan == "untagged" else 1
port_z = VlanTaggedPort(
VlanTag(value=egress_vlan, tag_type=1), port_id=egress_port_id
VlanTag(value=egress_vlan, tag_type=tag_type), port_id=egress_port_id
)

# Names look like "AMLIGHT_vlan_201_202_Ampath_Tenet". We
Expand Down Expand Up @@ -1161,6 +1162,8 @@ def _reserve_vlan(
for vlan_tag, vlan_usage in vlan_table.items():
if vlan_usage is UNUSED_VLAN:
available_tag = vlan_tag
elif tag == "untagged":
return tag
elif self._tag_is_vlan_range(tag):
# expand the range.
start, end = map(int, tag.split(":"))
Expand All @@ -1171,7 +1174,10 @@ def _reserve_vlan(
# Check if all VLANs in the range are available.
for vlan in vlans:
if vlan_table[vlan] is not UNUSED_VLAN:
raise Exception(f"VLAN {vlan} is in use; can't reserve {tag} range")
raise TEError(
f"VLAN {vlan} is in use; can't reserve {tag}",
409,
)

# Mark range in use.
for vlan in vlans:
Expand All @@ -1191,7 +1197,10 @@ def _reserve_vlan(
available_tag = tag
else:
self._logger.error(f"VLAN {tag} is in use by {vlan_table[tag]}")
return None
raise TEError(
f"VLAN {vlan} is in use; can't reserve {tag}",
409,
)
else:
self._logger.error(f"VLAN {tag} is not present in the table")
return None
Expand Down
4 changes: 2 additions & 2 deletions tests/test_te_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ def test_connection_amlight_to_zaoxi_user_port_any(self):
)

# Rewrite the request to have VLAN of "any".
connection_request["endpoints"][0]["vlan"] = "any"
connection_request["endpoints"][0]["vlan"] = "untagged"
connection_request["endpoints"][1]["vlan"] = "any"

print(f"connection_request: {connection_request}")
Expand Down Expand Up @@ -1459,7 +1459,7 @@ def test_connection_amlight_to_zaoxi_user_port_any(self):
self.assertIsInstance(segment.get("dynamic_backup_path"), bool)
self.assertIsInstance(segment.get("uni_a"), dict)
self.assertIsInstance(segment.get("uni_a").get("tag"), dict)
self.assertIsInstance(segment.get("uni_a").get("tag").get("value"), int)
# self.assertIsInstance(segment.get("uni_a").get("tag").get("value"), int)
self.assertIsInstance(segment.get("uni_a").get("tag").get("tag_type"), int)
self.assertIsInstance(segment.get("uni_a").get("port_id"), str)
self.assertIsInstance(segment.get("uni_z"), dict)
Expand Down

0 comments on commit d6b5f09

Please sign in to comment.