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

tests.unit.v0x04.test_controller2switch.test_flow_mod   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 32
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A _new_list_of_instructions() 0 6 1
A _new_match() 0 10 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A TestFlowMod.test_min_size() 0 9 1
1
"""FlowMod test."""
2
from pyof.v0x04.common.action import ActionOutput, ListOfActions
3
from pyof.v0x04.common.flow_instructions import (
4
    InstructionApplyAction, ListOfInstruction)
5
from pyof.v0x04.common.flow_match import (
6
    Match, MatchType, OxmClass, OxmOfbMatchField, OxmTLV)
7
from pyof.v0x04.common.port import PortNo
8
from pyof.v0x04.controller2switch.flow_mod import FlowMod, FlowModCommand
9
from tests.unit.test_struct import TestStruct
10
11
12
class TestFlowMod(TestStruct):
13
    """FlowMod test."""
14
15
    def test_min_size(self):
16
        """Test struct minimum size."""
17
        super().set_raw_dump_file('v0x04', 'ofpt_flow_mod')
18
        super().set_raw_dump_object(FlowMod, xid=2219910763,
19
                                    command=FlowModCommand.OFPFC_ADD,
20
                                    priority=1000,
21
                                    match=_new_match(),
22
                                    instructions=_new_list_of_instructions())
23
        super().set_minimum_size(56)
24
25
26
def _new_match():
27
    """Crate new Match instance."""
28
    oxm_tlv1 = OxmTLV(oxm_class=OxmClass.OFPXMC_OPENFLOW_BASIC,
29
                      oxm_field=OxmOfbMatchField.OFPXMT_OFB_ETH_TYPE,
30
                      oxm_hasmask=False, oxm_value=b'\x88\xcc')
31
    oxmt_lv2 = OxmTLV(oxm_class=OxmClass.OFPXMC_OPENFLOW_BASIC,
32
                      oxm_field=OxmOfbMatchField.OFPXMT_OFB_VLAN_VID,
33
                      oxm_hasmask=False, oxm_value=b'\x1e\xd7')
34
    return Match(match_type=MatchType.OFPMT_OXM,
35
                 oxm_match_fields=[oxm_tlv1, oxmt_lv2])
36
37
def _new_list_of_instructions():
38
    """Crate new ListOfInstruction."""
39
    output = ActionOutput(port=PortNo.OFPP_CONTROLLER)
40
    loa = ListOfActions([output])
41
    instruction = InstructionApplyAction(loa)
42
    return ListOfInstruction([instruction])
43