Пример #1
0
    def update_ue_stats(self, ue, ap, scale):
        """
        Helper method to update UE's stats
        """
        self.logger.debug("Updating UE's stats!")
        # Update UE-AP distance
        ue.distance = utils.get_ue_ap_distance(
            ue.location, ap.location
        )
        n_ues_on_ap = self.total_ues(ap.n_ues)
        # Update UE's throughput
        ue.throughput = utils.get_ue_throughput(
            scale, ue.distance, n_ues_on_ap,
            ap.uplink_bandwidth, ap.channel_bandwidth,
            ue.required_bandwidth
        )

        # Update UE's SLA
        ue.sla = self.update_ue_sla_handoff(ue.sla, ue.throughput, ue.required_bandwidth)
        if ue.app == 1:
            app = 'web'
        elif ue.app == 2:
            app = 'video'
        ap.ues_meeting_sla[app] += ue.sla

        # Get new signal power based on UE-AP
        ue.signal_power = utils.get_ue_sig_power(ue.distance)
Пример #2
0
    def calculate_ue_throughput(self, current_ap, ue_ap_distance,
                                ue_required_bandwidth):
        """
        Helper to calculate ue_throughput for the current AP
        """
        ap_n_ues = self.total_ues(current_ap.n_ues)
        ap_uplink_bandwidth = current_ap.uplink_bandwidth
        ap_channel_bandwidth = current_ap.channel_bandwidth

        return utils.get_ue_throughput(self.scale, ue_ap_distance, ap_n_ues,
                                       ap_uplink_bandwidth,
                                       ap_channel_bandwidth,
                                       ue_required_bandwidth)
def test_get_ue_throughput():
    """
    Tests get_ue_throughput function
    """
    assert utils.get_ue_throughput(100, 441.367, 58, 50.0, 10.0, 0.25) == 0.25
Пример #4
0
    def reset_network_after_move(self):
        """
        Method to create new UEs after one move within the grid
        and connect them to their respective APs
        """
        self.logger.debug(
            "Instantiating {} UEs after one move and placing them".format(
                self._client.get_num_ues()))

        self.ue_sla_stats = defaultdict(int)
        scale = self._client.get_ap_info(1)['location'][0]
        x_units = int(math.sqrt(self._client.get_num_aps()))
        aps_per_axis = [(1 + (2 * i)) * scale for i in range(x_units)]

        for ue_id, ue in self._ue_dict.items():
            ue_id = ue_id
            ue_app = ue.app

            if ue_app == 1:
                app = 'web'
            else:
                app = 'video'

            # Get update UE's location after one move
            ue_location_before = ue.location
            br_id = ue.br_id
            if br_id == 0:
                br_info = {}
            else:
                br_info = self._br_dict[br_id]
            ue_location_after_move = utils.get_ue_location_after_move(
                br_info, ue_location_before, ue.location_type,
                ue.velocity, ue.direction, aps_per_axis, scale
                )

            # Get UE's closest AP, after move the closest AP may have changed
            # Set the current Ap as the AP from the previous episode, but recalculate
            # the neighboring APS
            current_ap_id = ue.ap
            current_ap = self._ap_dict[current_ap_id]

            # the temp_current_ap_location is calcuted based on the movement of the UE
            # but we don't make the UE handoff to the temporary current AP
            (closest_ap_location, current_neighboring_aps) = utils.get_ue_ap(
                ue_location_after_move, aps_per_axis, radius=1
                )
            # Get current temporary ap_id, 
            closest_ap_id = self._reverse_ap_lookup[closest_ap_location]

            current_neighboring_aps_id = self.neighboring_ap_ids(
                closest_ap_location, current_neighboring_aps
                )
            # Update the neighboring aps after move 
            neighboring_aps_id = utils.update_neighboring_aps_after_move(
                ue, current_neighboring_aps_id, closest_ap_id
                )
            # recalculate the location and velocity of the UE after move,
            # e.g. if the new location is on road just recalculate its velocity
            # to match the road type
            [location_type, velocity, ue_direction, br_id] =\
                utils.is_road_or_building(
                    self._br_dict, ue_location_after_move,
                    aps_per_axis, scale, ue.direction
                    )

            ue.location = ue_location_after_move
            ue.velocity = velocity
            ue.direction = ue_direction
            # ue.ap = current_ap_id
            ue.location_type = location_type
            ue.neighboring_aps = neighboring_aps_id
            ue.distance = utils.get_ue_ap_distance(
                ue_location_after_move, current_ap.location
                )
            n_ues_on_ap = self.total_ues(current_ap.n_ues)

            ue_throughput = utils.get_ue_throughput(
                scale, ue.distance, n_ues_on_ap, current_ap.uplink_bandwidth,
                current_ap.channel_bandwidth, ue.required_bandwidth
                )
            ue.throughput = ue_throughput

            # update the sla of the UE according to the change of distance
            sla = self.calculate_ue_sla(
                ue.throughput, ue.required_bandwidth
                )
            # change the current AP's SLA according to the UE's SLA after move
            if not sla and ue.sla:
                current_ap.ues_meeting_sla[app] -= ue.sla
            if sla and not ue.sla:
                current_ap.ues_meeting_sla[app] += ue.sla

            ue.sla = sla
            ue.signal_power = utils.get_ue_sig_power(ue.distance)
