162306a36Sopenharmony_ciMotivation
262306a36Sopenharmony_ci==========
362306a36Sopenharmony_ci
462306a36Sopenharmony_ciOne of the nice things about network namespaces is that they allow one
562306a36Sopenharmony_cito easily create and test complex environments.
662306a36Sopenharmony_ci
762306a36Sopenharmony_ciUnfortunately, these namespaces can not be used with actual switching
862306a36Sopenharmony_ciASICs, as their ports can not be migrated to other network namespaces
962306a36Sopenharmony_ci(NETIF_F_NETNS_LOCAL) and most of them probably do not support the
1062306a36Sopenharmony_ciL1-separation provided by namespaces.
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ciHowever, a similar kind of flexibility can be achieved by using VRFs and
1362306a36Sopenharmony_ciby looping the switch ports together. For example:
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci                             br0
1662306a36Sopenharmony_ci                              +
1762306a36Sopenharmony_ci               vrf-h1         |           vrf-h2
1862306a36Sopenharmony_ci                 +        +---+----+        +
1962306a36Sopenharmony_ci                 |        |        |        |
2062306a36Sopenharmony_ci    192.0.2.1/24 +        +        +        + 192.0.2.2/24
2162306a36Sopenharmony_ci               swp1     swp2     swp3     swp4
2262306a36Sopenharmony_ci                 +        +        +        +
2362306a36Sopenharmony_ci                 |        |        |        |
2462306a36Sopenharmony_ci                 +--------+        +--------+
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ciThe VRFs act as lightweight namespaces representing hosts connected to
2762306a36Sopenharmony_cithe switch.
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ciThis approach for testing switch ASICs has several advantages over the
3062306a36Sopenharmony_citraditional method that requires multiple physical machines, to name a
3162306a36Sopenharmony_cifew:
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci1. Only the device under test (DUT) is being tested without noise from
3462306a36Sopenharmony_ciother system.
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci2. Ability to easily provision complex topologies. Testing bridging
3762306a36Sopenharmony_cibetween 4-ports LAGs or 8-way ECMP requires many physical links that are
3862306a36Sopenharmony_cinot always available. With the VRF-based approach one merely needs to
3962306a36Sopenharmony_ciloopback more ports.
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ciThese tests are written with switch ASICs in mind, but they can be run
4262306a36Sopenharmony_cion any Linux box using veth pairs to emulate physical loopbacks.
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ciGuidelines for Writing Tests
4562306a36Sopenharmony_ci============================
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_cio Where possible, reuse an existing topology for different tests instead
4862306a36Sopenharmony_ci  of recreating the same topology.
4962306a36Sopenharmony_cio Tests that use anything but the most trivial topologies should include
5062306a36Sopenharmony_ci  an ASCII art showing the topology.
5162306a36Sopenharmony_cio Where possible, IPv6 and IPv4 addresses shall conform to RFC 3849 and
5262306a36Sopenharmony_ci  RFC 5737, respectively.
5362306a36Sopenharmony_cio Where possible, tests shall be written so that they can be reused by
5462306a36Sopenharmony_ci  multiple topologies and added to lib.sh.
5562306a36Sopenharmony_cio Checks shall be added to lib.sh for any external dependencies.
5662306a36Sopenharmony_cio Code shall be checked using ShellCheck [1] prior to submission.
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci1. https://www.shellcheck.net/
59