net Package

basic_machine Module

common Module

net_tc Module

Convenience methods for use to manipulate traffic control settings.

see http://linux.die.net/man/8/tc for details about traffic controls in linux.

Example
try:
import autotest.common as common # pylint: disable=W0611
except ImportError:
import common # pylint: disable=W0611

from autotest.client.net.net_tc import * from autotest.client.net.net_utils import *

class mock_netif(object):

def __init__(self, name):
self._name = name
def get_name(self):
return self._name

netem_qdisc = netem() netem_qdisc.add_param(‘loss 100%’)

ack_filter = u32filter() ack_filter.add_rule(‘match ip protocol 6 0xff’) ack_filter.add_rule(‘match u8 0x10 0x10 at nexthdr+13’) ack_filter.set_dest_qdisc(netem_qdisc)

root_qdisc = prio() root_qdisc.get_class(2).set_leaf_qdisc(netem_qdisc) root_qdisc.add_filter(ack_filter)

lo_if = mock_netif(‘lo’)

root_qdisc.setup(lo_if)

# run test here ... root_qdisc.restore(lo_if)

class autotest.client.net.net_tc.classful_qdisc(handle)[source]

Bases: autotest.client.net.net_tc.qdisc

add_class(child_class)[source]
add_filter(filter)[source]
classful = True
restore(netif)[source]
setup(netif)[source]
class autotest.client.net.net_tc.classless_qdisc(handle)[source]

Bases: autotest.client.net.net_tc.qdisc

classful = False
class autotest.client.net.net_tc.netem(handle=300)[source]

Bases: autotest.client.net.net_tc.classless_qdisc

add_param(param)[source]
name = 'netem'
setup(netif)[source]
autotest.client.net.net_tc.new_handle()[source]
class autotest.client.net.net_tc.pfifo(handle=200)[source]

Bases: autotest.client.net.net_tc.classless_qdisc

name = 'pfifo'
setup(netif)[source]
class autotest.client.net.net_tc.prio(handle=100, bands=3)[source]

Bases: autotest.client.net.net_tc.classful_qdisc

get_class(band)[source]
name = 'prio'
setup(netif)[source]
class autotest.client.net.net_tc.qdisc(handle)[source]

Bases: object

get_handle()[source]
get_parent_class()[source]
id()[source]
restore(netif)[source]
set_parent_class(parent_class)[source]
setup(netif)[source]
tc_cmd(tc_conf)[source]
class autotest.client.net.net_tc.tcclass(handle, minor, leaf_qdisc=None)[source]

Bases: object

add_child(child_class)[source]
get_leaf_qdisc()[source]
get_minor()[source]
get_parent_class()[source]
id()[source]
restore(netif)[source]
set_leaf_qdisc(leaf_qdisc)[source]
set_parent_class(parent_class)[source]
setup(netif)[source]
class autotest.client.net.net_tc.tcfilter[source]

Bases: object

conf_command = 'cmd'
conf_device = 'dev'
conf_flowid = 'flowid'
conf_name = 'name'
conf_params = 'params'
conf_parent = 'parent'
conf_priority = 'priority'
conf_protocol = 'protocol'
conf_qdiscid = 'qdiscid'
conf_rules = 'cmd'
conf_type = 'filtertype'
get_dest_qdisc()[source]
get_handle()[source]
get_parent_qdisc()[source]
get_priority()[source]
get_protocol()[source]
restore(netif)[source]
set_dest_qdisc(dest_qdisc)[source]
set_handle(handle)[source]
set_parent_qdisc(parent_qdisc)[source]
set_priority(priority)[source]
set_protocol(protocol)[source]
setup(netif)[source]
tc_cmd(tc_conf)[source]
class autotest.client.net.net_tc.u32filter[source]

Bases: autotest.client.net.net_tc.tcfilter

add_rule(rule)[source]
filtertype = 'u32'
restore(netif)[source]
setup(netif)[source]

net_utils Module

Convenience functions for use by network tests or whomever.

This library is to release in the public repository.

autotest.client.net.net_utils.bond()[source]
class autotest.client.net.net_utils.bonding[source]

