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. 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/ 59*0cb86287SPetr Machata 60*0cb86287SPetr MachataCustomization 61*0cb86287SPetr Machata============= 62*0cb86287SPetr Machata 63*0cb86287SPetr MachataThe forwarding selftests framework uses a number of variables that 64*0cb86287SPetr Machatainfluence its behavior and tools it invokes, and how it invokes them, in 65*0cb86287SPetr Machatavarious ways. A number of these variables can be overridden. The way these 66*0cb86287SPetr Machataoverridable variables are specified is typically one of the following two 67*0cb86287SPetr Machatasyntaxes: 68*0cb86287SPetr Machata 69*0cb86287SPetr Machata : "${VARIABLE:=default_value}" 70*0cb86287SPetr Machata VARIABLE=${VARIABLE:=default_value} 71*0cb86287SPetr Machata 72*0cb86287SPetr MachataAny of these variables can be overridden. Notably net/forwarding/lib.sh and 73*0cb86287SPetr Machatanet/lib.sh contain a number of overridable variables. 74*0cb86287SPetr Machata 75*0cb86287SPetr MachataOne way of overriding these variables is through the environment: 76*0cb86287SPetr Machata 77*0cb86287SPetr Machata PAUSE_ON_FAIL=yes ./some_test.sh 78*0cb86287SPetr Machata 79*0cb86287SPetr MachataThe variable NETIFS is special. Since it is an array variable, there is no 80*0cb86287SPetr Machataway to pass it through the environment. Its value can instead be given as 81*0cb86287SPetr Machataconsecutive arguments to the selftest: 82*0cb86287SPetr Machata 83*0cb86287SPetr Machata ./some_test.sh swp{1..8} 84*0cb86287SPetr Machata 85*0cb86287SPetr MachataA way to customize variables in a persistent fashion is to create a file 86*0cb86287SPetr Machatanamed forwarding.config in this directory. lib.sh sources the file if 87*0cb86287SPetr Machatapresent, so it can contain any shell code. Typically it will contain 88*0cb86287SPetr Machataassignments of variables whose value should be overridden. 89*0cb86287SPetr Machata 90*0cb86287SPetr Machataforwarding.config.sample is available in the directory as an example of 91*0cb86287SPetr Machatahow forwarding.config might look. 92