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 to all tables in
289
               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 0xFFFFFFFFFFFFFFFF
293
                indicates that the table can match the full metadata field.
294
            metadata_write(int): Indicates the bits of the metadata field that
295
               the table can write using the OFPIT_WRITE_METADATA instruction.
296
               The default value 0xFFFFFFFFFFFFFFFF indicates that the table
297
               can write the full metadata field.
298
            config(int): Field reseved for future use.
299
            max_entries(int): Describe the maximum number of flow entries that
300
               can be inserted into that table.
301
            properties(~pyof.v0x04.controller2switch.common.Property):
302
               List of Property intances.
303
        """
304
        super().__init__()
305
        self.table_id = table_id
306
        self.name = name
307
        self.metadata_match = metadata_match
308
        self.metadata_write = metadata_write
309
        self.config = config
310
        self.max_entries = max_entries
311
        self.properties = properties
312
        self.update_length()
313
314
    def pack(self, value=None):
315
        """Pack method used to update the length of instance and packing.
316
317
        Args:
318
            value: Structure to be packed.
319
        """
320
        self.update_length()
321
        return super().pack(value)
322
323
    def update_length(self):
324
        """Update the length of current instance."""
325
        self.length = self.get_size()
326
327
    def unpack(self, buff=None, offset=0):
328
        """Unpack *buff* into this object.
329
330
        This method will convert a binary data into a readable value according
331
        to the attribute format.
332
333
        Args:
334
            buff (bytes): Binary buffer.
335
            offset (int): Where to begin unpacking.
336
337
        Raises:
338
            :exc:`~.exceptions.UnpackException`: If unpack fails.
339
        """

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