pyof.v0x01.asynchronous.packet_in   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
eloc 27
dl 0
loc 68
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A PacketIn.__init__() 0 23 1
1
"""For packets received by the datapath and sent to the controller."""
2
3
# System imports
4 1
from enum import IntEnum
5
6 1
from pyof.foundation.base import GenericMessage
7 1
from pyof.foundation.basic_types import (
8
    BinaryData, Pad, UBInt8, UBInt16, UBInt32)
9 1
from pyof.v0x01.common.constants import NO_BUFFER
10 1
from pyof.v0x01.common.header import Header, Type
11
12
# Third-party imports
13
14
15 1
__all__ = ('PacketIn', 'PacketInReason')
16
17
# Enums
18
19
20 1
class PacketInReason(IntEnum):
21
    """Reason why this packet is being sent to the controller."""
22
23
    #: No matching flow
24 1
    OFPR_NO_MATCH = 0
25
    #: Action explicitly output to controller
26 1
    OFPR_ACTION = 1
27
28
29
# Classes
30
31
32 1
class PacketIn(GenericMessage):
33
    """Packet received on port (datapath -> controller)."""
34
35
    #: :class:`~pyof.v0x01.common.header.Header`: OpenFlow Header
36 1
    header = Header(message_type=Type.OFPT_PACKET_IN)
37 1
    buffer_id = UBInt32()
38 1
    total_len = UBInt16()
39 1
    in_port = UBInt16()
40 1
    reason = UBInt8(enum_ref=PacketInReason)
41
    #: Align to 32-bits.
42 1
    pad = Pad(1)
43 1
    data = BinaryData()
44
45 1
    def __init__(self, xid=None, buffer_id=NO_BUFFER, total_len=None,
46
                 in_port=None, reason=None, data=b''):
47
        """Assign parameters to object attributes.
48
49
        Args:
50
            xid (int): Header's xid.
51
            buffer_id (int): ID assigned by datapath.
52
            total_len (int): Full length of frame.
53
            in_port (int): Port on which frame was received.
54
            reason (~pyof.v0x01.asynchronous.packet_in.PacketInReason):
55
                The reason why the packet is being sent
56
            data (bytes): Ethernet frame, halfway through 32-bit word, so the
57
                IP header is 32-bit aligned. The amount of data is inferred
58
                from the length field in the header. Because of padding,
59
                offsetof(struct ofp_packet_in, data) ==
60
                sizeof(struct ofp_packet_in) - 2.
61
        """
62 1
        super().__init__(xid)
63 1
        self.buffer_id = buffer_id
64 1
        self.total_len = total_len
65 1
        self.in_port = in_port
66 1
        self.reason = reason
67
        self.data = data
68