pyof.v0x01.common.queue.PacketQueue.__init__()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 13
Code Lines 5

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 13
loc 13
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nop 4
crap 2
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 FixedTypeList, Pad, UBInt16, UBInt32
9
10
# Third-party imports
11
12
13 1
__all__ = ('QueuePropHeader', 'PacketQueue', 'QueuePropMinRate',
14
           'QueueProperties', 'ListOfProperties', 'ListOfQueues')
15
16
# Enums
17
18
19 1
class QueueProperties(IntEnum):
20
    """Describe queue properties."""
21
22
    #: No property defined for queue (default)
23 1
    OFPQT_NONE = 0
24
    #: Minimum datarate guaranteed
25 1
    OFPQT_MIN_RATE = 1
26
27
28
# Classes
29
30
31 1
class ListOfProperties(FixedTypeList):
32
    """List of properties.
33
34
    Represented by instances of :class:`QueuePropHeader` and used on
35
    :class:`PacketQueue` objects.
36
    """
37
38 1
    def __init__(self, items=None):
39
        """Create a ListOfProperties with the optional parameters below.
40
41
        Args:
42
            items (:class:`list` of/or :class:`QueuePropHeader`):
43
                :class:`QueuePropHeader` instance or list of instances.
44
        """
45 1
        super().__init__(pyof_class=QueuePropHeader,
46
                         items=items)
47
48
49 1
class QueuePropHeader(GenericStruct):
50
    """Describe the header of each queue property."""
51
52 1
    queue_property = UBInt16(enum_ref=QueueProperties)
53 1
    length = UBInt16()
54
    #: 64-bit alignment
55 1
    pad = Pad(4)
56
57 1
    def __init__(self, queue_property=None, length=None):
58
        """Create a QueuePropHeader with the optional parameters below.
59
60
        Args:
61
            queue_property (~pyof.v0x01.common.queue.QueueProperties):
62
                The queue property.
63
            length (int): Length of property, including this header.
64
        """
65 1
        super().__init__()
66 1
        self.queue_property = queue_property
67 1
        self.length = length
68
69
70 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...
71
    """Describe a queue."""
72
73 1
    queue_id = UBInt32()
74 1
    length = UBInt16()
75
    #: 64-bit alignment.
76 1
    pad = Pad(2)
77 1
    properties = ListOfProperties()
78
79 1
    def __init__(self, queue_id=None, length=None, properties=None):
80
        """Create a PacketQueue with the optional parameters below.
81
82
        Args:
83
            queue_id (int): ID of the specific queue.
84
            length (int): Length in bytes of this queue desc.
85
            properties(~pyof.v0x01.common.queue.ListOfProperties):
86
                Queue's list of properties. Default is an empty list.
87
        """
88 1
        super().__init__()
89 1
        self.queue_id = queue_id
90 1
        self.length = length
91 1
        self.properties = [] if properties is None else properties
92
93
94 1
class QueuePropMinRate(GenericStruct):
95
    """Define the minimum-rate type queue."""
96
97 1
    prop_header = QueuePropHeader(
98
        queue_property=QueueProperties.OFPQT_MIN_RATE, length=16)
99 1
    rate = UBInt16()
100
    #: 64-bit alignmet.
101 1
    pad = Pad(6)
102
103 1
    def __init__(self, rate=None):
104
        """Create a QueuePropMinRate with the optional parameters below.
105
106
        Args:
107
            rate (int): In 1/10 of a percent (1000 -> 100%); >1000 -> disabled.
108
        """
109 1
        super().__init__()
110 1
        self.rate = rate
111
112
113 1
class ListOfQueues(FixedTypeList):
114
    """List of queues.
115
116
    Represented by instances of :class:`PacketQueue` and used on
117
    :class:`QueueGetConfigReply` objects.
118
    """
119
120 1
    def __init__(self, items=None):
121
        """Create a ListOfQueues with the optional parameters below.
122
123
        Args:
124
            items (:class:`list` of/or :class:`PacketQueue`):
125
                :class:`PacketQueue` instance or list of instances.
126
        """
127 1
        super().__init__(pyof_class=PacketQueue,
128
                         items=items)
129