示例#1
0
 def __init__(self, config):
     """Initialize AP."""
     self.ssh_settings = settings.from_config(config["ssh_config"])
     self.ssh = connection.SshConnection(self.ssh_settings)
     self.log = logger.create_logger(lambda msg: "[OpenWrtAP|%s] %s" %
                                     (self.ssh_settings.hostname, msg))
     self.wireless_setting = None
     self.network_setting = network_settings.NetworkSettings(
         self.ssh, config["ssh_config"]["host"], self.log)
示例#2
0
 def __init__(self, adb):
     self._listen_for_port_lock = threading.Lock()
     self._sl4a_ports = set()
     self.adb = adb
     self.log = logger.create_logger(lambda msg: '[SL4A Manager|%s] %s' %
                                     (adb.serial, msg))
     self.sessions = {}
     self._started = False
     self.error_reporter = error_reporter.ErrorReporter('SL4A %s' %
                                                        adb.serial)
    def __init__(self, serial, rpc_client):
        self._serial = serial
        self._rpc_client = rpc_client
        self._started = False
        self._executor = None
        self._event_dict = {}
        self._handlers = {}
        self._lock = threading.RLock()

        def _log_formatter(message):
            """Defines the formatting used in the logger."""
            return '[E Dispatcher|%s|%s] %s' % (self._serial,
                                                self._rpc_client.uid, message)

        self.log = logger.create_logger(_log_formatter)
示例#4
0
    def __init__(self, configs):
        """
        Args:
            configs: configs for the access point from config file.
        """
        self.ssh_settings = settings.from_config(configs['ssh_config'])
        self.log = logger.create_logger(lambda msg: '[Access Point|%s] %s' %
                                        (self.ssh_settings.hostname, msg))
        self.device_pdu_config = configs.get('PduDevice', None)
        self.identifier = self.ssh_settings.hostname

        if 'ap_subnet' in configs:
            self._AP_2G_SUBNET_STR = configs['ap_subnet']['2g']
            self._AP_5G_SUBNET_STR = configs['ap_subnet']['5g']
        else:
            self._AP_2G_SUBNET_STR = _AP_2GHZ_SUBNET_STR_DEFAULT
            self._AP_5G_SUBNET_STR = _AP_5GHZ_SUBNET_STR_DEFAULT

        self._AP_2G_SUBNET = dhcp_config.Subnet(
            ipaddress.ip_network(self._AP_2G_SUBNET_STR))
        self._AP_5G_SUBNET = dhcp_config.Subnet(
            ipaddress.ip_network(self._AP_5G_SUBNET_STR))

        self.ssh = connection.SshConnection(self.ssh_settings)

        # Singleton utilities for running various commands.
        self._ip_cmd = ip.LinuxIpCommand(self.ssh)
        self._route_cmd = route.LinuxRouteCommand(self.ssh)

        # A map from network interface name to _ApInstance objects representing
        # the hostapd instance running against the interface.
        self._aps = dict()
        self._dhcp = None
        self._dhcp_bss = dict()
        self.bridge = bridge_interface.BridgeInterface(self)
        self.interfaces = ap_get_interface.ApInterfaces(self)
        self.iwconfig = ap_iwconfig.ApIwconfig(self)

        # Get needed interface names and initialize the unneccessary ones.
        self.wan = self.interfaces.get_wan_interface()
        self.wlan = self.interfaces.get_wlan_interface()
        self.wlan_2g = self.wlan[0]
        self.wlan_5g = self.wlan[1]
        self.lan = self.interfaces.get_lan_interface()
        self._initial_ap()
        self.scapy_install_path = None
        self.setup_bridge = False
示例#5
0
    def __init__(self, adb, ports, client_socket, socket_fd, uid=UNKNOWN_UID):
        self._client_socket = client_socket
        self._socket_file = socket_fd
        self._ticket_counter = 0
        self._ticket_lock = threading.Lock()
        self.adb = adb
        self.uid = uid

        def _log_formatter(message):
            """Defines the formatting used in the logger."""
            return '[SL4A Client|%s|%s] %s' % (self.adb.serial, self.uid,
                                               message)

        self.log = logger.create_logger(_log_formatter)

        self.ports = ports
        self.set_timeout(rpc_client.SOCKET_TIMEOUT)
示例#6
0
    def __init__(self, settings):
        """
        Args:
            settings: The ssh settings to use for this connection.
            formatter: The object that will handle formatting ssh command
                       for use with the background job.
        """
        self._settings = settings
        self._formatter = formatter.SshFormatter()
        self._lock = threading.Lock()
        self._master_ssh_proc = None
        self._master_ssh_tempdir = None
        self._tunnels = list()

        def log_line(msg):
            return '[SshConnection | %s] %s' % (self._settings.hostname, msg)

        self.log = logger.create_logger(log_line)
