Пример #1
0
def assignMasterSlave(robot1, robot2):

    if robot1.type == robot2.type:
        printc("On ne peut pas permuter 2 " + robot2.type, 'Fail')

    if robot1.type == "Slave":
        slave = Slave(robot1.s, robot1.hostname)
        master = Master(robot2.s, robot2.hostname)
    else:
        slave = Slave(robot2.s, robot2.hostname)
        master = Master(robot1.s, robot1.hostname)
    return master, slave
Пример #2
0
    def run(self):
        nb_stack = 0
        nb_slave = 0
        value = 1
        
        while True:

            print("Broadcasting cpu request")
            self.__udp_comm.broadcast(self.__commands.get_index("cpu")+";", self.__master.get_cluster_ip_addresses())
            
            data, addr = self.__udp_comm.receive(1024)    
            print("received message: {} from {}".format(data, addr))
                            
            print(data[:-1])
            if data[:-1] == b"configure;":#To-Do: check why data is bstr
                if(nb_slave <= 5):
                    stack = self.__master.get_stack(nb_stack)
                    #To-do : check for ip_address conflict, implement some kind of simple DHCP. May look for DHCP Py libs
                    new_slave = Slave(nb_stack + RASP_CLASS_ADDRESSES[int(data[10:])-1], nb_stack, "AA:AA:AA:AA:AA:AA", addr[0], int(data.decode().split(";")[1]))
                    self.__master.get_stack(nb_stack).add_pi_device(new_slave)
                    value = value + 1
                    self.__udp_comm.send(self.__commands.get_index("configure") + ";" + addr[0] + ";", new_slave.get_ip_address())
                    print("Configured new slave of ip_addr {}".format(addr[0]))
                    nb_slave = nb_slave + 1
                else:
                    nb_stack = nb_stack + 1
                    new_stack = Stack(nb_stack, nb_stack)
                    self.__master.add_stack(new_stack)
                    nb_slave = 0


            elif data[:4] == b"cpu;":
                cpu_value = data.decode().split(";")[1]
                self.__master.get_slave_by_ip(addr[0]).set_cpu_usage(cpu_value)
                value = value + 1
                print("Received cpu_usage ({}) from slave {}, updating value".format(addr[0], cpu_value))
Пример #3
0
 def GetStations(self):
     if (not self.isLoggedIn):
         raise Exception("You are not logged in")
     try:
         slaves = []
         r = requests.get(self.address + "/GetStations",
                          cookies=self.jar,
                          timeout=1)
         stations = json.loads(r.text)
         stations = stations["stations"]
         for station in stations:
             slaves.append(
                 Slave(int(station["StationID"]), station["Name"],
                       int(station["refTime"]), station["enableSettings"]))
     except RequestException as e:
         raise Exception(str(e))
     except Exception as e:
         raise Exception("Error occurred during slaves loading")
     else:
         return slaves
Пример #4
0
    def Machine(self, mtype, ip_port, clock_time, logs_file, **kwargs):
        i = 0
        if mtype is 'm':
            master = Master(ip_port, clock_time, logs_file, kwargs['d'],
                            kwargs['slaves_file'])
            while True:
                i += 1
                print("Execution ", i)
                master.get_slaves_time()
                master.calculate_time()
                time.sleep(5)

        elif mtype is 's':
            slave = Slave(ip_port, clock_time, logs_file)
            from rpyc.utils.server import ThreadedServer
            print("Slave machine")
            t = ThreadedServer(slave,
                               port=int(ip_port[ip_port.index(':') + 1:]))
            t.start()
        else:
            print("Option not available")
Пример #5
0
 def __init__(self):
     self.master = Master()
     self.slave = Slave()
