SlideShare ist ein Scribd-Unternehmen logo
1 von 53
Downloaden Sie, um offline zu lesen
Spanning Tree
Protocol
Jason Myers / Emma / @jasonamyers
Spanning Tree
Protocol
Jason Myers / Emma / @jasonamyers
Spanning Tree
Protocol
Jason Myers / Emma / @jasonamyers
Radia Perlman
STP, Link State Protocols, TRILL

over 40 years on the same problem set!
Port States
• Disabled - administrator turned the port off
• Blocking - This port would cause a loop
• Listening - Trying to determine if it should block
• Learning - Adding source addresses to it’s CAM
• Forwarding - Moving the bits
def _state_machine(self):!
! role_str = {ROOT_PORT: 'ROOT_PORT ',!
DESIGNATED_PORT: 'DESIGNATED_PORT ',!
NON_DESIGNATED_PORT: 'NON_DESIGNATED_PORT'}!
state_str = {PORT_STATE_DISABLE: 'DISABLE',!
PORT_STATE_BLOCK: 'BLOCK',!
PORT_STATE_LISTEN: 'LISTEN',!
PORT_STATE_LEARN: 'LEARN',!
PORT_STATE_FORWARD: 'FORWARD'}!
!
if self.state is PORT_STATE_DISABLE:!
self.ofctl.set_port_status(self.ofport, self.state)!
!
while True:!
self.logger.info('[port=%d] %s / %s', self.ofport.port_no,!
role_str[self.role], state_str[self.state],!
extra=self.dpid_str)!
!
self.state_event = hub.Event()!
timer = self._get_timer()!
if timer:!
timeout = hub.Timeout(timer)!
try:!
self.state_event.wait()!
except hub.Timeout as t:!
if t is not timeout:!
err_msg = 'Internal error. Not my timeout.'!
raise RyuException(msg=err_msg)!
new_state = self._get_next_state()!
self._change_status(new_state, thread_switch=False)!
finally:!
timeout.cancel()!
else:!
self.state_event.wait()!
!
self.state_event = None!
def recalculate_spanning_tree(self, init=True):!
""" Re-calculation of spanning tree. """!
# All port down.!
for port in self.ports.values():!
if port.state is not PORT_STATE_DISABLE:!
port.down(PORT_STATE_BLOCK, msg_init=init)!
!
# Send topology change event.!
if init:!
self.send_event(EventTopologyChange(self.dp))!
!
# Update tree roles.!
port_roles = {}!
self.root_priority = Priority(self.bridge_id, 0, None, None)!
self.root_times = self.bridge_times!
!
if init:!
self.logger.info('Root bridge.', extra=self.dpid_str)!
for port_no in self.ports.keys():!
port_roles[port_no] = DESIGNATED_PORT!
else:!
(port_roles,!
self.root_priority,!
self.root_times) = self._spanning_tree_algorithm()!
!
# All port up.!
for port_no, role in port_roles.items():!
if self.ports[port_no].state is not PORT_STATE_DISABLE:!
self.ports[port_no].up(role, self.root_priority,!
self.root_times)!
A B
C
I am the root!
32768.00-00-00-00-00-01
I am the root!
32768.00-00-00-00-00-03
I am the root!
32768.00-00-00-00-00-02
def _spanning_tree_algorithm(self):!
port_roles = {}!
!
root_port = self._select_root_port()!
!
if root_port is None:!
# My bridge is a root bridge.!
self.logger.info('Root bridge.', extra=self.dpid_str)!
root_priority = self.root_priority!
root_times = self.root_times!
!
for port_no in self.ports.keys():!
if self.ports[port_no].state is not PORT_STATE_DISABLE:!
port_roles[port_no] = DESIGNATED_PORT
A B
C
I am the root!
32768.00-00-00-00-00-01
I am the root!
32768.00-00-00-00-00-03
I am the root!
32768.00-00-00-00-00-02
A B
C
I am the root!
32768.00-00-00-00-00-01
I am the root!
32768.00-00-00-00-00-03
I am the root!
32768.00-00-00-00-00-02
BPDU from C
A B
C
I am the root!
32768.00-00-00-00-00-01
I am the root!
32768.00-00-00-00-00-03
I am the root!
32768.00-00-00-00-00-02
BPDU from CBPDU from C
BPDU
• Protocol ID
• Version ID
• BPDU Type
• Flags
• Root ID
• Root Path Cost
• bridge id
• Port ID
• Message Age
• Max Age (20 Sec)
• Hello Time (2 Sec)
• Forward Delay (15 sec)
• version 1 Length
• version 3 Length
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is C
I am the root!
32768.00-00-00-00-00-02
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is C
I am the root!
32768.00-00-00-00-00-02
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is C
I am the root!
32768.00-00-00-00-00-02
BPDU from A
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is C
I am the root!
32768.00-00-00-00-00-02
BPDU from A
BPDU from A
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
def _select_root_port(self):!
root_port = None!
!
for port in self.ports.values():!
root_msg = (self.root_priority if root_port is None!
else root_port.designated_priority)!
port_msg = port.designated_priority!
if port.state is PORT_STATE_DISABLE or port_msg is None:!
continue!
if root_msg.root_id.value > port_msg.root_id.value:!
result = SUPERIOR!
elif root_msg.root_id.value == port_msg.root_id.value:!
if root_msg.designated_bridge_id is None:!
result = INFERIOR!
else:!
result = Stp.compare_root_path(!
port_msg.root_path_cost,!
root_msg.root_path_cost,!
port_msg.designated_bridge_id.value,!
root_msg.designated_bridge_id.value,!
port_msg.designated_port_id.value,!
root_msg.designated_port_id.value)!
else:!
result = INFERIOR!
!
if result is SUPERIOR:!
root_port = port!
!
return root_port!
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
else:!
# Other bridge is a root bridge.!
self.logger.info('Non root bridge.', extra=self.dpid_str)!
root_priority = root_port.designated_priority!
root_times = root_port.designated_times!
!
port_roles[root_port.ofport.port_no] = ROOT_PORT!
!
d_ports = self._select_designated_port(root_port)!
for port_no in d_ports:!
port_roles[port_no] = DESIGNATED_PORT!
!
for port in self.ports.values():!
if port.state is not PORT_STATE_DISABLE:!
port_roles.setdefault(port.ofport.port_no,!
NON_DESIGNATED_PORT)!
!
return port_roles, root_priority, root_times!
def _select_designated_port(self, root_port):!
d_ports = []!
root_msg = root_port.designated_priority!
!
for port in self.ports.values():!
port_msg = port.designated_priority!
if (port.state is PORT_STATE_DISABLE!
or port.ofport.port_no == root_port.ofport.port_no):!
continue!
if (port_msg is None or!
(port_msg.root_id.value != root_msg.root_id.value)):!
d_ports.append(port.ofport.port_no)!
else:!
result = Stp.compare_root_path(!
root_msg.root_path_cost,!
port_msg.root_path_cost - port.path_cost,!
self.bridge_id.value,!
port_msg.designated_bridge_id.value,!
port.port_id.value,!
port_msg.designated_port_id.value)!
if result is SUPERIOR:!
d_ports.append(port.ofport.port_no)!
!
return d_ports
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
Forwarding
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
ForwardingForwarding
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
ForwardingForwarding
Forwarding
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
ForwardingForwarding
Forwarding
Forwarding
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
ForwardingForwarding
Forwarding
Forwarding Forwarding
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
ForwardingForwarding
Forwarding
Forwarding Forwarding
Blocking
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
X
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
Forwarding
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
ForwardingForwarding
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
ForwardingForwarding
Forwarding
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
ForwardingForwarding
Forwarding Listening
def topology_change_notify(self, port_state):!
notice = False!
if port_state is PORT_STATE_FORWARD:!
for port in self.ports.values():!
if port.role is DESIGNATED_PORT:!
notice = True!
break!
else:!
notice = True!
!
if notice:!
self.send_event(EventTopologyChange(self.dp))!
if self.is_root_bridge:!
self._transmit_tc_bpdu()!
else:!
self._transmit_tcn_bpdu()!
!
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
Forwarding
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
ForwardingForwarding
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
ForwardingForwarding
Forwarding
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
ForwardingForwarding
Forwarding Learning
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
Forwarding
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
ForwardingForwarding
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
ForwardingForwarding
Forwarding
A B
C
I am the root!
32768.00-00-00-00-00-01
32768.00-00-00-00-00-03
Root is A
32768.00-00-00-00-00-02
Root is A
ForwardingForwarding
Forwarding Forwarding
Implementation
• Ryu - https://github.com/osrg/ryu/blob/master/
ryu/lib/stplib.py
• OpenStack Neutron
• Prim’s MST
I think that I shall never see
A graph as lovely as a tree.
A tree which must be sure to span.
So packets can reach every LAN.
First the root must be selected.
By ID, it is elected.
Least cost paths from Root are traced.
In the tree these paths are placed.
A mesh is made by folks like me.
Then bridges find a spanning tree.

