Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added vlan_range support #396

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
000ddb7
Modified get_vlan_tags_and_masks to support list of ranges
Alopalao Oct 20, 2023
9132610
Updated get_vlan_tags_and_masks and test
Alopalao Oct 23, 2023
b1f3afb
Fixed lint
Alopalao Oct 23, 2023
812177a
feat: add set_vlan only if in_vlan_a != in_vlan_z when pushing UNI flow
viniarck Oct 31, 2023
110d91e
tests: covered with unit test accordingly
viniarck Oct 31, 2023
8b0d694
docs: updated CHANGELOG.rst
viniarck Oct 31, 2023
4325eb0
feat: added scripts/redeploy_evpls_same_vlans.py
viniarck Nov 1, 2023
5c41728
docs: updated scripts/README.md with redeploy_evpls_same_vlans.py
viniarck Nov 1, 2023
35bc81d
docs: updated CHANGELOG.rst
viniarck Nov 1, 2023
f150a79
docs: fixed typos
viniarck Nov 1, 2023
4f04069
docs: augmented scripts/README.md
viniarck Nov 3, 2023
6d53522
docs: added extra phrase on scripts/README.md
viniarck Nov 3, 2023
f88fb44
Added vlan_range support
Alopalao Nov 6, 2023
4cd70e2
Fixed trace
Alopalao Nov 9, 2023
8f8bae4
Updated exceptions
Alopalao Nov 9, 2023
84ca0c0
Added unit tests
Alopalao Nov 13, 2023
2c7b49c
Added `RANGE_SB_PRIORITY`
Alopalao Nov 14, 2023
8ef5dda
Merge branch 'fix/handle_switch_changes' into epic/vlan_range
Alopalao Nov 16, 2023
9531831
Merge branch 'epic/vlan_range' of https://github.com/kytos-ng/mef_eli…
Alopalao Nov 16, 2023
1086884
Using `_is_duplicated_evc()` when updating
Alopalao Nov 17, 2023
a294896
Bypassed tag checking
Alopalao Nov 17, 2023
b4b2cb4
Merge branch 'fix/handle_switch_changes' into epic/vlan_range
Alopalao Nov 20, 2023
7052f3b
Updated arguments Interface tag functions
Alopalao Nov 20, 2023
7dde156
Added vlan_range support
Alopalao Nov 6, 2023
2e6f94e
Fixed trace
Alopalao Nov 9, 2023
8d45230
Updated exceptions
Alopalao Nov 9, 2023
6e71454
Added unit tests
Alopalao Nov 13, 2023
f8ac14d
Added `RANGE_SB_PRIORITY`
Alopalao Nov 14, 2023
dcd59b0
Using `_is_duplicated_evc()` when updating
Alopalao Nov 17, 2023
f95145e
Bypassed tag checking
Alopalao Nov 17, 2023
3c02043
Updated arguments Interface tag functions
Alopalao Nov 20, 2023
f9e0143
Merge branch 'epic/vlan_range' of https://github.com/kytos-ng/mef_eli…
Alopalao Nov 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Added
- Added a UI button for redeploying an EVC.
- UNI tag_type are now accepted as string.
- EVCs now listen to ``switch.interface.(link_up|link_down|created|deleted)`` events for activation/deactivation
- Circuits with a vlan range are supported now. The ranges follows ``list[list[int]]`` format and both UNIs vlan should have the same ranges.
viniarck marked this conversation as resolved.
Show resolved Hide resolved

Changed
=======
Expand Down
5 changes: 4 additions & 1 deletion db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ class CircuitScheduleDoc(BaseModel):
class TAGDoc(BaseModel):
"""TAG model"""
tag_type: str
value: Union[int, str]
value: Union[int, str, list[list[int]]]
mask_list: Optional[list[str, int]]

@validator('value')
def validate_value(cls, value):
"""Validate value when is a string"""
if isinstance(value, list):
return value
if isinstance(value, int):
return value
if isinstance(value, str) and value in ("any", "untagged"):
Expand Down
51 changes: 36 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@

from kytos.core import KytosNApp, log, rest
from kytos.core.events import KytosEvent
from kytos.core.exceptions import KytosTagError
from kytos.core.helpers import (alisten_to, listen_to, load_spec,
validate_openapi)
from kytos.core.interface import TAG, UNI
from kytos.core.interface import TAG, UNI, TAGRange
from kytos.core.link import Link
from kytos.core.rest_api import (HTTPException, JSONResponse, Request,
get_json_or_400)
from kytos.core.tag_ranges import get_tag_ranges
from napps.kytos.mef_eline import controllers, settings
from napps.kytos.mef_eline.exceptions import DisabledSwitch, InvalidPath
from napps.kytos.mef_eline.models import (EVC, DynamicPathManager, EVCDeploy,
Path)
from napps.kytos.mef_eline.scheduler import CircuitSchedule, Scheduler
from napps.kytos.mef_eline.utils import (aemit_event, check_disabled_component,
emit_event, map_evc_event_content)
emit_event, get_vlan_tags_and_masks,
map_evc_event_content)


