コード例 #1
0
    def recv(self):
        serialized_ack, addr = self.sock.recvfrom(1600)

        if addr != self.peer_addr:
            return

        ack = datagram_pb2.Ack()
        ack.ParseFromString(serialized_ack)

        action = self.action

        self.update_state(ack)

        if self.step_start_ms is None:
            self.step_start_ms = curr_ts_ms()

        done = False
        reward = 0
        # At each step end, feed the state:
        if curr_ts_ms() - self.step_start_ms > self.step_len_ms:  # step's end
            self.state = [
                self.delay_ewma, self.delivery_rate_ewma, self.send_rate_ewma,
                self.cwnd
            ]
            #print(state)

            # time how long it takes to get an action from the NN
            if self.debug:
                start_sample = time.time()

            norm_state = normalize(self.state)
            one_hot_action = one_hot(self.action, self.action_cnt)
            state = norm_state + one_hot_action

            self.action = self.sample_action(state)

            if self.debug:
                self.sampling_file.write('%.2f ms\n' %
                                         ((time.time() - start_sample) * 1000))

            self.take_action(self.action)
            '''
            self.delay_ewma = None
            self.delivery_rate_ewma = None
            self.send_rate_ewma = None
            '''

            self.step_start_ms = curr_ts_ms()

            done = False
            if self.train:
                self.step_cnt += 1
                reward = self.compute_performance()
                if self.step_cnt >= Sender.max_steps:
                    self.step_cnt = 0
                    self.running = False
                    done = True
                #print self.state,self.action, reward, done

        return self.state, action, reward, done
コード例 #2
0
ファイル: sender.py プロジェクト: albararamli/indigo
    def recv(self):
        serialized_ack, addr = self.sock.recvfrom(1600)

        if addr != self.peer_addr:
            return

        ack = datagram_pb2.Ack()
        ack.ParseFromString(serialized_ack)

        self.update_state(ack)

        if self.step_start_ms is None:
            self.step_start_ms = curr_ts_ms()

        # At each step end, feed the state:
        if curr_ts_ms() - self.step_start_ms > self.step_len_ms:  # step's end
            state = [
                self.delay_ewma, self.delivery_rate_ewma, self.send_rate_ewma,
                self.cwnd
            ]

            # time how long it takes to get an action from the NN
            if self.debug:
                start_sample = time.time()

            action = self.sample_action(state)
            #os.system()
            ##scriptx = "echo "+"{:04d}".format(self.thid)+ '\t' +str(time.time()) + '\t'+str(self.delay_ewma)+'\t'+str(self.delivery_rate_ewma)+'\t'+str(self.send_rate_ewma)+'\t'+str(self.cwnd) +">> logx/"+line_algo+"-state.txt"
            ##proc = subprocess.Popen(scriptx,stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
            #(out, err) = proc.communicate()
            if self.debug:
                self.sampling_file.write('%.2f ms\n' %
                                         ((time.time() - start_sample) * 1000))

            self.take_action(action)

            self.delay_ewma = None
            self.delivery_rate_ewma = None
            self.send_rate_ewma = None

            self.step_start_ms = curr_ts_ms()

            if self.train:
                self.step_cnt += 1
                if self.step_cnt >= Sender.max_steps:
                    self.step_cnt = 0
                    self.running = False

                    self.compute_performance()
コード例 #3
0
ファイル: receiver.py プロジェクト: hexi519/a3c_indigo
    def construct_ack_from_data(self, serialized_data):
        """Construct a serialized ACK that acks a serialized datagram."""

        data = datagram_pb2.Data()
        data.ParseFromString(serialized_data)

        ack = datagram_pb2.Ack()
        ack.seq_num = data.seq_num
        ack.send_ts = data.send_ts
        ack.sent_bytes = data.sent_bytes
        ack.delivered_time = data.delivered_time
        ack.delivered = data.delivered
        ack.ack_bytes = len(serialized_data)

        return ack.SerializeToString()
コード例 #4
0
ファイル: sender.py プロジェクト: caoshiyi/a3c_indigo
    def recv(self):
        serialized_ack, addr = self.sock.recvfrom(1600)
        k = -1

        if addr != self.peer_addr:
            return

        ack = datagram_pb2.Ack()
        ack.ParseFromString(serialized_ack)

        self.update_state(ack)

        if self.step_start_ms is None:
            self.step_start_ms = curr_ts_ms()

        # At each step end, feed the state:
        if curr_ts_ms() - self.step_start_ms > self.step_len_ms:  # step's end
            state = [
                self.delay_ewma, self.delivery_rate_ewma, self.send_rate_ewma,
                self.cwnd
            ]

            # time how long it takes to get an action from the NN
            if self.debug:
                start_sample = time.time()

            action = self.sample_action(state)

            if self.debug:
                self.sampling_file.write('%.2f ms\n' %
                                         ((time.time() - start_sample) * 1000))

            self.take_action(action)

            self.delay_ewma = None
            self.delivery_rate_ewma = None
            self.send_rate_ewma = None

            self.step_start_ms = curr_ts_ms()

            if self.train:
                self.step_cnt += 1
                if self.step_cnt >= Sender.max_steps:
                    self.step_cnt = 0
                    self.running = False

                    k = self.compute_performance()
        return k
コード例 #5
0
    def recv(self):
        serialized_ack, addr = self.sock.recvfrom(1600)

        if addr != self.peer_addr:
            return

        ack = datagram_pb2.Ack()
        ack.ParseFromString(serialized_ack)

        self.update_state(ack)

        if self.step_start_ms is None:
            self.step_start_ms = curr_ts_ms()

        # At each step end, feed the state:
        if curr_ts_ms() - self.step_start_ms > self.step_len_ms:  # step's end
            self.new_send_count = self.seq_num - self.last_seq_num
            self.last_seq_num = self.seq_num
            new_not_ack_count = self.new_send_count - self.new_rec_count
            new_loss = float(
                new_not_ack_count
            ) / self.new_send_count if self.new_send_count else 0

            new_latency = self.new_compute_latency() / 1000  # s

            # new_throughput = float(self.new_rec_count) / self.step_len_ms
            delivered = self.delivered - self.last_delivered
            new_throughput = 0.008 * delivered / self.step_len_ms  # Mbit/s
            self.last_delivered = self.delivered

            new_ele_list = [new_throughput, new_latency, new_loss]

            # sys.stderr.write(str(new_ele_list)+'\n')

            new_reward = new_throughput - 10 * new_latency
            state = [
                self.delay_ewma, self.delivery_rate_ewma, self.send_rate_ewma,
                self.cwnd
            ]

            # time how long it takes to get an action from the NN
            if self.debug:
                start_sample = time.time()

            action, new_aug_state = self.sample_action(state)

            new_is_done = 0

            self.fout.write('|'.join([
                str(self.new_pre_state),
                str(action),
                str(new_aug_state),
                str(new_reward),
                str(new_is_done),
                str(new_ele_list)
            ]))
            self.fout.write('\n')

            self.new_pre_state = new_aug_state
            self.new_rec_count = 0

            if self.debug:
                self.sampling_file.write('%.2f ms\n' %
                                         ((time.time() - start_sample) * 1000))

            self.take_action(action)

            self.delay_ewma = None
            self.delivery_rate_ewma = None
            self.send_rate_ewma = None

            self.step_start_ms = curr_ts_ms()

            if self.train:
                self.step_cnt += 1
                if self.step_cnt >= Sender.max_steps:
                    self.step_cnt = 0
                    self.running = False

                    self.compute_performance()