Пример #6
0
class Simulation(object):
    def __init__(self):
        self.master = Master()
        self.slave = Slave()

    def start_simulation(self):
        detections = 0
        numOfDetections = 4000
        timeArray = np.arange(numOfDetections)

        masters_clock = 1  # 1 - 16384

        # 15 + 1023 + 16 <- Max case
        # min 4 max 1054

        true_clock = 1
        while (detections < numOfDetections):
            self.master.tic(masters_clock)
            self.slave.tic()

            if masters_clock == 1:
                print true_clock
            #if true_clock >= 2048:
            #print '****************'
            #print 'Clock ' + str(true_clock)
            #print 'F1: ' + str(self.master.freqNumOne) + ' F2: ' + str(self.master.freqNumTwo)

            #if true_clock == 4096:
            #break;

            if self.master.slotMode == MasterSlotMode.tx:
                if (self.slave.sendFHS == True):
                    print 'Assert: TX & slave sending FHS'
                if ((self.slave.inBackOffZone == False) &
                    (self.slave.inOneSlotTo == False)):
                    if ((self.slave.freqNum == self.master.freqNumOne) |
                        (self.slave.freqNum == self.master.freqNumTwo)):
                        self.slave.listen("Master_MAC")
                        print '>> Hit at ' + str(true_clock)
            else:  # in Rx mode
                if (self.slave.sendFHS == True):
                    if ((self.slave.freqNum == self.master.freqNumOne) |
                        (self.slave.freqNum == self.master.freqNumTwo)):
                        time = true_clock
                        timeArray[detections] = time

                        # Reset Master & Slave
                        self.slave.reset()
                        self.master.resetTrain()
                        masters_clock = 0  # because it will get increment at the end of while loop
                        true_clock = 0

                        detections = detections + 1
                    else:
                        print 'Assert: RX & FHS sent, freqs didnt match ' + str(
                            true_clock)

            #increment clocks
            true_clock = true_clock + 1
            masters_clock = masters_clock + 1
            if masters_clock > 16384:
                masters_clock = 1
                #self.master.resetTrain()

        rand_str = ''.join(
            random.choice(string.ascii_lowercase + string.ascii_uppercase +
                          string.digits) for i in range(5)) + '.csv'
        path = 'temp/' + rand_str
        #print timeArray
        np.savetxt(path, timeArray, delimiter=',', header='Time', fmt='%1.0f')
Пример #7
0
 def get_server(self):
     if (self.master[0] == self.ip and self.master[1] == self.port):
         return Master(self.zookeeper, self.ip, self.socket)
     else:
         self.socket.close()
         return Slave(self.zookeeper, self.master, self.ip)
Пример #8
0
if __name__ == '__main__':
    # initial logger
    root.setLevel(logging.DEBUG)
    fh = logging.FileHandler('slave.log')
    fh.setLevel(logging.DEBUG)
    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    fh.setFormatter(formatter)
    root.addHandler(fh)

    if True:
        std = logging.StreamHandler(sys.stdout)
        root.addHandler(std)
    root.debug('logger stand by...')

    slave = Slave()
    slave.start()

    msgCenter = slave.getMsgCenter()
    ec = slave.getEncoder()
    lm = slave.getLocalMachine()
    while True:
        cmd = input(
            "start to start, 1 - 5 to change request, stop to stop, t to terminate\n"
        )
        msg = None
        if cmd == "start":
            msg = ec.encodeMsg_out("sys", "start transmit", lm.getName())
        elif cmd == "stop":
            msg = ec.encodeMsg_out("sys", "stop transmit", lm.getName())
        elif cmd == "t":
from threading import Thread
from Slave import Slave
from Master import Master
from time import sleep

if __name__ == '__main__':
    master = Master()
    print("Master tiempo {}".format(master.get_human_time()))
    slave1 = Slave(10000)
    slave2 = Slave(10001)
    slave3 = Slave(10002)
    slave4 = Slave(10003)
    master.registrar_slave(10000)
    master.registrar_slave(10001)
    master.registrar_slave(10002)
    master.registrar_slave(10003)
    print("slave 1 tiempo {}".format(slave1.get_human_time()))
    t1 = Thread(target=slave1.escuchar)
    t1.start()
    print("slave 2 tiempo {}".format(slave2.get_human_time()))
    t2 = Thread(target=slave2.escuchar)
    t2.start()
    print("slave 3 tiempo {}".format(slave3.get_human_time()))
    t3 = Thread(target=slave3.escuchar)
    t3.start()
    print("slave 4 tiempo {}".format(slave4.get_human_time()))
    t4 = Thread(target=slave4.escuchar)
    t4.start()
    master.work()
    print("Diferencia media {}[s]".format(master.diferencia_media))
    print("Master ajustado tiempo {}".format(master.get_human_time()))
