| @@ 34-84 (lines=51) @@ | ||
| 31 | # Classes |
|
| 32 | ||
| 33 | ||
| 34 | class PacketIn(GenericMessage): |
|
| 35 | """Packet received on port (datapath -> controller).""" |
|
| 36 | ||
| 37 | #: :class:`~.header.Header`: OpenFlow Header |
|
| 38 | header = Header(message_type=Type.OFPT_PACKET_IN) |
|
| 39 | #: ID assigned by datapath. |
|
| 40 | buffer_id = UBInt32() |
|
| 41 | #: Full length of frame. |
|
| 42 | total_len = UBInt16() |
|
| 43 | #: Reason packet is being sent (one of OFPR_*), |
|
| 44 | reason = UBInt8(enum_ref=PacketInReason) |
|
| 45 | #: ID of the table that was looked up. |
|
| 46 | table_id = UBInt8() |
|
| 47 | #: Cookie of the flow entry that was looked up. |
|
| 48 | cookie = UBInt64() |
|
| 49 | #: Packet metadata. Variable size. |
|
| 50 | match = Match() |
|
| 51 | #: Align to 64 bit + 16 bit |
|
| 52 | pad = Pad(2) |
|
| 53 | #: Ethernet frame whose length is inferred from header.length. |
|
| 54 | #: The padding bytes preceding the Ethernet frame ensure that the IP |
|
| 55 | #: header (if any) following the Ethernet header is 32-bit aligned. |
|
| 56 | data = BinaryData() |
|
| 57 | ||
| 58 | def __init__(self, xid=None, buffer_id=None, total_len=None, reason=None, |
|
| 59 | table_id=None, cookie=None, match=None, data=b''): |
|
| 60 | """Assign parameters to object attributes. |
|
| 61 | ||
| 62 | Args: |
|
| 63 | xid (int): Header's xid. |
|
| 64 | buffer_id (int): ID assigned by datapath. |
|
| 65 | total_len (int): Full length of frame. |
|
| 66 | reason (PacketInReason): The reason why the packet is being sent |
|
| 67 | table_id (int): ID of the table that was looked up |
|
| 68 | cookie (int): Cookie of the flow entry that was looked up |
|
| 69 | match (:class:`~.common.flow_match.Match`): Packet metadata. |
|
| 70 | Variable size. |
|
| 71 | data (bytes): Ethernet frame, halfway through 32-bit word, so the |
|
| 72 | IP header is 32-bit aligned. The amount of data is inferred |
|
| 73 | from the length field in the header. Because of padding, |
|
| 74 | offsetof(struct ofp_packet_in, data) == |
|
| 75 | sizeof(struct ofp_packet_in) - 2. |
|
| 76 | """ |
|
| 77 | super().__init__(xid) |
|
| 78 | self.buffer_id = buffer_id |
|
| 79 | self.total_len = total_len |
|
| 80 | self.reason = reason |
|
| 81 | self.table_id = table_id |
|
| 82 | self.cookie = cookie |
|
| 83 | self.match = match |
|
| 84 | self.data = data |
|
| 85 | ||
| @@ 36-80 (lines=45) @@ | ||
| 33 | ||
| 34 | # Classes |
|
| 35 | ||
| 36 | class SwitchFeatures(GenericMessage): |
|
| 37 | """Message sent by the switch device to the controller. |
|
| 38 | ||
| 39 | This message is the response for a features_request message, sent by the |
|
| 40 | controller to the switch device. The 'OFPT_FEATURES_REPLY' message inherits |
|
| 41 | from this class, despite the strange name. |
|
| 42 | """ |
|
| 43 | ||
| 44 | header = Header(message_type=Type.OFPT_FEATURES_REPLY) |
|
| 45 | datapath_id = UBInt64() |
|
| 46 | ||
| 47 | n_buffers = UBInt32() |
|
| 48 | ||
| 49 | n_tables = UBInt8() |
|
| 50 | auxiliary_id = UBInt8() |
|
| 51 | #: Align to 64-bits. |
|
| 52 | pad = Pad(2) |
|
| 53 | ||
| 54 | # Features |
|
| 55 | capabilities = UBInt32(enum_ref=Capabilities) |
|
| 56 | reserved = UBInt32() |
|
| 57 | ||
| 58 | def __init__(self, xid=None, datapath_id=None, n_buffers=None, |
|
| 59 | n_tables=None, auxiliary_id=None, capabilities=None, |
|
| 60 | reserved=None): |
|
| 61 | """The constructor just assings parameters to object attributes. |
|
| 62 | ||
| 63 | Args: |
|
| 64 | xid (int): xid to be used on the message header. |
|
| 65 | datapath_id (int): Datapath unique ID. |
|
| 66 | The lower 48-bits are for MAC address, while |
|
| 67 | the upper 16-bits are implementer-defined. |
|
| 68 | n_buffers (int): Max packets buffered at once. |
|
| 69 | n_tables (int): Number of tables supported by datapath. |
|
| 70 | auxiliary_id (int): Identify auxiliary connections. |
|
| 71 | capabilities (int): bitmap of supported capabilities. |
|
| 72 | reserved (int): Reserved. |
|
| 73 | """ |
|
| 74 | super().__init__(xid) |
|
| 75 | self.datapath_id = datapath_id |
|
| 76 | self.n_buffers = n_buffers |
|
| 77 | self.n_tables = n_tables |
|
| 78 | self.auxiliary_id = auxiliary_id |
|
| 79 | self.capabilities = capabilities |
|
| 80 | self.reserved = reserved |
|
| 81 | ||
| 82 | ||
| 83 | class FeaturesReply(SwitchFeatures): |
|
| @@ 403-439 (lines=37) @@ | ||
| 400 | self.queue_id = queue_id |
|
| 401 | ||
| 402 | ||
| 403 | class TableStats(GenericStruct): |
|
| 404 | """Body of reply to OFPST_TABLE request.""" |
|
| 405 | ||
| 406 | table_id = UBInt8() |
|
| 407 | #: Align to 32-bits. |
|
| 408 | pad = Pad(3) |
|
| 409 | name = Char(length=OFP_MAX_TABLE_NAME_LEN) |
|
| 410 | wildcards = UBInt32(enum_ref=FlowWildCards) |
|
| 411 | max_entries = UBInt32() |
|
| 412 | active_count = UBInt32() |
|
| 413 | count_lookup = UBInt64() |
|
| 414 | count_matched = UBInt64() |
|
| 415 | ||
| 416 | def __init__(self, table_id=None, name=None, wildcards=None, |
|
| 417 | max_entries=None, active_count=None, count_lookup=None, |
|
| 418 | count_matched=None): |
|
| 419 | """The constructor just assings parameters to object attributes. |
|
| 420 | ||
| 421 | Args: |
|
| 422 | table_id (int): Identifier of table. Lower numbered tables are |
|
| 423 | consulted first. |
|
| 424 | name (str): Table name. |
|
| 425 | wildcards (FlowWildCards): Bitmap of OFPFW_* wildcards that are |
|
| 426 | supported by the table. |
|
| 427 | max_entries (int): Max number of entries supported. |
|
| 428 | active_count (int): Number of active entries. |
|
| 429 | count_lookup (int): Number of packets looked up in table. |
|
| 430 | count_matched (int): Number of packets that hit table. |
|
| 431 | """ |
|
| 432 | super().__init__() |
|
| 433 | self.table_id = table_id |
|
| 434 | self.name = name |
|
| 435 | self.wildcards = wildcards |
|
| 436 | self.max_entries = max_entries |
|
| 437 | self.active_count = active_count |
|
| 438 | self.count_lookup = count_lookup |
|
| 439 | self.count_matched = count_matched |
|
| 440 | ||
| @@ 36-76 (lines=41) @@ | ||
| 33 | ||
| 34 | # Classes |
|
| 35 | ||
| 36 | class SwitchFeatures(GenericMessage): |
|
| 37 | """Message sent by the switch device to the controller. |
|
| 38 | ||
| 39 | This message is the response for a features_request message, sent by the |
|
| 40 | controller to the switch device. The 'OFPT_FEATURES_REPLY' message inherits |
|
| 41 | from this class, despite the strange name. |
|
| 42 | """ |
|
| 43 | ||
| 44 | header = Header(message_type=Type.OFPT_FEATURES_REPLY) |
|
| 45 | datapath_id = DPID() |
|
| 46 | n_buffers = UBInt32() |
|
| 47 | n_tables = UBInt8() |
|
| 48 | #: Align to 64-bits. |
|
| 49 | pad = Pad(3) |
|
| 50 | # Features |
|
| 51 | capabilities = UBInt32(enum_ref=Capabilities) |
|
| 52 | actions = UBInt32(enum_ref=ActionType) |
|
| 53 | ports = ListOfPhyPorts() |
|
| 54 | ||
| 55 | def __init__(self, xid=None, datapath_id=None, n_buffers=None, |
|
| 56 | n_tables=None, capabilities=None, actions=None, ports=None): |
|
| 57 | """The constructor just assings parameters to object attributes. |
|
| 58 | ||
| 59 | Args: |
|
| 60 | xid (int): xid to be used on the message header. |
|
| 61 | datapath_id (str or :class:`.DPID`): datapath unique ID. |
|
| 62 | The lower 48-bits are for MAC address, while |
|
| 63 | the upper 16-bits are implementer-defined. |
|
| 64 | n_buffers (int): UBInt32 max packets buffered at once. |
|
| 65 | n_tables (int): UBInt8 number of tables supported by datapath. |
|
| 66 | capabilities (int): UBInt32 bitmap of supported capabilities. |
|
| 67 | actions (int): UBInt32 Bitmap of supported "action_type"s. |
|
| 68 | ports (int): Port definitions. |
|
| 69 | """ |
|
| 70 | super().__init__(xid) |
|
| 71 | self.datapath_id = datapath_id |
|
| 72 | self.n_buffers = n_buffers |
|
| 73 | self.n_tables = n_tables |
|
| 74 | self.capabilities = capabilities |
|
| 75 | self.actions = actions |
|
| 76 | self.ports = [] if ports is None else ports |
|
| 77 | ||
| 78 | ||
| 79 | class FeaturesReply(SwitchFeatures): |
|