Ejemplo n.º 1
0
 def run(self):
     global break_flag
     #global round_start_flag
     global complete_flag
     global rx_clear_flag
     global handle_clear_flag
     global final_round_flag
     for i in range(self.MAX_EPISODES):
         index = 0
         rx_clear_flag = False
         handle_clear_flag = False
         #round_start_flag = True
         time.sleep(0.5)
         c_f = gl.get_continue_flag()
         if (c_f or i == 0) and not complete_flag:
             if c_f:
                 continue_flag = False
                 gl.set_continue_flag(continue_flag)
             r_s_f = True
             gl.set_round_start_flag(r_s_f)
             while not gl.get_ready_flag():
                 time.sleep(0.1)
             if gl.get_ready_flag():
                 r_s_f_ = False
                 r_f_ = False
                 gl.set_round_start_flag(r_s_f_)
                 gl.set_ready_flag(r_f_)
                 while index < len(self.flow_size_list):
                     f_size = self.flow_size_list[index]
                     self.set_flow_size(f_size)
                     index = index + 1
                     time.sleep(1)
                     if gl.get_continue_flag():
                         break
             str = "Round %d complete\n" % (i+1)
             sys.stdout.write(str)
             if i + 2 >= self.MAX_EPISODES:
                 final_round_flag = True
             while not gl.get_learn_complete_flag():
                 time.sleep(0.1)
             if gl.get_learn_complete_flag():
                 complete_flag = True
                 l_f_ = False
                 gl.set_learn_complete_flag(l_f_)
             #round_start_flag = False
             time.sleep(2)
     if gl.get_continue_flag():
         break_flag = True
         gl.set_break_flag(break_flag)
Ejemplo n.º 2
0
    def run(self):
        global rx_clear_flag
        global complete_flag
        global drop_count_list
        while True:
            timer1 = time.time()
            f_count = 0
            f_size = int(self.get_flow_size(self.id))
            s_time = time.time()

            for i in range(f_size):
                tmp_flow = flow
                tmp_flow.s_time = s_time
                if not self.rx_queue.full():
                    self.rx_queue.put_nowait(tmp_flow)
                    f_count = f_count + 1
                else:
                    self.drop_count = self.drop_count + 1
            self.set_drop_count(self.id, self.drop_count)
            if complete_flag:
                if not self.rx_queue.empty():
                    self.rx_queue.queue.clear()
                self.drop_count = 0
                drop_count_list = np.zeros(100)
                rx_clear_flag = True
                #print('Node', self.id, 'rx thread para clear')
                if handle_clear_flag and rx_clear_flag and gl.get_continue_flag():
                    complete_flag = False
                    #print("Node", self.id, "In rx thread both thread clear")
            if break_flag:
                break
            timer2 = time.time()
            while timer2 - timer1 < 1:
                time.sleep(0.01)
                timer2 = time.time()
