mobly.controllers package

Subpackages

Submodules

mobly.controllers.android_device module

mobly.controllers.attenuator module

Controller module for attenuators.

Sample Config:

"Attenuator": [
    {
        "address": "192.168.1.12",
        "port": 23,
        "model": "minicircuits",
        "paths": ["AP1-2G", "AP1-5G", "AP2-2G", "AP2-5G"]
    },
    {
        "address": "192.168.1.14",
        "port": 23,
        "model": "minicircuits",
        "paths": ["AP-DUT"]
    }
]
class mobly.controllers.attenuator.AttenuatorPath(attenuation_device, idx=0, name=None)[source]

Bases: object

A convenience class that allows users to control each attenuator path separately as different objects, as opposed to passing in an index number to the functions of an attenuator device object.

This decouples the test code from the actual attenuator device used in the physical test bed.

For example, if a test needs to attenuate four signal paths, this allows the test to do:

self.attenuation_paths[0].set_atten(50)
self.attenuation_paths[1].set_atten(40)

instead of:

self.attenuators[0].set_atten(0, 50)
self.attenuators[0].set_atten(1, 40)

The benefit the former is that the physical test bed can use either four single-channel attenuators, or one four-channel attenuators. Whereas the latter forces the test bed to use a four-channel attenuator.

get_atten()[source]

Gets the current attenuation setting of Attenuator.

Returns:A float that is the current attenuation value. Unit is db.
get_max_atten()[source]

Gets the max attenuation supported by the Attenuator.

Returns:A float that is the max attenuation value.
set_atten(value)[source]

This function sets the attenuation of Attenuator.

Parameters:value – This is a floating point value for nominal attenuation to be set. Unit is db.
exception mobly.controllers.attenuator.Error[source]

Bases: Exception

This is the Exception class defined for all errors generated by Attenuator-related modules.

mobly.controllers.attenuator.create(configs)[source]
mobly.controllers.attenuator.destroy(objs)[source]

mobly.controllers.iperf_server module

mobly.controllers.monsoon module

mobly.controllers.sniffer module

class mobly.controllers.sniffer.ActiveCaptureContext(sniffer, timeout=None)[source]

Bases: object

This class defines an object representing an active sniffer capture.

The object is returned by a Sniffer.start_capture() command and terminates the capture when the ‘with’ clause exits. It is syntactic sugar for try/finally.

exception mobly.controllers.sniffer.ExecutionError[source]

Bases: mobly.controllers.sniffer.SnifferError

This exception is thrown when trying to configure the capture device or when trying to execute the capture operation.

When this exception is seen, it is possible that the sniffer module is run without sudo (for local sniffers) or keys are out-of-date (for remote sniffers).

exception mobly.controllers.sniffer.InvalidDataError[source]

Bases: Exception

This exception is thrown when invalid configuration data is passed to a method.

exception mobly.controllers.sniffer.InvalidOperationError[source]

Bases: mobly.controllers.sniffer.SnifferError

Certain methods may only be accessed when the instance upon which they are invoked is in a certain state. This indicates that the object is not in the correct state for a method to be called.

class mobly.controllers.sniffer.Sniffer(interface, logger, base_configs=None)[source]

Bases: object

This class defines an object representing a sniffer.

The object defines the generic behavior of sniffers - irrespective of how they are implemented, or where they are located: on the local machine or on the remote machine.

CONFIG_KEY_CHANNEL = 'channel'
get_capture_file()[source]

The sniffer places a capture in the logger directory. This function enables the caller to obtain the path of that capture.

Returns:The full path of the current or last capture.
get_descriptor()[source]

This function returns a string describing the sniffer. The specific string (and its format) is up to each derived sniffer type.

Returns:A string describing the sniffer.
get_interface()[source]

This function returns The interface used to configure the sniffer, e.g. ‘wlan0’.

Returns:The interface (string) used to configure the sniffer. Corresponds to the ‘Interface’ key of the sniffer configuration.
get_subtype()[source]

This function returns the sub-type of the sniffer.