Bases: object

This class implements bonding interface abstraction.

AB_MODE = 1
AD_MODE = 2
NO_MODE = 0
disable()[source]
enable()[source]
get_active_interfaces()[source]
get_mii_status()[source]
get_mode()[source]
get_slave_interfaces()[source]
is_bondable()[source]
is_enabled()[source]
wait_for_state_change()[source]

Wait for bonding state change.

Wait up to 90 seconds to successfully ping the gateway. This is to know when LACP state change has converged. (0 seconds is 3x lacp timeout, use by protocol)

class autotest.client.net.net_utils.ethernet[source]

Bases: object

Provide ethernet packet manipulation methods.

CHECKSUM_LEN = 4
ETH_LLDP_DST_MAC = '01:80:C2:00:00:0E'
ETH_PACKET_MAX_SIZE = 1518
ETH_PACKET_MIN_SIZE = 64
ETH_TYPE_8021Q = 33024
ETH_TYPE_ARP = 2054
ETH_TYPE_CDP = 8192
ETH_TYPE_IP = 2048
ETH_TYPE_IP6 = 34525
ETH_TYPE_LLDP = 35020
ETH_TYPE_LOOPBACK = 36864
FRAME_KEY_DST_MAC = 'dst'
FRAME_KEY_PAYLOAD = 'payload'
FRAME_KEY_PROTO = 'proto'
FRAME_KEY_SRC_MAC = 'src'
HDR_LEN = 14
static mac_binary_to_string(hwaddr)[source]

Converts a MAC address byte string to text string.

Converts a MAC byte string ‘xxxxxxxxxxxx’ to a text string ‘aa:aa:aa:aa:aa:aa’

Args:
hwaddr: a byte string containing the MAC address to convert.
Returns:
A text string.
static mac_string_to_binary(hwaddr)[source]

Converts a MAC address text string to byte string.

Converts a MAC text string from a text string ‘aa:aa:aa:aa:aa:aa’ to a byte string ‘xxxxxxxxxxxx’

Args:
hwaddr: a text string containing the MAC address to convert.
Returns:
A byte string.
static pack(dst, src, protocol, payload)[source]

Pack a frame in a byte string.

Args:
dst: destination mac in byte string format src: src mac address in byte string format protocol: short in network byte order payload: byte string payload data
Returns:
An ethernet frame with header and payload in a byte string.
static unpack(raw_frame)[source]

Unpack a raw ethernet frame.

Returns:
None on error
{ ‘dst’ : byte string,
‘src’ : byte string, ‘proto’ : short in host byte order, ‘payload’ : byte string

}

autotest.client.net.net_utils.ethernet_packet()[source]
autotest.client.net.net_utils.netif(name)[source]
autotest.client.net.net_utils.network()[source]
class autotest.client.net.net_utils.network_interface(name)[source]

Bases: object

DISABLE = False
ENABLE = True
add_maddr(maddr)[source]
del_maddr(maddr)[source]
disable_loopback()[source]
disable_promisc()[source]
down()[source]
enable_loopback()[source]
enable_promisc()[source]
exists()[source]
flush()[source]
get_carrier()[source]
get_driver()[source]
get_hwaddr()[source]
get_ipaddr()[source]
get_name()[source]
get_speed()[source]
get_stats()[source]
get_stats_diff(orig_stats)[source]
get_wakeon()[source]
is_autoneg_advertised()[source]
is_autoneg_on()[source]
is_down()[source]
is_full_duplex()[source]
is_loopback_enabled()[source]
is_pause_autoneg_on()[source]
is_rx_pause_on()[source]
is_rx_summing_on()[source]
is_scatter_gather_on()[source]
is_tso_on()[source]
is_tx_pause_on()[source]
is_tx_summing_on()[source]
parse_ethtool(field, match, option='', next_field='')[source]
recv(len)[source]
restore()[source]
send(buf)[source]
set_hwaddr(hwaddr)[source]
set_ipaddr(ipaddr)[source]
up()[source]
wait_for_carrier(timeout=60)[source]
class autotest.client.net.net_utils.network_utils[source]

