xref: /OK3568_Linux_fs/kernel/tools/testing/selftests/net/forwarding/README (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593SmuzhiyunMotivation
2*4882a593Smuzhiyun==========
3*4882a593Smuzhiyun
4*4882a593SmuzhiyunOne of the nice things about network namespaces is that they allow one
5*4882a593Smuzhiyunto easily create and test complex environments.
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunUnfortunately, these namespaces can not be used with actual switching
8*4882a593SmuzhiyunASICs, as their ports can not be migrated to other network namespaces
9*4882a593Smuzhiyun(NETIF_F_NETNS_LOCAL) and most of them probably do not support the
10*4882a593SmuzhiyunL1-separation provided by namespaces.
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunHowever, a similar kind of flexibility can be achieved by using VRFs and
13*4882a593Smuzhiyunby looping the switch ports together. For example:
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun                             br0
16*4882a593Smuzhiyun                              +
17*4882a593Smuzhiyun               vrf-h1         |           vrf-h2
18*4882a593Smuzhiyun                 +        +---+----+        +
19*4882a593Smuzhiyun                 |        |        |        |
20*4882a593Smuzhiyun    192.0.2.1/24 +        +        +        + 192.0.2.2/24
21*4882a593Smuzhiyun               swp1     swp2     swp3     swp4
22*4882a593Smuzhiyun                 +        +        +        +
23*4882a593Smuzhiyun                 |        |        |        |
24*4882a593Smuzhiyun                 +--------+        +--------+
25*4882a593Smuzhiyun
26*4882a593SmuzhiyunThe VRFs act as lightweight namespaces representing hosts connected to
27*4882a593Smuzhiyunthe switch.
28*4882a593Smuzhiyun
29*4882a593SmuzhiyunThis approach for testing switch ASICs has several advantages over the
30*4882a593Smuzhiyuntraditional method that requires multiple physical machines, to name a
31*4882a593Smuzhiyunfew:
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun1. Only the device under test (DUT) is being tested without noise from
34*4882a593Smuzhiyunother system.
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun2. Ability to easily provision complex topologies. Testing bridging
37*4882a593Smuzhiyunbetween 4-ports LAGs or 8-way ECMP requires many physical links that are
38*4882a593Smuzhiyunnot always available. With the VRF-based approach one merely needs to
39*4882a593Smuzhiyunloopback more ports.
40*4882a593Smuzhiyun
41*4882a593SmuzhiyunThese tests are written with switch ASICs in mind, but they can be run
42*4882a593Smuzhiyunon any Linux box using veth pairs to emulate physical loopbacks.
43*4882a593Smuzhiyun
44*4882a593SmuzhiyunGuidelines for Writing Tests
45*4882a593Smuzhiyun============================
46*4882a593Smuzhiyun
47*4882a593Smuzhiyuno Where possible, reuse an existing topology for different tests instead
48*4882a593Smuzhiyun  of recreating the same topology.
49*4882a593Smuzhiyuno Tests that use anything but the most trivial topologies should include
50*4882a593Smuzhiyun  an ASCII art showing the topology.
51*4882a593Smuzhiyuno Where possible, IPv6 and IPv4 addresses shall conform to RFC 3849 and
52*4882a593Smuzhiyun  RFC 5737, respectively.
53*4882a593Smuzhiyuno Where possible, tests shall be written so that they can be reused by
54*4882a593Smuzhiyun  multiple topologies and added to lib.sh.
55*4882a593Smuzhiyuno Checks shall be added to lib.sh for any external dependencies.
56*4882a593Smuzhiyuno Code shall be checked using ShellCheck [1] prior to submission.
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun1. https://www.shellcheck.net/
59