Code Duplication    Length = 69-71 lines in 2 locations

pyof/v0x01/controller2switch/common.py 1 location

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