xref: /linux/tools/testing/selftests/net/forwarding/README (revision 9410645520e9b820069761f3450ef6661418e279)
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
9*05c1280aSAlexander Lobakin(dev->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/
590cb86287SPetr Machata
600cb86287SPetr MachataCustomization
610cb86287SPetr Machata=============
620cb86287SPetr Machata
630cb86287SPetr MachataThe forwarding selftests framework uses a number of variables that
640cb86287SPetr Machatainfluence its behavior and tools it invokes, and how it invokes them, in
650cb86287SPetr Machatavarious ways. A number of these variables can be overridden. The way these
660cb86287SPetr Machataoverridable variables are specified is typically one of the following two
670cb86287SPetr Machatasyntaxes:
680cb86287SPetr Machata
690cb86287SPetr Machata	: "${VARIABLE:=default_value}"
700cb86287SPetr Machata	VARIABLE=${VARIABLE:=default_value}
710cb86287SPetr Machata
720cb86287SPetr MachataAny of these variables can be overridden. Notably net/forwarding/lib.sh and
730cb86287SPetr Machatanet/lib.sh contain a number of overridable variables.
740cb86287SPetr Machata
750cb86287SPetr MachataOne way of overriding these variables is through the environment:
760cb86287SPetr Machata
770cb86287SPetr Machata	PAUSE_ON_FAIL=yes ./some_test.sh
780cb86287SPetr Machata
790cb86287SPetr MachataThe variable NETIFS is special. Since it is an array variable, there is no
800cb86287SPetr Machataway to pass it through the environment. Its value can instead be given as
810cb86287SPetr Machataconsecutive arguments to the selftest:
820cb86287SPetr Machata
830cb86287SPetr Machata	./some_test.sh swp{1..8}
840cb86287SPetr Machata
850cb86287SPetr MachataA way to customize variables in a persistent fashion is to create a file
860cb86287SPetr Machatanamed forwarding.config in this directory. lib.sh sources the file if
870cb86287SPetr Machatapresent, so it can contain any shell code. Typically it will contain
880cb86287SPetr Machataassignments of variables whose value should be overridden.
890cb86287SPetr Machata
900cb86287SPetr Machataforwarding.config.sample is available in the directory as an example of
910cb86287SPetr Machatahow forwarding.config might look.
92