Ejemplo n.º 3
0
    def run(self):
        global break_flag
        #global round_start_flag
        global complete_flag
        global clear_flag
        global final_round_flag
        for i in range(self.MAX_EPISODES):
            index = 0
            #round_start_flag = True
            self.init_clear_flag()
            time.sleep(0.5)
            c_f = gl.get_continue_flag()
            # s1 = "%d %s %s\n" % (i, str(c_f), str(complete_flag))
            # sys.stdout.write(s1)
            t1 = time.time()
            while complete_flag:
                t2 = time.time()
                time.sleep(0.01)
                # if t2 - t1 > 60:
                #     os._exit(0)

            if (c_f or i == 0) and not complete_flag:
                str0 = "Round %d start\n" % (i + 1)
                sys.stdout.write(str0)
                if c_f:
                    continue_flag = False
                    gl.set_continue_flag(continue_flag)
                r_s_f = True
                gl.set_round_start_flag(r_s_f)
                while not gl.get_ready_flag():
                    # str1 = "not get get_ready_flag\n"
                    # sys.stdout.write(str1)
                    time.sleep(0.1)
                if gl.get_ready_flag():
                    r_s_f_ = False
                    r_f_ = False
                    gl.set_round_start_flag(r_s_f_)
                    gl.set_ready_flag(r_f_)
                    while index < len(self.flow_size_list):
                        f_size = self.flow_size_list[index]
                        #print(f_size, index)
                        self.set_flow_size(f_size)
                        index = index + 1
                        time.sleep(1)
                        if gl.get_continue_flag():
                            break
                str4 = "Round %d complete\n" % (i + 1)
                sys.stdout.write(str4)
                if i + 2 >= self.MAX_EPISODES:
                    final_round_flag = True
                while not gl.get_learn_complete_flag():
                    # str2 = "not get get_learn_complete_flag\n"
                    # sys.stdout.write(str2)
                    time.sleep(0.1)
                if gl.get_learn_complete_flag():
                    complete_flag_lock.acquire()
                    complete_flag = True
                    complete_flag_lock.release()
                    l_f_ = False
                    gl.set_learn_complete_flag(l_f_)
                #round_start_flag = False
                time.sleep(2)
        if gl.get_continue_flag():
            break_flag = True
            gl.set_break_flag(break_flag)
Ejemplo n.º 4
0
    def run(self):
        global exit_flag
        global complete_flag
        global handle_clear_flag
        while True:
            sr = "%d alive\n" % (self.id)
            sys.stdout.write(sr)
            f_batch = []
            #timer1 = time.time()
            f_count = 0
            while not self.rx_queue.empty() or self.id > 0:
                while self.rx_queue.empty():
                    time.sleep(0.1)
                self.ins_num = self.get_ins_num(self.id)
                #timer3 = time.time()
                for i in range(self.ins_num):
                    #timer2 = time.time()
                    # if self.id == sfc[0]:
                    #     if not self.rx_queue.empty() and timer2 - timer1 < 1:
                    #         #f = self.rx_queue.get_nowait()
                    #         f = self.rx_queue.get()
                    #         f_count = f_count + 1
                    #         f_batch.append(f)
                    # else:
                    #     if not self.rx_queue.empty() and timer2 - timer1 < 1 and f_count <= self.get_last_throughput(self.id):
                    #         #f = self.rx_queue.get_nowait()
                    #         f = self.rx_queue.get()
                    #         f_count = f_count + 1
                    #         f_batch.append(f)
                    if not self.rx_queue.empty():
                        # f = self.rx_queue.get_nowait()
                        f = self.rx_queue.get()
                        f_count = f_count + 1
                        f_batch.append(f)
                time.sleep(service_time / 1000)
                #timer4 = time.time()
                end_time = time.time()
                #if timer2 - timer1 >= 1:
                #self.throughput = f_count / (timer4 - timer3)
                #self.throughput = f_count * (1000/ service_time)
                self.throughput = self.ins_num * (1000 / service_time)
                if self.throughput > self.get_rx_throughput(self.id) and self.id == sfc[0]:
                    self.throughput = rx_throughput_list[sfc[0]]
                if self.throughput > self.get_rx_throughput(self.id) and self.id != sfc[0]:
                    self.throughput = self.get_rx_throughput(self.id)
                self.set_tran_flow(self.throughput, self.id, self.connection)
                # str2 = "%s Throughput: %d f/s VMs: %d\n" % (
                # self.name, self.throughput, self.ins_num)
                # sys.stdout.write(str2)
                #self.set_throughput(self.id, self.throughput / (timer2 - timer1))
                self.set_throughput(self.id, self.throughput)
                f_count = 0
                #timer1 = time.time()
                for j in range(len(f_batch)):
                    f_batch[j].f_time = end_time
                    self.tx_queue.put_nowait(f_batch[j])
                    if len(self.delay_list) == delay_span:
                        self.avg_delay = self.get_avg_delay(self.delay_list)
                        self.delay_list.clear()
                        #str1 = "%s Latency: %d ms  Packet loss: %d" % (self.name, self.avg_delay, drop_count_list[self.id])
                        #print(str1)
                        self.set_latency(self.id, self.avg_delay)
                    delay = (f_batch[j].f_time - f_batch[j].s_time) * 1000
                    self.delay_list.append(delay)

                f_batch.clear()

                if complete_flag:
                    self.clear_para(self.rx_queue,self.tx_queue,self.delay_list)
                    handle_clear_flag = True
                    #print('Node', self.id, 'handle thread para clear')
                    if handle_clear_flag and rx_clear_flag and gl.get_continue_flag():
                        complete_flag = False
                        #print("Node", self.id, "In handle thread both thread clear")
                if break_flag:
                    exit_flag = True
                    break
            if exit_flag:
                break
