Commit a4e47b81074dc33347624b181ec235ae1a49f971

Authored by Ginés García
1 parent f301ed39

small changes

Showing 3 changed files with 224 additions and 1 deletions   Show diff stats
setup-wlan.py~ 0 → 100644
... ... @@ -0,0 +1,74 @@
  1 +import sys, os.path, threading, time
  2 +
  3 +# It Includes search_ap_data & configure_ap
  4 +import utils_ap
  5 +import utils_config
  6 +import utils_peers
  7 +
  8 +# Global Variables
  9 +threads = []
  10 +
  11 +utils_config.check_input_param(str(sys.argv[1]), str(sys.argv[2]), len(sys.argv))
  12 +
  13 +config_file_path = str(sys.argv[1])
  14 +peers_file_path = str(sys.argv[2])
  15 +
  16 +# Get all the information from json
  17 +ap_addr, bssid, rate, mac_ap, power, channel, video_nodes, data_nodes, mechanism = utils_config.get_config_from_json(config_file_path)
  18 +# Remove M from rate (Ej: 24M -> 24)
  19 +rate = rate[:-1]
  20 +b_size = 0
  21 +retries = 0
  22 +# Check selected mechanism and get extra data if needed
  23 +if utils_config.check_mechanism(mechanism) == "not_valid":
  24 + print "Mechanism not supported"
  25 + sys.exit()
  26 +elif mechanism == "UR":
  27 + retries = utils_config.get_specific_config(config_file_path,mechanism)
  28 +elif mechanism == "BLOCK_ACK":
  29 + b_size = utils_config.get_specific_config(config_file_path,mechanism)
  30 +
  31 +# Setting up AP and peers
  32 +if video_nodes > 0:
  33 +
  34 + # AP configuration
  35 + wlan0_ip, mac, wired_ip = utils_ap.search_ap_data(peers_file_path, ap_addr)
  36 + if (wlan0_ip == "EMPTY") or (mac == "EMPTY") or (wired_ip == "EMPTY"):
  37 + print "No configuration for the AP available on peers file."
  38 + sys.exit()
  39 + else:
  40 + utils_ap.reload_ap(ap_addr)
  41 + utils_ap.set_mechanism(ap_addr, mechanism, rate, b_size, retries)
  42 + utils_ap.start_ap(ap_addr, wlan0_ip, rate, channel, power)
  43 +
  44 + # Check ap configuration
  45 + ap_status = utils_ap.check_ap(ap_addr, wlan0_ip)
  46 + if ap_status != "ok":
  47 + print "AP not configured correctly. Problems with %s" % ap_status
  48 + sys.exit()
  49 + else:
  50 + print "AP configured"
  51 +
  52 + # Peers Configuration
  53 + #utils_peers.configure_peers(peers_file_path, ap_addr, bssid, rate, power, channel, mechanism)
  54 +'''
  55 + index = 0
  56 + with open(peers_file_path) as peers_file_opened:
  57 + for peer in peers_file_opened:
  58 + peer = peer.split()
  59 + peer_ip = peer[0]
  60 + peer_mac = peer[1]
  61 + peer_ip_wired = peer[2]
  62 +
  63 + if peer_ip_wired != ap_addr:
  64 + index = index+1
  65 + thr_name = "thread_%d" % index
  66 + t = threading.Thread(target=utils_peers.configure_peer, name=thr_name, args=(peer_ip, peer_ip_wired, bssid, rate, power, channel, mechanism))
  67 + threads.append(t)
  68 + t.start()
  69 + time.sleep(0.005)
  70 +
  71 + for thread in threads:
  72 + t.join()
  73 + print "Configuration process end"
  74 +'''
... ...
utils_ap.py
... ... @@ -53,7 +53,7 @@ def set_mechanism(ap_addr, mechanism, rate, b_size, retries):
53 53 if mechanism == "BLOCK_ACK":
54 54 set_block_ack(ap_addr, rate, b_size)
55 55 elif mechanism == "DMS":
56   - set_dms()
  56 + set_dms(ap_addr, rate)
