Code Duplication    Length = 69-71 lines in 2 locations

pyof/v0x01/controller2switch/common.py 1 location

@@ 176-246 (lines=71) @@
173
        self.dp_desc = dp_desc
174
175
176
class FlowStats(GenericStruct):
177
    """Body of reply to OFPST_FLOW request."""
178
179
    length = UBInt16()
180
    table_id = UBInt8()
181
    #: Align to 32 bits.
182
    pad = Pad(1)
183
    match = Match()
184
    duration_sec = UBInt32()
185
    duration_nsec = UBInt32()
186
    priority = UBInt16()
187
    idle_timeout = UBInt16()
188
    hard_timeout = UBInt16()
189
    #: Align to 64-bits
190
    pad2 = Pad(6)
191
    cookie = UBInt64()
192
    packet_count = UBInt64()
193
    byte_count = UBInt64()
194
    actions = ListOfActions()
195
196
    def __init__(self, length=None, table_id=None, match=None,
197
                 duration_sec=None, duration_nsec=None, priority=None,
198
                 idle_timeout=None, hard_timeout=None, cookie=None,
199
                 packet_count=None, byte_count=None, actions=None):
200
        """Create a FlowStats with the optional parameters below.
201
202
        Args:
203
            length (int): Length of this entry.
204
            table_id (int): ID of table flow came from.
205
            match (~pyof.v0x01.common.flow_match.Match): Description of fields.
206
            duration_sec (int): Time flow has been alive in seconds.
207
            duration_nsec (int): Time flow has been alive in nanoseconds in
208
                addition to duration_sec.
209
            priority (int): Priority of the entry. Only meaningful when this
210
                is not an exact-match entry.
211
            idle_timeout (int): Number of seconds idle before expiration.
212
            hard_timeout (int): Number of seconds before expiration.
213
            cookie (int): Opaque controller-issued identifier.
214
            packet_count (int): Number of packets in flow.
215
            byte_count (int): Number of bytes in flow.
216
            actions (:class:`~pyof.v0x01.common.actions.ListOfActions`):
217
                List of Actions.
218
        """
219
        super().__init__()
220
        self.length = length
221
        self.table_id = table_id
222
        self.match = match
223
        self.duration_sec = duration_sec
224
        self.duration_nsec = duration_nsec
225
        self.priority = priority
226
        self.idle_timeout = idle_timeout
227
        self.hard_timeout = hard_timeout
228
        self.cookie = cookie
229
        self.packet_count = packet_count
230
        self.byte_count = byte_count
231
        self.actions = [] if actions is None else actions
232
233
    def unpack(self, buff, offset=0):
234
        """Unpack *buff* into this object.
235
236
        Do nothing, since the _length is already defined and it is just a Pad.
237
        Keep buff and offset just for compability with other unpack methods.
238
239
        Args:
240
            buff (bytes): Buffer where data is located.
241
            offset (int): Where data stream begins.
242
        """
243
        self.length = UBInt16()
244
        self.length.unpack(buff, offset)
245
        max_length = offset + self.length.value
246
        super().unpack(buff[:max_length], offset)
247
248
249
class FlowStatsRequest(GenericStruct):

pyof/v0x04/controller2switch/multipart_reply.py 1 location

@@ 239-307 (lines=69) @@
236
        self.dp_desc = dp_desc
237
238
239
class FlowStats(GenericStruct):
240
    """Body of reply to OFPST_FLOW request."""
241
242
    length = UBInt16()
243
    table_id = UBInt8()
244
    #: Align to 32 bits.
245
    pad = Pad(1)
246
    duration_sec = UBInt32()
247
    duration_nsec = UBInt32()
248
    priority = UBInt16()
249
    idle_timeout = UBInt16()
250
    hard_timeout = UBInt16()
251
    flags = UBInt16()
252
    #: Align to 64-bits
253
    pad2 = Pad(4)
254
    cookie = UBInt64()
255
    packet_count = UBInt64()
256
    byte_count = UBInt64()
257
    match = Match()
258
    instructions = ListOfInstruction()
259
260
    def __init__(self, length=None, table_id=None, duration_sec=None,
261
                 duration_nsec=None, priority=None, idle_timeout=None,
262
                 hard_timeout=None, flags=None, cookie=None, packet_count=None,
263
                 byte_count=None, match=None, instructions=None):
264
        """Create a FlowStats with the optional parameters below.
265
266
        Args:
267
            length (int): Length of this entry.
268
            table_id (int): ID of table flow came from.
269
            duration_sec (int): Time flow has been alive in seconds.
270
            duration_nsec (int): Time flow has been alive in nanoseconds in
271
                addition to duration_sec.
272
            priority (int): Priority of the entry. Only meaningful when this
273
                is not an exact-match entry.
274
            idle_timeout (int): Number of seconds idle before expiration.
275
            hard_timeout (int): Number of seconds before expiration.
276
            cookie (int): Opaque controller-issued identifier.
277
            packet_count (int): Number of packets in flow.
278
            byte_count (int): Number of bytes in flow.
279
            match (~pyof.v0x04.common.flow_match.Match): Description of fields.
280
        """
281
        super().__init__()
282
        self.length = length
283
        self.table_id = table_id
284
        self.duration_sec = duration_sec
285
        self.duration_nsec = duration_nsec
286
        self.priority = priority
287
        self.idle_timeout = idle_timeout
288
        self.hard_timeout = hard_timeout
289
        self.flags = flags
290
        self.cookie = cookie
291
        self.packet_count = packet_count
292
        self.byte_count = byte_count
293
        self.match = match
294
        self.instructions = instructions or []
295
296
    def unpack(self, buff, offset=0):
297
        """Unpack a binary message into this object's attributes.
298
299
        Pass the correct length for list unpacking.
300
301
        Args:
302
            buff (bytes): Binary data package to be unpacked.
303
            offset (int): Where to begin unpacking.
304
        """
305
        unpack_length = UBInt16()
306
        unpack_length.unpack(buff, offset)
307
        super().unpack(buff[:offset+unpack_length], offset)
308
309
310
class PortStats(GenericStruct):