pyof.v0x04.common.queue.QueuePropHeader.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 11
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 11
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nop 3
crap 1
1
"""Defines OpenFlow queues structures and related items."""
2
3
# System imports
4 1
from enum import IntEnum
5
6
# Local source tree imports
7 1
from pyof.foundation.base import GenericStruct
8 1
from pyof.foundation.basic_types import (
9
    BinaryData, FixedTypeList, Pad, UBInt16, UBInt32)
10
11
# Third-party imports
12
13 1
__all__ = ('ListOfProperties', 'ListOfQueues', 'PacketQueue',
14
           'QueueProperties', 'QueuePropExperimenter', 'QueuePropHeader',
15
           'QueuePropMaxRate', 'QueuePropMinRate')
16
17
# Enums
18
19
20 1
class QueueProperties(IntEnum):
21
    """Describe queue properties."""
22
23
    #: Minimum datarate guaranteed
24 1
    OFPQT_MIN_RATE = 1
25
    #: Maximum datarate guaranteed
26 1
    OFPQT_MAX_RATE = 2
27
    #: Experimenter defined property
28 1
    OFPQT_EXPERIMENTER = 0xffff
29
30
31
# Classes
32
33
34 1
class QueuePropHeader(GenericStruct):
35
    """Describe the header of each queue property."""
36
37
    #: One of OFPQT_*
38 1
    queue_property = UBInt16(enum_ref=QueueProperties)
39
    #: Length of property, including this header
40 1
    length = UBInt16()
41
    #: 64-bit alignment
42 1
    pad = Pad(4)
43
44 1
    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 1
        super().__init__()
53 1
        self.queue_property = queue_property
54 1
        self.length = length
55
56
57 1
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 1
    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 1
        super().__init__(pyof_class=QueuePropHeader,
72
                         items=items)
73
74
75 1 View Code Duplication
class PacketQueue(GenericStruct):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
76
    """Describe a queue."""
77
78
    #: id for the specific queue
79 1
    queue_id = UBInt32()
80
    #: Port this queue is attached to.
81 1
    port = UBInt32()
82
    #: Length, in bytes, of this queue desc.
83 1
    length = UBInt16()
84
    #: 64-bit alignment.
85 1
    pad = Pad(6)
86
    #: List of properties
87 1
    properties = ListOfProperties()
88
89 1
    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 1
        super().__init__()
100 1
        self.queue_id = queue_id
101 1
        self.port = port
102 1
        self.length = length
103 1
        self.properties = [] if properties is None else properties
104
105
106 1
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 1
    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 1
        super().__init__(pyof_class=PacketQueue,
121
                         items=items)
122
123
124 1
class QueuePropExperimenter(GenericStruct):
125
    """Experimenter queue property uses the following structure and fields."""
126
127 1
    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 1
    experimenter = UBInt32()
132
    #: 64-bit alignmet.
133 1
    pad = Pad(4)
134
    #: Experimenter defined data.
135 1
    data = BinaryData()
136
137 1
    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 1
        super().__init__()
146 1
        self.experimenter = experimenter
147 1
        self.data = data
148
149
150 1
class QueuePropMaxRate(GenericStruct):
151
    """Maximum-rate queue property uses the following structure and fields."""
152
153 1
    prop_header = QueuePropHeader(
154
        queue_property=QueueProperties.OFPQT_MAX_RATE, length=16)
155
    #: In 1/10 of a percent; >1000 -> disabled.
156 1
    rate = UBInt16()
157
    #: 64-bit alignmet.
158 1
    pad = Pad(6)
159
160 1
    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 1
        super().__init__()
167 1
        self.rate = rate
168
169
170 1
class QueuePropMinRate(GenericStruct):
171
    """Minimum-rate queue property uses the following structure and fields."""
172
173 1
    prop_header = QueuePropHeader(
174
        queue_property=QueueProperties.OFPQT_MIN_RATE, length=16)
175
    #: In 1/10 of a percent; >1000 -> disabled.
176 1
    rate = UBInt16()
177
    #: 64-bit alignmet.
178 1
    pad = Pad(6)
179
180 1
    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 1
        super().__init__()
187
        self.rate = rate
188