Weitere ähnliche Inhalte

Ähnlich wie Spanning Tree Algorithm

Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34Shaikhul Islam Chowdhury
 
Os Capouchtutorial
Os CapouchtutorialOs Capouchtutorial
Os Capouchtutorialoscon2007
 
Metafuzz: Building Boring Fuzzers Faster, Using Metadata
Metafuzz: Building Boring Fuzzers Faster, Using MetadataMetafuzz: Building Boring Fuzzers Faster, Using Metadata
Metafuzz: Building Boring Fuzzers Faster, Using Metadataamiable_indian
 
How STP and RSTP Works
How STP and RSTP WorksHow STP and RSTP Works
How STP and RSTP WorksGary Jan
 
City School Network- Routing & Switching Final Report
City School Network- Routing & Switching Final ReportCity School Network- Routing & Switching Final Report
City School Network- Routing & Switching Final ReportShahzeb Pirzada
 
Михаил Епихин — Бутылочное горлышко. как найти узкие места сервиса и увеличит...
Михаил Епихин — Бутылочное горлышко. как найти узкие места сервиса и увеличит...Михаил Епихин — Бутылочное горлышко. как найти узкие места сервиса и увеличит...
Михаил Епихин — Бутылочное горлышко. как найти узкие места сервиса и увеличит...Yandex
 
