File: packet_in.py

package info (click to toggle)
python-openflow 1.1.0~alpha2-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 692 kB
  • ctags: 1,027
  • sloc: python: 2,713; makefile: 207; sh: 8
file content (65 lines) | stat: -rw-r--r-- 2,031 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""For packets received by the datapath and sent to the controller."""

# System imports
from enum import Enum

from pyof.v0x01.common.header import Header, Type
from pyof.v0x01.foundation.base import GenericMessage
from pyof.v0x01.foundation.basic_types import (PAD, BinaryData, UBInt8,
                                               UBInt16, UBInt32)

# Third-party imports


__all__ = ('PacketIn', 'PacketInReason')

# Enums


class PacketInReason(Enum):
    """Reason why this packet is being sent to the controller."""

    #: No matching flow
    OFPR_NO_MATCH = 0
    #: Action explicitly output to controller
    OFPR_ACTION = 1


# Classes


class PacketIn(GenericMessage):
    """Packet received on port (datapath -> controller)."""

    #: :class:`~.header.Header`: OpenFlow Header
    header = Header(message_type=Type.OFPT_PACKET_IN)
    buffer_id = UBInt32()
    total_len = UBInt16()
    in_port = UBInt16()
    reason = UBInt8(enum_ref=PacketInReason)
    #: Align to 32-bits.
    pad = PAD(1)
    data = BinaryData()

    def __init__(self, xid=None, buffer_id=None, total_len=None, in_port=None,
                 reason=None, data=b''):
        """Assign parameters to object attributes.

        Args:
            xid (int): Header's xid.
            buffer_id (int): ID assigned by datapath.
            total_len (int): Full length of frame.
            in_port (int): Port on which frame was received.
            reason (PacketInReason): The reason why the packet is being sent
            data (bytes): Ethernet frame, halfway through 32-bit word, so the
                IP header is 32-bit aligned. The amount of data is inferred
                from the length field in the header. Because of padding,
                offsetof(struct ofp_packet_in, data) ==
                sizeof(struct ofp_packet_in) - 2.
        """
        super().__init__(xid)
        self.buffer_id = buffer_id
        self.total_len = total_len
        self.in_port = in_port
        self.reason = reason
        self.data = data