Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Multi-Port Network Namespaces #799

Merged
merged 10 commits into from
Nov 5, 2024
Merged

test: Multi-Port Network Namespaces #799

merged 10 commits into from
Nov 5, 2024

Conversation

wkz
Copy link
Contributor

@wkz wkz commented Nov 4, 2024

Description

  • Generalize the existing IsolatedMacVlan class to support creating namespaces with multiple ports
  • Provide a Two-Port MAC Relay (TPMR) as an example implementation, which by default just relays frames between two ports, but can dynamically be set to block frames from passing through it. This is useful to test fail-over behavior of various protocols
  • Add a test of BFD fail-over in combination with OSPF, using the new TPMR device

In order for the TPMR to act as a bridge, the mode of the MACVLANs has been changed to passthru, which allows it to receive all packets from its lower interface, and also lets it transmit unicast packets with any SA without triggering the kernel's spoof protection logic. This also enables us to use the parent interface's promiscuity value as an indicator for when a MACVLAN has been fully removed in the kernel, which should be more reliable than the old time.sleep(.5).

Close #261

Checklist

Tick relevant boxes, this PR is-a or has-a:

  • Bugfix
    • Regression tests
    • ChangeLog updates (for next release)
  • Feature
    • YANG model change => revision updated?
    • Regression tests added?
    • ChangeLog updates (for next release)
    • Documentation added?
  • Test changes
    • Checked in changed Readme.adoc (make test-spec)
    • Added new test to group Readme.adoc and yaml file
  • Code style update (formatting, renaming)
  • Refactoring (please detail in commit messages)
  • Build related changes
  • Documentation content changes
    • ChangeLog updated (for major changes)
  • Other (please describe):

Story time:

In the days of yore, we generated PCAPs using tcpdump, which will
flush any buffered packets to its output file on reception of
SIGUSR2. Therefore we sent a USR2 before terminating the capture.

At some point, we switched over to use tshark to capture packets for
us, but the SIGUSR2 sayed in place.

It turns out, tshark will just die on USR2, abandoning the dumpcap
child it has created, which means the enclosing network namespace
can't be properly torn down.

Therefore:

Remove skip sending USR2 and just send TERM directly.
This is needed to create namespaces with MACVLANs from different
parent interfaces. The first consumer will be a Two-Port Mac
Relay (TPMR), so that we can control the flow of packets between two
nodes.
This mode let's us receive all packets from the parent device, which
is automatically set in promiscuous mode, and let's the MACVLAN
transmit packets with any SA, which we need to implement a TPMR (or a
bridge or anything else we might dream up)
This gets rid of annoying "Address already in use" errors when running
tests repeatedly from a test-sh.
When used as a context manager, __exit__ will be called even though
__enter__ might throw an exception half way through. So there is no
guarantee that the instance is on the cleanup list when we get to
stop().
Now that we're using the `passthru` mode of MACVLANs, it seems we can
rely on the parent interface's promiscuity going down to 0 as an
indication that the kernel has completed the removal of the interface,
and will accept the creation of a new one.
This is a specialized namespace, containing two ports,
which (hopefully) acts as completely transparent "bump-on-the-wire"
bridge.

Useful in scenarios where you want to test what happens when the flow
of packets between two nodes is disrupted. E.g., for testing fail-over
behavior in dynamic routing protocols, L2 redundancy, VRRP etc.
Initially done as a workaround for the MACVLAN create/remove race. But
even though the old version of this test now works, this refactor
provides better test step descriptions, making it easier to follow for
anyone looking to manually verify the functionality.
@wkz wkz marked this pull request as ready for review November 4, 2024 15:46
Copy link
Contributor

@mattiaswal mattiaswal left a comment

Choose a reason for hiding this comment

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

Flawless as always 💯

Copy link
Contributor

@troglobit troglobit left a comment

Choose a reason for hiding this comment

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

Very nice, great to have a pure BFD test, finally. Only a minor comment.

test/infamy/netns.py Outdated Show resolved Hide resolved
@wkz wkz merged commit 3840ebc into main Nov 5, 2024
0 of 4 checks passed
@wkz wkz deleted the ospf-bfd branch November 5, 2024 14:46
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.

infamy: Add support for link breakers
3 participants