Understanding stp-rstp-convergence
Understanding stp-rstp-convergenceUnderstanding stp-rstp-convergence
Understanding stp-rstp-convergenceHazhir Yadegari
 
DEF CON 27 - SMEA - adventures in smart buttplug penetration testing
DEF CON 27 - SMEA - adventures in smart buttplug penetration testingDEF CON 27 - SMEA - adventures in smart buttplug penetration testing
DEF CON 27 - SMEA - adventures in smart buttplug penetration testingFelipe Prado
 

Ähnlich wie Spanning Tree Algorithm (9)

Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34
 
Os Capouchtutorial
Os CapouchtutorialOs Capouchtutorial
Os Capouchtutorial
 
A Step Towards Data Orientation
A Step Towards Data OrientationA Step Towards Data Orientation
A Step Towards Data Orientation
 
Metafuzz: Building Boring Fuzzers Faster, Using Metadata
Metafuzz: Building Boring Fuzzers Faster, Using MetadataMetafuzz: Building Boring Fuzzers Faster, Using Metadata
Metafuzz: Building Boring Fuzzers Faster, Using Metadata
 
How STP and RSTP Works
How STP and RSTP WorksHow STP and RSTP Works
How STP and RSTP Works
 
City School Network- Routing & Switching Final Report
City School Network- Routing & Switching Final ReportCity School Network- Routing & Switching Final Report
City School Network- Routing & Switching Final Report
 
Михаил Епихин — Бутылочное горлышко. как найти узкие места сервиса и увеличит...
Михаил Епихин — Бутылочное горлышко. как найти узкие места сервиса и увеличит...Михаил Епихин — Бутылочное горлышко. как найти узкие места сервиса и увеличит...
Михаил Епихин — Бутылочное горлышко. как найти узкие места сервиса и увеличит...
 
