Issues (31)

pyof/v0x01/common/queue.py (1 issue)

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 FixedTypeList, Pad, UBInt16, UBInt32
9
10
# Third-party imports
11
12
13
__all__ = ('QueuePropHeader', 'PacketQueue', 'QueuePropMinRate',
14
           'QueueProperties', 'ListOfProperties', 'ListOfQueues')
15
16
# Enums
17
18
19
class QueueProperties(IntEnum):
20
    """Describe queue properties."""
21
22
    #: No property defined for queue (default)
23
    OFPQT_NONE = 0
24
    #: Minimum datarate guaranteed
25
    OFPQT_MIN_RATE = 1
26
27
28
# Classes
29
30
31
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
    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
        super().__init__(pyof_class=QueuePropHeader,
46
                         items=items)
47
48
49
class QueuePropHeader(GenericStruct):
50
    """Describe the header of each queue property."""
51
52
    queue_property = UBInt16(enum_ref=QueueProperties)
53
    length = UBInt16()
54
    #: 64-bit alignment
55
    pad = Pad(4)
56
57
    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
        super().__init__()
66
        self.queue_property = queue_property
67
        self.length = length
68
69
70 View Code Duplication
class PacketQueue(GenericStruct):
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
71
    """Describe a queue."""
72
73
    queue_id = UBInt32()
74
    length = UBInt16()
75
    #: 64-bit alignment.
76
    pad = Pad(2)
77
    properties = ListOfProperties()
78
79
    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
        super().__init__()
89
        self.queue_id = queue_id
90
        self.length = length
91
        self.properties = [] if properties is None else properties
92
93
94
class QueuePropMinRate(GenericStruct):
95
    """Define the minimum-rate type queue."""
96
97
    prop_header = QueuePropHeader(
98
        queue_property=QueueProperties.OFPQT_MIN_RATE, length=16)
99
    rate = UBInt16()
100
    #: 64-bit alignmet.
101
    pad = Pad(6)
102
103
    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
        super().__init__()
110
        self.rate = rate
111
112
113
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
    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
        super().__init__(pyof_class=PacketQueue,
128
                         items=items)
129