Passed
Pull Request — master (#577)
by Gleyberson
02:14
created

tests.v0x04.test_controller2switch.test_flow_mod   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 24.39 %

Importance

Changes 0
Metric Value
wmc 3
eloc 31
dl 10
loc 41
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A TestFlowMod.test_min_size() 0 9 1

2 Functions

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

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
"""FlowMod test."""
2
from pyof.v0x04.common.flow_instructions import InstructionApplyAction, InstructionType, ListOfInstruction
3
from pyof.v0x04.common.flow_match import (
4
    Match, MatchType, OxmClass, OxmOfbMatchField, OxmTLV)
5
from pyof.v0x04.controller2switch.flow_mod import FlowMod, FlowModCommand
6
from pyof.v0x04.common.action import ActionOutput, ListOfActions
7
from pyof.v0x04.common.port import PortNo
8
from tests.test_struct import TestStruct
9
10
class TestFlowMod(TestStruct):
11
    """FlowMod test."""
12
13
    def test_min_size(self):
14
        """Test struct minimum size."""
15
        super().set_raw_dump_file('v0x04', 'ofpt_flow_mod')
16
        super().set_raw_dump_object(FlowMod, xid=2219910763,
17
                                             command=FlowModCommand.OFPFC_ADD,
18
                                             priority = 1000,
19
                                             match = _new_match(),
20
                                             instructions = _new_list_of_instructions())
21
        super().set_minimum_size(56)
22
23
24 View Code Duplication
def _new_match():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
25
    """Crate new Match instance."""
26
    oxmtlv1 = OxmTLV(oxm_class=OxmClass.OFPXMC_OPENFLOW_BASIC,
27
                    oxm_field=OxmOfbMatchField.OFPXMT_OFB_ETH_TYPE,
28
                    oxm_hasmask=False, oxm_value=b'\x88\xcc')
29
    oxmtlv2 = OxmTLV(oxm_class=OxmClass.OFPXMC_OPENFLOW_BASIC,
30
                oxm_field=OxmOfbMatchField.OFPXMT_OFB_VLAN_VID,
31
                oxm_hasmask=False, oxm_value=b'\x1e\xd7')
32
    return Match(match_type=MatchType.OFPMT_OXM,
33
                 oxm_match_fields=[oxmtlv1, oxmtlv2])
34
35
def _new_list_of_instructions():
36
    """Crate new ListOfInstruction."""
37
    ao = ActionOutput(port=PortNo.OFPP_CONTROLLER)
38
    loa = ListOfActions([ao])
39
    instruction = InstructionApplyAction(loa)
40
    return ListOfInstruction([instruction])
41