Understanding stp-rstp-convergence
Understanding stp-rstp-convergenceUnderstanding stp-rstp-convergence
Understanding stp-rstp-convergence
 
DEF CON 27 - SMEA - adventures in smart buttplug penetration testing
DEF CON 27 - SMEA - adventures in smart buttplug penetration testingDEF CON 27 - SMEA - adventures in smart buttplug penetration testing
DEF CON 27 - SMEA - adventures in smart buttplug penetration testing
 

Mehr von Jason Myers

Filling the flask
Filling the flaskFilling the flask
Filling the flaskJason Myers
 
Building CLIs that Click
Building CLIs that ClickBuilding CLIs that Click
Building CLIs that ClickJason Myers
 
Introduction to Pandas
Introduction to PandasIntroduction to Pandas
Introduction to PandasJason Myers
 
Generating Power with Yield
Generating Power with YieldGenerating Power with Yield
Generating Power with YieldJason Myers
 
Introduction to SQLAlchemy and Alembic Migrations
Introduction to SQLAlchemy and Alembic MigrationsIntroduction to SQLAlchemy and Alembic Migrations
Introduction to SQLAlchemy and Alembic MigrationsJason Myers
 
Diabetes and Me: My Journey So Far
Diabetes and Me: My Journey So FarDiabetes and Me: My Journey So Far
Diabetes and Me: My Journey So FarJason Myers
 
Selenium testing
Selenium testingSelenium testing
Selenium testingJason Myers
 
Coderfaire Data Networking for Developers
Coderfaire Data Networking for DevelopersCoderfaire Data Networking for Developers
Coderfaire Data Networking for DevelopersJason Myers
 

Mehr von Jason Myers (8)

Filling the flask
Filling the flaskFilling the flask
Filling the flask
 
Building CLIs that Click
Building CLIs that ClickBuilding CLIs that Click
Building CLIs that Click
 
Introduction to Pandas
Introduction to PandasIntroduction to Pandas
Introduction to Pandas
 
Generating Power with Yield
Generating Power with YieldGenerating Power with Yield
Generating Power with Yield
 
Introduction to SQLAlchemy and Alembic Migrations
Introduction to SQLAlchemy and Alembic MigrationsIntroduction to SQLAlchemy and Alembic Migrations
Introduction to SQLAlchemy and Alembic Migrations
 
Diabetes and Me: My Journey So Far
Diabetes and Me: My Journey So FarDiabetes and Me: My Journey So Far
Diabetes and Me: My Journey So Far
 
Selenium testing
Selenium testingSelenium testing
Selenium testing
 
Coderfaire Data Networking for Developers
Coderfaire Data Networking for DevelopersCoderfaire Data Networking for Developers
Coderfaire Data Networking for Developers
 

KĂźrzlich hochgeladen

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

