def test_iperf_upper_limit(self, requires_tc): # Upper limit is not an accurate measure. This is because it converges # over time and depends on current machine hardware (CPU). # Hence, it is hard to make hard assertions on it. The test should run # at least 60 seconds (the longer the better) and the user should # inspect the computed average rate and optionally the additional # traffic data that was collected in client.out in order to be # convinced QOS is working properly. limit_kbps = 1000 # 1 Mbps (in kbps) server_ip = '192.0.2.1' client_ip = '192.0.2.10' qos_out = {'ul': {'m2': limit_kbps}, 'ls': {'m2': limit_kbps}} # using a network namespace is essential since otherwise the kernel # short-circuits the traffic and bypasses the veth devices and the # classfull qdisc. with network_namespace( 'server_ns') as ns, bridge_device() as bridge, veth_pair() as ( server_peer, server_dev, ), veth_pair() as ( client_dev, client_peer, ): # iperf server and its veth peer lie in a separate network # namespace link_set_netns(server_dev, ns) bridge.add_port(server_peer) bridge.add_port(client_peer) netns_exec(ns, ['ip', 'link', 'set', 'dev', server_dev, 'up']) Interface.from_existing_dev_name(client_dev).add_ip( client_ip, 24, IpFamily.IPv4) netns_exec( ns, [ 'ip', '-4', 'addr', 'add', 'dev', server_dev, '%s/24' % server_ip, ], ) qos.configure_outbound(qos_out, client_peer, None) with running(IperfServer(server_ip, network_ns=ns)): client = IperfClient(server_ip, client_ip, test_time=60) client.start() max_rate = max([ float(interval['streams'][0]['bits_per_second']) // (2**10) for interval in client.out['intervals'] ]) assert 0 < max_rate < limit_kbps * 1.5
def _bridge_device(): with nettestlib.bridge_device() as bridge: yield bridge.devName
def _bridge_device(): with nettestlib.bridge_device() as bridge: yield bridge.devName
def bridge0(): with bridge_device() as br: yield br
def _bridge_device(): with bridge_device() as bridge: yield bridge
def bridge_dev(): with bridge_device() as dev: yield dev
def test_detect_device_driver(self): with bridge_device() as br: self.assertEqual('bridge', ethtool.driver_name(br.devName))