gre_multipath.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. # Test traffic distribution when a wECMP route forwards traffic to two GRE
  4. # tunnels.
  5. #
  6. # +-------------------------+
  7. # | H1 |
  8. # | $h1 + |
  9. # | 192.0.2.1/28 | |
  10. # +-------------------|-----+
  11. # |
  12. # +-------------------|------------------------+
  13. # | SW1 | |
  14. # | $ol1 + |
  15. # | 192.0.2.2/28 |
  16. # | |
  17. # | + g1a (gre) + g1b (gre) |
  18. # | loc=192.0.2.65 loc=192.0.2.81 |
  19. # | rem=192.0.2.66 --. rem=192.0.2.82 --. |
  20. # | tos=inherit | tos=inherit | |
  21. # | .------------------' | |
  22. # | | .------------------' |
  23. # | v v |
  24. # | + $ul1.111 (vlan) + $ul1.222 (vlan) |
  25. # | | 192.0.2.129/28 | 192.0.2.145/28 |
  26. # | \ / |
  27. # | \________________/ |
  28. # | | |
  29. # | + $ul1 |
  30. # +------------|-------------------------------+
  31. # |
  32. # +------------|-------------------------------+
  33. # | SW2 + $ul2 |
  34. # | _______|________ |
  35. # | / \ |
  36. # | / \ |
  37. # | + $ul2.111 (vlan) + $ul2.222 (vlan) |
  38. # | ^ 192.0.2.130/28 ^ 192.0.2.146/28 |
  39. # | | | |
  40. # | | '------------------. |
  41. # | '------------------. | |
  42. # | + g2a (gre) | + g2b (gre) | |
  43. # | loc=192.0.2.66 | loc=192.0.2.82 | |
  44. # | rem=192.0.2.65 --' rem=192.0.2.81 --' |
  45. # | tos=inherit tos=inherit |
  46. # | |
  47. # | $ol2 + |
  48. # | 192.0.2.17/28 | |
  49. # +-------------------|------------------------+
  50. # |
  51. # +-------------------|-----+
  52. # | H2 | |
  53. # | $h2 + |
  54. # | 192.0.2.18/28 |
  55. # +-------------------------+
  56. ALL_TESTS="
  57. ping_ipv4
  58. multipath_ipv4
  59. "
  60. NUM_NETIFS=6
  61. source lib.sh
  62. h1_create()
  63. {
  64. simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64
  65. ip route add vrf v$h1 192.0.2.16/28 via 192.0.2.2
  66. }
  67. h1_destroy()
  68. {
  69. ip route del vrf v$h1 192.0.2.16/28 via 192.0.2.2
  70. simple_if_fini $h1 192.0.2.1/28
  71. }
  72. sw1_create()
  73. {
  74. simple_if_init $ol1 192.0.2.2/28
  75. __simple_if_init $ul1 v$ol1
  76. vlan_create $ul1 111 v$ol1 192.0.2.129/28
  77. vlan_create $ul1 222 v$ol1 192.0.2.145/28
  78. tunnel_create g1a gre 192.0.2.65 192.0.2.66 tos inherit dev v$ol1
  79. __simple_if_init g1a v$ol1 192.0.2.65/32
  80. ip route add vrf v$ol1 192.0.2.66/32 via 192.0.2.130
  81. tunnel_create g1b gre 192.0.2.81 192.0.2.82 tos inherit dev v$ol1
  82. __simple_if_init g1b v$ol1 192.0.2.81/32
  83. ip route add vrf v$ol1 192.0.2.82/32 via 192.0.2.146
  84. ip route add vrf v$ol1 192.0.2.16/28 \
  85. nexthop dev g1a \
  86. nexthop dev g1b
  87. }
  88. sw1_destroy()
  89. {
  90. ip route del vrf v$ol1 192.0.2.16/28
  91. ip route del vrf v$ol1 192.0.2.82/32 via 192.0.2.146
  92. __simple_if_fini g1b 192.0.2.81/32
  93. tunnel_destroy g1b
  94. ip route del vrf v$ol1 192.0.2.66/32 via 192.0.2.130
  95. __simple_if_fini g1a 192.0.2.65/32
  96. tunnel_destroy g1a
  97. vlan_destroy $ul1 222
  98. vlan_destroy $ul1 111
  99. __simple_if_fini $ul1
  100. simple_if_fini $ol1 192.0.2.2/28
  101. }
  102. sw2_create()
  103. {
  104. simple_if_init $ol2 192.0.2.17/28
  105. __simple_if_init $ul2 v$ol2
  106. vlan_create $ul2 111 v$ol2 192.0.2.130/28
  107. vlan_create $ul2 222 v$ol2 192.0.2.146/28
  108. tunnel_create g2a gre 192.0.2.66 192.0.2.65 tos inherit dev v$ol2
  109. __simple_if_init g2a v$ol2 192.0.2.66/32
  110. ip route add vrf v$ol2 192.0.2.65/32 via 192.0.2.129
  111. tunnel_create g2b gre 192.0.2.82 192.0.2.81 tos inherit dev v$ol2
  112. __simple_if_init g2b v$ol2 192.0.2.82/32
  113. ip route add vrf v$ol2 192.0.2.81/32 via 192.0.2.145
  114. ip route add vrf v$ol2 192.0.2.0/28 \
  115. nexthop dev g2a \
  116. nexthop dev g2b
  117. tc qdisc add dev $ul2 clsact
  118. tc filter add dev $ul2 ingress pref 111 prot 802.1Q \
  119. flower vlan_id 111 action pass
  120. tc filter add dev $ul2 ingress pref 222 prot 802.1Q \
  121. flower vlan_id 222 action pass
  122. }
  123. sw2_destroy()
  124. {
  125. tc qdisc del dev $ul2 clsact
  126. ip route del vrf v$ol2 192.0.2.0/28
  127. ip route del vrf v$ol2 192.0.2.81/32 via 192.0.2.145
  128. __simple_if_fini g2b 192.0.2.82/32
  129. tunnel_destroy g2b
  130. ip route del vrf v$ol2 192.0.2.65/32 via 192.0.2.129
  131. __simple_if_fini g2a 192.0.2.66/32
  132. tunnel_destroy g2a
  133. vlan_destroy $ul2 222
  134. vlan_destroy $ul2 111
  135. __simple_if_fini $ul2
  136. simple_if_fini $ol2 192.0.2.17/28
  137. }
  138. h2_create()
  139. {
  140. simple_if_init $h2 192.0.2.18/28
  141. ip route add vrf v$h2 192.0.2.0/28 via 192.0.2.17
  142. }
  143. h2_destroy()
  144. {
  145. ip route del vrf v$h2 192.0.2.0/28 via 192.0.2.17
  146. simple_if_fini $h2 192.0.2.18/28
  147. }
  148. setup_prepare()
  149. {
  150. h1=${NETIFS[p1]}
  151. ol1=${NETIFS[p2]}
  152. ul1=${NETIFS[p3]}
  153. ul2=${NETIFS[p4]}
  154. ol2=${NETIFS[p5]}
  155. h2=${NETIFS[p6]}
  156. vrf_prepare
  157. h1_create
  158. sw1_create
  159. sw2_create
  160. h2_create
  161. forwarding_enable
  162. }
  163. cleanup()
  164. {
  165. pre_cleanup
  166. forwarding_restore
  167. h2_destroy
  168. sw2_destroy
  169. sw1_destroy
  170. h1_destroy
  171. vrf_cleanup
  172. }
  173. multipath4_test()
  174. {
  175. local what=$1; shift
  176. local weight1=$1; shift
  177. local weight2=$1; shift
  178. sysctl_set net.ipv4.fib_multipath_hash_policy 1
  179. ip route replace vrf v$ol1 192.0.2.16/28 \
  180. nexthop dev g1a weight $weight1 \
  181. nexthop dev g1b weight $weight2
  182. local t0_111=$(tc_rule_stats_get $ul2 111 ingress)
  183. local t0_222=$(tc_rule_stats_get $ul2 222 ingress)
  184. ip vrf exec v$h1 \
  185. $MZ $h1 -q -p 64 -A 192.0.2.1 -B 192.0.2.18 \
  186. -d 1msec -t udp "sp=1024,dp=0-32768"
  187. local t1_111=$(tc_rule_stats_get $ul2 111 ingress)
  188. local t1_222=$(tc_rule_stats_get $ul2 222 ingress)
  189. local d111=$((t1_111 - t0_111))
  190. local d222=$((t1_222 - t0_222))
  191. multipath_eval "$what" $weight1 $weight2 $d111 $d222
  192. ip route replace vrf v$ol1 192.0.2.16/28 \
  193. nexthop dev g1a \
  194. nexthop dev g1b
  195. sysctl_restore net.ipv4.fib_multipath_hash_policy
  196. }
  197. ping_ipv4()
  198. {
  199. ping_test $h1 192.0.2.18
  200. }
  201. multipath_ipv4()
  202. {
  203. log_info "Running IPv4 multipath tests"
  204. multipath4_test "ECMP" 1 1
  205. multipath4_test "Weighted MP 2:1" 2 1
  206. multipath4_test "Weighted MP 11:45" 11 45
  207. }
  208. trap cleanup EXIT
  209. setup_prepare
  210. setup_wait
  211. tests_run
  212. exit $EXIT_STATUS