/contrib/netbsd-tests/net/mpls/t_mpls_fw6.sh

https://bitbucket.org/freebsd/freebsd-base · Shell · 220 lines · 145 code · 33 blank · 42 comment · 0 complexity · 094787df5e634049fd93e83b1385a1cc MD5 · raw file

  1. # $NetBSD: t_mpls_fw6.sh,v 1.3 2016/08/10 07:50:37 ozaki-r Exp $
  2. #
  3. # Copyright (c) 2015 The NetBSD Foundation, Inc.
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. # 1. Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. # notice, this list of conditions and the following disclaimer in the
  13. # documentation and/or other materials provided with the distribution.
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  16. # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  17. # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18. # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  19. # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. # POSSIBILITY OF SUCH DAMAGE.
  26. #
  27. # Test MPLS encap/decap and forwarding using INET6 as encapsulated protocol
  28. # Setup four routers connected like this: R1---R2---R3---R4--
  29. # Goal is to be able to ping from R1 the outermost interface of R4
  30. # Disable net.inet6.ip6.forwarding, enable net.mpls.forwarding
  31. # Add route on R1 in order to encapsulate into MPLS the IP6 packets with
  32. # destination equal to R4 right hand side interface
  33. # Add MPLS routes on R2 in order to forward frames belonging to that FEC to R3
  34. # Add MPLS "POP" route on R3 for that FEC, pointing to R4
  35. # Do the same for the reverse direction (R4 to R1)
  36. # ping6 from R1 to R4 right hand side interface
  37. #
  38. # redo the test using IPv6 explicit null label
  39. RUMP_SERVER1=unix://./r1
  40. RUMP_SERVER2=unix://./r2
  41. RUMP_SERVER3=unix://./r3
  42. RUMP_SERVER4=unix://./r4
  43. RUMP_FLAGS6="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6 \
  44. -lrumpdev -lrumpnet_shmif -lrumpnet_netmpls"
  45. atf_test_case mplsfw6 cleanup
  46. mplsfw6_head()
  47. {
  48. atf_set "descr" "IP6/MPLS forwarding test using PHP"
  49. atf_set "require.progs" "rump_server"
  50. }
  51. startservers()
  52. {
  53. ulimit -r 300
  54. atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER1}
  55. atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER2}
  56. atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER3}
  57. atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER4}
  58. }
  59. configservers()
  60. {
  61. # Setup the first server
  62. export RUMP_SERVER=${RUMP_SERVER1}
  63. atf_check -s exit:0 rump.ifconfig shmif0 create
  64. atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
  65. atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234::1/64 alias
  66. atf_check -s exit:0 rump.ifconfig mpls0 create up
  67. atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
  68. atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0
  69. atf_check -s exit:0 rump.route -q add -inet6 fd00:1234:0:3::/64 \
  70. -ifa fd00:1234::1 \
  71. -ifp mpls0 -tag 25 -inet6 fd00:1234::2
  72. # Setup the second server
  73. export RUMP_SERVER=${RUMP_SERVER2}
  74. atf_check -s exit:0 rump.ifconfig shmif0 create
  75. atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
  76. atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234::2/64 alias
  77. atf_check -s exit:0 rump.ifconfig shmif1 create
  78. atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom2
  79. atf_check -s exit:0 rump.ifconfig shmif1 inet6 fd00:1234:0:1::1/64 alias
  80. atf_check -s exit:0 rump.ifconfig mpls0 create up
  81. atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
  82. atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1
  83. atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0
  84. atf_check -s exit:0 rump.route -q add -mpls 25 -tag 30 \
  85. -inet6 fd00:1234:0:1::2
  86. atf_check -s exit:0 rump.route -q add -mpls 27 -tag ${1} -inet6 \
  87. fd00:1234::1
  88. # Setup the third server
  89. export RUMP_SERVER=${RUMP_SERVER3}
  90. atf_check -s exit:0 rump.ifconfig shmif0 create
  91. atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom2
  92. atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234:0:1::2/64 alias
  93. atf_check -s exit:0 rump.ifconfig shmif1 create
  94. atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom3
  95. atf_check -s exit:0 rump.ifconfig shmif1 inet6 fd00:1234:0:2::1/64 alias
  96. atf_check -s exit:0 rump.ifconfig mpls0 create up
  97. atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
  98. atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1
  99. atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0
  100. atf_check -s exit:0 rump.route -q add -mpls 30 -tag ${1} \
  101. -inet6 fd00:1234:0:2::2
  102. atf_check -s exit:0 rump.route -q add -mpls 26 -tag 27 \
  103. -inet6 fd00:1234:0:1::1
  104. # Setup the fourth server
  105. export RUMP_SERVER=${RUMP_SERVER4}
  106. atf_check -s exit:0 rump.ifconfig shmif0 create
  107. atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom3
  108. atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234:0:2::2/64 alias
  109. atf_check -s exit:0 rump.ifconfig shmif1 create
  110. atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom4
  111. atf_check -s exit:0 rump.ifconfig shmif1 inet6 fd00:1234:0:3::1/64 alias
  112. atf_check -s exit:0 rump.ifconfig mpls0 create up
  113. atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
  114. atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0
  115. atf_check -s exit:0 rump.route -q add -inet6 fd00:1234::/64 \
  116. -ifa fd00:1234:0:2::2 \
  117. -ifp mpls0 -tag 26 -inet6 fd00:1234:0:2::1
  118. unset RUMP_SERVER
  119. }
  120. doping()
  121. {
  122. export RUMP_SERVER=${RUMP_SERVER1}
  123. atf_check -s exit:0 \
  124. -o match:" bytes from fd00:1234::2, icmp_seq=" \
  125. rump.ping6 -n -o -X 2 fd00:1234::2
  126. export RUMP_SERVER=${RUMP_SERVER2}
  127. atf_check -s exit:0 \
  128. -o match:" bytes from fd00:1234:0:1::2, icmp_seq=" \
  129. rump.ping6 -n -o -X 2 fd00:1234:0:1::2
  130. export RUMP_SERVER=${RUMP_SERVER3}
  131. atf_check -s exit:0 \
  132. -o match:" bytes from fd00:1234:0:2::2, icmp_seq=" \
  133. rump.ping6 -n -o -X 2 fd00:1234:0:2::2
  134. export RUMP_SERVER=${RUMP_SERVER1}
  135. atf_check -s exit:0 \
  136. -o match:" bytes from fd00:1234:0:3::1, icmp_seq=" \
  137. rump.ping6 -n -o -X 2 fd00:1234:0:3::1
  138. unset RUMP_SERVER
  139. }
  140. do_check_route()
  141. {
  142. export RUMP_SERVER=${RUMP_SERVER1}
  143. atf_check -s exit:0 \
  144. -o match:"^fd00:1234:0:3::/64.+fd00:1234::2.+25.+mpls0" \
  145. rump.netstat -nrT
  146. unset RUMP_SERVER
  147. }
  148. docleanup()
  149. {
  150. RUMP_SERVER=${RUMP_SERVER1} rump.halt
  151. RUMP_SERVER=${RUMP_SERVER2} rump.halt
  152. RUMP_SERVER=${RUMP_SERVER3} rump.halt
  153. RUMP_SERVER=${RUMP_SERVER4} rump.halt
  154. }
  155. mplsfw6_body()
  156. {
  157. startservers
  158. configservers 3
  159. do_check_route
  160. doping
  161. }
  162. mplsfw6_cleanup()
  163. {
  164. docleanup
  165. }
  166. atf_test_case mplsfw6_expl cleanup
  167. mplsfw4_expl_head()
  168. {
  169. atf_set "descr" "IP6/MPLS forwarding test using explicit NULL labels"
  170. atf_set "require.progs" "rump_server"
  171. }
  172. mplsfw6_expl_body()
  173. {
  174. startservers
  175. configservers 2
  176. do_check_route
  177. doping
  178. }
  179. mplsfw6_expl_cleanup()
  180. {
  181. docleanup
  182. }
  183. atf_init_test_cases()
  184. {
  185. atf_add_test_case mplsfw6
  186. atf_add_test_case mplsfw6_expl
  187. }