test_wmediumd.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. # wmediumd sanity checks
  2. # Copyright (c) 2015, Intel Deutschland GmbH
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import tempfile, os, subprocess, errno, hwsim_utils
  7. from utils import HwsimSkip
  8. from test_ap_open import _test_ap_open
  9. from test_wpas_mesh import check_mesh_support, check_mesh_group_added
  10. from test_wpas_mesh import check_mesh_peer_connected, add_open_mesh_network
  11. from test_wpas_mesh import check_mesh_group_removed
  12. CFG = """
  13. ifaces :
  14. {
  15. ids = ["%s", "%s" ];
  16. links = (
  17. (0, 1, 30)
  18. );
  19. };
  20. """
  21. CFG2 = """
  22. ifaces :
  23. {
  24. ids = ["%s", "%s", "%s"];
  25. links = (
  26. (0, 1, 50),
  27. (0, 2, 50),
  28. (1, 2, -10)
  29. );
  30. };
  31. """
  32. def output_wmediumd_log(p, params, data):
  33. log_file = open(os.path.abspath(os.path.join(params['logdir'],
  34. 'wmediumd.log')), 'a')
  35. log_file.write(data)
  36. log_file.close()
  37. def start_wmediumd(fn, params):
  38. try:
  39. p = subprocess.Popen(['wmediumd', '-c', fn],
  40. stdout=subprocess.PIPE,
  41. stderr=subprocess.STDOUT)
  42. except OSError, e:
  43. if e.errno == errno.ENOENT:
  44. raise HwsimSkip('wmediumd not available')
  45. raise
  46. logs = ''
  47. while True:
  48. line = p.stdout.readline()
  49. if not line:
  50. output_wmediumd_log(p, params, logs)
  51. raise Exception('wmediumd was terminated unexpectedly')
  52. if line.find('REGISTER SENT!') > -1:
  53. break
  54. logs += line
  55. return p
  56. def stop_wmediumd(p, params):
  57. p.terminate()
  58. p.wait()
  59. stdoutdata, stderrdata = p.communicate()
  60. output_wmediumd_log(p, params, stdoutdata)
  61. def test_wmediumd_simple(dev, apdev, params):
  62. """test a simple wmediumd configuration"""
  63. fd, fn = tempfile.mkstemp()
  64. try:
  65. f = os.fdopen(fd, 'w')
  66. f.write(CFG % (apdev[0]['bssid'], dev[0].own_addr()))
  67. f.close()
  68. p = start_wmediumd(fn, params)
  69. try:
  70. _test_ap_open(dev, apdev)
  71. finally:
  72. stop_wmediumd(p, params)
  73. # test that releasing hwsim works correctly
  74. _test_ap_open(dev, apdev)
  75. finally:
  76. os.unlink(fn)
  77. def test_wmediumd_path_simple(dev, apdev, params):
  78. """test a mesh path"""
  79. # 0 and 1 is connected
  80. # 0 and 2 is connected
  81. # 1 and 2 is not connected
  82. # 1 --- 0 --- 2
  83. # | |
  84. # +-----X-----+
  85. # This tests if 1 and 2 can communicate each other via 0.
  86. fd, fn = tempfile.mkstemp()
  87. try:
  88. f = os.fdopen(fd, 'w')
  89. f.write(CFG2 % (dev[0].own_addr(), dev[1].own_addr(),
  90. dev[2].own_addr()))
  91. f.close()
  92. p = start_wmediumd(fn, params)
  93. try:
  94. _test_wmediumd_path_simple(dev, apdev)
  95. finally:
  96. stop_wmediumd(p, params)
  97. finally:
  98. os.unlink(fn)
  99. def _test_wmediumd_path_simple(dev, apdev):
  100. for i in range(0, 3):
  101. check_mesh_support(dev[i])
  102. add_open_mesh_network(dev[i], freq="2462", basic_rates="60 120 240")
  103. # Check for mesh joined
  104. for i in range(0, 3):
  105. check_mesh_group_added(dev[i])
  106. state = dev[i].get_status_field("wpa_state")
  107. if state != "COMPLETED":
  108. raise Exception("Unexpected wpa_state on dev" + str(i) + ": " + state)
  109. mode = dev[i].get_status_field("mode")
  110. if mode != "mesh":
  111. raise Exception("Unexpected mode: " + mode)
  112. # Check for peer connected
  113. check_mesh_peer_connected(dev[0])
  114. check_mesh_peer_connected(dev[0])
  115. check_mesh_peer_connected(dev[1])
  116. check_mesh_peer_connected(dev[2])
  117. # Test connectivity 1->2 and 2->1
  118. hwsim_utils.test_connectivity(dev[1], dev[2])
  119. # Check mpath table on 0
  120. res, data = dev[0].cmd_execute(['iw', dev[0].ifname, 'mpath', 'dump'])
  121. if res != 0:
  122. raise Exception("iw command failed on dev0")
  123. if data.find(dev[1].own_addr() + ' ' + dev[1].own_addr()) == -1 or \
  124. data.find(dev[2].own_addr() + ' ' + dev[2].own_addr()) == -1:
  125. raise Exception("mpath not found on dev0:\n" + data)
  126. if data.find(dev[0].own_addr()) > -1:
  127. raise Exception("invalid mpath found on dev0:\n" + data)
  128. # Check mpath table on 1
  129. res, data = dev[1].cmd_execute(['iw', dev[1].ifname, 'mpath', 'dump'])
  130. if res != 0:
  131. raise Exception("iw command failed on dev1")
  132. if data.find(dev[0].own_addr() + ' ' + dev[0].own_addr()) == -1 or \
  133. data.find(dev[2].own_addr() + ' ' + dev[0].own_addr()) == -1:
  134. raise Exception("mpath not found on dev1:\n" + data)
  135. if data.find(dev[2].own_addr() + ' ' + dev[2].own_addr()) > -1 or \
  136. data.find(dev[1].own_addr()) > -1:
  137. raise Exception("invalid mpath found on dev1:\n" + data)
  138. # Check mpath table on 2
  139. res, data = dev[2].cmd_execute(['iw', dev[2].ifname, 'mpath', 'dump'])
  140. if res != 0:
  141. raise Exception("iw command failed on dev2")
  142. if data.find(dev[0].own_addr() + ' ' + dev[0].own_addr()) == -1 or \
  143. data.find(dev[1].own_addr() + ' ' + dev[0].own_addr()) == -1:
  144. raise Exception("mpath not found on dev2:\n" + data)
  145. if data.find(dev[1].own_addr() + ' ' + dev[1].own_addr()) > -1 or \
  146. data.find(dev[2].own_addr()) > -1:
  147. raise Exception("invalid mpath found on dev2:\n" + data)
  148. # remove mesh groups
  149. for i in range(0, 3):
  150. dev[i].mesh_group_remove()
  151. check_mesh_group_removed(dev[i])
  152. dev[i].dump_monitor()