hsr_redbox.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. ipv6=false
  4. source ./hsr_common.sh
  5. do_complete_ping_test()
  6. {
  7. echo "INFO: Initial validation ping (HSR-SAN/RedBox)."
  8. # Each node has to be able to reach each one.
  9. do_ping "${ns1}" 100.64.0.2
  10. do_ping "${ns2}" 100.64.0.1
  11. # Ping between SANs (test bridge)
  12. do_ping "${ns4}" 100.64.0.51
  13. do_ping "${ns5}" 100.64.0.41
  14. # Ping from SANs to hsr1 (via hsr2) (and opposite)
  15. do_ping "${ns3}" 100.64.0.1
  16. do_ping "${ns1}" 100.64.0.3
  17. do_ping "${ns1}" 100.64.0.41
  18. do_ping "${ns4}" 100.64.0.1
  19. do_ping "${ns1}" 100.64.0.51
  20. do_ping "${ns5}" 100.64.0.1
  21. stop_if_error "Initial validation failed."
  22. # Wait for MGNT HSR frames being received and nodes being
  23. # merged.
  24. sleep 5
  25. echo "INFO: Longer ping test (HSR-SAN/RedBox)."
  26. # Ping from SAN to hsr1 (via hsr2)
  27. do_ping_long "${ns3}" 100.64.0.1
  28. # Ping from hsr1 (via hsr2) to SANs (and opposite)
  29. do_ping_long "${ns1}" 100.64.0.3
  30. do_ping_long "${ns1}" 100.64.0.41
  31. do_ping_long "${ns4}" 100.64.0.1
  32. do_ping_long "${ns1}" 100.64.0.51
  33. do_ping_long "${ns5}" 100.64.0.1
  34. stop_if_error "Longer ping test failed."
  35. echo "INFO: All good."
  36. }
  37. setup_hsr_interfaces()
  38. {
  39. local HSRv="$1"
  40. echo "INFO: preparing interfaces for HSRv${HSRv} (HSR-SAN/RedBox)."
  41. #
  42. # IPv4 addresses (100.64.X.Y/24), and [X.Y] is presented on below diagram:
  43. #
  44. #
  45. # |NS1 | |NS4 |
  46. # | [0.1] | | |
  47. # | /-- hsr1 --\ | | [0.41] |
  48. # | ns1eth1 ns1eth2 | | ns4eth1 (SAN) |
  49. # |------------------------| |-------------------|
  50. # | | |
  51. # | | |
  52. # | | |
  53. # |------------------------| |-------------------------------|
  54. # | ns2eth1 ns2eth2 | | ns3eth2 |
  55. # | \-- hsr2 --/ | | / |
  56. # | [0.2] \ | | / | |------------|
  57. # | ns2eth3 |---| ns3eth1 -- ns3br1 -- ns3eth3--|--| ns5eth1 |
  58. # | (interlink)| | [0.3] [0.11] | | [0.51] |
  59. # |NS2 (RedBOX) | |NS3 (BR) | | NS5 (SAN) |
  60. #
  61. #
  62. # Check if iproute2 supports adding interlink port to hsrX device
  63. ip link help hsr | grep -q INTERLINK
  64. [ $? -ne 0 ] && { echo "iproute2: HSR interlink interface not supported!"; exit 0; }
  65. # Create interfaces for name spaces
  66. ip link add ns1eth1 netns "${ns1}" type veth peer name ns2eth1 netns "${ns2}"
  67. ip link add ns1eth2 netns "${ns1}" type veth peer name ns2eth2 netns "${ns2}"
  68. ip link add ns2eth3 netns "${ns2}" type veth peer name ns3eth1 netns "${ns3}"
  69. ip link add ns3eth2 netns "${ns3}" type veth peer name ns4eth1 netns "${ns4}"
  70. ip link add ns3eth3 netns "${ns3}" type veth peer name ns5eth1 netns "${ns5}"
  71. sleep 1
  72. ip -n "${ns1}" link set ns1eth1 up
  73. ip -n "${ns1}" link set ns1eth2 up
  74. ip -n "${ns2}" link set ns2eth1 up
  75. ip -n "${ns2}" link set ns2eth2 up
  76. ip -n "${ns2}" link set ns2eth3 up
  77. ip -n "${ns3}" link add name ns3br1 type bridge
  78. ip -n "${ns3}" link set ns3br1 up
  79. ip -n "${ns3}" link set ns3eth1 master ns3br1 up
  80. ip -n "${ns3}" link set ns3eth2 master ns3br1 up
  81. ip -n "${ns3}" link set ns3eth3 master ns3br1 up
  82. ip -n "${ns4}" link set ns4eth1 up
  83. ip -n "${ns5}" link set ns5eth1 up
  84. ip -net "$ns1" link set address 00:11:22:00:01:01 dev ns1eth1
  85. ip -net "$ns1" link set address 00:11:22:00:01:02 dev ns1eth2
  86. ip -net "$ns2" link set address 00:11:22:00:02:01 dev ns2eth1
  87. ip -net "$ns2" link set address 00:11:22:00:02:02 dev ns2eth2
  88. ip -net "$ns2" link set address 00:11:22:00:02:03 dev ns2eth3
  89. ip -net "$ns3" link set address 00:11:22:00:03:11 dev ns3eth1
  90. ip -net "$ns3" link set address 00:11:22:00:03:11 dev ns3eth2
  91. ip -net "$ns3" link set address 00:11:22:00:03:11 dev ns3eth3
  92. ip -net "$ns3" link set address 00:11:22:00:03:11 dev ns3br1
  93. ip -net "$ns4" link set address 00:11:22:00:04:01 dev ns4eth1
  94. ip -net "$ns5" link set address 00:11:22:00:05:01 dev ns5eth1
  95. ip -net "${ns1}" link add name hsr1 type hsr slave1 ns1eth1 slave2 ns1eth2 supervision 45 version ${HSRv} proto 0
  96. ip -net "${ns2}" link add name hsr2 type hsr slave1 ns2eth1 slave2 ns2eth2 interlink ns2eth3 supervision 45 version ${HSRv} proto 0
  97. ip -n "${ns1}" addr add 100.64.0.1/24 dev hsr1
  98. ip -n "${ns2}" addr add 100.64.0.2/24 dev hsr2
  99. ip -n "${ns3}" addr add 100.64.0.11/24 dev ns3br1
  100. ip -n "${ns3}" addr add 100.64.0.3/24 dev ns3eth1
  101. ip -n "${ns4}" addr add 100.64.0.41/24 dev ns4eth1
  102. ip -n "${ns5}" addr add 100.64.0.51/24 dev ns5eth1
  103. ip -n "${ns1}" link set hsr1 up
  104. ip -n "${ns2}" link set hsr2 up
  105. }
  106. check_prerequisites
  107. setup_ns ns1 ns2 ns3 ns4 ns5
  108. trap cleanup_all_ns EXIT
  109. setup_hsr_interfaces 1
  110. do_complete_ping_test
  111. exit $ret