README 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. Motivation
  2. ==========
  3. One of the nice things about network namespaces is that they allow one
  4. to easily create and test complex environments.
  5. Unfortunately, these namespaces can not be used with actual switching
  6. ASICs, as their ports can not be migrated to other network namespaces
  7. (dev->netns_local) and most of them probably do not support the
  8. L1-separation provided by namespaces.
  9. However, a similar kind of flexibility can be achieved by using VRFs and
  10. by looping the switch ports together. For example:
  11. br0
  12. +
  13. vrf-h1 | vrf-h2
  14. + +---+----+ +
  15. | | | |
  16. 192.0.2.1/24 + + + + 192.0.2.2/24
  17. swp1 swp2 swp3 swp4
  18. + + + +
  19. | | | |
  20. +--------+ +--------+
  21. The VRFs act as lightweight namespaces representing hosts connected to
  22. the switch.
  23. This approach for testing switch ASICs has several advantages over the
  24. traditional method that requires multiple physical machines, to name a
  25. few:
  26. 1. Only the device under test (DUT) is being tested without noise from
  27. other system.
  28. 2. Ability to easily provision complex topologies. Testing bridging
  29. between 4-ports LAGs or 8-way ECMP requires many physical links that are
  30. not always available. With the VRF-based approach one merely needs to
  31. loopback more ports.
  32. These tests are written with switch ASICs in mind, but they can be run
  33. on any Linux box using veth pairs to emulate physical loopbacks.
  34. Guidelines for Writing Tests
  35. ============================
  36. o Where possible, reuse an existing topology for different tests instead
  37. of recreating the same topology.
  38. o Tests that use anything but the most trivial topologies should include
  39. an ASCII art showing the topology.
  40. o Where possible, IPv6 and IPv4 addresses shall conform to RFC 3849 and
  41. RFC 5737, respectively.
  42. o Where possible, tests shall be written so that they can be reused by
  43. multiple topologies and added to lib.sh.
  44. o Checks shall be added to lib.sh for any external dependencies.
  45. o Code shall be checked using ShellCheck [1] prior to submission.
  46. 1. https://www.shellcheck.net/
  47. Customization
  48. =============
  49. The forwarding selftests framework uses a number of variables that
  50. influence its behavior and tools it invokes, and how it invokes them, in
  51. various ways. A number of these variables can be overridden. The way these
  52. overridable variables are specified is typically one of the following two
  53. syntaxes:
  54. : "${VARIABLE:=default_value}"
  55. VARIABLE=${VARIABLE:=default_value}
  56. Any of these variables can be overridden. Notably net/forwarding/lib.sh and
  57. net/lib.sh contain a number of overridable variables.
  58. One way of overriding these variables is through the environment:
  59. PAUSE_ON_FAIL=yes ./some_test.sh
  60. The variable NETIFS is special. Since it is an array variable, there is no
  61. way to pass it through the environment. Its value can instead be given as
  62. consecutive arguments to the selftest:
  63. ./some_test.sh swp{1..8}
  64. A way to customize variables in a persistent fashion is to create a file
  65. named forwarding.config in this directory. lib.sh sources the file if
  66. present, so it can contain any shell code. Typically it will contain
  67. assignments of variables whose value should be overridden.
  68. forwarding.config.sample is available in the directory as an example of
  69. how forwarding.config might look.