2
0

ns-ping.test 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/sh
  2. . ./testlib.sh
  3. # Skip this test if we aren't root or if "ip netns" does not exist
  4. test "`id -u`" = "0" || exit 77
  5. ip netns list || exit 77
  6. # Initialize two nodes
  7. $tinc $c1 <<EOF
  8. init foo
  9. set Mode switch
  10. set Interface ping.test1
  11. set Port 32573
  12. set Address localhost
  13. EOF
  14. cat >$d1/tinc-up <<EOF
  15. #!/bin/sh
  16. ip netns add ping.test1
  17. ip link set dev \$INTERFACE netns ping.test1
  18. ip netns exec ping.test1 ip addr add 192.168.1.1/24 dev \$INTERFACE
  19. ip netns exec ping.test1 ip link set \$INTERFACE up
  20. EOF
  21. $tinc $c2 <<EOF
  22. init bar
  23. set Mode switch
  24. set Interface ping.test2
  25. set Port 32574
  26. EOF
  27. cat >$d2/tinc-up <<EOF
  28. #!/bin/sh
  29. ip netns add ping.test2
  30. ip link set dev \$INTERFACE netns ping.test2
  31. ip netns exec ping.test2 ip addr add 192.168.1.2/24 dev \$INTERFACE
  32. ip netns exec ping.test2 ip link set \$INTERFACE up
  33. EOF
  34. # Exchange configuration files
  35. $tinc $c1 export | $tinc $c2 exchange | $tinc $c1 import
  36. # Start tinc
  37. $tinc $c1 start $r1
  38. $tinc $c2 start $r2
  39. sleep 1
  40. # The nodes should not be able to ping each other if there is no connection
  41. ip netns exec ping.test1 ping -W1 -c3 192.168.1.2 && exit 1
  42. # After connecting they should be
  43. $tinc $c2 add ConnectTo foo
  44. sleep 1
  45. ip netns exec ping.test1 ping -W1 -c3 192.168.1.2
  46. # Clean up
  47. $tinc $c2 stop
  48. $tinc $c1 stop
  49. ip netns del ping.test2
  50. ip netns del ping.test1