KĂźrzlich hochgeladen (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Spanning Tree Algorithm

  • 1. Spanning Tree Protocol Jason Myers / Emma / @jasonamyers
  • 2. Spanning Tree Protocol Jason Myers / Emma / @jasonamyers
  • 3. Spanning Tree Protocol Jason Myers / Emma / @jasonamyers
  • 4. Radia Perlman STP, Link State Protocols, TRILL
 over 40 years on the same problem set!
  • 5. Port States • Disabled - administrator turned the port off • Blocking - This port would cause a loop • Listening - Trying to determine if it should block • Learning - Adding source addresses to it’s CAM • Forwarding - Moving the bits
  • 6. def _state_machine(self):! ! role_str = {ROOT_PORT: 'ROOT_PORT ',! DESIGNATED_PORT: 'DESIGNATED_PORT ',! NON_DESIGNATED_PORT: 'NON_DESIGNATED_PORT'}! state_str = {PORT_STATE_DISABLE: 'DISABLE',! PORT_STATE_BLOCK: 'BLOCK',! PORT_STATE_LISTEN: 'LISTEN',! PORT_STATE_LEARN: 'LEARN',! PORT_STATE_FORWARD: 'FORWARD'}! ! if self.state is PORT_STATE_DISABLE:! self.ofctl.set_port_status(self.ofport, self.state)! ! while True:! self.logger.info('[port=%d] %s / %s', self.ofport.port_no,! role_str[self.role], state_str[self.state],! extra=self.dpid_str)! ! self.state_event = hub.Event()! timer = self._get_timer()! if timer:! timeout = hub.Timeout(timer)! try:! self.state_event.wait()! except hub.Timeout as t:! if t is not timeout:! err_msg = 'Internal error. Not my timeout.'! raise RyuException(msg=err_msg)! new_state = self._get_next_state()! self._change_status(new_state, thread_switch=False)! finally:! timeout.cancel()! else:! self.state_event.wait()! ! self.state_event = None!
  • 7. def recalculate_spanning_tree(self, init=True):! """ Re-calculation of spanning tree. """! # All port down.! for port in self.ports.values():! if port.state is not PORT_STATE_DISABLE:! port.down(PORT_STATE_BLOCK, msg_init=init)! ! # Send topology change event.! if init:! self.send_event(EventTopologyChange(self.dp))! ! # Update tree roles.! port_roles = {}! self.root_priority = Priority(self.bridge_id, 0, None, None)! self.root_times = self.bridge_times! ! if init:! self.logger.info('Root bridge.', extra=self.dpid_str)! for port_no in self.ports.keys():! port_roles[port_no] = DESIGNATED_PORT! else:! (port_roles,! self.root_priority,! self.root_times) = self._spanning_tree_algorithm()! ! # All port up.! for port_no, role in port_roles.items():! if self.ports[port_no].state is not PORT_STATE_DISABLE:! self.ports[port_no].up(role, self.root_priority,! self.root_times)!
  • 8. A B C I am the root! 32768.00-00-00-00-00-01 I am the root! 32768.00-00-00-00-00-03 I am the root! 32768.00-00-00-00-00-02
  • 9. def _spanning_tree_algorithm(self):! port_roles = {}! ! root_port = self._select_root_port()! ! if root_port is None:! # My bridge is a root bridge.! self.logger.info('Root bridge.', extra=self.dpid_str)! root_priority = self.root_priority! root_times = self.root_times! ! for port_no in self.ports.keys():! if self.ports[port_no].state is not PORT_STATE_DISABLE:! port_roles[port_no] = DESIGNATED_PORT
  • 10. A B C I am the root! 32768.00-00-00-00-00-01 I am the root! 32768.00-00-00-00-00-03 I am the root! 32768.00-00-00-00-00-02
  • 11. A B C I am the root! 32768.00-00-00-00-00-01 I am the root! 32768.00-00-00-00-00-03 I am the root! 32768.00-00-00-00-00-02 BPDU from C
  • 12. A B C I am the root! 32768.00-00-00-00-00-01 I am the root! 32768.00-00-00-00-00-03 I am the root! 32768.00-00-00-00-00-02 BPDU from CBPDU from C
  • 13. BPDU • Protocol ID • Version ID • BPDU Type • Flags • Root ID • Root Path Cost • bridge id • Port ID • Message Age • Max Age (20 Sec) • Hello Time (2 Sec) • Forward Delay (15 sec) • version 1 Length • version 3 Length
  • 14. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is C I am the root! 32768.00-00-00-00-00-02
  • 15. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is C I am the root! 32768.00-00-00-00-00-02
  • 16. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is C I am the root! 32768.00-00-00-00-00-02 BPDU from A
  • 17. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is C I am the root! 32768.00-00-00-00-00-02 BPDU from A BPDU from A
  • 18. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A
  • 19. def _select_root_port(self):! root_port = None! ! for port in self.ports.values():! root_msg = (self.root_priority if root_port is None! else root_port.designated_priority)! port_msg = port.designated_priority! if port.state is PORT_STATE_DISABLE or port_msg is None:! continue! if root_msg.root_id.value > port_msg.root_id.value:! result = SUPERIOR! elif root_msg.root_id.value == port_msg.root_id.value:! if root_msg.designated_bridge_id is None:! result = INFERIOR! else:! result = Stp.compare_root_path(! port_msg.root_path_cost,! root_msg.root_path_cost,! port_msg.designated_bridge_id.value,! root_msg.designated_bridge_id.value,! port_msg.designated_port_id.value,! root_msg.designated_port_id.value)! else:! result = INFERIOR! ! if result is SUPERIOR:! root_port = port! ! return root_port!
  • 20. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A
  • 21. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A
  • 22. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A
  • 23. else:! # Other bridge is a root bridge.! self.logger.info('Non root bridge.', extra=self.dpid_str)! root_priority = root_port.designated_priority! root_times = root_port.designated_times! ! port_roles[root_port.ofport.port_no] = ROOT_PORT! ! d_ports = self._select_designated_port(root_port)! for port_no in d_ports:! port_roles[port_no] = DESIGNATED_PORT! ! for port in self.ports.values():! if port.state is not PORT_STATE_DISABLE:! port_roles.setdefault(port.ofport.port_no,! NON_DESIGNATED_PORT)! ! return port_roles, root_priority, root_times!
  • 24. def _select_designated_port(self, root_port):! d_ports = []! root_msg = root_port.designated_priority! ! for port in self.ports.values():! port_msg = port.designated_priority! if (port.state is PORT_STATE_DISABLE! or port.ofport.port_no == root_port.ofport.port_no):! continue! if (port_msg is None or! (port_msg.root_id.value != root_msg.root_id.value)):! d_ports.append(port.ofport.port_no)! else:! result = Stp.compare_root_path(! root_msg.root_path_cost,! port_msg.root_path_cost - port.path_cost,! self.bridge_id.value,! port_msg.designated_bridge_id.value,! port.port_id.value,! port_msg.designated_port_id.value)! if result is SUPERIOR:! d_ports.append(port.ofport.port_no)! ! return d_ports
  • 25. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A
  • 26. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A
  • 27. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A
  • 28. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A
  • 29. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A Forwarding
  • 30. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A ForwardingForwarding
  • 31. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A ForwardingForwarding Forwarding
  • 32. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A ForwardingForwarding Forwarding Forwarding
  • 33. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A ForwardingForwarding Forwarding Forwarding Forwarding
  • 34. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A ForwardingForwarding Forwarding Forwarding Forwarding Blocking
  • 35. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A X
  • 36. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A
  • 37. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A Forwarding
  • 38. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A ForwardingForwarding
  • 39. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A ForwardingForwarding Forwarding
  • 40. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A ForwardingForwarding Forwarding Listening
  • 41. def topology_change_notify(self, port_state):! notice = False! if port_state is PORT_STATE_FORWARD:! for port in self.ports.values():! if port.role is DESIGNATED_PORT:! notice = True! break! else:! notice = True! ! if notice:! self.send_event(EventTopologyChange(self.dp))! if self.is_root_bridge:! self._transmit_tc_bpdu()! else:! self._transmit_tcn_bpdu()! !
  • 42. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A
  • 43. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A Forwarding
  • 44. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A ForwardingForwarding
  • 45. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A ForwardingForwarding Forwarding
  • 46. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A ForwardingForwarding Forwarding Learning
  • 47. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A
  • 48. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A Forwarding
  • 49. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A ForwardingForwarding
  • 50. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A ForwardingForwarding Forwarding
  • 51. A B C I am the root! 32768.00-00-00-00-00-01 32768.00-00-00-00-00-03 Root is A 32768.00-00-00-00-00-02 Root is A ForwardingForwarding Forwarding Forwarding
  • 52. Implementation • Ryu - https://github.com/osrg/ryu/blob/master/ ryu/lib/stplib.py • OpenStack Neutron • Prim’s MST
  • 53. I think that I shall never see A graph as lovely as a tree. A tree which must be sure to span. So packets can reach every LAN. First the root must be selected. By ID, it is elected. Least cost paths from Root are traced. In the tree these paths are placed. A mesh is made by folks like me. Then bridges find a spanning tree.