File: test_classful.py

package info (click to toggle)
pyroute2 0.8.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,700 kB
  • sloc: python: 50,245; makefile: 280; javascript: 183; ansic: 81; sh: 44; awk: 17
file content (58 lines) | stat: -rw-r--r-- 2,150 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import errno

import pytest
from pr2test.context_manager import make_test_matrix
from pr2test.marks import require_root
from pr2test.tools import qdisc_exists

from pyroute2 import NetlinkError

pytestmark = [require_root()]
test_matrix = make_test_matrix(targets=['local', 'netns'])


@pytest.mark.parametrize('context', test_matrix, indirect=True)
def test_drr(context):
    index, ifname = context.default_interface
    try:
        context.ipr.tc('add', 'drr', index=index, handle='1:')
    except NetlinkError as e:
        if e.code == errno.ENOENT:
            pytest.skip('qdisc not supported: drr')
        raise
    context.ipr.tc('add-class', 'drr', index=index, handle='1:20', quantum=20)
    context.ipr.tc('add-class', 'drr', index=index, handle='1:30', quantum=30)
    assert qdisc_exists(context.netns, 'drr', ifname=ifname)
    cls = context.ipr.get_classes(index=index)
    assert len(cls) == 2
    assert cls[0].get_attr('TCA_KIND') == 'drr'
    assert cls[1].get_attr('TCA_KIND') == 'drr'
    assert cls[0].get_attr('TCA_OPTIONS').get_attr('TCA_DRR_QUANTUM') == 20
    assert cls[1].get_attr('TCA_OPTIONS').get_attr('TCA_DRR_QUANTUM') == 30


@pytest.mark.parametrize('context', test_matrix, indirect=True)
def test_hfsc(context):
    index, ifname = context.default_interface
    # root queue
    context.ipr.tc('add', 'hfsc', index=index, handle='1:0', default='1:1')
    assert qdisc_exists(context.netns, 'hfsc', ifname=ifname, defcls=1)
    # classes
    context.ipr.tc(
        'add-class',
        'hfsc',
        index=index,
        handle='1:1',
        parent='1:0',
        rsc={'m2': '3mbit'},
    )
    cls = context.ipr.get_classes(index=index)
    assert len(cls) == 2  # implicit root class + the defined one
    assert cls[0].get_attr('TCA_KIND') == 'hfsc'
    assert cls[1].get_attr('TCA_KIND') == 'hfsc'
    curve = cls[1].get_attr('TCA_OPTIONS').get_attr('TCA_HFSC_RSC')
    assert curve['m1'] == 0
    assert curve['d'] == 0
    assert curve['m2'] == 375000
    assert cls[1].get_attr('TCA_OPTIONS').get_attr('TCA_HFSC_FSC') is None
    assert cls[1].get_attr('TCA_OPTIONS').get_attr('TCA_HFSC_USC') is None