setup-wlan.py 2.24 KB
import sys, os.path, threading, time

# It Includes search_ap_data & configure_ap
import utils_ap
import utils_config
import utils_peers

# Global Variables
threads = []

utils_config.check_input_param(str(sys.argv[1]), str(sys.argv[2]), len(sys.argv))

config_file_path = str(sys.argv[1])
peers_file_path = str(sys.argv[2])

# Get all the information from json
ap_addr, bssid, rate, mac_ap, power, channel, video_nodes, data_nodes, mechanism = utils_config.get_config_from_json(config_file_path)
# Remove M from rate (Ej: 24M -> 24)
rate = rate[:-1]
b_size = 0
retries = 0
# Check selected mechanism and get extra data if needed
if utils_config.check_mechanism(mechanism) == "not_valid":
	print "Mechanism not supported"
	sys.exit()
elif mechanism == "UR":
	retries = utils_config.get_specific_config(config_file_path,mechanism)
elif mechanism == "BLOCK_ACK":
	b_size = utils_config.get_specific_config(config_file_path,mechanism)

# Setting up AP and peers
if video_nodes > 0:

	# AP configuration
	wlan0_ip, mac, wired_ip = utils_ap.search_ap_data(peers_file_path, ap_addr)
	if (wlan0_ip == "EMPTY") or (mac == "EMPTY") or (wired_ip == "EMPTY"):
		print "No configuration for the AP available on peers file."
		sys.exit()
	else:
		utils_ap.reload_ap(ap_addr)
		utils_ap.set_mechanism(ap_addr, mechanism, rate, b_size, retries)
		utils_ap.start_ap(ap_addr, wlan0_ip, rate, channel, power)

		# Check ap configuration	
		ap_status = utils_ap.check_ap(ap_addr, wlan0_ip)
		if ap_status != "ok":
			print "AP not configured correctly. Problems with %s" % ap_status
			sys.exit()
		else:
			print "AP configured"

	# Peers Configuration
	#utils_peers.configure_peers(peers_file_path, ap_addr, bssid, rate, power, channel, mechanism)
'''
	index = 0
	with open(peers_file_path) as peers_file_opened:
		for peer in peers_file_opened:
			peer = peer.split()
			peer_ip = peer[0]
			peer_mac = peer[1]
			peer_ip_wired = peer[2]

			if peer_ip_wired != ap_addr:
				index = index+1
				thr_name = "thread_%d" % index
				t = threading.Thread(target=utils_peers.configure_peer, name=thr_name, args=(peer_ip, peer_ip_wired, bssid, rate, power, channel, mechanism))
				threads.append(t)
				t.start()
				time.sleep(0.005)

	for thread in threads:
		t.join()
	print "Configuration process end"
'''