Code Duplication    Length = 70-90 lines in 2 locations

pyof/v0x04/common/table_feature.py 1 location

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

pyof/v0x04/controller2switch/multipart_reply.py 1 location

@@ 609-678 (lines=70) @@
606
            items (BandStats): Instance or a list of instances.
607
        """
608
        super().__init__(pyof_class=BandStats, items=items)
609
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