Bases: object

disable_ip_local_loopback(ignore_status=False)[source]
enable_ip_local_loopback(ignore_status=False)[source]
get_ip_local(query_ip, netmask='24')[source]

Get ip address in local system which can communicate with query_ip.

Parameters:query_ip – IP of client which wants to communicate with autotest machine.
Returns:IP address which can communicate with query_ip
list()[source]
process_mpstat(mpstat_out, sample_count, loud=True)[source]

Parses mpstat output of the following two forms: 02:10:17 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 1012.87 02:10:13 PM 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 1019.00

reset(ignore_status=False)[source]
start(ignore_status=False)[source]
stop(ignore_status=False)[source]
class autotest.client.net.net_utils.raw_socket(iface_name)[source]

Bases: object

This class implements an raw socket abstraction.

ETH_P_ALL = 3
SOCKET_TIMEOUT = 1
close()[source]

Close the raw socket

open(protocol=None)[source]

Opens the raw socket to send and receive.

Args:
protocol : short in host byte order. None if ALL
recv(timeout)[source]

Synchroneous receive.

Receives one packet from the interface and returns its content in a string. Wait up to timeout for the packet if timeout is not 0. This function filters out all the packets that are less than the minimum ethernet packet size (60+crc).

Args:
timeout: max time in seconds to wait for the read to complete.
‘0’, wait for ever until a valid packet is received
Returns:
packet: None no packet was received
a binary string containing the received packet.

time_left: amount of time left in timeout

recv_from(dst_mac, src_mac, protocol)[source]

Receive an ethernet frame that matches the dst, src and proto.

Filters all received packet to find a matching one, then unpack it and present it to the caller as a frame.

Waits up to self._socket_timeout for a matching frame before returning.

Args:
dst_mac: ‘byte string’. None do not use in filter. src_mac: ‘byte string’. None do not use in filter. protocol: short in host byte order. None do not use in filter.
Returns:
ethernet frame: { ‘dst’ : byte string,
‘src’ : byte string, ‘proto’ : short in host byte order, ‘payload’ : byte string

}

send(packet)[source]

Send an ethernet packet.

send_to(dst_mac, src_mac, protocol, payload)[source]

Send an ethernet frame.

Send an ethernet frame, formating the header.

Args:
dst_mac: ‘byte string’ src_mac: ‘byte string’ protocol: short in host byte order payload: ‘byte string’
set_socket_timeout(timeout)[source]

Set the timeout use by recv_from.

Args:
timeout: time in seconds
socket()[source]
socket_timeout()[source]

Get the timeout use by recv_from

net_utils_mock Module

Set of Mocks and stubs for network utilities unit tests.

Implement a set of mocks and stubs use to implement unit tests for the network libraries.

class autotest.client.net.net_utils_mock.netif_stub(iface, cls, name, *args, **kwargs)[source]

Bases: autotest.client.shared.test_utils.mock.mock_class

wait_for_carrier(timeout)[source]
autotest.client.net.net_utils_mock.netutils_netif(iface)[source]
class autotest.client.net.net_utils_mock.network_interface_mock(iface='some_name', test_init=False)[source]

Bases: autotest.client.net.net_utils.network_interface

get_driver()[source]
get_ipaddr()[source]
is_down()[source]
is_loopback_enabled()[source]
wait_for_carrier(timeout=1)[source]
autotest.client.net.net_utils_mock.os_open(*args, **kwarg)[source]
class autotest.client.net.net_utils_mock.os_stub(symbol, **kwargs)[source]

Bases: autotest.client.shared.test_utils.mock.mock_function

open(*args, **kwargs)[source]
read(*args, **kwargs)[source]
readval = ''
class autotest.client.net.net_utils_mock.socket_stub(iface, cls, name, *args, **kwargs)[source]

Bases: autotest.client.shared.test_utils.mock.mock_class

Class use to mock sockets.

bind(arg)[source]
close()[source]
recv(size)[source]
send(buf)[source]
settimeout(timeout)[source]
socket(family, type)[source]