Code Duplication    Length = 70-90 lines in 2 locations

pyof/v0x04/common/table_feature.py 1 location

@@ 247-336 (lines=90) @@
244
        super().__init__(pyof_class=Property, items=items)
245
246
247
class TableFeatures(GenericStruct):
248
    """Abstration of common class Table Features.
249
250
    Body for MultipartRequest of type OFPMP_TABLE_FEATURES.
251
    Body of reply to OFPMP_TABLE_FEATURES request.
252
    """
253
254
    length = UBInt16()
255
    # /* Identifier of table.  Lower numbered tables are consulted first. */
256
    table_id = UBInt8()
257
    # /* Align to 64-bits. */
258
    pad = Pad(5)
259
    name = Char(length=OFP_MAX_TABLE_NAME_LEN)
260
    # /* Bits of metadata table can match. */
261
    metadata_match = UBInt64()
262
    # /* Bits of metadata table can write. */
263
    metadata_write = UBInt64()
264
    # /* Bitmap of OFPTC_* values */
265
    config = UBInt32()
266
    # /* Max number of entries supported. */
267
    max_entries = UBInt32()
268
    # /* Table Feature Property list */
269
    properties = ListOfProperty()
270
271
    def __init__(self, table_id=Table.OFPTT_ALL, name="",
272
                 metadata_match=0xFFFFFFFFFFFFFFFF,
273
                 metadata_write=0xFFFFFFFFFFFFFFFF,
274
                 config=0,
275
                 max_entries=0,
276
                 properties=ListOfProperty()):
277
        """The constructor of TableFeatures receives the paramters below.
278
279
        Args:
280
            table_id(int):       Indetifier of table.The default value
281
                                 OFPTT_ALL(0xff) will apply the configuration
282
                                 to all tables in the switch.
283
            name(Char):          Characters representing the table name.
284
            metadata_match(int): Indicate the bits of the metadata field that
285
                                 the table can match on.The default value
286
                                 0xFFFFFFFFFFFFFFFF indicates that the table
287
                                 can match the full metadata field.
288
            metadata_write(int): Indicates the bits of the metadata field that
289
                                 the table can write using the
290
                                 OFPIT_WRITE_METADATA instruction.The default
291
                                 value 0xFFFFFFFFFFFFFFFF indicates that the
292
                                 table can write the full metadata field.
293
            config(int):         Field reseved for future use.
294
            max_entries(int):    Describe the maximum number of flow entries
295
                                 that can be inserted into that table.
296
            properties(ListOfProperty): List of Property intances.
297
        """
298
        super().__init__()
299
        self.table_id = table_id
300
        self.name = name
301
        self.metadata_match = metadata_match
302
        self.metadata_write = metadata_write
303
        self.config = config
304
        self.max_entries = max_entries
305
        self.properties = properties
306
        self.update_length()
307
308
    def pack(self, value=None):
309
        """Pack method used to update the length of instance and packing.
310
311
        Args:
312
            value: Structure to be packed.
313
        """
314
        self.update_length()
315
        return super().pack(value)
316
317
    def update_length(self):
318
        """Update the length of current instance."""
319
        self.length = self.get_size()
320
321
    def unpack(self, buff=None, offset=0):
322
        """Unpack *buff* into this object.
323
324
        This method will convert a binary data into a readable value according
325
        to the attribute format.
326
327
        Args:
328
            buff (bytes): Binary buffer.
329
            offset (int): Where to begin unpacking.
330
331
        Raises:
332
            :exc:`~.exceptions.UnpackException`: If unpack fails.
333
        """
334
        length = UBInt16()
335
        length.unpack(buff, offset)
336
        super().unpack(buff[:offset+length.value], offset)
337

pyof/v0x04/controller2switch/multipart_reply.py 1 location

@@ 582-651 (lines=70) @@
579
    packet_band_count = UBInt64()
580
    byte_band_count = UBInt64()
581
582
    def __init__(self, packet_band_count=None, byte_band_count=None):
583
        """The constructor just assings parameters to object attributes.
584
585
        Args:
586
            packet_band_count(int): Number of packets in band.
587
            byte_band_count(int):   Number of bytes in band.
588
        """
589
        super().__init__()
590
        self.packet_band_count = packet_band_count
591
        self.byte_band_count = byte_band_count
592
593
594
class ListOfBandStats(FixedTypeList):
595
    """List of BandStats.
596
597
    Represented by instances of BandStats.
598
    """
599
600
    def __init__(self, items=None):
601
        """The constructor just assings parameters to object attributes.
602
603
        Args:
604
            items (BandStats): Instance or a list of instances.
605
        """
606
        super().__init__(pyof_class=BandStats, items=items)
607
608
609
class MeterStats(GenericStruct):
610
    """Meter Statistics.
611
612
    Body of reply to OFPMP_METER request.
613
    """
614
615
    meter_id = UBInt32()
616
    length = UBInt16()
617
    pad = Pad(6)
618
    flow_count = UBInt32()
619
    packet_in_count = UBInt64()
620
    byte_in_count = UBInt64()
621
    duration_sec = UBInt32()
622
    duration_nsec = UBInt32()
623
    band_stats = ListOfBandStats()
624
625
    def __init__(self, meter_id=None, flow_count=None,
626
                 packet_in_count=None, byte_in_count=None, duration_sec=None,
627
                 duration_nsec=None, band_stats=None):
628
        """The constructor just assings parameters to object attributes.
629
630
        Args:
631
            meter_id(Meter):      Meter instance.
632
            flow_count(int):      Number of flows bound to meter.
633
            packet_in_count(int): Number of packets in input.
634
            byte_in_count(int):   Number of bytes in input.
635
            duration_sec(int):    Time meter has been alive in seconds.
636
            duration_nsec(int):   Time meter has been alive in
637
                                  nanoseconds beyond duration_sec.
638
            band_stats(list):     Instances of BandStats
639
        """
640
        super().__init__()
641
        self.meter_id = meter_id
642
        self.flow_count = flow_count
643
        self.packet_in_count = packet_in_count
644
        self.byte_in_count = byte_in_count
645
        self.duration_sec = duration_sec
646
        self.duration_nsec = duration_nsec
647
        self.band_stats = band_stats if band_stats else []
648
        self.update_length()
649
650
    def update_length(self):
651
        """Update length attribute with current struct length."""
652
        self.length = self.get_size()
653
654
    def pack(self, value=None):