Skip to content

Conversation

@RamProsad2
Copy link
Collaborator

@RamProsad2 RamProsad2 commented Dec 13, 2025

MSTP is working on VLANs

  1. VID-to-FID table
FID 0: 2-4094
FID 10: 1
FID 20: 1
  • This means VLAN 10 and VLAN 20 are mapped to FID 1.
  • FID 1 is managed by MSTI 1, a separate spanning tree instance.
  • All other VLANs (2–4094 except 10 and 20) are in FID 0 → default MSTP instance (CIST).
  1. FID-to-MSTID table
MSTID 0: 0,2-4095
MSTID 1: 1
  • FID 1 → MSTI 1 → MSTP will manage VLANs in FID 1 independently of the default spanning tree.

Why this proves MSTP works on VLANs

  • MSTP knows which VLANs belong to which spanning tree.
  • By mapping VLANs to FIDs and MSTIs, MSTP will control loop prevention and port blocking/forwarding separately for those VLANs.
  • Even though you only have one bridge now, this setup confirms MSTP is configured to work on VLANs.

sudo mstpctl showvid2fid br-test → VLAN → FID mapping.
sudo mstpctl showfid2mstid br-test → FID → MSTI mapping.
“VLANs 10 and 20 are mapped to FID 1, which is managed by MSTI 1. MSTP will manage these VLANs independently of the default spanning tree.”

Comment on lines 1 to 9
"""
MSTP (Multiple Spanning Tree Protocol) configuration utilities.
MSTP allows mapping multiple VLANs to different spanning tree instances,
providing load balancing and redundancy for VLAN traffic.
For MSTP we use Linux bridge with mstpd instead of OVS,
because OVS doesn't support true MSTP with multiple spanning tree instances.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мне кажется это можно убрать

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes



def setup_mstp(net: IPNet, nodes: list[Node]) -> None:
"""Configure MSTP on switches that have stp=3.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тоже можно сократить, слишком комментариев много, они не помогают лучше разобраться

configure_mstp_bridge(switch, node)


def configure_mstp_bridge(switch, node: Node) -> None:
Copy link
Contributor

@d-zaytsev d-zaytsev Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Аннотацию для параметра switch надо добавить. Вообще прогони PR через mypy

Comment on lines 123 to 125
# Ensure priority is in valid range 0-15
prio = min(15, max(0, priority))
switch.cmd(f"mstpctl settreeprio {bridge_name} {instance_id} " f"{prio}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А точно нужно priority подгонять под правильное значение? Может лучше если оно выходит за рамки бросать ошибку

Copy link
Collaborator Author

@RamProsad2 RamProsad2 Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“I intentionally kept the MST priority clamping in the code. If a user sets a value outside the valid range (0–15), the code automatically clamps it to the nearest valid value.
This ensures the network topology always comes up and avoids runtime errors from misconfigured priorities.
I added a warning to inform users when clamping occurs, so it’s visible and debuggable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures the network topology always comes up and avoids runtime errors from misconfigured priorities

А эти свойства пользователь задаёт или кто? Просто если пользователь, то он наверное ожидает, что будет такое свойство, как он написал, либо ошибка.

И ещё... чья это цитата?

Comment on lines 21 to 36
@dataclass
class MstInstance:
"""
Represents an MST (Multiple Spanning Tree) instance configuration.
Attributes:
instance_id (int): MST instance ID (0-64).
vlans (list[int]): List of VLAN IDs mapped to this instance.
priority (Optional[int]): Bridge priority for this MST instance.
"""

instance_id: int
vlans: list[int]
priority: Optional[int] = None


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ты уверен что этот класс необходим? И если необходим, то он точно нужен именно в этом файле?

Просто в этом файле определены глобальные абстракции типо вершины, ребра, задачи. В нём нет ничего связанного с конкретными протоколами

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А за что эти три файла удалены были?

result = switch.cmd("which mstpctl 2>/dev/null || echo 'not found'")

if "not found" in result:
print(f"Warning: mstpctl not found, using STP fallback for " f"{switch.name}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print не нужен наверное тут

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants