gre_multipath.sh 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. tc qdisc add dev $ul1 clsact
  88. tc filter add dev $ul1 egress pref 111 prot ipv4 \
  89. flower dst_ip 192.0.2.66 action pass
  90. tc filter add dev $ul1 egress pref 222 prot ipv4 \
  91. flower dst_ip 192.0.2.82 action pass
  92. }
  93. sw1_destroy()
  94. {
  95. tc qdisc del dev $ul1 clsact
  96. ip route del vrf v$ol1 192.0.2.16/28
  97. ip route del vrf v$ol1 192.0.2.82/32 via 192.0.2.146
  98. __simple_if_fini g1b 192.0.2.81/32
  99. tunnel_destroy g1b
  100. ip route del vrf v$ol1 192.0.2.66/32 via 192.0.2.130
  101. __simple_if_fini g1a 192.0.2.65/32
  102. tunnel_destroy g1a
  103. vlan_destroy $ul1 222
  104. vlan_destroy $ul1 111
  105. __simple_if_fini $ul1
  106. simple_if_fini $ol1 192.0.2.2/28
  107. }
  108. sw2_create()
  109. {
  110. simple_if_init $ol2 192.0.2.17/28
  111. __simple_if_init $ul2 v$ol2
  112. vlan_create $ul2 111 v$ol2 192.0.2.130/28
  113. vlan_create $ul2 222 v$ol2 192.0.2.146/28
  114. tunnel_create g2a gre 192.0.2.66 192.0.2.65 tos inherit dev v$ol2
  115. __simple_if_init g2a v$ol2 192.0.2.66/32
  116. ip route add vrf v$ol2 192.0.2.65/32 via 192.0.2.129
  117. tunnel_create g2b gre 192.0.2.82 192.0.2.81 tos inherit dev v$ol2
  118. __simple_if_init g2b v$ol2 192.0.2.82/32
  119. ip route add vrf v$ol2 192.0.2.81/32 via 192.0.2.145
  120. ip route add vrf v$ol2 192.0.2.0/28 \
  121. nexthop dev g2a \
  122. nexthop dev g2b
  123. }
  124. sw2_destroy()
  125. {
  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. }
  162. cleanup()
  163. {
  164. pre_cleanup
  165. h2_destroy
  166. sw2_destroy
  167. sw1_destroy
  168. h1_destroy
  169. vrf_cleanup
  170. }
  171. multipath4_test()
  172. {
  173. local what=$1; shift
  174. local weight1=$1; shift
  175. local weight2=$1; shift
  176. sysctl_set net.ipv4.fib_multipath_hash_policy 1
  177. ip route replace vrf v$ol1 192.0.2.16/28 \
  178. nexthop dev g1a weight $weight1 \
  179. nexthop dev g1b weight $weight2
  180. local t0_111=$(tc_rule_stats_get $ul1 111 egress)
  181. local t0_222=$(tc_rule_stats_get $ul1 222 egress)
  182. ip vrf exec v$h1 \
  183. $MZ $h1 -q -p 64 -A 192.0.2.1 -B 192.0.2.18 \
  184. -d 1msec -t udp "sp=1024,dp=0-32768"
  185. local t1_111=$(tc_rule_stats_get $ul1 111 egress)
  186. local t1_222=$(tc_rule_stats_get $ul1 222 egress)
  187. local d111=$((t1_111 - t0_111))
  188. local d222=$((t1_222 - t0_222))
  189. multipath_eval "$what" $weight1 $weight2 $d111 $d222
  190. ip route replace vrf v$ol1 192.0.2.16/28 \
  191. nexthop dev g1a \
  192. nexthop dev g1b
  193. sysctl_restore net.ipv4.fib_multipath_hash_policy
  194. }
  195. ping_ipv4()
  196. {
  197. ping_test $h1 192.0.2.18
  198. }
  199. multipath_ipv4()
  200. {
  201. log_info "Running IPv4 multipath tests"
  202. multipath4_test "ECMP" 1 1
  203. multipath4_test "Weighted MP 2:1" 2 1
  204. multipath4_test "Weighted MP 11:45" 11 45
  205. }
  206. trap cleanup EXIT
  207. setup_prepare
  208. setup_wait
  209. tests_run
  210. exit $EXIT_STATUS