18c2ecf20Sopenharmony_ciMotivation 28c2ecf20Sopenharmony_ci========== 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ciOne of the nice things about network namespaces is that they allow one 58c2ecf20Sopenharmony_cito easily create and test complex environments. 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ciUnfortunately, these namespaces can not be used with actual switching 88c2ecf20Sopenharmony_ciASICs, as their ports can not be migrated to other network namespaces 98c2ecf20Sopenharmony_ci(NETIF_F_NETNS_LOCAL) and most of them probably do not support the 108c2ecf20Sopenharmony_ciL1-separation provided by namespaces. 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ciHowever, a similar kind of flexibility can be achieved by using VRFs and 138c2ecf20Sopenharmony_ciby looping the switch ports together. For example: 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci br0 168c2ecf20Sopenharmony_ci + 178c2ecf20Sopenharmony_ci vrf-h1 | vrf-h2 188c2ecf20Sopenharmony_ci + +---+----+ + 198c2ecf20Sopenharmony_ci | | | | 208c2ecf20Sopenharmony_ci 192.0.2.1/24 + + + + 192.0.2.2/24 218c2ecf20Sopenharmony_ci swp1 swp2 swp3 swp4 228c2ecf20Sopenharmony_ci + + + + 238c2ecf20Sopenharmony_ci | | | | 248c2ecf20Sopenharmony_ci +--------+ +--------+ 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ciThe VRFs act as lightweight namespaces representing hosts connected to 278c2ecf20Sopenharmony_cithe switch. 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ciThis approach for testing switch ASICs has several advantages over the 308c2ecf20Sopenharmony_citraditional method that requires multiple physical machines, to name a 318c2ecf20Sopenharmony_cifew: 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci1. Only the device under test (DUT) is being tested without noise from 348c2ecf20Sopenharmony_ciother system. 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci2. Ability to easily provision complex topologies. Testing bridging 378c2ecf20Sopenharmony_cibetween 4-ports LAGs or 8-way ECMP requires many physical links that are 388c2ecf20Sopenharmony_cinot always available. With the VRF-based approach one merely needs to 398c2ecf20Sopenharmony_ciloopback more ports. 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ciThese tests are written with switch ASICs in mind, but they can be run 428c2ecf20Sopenharmony_cion any Linux box using veth pairs to emulate physical loopbacks. 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ciGuidelines for Writing Tests 458c2ecf20Sopenharmony_ci============================ 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cio Where possible, reuse an existing topology for different tests instead 488c2ecf20Sopenharmony_ci of recreating the same topology. 498c2ecf20Sopenharmony_cio Tests that use anything but the most trivial topologies should include 508c2ecf20Sopenharmony_ci an ASCII art showing the topology. 518c2ecf20Sopenharmony_cio Where possible, IPv6 and IPv4 addresses shall conform to RFC 3849 and 528c2ecf20Sopenharmony_ci RFC 5737, respectively. 538c2ecf20Sopenharmony_cio Where possible, tests shall be written so that they can be reused by 548c2ecf20Sopenharmony_ci multiple topologies and added to lib.sh. 558c2ecf20Sopenharmony_cio Checks shall be added to lib.sh for any external dependencies. 568c2ecf20Sopenharmony_cio Code shall be checked using ShellCheck [1] prior to submission. 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci1. https://www.shellcheck.net/ 59