# pylint: disable=too-many-public-methods
Expand Down Expand Up @@ -199,6 +202,7 @@ def get_circuit(self, request: Request) -> JSONResponse:
log.debug("get_circuit result %s %s", circuit, status)
return JSONResponse(circuit, status_code=status)

# pylint: disable=too-many-branches, too-many-statements
@rest("/v2/evc/", methods=["POST"])
@validate_openapi(spec)
def create_circuit(self, request: Request) -> JSONResponse:
Expand Down Expand Up @@ -234,7 +238,9 @@ def create_circuit(self, request: Request) -> JSONResponse:
except ValueError as exception:
log.debug("create_circuit result %s %s", exception, 400)
raise HTTPException(400, detail=str(exception)) from exception

except KytosTagError as exception:
log.debug("create_circuit result %s %s", exception, 400)
raise HTTPException(400, detail=str(exception)) from exception
try:
check_disabled_component(evc.uni_a, evc.uni_z)
except DisabledSwitch as exception:
Expand Down Expand Up @@ -269,20 +275,23 @@ def create_circuit(self, request: Request) -> JSONResponse:
detail=f"backup_path is not valid: {exception}"
) from exception

# verify duplicated evc
if self._is_duplicated_evc(evc):
result = "The EVC already exists."
log.debug("create_circuit result %s %s", result, 409)
raise HTTPException(409, detail=result)

if not evc._tag_lists_equal():
detail = "UNI_A and UNI_Z tag lists should be the same."
raise HTTPException(400, detail=detail)

try:
evc._validate_has_primary_or_dynamic()
except ValueError as exception:
raise HTTPException(400, detail=str(exception)) from exception

try:
self._use_uni_tags(evc)
except ValueError as exception:
except KytosTagError as exception:
raise HTTPException(400, detail=str(exception)) from exception

# save circuit
Expand Down Expand Up @@ -313,14 +322,11 @@ def create_circuit(self, request: Request) -> JSONResponse:
@staticmethod
def _use_uni_tags(evc):
uni_a = evc.uni_a
try:
evc._use_uni_vlan(uni_a)
except ValueError as err:
raise err
evc._use_uni_vlan(uni_a)
try:
uni_z = evc.uni_z
evc._use_uni_vlan(uni_z)
except ValueError as err:
except KytosTagError as err:
evc.make_uni_vlan_available(uni_a)
raise err

Expand Down Expand Up @@ -364,10 +370,11 @@ def update(self, request: Request) -> JSONResponse:
enable, redeploy = evc.update(
**self._evc_dict_with_instances(data)
)
except KytosTagError as exception:
raise HTTPException(400, detail=str(exception)) from exception
except ValidationError as exception:
raise HTTPException(400, detail=str(exception)) from exception
except ValueError as exception:
log.error(exception)
log.debug("update result %s %s", exception, 400)
raise HTTPException(400, detail=str(exception)) from exception
except DisabledSwitch as exception:
Expand All @@ -377,6 +384,11 @@ def update(self, request: Request) -> JSONResponse:
detail=f"Path is not valid: {exception}"
) from exception

if self._is_duplicated_evc(evc):
result = "The EVC already exists."
log.debug("create_circuit result %s %s", result, 409)
raise HTTPException(409, detail=result)

if evc.is_active():
if enable is False: # disable if active
with evc.lock:
Expand Down Expand Up @@ -716,7 +728,8 @@ def _is_duplicated_evc(self, evc):

"""
for circuit in tuple(self.circuits.values()):
if not circuit.archived and circuit.shares_uni(evc):
if (not circuit.archived and circuit._id != evc._id
and circuit.shares_uni(evc)):
return True
return False

Expand Down Expand Up @@ -911,7 +924,11 @@ def _load_evc(self, circuit_dict):
f"Could not load EVC: dict={circuit_dict} error={exception}"
)
return None

except KytosTagError as exception:
viniarck marked this conversation as resolved.
Show resolved Hide resolved
log.error(
f"Could not load EVC: dict={circuit_dict} error={exception}"
)
return None
if evc.archived:
return None

Expand Down Expand Up @@ -1001,11 +1018,15 @@ def _uni_from_dict(self, uni_dict):
tag_type = tag_dict.get("tag_type")
tag_type = tag_convert.get(tag_type, tag_type)
tag_value = tag_dict.get("value")
tag = TAG(tag_type, tag_value)
if isinstance(tag_value, list):
tag_value = get_tag_ranges(tag_value)
mask_list = get_vlan_tags_and_masks(tag_value)
tag = TAGRange(tag_type, tag_value, mask_list)
else:
tag = TAG(tag_type, tag_value)
else:
tag = None
uni = UNI(interface, tag)

return uni

def _link_from_dict(self, link_dict):
Expand Down
Loading