Test Failed
Pull Request — master (#505)
by macartur
01:31
created

QueuePropMaxRate   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
dl 0
loc 18
ccs 0
cts 7
cp 0
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 8 1
1
"""Defines OpenFlow queues structures and related items."""
2
3
# System imports
4
from enum import IntEnum
5
6
# Local source tree imports
7
from pyof.foundation.base import GenericStruct
8
from pyof.foundation.basic_types import (
9
    BinaryData, FixedTypeList, Pad, UBInt16, UBInt32)
10
11
# Third-party imports
12
13
__all__ = ('ListOfProperties', 'ListOfQueues', 'PacketQueue',
14
           'QueueProperties', 'QueuePropExperimenter', 'QueuePropHeader',
15
           'QueuePropMaxRate', 'QueuePropMinRate')
16
17
# Enums
18
19
20
class QueueProperties(IntEnum):
21
    """Describe queue properties."""
22
23
    #: Minimum datarate guaranteed
24
    OFPQT_MIN_RATE = 1
25
    #: Maximum datarate guaranteed
26
    OFPQT_MAX_RATE = 2
27
    #: Experimenter defined property
28
    OFPQT_EXPERIMENTER = 0xffff
29
30
31
# Classes
32
33
34
class QueuePropHeader(GenericStruct):
35
    """Describe the header of each queue property."""
36
37
    #: One of OFPQT_*
38
    queue_property = UBInt16(enum_ref=QueueProperties)
39
    #: Length of property, including this header
40
    length = UBInt16()
41
    #: 64-bit alignment
42
    pad = Pad(4)
43
44
    def __init__(self, queue_property=None, length=None):
45
        """Create a QueuePropHeader with the optional parameters below.
46
47
        Args:
48
            queue_property (~pyof.v0x04.common.queue.QueueProperties):
49
                The queue property.
50
            length (int): Length of property, including this header.
51
        """
52
        super().__init__()
53
        self.queue_property = queue_property
54
        self.length = length
55
56
57
class ListOfProperties(FixedTypeList):
58
    """List of properties.
59
60
    Represented by instances of :class:`QueuePropHeader` and used on
61
    :class:`PacketQueue` objects.
62
    """
63
64
    def __init__(self, items=None):
65
        """Create a ListOfProperties with the optional parameters below.
66
67
        Args:
68
            items (:class:`list` of/or :class:`QueuePropHeader`):
69
                :class:`QueuePropHeader` instance or list of instances.
70
        """
71
        super().__init__(pyof_class=QueuePropHeader,
72
                         items=items)
73
74
75
class PacketQueue(GenericStruct):
76
    """Describe a queue."""
77
78
    #: id for the specific queue
79
    queue_id = UBInt32()
80
    #: Port this queue is attached to.
81
    port = UBInt32()
82
    #: Length, in bytes, of this queue desc.
83
    length = UBInt16()
84
    #: 64-bit alignment.
85
    pad = Pad(6)
86
    #: List of properties
87
    properties = ListOfProperties()
88
89
    def __init__(self, queue_id=None, port=None, length=None, properties=None):
90
        """Create a PacketQueue with the optional parameters below.
91
92
        Args:
93
            queue_id (int): ID of the specific queue.
94
            port (int): Port his queue is attached to.
95
            length (int): Length in bytes of this queue desc.
96
            properties(~pyof.v0x04.common.queue.ListOfProperties):
97
                Queue's list of properties. Default is an empty list.
98
        """
99
        super().__init__()
100
        self.queue_id = queue_id
101
        self.port = port
102
        self.length = length
103
        self.properties = [] if properties is None else properties
104
105
106
class ListOfQueues(FixedTypeList):
107
    """List of queues.
108
109
    Represented by instances of :class:`PacketQueue` and used on
110
    :class:`QueueGetConfigReply` objects.
111
    """
112
113
    def __init__(self, items=None):
114
        """Create a ListOfQueues with the optional parameters below.
115
116
        Args:
117
            items (:class:`list` of/or :class:`PacketQueue`):
118
                :class:`PacketQueue` instance or list of instances.
119
        """
120
        super().__init__(pyof_class=PacketQueue,
121
                         items=items)
122
123
124
class QueuePropExperimenter(GenericStruct):
125
    """Experimenter queue property uses the following structure and fields."""
126
127
    prop_header = QueuePropHeader(
128
        queue_property=QueueProperties.OFPQT_EXPERIMENTER, length=16)
129
    #: Experimenter ID which takes the same form as in struct
130
    #:     ofp_experimenter_header
131
    experimenter = UBInt32()
132
    #: 64-bit alignmet.
133
    pad = Pad(4)
134
    #: Experimenter defined data.
135
    data = BinaryData()
136
137
    def __init__(self, experimenter=None, data=None):
138
        """Create a QueuePropExperimenter with the optional parameters below.
139
140
        Args:
141
            experimenter (int): Experimenter ID which takes the same form as in
142
                struct ofp_experimenter_header.
143
            data (bytes): Experimenter defined data.
144
        """
145
        super().__init__()
146
        self.experimenter = experimenter
147
        self.data = data
148
149
150
class QueuePropMaxRate(GenericStruct):
151
    """Maximum-rate queue property uses the following structure and fields."""
152
153
    prop_header = QueuePropHeader(
154
        queue_property=QueueProperties.OFPQT_MAX_RATE, length=16)
155
    #: In 1/10 of a percent; >1000 -> disabled.
156
    rate = UBInt16()
157
    #: 64-bit alignmet.
158
    pad = Pad(6)
159
160
    def __init__(self, rate=None):
161
        """Create a QueuePropMaxRate with the optional parameters below.
162
163
        Args:
164
            rate (int): In 1/10 of a percent (1000 -> 100%); >1000 -> disabled.
165
        """
166
        super().__init__()
167
        self.rate = rate
168
169
170
class QueuePropMinRate(GenericStruct):
171
    """Minimum-rate queue property uses the following structure and fields."""
172
173
    prop_header = QueuePropHeader(
174
        queue_property=QueueProperties.OFPQT_MIN_RATE, length=16)
175
    #: In 1/10 of a percent; >1000 -> disabled.
176
    rate = UBInt16()
177
    #: 64-bit alignmet.
178
    pad = Pad(6)
179
180
    def __init__(self, rate=None):
181
        """Create a QueuePropMinRate with the optional parameters below.
182
183
        Args:
184
            rate (int): In 1/10 of a percent (1000 -> 100%); >1000 -> disabled.
185
        """
186
        super().__init__()
187
        self.rate = rate
188