Skip to content

Commit

Permalink
Added take_last to EVC
Browse files Browse the repository at this point in the history
  • Loading branch information
Alopalao committed Nov 5, 2024
1 parent e3654fa commit abc5445
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class EVCBaseDoc(DocumentBaseModel):
metadata: Dict = {}
active: bool
enabled: bool
take_last: bool

@staticmethod
def projection() -> Dict:
Expand Down
9 changes: 6 additions & 3 deletions models/evc.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def __init__(self, controller, **kwargs):
self.backup_links_cache = set()
self.affected_by_link_at = get_time("0001-01-01T00:00:00")
self.old_path = Path([])
self.take_last = kwargs.get("take_last", False)

self.lock = Lock()

Expand Down Expand Up @@ -431,6 +432,7 @@ def as_dict(self, keys: set = None):
evc_dict["secondary_constraints"] = self.secondary_constraints
evc_dict["flow_removed_at"] = self.flow_removed_at
evc_dict["updated_at"] = self.updated_at
evc_dict["take_last"] = self.take_last

if keys:
selected = {}
Expand Down Expand Up @@ -847,7 +849,7 @@ def deploy_to_path(self, path=None):
tag_errors = []
if self.should_deploy(use_path):
try:
use_path.choose_vlans(self._controller)
use_path.choose_vlans(self._controller, self.take_last)
except KytosNoTagAvailableError as e:
tag_errors.append(str(e))
use_path = None
Expand All @@ -856,7 +858,7 @@ def deploy_to_path(self, path=None):
if use_path is None:
continue
try:
use_path.choose_vlans(self._controller)
use_path.choose_vlans(self._controller, self.take_last)
break
except KytosNoTagAvailableError as e:
tag_errors.append(str(e))
Expand Down Expand Up @@ -886,6 +888,7 @@ def deploy_to_path(self, path=None):
return False
self.activate()
self.current_path = use_path
self.take_last = not self.take_last
self.sync()
log.info(f"{self} was deployed.")
return True
Expand Down Expand Up @@ -932,7 +935,7 @@ def setup_failover_path(self):
if not use_path:
continue
try:
use_path.choose_vlans(self._controller)
use_path.choose_vlans(self._controller, not self.take_last)
break
except KytosNoTagAvailableError as e:
tag_errors.append(str(e))
Expand Down
6 changes: 4 additions & 2 deletions models/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ def link_affected_by_interface(self, interface=None):
return link
return None

def choose_vlans(self, controller):
def choose_vlans(self, controller, take_last):
"""Choose the VLANs to be used for the circuit."""
for link in self:
tag_value = link.get_next_available_tag(controller, link.id)
tag_value = link.get_next_available_tag(
controller, link.id, take_last=take_last
)
tag = TAG('vlan', tag_value)
link.add_metadata("s_vlan", tag)

Expand Down
4 changes: 4 additions & 0 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ components:
request_time:
type: string
format: date-time
take_last:
type: boolean

UpdateCircuit: # Can be referenced via '#/components/schemas/UpdateCircuit'
type: object
Expand Down Expand Up @@ -762,6 +764,8 @@ components:
type: object
enabled:
type: boolean
take_last:
type: boolean

Tag: # Can be referenced via '#/components/schemas/Tag'
type: object
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
# pip-compile --output-file requirements/dev.txt requirements/dev.in
#
-e git+https://github.com/kytos-ng/python-openflow.git#egg=python-openflow
-e git+https://github.com/kytos-ng/kytos.git#egg=kytos[dev]
-e git+https://github.com/kytos-ng/kytos.git@feature/last_tag#egg=kytos[dev]
-e .
3 changes: 2 additions & 1 deletion tests/unit/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def setup_method(self) -> None:
"priority": 100,
"active": False,
"enabled": True,
"circuit_scheduler": []
"circuit_scheduler": [],
"take_last": False,
}

def test_bootstrap_indexes(self):
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/test_db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def setup_method(self):
"active": False,
"enabled": False,
"circuit_scheduler": [],
"queue_id": None
"queue_id": None,
"take_last": False,
}
self.evc_update = {
"uni_a": {
Expand All @@ -55,7 +56,7 @@ def setup_method(self):
"sb_priority": 81,
"enabled": False,
"circuit_scheduler": [],
"queue_id": None
"queue_id": None,
}

def test_evcbasedoc(self):
Expand All @@ -71,6 +72,7 @@ def test_evcbasedoc(self):
assert not evc.active
assert not evc.enabled
assert not evc.circuit_scheduler
assert not evc.take_last

def test_evcupdatedoc(self):
"""Test EVCUpdateDoc model"""
Expand Down

0 comments on commit abc5445

Please sign in to comment.