173bae673SIdo SchimmelMotivation 273bae673SIdo Schimmel========== 373bae673SIdo Schimmel 473bae673SIdo SchimmelOne of the nice things about network namespaces is that they allow one 573bae673SIdo Schimmelto easily create and test complex environments. 673bae673SIdo Schimmel 773bae673SIdo SchimmelUnfortunately, these namespaces can not be used with actual switching 873bae673SIdo SchimmelASICs, as their ports can not be migrated to other network namespaces 973bae673SIdo Schimmel(NETIF_F_NETNS_LOCAL) and most of them probably do not support the 1073bae673SIdo SchimmelL1-separation provided by namespaces. 1173bae673SIdo Schimmel 1273bae673SIdo SchimmelHowever, a similar kind of flexibility can be achieved by using VRFs and 1373bae673SIdo Schimmelby looping the switch ports together. For example: 1473bae673SIdo Schimmel 1573bae673SIdo Schimmel br0 1673bae673SIdo Schimmel + 1773bae673SIdo Schimmel vrf-h1 | vrf-h2 1873bae673SIdo Schimmel + +---+----+ + 1973bae673SIdo Schimmel | | | | 2073bae673SIdo Schimmel 192.0.2.1/24 + + + + 192.0.2.2/24 2173bae673SIdo Schimmel swp1 swp2 swp3 swp4 2273bae673SIdo Schimmel + + + + 2373bae673SIdo Schimmel | | | | 2473bae673SIdo Schimmel +--------+ +--------+ 2573bae673SIdo Schimmel 2673bae673SIdo SchimmelThe VRFs act as lightweight namespaces representing hosts connected to 2773bae673SIdo Schimmelthe switch. 2873bae673SIdo Schimmel 2973bae673SIdo SchimmelThis approach for testing switch ASICs has several advantages over the 3073bae673SIdo Schimmeltraditional method that requires multiple physical machines, to name a 3173bae673SIdo Schimmelfew: 3273bae673SIdo Schimmel 3373bae673SIdo Schimmel1. Only the device under test (DUT) is being tested without noise from 3473bae673SIdo Schimmelother system. 3573bae673SIdo Schimmel 3673bae673SIdo Schimmel2. Ability to easily provision complex topologies. Testing bridging 3773bae673SIdo Schimmelbetween 4-ports LAGs or 8-way ECMP requires many physical links that are 3873bae673SIdo Schimmelnot always available. With the VRF-based approach one merely needs to 3973bae673SIdo Schimmelloopback more ports. 4073bae673SIdo Schimmel 4173bae673SIdo SchimmelThese tests are written with switch ASICs in mind, but they can be run 4273bae673SIdo Schimmelon any Linux box using veth pairs to emulate physical loopbacks. 4373bae673SIdo Schimmel 4473bae673SIdo SchimmelGuidelines for Writing Tests 4573bae673SIdo Schimmel============================ 4673bae673SIdo Schimmel 4773bae673SIdo Schimmelo Where possible, reuse an existing topology for different tests instead 4873bae673SIdo Schimmel of recreating the same topology. 49*18ec44f6SPetr Machatao Tests that use anything but the most trivial topologies should include 50*18ec44f6SPetr Machata an ASCII art showing the topology. 5173bae673SIdo Schimmelo Where possible, IPv6 and IPv4 addresses shall conform to RFC 3849 and 5273bae673SIdo Schimmel RFC 5737, respectively. 5373bae673SIdo Schimmelo Where possible, tests shall be written so that they can be reused by 5473bae673SIdo Schimmel multiple topologies and added to lib.sh. 5573bae673SIdo Schimmelo Checks shall be added to lib.sh for any external dependencies. 5673bae673SIdo Schimmelo Code shall be checked using ShellCheck [1] prior to submission. 5773bae673SIdo Schimmel 5873bae673SIdo Schimmel1. https://www.shellcheck.net/ 59