|
1
|
|
|
"""Controller replying state from datapath.""" |
|
2
|
|
|
|
|
3
|
|
|
# System imports |
|
4
|
|
|
from enum import Enum |
|
5
|
|
|
|
|
6
|
|
|
# Local source tree imports |
|
7
|
|
|
from pyof.foundation.base import GenericBitMask, GenericMessage, GenericStruct |
|
8
|
|
|
from pyof.foundation.basic_types import (BinaryData, Char, FixedTypeList, Pad, |
|
9
|
|
|
UBInt8, UBInt16, UBInt32, UBInt64) |
|
10
|
|
|
from pyof.foundation.constants import DESC_STR_LEN, SERIAL_NUM_LEN |
|
11
|
|
|
from pyof.v0x04.common.flow_match import Match |
|
12
|
|
|
from pyof.v0x04.common.header import Header, Type |
|
13
|
|
|
from pyof.v0x04.common.port import Port |
|
14
|
|
|
from pyof.v0x04.controller2switch.common import (Bucket, BucketCounter, |
|
15
|
|
|
ExperimenterMultipartHeader, |
|
16
|
|
|
MultipartTypes, TableFeatures) |
|
17
|
|
|
from pyof.v0x04.controller2switch.meter_mod import (ListOfMeterBandHeader, |
|
18
|
|
|
MeterBandType, MeterFlags) |
|
19
|
|
|
|
|
20
|
|
|
# Third-party imports |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
__all__ = ('MultipartReply', 'MultipartReplyFlags', 'AggregateStatsReply', |
|
24
|
|
|
'Desc', 'FlowStats', 'PortStats', 'QueueStats', 'GroupDescStats', |
|
25
|
|
|
'GroupFeatures', 'GroupStats', 'MeterConfig', 'MeterFeatures', |
|
26
|
|
|
'BandStats', 'ListOfBandStats', 'MeterStats', 'GroupCapabilities', |
|
27
|
|
|
'TableStats') |
|
28
|
|
|
|
|
29
|
|
|
# Enum |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
class MultipartReplyFlags(Enum): |
|
33
|
|
|
"""Flags for MultipartReply.""" |
|
34
|
|
|
|
|
35
|
|
|
#: More replies to follow. |
|
36
|
|
|
OFPMPF_REPLY_MORE = 1 << 0 |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
class GroupCapabilities(GenericBitMask): |
|
40
|
|
|
"""Group configuration flags.""" |
|
41
|
|
|
|
|
42
|
|
|
#: Support weight for select groups. |
|
43
|
|
|
OFPGFC_SELECT_WEIGHT = 1 << 0 |
|
44
|
|
|
#: Support liveness for select groups. |
|
45
|
|
|
OFPGFC_SELECT_LIVENESS = 1 << 1 |
|
46
|
|
|
#: Support chaining groups. |
|
47
|
|
|
OFPGFC_CHAINING = 1 << 2 |
|
48
|
|
|
#: Chack chaining for loops and delete. |
|
49
|
|
|
OFPGFC_CHAINING_CHECKS = 1 << 3 |
|
50
|
|
|
|
|
51
|
|
|
# Classes |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
class MultipartReply(GenericMessage): |
|
55
|
|
|
"""Reply datapath state. |
|
56
|
|
|
|
|
57
|
|
|
While the system is running, the controller may reply state from the |
|
58
|
|
|
datapath using the OFPT_MULTIPART_REPLY message. |
|
59
|
|
|
""" |
|
60
|
|
|
|
|
61
|
|
|
#: Openflow :class:`~pyof.v0x04.common.header.Header` |
|
62
|
|
|
header = Header(message_type=Type.OFPT_MULTIPART_REPLY) |
|
63
|
|
|
#: One of the OFPMP_* constants. |
|
64
|
|
|
multipart_type = UBInt16(enum_ref=MultipartTypes) |
|
65
|
|
|
#: OFPMPF_REPLY_* flags. |
|
66
|
|
|
flags = UBInt16(enum_ref=MultipartReplyFlags) |
|
67
|
|
|
#: Padding |
|
68
|
|
|
pad = Pad(4) |
|
69
|
|
|
#: Body of the reply |
|
70
|
|
|
body = BinaryData() |
|
71
|
|
|
|
|
72
|
|
|
def __init__(self, xid=None, multipart_type=None, flags=None, body=b''): |
|
73
|
|
|
"""The constructor just assings parameters to object attributes. |
|
74
|
|
|
|
|
75
|
|
|
Args: |
|
76
|
|
|
xid (int): xid to the header. |
|
77
|
|
|
multipart_type (int): One of the OFPMP_* constants. |
|
78
|
|
|
flags (int): OFPMPF_REPLY_* flags. |
|
79
|
|
|
body (bytes): Body of the reply. |
|
80
|
|
|
""" |
|
81
|
|
|
super().__init__(xid) |
|
82
|
|
|
self.multipart_type = multipart_type |
|
83
|
|
|
self.flags = flags |
|
84
|
|
|
self.body = body |
|
85
|
|
|
|
|
86
|
|
View Code Duplication |
def pack(self, value=None): |
|
|
|
|
|
|
87
|
|
|
"""Pack a StatsReply using the object's attributes. |
|
88
|
|
|
|
|
89
|
|
|
This method will pack the attribute body and multipart_type before pack |
|
90
|
|
|
the StatsReply object, then will return this struct as a binary data. |
|
91
|
|
|
|
|
92
|
|
|
Returns: |
|
93
|
|
|
stats_reply_packed (bytes): Binary data with StatsReply packed. |
|
94
|
|
|
""" |
|
95
|
|
|
buff = self.body |
|
96
|
|
|
if not value: |
|
97
|
|
|
value = self.body |
|
98
|
|
|
|
|
99
|
|
|
if value: |
|
100
|
|
|
if isinstance(value, (list, FixedTypeList)): |
|
101
|
|
|
obj = self._get_body_instance() |
|
102
|
|
|
obj.extend(value) |
|
103
|
|
|
elif hasattr(value, 'pack'): |
|
104
|
|
|
obj = value |
|
105
|
|
|
|
|
106
|
|
|
self.body = obj.pack() |
|
107
|
|
|
|
|
108
|
|
|
multiparty_packed = super().pack() |
|
109
|
|
|
self.body = buff |
|
110
|
|
|
|
|
111
|
|
|
return multiparty_packed |
|
112
|
|
|
|
|
113
|
|
|
def unpack(self, buff, offset=0): |
|
114
|
|
|
"""Unpack a binary message into this object's attributes. |
|
115
|
|
|
|
|
116
|
|
|
Unpack the binary value *buff* and update this object attributes based |
|
117
|
|
|
on the results. It is an inplace method and it receives the binary data |
|
118
|
|
|
of the message **without the header**. |
|
119
|
|
|
|
|
120
|
|
|
This class' unpack method is like the :meth:`.GenericMessage.unpack` |
|
121
|
|
|
one, except for the ``body`` attribute which has its type determined |
|
122
|
|
|
by the ``multipart_type`` attribute. |
|
123
|
|
|
|
|
124
|
|
|
Args: |
|
125
|
|
|
buff (bytes): Binary data package to be unpacked, without the |
|
126
|
|
|
header. |
|
127
|
|
|
""" |
|
128
|
|
|
super().unpack(buff[offset:]) |
|
129
|
|
|
self._unpack_body() |
|
130
|
|
|
|
|
131
|
|
|
def _unpack_body(self): |
|
132
|
|
|
"""Unpack `body` replace it by the result.""" |
|
133
|
|
|
obj = self._get_body_instance() |
|
134
|
|
|
obj.unpack(self.body.value) |
|
135
|
|
|
self.body = obj |
|
136
|
|
|
|
|
137
|
|
|
def _get_body_instance(self): |
|
138
|
|
|
"""Method used to return the body instance.""" |
|
139
|
|
|
exp_header = ExperimenterMultipartHeader |
|
140
|
|
|
simple_body = {MultipartTypes.OFPMP_DESC: Desc, |
|
141
|
|
|
MultipartTypes.OFPMP_GROUP_FEATURES: GroupFeatures, |
|
142
|
|
|
MultipartTypes.OFPMP_METER_FEATURES: MeterFeatures, |
|
143
|
|
|
MultipartTypes.OFPMP_EXPERIMENTER: exp_header} |
|
144
|
|
|
|
|
145
|
|
|
array_of_bodies = {MultipartTypes.OFPMP_FLOW: FlowStats, |
|
146
|
|
|
MultipartTypes.OFPMP_AGGREGATE: AggregateStatsReply, |
|
147
|
|
|
MultipartTypes.OFPMP_TABLE: TableStats, |
|
148
|
|
|
MultipartTypes.OFPMP_PORT_STATS: PortStats, |
|
149
|
|
|
MultipartTypes.OFPMP_QUEUE: QueueStats, |
|
150
|
|
|
MultipartTypes.OFPMP_GROUP: GroupStats, |
|
151
|
|
|
MultipartTypes.OFPMP_GROUP_DESC: GroupDescStats, |
|
152
|
|
|
MultipartTypes.OFPMP_METER: MeterStats, |
|
153
|
|
|
MultipartTypes.OFPMP_METER_CONFIG: MeterConfig, |
|
154
|
|
|
MultipartTypes.OFPMP_TABLE_FEATURES: TableFeatures, |
|
155
|
|
|
MultipartTypes.OFPMP_PORT_DESC: Port} |
|
156
|
|
|
|
|
157
|
|
|
if isinstance(self.multipart_type, (int, UBInt16)): |
|
158
|
|
|
self.multipart_type = self.multipart_type.enum_ref( |
|
159
|
|
|
self.multipart_type.value) |
|
160
|
|
|
|
|
161
|
|
|
pyof_class = simple_body.get(self.multipart_type, None) |
|
162
|
|
|
if pyof_class: |
|
163
|
|
|
return pyof_class() |
|
164
|
|
|
|
|
165
|
|
|
array_of_class = array_of_bodies.get(self.multipart_type, None) |
|
166
|
|
|
if array_of_class: |
|
167
|
|
|
return FixedTypeList(pyof_class=pyof_class) |
|
168
|
|
|
|
|
169
|
|
|
return BinaryData(b'') |
|
170
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
# MultipartReply Body |
|
173
|
|
|
|
|
174
|
|
|
class AggregateStatsReply(GenericStruct): |
|
175
|
|
|
"""Body of reply to OFPMP_AGGREGATE request.""" |
|
176
|
|
|
|
|
177
|
|
|
#: Number of packets in flows. |
|
178
|
|
|
packet_count = UBInt64() |
|
179
|
|
|
#: Number of bytes in flows. |
|
180
|
|
|
byte_count = UBInt64() |
|
181
|
|
|
#: Number of flows. |
|
182
|
|
|
flow_count = UBInt32() |
|
183
|
|
|
#: Align to 64 bits |
|
184
|
|
|
pad = Pad(4) |
|
185
|
|
|
|
|
186
|
|
|
def __init__(self, packet_count=None, byte_count=None, flow_count=None): |
|
187
|
|
|
"""The constructor just assings parameters to object attributes. |
|
188
|
|
|
|
|
189
|
|
|
Args: |
|
190
|
|
|
packet_count (int): Number of packets in flows |
|
191
|
|
|
byte_count (int): Number of bytes in flows |
|
192
|
|
|
flow_count (int): Number of flows |
|
193
|
|
|
""" |
|
194
|
|
|
super().__init__() |
|
195
|
|
|
self.packet_count = packet_count |
|
196
|
|
|
self.byte_count = byte_count |
|
197
|
|
|
self.flow_count = flow_count |
|
198
|
|
|
|
|
199
|
|
|
|
|
200
|
|
View Code Duplication |
class Desc(GenericStruct): |
|
|
|
|
|
|
201
|
|
|
"""Information available from the OFPST_DESC stats request. |
|
202
|
|
|
|
|
203
|
|
|
Information about the switch manufacturer, hardware revision, software |
|
204
|
|
|
revision, serial number and a description field. |
|
205
|
|
|
""" |
|
206
|
|
|
|
|
207
|
|
|
#: Manufacturer description |
|
208
|
|
|
mfr_desc = Char(length=DESC_STR_LEN) |
|
209
|
|
|
#: Hardware description |
|
210
|
|
|
hw_desc = Char(length=DESC_STR_LEN) |
|
211
|
|
|
#: Software description |
|
212
|
|
|
sw_desc = Char(length=DESC_STR_LEN) |
|
213
|
|
|
#: Serial number |
|
214
|
|
|
serial_num = Char(length=SERIAL_NUM_LEN) |
|
215
|
|
|
#: Datapath description |
|
216
|
|
|
dp_desc = Char(length=DESC_STR_LEN) |
|
217
|
|
|
|
|
218
|
|
|
def __init__(self, mfr_desc=None, hw_desc=None, sw_desc=None, |
|
219
|
|
|
serial_num=None, dp_desc=None): |
|
220
|
|
|
"""The constructor just assigns parameters to object attributes. |
|
221
|
|
|
|
|
222
|
|
|
Args: |
|
223
|
|
|
mfr_desc (str): Manufacturer description |
|
224
|
|
|
hw_desc (str): Hardware description |
|
225
|
|
|
sw_desc (str): Software description |
|
226
|
|
|
serial_num (str): Serial number |
|
227
|
|
|
dp_desc (str): Datapath description |
|
228
|
|
|
""" |
|
229
|
|
|
super().__init__() |
|
230
|
|
|
self.mfr_desc = mfr_desc |
|
231
|
|
|
self.hw_desc = hw_desc |
|
232
|
|
|
self.sw_desc = sw_desc |
|
233
|
|
|
self.serial_num = serial_num |
|
234
|
|
|
self.dp_desc = dp_desc |
|
235
|
|
|
|
|
236
|
|
|
|
|
237
|
|
|
class FlowStats(GenericStruct): |
|
238
|
|
|
"""Body of reply to OFPST_FLOW request.""" |
|
239
|
|
|
|
|
240
|
|
|
length = UBInt16() |
|
241
|
|
|
table_id = UBInt8() |
|
242
|
|
|
#: Align to 32 bits. |
|
243
|
|
|
pad = Pad(1) |
|
244
|
|
|
duration_sec = UBInt32() |
|
245
|
|
|
duration_nsec = UBInt32() |
|
246
|
|
|
priority = UBInt16() |
|
247
|
|
|
idle_timeout = UBInt16() |
|
248
|
|
|
hard_timeout = UBInt16() |
|
249
|
|
|
flags = UBInt16() |
|
250
|
|
|
#: Align to 64-bits |
|
251
|
|
|
pad2 = Pad(4) |
|
252
|
|
|
cookie = UBInt64() |
|
253
|
|
|
packet_count = UBInt64() |
|
254
|
|
|
byte_count = UBInt64() |
|
255
|
|
|
match = Match() |
|
256
|
|
|
|
|
257
|
|
|
def __init__(self, length=None, table_id=None, duration_sec=None, |
|
258
|
|
|
duration_nsec=None, priority=None, idle_timeout=None, |
|
259
|
|
|
hard_timeout=None, flags=None, cookie=None, packet_count=None, |
|
260
|
|
|
byte_count=None, match=None): |
|
261
|
|
|
"""The constructor just assings parameters to object attributes. |
|
262
|
|
|
|
|
263
|
|
|
Args: |
|
264
|
|
|
length (int): Length of this entry. |
|
265
|
|
|
table_id (int): ID of table flow came from. |
|
266
|
|
|
duration_sec (int): Time flow has been alive in seconds. |
|
267
|
|
|
duration_nsec (int): Time flow has been alive in nanoseconds in |
|
268
|
|
|
addition to duration_sec. |
|
269
|
|
|
priority (int): Priority of the entry. Only meaningful when this |
|
270
|
|
|
is not an exact-match entry. |
|
271
|
|
|
idle_timeout (int): Number of seconds idle before expiration. |
|
272
|
|
|
hard_timeout (int): Number of seconds before expiration. |
|
273
|
|
|
cookie (int): Opaque controller-issued identifier. |
|
274
|
|
|
packet_count (int): Number of packets in flow. |
|
275
|
|
|
byte_count (int): Number of bytes in flow. |
|
276
|
|
|
match (~pyof.v0x04.common.flow_match.Match): Description of fields. |
|
277
|
|
|
""" |
|
278
|
|
|
super().__init__() |
|
279
|
|
|
self.length = length |
|
280
|
|
|
self.table_id = table_id |
|
281
|
|
|
self.duration_sec = duration_sec |
|
282
|
|
|
self.duration_nsec = duration_nsec |
|
283
|
|
|
self.priority = priority |
|
284
|
|
|
self.idle_timeout = idle_timeout |
|
285
|
|
|
self.hard_timeout = hard_timeout |
|
286
|
|
|
self.flags = flags |
|
287
|
|
|
self.cookie = cookie |
|
288
|
|
|
self.packet_count = packet_count |
|
289
|
|
|
self.byte_count = byte_count |
|
290
|
|
|
|
|
291
|
|
|
|
|
292
|
|
|
class PortStats(GenericStruct): |
|
293
|
|
|
"""Body of reply to OFPST_PORT request. |
|
294
|
|
|
|
|
295
|
|
|
If a counter is unsupported, set the field to all ones. |
|
296
|
|
|
""" |
|
297
|
|
|
|
|
298
|
|
|
port_no = UBInt32() |
|
299
|
|
|
#: Align to 64-bits. |
|
300
|
|
|
pad = Pad(4) |
|
301
|
|
|
rx_packets = UBInt64() |
|
302
|
|
|
tx_packets = UBInt64() |
|
303
|
|
|
rx_bytes = UBInt64() |
|
304
|
|
|
tx_bytes = UBInt64() |
|
305
|
|
|
rx_dropped = UBInt64() |
|
306
|
|
|
tx_dropped = UBInt64() |
|
307
|
|
|
rx_errors = UBInt64() |
|
308
|
|
|
tx_errors = UBInt64() |
|
309
|
|
|
rx_frame_err = UBInt64() |
|
310
|
|
|
rx_over_err = UBInt64() |
|
311
|
|
|
rx_crc_err = UBInt64() |
|
312
|
|
|
collisions = UBInt64() |
|
313
|
|
|
duration_sec = UBInt32() |
|
314
|
|
|
duration_nsec = UBInt32() |
|
315
|
|
|
|
|
316
|
|
|
# Can't avoid "too many local variables" (R0914) in this struct. |
|
317
|
|
|
# pylint: disable=R0914 |
|
318
|
|
View Code Duplication |
def __init__(self, port_no=None, rx_packets=None, |
|
|
|
|
|
|
319
|
|
|
tx_packets=None, rx_bytes=None, tx_bytes=None, |
|
320
|
|
|
rx_dropped=None, tx_dropped=None, rx_errors=None, |
|
321
|
|
|
tx_errors=None, rx_frame_err=None, rx_over_err=None, |
|
322
|
|
|
rx_crc_err=None, collisions=None, duration_sec=None, |
|
323
|
|
|
duration_nsec=None): |
|
324
|
|
|
"""The constructor assigns parameters to object attributes. |
|
325
|
|
|
|
|
326
|
|
|
Args: |
|
327
|
|
|
port_no (:class:`int`, :class:`~pyof.v0x04.common.port.Port`): |
|
328
|
|
|
Port number. |
|
329
|
|
|
rx_packets (int): Number of received packets. |
|
330
|
|
|
tx_packets (int): Number of transmitted packets. |
|
331
|
|
|
rx_bytes (int): Number of received bytes. |
|
332
|
|
|
tx_bytes (int): Number of transmitted bytes. |
|
333
|
|
|
rx_dropped (int): Number of packets dropped by RX. |
|
334
|
|
|
tx_dropped (int): Number of packets dropped by TX. |
|
335
|
|
|
rx_errors (int): Number of receive errors. This is a super-set of |
|
336
|
|
|
more specific receive errors and should be greater than or |
|
337
|
|
|
equal to the sum of all rx_*_err values. |
|
338
|
|
|
tx_errors (int): Number of transmit errors. This is a super-set of |
|
339
|
|
|
more specific transmit errors and should be greater than or |
|
340
|
|
|
equal to the sum of all tx_*_err values (none currently |
|
341
|
|
|
defined). |
|
342
|
|
|
rx_frame_err (int): Number of frame alignment errors. |
|
343
|
|
|
rx_over_err (int): Number of packets with RX overrun. |
|
344
|
|
|
rx_crc_err (int): Number of CRC errors. |
|
345
|
|
|
collisions (int): Number of collisions. |
|
346
|
|
|
duration_sec (int): Time port has been alive in seconds |
|
347
|
|
|
duration_nsec (int): Time port has been alive in nanoseconds beyond |
|
348
|
|
|
duration_sec |
|
349
|
|
|
""" |
|
350
|
|
|
super().__init__() |
|
351
|
|
|
self.port_no = port_no |
|
352
|
|
|
self.rx_packets = rx_packets |
|
353
|
|
|
self.tx_packets = tx_packets |
|
354
|
|
|
self.rx_bytes = rx_bytes |
|
355
|
|
|
self.tx_bytes = tx_bytes |
|
356
|
|
|
self.rx_dropped = rx_dropped |
|
357
|
|
|
self.tx_dropped = tx_dropped |
|
358
|
|
|
self.rx_errors = rx_errors |
|
359
|
|
|
self.tx_errors = tx_errors |
|
360
|
|
|
self.rx_frame_err = rx_frame_err |
|
361
|
|
|
self.rx_over_err = rx_over_err |
|
362
|
|
|
self.rx_crc_err = rx_crc_err |
|
363
|
|
|
self.collisions = collisions |
|
364
|
|
|
self.duration_sec = duration_sec |
|
365
|
|
|
self.duration_nsec = duration_nsec |
|
366
|
|
|
|
|
367
|
|
|
|
|
368
|
|
|
class QueueStats(GenericStruct): |
|
369
|
|
|
"""Implements the reply body of a port_no.""" |
|
370
|
|
|
|
|
371
|
|
|
port_no = UBInt32() |
|
372
|
|
|
queue_id = UBInt32() |
|
373
|
|
|
tx_bytes = UBInt64() |
|
374
|
|
|
tx_packets = UBInt64() |
|
375
|
|
|
tx_errors = UBInt64() |
|
376
|
|
|
duration_sec = UBInt32() |
|
377
|
|
|
duration_nsec = UBInt32() |
|
378
|
|
|
|
|
379
|
|
|
def __init__(self, port_no=None, queue_id=None, tx_bytes=None, |
|
380
|
|
|
tx_packets=None, tx_errors=None, duration_sec=None, |
|
381
|
|
|
duration_nsec=None): |
|
382
|
|
|
"""The constructor just assings parameters to object attributes. |
|
383
|
|
|
|
|
384
|
|
|
Args: |
|
385
|
|
|
port_no (:class:`int`, :class:`~pyof.v0x04.common.port.Port`): |
|
386
|
|
|
Port Number. |
|
387
|
|
|
queue_id (int): Queue ID. |
|
388
|
|
|
tx_bytes (int): Number of transmitted bytes. |
|
389
|
|
|
tx_packets (int): Number of transmitted packets. |
|
390
|
|
|
tx_errors (int): Number of packets dropped due to overrun. |
|
391
|
|
|
duration_sec (int): Time queue has been alive in seconds. |
|
392
|
|
|
duration_nsec (int): Time queue has been alive in nanoseconds |
|
393
|
|
|
beyond duration_sec. |
|
394
|
|
|
""" |
|
395
|
|
|
super().__init__() |
|
396
|
|
|
self.port_no = port_no |
|
397
|
|
|
self.queue_id = queue_id |
|
398
|
|
|
self.tx_bytes = tx_bytes |
|
399
|
|
|
self.tx_packets = tx_packets |
|
400
|
|
|
self.tx_errors = tx_errors |
|
401
|
|
|
self.duration_sec = duration_sec |
|
402
|
|
|
self.duration_nsec = duration_nsec |
|
403
|
|
View Code Duplication |
|
|
|
|
|
|
|
404
|
|
|
|
|
405
|
|
|
class GroupDescStats(GenericStruct): |
|
406
|
|
|
"""Body of reply to OFPMP_GROUP_DESC request.""" |
|
407
|
|
|
|
|
408
|
|
|
length = UBInt16() |
|
409
|
|
|
group_type = UBInt8() |
|
410
|
|
|
#: Pad to 64 bits. |
|
411
|
|
|
pad = Pad(1) |
|
412
|
|
|
group_id = UBInt32() |
|
413
|
|
|
buckets = FixedTypeList(Bucket) |
|
414
|
|
|
|
|
415
|
|
|
def __init__(self, length=None, group_type=None, group_id=None, |
|
416
|
|
|
buckets=None): |
|
417
|
|
|
"""The constructor just assigns parameters to object attributes. |
|
418
|
|
|
|
|
419
|
|
|
Args: |
|
420
|
|
|
length: Length of this entry. |
|
421
|
|
|
group_type: One of OFPGT_*. |
|
422
|
|
|
group_id: Group identifier. |
|
423
|
|
|
buckets: List of buckets in group. |
|
424
|
|
|
""" |
|
425
|
|
|
super().__init__() |
|
426
|
|
|
self.length = length |
|
427
|
|
|
self.group_type = group_type |
|
428
|
|
|
self.group_id = group_id |
|
429
|
|
|
self.buckets = buckets |
|
430
|
|
|
|
|
431
|
|
|
|
|
432
|
|
|
class GroupFeatures(GenericStruct): |
|
433
|
|
|
"""Body of reply to OFPMP_GROUP_FEATURES request.Group features.""" |
|
434
|
|
|
|
|
435
|
|
|
types = UBInt32() |
|
436
|
|
|
capabilities = UBInt32(enum_ref=GroupCapabilities) |
|
437
|
|
|
max_groups1 = UBInt32() |
|
438
|
|
|
max_groups2 = UBInt32() |
|
439
|
|
|
max_groups3 = UBInt32() |
|
440
|
|
|
max_groups4 = UBInt32() |
|
441
|
|
|
actions1 = UBInt32() |
|
442
|
|
|
actions2 = UBInt32() |
|
443
|
|
|
actions3 = UBInt32() |
|
444
|
|
|
actions4 = UBInt32() |
|
445
|
|
|
|
|
446
|
|
|
def __init__(self, types=None, capabilities=None, max_groups1=None, |
|
447
|
|
|
max_groups2=None, max_groups3=None, max_groups4=None, |
|
448
|
|
|
actions1=None, actions2=None, actions3=None, actions4=None): |
|
449
|
|
|
"""The constructor just assigns parameters to object attributes. |
|
450
|
|
|
|
|
451
|
|
|
Args: |
|
452
|
|
|
types: Bitmap of OFPGT_* values supported. |
|
453
|
|
|
capabilities: Bitmap of OFPGFC_* capability supported. |
|
454
|
|
|
max_groups: 4-position array; Maximum number of groups for each |
|
455
|
|
|
type. |
|
456
|
|
|
actions: 4-position array; Bitmaps of OFPAT_* that are supported. |
|
457
|
|
|
""" |
|
458
|
|
|
super().__init__() |
|
459
|
|
|
self.types = types |
|
460
|
|
|
self.capabilities = capabilities |
|
461
|
|
|
self.max_groups1 = max_groups1 |
|
462
|
|
|
self.max_groups2 = max_groups2 |
|
463
|
|
|
self.max_groups3 = max_groups3 |
|
464
|
|
|
self.max_groups4 = max_groups4 |
|
465
|
|
|
self.actions1 = actions1 |
|
466
|
|
|
self.actions2 = actions2 |
|
467
|
|
|
self.actions3 = actions3 |
|
468
|
|
|
self.actions4 = actions4 |
|
469
|
|
|
|
|
470
|
|
|
|
|
471
|
|
|
class GroupStats(GenericStruct): |
|
472
|
|
|
"""Body of reply to OFPMP_GROUP request.""" |
|
473
|
|
|
|
|
474
|
|
|
length = UBInt16() |
|
475
|
|
|
#: Align to 64 bits. |
|
476
|
|
|
pad = Pad(2) |
|
477
|
|
|
group_id = UBInt32() |
|
478
|
|
|
ref_count = UBInt32() |
|
479
|
|
|
#: Align to 64 bits. |
|
480
|
|
|
pad2 = Pad(4) |
|
481
|
|
|
packet_count = UBInt64() |
|
482
|
|
|
byte_count = UBInt64() |
|
483
|
|
|
duration_sec = UBInt32() |
|
484
|
|
|
duration_nsec = UBInt32() |
|
485
|
|
|
bucket_stats = FixedTypeList(BucketCounter) |
|
486
|
|
|
|
|
487
|
|
|
def __init__(self, length=None, group_id=None, ref_count=None, |
|
488
|
|
|
packet_count=None, byte_count=None, duration_sec=None, |
|
489
|
|
|
duration_nsec=None, bucket_stats=None): |
|
490
|
|
|
"""The constructor just assings parameters to object attributes. |
|
491
|
|
|
|
|
492
|
|
|
Args: |
|
493
|
|
|
length: Length of this entry |
|
494
|
|
|
group_id: Group identifier |
|
495
|
|
|
ref_count: Number of flows or groups that directly forward |
|
496
|
|
|
to this group. |
|
497
|
|
|
packet_count: Number of packets processed by group |
|
498
|
|
|
byte_count: Number of bytes processed by group |
|
499
|
|
|
duration_sec: Time group has been alive in seconds |
|
500
|
|
|
duration_nsec: Time group has been alive in nanoseconds |
|
501
|
|
|
bucket_stats: List of stats of group buckets |
|
502
|
|
|
""" |
|
503
|
|
|
super().__init__() |
|
504
|
|
|
self.length = length |
|
505
|
|
|
self.group_id = group_id |
|
506
|
|
|
self.ref_count = ref_count |
|
507
|
|
|
self.packet_count = packet_count |
|
508
|
|
|
self.byte_count = byte_count |
|
509
|
|
|
self.duration_sec = duration_sec |
|
510
|
|
|
self.duration_nsec = duration_nsec |
|
511
|
|
|
self.bucket_stats = bucket_stats |
|
512
|
|
|
|
|
513
|
|
|
|
|
514
|
|
|
class MeterConfig(GenericStruct): |
|
515
|
|
|
"""MeterConfig is a class to represent ofp_meter_config structure. |
|
516
|
|
|
|
|
517
|
|
|
Body of reply to OFPMP_METER_CONFIG request. |
|
518
|
|
|
""" |
|
519
|
|
|
|
|
520
|
|
|
# Length of this entry. |
|
521
|
|
|
length = UBInt16() |
|
522
|
|
|
# All OFPMC_* that apply. |
|
523
|
|
|
flags = UBInt16(enum_ref=MeterFlags) |
|
524
|
|
|
# Meter instance or OFPM_ALL . |
|
525
|
|
|
meter_id = UBInt32() |
|
526
|
|
|
# The bands length is inferred from the length field. |
|
527
|
|
|
bands = ListOfMeterBandHeader() |
|
528
|
|
|
|
|
529
|
|
|
def __init__(self, flags=MeterFlags.OFPMF_STATS, meter_id=None, |
|
530
|
|
|
bands=None): |
|
531
|
|
|
"""The Constructor of MeterConfig receives the parameters below. |
|
532
|
|
|
|
|
533
|
|
|
Args: |
|
534
|
|
|
flags(MeterFlags): Meter configuration flags.The default value is |
|
535
|
|
|
MeterFlags.OFPMF_STATS |
|
536
|
|
|
meter_id(Meter): Meter Indentify.The value Meter.OFPM_ALL is used |
|
537
|
|
|
to refer to all Meters on the switch. |
|
538
|
|
|
bands(list): List of MeterBandHeader instances. |
|
539
|
|
|
""" |
|
540
|
|
|
super().__init__() |
|
541
|
|
|
self.flags = flags |
|
542
|
|
|
self.meter_id = meter_id |
|
543
|
|
|
self.bands = bands if bands else [] |
|
544
|
|
|
|
|
545
|
|
|
|
|
546
|
|
|
class MeterFeatures(GenericStruct): |
|
547
|
|
|
"""Body of reply to OFPMP_METER_FEATURES request. Meter features.""" |
|
548
|
|
|
|
|
549
|
|
|
max_meter = UBInt32() |
|
550
|
|
|
band_types = UBInt32(enum_ref=MeterBandType) |
|
551
|
|
|
capabilities = UBInt32(enum_ref=MeterFlags) |
|
552
|
|
|
max_bands = UBInt8() |
|
553
|
|
|
max_color = UBInt8() |
|
554
|
|
|
pad = Pad(2) |
|
555
|
|
|
|
|
556
|
|
|
def __init__(self, max_meter=None, band_types=None, capabilities=None, |
|
557
|
|
|
max_bands=None, max_color=None): |
|
558
|
|
|
"""The Constructor of MeterFeatures receives the parameters below. |
|
559
|
|
|
|
|
560
|
|
|
Args: |
|
561
|
|
|
max_meter(int): Maximum number of meters. |
|
562
|
|
|
band_types(Meter): Bitmaps of OFPMBT_* values supported. |
|
563
|
|
|
capabilities(MeterFlags): Bitmaps of "ofp_meter_flags". |
|
564
|
|
|
max_bands(int): Maximum bands per meters |
|
565
|
|
|
max_color(int): Maximum color value |
|
566
|
|
|
""" |
|
567
|
|
|
super().__init__() |
|
568
|
|
|
self.max_meter = max_meter |
|
569
|
|
|
self.band_types = band_types |
|
570
|
|
|
self.capabilities = capabilities |
|
571
|
|
|
self.max_bands = max_bands |
|
572
|
|
|
self.max_color = max_color |
|
573
|
|
|
|
|
574
|
|
|
|
|
575
|
|
|
class BandStats(GenericStruct): |
|
576
|
|
|
"""Band Statistics. |
|
577
|
|
|
|
|
578
|
|
|
Statistics for each meter band. |
|
579
|
|
|
""" |
|
580
|
|
|
|
|
581
|
|
|
packet_band_count = UBInt64() |
|
582
|
|
|
byte_band_count = UBInt64() |
|
583
|
|
|
|
|
584
|
|
|
def __init__(self, packet_band_count=None, byte_band_count=None): |
|
585
|
|
|
"""The constructor just assings parameters to object attributes. |
|
586
|
|
|
|
|
587
|
|
|
Args: |
|
588
|
|
|
packet_band_count(int): Number of packets in band. |
|
589
|
|
|
byte_band_count(int): Number of bytes in band. |
|
590
|
|
|
""" |
|
591
|
|
|
super().__init__() |
|
592
|
|
|
self.packet_band_count = packet_band_count |
|
593
|
|
|
self.byte_band_count = byte_band_count |
|
594
|
|
|
|
|
595
|
|
|
|
|
596
|
|
|
class ListOfBandStats(FixedTypeList): |
|
597
|
|
|
"""List of BandStats. |
|
598
|
|
|
|
|
599
|
|
|
Represented by instances of BandStats. |
|
600
|
|
|
""" |
|
601
|
|
|
|
|
602
|
|
|
def __init__(self, items=None): |
|
603
|
|
|
"""The constructor just assings parameters to object attributes. |
|
604
|
|
|
|
|
605
|
|
|
Args: |
|
606
|
|
|
items (BandStats): Instance or a list of instances. |
|
607
|
|
|
""" |
|
608
|
|
|
super().__init__(pyof_class=BandStats, items=items) |
|
609
|
|
View Code Duplication |
|
|
|
|
|
|
|
610
|
|
|
|
|
611
|
|
|
class MeterStats(GenericStruct): |
|
612
|
|
|
"""Meter Statistics. |
|
613
|
|
|
|
|
614
|
|
|
Body of reply to OFPMP_METER request. |
|
615
|
|
|
""" |
|
616
|
|
|
|
|
617
|
|
|
meter_id = UBInt32() |
|
618
|
|
|
length = UBInt16() |
|
619
|
|
|
pad = Pad(6) |
|
620
|
|
|
flow_count = UBInt32() |
|
621
|
|
|
packet_in_count = UBInt64() |
|
622
|
|
|
byte_in_count = UBInt64() |
|
623
|
|
|
duration_sec = UBInt32() |
|
624
|
|
|
duration_nsec = UBInt32() |
|
625
|
|
|
band_stats = ListOfBandStats() |
|
626
|
|
|
|
|
627
|
|
|
def __init__(self, meter_id=None, flow_count=None, |
|
628
|
|
|
packet_in_count=None, byte_in_count=None, duration_sec=None, |
|
629
|
|
|
duration_nsec=None, band_stats=None): |
|
630
|
|
|
"""The constructor just assings parameters to object attributes. |
|
631
|
|
|
|
|
632
|
|
|
Args: |
|
633
|
|
|
meter_id(Meter): Meter instance. |
|
634
|
|
|
flow_count(int): Number of flows bound to meter. |
|
635
|
|
|
packet_in_count(int): Number of packets in input. |
|
636
|
|
|
byte_in_count(int): Number of bytes in input. |
|
637
|
|
|
duration_sec(int): Time meter has been alive in seconds. |
|
638
|
|
|
duration_nsec(int): Time meter has been alive in |
|
639
|
|
|
nanoseconds beyond duration_sec. |
|
640
|
|
|
band_stats(list): Instances of BandStats |
|
641
|
|
|
""" |
|
642
|
|
|
super().__init__() |
|
643
|
|
|
self.meter_id = meter_id |
|
644
|
|
|
self.flow_count = flow_count |
|
645
|
|
|
self.packet_in_count = packet_in_count |
|
646
|
|
|
self.byte_in_count = byte_in_count |
|
647
|
|
|
self.duration_sec = duration_sec |
|
648
|
|
|
self.duration_nsec = duration_nsec |
|
649
|
|
|
self.band_stats = band_stats if band_stats else [] |
|
650
|
|
|
self.update_length() |
|
651
|
|
|
|
|
652
|
|
|
def update_length(self): |
|
653
|
|
|
"""Update length attribute with current struct length.""" |
|
654
|
|
|
self.length = self.get_size() |
|
655
|
|
|
|
|
656
|
|
|
def pack(self, value=None): |
|
657
|
|
|
"""Pack method used to update the length of instance and packing. |
|
658
|
|
|
|
|
659
|
|
|
Args: |
|
660
|
|
|
value: Structure to be packed. |
|
661
|
|
|
""" |
|
662
|
|
|
self.update_length() |
|
663
|
|
|
return super().pack(value) |
|
664
|
|
|
|
|
665
|
|
|
def unpack(self, buff=None, offset=0): |
|
666
|
|
|
"""Unpack *buff* into this object. |
|
667
|
|
|
|
|
668
|
|
|
This method will convert a binary data into a readable value according |
|
669
|
|
|
to the attribute format. |
|
670
|
|
|
Args: |
|
671
|
|
|
buff (bytes): Binary buffer. |
|
672
|
|
|
offset (int): Where to begin unpacking. |
|
673
|
|
|
Raises: |
|
674
|
|
|
:exc:`~.exceptions.UnpackException`: If unpack fails. |
|
675
|
|
|
""" |
|
676
|
|
|
length = UBInt16() |
|
677
|
|
|
length.unpack(buff, offset) |
|
678
|
|
|
|
|
679
|
|
|
length.unpack(buff, offset=offset+MeterStats.meter_id.get_size()) |
|
680
|
|
|
super().unpack(buff[:offset+length.value], offset=offset) |
|
681
|
|
|
|
|
682
|
|
|
|
|
683
|
|
|
class TableStats(GenericStruct): |
|
684
|
|
|
"""Body of reply to OFPST_TABLE request.""" |
|
685
|
|
|
|
|
686
|
|
|
table_id = UBInt8() |
|
687
|
|
|
#: Align to 32-bits. |
|
688
|
|
|
pad = Pad(3) |
|
689
|
|
|
active_count = UBInt32() |
|
690
|
|
|
lookup_count = UBInt64() |
|
691
|
|
|
matched_count = UBInt64() |
|
692
|
|
|
|
|
693
|
|
|
def __init__(self, table_id=None, name=None, max_entries=None, |
|
694
|
|
|
active_count=None, lookup_count=None, |
|
695
|
|
|
matched_count=None): |
|
696
|
|
|
"""The constructor just assings parameters to object attributes. |
|
697
|
|
|
|
|
698
|
|
|
Args: |
|
699
|
|
|
table_id (int): Identifier of table. Lower numbered tables are |
|
700
|
|
|
consulted first. |
|
701
|
|
|
active_count (int): Number of active entries. |
|
702
|
|
|
lookup_count (int): Number of packets looked up in table. |
|
703
|
|
|
matched_count (int): Number of packets that hit table. |
|
704
|
|
|
""" |
|
705
|
|
|
super().__init__() |
|
706
|
|
|
self.table_id = table_id |
|
707
|
|
|
self.active_count = active_count |
|
708
|
|
|
self.lookup_count = lookup_count |
|
709
|
|
|
self.matched_count = matched_count |
|
710
|
|
|
|