Skip to content

Commit

Permalink
device: improve LACP start ID
Browse files Browse the repository at this point in the history
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
  • Loading branch information
Noltari committed Aug 14, 2022
1 parent 8980444 commit ab265c2
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions aioqsw/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,10 @@ def get_tx_speed(self) -> int | None:
"""Get port TX speed."""
return self.tx_speed

def set_id(self, _id: int) -> None:
"""Set port ID."""
self.id = _id


class PortsStatistics:
"""Ports Statistics."""
Expand All @@ -613,13 +617,26 @@ def __init__(
if not res:
raise APIError

lacp_id_min = None
lacp_ports: dict[int, PortStatistics] = {}
for port in res:
port_stats = PortStatistics(port)
if port_stats and (port_id := port_stats.get_id()):
if lacp_start is None or port_id < lacp_start:
self.ports[port_id] = port_stats
else:
self.lacp_ports[port_id] = port_stats
lacp_ports[port_id] = port_stats
if lacp_id_min is None or port_id < lacp_id_min:
lacp_id_min = port_id

if lacp_id_min is not None:
lacp_id_min -= 1
for port in lacp_ports.values():
port_id = port.get_id()
if port_id is not None:
port_id -= lacp_id_min
port.set_id(port_id)
self.lacp_ports[port_id] = port

@staticmethod
def calc_speed(
Expand Down Expand Up @@ -889,6 +906,10 @@ def get_speed(self) -> int | None:
"""Get port speed."""
return self.speed

def set_id(self, _id: int) -> None:
"""Set port ID."""
self.id = _id


class PortsStatus:
"""Ports Status."""
Expand All @@ -903,13 +924,26 @@ def __init__(self, ports_status: dict[str, Any], lacp_start: int | None):
if not res:
raise APIError

lacp_id_min = None
lacp_ports: dict[int, PortStatus] = {}
for port in res:
port_status = PortStatus(port)
if port_status and (port_id := port_status.get_id()):
if lacp_start is None or port_id < lacp_start:
self.ports[port_id] = port_status
else:
self.lacp_ports[port_id] = port_status
lacp_ports[port_id] = port_status
if lacp_id_min is None or port_id < lacp_id_min:
lacp_id_min = port_id

if lacp_id_min is not None:
lacp_id_min -= 1
for port in lacp_ports.values():
port_id = port.get_id()
if port_id is not None:
port_id -= lacp_id_min
port.set_id(port_id)
self.lacp_ports[port_id] = port

def calc(self) -> None:
"""Calculate Ports Status data."""
Expand Down

0 comments on commit ab265c2

Please sign in to comment.