Пример #5
0
    def _instantiate_ues_after_move(self):
        """
        Method to create new UEs after one move within the grid
        and connect them to their respective APs
        """

        for ue_id, ue in self._ue_dict.items():
            ue_id = ue_id
            ue_app = ue.app

            # Get update UE's location after one move
            ue_location_before = ue.location
            br_id = ue.br_id
            if br_id == 0:
                br_info = {}
            else:
                br_info = self._br_dict[br_id]
            ue_location_after_move = utils.get_ue_location_after_move(
                br_info, ue_location_before, ue.location_type, ue.velocity,
                ue.direction, self.aps_per_axis, self.scale)

            current_ap_id = ue.ap
            current_ap = self._ap_dict[current_ap_id]

            (closest_ap_location,
             current_neighboring_aps) = utils.get_ue_ap(ue_location_after_move,
                                                        self.aps_per_axis,
                                                        radius=1)

            closest_ap_id = self._location_to_ap_lookup[closest_ap_location]

            current_neighboring_aps_id = self.neighboring_ap_ids(
                closest_ap_location, current_neighboring_aps)
            neighboring_aps_id = utils.update_neighboring_aps_after_move(
                ue, current_neighboring_aps_id, closest_ap_id)

            # Get UE's closest AP
            # (current_ap_location, neighboring_aps) = utils.get_ue_ap(
            #     ue_location_after_move, self.aps_per_axis, radius=1)

            # neighboring_aps_id = self.neighboring_ap_ids(
            #     current_ap_location, neighboring_aps)

            # # Get current ap_id
            # current_ap_id = self._location_to_ap_lookup[current_ap_location]

            # # Update UE count for the AP
            # current_ap.n_ues[ue_app].add(ue_id)

            # Update UE location type to be on the road or in the building,
            # and the br_id related with the ue
            # if br_id=0, means none br is related with that ue
            [location_type, velocity, ue_direction, br_id] =\
                utils.is_road_or_building(
                    self._br_dict, ue_location_after_move,
                    self.aps_per_axis, self.scale, ue.direction
                )

            ue.location = ue_location_after_move
            ue.velocity = velocity
            ue.direction = ue_direction
            ue.ap = current_ap_id
            ue.location_type = location_type
            ue.neighboring_aps = neighboring_aps_id
            ue.distance = utils.get_ue_ap_distance(ue_location_after_move,
                                                   current_ap.location)
            n_ues_on_ap = self.total_ues(current_ap.n_ues)

            ue_throughput = utils.get_ue_throughput(
                self.scale, ue.distance, n_ues_on_ap,
                current_ap.uplink_bandwidth, current_ap.channel_bandwidth,
                ue.required_bandwidth)

            ue.throughput = ue_throughput
            sla = self.calculate_ue_sla(ue.throughput, ue.required_bandwidth)
            if not sla and ue.sla:
                current_ap.ues_meeting_sla[ue_app] -= ue.sla
            if sla and not ue.sla:
                current_ap.ues_meeting_sla[ue_app] += ue.sla
            ue.sla = sla
            ue.signal_power = utils.get_ue_sig_power(ue.distance)