def add_antenna(self,
                 loss,
                 orientation,
                 device=None,
                 channel=None,
                 force_device=None):
     av_devs = self.available_devices if force_device is None else force_device
     # If the device is not provided we must find the best one for this link
     if not device:
         src_device = ubnt.get_fastest_link_hardware(
             loss, available_devices=av_devs)[1]
     else:
         src_device = ubnt.get_fastest_link_hardware(
             loss, device[0], available_devices=av_devs)[1]
     if not channel:
         channel = self._pick_channel()
     else:
         self.check_channel(channel)
     if not src_device:
         raise LinkUnfeasibilty
     if len(self.antennas) >= self.max_ant:
         raise AntennasExahustion
     ant = Antenna(src_device, orientation, channel)
     self.antennas.append(ant)
     return ant
    def get_best_dst_antenna(self,
                             link,
                             pref_channels=None,
                             force_device=None):
        av_devs = self.available_devices if force_device is None else force_device
        # filter the antennas that are directed toward the src
        # and on the same channel
        visible_antennas = [
            ant for ant in self.antennas
            if (pref_channels is None or (ant.channel in pref_channels))
            and ant.check_node_vis(link_angles=link['dst_orient'])
        ]

        # sort them by the bitrate and take the fastest one
        if visible_antennas:
            best_ant = max(visible_antennas,
                           key=lambda x: ubnt.get_fastest_link_hardware(
                               link['loss'], target=x.ubnt_device[0])[0])
            result = best_ant
        else:
            try:
                pref_channels = pref_channels & set(self.free_channels)
                pref_channel = random.sample(pref_channels, 1)[0]
            except Exception:
                pref_channel = None
            result = self.add_antenna(loss=link['loss'],
                                      orientation=link['dst_orient'],
                                      force_device=av_devs,
                                      channel=pref_channel)
        return result
Beispiel #3
0
    def get_best_dst_antenna(self, link):
        result = None
        # filter the antennas that are directed toward the src
        # and on the same channel
        visible_antennas = [
            ant for ant in self.antennas
            if ant.check_node_vis(link_angles=link['dst_orient'])
        ]

        # sort them by the bitrate and take the fastest one
        if visible_antennas:
            best_ant = max(visible_antennas,
                           key=lambda x: ubnt.get_fastest_link_hardware(
                               link['loss'], target=x.ubnt_device[0])[0])
            result = best_ant
        else:
            result = self.add_antenna(loss=link['loss'],
                                      orientation=link['dst_orient'])
        return result
 def test_fastest_link(self):
     for p in range(80, 160, 10):
         print(ubnt.get_fastest_link_hardware(p))