netns_comm.sh 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/sh
  2. #==============================================================================
  3. # Copyright (c) 2015 Red Hat, Inc.
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of version 2 the GNU General Public License as
  7. # published by the Free Software Foundation.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #
  17. # Written by Matus Marhefka <mmarhefk@redhat.com>
  18. #
  19. #==============================================================================
  20. #
  21. # SYNOPSIS:
  22. # netns_comm.sh <NS_EXEC_PROGRAM> <IP_VERSION> <COMM_TYPE>
  23. #
  24. # OPTIONS:
  25. # * NS_EXEC_PROGRAM (ns_exec|ip)
  26. # Program which will be used to enter and run other commands
  27. # inside a network namespace.
  28. # * IP_VERSION (ipv4|ipv6)
  29. # Version of IP. (ipv4|ipv6)
  30. # * COMM_TYPE (netlink|ioctl)
  31. # Communication type between kernel and user space
  32. # for basic setup: enabling and assigning IP addresses
  33. # to the virtual ethernet devices. (Uses 'ip' command for netlink
  34. # and 'ifconfig' for ioctl.)
  35. #
  36. # Tests that a separate network namespace can configure and communicate
  37. # over the devices it sees. Tests are done using netlink(7) ('ip' command)
  38. # or ioctl(2) ('ifconfig' command) for controlling devices.
  39. #
  40. # There are three test cases:
  41. # 1,2. communication over paired veth (virtual ethernet) devices
  42. # from two different network namespaces (each namespace has
  43. # one device)
  44. # 3. communication over the lo (localhost) device in a separate
  45. # network namespace
  46. #==============================================================================
  47. TCID="netns_comm_$1_$2_$3"
  48. TST_TOTAL=3
  49. . netns_helper.sh
  50. # SETUP
  51. netns_setup $1 $2 $3 "192.168.0.2" "192.168.0.3" "fd00::2" "fd00::3"
  52. tst_resm TINFO "NS interaction: $1 | devices setup: $3"
  53. # TEST CASE #1
  54. $NS_EXEC $NS_HANDLE0 $NS_TYPE $tping -q -c2 -I veth0 $IP1 1>/dev/null
  55. if [ $? -eq 0 ]; then
  56. tst_resm TPASS "configuration and communication over veth0"
  57. else
  58. tst_resm TFAIL "configuration and communication over veth0"
  59. fi
  60. # TEST CASE #2
  61. $NS_EXEC $NS_HANDLE1 $NS_TYPE $tping -q -c2 -I veth1 $IP0 1>/dev/null
  62. if [ $? -eq 0 ]; then
  63. tst_resm TPASS "configuration and communication over veth1"
  64. else
  65. tst_resm TFAIL "configuration and communication over veth1"
  66. fi
  67. # TEST CASE #3
  68. case "$2" in
  69. ipv4) IP_LO="127.0.0.1" ;;
  70. ipv6) IP_LO="::1" ;;
  71. esac
  72. case "$3" in
  73. netlink)
  74. $NS_EXEC $NS_HANDLE0 $NS_TYPE ip link set dev lo up || \
  75. tst_brkm TBROK "enabling lo device failed"
  76. ;;
  77. ioctl)
  78. $NS_EXEC $NS_HANDLE0 $NS_TYPE ifconfig lo up || \
  79. tst_brkm TBROK "enabling lo device failed"
  80. ;;
  81. esac
  82. $NS_EXEC $NS_HANDLE0 $NS_TYPE $tping -q -c2 -I lo $IP_LO 1>/dev/null
  83. if [ $? -eq 0 ]; then
  84. tst_resm TPASS "configuration and communication over localhost"
  85. else
  86. tst_resm TFAIL "configuration and communication over localhost"
  87. fi
  88. tst_exit