Пример #10
0
    'log_file_path'] if 'log_file_path' in config else tempfile.gettempdir(
    ) + os.path.sep + 'puha-manager.log'
logging.basicConfig(filename=log_path,
                    format='%(asctime)s %(message)s',
                    level=logging.DEBUG)

db_path = config[
    'db_file_path'] if 'db_file_path' in config else tempfile.gettempdir(
    ) + os.path.sep + 'puha-manager-data.db'
Database(db_path)

slaves = []
slave_names = []
for slave_params in config['slaves']:
    slaves.append(
        Slave(slave_params['ip'], slave_params['port'], slave_params['name'],
              config))
    slave_names.append(slave_params['name'])

selected_slave_index = 0
slave = slaves[selected_slave_index]

header_data = {
    'site_title':
    config['site_title'],
    'navigation': [{
        'url': '/',
        'name': 'LED Control'
    }, {
        'url': '/temperature',
        'name': 'Temperature'
    }, {
Пример #11
0
def main(argv):
    #default values
    try:
        inputfile = "../data/param_config.xml"
        configfile = "../data/DABConfigFile"
        probType = util.problemType.FUSION
        solverType = util.solverType.DAB
        #verbose = 4, prints debug messages. 3 prints info messages.
        #2 prints warnings, 1 prints only errors
        verboseLevel = 4

        #process the arguments if the argparse module has been found
        if (argparseFound):
            parser = argparse.ArgumentParser(prog='disop.py',
                 formatter_class=argparse.RawDescriptionHelpFormatter,
                 description='Distributed Solver for Global Optimization.',
                 epilog=textwrap.dedent(__author__))

            parser.add_argument('-p', '--problem', required=True, type=str,
                                default='FUSION',
                                choices=['FUSION', 'NONSEPARABLE'],
                                help='Problem type')
            parser.add_argument('-v', '--verbose', required=False, type=int,
                                default=3, choices=[1, 2, 3, 4],
                                help='Verbosity')
            parser.add_argument('-s', '--solver', required=True, type=str,
                                default='DAB',
                                choices=['DAB', 'SA'],
                                help='Solver type')
            parser.add_argument('-i', '--ifile', required=True,
                                help='input parameters file (an XML file)',
                                type=lambda x: is_valid_file(parser, x))
            parser.add_argument('-c', '--cfile', required=True,
                                help='configuration INI file',
                                type=lambda x: is_valid_file(parser, x))
            parser.add_argument('--version', action='version',
                                 version='%(prog)s ' + __version__)

            args = parser.parse_args()

            #extract the problem type
            if (args.problem == 'FUSION'):
                probType = util.problemType.FUSION
            if (args.problem == 'NONSEPARABLE'):
                probType = util.problemType.NONSEPARABLE

            #extract the solver type
            if (args.solver == 'DAB'):
                solverType = util.solverType.DAB
            if (args.solver == 'SA'):
                solverType = util.solverType.SA

            verboseLevel = args.verbose

            #input and config file
            inputfile = args.ifile
            configfile = args.cfile

        else:
            #process the arguments if argparse not found
            try:
                opts, args = getopt.getopt(sys.argv[1:],
                             "hp:s:i:c:v:",
                             ["help", "problem", "solver", "ifile",
                              "cfile", "verbose"])
            except getopt.GetoptError, err:
                print str(err)
            for o, val in opts:
                if o in("-v", "--verbose"):
                    verboseLevel = int(val)
                elif o in ("-p", "--problem"):
                    if (val == "FUSION"):
                        probType = util.problemType.FUSION
                    else:
                        probType = util.problemType.NONSEPARABLE
                elif o in ("-s", "--solver"):
                    if (val == "DAB"):
                        solverType = util.solverType.DAB
                    if (val == "SA"):
                        solverType = util.solverType.SA
                elif o in ("-i", "--ifile"):
                    inputfile = val
                elif o in ("-c", "--cfile"):
                    configfile = val
                else:
                    assert False, "unhandled option"

        #init he configuration
        init(configfile)

        #init MPI
        rank = MPI.COMM_WORLD.Get_rank()
        comm = MPI.COMM_WORLD
        util.rank = rank
        util.comm = comm
        util.size = comm.Get_size()

        #set the verbosity level
        if (rank == 0):
            util.logger.info("Verbose level: " + str(verboseLevel))
        if (verboseLevel == 1):
            logging.disable(logging.WARNING)
        if (verboseLevel == 2):
            logging.disable(logging.INFO)
        if (verboseLevel == 3):
            logging.disable(logging.DEBUG)

        if (util.commModel == util.commModelType.MASTERSLAVE):
            if (rank == 0):
                #create master task
                util.logger.info("MASTER - BEGIN OF THE EXECUTION")
                #create the solver
                if (solverType == util.solverType.DAB):
                    solver = SolverDAB(probType, inputfile, configfile)
                elif (solverType == util.solverType.SA):
                    solver = SolverSA(probType, inputfile, configfile)
                else:
                    solver = SolverBase(probType, inputfile, configfile)
                #initialize the solver
                solver.initialize()
                #execute the solver
                solver.solve()
                util.logger.info("MASTER has finished solve")
                #clean everything
                solver.finish()
                util.logger.info("MASTER - END OF THE EXECUTION")
            else:
                #create slave task
                util.logger.info("SLAVE " + str(rank) +
                                 " - BEGIN OF THE EXECUTION")
                slave = Slave(comm, probType)
                slave.run(inputfile, configfile)
                slave.finish()
                util.logger.info("SLAVE " + str(rank) + " - END OF THE EXECUTION")
        else:
            util.logger.info("ALL2ALL - BEGIN OF THE EXECUTION")
            #create the solver
            if (solverType == util.solverType.DAB):
                solver = SolverDAB(probType, inputfile, configfile)
            elif (solverType == util.solverType.SA):
                solver = SolverSA(probType, inputfile, configfile)
            else:
                solver = SolverBase(probType, inputfile, configfile)
            #initialize the solver
            solver.initialize()
            #execute the solver
            solver.solve()
            util.logger.info("Rank " + str(rank) + " has finished solve")
            #clean everything
            solver.finish()
            util.logger.info("RANK " + str(rank) + " END OF THE EXECUTION")
            
        dump = array('i', [0]) * 1
        util.comm.Bcast(dump)
Пример #12
0
if __name__ == "__main__":

    import sys
    sys.path.append("../../lib")
    sys.path.append("../../lib/stub")
    from XmlReader import XmlReader
    #XmlReader.PATH = "../../../../../xml/xml/"
    from BattleNotify import gBattleNotify
    from Slave import Slave
    slave = Slave()
    gBattleNotify.init(slave)
    #from Battle import battle_test
    #battle_test()
    from PVEBattle import pve_test
    pve = pve_test()
    from PVPBattle import pvp_test
    pvp_test()
    from BossBattle import BossBattle
    import timeit
    from TeamBattle import TeamBattle, TeamBattle_TestCase
    a = timeit.Timer(
        stmt="TeamBattle_TestCase();test_5v5team_battle_testcase()",
        setup=
        "from TeamBattle import TeamBattle,TeamBattle_TestCase,test_5v5team_battle_testcase"
    )
    print a.timeit(1)
Пример #13
0
	def __init__(self):
		self.master = Master()
		self.slave = Slave()
Пример #14
0
class Simulation(object):
	def __init__(self):
		self.master = Master()
		self.slave = Slave()

	def start_simulation(self):
		detections = 0
		numOfDetections = 4000
		timeArray = np.arange(numOfDetections)
		

		masters_clock = 1 # 1 - 16384

		# 15 + 1023 + 16 <- Max case
		# min 4 max 1054

		true_clock = 1
		while(detections < numOfDetections):
			self.master.tic(masters_clock)
			self.slave.tic()

			if masters_clock == 1:
				print true_clock
			#if true_clock >= 2048:
				#print '****************'
				#print 'Clock ' + str(true_clock)
				#print 'F1: ' + str(self.master.freqNumOne) + ' F2: ' + str(self.master.freqNumTwo)
				
			#if true_clock == 4096:
				#break;

			if self.master.slotMode == MasterSlotMode.tx:
				if (self.slave.sendFHS==True):
					print 'Assert: TX & slave sending FHS'
				if ((self.slave.inBackOffZone==False) & (self.slave.inOneSlotTo==False)):
					if ((self.slave.freqNum == self.master.freqNumOne) | (self.slave.freqNum == self.master.freqNumTwo)):
						self.slave.listen("Master_MAC")
						print '>> Hit at ' + str(true_clock)
			else: # in Rx mode
				if (self.slave.sendFHS==True):
					if ((self.slave.freqNum == self.master.freqNumOne) | (self.slave.freqNum == self.master.freqNumTwo)):
						time = true_clock
						timeArray[detections] = time

						# Reset Master & Slave
						self.slave.reset()
						self.master.resetTrain()
						masters_clock = 0 # because it will get increment at the end of while loop
						true_clock = 0

						detections = detections +1
					else:
						print 'Assert: RX & FHS sent, freqs didnt match ' + str(true_clock)
					

			#increment clocks
			true_clock = true_clock + 1
			masters_clock = masters_clock + 1
			if masters_clock > 16384:
				masters_clock = 1
				#self.master.resetTrain()
			
		rand_str = ''.join(random.choice(
                    string.ascii_lowercase
                    + string.ascii_uppercase
                    + string.digits)
               for i in range(5)) + '.csv'
		path = 'temp/'+rand_str
		#print timeArray
		np.savetxt(path, timeArray, delimiter=',', header='Time', fmt='%1.0f')
Пример #15
0
import sys
import os 
sys.path.append('src')
from Slave import Slave
import shutil
 
def copyDirectory(src, dest):
    try:
        shutil.copytree(src, dest)
    # Directories are the same
    except shutil.Error as e:
        print('Directory not copied. Error: %s' % e)
    # Any error saying that the directory doesn't exist
    except OSError as e:
        print('Directory not copied. Error: %s' % e)

if os.path.exists('Testing/TestImagesTmp'):
	shutil.rmtree('Testing/TestImagesTmp')
copyDirectory('Testing/TestImages', 'Testing/TestImagesTmp')

s0 = Slave(name = 'Slave01', folder_loc='Testing/TestImagesTmp/Ingest_01', host='localhost', port=8080, debug=True)
s0.setParameters(name='Params',destination='Testing/Params')
s0.run()
Пример #16
0
import sys
import os
sys.path.append('src')
from Slave import Slave
import shutil


def copyDirectory(src, dest):
    try:
        shutil.copytree(src, dest)
    # Directories are the same
    except shutil.Error as e:
        print('Directory not copied. Error: %s' % e)
    # Any error saying that the directory doesn't exist
    except OSError as e:
        print('Directory not copied. Error: %s' % e)


if os.path.exists('Testing/TestImagesTmp'):
    shutil.rmtree('Testing/TestImagesTmp')
copyDirectory('Testing/TestImages', 'Testing/TestImagesTmp')

s0 = Slave(name='Slave01',
           folder_loc='Testing/TestImagesTmp/Ingest_01',
           host='localhost',
           port=8080,
           debug=True)
s0.setParameters(name='Params', destination='Testing/Params')
s0.run()