FlowRemoved.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 34
Code Lines 16

Duplication

Lines 34
Ratio 100 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 16
dl 34
loc 34
ccs 13
cts 13
cp 1
rs 9.6
c 0
b 0
f 0
cc 1
nop 13
crap 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
"""The controller has requested to be notified when flows time out."""
2
# System imports
3 1
from enum import IntEnum
4
5 1
from pyof.foundation.base import GenericMessage
6 1
from pyof.foundation.basic_types import UBInt8, UBInt16, UBInt32, UBInt64
7
# Local source tree imports
8 1
from pyof.v0x04.common.flow_match import Match
9 1
from pyof.v0x04.common.header import Header, Type
10
11 1
__all__ = ('FlowRemoved', 'FlowRemovedReason')
12
13
# Enums
14
15
16 1
class FlowRemovedReason(IntEnum):
17
    """Why the flow was removed."""
18
19
    #: Flow idle time exceeded idle_timeout
20 1
    OFPRR_IDLE_TIMEOUT = 0
21
    #: Time exceeded hard_timeout
22 1
    OFPRR_HARD_TIMEOUT = 1
23
    #: Evicted by a DELETE flow mod
24 1
    OFPRR_DELETE = 2
25
    #: Group was removed.
26 1
    OFPRR_GROUP_DELETE = 3
27
28
29
# Classes
30 1 View Code Duplication
class FlowRemoved(GenericMessage):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
31
    """Flow removed (datapath -> controller).
32
33
    If the controller has requested to be notified when flow entries time out
34
    or are deleted from tables, the datapath does this with the
35
    OFPT_FLOW_REMOVED message.
36
    """
37
38
    #: :class:`~pyof.v0x04.common.header.Header`: OpenFlow Header
39 1
    header = Header(message_type=Type.OFPT_FLOW_REMOVED)
40
    #: Opaque controller-issued identifier.
41 1
    cookie = UBInt64()
42
    #: Priority level of flow entry.
43 1
    priority = UBInt16()
44
    #: One of OFPRR_*.
45 1
    reason = UBInt8(enum_ref=FlowRemovedReason)
46
    #: ID of the table
47 1
    table_id = UBInt8()
48
    #: Time flow was alive in seconds.
49 1
    duration_sec = UBInt32()
50
    #: Time flow was alive in nanoseconds beyond duration_sec.
51 1
    duration_nsec = UBInt32()
52
    #: Idle timeout from original flow mod.
53 1
    idle_timeout = UBInt16()
54
    #: Hard timeout from original flow mod.
55 1
    hard_timeout = UBInt16()
56 1
    packet_count = UBInt64()
57 1
    byte_count = UBInt64()
58
    #: Description of fields. Variable size.
59
    #: :class:`~pyof.v0x04.common.flow_match.Match`
60 1
    match = Match()
61
62 1
    def __init__(self, xid=None, cookie=None, priority=None, reason=None,
63
                 table_id=None, duration_sec=None, duration_nsec=None,
64
                 idle_timeout=None, hard_timeout=None, packet_count=None,
65
                 byte_count=None, match=None):
66
        """Assign parameters to object attributes.
67
68
        Args:
69
            xid (int): OpenFlow Header's xid.
70
            cookie (int): Opaque controller-issued identifier.
71
            priority (int): Priority level of flow entry.
72
            reason (~pyof.v0x04.asynchronous.flow_removed.FlowRemovedReason):
73
                Why the flow was removed.
74
            table_id (int): ID of the table.
75
            duration_sec (int): Time the flow was alive in seconds.
76
            duration_nsec (int): Time the flow was alive in nanoseconds in
77
                addition to duration_sec.
78
            idle_timeout (int): Idle timeout from original flow mod.
79
            hard_timeout (int): Hard timeout from original flow mod.
80
            packet_count (int): Number of packets.
81
            byte_count (int): Byte count.
82
            match (~pyof.v0x04.common.flow_match.Match): Fields' description.
83
        """
84 1
        super().__init__(xid)
85 1
        self.cookie = cookie
86 1
        self.priority = priority
87 1
        self.reason = reason
88 1
        self.table_id = table_id
89 1
        self.duration_sec = duration_sec
90 1
        self.duration_nsec = duration_nsec
91 1
        self.idle_timeout = idle_timeout
92 1
        self.hard_timeout = hard_timeout
93 1
        self.packet_count = packet_count
94 1
        self.byte_count = byte_count
95
        self.match = match
96