Example #1
0
    def prepare_run(self, obj):
        print("# Prepare run")
        # Apply received configurations
        if not self.setup.apply_setup(obj.run_info):
            self.report(interface.node(interface.PREPARE_ERROR, error=self.setup.error))

        # Inform the sampler about the new run
        if not self.sampler.set_run_info(obj.run_info):
            print(self.sampler.error)
            self.report(interface.node(interface.PREPARE_ERROR, error=self.sampler.error))

        # (Re)start iperf server
        if self.tester_server:
            self.tester_server.kill()
        self.tester_server = tester.server(self.server.args, obj.run_info)

        # Wait for previous iperf clients to finish
        for client in self.tester_clients:
            print("  Waiting for clients")
            client.join()

        # Prepare new iperf client threads
        self.tester_clients = []
        for node in obj.dests:
            client = tester.client(self, node, obj.run_info)
            self.tester_clients.append(client)

        # Report back to controller that we are ready
        self.report(interface.node(interface.PREPARE_DONE))
        print("  Prepare done")
Example #2
0
    def python_server(self):
        l = str(self.iperf_len)
        p = os.path.dirname(self.args.udp_path) + "/udp_server.py"
        self.cmd = [p, l, "1"]

        print("  Starting server: {}".format(self.cmd))
        self.p = subprocess.Popen(self.cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
        self.running = True
        self.p.wait()
        self.running = False

        (stdout,stderr) = self.p.communicate()

        if stderr:
            obj = interface.node(interface.RUN_ERROR, error=stderr)
            self.controller.report(obj)
            return
        elif not stdout:
            obj = interface.node(interface.RUN_ERROR, error="no server result")
            self.controller.report(obj)
            return

        result = {}
        for line in stdout.splitlines():
            key,val = line.split(": ")
            result[key] = float(val)
        
        if result:
            obj = interface.node(interface.RUN_RESULT, result=result)
            self.controller.report(obj)
        else:
            obj = interface.node(interface.RUN_ERROR, error="empty server result")
            self.controller.report(obj)
Example #3
0
    def finish_run(self, obj):
        print("# Finish run")
        
        if self.run_info['profile'] in ( 'udp_rates', 'power_meas','udp_ratios','hold_times','tcp_algos','tcp_windows','rlnc'): #RASP! NEW_TEST!
            self.send_sample(finish=True)
        elif self.run_info['profile'] in ('rasp_rank', 'rasp_symbols_sweep','rasp_link_quality'):
            pass

        if self.run_info and self.run_info['coding'] == 'helper' and not self.setup.check_fox():
            err = interface.node(interface.RUN_ERROR, error="fox failed")
            self.report(err)
            return

        if self.run_info and self.run_info['coding'] == 'nohelper' and self.run_info['role'] != 'helper' and not self.setup.check_fox():
            err = interface.node(interface.RUN_ERROR, error="fox failed")
            self.report(err)
            return
        
        print('# Stop client')    
        for client in self.tester_clients:
            client.stop() #INTEREST!

        # Report back to controller that we are done
        time.sleep(report_sleep) #TIME!
        self.report(interface.node(interface.FINISH_DONE))
        print("# report FINISH_DONE")#DEBUG!
Example #4
0
    def send_sample(self, finish=False):
        try:
            sample = {'timestamp': time.time()}

            # Sample bat stats
            print("  Sample bat stats")
            cmd = ["batctl", "s"]
            p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
            p.wait()
            nc,d = p.communicate()

            # Sample iw
            print("  Sample iw")
            cmd = ["iw", "dev", self.server.args.wifi_iface, "station", "dump"]
            p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
            p.wait()
            iw,d = p.communicate()

            # Sample cpu
            print("  Sample cpu")
            cpu = open("/proc/stat").read()

            # Sample fox
            if finish:
                fox = self.sample_fox()
            else:
                fox = ""

            print("  Send sample")
            sample = interface.node(interface.SAMPLE, sample=sample, nc=nc, iw=iw, cpu=cpu, fox=fox)
            self.report(sample)
        except Exception as e:
            err = interface.node(interface.SAMPLE_ERROR, error=e)
            self.report(err)
Example #5
0
    def rasp_server(self):
        #ADD_ARG!
        #l = str(self.iperf_len)
        p = os.path.dirname(self.args.rasp_udp_path) + self.args.program #DUMMY_TEST! #LOCAL_TEST!
        #p = os.path.dirname(self.args.rasp_udp_path) + "/dummy_dest_5"
        print self.run_info
        #print "meshport server:", self.args.mesh_port
        #print "port server:",self.args.port
        
        f = "--field=" + str(self.run_info['field'])
        i = "--iteration=" + str(self.run_info['test_num'])
        s = "--symbols=" + str(self.run_info['symbols'])
        l = "--symbol_size=" + str(self.run_info['packet_size'])
        r = "--rate=" + str(self.run_info['rate'])
        g = "--port=" + str(self.args.mesh_port)
        t = "--type=" + 'destination'
        d = "--format=" + "python"
        q = "--linkquality=" + self.run_info['linkquality'] #LOCAL_TEST!
        n = "--id=" + str(self.run_info['id']) #LOCAL_TEST!
        #d = "--output=" + "python
        self.cmd = [p, f, i, s, l, r, g, t, d, q, n]#LOCAL_TEST!
        
        print("  Starting server: {}".format(self.cmd)) #DEBUG!
        
        self.p = subprocess.Popen(self.cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
        self.running = True
        """
        print "# Begin program"
        while self.p.poll() is None:
            pass
        print "# End program"
        """
        self.p.wait() #DEBUG_HYPO!
        self.running = False
        
        print("server done")
        (stdout,stderr) = self.p.communicate()
        print stdout
        if stderr:
            obj = interface.node(interface.RUN_ERROR, error=stderr)
            self.controller.report(obj)
            return
        elif not stdout:
            print("Error: No result from destination")
            obj = interface.node(interface.RUN_ERROR, error="no server result")
            self.controller.report(obj)
            return
        
        result = eval(stdout)

        if result:
            #if randint(1,10) < 3:
            #    time.sleep(40)#LOCAL_TEST!
            obj = interface.node(interface.RUN_RESULT, result=result)
            self.controller.report(obj)
            print("# Result is send ")
        else:
            obj = interface.node(interface.RUN_ERROR, error="empty server result")
            self.controller.report(obj)
Example #6
0
 def send_dummy_result(self): #RASP!
     try:
         if self.run_info['role'] == 'helper':
             #print("  Sending dummy result")
             time.sleep(report_sleep) #TIME!
             obj = interface.node(interface.RUN_RESULT, result=None)
             self.report(obj)
     except AttributeError as e:
         time.sleep(report_sleep) #TIME!
         obj = interface.node(interface.RUN_ERROR, error=e)
         self.report(obj)
         print("  Run error: " + e)
     else:
         print("  Run done")
Example #7
0
 def rasp_send_dummy_result(self):
     try:
         if self.run_info['role'] == 'source':
             print('# Sending dummy result') #DEBUG!
             time.sleep(report_sleep) #TIME!
             obj = interface.node(interface.RUN_RESULT, result=None)
             self.report(obj)
             print("# report RUN_RESULT") #DEBUG!
     except AttributeError as e:
         time.sleep(report_sleep) #TIME!
         obj = interface.node(interface.RUN_ERROR, error=e)
         self.report(obj)
         print("  Run error: " + e)
     else:
         print("  Run done")
Example #8
0
    def report_samples(self):
        self.samples['timestamp'] = time.time()
        obj = interface.node(interface.SAMPLE, sample=self.samples)
        self.controller.report(obj)

        # Reset our samples before a new run
        self.samples = {}
Example #9
0
 def send_node_info(self):
     args = self.server.args
     if os.path.exists("/sys/class/net/{}/address".format(args.wifi_iface)):
         mac = open("/sys/class/net/{}/address".format(args.wifi_iface)).read()
     else:
         mac = None
     obj = interface.node(interface.NODE_INFO, mesh_host=args.mesh_host, mesh_port=args.mesh_port, mesh_mac=mac)
     self.report(obj)
     print("# report NODE_INFO")
Example #10
0
    def start_run(self, obj):
        print("# Start run")
        for client in self.tester_clients:
            client.start()

        # If no clients exists, we don't want the controller to
        # wait for us, so we send an empty result immediately.
        if not self.tester_clients:
            print("  Sending dummy result")
            obj = interface.node(interface.RUN_RESULT, result=None)
            self.report(obj)
        print("  Run done")
Example #11
0
    def run(self):
        l = str(self.iperf_len)
        c = str(self.run_info['gen_size'])
        p = os.path.join(self.args.udp_path, "udp_server.py")
        self.cmd = [p, l, c, "1"]

        print("  Starting server: {}".format(self.cmd))
        try:
            self.p = subprocess.Popen(self.cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
        except OSError as e:
            obj = interface.node(interface.RUN_ERROR, error=e.message + ":" + " ".join(self.cmd))
            self.controller.report(obj)
            return

        self.running = True
        self.p.wait()
        self.running = False

        (stdout,stderr) = self.p.communicate()

        if stderr:
            obj = interface.node(interface.RUN_ERROR, error=stderr)
            self.controller.report(obj)
            return
        elif not stdout:
            obj = interface.node(interface.RUN_ERROR, error="no server result")
            self.controller.report(obj)
            return

        result = {"role": "dst"}
        for line in stdout.splitlines():
            key,val = line.split(": ")
            result[key] = float(val)

        if result:
            obj = interface.node(interface.RUN_RESULT, result=result)
            self.controller.report(obj)
        else:
            obj = interface.node(interface.RUN_ERROR, error="empty server result")
            self.controller.report(obj)
Example #12
0
    def finish_run(self, obj):
        print("# Finish run")
        for client in self.tester_clients:
            print("  Killing client")
            client.kill_client()

        if self.tester_server:
            print("  Killing server")
            self.tester_server.kill()

        # Report back to controller that we are done
        self.report(interface.node(interface.FINISH_DONE))
        print("  Finish done")
Example #13
0
    def prepare_run(self, obj):
        print("# Prepare run")
        self.run_info = obj.run_info #run info sendt from riddler controller

        # Apply received configuration
        if not self.setup.apply_setup(obj.run_info):
            self.report(interface.node(interface.PREPARE_ERROR, error=self.setup.error)) # Had a setup error
        # Inform the sampler about the new run
        #if not self.sampler.set_run_info(obj.run_info):
        #    print(self.sampler.error)
        #    self.report(interface.node(interface.PREPARE_ERROR, error=self.sampler.error))

        # (Re)start iperf server
        if self.tester_server: #Kills any remaining tester servers
            self.tester_server.kill()
        
        #INDIVIDUAL_NODE!
        
        if self.run_info['role'] == "destination": #if the node is a destination
            self.tester_server = tester.server(self, self.server.args, obj.run_info)
        
        # Wait for previous iperf clients to finish
        for client in self.tester_clients:
            print("#  Waiting for clients to finish")
            client.stop()#INTEREST!

        # Prepare new iperf client threads
        self.tester_clients = []
        for node in obj.dests:
            client = tester.client(self, node, obj.run_info, self.server.args)
            self.tester_clients.append(client)
            if self.run_info['profile'] in ('rasp_rank', 'rasp_symbols_sweep','rasp_link_quality'): #RASP! #ADD_TEST! #NEW_TEST! #only one source is needed
                break

        # Report back to controller that we are ready
        time.sleep(1) #TIME!
        self.report(interface.node(interface.PREPARE_DONE)) #reporting to the controller that the node is ready
        print("# report  PREPARE_DONE") #DEBUG!
Example #14
0
    def start_run(self, obj):
        print("# Start run")

        self.send_sample()

        for client in self.tester_clients:
            client.start()

        # If no clients exists, we don't want the controller to
        # wait for us, so we send an empty result immediately.
        try:
            if self.run_info['role'] == 'helper':
                print("  Sending dummy result")
                time.sleep(1)
                obj = interface.node(interface.RUN_RESULT, result=None)
                self.report(obj)
        except AttributeError as e:
            time.sleep(1)
            obj = interface.node(interface.RUN_ERROR, error=e)
            self.report(obj)
            print("  Run error: " + e)
        else:
            print("  Run done")
Example #15
0
    def finish_run(self, obj):
        print("# Finish run")
        self.send_sample(finish=True)

#        if self.run_info and self.run_info['coding'] == 'helper' and not self.setup.check_fox():
#            err = interface.node(interface.RUN_ERROR, error="fox failed")
#            self.report(err)
#            return
#
#        if self.run_info and self.run_info['coding'] == 'nohelper' and self.run_info['role'] != 'helper' and not self.setup.check_fox():
#            err = interface.node(interface.RUN_ERROR, error="fox failed")
#            self.report(err)
#            return

        # Report back to controller that we are done
        time.sleep(1)
        self.report(interface.node(interface.FINISH_DONE))
        print("  Finish done")
Example #16
0
 def report_error(self, error):
     print(error)
     obj = interface.node(interface.SAMPLE_ERROR, error = error)
     self.controller.report(obj)
Example #17
0
 def send_node_info(self):
     args = self.server.args
     mac = open("/sys/class/net/{}/address".format(args.wifi_iface)).read()
     obj = interface.node(interface.NODE_INFO, mesh_host=args.mesh_host, mesh_port=args.mesh_port, mesh_mac=mac)
     self.report(obj)
Example #18
0
 def send_node_info(self):
     args = self.server.args
     output = interface.exec_cmd(["batctl", "o"])
     mac = re.findall("((?:[0-9a-f]{2}:){5}[0-9a-f]{2})", output)[0]
     obj = interface.node(interface.NODE_INFO, mesh_host=args.mesh_host, mesh_port=args.mesh_port, mesh_mac=mac)
     self.report(obj)
Example #19
0
 def report_error(self, error):
     #print error
     print("  Reporting error")
     obj = interface.node(interface.RUN_ERROR, error=error)
     self.controller.report(obj)
Example #20
0
 def report_result(self, result):
     obj = interface.node(interface.RUN_RESULT, result=result)
     self.controller.report(obj)
     print("# report  RUN_RESULT")
Example #21
0
 def report_result(self, result):
     print("  Reporting result")
     obj = interface.node(interface.RUN_RESULT, result=result)
     self.controller.report(obj)