57 57 elif mechanism == "UR":
58 58 set_ur(ap_addr, rate, retries)
59 59 elif mechanism == "LEGACY":
... ...
utils_ap.py~ 0 → 100644
... ... @@ -0,0 +1,149 @@
  1 +import os
  2 +import utils_config ## incluse ssh command execution method
  3 +
  4 +# Global variables
  5 +path_module_b43 = "/lib/modules/2.6.36/kernel/drivers/net/wireless"
  6 +path_module_80211 = "/lib/modules/2.6.36/kernel/net/mac80211"
  7 +path_firm_b43_blockack = "/lib/firmware/b43.video/firmware.blockack"
  8 +
  9 +# Get ap data from peers file
  10 +# - Input: Path to peers file and wired ip where AP is located
  11 +# - Output: peer[0] (wlan0 ip - 192.168.98.1), peer[1] (mac address), peer[2] (wired ip - 192.168.97.1)
  12 +def search_ap_data(peers_file, ap_addr):
  13 + with open(peers_file) as peers_file_opened:
  14 + for peer in peers_file_opened:
  15 + if ap_addr in peer:
  16 + peer = peer.split()
  17 + return peer[0], peer[1], peer[2]
  18 +
  19 + return "EMPTY", "EMPTY", "EMPTY"
  20 +
  21 +
  22 +# Reload all the modules needed by the ap
  23 +# - Input: ap_addr
  24 +def reload_ap(ap_addr):
  25 + print "Reload AP modules using wired ip -> %s" % ap_addr
  26 +
  27 + hostapd_pids = utils_config.exec_command_ssh(ap_addr, "pgrep -x hostapd")
  28 + if hostapd_pids != "ERROR":
  29 + for pid in hostapd_pids:
  30 + pid = int(pid)
  31 + utils_config.exec_command_ssh(ap_addr, ("kill -SIGTERM %d" % pid))
  32 + print "Process hostapd (pid = %d) killed" % pid
  33 +
  34 + print "Reconfiguring Interface ..."
  35 + utils_config.exec_command_ssh(ap_addr, "rmmod ath9k && sleep 0.5")
  36 + utils_config.exec_command_ssh(ap_addr, "rmmod mac80211")
  37 + utils_config.exec_command_ssh(ap_addr, "rmmod b43")
  38 +
  39 + utils_config.exec_command_ssh(ap_addr, "rm /lib/firmware/b43")
  40 + utils_config.exec_command_ssh(ap_addr, ("rm %s/b43/b43.ko" % path_module_b43))
  41 + utils_config.exec_command_ssh(ap_addr, ("rm %s/b43" % path_module_b43))
  42 + utils_config.exec_command_ssh(ap_addr, ("rm %s/mac80211.ko" % path_module_80211))
  43 +
  44 + utils_config.exec_command_ssh(ap_addr, ("ln -s %s/mac80211.video.ko %s/mac80211.ko" % (path_module_80211, path_module_80211)))
  45 + utils_config.exec_command_ssh(ap_addr, "modprobe mac80211")
  46 + utils_config.exec_command_ssh(ap_addr, ("ln -s %s/b43.video %s/b43" % (path_module_b43, path_module_b43)))
  47 +
  48 +# Enable the required modules according to the selected mechanism
  49 +# - Input: AP address, mechanism and rate. In addition b_size or retries if mechanism is BLOCK_ACK or UR
  50 +def set_mechanism(ap_addr, mechanism, rate, b_size, retries):
  51 + print "Mechanism %s selected for the AP. Loading modules ..." % mechanism
  52 +
  53 + if mechanism == "BLOCK_ACK":
  54 + set_block_ack(ap_addr, rate, b_size)
  55 + elif mechanism == "DMS":
  56 + set_dms()
  57 + elif mechanism == "UR":
  58 + set_ur(ap_addr, rate, retries)
  59 + elif mechanism == "LEGACY":
  60 + set_legacy(ap_addr, rate)
  61 +
  62 +# Check if all the configuration is correctly set
  63 +# - Input: AP address
  64 +def check_ap(ap_addr, wlan0_ip):
  65 + print "Checking AP ..."
  66 + if utils_config.exec_command_ssh(ap_addr, "pgrep -x hostapd") == "ERROR":
  67 + return "hostapd"
  68 + elif utils_config.exec_command_ssh(ap_addr, "modprobe -l | grep mac80211.ko") == "ERROR":
  69 + return "mac80211"
  70 + elif utils_config.exec_command_ssh(ap_addr, "modprobe -l | grep b43.ko") == "ERROR":
  71 + return "b43"
  72 + else:
  73 + ap_status = utils_config.check_ping(wlan0_ip)
  74 + if ap_status != "ok":
  75 + return "ERROR"
  76 + else:
  77 + return "ok"
  78 +
  79 +# Load modules in order to enable BLOCK_ACK mechanism
  80 +# - Input: AP wired address, rate and b_size
  81 +def set_block_ack(ap_addr, rate, b_size):
  82 + utils_config.exec_command("cp %s/%s/ucode5.back-%s.fw %s/ucode5.fw" % (path_firm_b43_blockack, rate, b_size, path_firm_b43_blockack))
  83 + # DMA
  84 + #utils_config.exec_command_ssh(ap_addr, ("cp %s/%s/ucode5.back-%s.fw.dma %s/ucode5.fw" % (path_firm_b43_blockack, rate, b_size, path_firm_b43_blockack)))
  85 + utils_config.exec_command_ssh(ap_addr, "cp %s/%s/ucode5.back-%s.fw %s/ucode5.fw" % (path_firm_b43_blockack, rate, b_size, path_firm_b43_blockack))
  86 + # END DMA
  87 +
  88 + utils_config.exec_command_ssh(ap_addr, "ln -s %s /lib/firmware/b43" % path_firm_b43_blockack)
  89 + utils_config.exec_command_ssh(ap_addr, "ln -s %s/b43/b43.rate-adaptation.ko %s/b43/b43.ko" % (path_module_b43, path_module_b43))
  90 + #utils_config.exec_command_ssh(ap_addr, "ln -s %s/b43/b43.blockack.ko %s/b43/b43.ko" % (path_module_b43, path_module_b43))
  91 +#PABLO
  92 +# ATTENTION: frate=1 implies the transmission rate is fixed, so no rate controller
  93 + utils_config.exec_command_ssh(ap_addr, "modprobe b43 qos=1 aseq=1 frate=0 bsize=%s brate=%s && sleep 0.5" % (b_size, rate))
  94 +
  95 +
  96 +# Load modules in order to enable DMS mechanism
  97 +# - Input: AP wired address and rate
  98 +def set_dms(ap_addr, rate):
  99 + utils_config.exec_command_ssh(ap_addr, "ln -s /lib/firmware/b43.video/firmware.dms /lib/firmware/b43")
  100 + utils_config.exec_command_ssh(ap_addr, "ln -s %s/b43/b43.dms.ko %s/b43/b43.ko" % (path_module_b43, path_module_b43))
  101 + utils_config.exec_command_ssh(ap_addr, "modprobe b43 qos=0 brate=%s && sleep 0.5" % rate)
  102 +
  103 +
  104 +# Load modules in order to enable UR mechanism
  105 +# - Input: AP wired address, rate and retries
  106 +def set_ur(ap_addr, rate, retries):
  107 + utils_config.exec_command_ssh(ap_addr, "ln -s /lib/firmware/b43.video/firmware.ur /lib/firmware/b43")
  108 + utils_config.exec_command_ssh(ap_addr, "rm /lib/firmware/b43.video/firmware.ur/ucode5.fw")
  109 + utils_config.exec_command_ssh(ap_addr, "ln -s /lib/firmware/b43.video/firmware.ur/ucode5.ur-%s.fw /lib/firmware/b43/ucode5.fw" % retries)
  110 + utils_config.exec_command_ssh(ap_addr, "ln -s %s/b43/b43.ur.ko %s/b43/b43.ko" % (path_module_b43, path_module_b43))
  111 + utils_config.exec_command_ssh(ap_addr, "modprobe b43 qos=1 brate=%s && sleep 0.5" % rate)
  112 +
  113 +
  114 +# Load modules in order to enable LEGACY mechanism
  115 +# - Input: AP wired address and rate
  116 +def set_legacy(ap_addr, rate):
  117 + utils_config.exec_command_ssh(ap_addr, "ln -s /lib/firmware/b43.video/firmware.dms /lib/firmware/b43")
  118 + utils_config.exec_command_ssh(ap_addr, "ln -s %s/b43/b43.dms.ko %s/b43/b43.ko" % (path_module_b43, path_module_b43))
  119 + utils_config.exec_command_ssh(ap_addr, "modprobe b43 qos=0 brate=%s && sleep 0.5" % rate)
  120 +
  121 +# Starts AP with the given configuration and set up wlan0
  122 +# - Input: Input: AP address, rate, channel and power that we want to stablish in the AP
  123 +def start_ap(ap_addr, wlan0_ip, rate, channel, power):
  124 + print "Starting AP on %s with rate = %s, power = %s " % (wlan0_ip, rate, power)
  125 + utils_config.exec_command_ssh(ap_addr, "ifconfig wlan0 %s up" % wlan0_ip)
  126 + utils_config.exec_command_ssh(ap_addr, "iw reg set JP")
  127 +
  128 + #print "Running hostapd and setting his configuration and log file"
  129 + utils_config.exec_command_ssh(ap_addr, ("cp $PWD/hostapd-minimal-R %s-%s.conf $PWD/hostapd-minimal.conf" % (rate, channel)))
  130 + utils_config.exec_command_ssh(ap_addr, "$PWD/hostapd -ddd $PWD/hostapd-minimal.conf > $PWD/hostap.log &")
  131 + # utils_config.exec_command_ssh(ap_addr, "hostapd -B /root/hostapd-minimal.conf")
  132 +
  133 + #print "Configuring Rate and TX Power"
  134 + utils_config.exec_command_ssh(ap_addr, ("iwconfig wlan0 rate %s fixed txpower %s fixed" % (rate, power)))
  135 +
  136 + #print "Configuring multicast route"
  137 + utils_config.exec_command_ssh(ap_addr, "route add -host 224.0.0.1 wlan0")
  138 +
  139 + #print "Setting arp table"
  140 + #utils_config.exec_command_ssh(ap_addr, "$PWD/setarp.sh $PATH_AP")
  141 +
  142 +
  143 +
  144 +
  145 +
  146 +
  147 +
  148 +
  149 +
... ...