Returns:The sub-type (string) of the sniffer. Corresponds to the ‘SubType’ key of the sniffer configuration.
get_type()[source]

This function returns the type of the sniffer.

Returns:The type (string) of the sniffer. Corresponds to the ‘Type’ key of the sniffer configuration.
start_capture(override_configs=None, additional_args=None, duration=None, packet_count=None)[source]

This function starts a capture which is saved to the specified file path.

Depending on the type/subtype and configuration of the sniffer the capture may terminate on its own or may require an explicit call to the stop_capture() function.

This is a non-blocking function so a terminating function must be called either explicitly or implicitly:

  • Explicitly: call either stop_capture() or wait_for_capture()
  • Implicitly: use with a with clause. The wait_for_capture()
    function will be called if a duration is specified (i.e. is not None), otherwise a stop_capture() will be called.

The capture is saved to a file in the log path of the logger. Use the get_capture_file() to get the full path to the current or most recent capture.

Parameters:
  • override_configs – A dictionary which is combined with the base_configs (“BaseConfigs” in the sniffer configuration). The keys (specified by Sniffer.CONFIG_KEY_*) determine the configuration of the sniffer for this specific capture.
  • additional_args – A string specifying additional raw command-line arguments to pass to the underlying sniffer. The interpretation of these flags is sniffer-dependent.
  • duration – An integer specifying the number of seconds over which to capture packets. The sniffer will be terminated after this duration. Used in implicit mode when using a ‘with’ clause. In explicit control cases may have to be performed using a sleep+stop or as the timeout argument to the wait function.
  • packet_count – An integer specifying the number of packets to capture before terminating. Should be used with duration to guarantee that capture terminates at some point (even if did not capture the specified number of packets).
Returns:

An ActiveCaptureContext process which can be used with a ‘with’ clause.

Raises:
  • InvalidDataError – for invalid configurations
  • NoPermissionError – if an error occurs while configuring and running the sniffer.
stop_capture()[source]

This function stops a capture and guarantees that the capture is saved to the capture file configured during the start_capture() method. Depending on the type of the sniffer the file may previously contain partial results (e.g. for a local sniffer) or may not exist until the stop_capture() method is executed (e.g. for a remote sniffer).

Depending on the type/subtype and configuration of the sniffer the capture may terminate on its own without requiring a call to this function. In such a case it is still necessary to call either this function or the wait_for_capture() function to make sure that the capture file is moved to the correct location.

Raises:NoPermissionError – No permission when trying to stop a capture and save the capture file.
wait_for_capture(timeout=None)[source]

This function waits for a capture to terminate and guarantees that the capture is saved to the capture file configured during the start_capture() method. Depending on the type of the sniffer the file may previously contain partial results (e.g. for a local sniffer) or may not exist until the stop_capture() method is executed (e.g. for a remote sniffer).

Depending on the type/subtype and configuration of the sniffer the capture may terminate on its own without requiring a call to this function. In such a case it is still necessary to call either this function or the stop_capture() function to make sure that the capture file is moved to the correct location.

Parameters:timeout – An integer specifying the number of seconds to wait for the capture to terminate on its own. On expiration of the timeout the sniffer is stopped explicitly using the stop_capture() function.
Raises:NoPermissionError – No permission when trying to stop a capture and save the capture file.
exception mobly.controllers.sniffer.SnifferError[source]

Bases: Exception

This is the Exception class defined for all errors generated by Sniffer-related modules.

mobly.controllers.sniffer.create(configs)[source]

Initializes the sniffer structures based on the JSON configuration. The expected keys are:

  • Type: A first-level type of sniffer. Planned to be ‘local’ for
    sniffers running on the local machine, or ‘remote’ for sniffers running remotely.
  • SubType: The specific sniffer type to be used.
  • Interface: The WLAN interface used to configure the sniffer.
  • BaseConfigs: A dictionary specifying baseline configurations of
    the sniffer. Configurations can be overridden when starting a capture. The keys must be one of the Sniffer.CONFIG_KEY_* values.
mobly.controllers.sniffer.destroy(objs)[source]

Destroys the sniffers and terminates any ongoing capture sessions.

Module contents