Code Duplication    Length = 20-28 lines in 3 locations

pyof/v0x04/controller2switch/group_mod.py 1 location

@@ 65-92 (lines=28) @@
62
        """
63
        super().__init__(pyof_class=Bucket, items=items)
64
65
66
class GroupMod(GenericMessage):
67
    """Group setup and teardown (controller -> datapath)."""
68
69
    header = Header(message_type=Type.OFPT_GROUP_MOD)
70
    command = UBInt16(enum_ref=GroupModCommand)
71
    group_type = UBInt8()
72
    #: Pad to 64 bits.
73
    pad = Pad(1)
74
    group_id = UBInt32()
75
    buckets = ListOfBuckets()
76
77
    def __init__(self, xid=None, command=None, group_type=None, group_id=None,
78
                 buckets=None):
79
        """Initialize all instance variables.
80
81
        Args:
82
            xid (int): Header's transaction id. Defaults to random.
83
            command (GroupModCommand): One of OFPGC_*.
84
            group_type (GroupType): One of OFPGT_*.
85
            group_id (int): Group identifier.
86
            buckets (:class:`ListOfBuckets`): The length of the bucket
87
                array is inferred from the length field in the header.
88
        """
89
        super().__init__(xid)
90
        self.command = command
91
        self.group_type = group_type
92
        self.group_id = group_id
93
        self.buckets = buckets
94

pyof/v0x04/controller2switch/multipart_reply.py 1 location

@@ 376-400 (lines=25) @@
373
    tx_bytes = UBInt64()
374
    tx_packets = UBInt64()
375
    tx_errors = UBInt64()
376
    duration_sec = UBInt32()
377
    duration_nsec = UBInt32()
378
379
    def __init__(self, port_no=None, queue_id=None, tx_bytes=None,
380
                 tx_packets=None, tx_errors=None, duration_sec=None,
381
                 duration_nsec=None):
382
        """The constructor just assigns parameters to object attributes.
383
384
        Args:
385
            port_no (:class:`int`, :class:`~pyof.v0x04.common.port.Port`):
386
                Port Number.
387
            queue_id (int): Queue ID.
388
            tx_bytes (int): Number of transmitted bytes.
389
            tx_packets (int): Number of transmitted packets.
390
            tx_errors (int): Number of packets dropped due to overrun.
391
            duration_sec (int): Time queue has been alive in seconds.
392
            duration_nsec (int): Time queue has been alive in nanoseconds
393
                beyond duration_sec.
394
        """
395
        super().__init__()
396
        self.port_no = port_no
397
        self.queue_id = queue_id
398
        self.tx_bytes = tx_bytes
399
        self.tx_packets = tx_packets
400
        self.tx_errors = tx_errors
401
        self.duration_sec = duration_sec
402
        self.duration_nsec = duration_nsec
403

pyof/v0x01/common/header.py 1 location

@@ 68-87 (lines=20) @@
65
# Classes
66
67
68
class Header(GenericStruct):
69
    """Representation of an OpenFlow message Header."""
70
71
    version = UBInt8(OFP_VERSION)
72
    message_type = UBInt8(enum_ref=Type)
73
    length = UBInt16()
74
    xid = UBInt32()
75
76
    def __init__(self, message_type=None, length=None, xid=None):
77
        """The constructor takes the optional parameters below.
78
79
        Args:
80
            message_type (~pyof.v0x01.common.header.Type): Type of the message.
81
            xid (int): ID of the message. Defaults to a random integer.
82
            length (int): Length of the message, including the header itself.
83
        """
84
        super().__init__()
85
        self.message_type = message_type
86
        self.length = length
87
        self.xid = randint(0, MAXID) if xid is None else xid
88