pyof.v0x01.controller2switch.port_mod   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 53
Duplicated Lines 66.04 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
eloc 22
dl 35
loc 53
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A PortMod.__init__() 23 23 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
"""Modifications to the port from the controller."""
2
3
# System imports
4
5
# Third-party imports
6
7 1
from pyof.foundation.base import GenericMessage
8 1
from pyof.foundation.basic_types import HWAddress, Pad, UBInt16, UBInt32
9
# Local source tree imports
10 1
from pyof.v0x01.common.header import Header, Type
11 1
from pyof.v0x01.common.phy_port import PortConfig, PortFeatures
12
13 1
__all__ = ('PortMod',)
14
15
# Classes
16
17
18 1 View Code Duplication
class PortMod(GenericMessage):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
19
    """Implement messages to modify the physical port behavior."""
20
21 1
    header = Header(message_type=Type.OFPT_PORT_MOD)
22 1
    port_no = UBInt16()
23 1
    hw_addr = HWAddress()
24 1
    config = UBInt32(enum_ref=PortConfig)
25 1
    mask = UBInt32(enum_ref=PortConfig)
26 1
    advertise = UBInt32(enum_ref=PortFeatures)
27
    #: Pad to 64-bits.
28 1
    pad = Pad(4)
29
30 1
    def __init__(self, xid=None, port_no=None, hw_addr=None, config=None,
31
                 mask=None, advertise=None):
32
        """Create a PortMod with the optional parameters below.
33
34
        Args:
35
            xid (int): OpenFlow xid to the header.
36
            port_no (int): Physical port number.
37
            hw_addr (HWAddress): The hardware address is not configurable.
38
                This is used to sanity-check the request,
39
                so it must be the same as returned in an ofp_phy_port struct.
40
            config (~pyof.v0x01.common.phy_port.PortConfig):
41
                Bitmap of OFPPC_* flags
42
            mask (~pyof.v0x01.common.phy_port.PortConfig):
43
                Bitmap of OFPPC_* flags to be changed
44
            advertise (~pyof.v0x01.common.phy_port.PortFeatures):
45
                Bitmap of "ofp_port_features"s
46
        """
47 1
        super().__init__(xid)
48 1
        self.port_no = port_no
49 1
        self.hw_addr = hw_addr
50 1
        self.config = config
51 1
        self.mask = mask
52
        self.advertise = advertise
53