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 90c493da8SNicolas Dichtel(dev->netns_immutable) 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. 4918ec44f6SPetr Machatao Tests that use anything but the most trivial topologies should include 5018ec44f6SPetr 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/ 590cb86287SPetr Machata 60*fca6ff91SPetr MachataCleanups 61*fca6ff91SPetr Machata-------- 62*fca6ff91SPetr Machata 63*fca6ff91SPetr Machatao lib.sh brings in defer.sh (by way of ../lib.sh) by default. Consider 64*fca6ff91SPetr Machata making use of the defer primitive to schedule automatic cleanups. This 65*fca6ff91SPetr Machata makes it harder to forget to remove a temporary netdevice, kill a running 66*fca6ff91SPetr Machata process or perform other cleanup when the test script is interrupted. 67*fca6ff91SPetr Machata 68*fca6ff91SPetr Machatao When adding a helper that dirties the environment, but schedules all 69*fca6ff91SPetr Machata necessary cleanups through defer, consider prefixing it adf_ for 70*fca6ff91SPetr Machata consistency with lib.sh and ../lib.sh helpers. This serves as an 71*fca6ff91SPetr Machata immediately visible bit of documentation about the helper API. 72*fca6ff91SPetr Machata 73*fca6ff91SPetr Machatao Definitely do the above for any new code in lib.sh, if practical. 74*fca6ff91SPetr Machata 750cb86287SPetr MachataCustomization 760cb86287SPetr Machata============= 770cb86287SPetr Machata 780cb86287SPetr MachataThe forwarding selftests framework uses a number of variables that 790cb86287SPetr Machatainfluence its behavior and tools it invokes, and how it invokes them, in 800cb86287SPetr Machatavarious ways. A number of these variables can be overridden. The way these 810cb86287SPetr Machataoverridable variables are specified is typically one of the following two 820cb86287SPetr Machatasyntaxes: 830cb86287SPetr Machata 840cb86287SPetr Machata : "${VARIABLE:=default_value}" 850cb86287SPetr Machata VARIABLE=${VARIABLE:=default_value} 860cb86287SPetr Machata 870cb86287SPetr MachataAny of these variables can be overridden. Notably net/forwarding/lib.sh and 880cb86287SPetr Machatanet/lib.sh contain a number of overridable variables. 890cb86287SPetr Machata 900cb86287SPetr MachataOne way of overriding these variables is through the environment: 910cb86287SPetr Machata 920cb86287SPetr Machata PAUSE_ON_FAIL=yes ./some_test.sh 930cb86287SPetr Machata 940cb86287SPetr MachataThe variable NETIFS is special. Since it is an array variable, there is no 950cb86287SPetr Machataway to pass it through the environment. Its value can instead be given as 960cb86287SPetr Machataconsecutive arguments to the selftest: 970cb86287SPetr Machata 980cb86287SPetr Machata ./some_test.sh swp{1..8} 990cb86287SPetr Machata 1000cb86287SPetr MachataA way to customize variables in a persistent fashion is to create a file 1010cb86287SPetr Machatanamed forwarding.config in this directory. lib.sh sources the file if 1020cb86287SPetr Machatapresent, so it can contain any shell code. Typically it will contain 1030cb86287SPetr Machataassignments of variables whose value should be overridden. 1040cb86287SPetr Machata 1050cb86287SPetr Machataforwarding.config.sample is available in the directory as an example of 1060cb86287SPetr Machatahow forwarding.config might look. 107