config.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Environment configuration
  2. # Copyright (c) 2016, Tieto Corporation
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. #
  7. # Currently static definition, in the future this could be a config file,
  8. # or even common database with host management.
  9. #
  10. import logging
  11. logger = logging.getLogger()
  12. #
  13. # You can put your settings in cfg.py file with setup_params, devices
  14. # definitions in the format as below. In other case HWSIM cfg will be used.
  15. #
  16. setup_params = { "setup_hw" : "./tests/setup_hw.sh",
  17. "hostapd" : "./tests/hostapd",
  18. "wpa_supplicant" : "./tests/wpa_supplicant",
  19. "iperf" : "iperf",
  20. "country" : "US",
  21. "log_dir" : "/tmp/",
  22. "ipv4_test_net" : "192.168.12.0",
  23. "trace_start" : "./tests/trace_start.sh",
  24. "trace_stop" : "./tests/trace_stop.sh",
  25. "perf_start" : "./tests/perf_start.sh",
  26. "perf_stop" : "./tests/perf_stop.sh" }
  27. #
  28. #devices = [{"hostname": "192.168.254.58", "ifname" : "wlan0", "port": "9877", "name" : "t2-ath9k", "flags" : "AP_HT40 STA_HT40"},
  29. # {"hostname": "192.168.254.58", "ifname" : "wlan1", "port": "9877", "name" : "t2-ath10k", "flags" : "AP_VHT80"},
  30. # {"hostname": "192.168.254.58", "ifname" : "wlan3", "port": "9877", "name" : "t2-intel7260", "flags" : "STA_VHT80"},
  31. # {"hostname": "192.168.254.55", "ifname" : "wlan0, wlan1, wlan2", "port": "", "name" : "t3-monitor"},
  32. # {"hostname": "192.168.254.50", "ifname" : "wlan0", "port": "9877", "name" : "t1-ath9k"},
  33. # {"hostname": "192.168.254.50", "ifname" : "wlan1", "port": "9877", "name" : "t1-ath10k"}]
  34. #
  35. # HWSIM - ifaces available after modprobe mac80211_hwsim
  36. #
  37. devices = [{"hostname": "localhost", "ifname": "wlan0", "port": "9868", "name": "hwsim0", "flags": "AP_VHT80 STA_VHT80"},
  38. {"hostname": "localhost", "ifname": "wlan1", "port": "9878", "name": "hwsim1", "flags": "AP_VHT80 STA_VHT80"},
  39. {"hostname": "localhost", "ifname": "wlan2", "port": "9888", "name": "hwsim2", "flags": "AP_VHT80 STA_VHT80"},
  40. {"hostname": "localhost", "ifname": "wlan3", "port": "9898", "name": "hwsim3", "flags": "AP_VHT80 STA_VHT80"},
  41. {"hostname": "localhost", "ifname": "wlan4", "port": "9908", "name": "hwsim4", "flags": "AP_VHT80 STA_VHT80"}]
  42. def get_setup_params(filename="cfg.py"):
  43. try:
  44. mod = __import__(filename.split(".")[0])
  45. return mod.setup_params
  46. except:
  47. logger.debug("__import__(" + filename + ") failed, using static settings")
  48. pass
  49. return setup_params
  50. def get_devices(filename="cfg.py"):
  51. try:
  52. mod = __import__(filename.split(".")[0])
  53. return mod.devices
  54. except:
  55. logger.debug("__import__(" + filename + ") failed, using static settings")
  56. pass
  57. return devices
  58. def get_device(devices, name=None, flags=None, lock=False):
  59. if name is None and flags is None:
  60. raise Exception("Failed to get device")
  61. for device in devices:
  62. if device['name'] == name:
  63. return device
  64. for device in devices:
  65. try:
  66. device_flags = device['flags']
  67. if device_flags.find(flags) != -1:
  68. return device
  69. except:
  70. pass
  71. raise Exception("Failed to get device " + name)
  72. def put_device(devices, name):
  73. pass