Skip to content

Updating switch when interface is created#291

Open
Alopalao wants to merge 1 commit intomasterfrom
fix/new_interface
Open

Updating switch when interface is created#291
Alopalao wants to merge 1 commit intomasterfrom
fix/new_interface

Conversation

@Alopalao
Copy link
Copy Markdown

@Alopalao Alopalao commented Mar 25, 2026

Closes #290

Summary

Fixed updating switch interfaces in the database when an interface is added while Kytos is running.
Only added updated after OFPPR_ADD which comes only from of_core

Local Tests

Created new interface on Mininet with this commands:

py net.addLink(s1, s3, port1=9, port2=9)
py s3.attach('s3-eth9')
py s1.attach('s1-eth9')

End-to-End Tests

This PR has a new related test and the results when running.

+ python3 -m pytest tests/ --reruns 2 -r fEr
============================= test session starts ==============================
platform linux -- Python 3.11.2, pytest-8.4.2, pluggy-1.6.0
rootdir: /builds/amlight/kytos-end-to-end-tester/kytos-end-to-end-tests
configfile: pytest.ini
plugins: asyncio-1.1.0, rerunfailures-13.0, timeout-2.2.0, anyio-4.3.0
asyncio: mode=Mode.AUTO, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 302 items
tests/test_e2e_01_kytos_startup.py ..                                    [  0%]
tests/test_e2e_05_topology.py ...................                        [  6%]
tests/test_e2e_06_topology.py .....                                      [  8%]
tests/test_e2e_10_mef_eline.py ..........ss.....x....................... [ 22%]
.                                                                        [ 22%]
tests/test_e2e_11_mef_eline.py ........                                  [ 25%]
tests/test_e2e_12_mef_eline.py .....Xx.                                  [ 27%]
tests/test_e2e_13_mef_eline.py ....Xs.s.....Xs.s.XXxX.xxxx..X........... [ 41%]
.                                                                        [ 41%]
tests/test_e2e_14_mef_eline.py ......                                    [ 43%]
tests/test_e2e_15_mef_eline.py ......                                    [ 45%]
tests/test_e2e_16_mef_eline.py ..                                        [ 46%]
tests/test_e2e_17_mef_eline.py .....                                     [ 48%]
tests/test_e2e_18_mef_eline.py .....                                     [ 49%]
tests/test_e2e_20_flow_manager.py ............................           [ 58%]
tests/test_e2e_21_flow_manager.py ...                                    [ 59%]
tests/test_e2e_22_flow_manager.py ...............                        [ 64%]
tests/test_e2e_23_flow_manager.py ..............                         [ 69%]
tests/test_e2e_30_of_lldp.py ....                                        [ 70%]
tests/test_e2e_31_of_lldp.py ....                                        [ 72%]
tests/test_e2e_32_of_lldp.py ...                                         [ 73%]
tests/test_e2e_40_sdntrace.py ................                           [ 78%]
tests/test_e2e_41_kytos_auth.py ........                                 [ 81%]
tests/test_e2e_42_sdntrace.py ..                                         [ 81%]
tests/test_e2e_50_maintenance.py ...............................         [ 92%]
tests/test_e2e_60_of_multi_table.py .....                                [ 93%]
tests/test_e2e_70_kytos_stats.py .........                               [ 96%]
tests/test_e2e_80_pathfinder.py ss......                                 [ 99%]
tests/test_e2e_90_kafka_events.py .                                      [ 99%]
tests/test_e2e_95_telemtry_int.py s                                      [100%]

self.handle_interface_link_up(interface, event)

@listen_to('.*.topology.switch.interface.created')
@listen_to('.*.switch.interface.created')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Alopalao can you please double check possible overload when multiple switches connect at the same time and each switch having 30 or so interfaces. Wont this overload the database?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You are right this could be improve. I will be looking to implement some sort of pacer so only the last switch upsert call is executed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Indeed only subscribing to .*.switch.interfaces.created was meant to minimize dozens of extra DB writes. So, the key to simplify for us here while not increasing too much extra DB writes is to only publish 'kytos/of_core.switch.interface.created' on of_core on port status OFPPR_ADD after this statement, and then on topology we also handle here as @Alopalao implemented.

Can you double check this approach @Alopalao? Good catch @italovalcy

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Created a draft PR with that approach. I have tested it and it seems to be working fine. I am going to wait for the end-to-end results.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Alopalao, great. Just realized that update_port_status(port_status, soruce) was already sending kytos/of_core.switch.interface.created when handling OFPPR_ADD. Check out if we also need to augment an unit explicit unit test to be extra safe too. Other than that, it's looking great to me if you also locally tested adding an interface after a switch handshake

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I tested locally with changes in of_core and found no issues.

Copy link
Copy Markdown
Member

@viniarck viniarck left a comment

Choose a reason for hiding this comment

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

Well done @Alopalao, looks good to me. Left one minor comment to be refactored, check it out, and suggested a change for a future related PR on 2026.1 after David's PRs land.

created event again and it can be belong to a link.
"""
interface = event.content['interface']
if "of_core" in event.name:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Alopalao, can you refactor this if to compare the event name completely? "kytos/of_core.switch.interface.created", that will improve readability and easier for us to remember/understand why we did it without having to navigate in a lot of git history. Plus a comment in the docstring explaining it's for handling interface creation from a OFPPR_ADD that'd be great too. Wdyt?

- ``.*.switch.(new|reconnected)``
- ``.*.connection.lost``
- ``.*.switch.interface.created``
- ``.*.switch.interfaces.created``
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good catch. Thanks for improving this event subscription doc.

created event again and it can be belong to a link.
"""
interface = event.content['interface']
if "of_core" in event.name:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This if and its statements are susceptible to events out of order if OFPPR_ADD from more than one ports get sent shortly after and get preempted, it won't result in any major issue, but it will waste extra DB writes reinserting the same switch, but since this is expected to be only a few extra writes if any in most cases, and in production usage a switch won't keep creating interfaces constantly than it's acceptable as it is.

Plus, please, map a new issue on 2026.1 to improve this and assign yourself, including when handling '.*.switch.interfaces.created it needs a switch lock and keeping track of when it was last inserted at, and if out of order you skip the write. But let's only tackle this minor enhancement after @Ktmi changes since he's refactoring some locks, so this will minimize conflicts. OK?

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.

New interfaces created after switch connected are not saved to MongoDB

3 participants