Passed
Push — master ( b50e97...feedcb )
by Humberto
01:28 queued 14s
created

tests.unit.v0x01.test_controller2switch.test_flow_mod   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 38
dl 0
loc 59
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A TestFlowDelete.setUpClass() 0 7 1
A TestFlowAdd.setUpClass() 0 8 1

3 Functions

Rating   Name   Duplication   Size   Complexity  
A _get_flowmod_kwargs() 0 13 1
A _get_actions() 0 4 1
A _get_match() 0 3 1
1
"""Flow modification (add/delete) message tests."""
2
from pyof.v0x01.common.action import ActionOutput
3
from pyof.v0x01.common.flow_match import Match
4
from pyof.v0x01.common.phy_port import Port
5
from pyof.v0x01.controller2switch.flow_mod import FlowMod, FlowModCommand
6
from tests.unit.test_struct import TestStruct
7
8
9
class TestFlowAdd(TestStruct):
10
    """Flow addition message tests (also those in :class:`.TestDump`)."""
11
12
    @classmethod
13
    def setUpClass(cls):
14
        """Configure raw file and its object in parent class (TestDump)."""
15
        super().setUpClass()
16
        super().set_raw_dump_file('v0x01', 'ofpt_flow_add')
17
        kwargs = _get_flowmod_kwargs(FlowModCommand.OFPFC_ADD)
18
        super().set_raw_dump_object(FlowMod, **kwargs)
19
        super().set_minimum_size(72)
20
21
22
class TestFlowDelete(TestStruct):
23
    """Flow deletion message tests (also those in :class:`.TestDump`)."""
24
25
    @classmethod
26
    def setUpClass(cls):
27
        """Configure raw file and its object in parent class (TestDump)."""
28
        super().setUpClass()
29
        super().set_raw_dump_file('v0x01', 'ofpt_flow_delete')
30
        kwargs = _get_flowmod_kwargs(FlowModCommand.OFPFC_DELETE)
31
        super().set_raw_dump_object(FlowMod, **kwargs)
32
        # No need to test minimum size again.
33
34
35
def _get_flowmod_kwargs(command):
36
    """Return parameters for FlowMod object."""
37
    return {'xid': 4,
38
            'command': command,
39
            'match': _get_match(),
40
            'cookie': 0,
41
            'idle_timeout': 0,
42
            'hard_timeout': 0,
43
            'priority': 32768,
44
            'buffer_id': 4294967295,
45
            'out_port': Port.OFPP_NONE,
46
            'flags': 0,
47
            'actions': _get_actions()}
48
49
50
def _get_match():
51
    """Return a Match object."""
52
    return Match()
53
54
55
def _get_actions():
56
    """Return a List of actions registered by flow object."""
57
    action = ActionOutput(port=65533, max_length=65535)
58
    return [action]
59