Esempio n. 1
0
 def _init_interfaces(self, possible_ifaces):
     """
     Enumerate all network interfaces that are currently able to stream CHDR
     Returns a dictionary iface name -> iface info, where iface info is the
     return value of get_iface_info().
     """
     self.log.trace("Testing available interfaces out of `{}'".format(
         list(possible_ifaces)))
     valid_iface_infos = {
         x: net.get_iface_info(x)
         for x in net.get_valid_interfaces(possible_ifaces)
     }
     # Because get_iface_info() and get_valid_interfaces() are not one atomic
     # operation, there are rare scenarios when their return values are
     # inconsistent. To catch these cases, we filter the list again and warn
     # the user. Usually, this is not a problem and the next call to
     # _init_interfaces() will be back to normal.
     valid_iface_infos_filtered = {
         x: valid_iface_infos[x]
         for x in valid_iface_infos if valid_iface_infos[x]['ip_addr']
     }
     if len(valid_iface_infos) != len(valid_iface_infos_filtered):
         self.log.warning(
             "Number of detected CHDR devices is inconsistent. Dropped from "
             "{} to {}.".format(len(valid_iface_infos),
                                len(valid_iface_infos_filtered)))
     if len(valid_iface_infos_filtered):
         self.log.debug("Found CHDR interfaces: `{}'".format(", ".join(
             list(valid_iface_infos.keys()))))
     else:
         self.log.info("No CHDR interfaces found!")
     return valid_iface_infos_filtered
Esempio n. 2
0
    def test_get_iface_info(self):
        """
        Tests the get_iface_info function.
        Expected ifaces should return information in the correct format
        while unexpected ifaces should raise an IndexError.

        Note: This test is only valid when run on a USRP because the
        network interfaces of a dev machine are unknown.
        """
        if self.device_name == 'n3xx':
            possible_ifaces = ['eth0', 'sfp0', 'sfp1']
        else:
            possible_ifaces = ['eth0', 'sfp0']

        active_ifaces = net.get_valid_interfaces(possible_ifaces)

        for iface_name in possible_ifaces:
            iface_info = net.get_iface_info(iface_name)
            # Verify the output info contains the expected keys
            self.assertGreaterEqual(set(iface_info), {'mac_addr', 'ip_addr', 'ip_addrs', 'link_speed'})
            if iface_name in active_ifaces:
                # Verify interfaces with an active connection have a set IPv4 address
                self.assertNotEqual(iface_info['ip_addr'], '')

        unknown_name = 'unknown_iface'
        # Verify that an unknown interface throws a LookupError
        self.assertRaises(LookupError, net.get_iface_info, unknown_name)
Esempio n. 3
0
 def _init_interfaces(self, possible_ifaces):
     """
     Enumerate all network interfaces that are currently able to stream CHDR
     Returns a dictionary iface name -> iface info, where iface info is the
     return value of get_iface_info().
     """
     self.log.trace("Testing available interfaces out of `{}'".format(
         list(possible_ifaces)))
     valid_ifaces = net.get_valid_interfaces(possible_ifaces)
     if len(valid_ifaces):
         self.log.debug("Found CHDR interfaces: `{}'".format(valid_ifaces))
     else:
         self.log.info("No CHDR interfaces found!")
     return {x: net.get_iface_info(x) for x in valid_ifaces}
Esempio n. 4
0
 def _init_interfaces(self, possible_ifaces):
     """
     Enumerate all network interfaces that are currently able to stream CHDR
     Returns a dictionary iface name -> iface info, where iface info is the
     return value of get_iface_info().
     """
     self.log.trace("Testing available interfaces out of `{}'".format(
         list(possible_ifaces)
     ))
     valid_iface_infos = {
         x: net.get_iface_info(x)
         for x in net.get_valid_interfaces(possible_ifaces)
     }
     # Because get_iface_info() and get_valid_interfaces() are not one atomic
     # operation, there are rare scenarios when their return values are
     # inconsistent. To catch these cases, we filter the list again and warn
     # the user. Usually, this is not a problem and the next call to
     # _init_interfaces() will be back to normal.
     valid_iface_infos_filtered = {
         x: valid_iface_infos[x]
         for x in valid_iface_infos
         if valid_iface_infos[x]['ip_addr']
     }
     if len(valid_iface_infos) != len(valid_iface_infos_filtered):
         self.log.warning(
             "Number of detected CHDR devices is inconsistent. Dropped from "
             "{} to {}."
             .format(len(valid_iface_infos), len(valid_iface_infos_filtered))
         )
     if len(valid_iface_infos_filtered):
         self.log.debug(
             "Found CHDR interfaces: `{}'"
             .format(", ".join(list(valid_iface_infos.keys())))
         )
     else:
         self.log.info("No CHDR interfaces found!")
     return valid_iface_infos_filtered