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-
classful= True¶
-
-
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-
name= 'netem'¶
-
-
class
autotest.client.net.net_tc.pfifo(handle=200)[source]¶ Bases:
autotest.client.net.net_tc.classless_qdisc-
name= 'pfifo'¶
-
-
class
autotest.client.net.net_tc.prio(handle=100, bands=3)[source]¶ Bases:
autotest.client.net.net_tc.classful_qdisc-
name= 'prio'¶
-
-
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'¶
-
net_utils Module¶
Convenience functions for use by network tests or whomever.
This library is to release in the public repository.
-
class
autotest.client.net.net_utils.bonding[source]¶ Bases:
objectThis class implements bonding interface abstraction.
-
AB_MODE= 1¶
-
AD_MODE= 2¶
-
NO_MODE= 0¶
-
-
class
autotest.client.net.net_utils.ethernet[source]¶ Bases:
objectProvide 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.
-
-
class
autotest.client.net.net_utils.network_interface(name)[source]¶ Bases:
object-
DISABLE= False¶
-
ENABLE= True¶
-
-
class
autotest.client.net.net_utils.network_utils[source]¶ Bases:
object-
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
-
-
class
autotest.client.net.net_utils.raw_socket(iface_name)[source]¶ Bases:
objectThis class implements an raw socket abstraction.
-
ETH_P_ALL= 3¶
-
SOCKET_TIMEOUT= 1¶
-
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_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’
-
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.network_interface_mock(iface='some_name', test_init=False)[source]¶
-
class
autotest.client.net.net_utils_mock.os_stub(symbol, **kwargs)[source]¶ Bases:
autotest.client.shared.test_utils.mock.mock_function-
readval= ''¶
-
-
class
autotest.client.net.net_utils_mock.socket_stub(iface, cls, name, *args, **kwargs)[source]¶ Bases:
autotest.client.shared.test_utils.mock.mock_classClass use to mock sockets.