Ejemplo n.º 5
0
    def run(self):
        #global exit_flag
        global complete_flag
        global clear_flag
        global all_clear_flag
        while not break_flag:
            # str7 = "handle %d Alive\n" % (self.id)
            # sys.stdout.write(str7)

            if complete_flag:
                self.clear_para(self.rx_queue, self.tx_queue)
                if len(self.delay_list) > 0:
                    self.delay_list.clear()
                self.set_clear_flag(self.id)

                if self.check_clear_flag():
                    all_clear_flag_lock.acquire()
                    all_clear_flag = True
                    all_clear_flag_lock.release()
                else:
                    continue

                # while not (all_clear_flag and gl.get_continue_flag()):
                #     time.sleep(0.1)
                if all_clear_flag and gl.get_continue_flag():
                    complete_flag_lock.acquire()
                    complete_flag = False
                    complete_flag_lock.release()
                else:
                    continue
            else:
                f_batch = []
                #timer1 = time.time()
                f_count = 0

                self.ins_num = self.get_ins_num(self.id)
                #timer3 = time.time()
                for i in range(self.ins_num):
                    if not self.rx_queue.empty():
                        # f = self.rx_queue.get_nowait()
                        f = self.rx_queue.get()
                        f_count += 1
                        f_batch.append(f)
                time.sleep(service_time / 1000)
                #timer4 = time.time()
                end_time = time.time()
                #if timer2 - timer1 >= 1:
                #self.throughput = f_count / (timer4 - timer3)
                # self.throughput = f_count * (1000/ service_time)
                self.throughput = self.ins_num * (1000 / service_time)
                if self.throughput > self.get_rx_throughput(
                        self.id) and self.id == sfc[0]:
                    self.throughput = rx_throughput_list[sfc[0]]
                if self.throughput > self.get_rx_throughput(
                        self.id) and self.id != sfc[0]:
                    self.throughput = self.get_rx_throughput(self.id)
                self.set_tran_flow(self.throughput, self.id, self.connection)
                # str2 = "%s Throughput: %d f/s VMs: %d\n" % (
                # self.name, self.throughput, self.ins_num)
                # sys.stdout.write(str2)
                #self.set_throughput(self.id, self.throughput / (timer2 - timer1))
                self.set_throughput(self.id, self.throughput)
                #f_count = 0
                #timer1 = time.time()
                # for j in range(len(f_batch)):
                #     f_batch[j].f_time = end_time
                #     self.tx_queue.put(f_batch[j])
                #     if len(self.delay_list) == delay_span:
                #         self.avg_delay = self.get_avg_delay(self.delay_list)
                #         self.delay_list.clear()
                #         #str1 = "%s Latency: %d ms  Packet loss: %d" % (self.name, self.avg_delay, drop_count_list[self.id])
                #         #print(str1)
                #         self.set_latency(self.id, self.avg_delay)
                #     delay = (f_batch[j].f_time - f_batch[j].s_time) * 1000
                #     self.delay_list.append(delay)

                f_batch.clear()