|
| 1 | +"""Module with generic messages used in controller2switch.""" |
| 2 | + |
| 3 | +# System imports |
| 4 | +from enum import Enum |
| 5 | + |
| 6 | +from pyof.foundation.base import GenericMessage |
| 7 | +from pyof.foundation.basic_types import Pad, UBInt16, UBInt32, UBInt64 |
| 8 | +from pyof.v0x04.asynchronous.flow_removed import FlowRemovedReason |
| 9 | +from pyof.v0x04.asynchronous.packet_in import PacketInReason |
| 10 | +from pyof.v0x04.asynchronous.port_status import PortReason |
| 11 | +from pyof.v0x04.common.header import Header |
| 12 | + |
| 13 | +__all__ = ('ConfigFlags', 'ControllerRole',) |
| 14 | + |
| 15 | + |
| 16 | +class ConfigFlags(Enum): |
| 17 | + """Handling of IP fragments.""" |
| 18 | + |
| 19 | + #: No special handling for fragments. |
| 20 | + OFPC_FRAG_NORMAL = 0 |
| 21 | + #: Drop fragments. |
| 22 | + OFPC_FRAG_DROP = 1 |
| 23 | + #: Reassemble (only if OFPC_IP_REASM set). |
| 24 | + OFPC_FRAG_REASM = 2 |
| 25 | + OFPC_FRAG_MASK = 3 |
| 26 | + |
| 27 | + |
| 28 | +class ControllerRole(Enum): |
| 29 | + """Controller roles.""" |
| 30 | + |
| 31 | + #: Don’t change current role. |
| 32 | + OFPCR_ROLE_NOCHANGE = 0 |
| 33 | + #: Default role, full access. |
| 34 | + OFPCR_ROLE_EQUAL = 1 |
| 35 | + #: Full access, at most one master. |
| 36 | + OFPCR_ROLE_MASTER = 2 |
| 37 | + #: Read-only access. |
| 38 | + OFPCR_ROLE_SLAVE = 3 |
| 39 | + |
| 40 | +# Base Classes for other messages - not meant to be directly used, so, because |
| 41 | +# of that, they will not be inserted on the __all__ attribute. |
| 42 | + |
| 43 | + |
| 44 | +class AsyncConfig(GenericMessage): |
| 45 | + """Asynchronous message configuration base class. |
| 46 | +
|
| 47 | + Common structure for SetAsync and GetAsyncReply messages. |
| 48 | +
|
| 49 | + AsyncConfig contains three 2-element arrays. Each array controls whether |
| 50 | + the controller receives asynchronous messages with a specific |
| 51 | + :class:`~.common.header.Type`. Within each array, element 0 specifies |
| 52 | + messages of interest when the controller has a OFPCR_ROLE_EQUAL or |
| 53 | + OFPCR_ROLE_MASTER role; element 1, when the controller has a |
| 54 | + OFPCR_ROLE_SLAVE role. Each array element is a bit-mask in which a 0-bit |
| 55 | + disables receiving a message sent with the reason code corresponding to the |
| 56 | + bit index and a 1-bit enables receiving it. |
| 57 | + """ |
| 58 | + |
| 59 | + #: OpenFlow :class:`~common.header.Header` |
| 60 | + #: OFPT_GET_ASYNC_REPLY or OFPT_SET_ASYNC. |
| 61 | + header = Header() |
| 62 | + packet_in_mask1 = UBInt32(enum_ref=PacketInReason) |
| 63 | + packet_in_mask2 = UBInt32(enum_ref=PacketInReason) |
| 64 | + port_status_mask1 = UBInt32(enum_ref=PortReason) |
| 65 | + port_status_mask2 = UBInt32(enum_ref=PortReason) |
| 66 | + flow_removed_mask1 = UBInt32(enum_ref=FlowRemovedReason) |
| 67 | + flow_removed_mask2 = UBInt32(enum_ref=FlowRemovedReason) |
| 68 | + |
| 69 | + def __init__(self, xid=None, packet_in_mask1=None, packet_in_mask2=None, |
| 70 | + port_status_mask1=None, port_status_mask2=None, |
| 71 | + flow_removed_mask1=None, flow_removed_mask2=None): |
| 72 | + """Base class for Asynchronous configuration messages. |
| 73 | +
|
| 74 | + Common structure for SetAsync and GetAsyncReply messages. |
| 75 | +
|
| 76 | + Args: |
| 77 | + xid (int): xid to be used on the message header. |
| 78 | + packet_in_mask1 (): . |
| 79 | + packet_in_mask2 (): . |
| 80 | + port_status_mask1 (): . |
| 81 | + port_status_mask2 (): . |
| 82 | + flow_removed_mask1 (): . |
| 83 | + flow_removed_mask2 (): . |
| 84 | + """ |
| 85 | + super().__init__(xid) |
| 86 | + self.packet_in_mask1 = packet_in_mask1 |
| 87 | + self.packet_in_mask2 = packet_in_mask2 |
| 88 | + self.port_status_mask1 = port_status_mask1 |
| 89 | + self.port_status_mask2 = port_status_mask2 |
| 90 | + self.flow_removed_mask1 = flow_removed_mask1 |
| 91 | + self.flow_removed_mask2 = flow_removed_mask2 |
| 92 | + |
| 93 | + |
| 94 | +class RoleBaseMessage(GenericMessage): |
| 95 | + """Role basic structure for RoleRequest and RoleReply messages.""" |
| 96 | + |
| 97 | + #: :class:`~.common.header.Header` |
| 98 | + #: Type OFPT_ROLE_REQUEST/OFPT_ROLE_REPLY. |
| 99 | + header = Header() |
| 100 | + #: One of NX_ROLE_*. (:class:`~.controller2switch.common.ControllerRole`) |
| 101 | + role = UBInt32(enum_ref=ControllerRole) |
| 102 | + #: Align to 64 bits. |
| 103 | + pad = Pad(4) |
| 104 | + #: Master Election Generation Id. |
| 105 | + generation_id = UBInt64() |
| 106 | + |
| 107 | + def __init__(self, xid=None, role=None, generation_id=None): |
| 108 | + """The constructor just assings parameters to object attributes. |
| 109 | +
|
| 110 | + Args: |
| 111 | + xid (int): OpenFlow xid to the header. |
| 112 | + role (:class:`~.controller2switch.common.ControllerRole`): . |
| 113 | + generation_id (int): Master Election Generation Id. |
| 114 | + """ |
| 115 | + super().__init__(xid) |
| 116 | + self.role = role |
| 117 | + self.generation_id = generation_id |
| 118 | + |
| 119 | + |
| 120 | +class SwitchConfig(GenericMessage): |
| 121 | + """Used as base class for SET_CONFIG and GET_CONFIG_REPLY messages.""" |
| 122 | + |
| 123 | + #: OpenFlow :class:`~common.header.Header` |
| 124 | + header = Header() |
| 125 | + flags = UBInt16(enum_ref=ConfigFlags) |
| 126 | + miss_send_len = UBInt16() |
| 127 | + |
| 128 | + def __init__(self, xid=None, flags=None, miss_send_len=None): |
| 129 | + """The constructor just assings parameters to object attributes. |
| 130 | +
|
| 131 | + Args: |
| 132 | + xid (int): xid to be used on the message header. |
| 133 | + flags (ConfigFlags): OFPC_* flags. |
| 134 | + miss_send_len (int): UBInt16 max bytes of new flow that the |
| 135 | + datapath should send to the controller. |
| 136 | + """ |
| 137 | + super().__init__(xid) |
| 138 | + self.flags = flags |
| 139 | + self.miss_send_len = miss_send_len |
0 commit comments