PortStatus.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 12
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 12
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nop 4
crap 1
1
"""Defines an PortStatus Message."""
2
# System imports
3 1
from enum import IntEnum
4
5
# Local source tree imports
6 1
from pyof.foundation.base import GenericMessage
7 1
from pyof.foundation.basic_types import Pad, UBInt8
8 1
from pyof.v0x04.common.header import Header, Type
9 1
from pyof.v0x04.common.port import Port
10
11
# Third-party imports
12
13 1
__all__ = ('PortStatus', 'PortReason')
14
15
# Enums
16
17
18 1
class PortReason(IntEnum):
19
    """What changed about the physical port."""
20
21
    #: The port was added
22 1
    OFPPR_ADD = 0
23
    #: The port was removed
24 1
    OFPPR_DELETE = 1
25
    #: Some attribute of the port has changed
26 1
    OFPPR_MODIFY = 2
27
28
29
# Classes
30
31 1
class PortStatus(GenericMessage):
32
    """A physical port has changed in the datapath."""
33
34
    #: :class:`~pyof.v0x04.common.action.ActionHeader`: OpenFlow Header
35 1
    header = Header(message_type=Type.OFPT_PORT_STATUS)
36
    #: One of OFPPR_*.
37 1
    reason = UBInt8(enum_ref=PortReason)
38
    #: Align to 32-bits.
39 1
    pad = Pad(7)
40
    #: :class:`~pyof.v0x04.common.port.Port`
41 1
    desc = Port()
42
43 1
    def __init__(self, xid=None, reason=None, desc=None):
44
        """Assign parameters to object attributes.
45
46
        Args:
47
            xid (int): Header's xid.
48
            reason (~pyof.v0x04.asynchronous.port_status.PortReason):
49
                Addition, deletion or modification.
50
            desc (~pyof.v0x04.common.port.Port): Port description.
51
        """
52 1
        super().__init__(xid)
53 1
        self.reason = reason
54
        self.desc = desc
55