示例#7
0
    def __init__(self,
                 adb,
                 host_port,
                 device_port,
                 get_server_port_func,
                 on_error_callback,
                 max_connections=None):
        """Creates an SL4A Session.

        Args:
            adb: A reference to the adb proxy
            get_server_port_func: A lambda (int) that returns the corrected
                server port. The int passed in hints at which port to use, if
                possible.
            host_port: The port the host machine uses to connect to the SL4A
                server for its first connection.
            device_port: The SL4A server port to be used as a hint for which
                SL4A server to connect to.
        """
        self._event_dispatcher = None
        self._terminate_lock = threading.Lock()
        self._terminated = False
        self.adb = adb

        def _log_formatter(message):
            return '[SL4A Session|%s|%s] %s' % (self.adb.serial, self.uid,
                                                message)

        self.log = logger.create_logger(_log_formatter)

        self.server_port = device_port
        self.uid = UNKNOWN_UID
        self.obtain_server_port = get_server_port_func
        self._on_error_callback = on_error_callback

        connection_creator = self._rpc_connection_creator(host_port)
        self.rpc_client = rpc_client.RpcClient(self.uid,
                                               self.adb.serial,
                                               self.diagnose_failure,
                                               connection_creator,
                                               max_connections=max_connections)
示例#8
0
    def __init__(self, configs):
        """Initialize objects.

        Args:
            configs: config for the packet capture.
        """
        self.ssh_settings = settings.from_config(configs['ssh_config'])
        self.ssh = connection.SshConnection(self.ssh_settings)
        self.log = logger.create_logger(lambda msg: '[%s|%s] %s' % (
            MOBLY_CONTROLLER_CONFIG_NAME, self.ssh_settings.hostname, msg))

        self._create_interface(MON_2G, 'monitor')
        self._create_interface(MON_5G, 'monitor')
        self.managed_mode = True
        result = self.ssh.run('ifconfig -a', ignore_status=True)
        if result.stderr or SCAN_IFACE not in result.stdout:
            self.managed_mode = False
        if self.managed_mode:
            self._create_interface(SCAN_IFACE, 'managed')

        self.pcap_properties = dict()
        self._pcap_stop_lock = threading.Lock()
示例#9
0
    def __init__(self,
                 uid,
                 serial,
                 on_error_callback,
                 _create_connection_func,
                 max_connections=None):
        """Creates a new RpcClient object.

        Args:
            uid: The session uid this client is a part of.
            serial: The serial of the Android device. Used for logging.
            on_error_callback: A callback for when a connection error is raised.
            _create_connection_func: A reference to the function that creates a
                new session.
            max_connections: The maximum number of connections the RpcClient
                can have.
        """
        self._serial = serial
        self.on_error = on_error_callback
        self._create_connection_func = _create_connection_func
        self._free_connections = [self._create_connection_func(uid)]

        self.uid = self._free_connections[0].uid
        self._lock = threading.Lock()

        def _log_formatter(message):
            """Formats the message to be logged."""
            return '[RPC Service|%s|%s] %s' % (self._serial, self.uid, message)

        self._log = logger.create_logger(_log_formatter)

        self._working_connections = []
        if max_connections is None:
            self.max_connections = RpcClient.DEFAULT_MAX_CONNECTION
        else:
            self.max_connections = max_connections

        self._async_client = RpcClient.AsyncClient(self)
        self.is_alive = True
示例#10
0
]

# GPS TTFF Log Reading Config
CONFIG_GPSTTFFLOG = {
    'ttff_info':
    r'Loop:(?P<loop>\d+)\s+'
    r'(?P<start_datetime>\d+\/\d+\/\d+-\d+:\d+:\d+.\d+)\s+'
    r'(?P<stop_datetime>\d+\/\d+\/\d+-\d+:\d+:\d+.\d+)\s+'
    r'(?P<ttff>\d+.\d+)\s+'
    r'\[Antenna_Avg Top4 : (?P<ant_avg_top4_cn0>\d+.\d+)\]\s'
    r'\[Antenna_Avg : (?P<ant_avg_cn0>\d+.\d+)\]\s'
    r'\[Baseband_Avg Top4 : (?P<bb_avg_top4_cn0>\d+.\d+)\]\s'
    r'\[Baseband_Avg : (?P<bb_avg_cn0>\d+.\d+)\]\s+\[(?P<fix_type>\d+\w+ fix)\]\s+'
    r'\[Satellites used for fix : (?P<satnum_for_fix>\d+)\]'
}
LOGPARSE_UTIL_LOGGER = logger.create_logger()


def parse_log_to_df(filename, configs, index_rownum=True):
    r"""Parse log to a dictionary of Pandas dataframes.

    Args:
      filename: log file name.
        Type String.
      configs: configs dictionary of parsed Pandas dataframes.
        Type dictionary.
        dict key, the parsed pattern name, such as 'Speed',
        dict value, regex of the config pattern,
          Type Raw String.
      index_rownum: index row number from raw data.
        Type Boolean.