class QueueStats(GenericStruct): """Implements the reply body of a port_no.""" port_no = UBInt16() #: Align to 32-bits. pad = Pad(2) queue_id = UBInt32() tx_bytes = UBInt64() tx_packets = UBInt64() tx_errors = UBInt64() def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None): """The constructor just assings parameters to object attributes. Args: port_no (:class:`int`, :class:`.Port`): Port Number. queue_id (int): Queue ID. tx_bytes (int): Number of transmitted bytes. tx_packets (int): Number of transmitted packets. tx_errors (int): Number of packets dropped due to overrun. """ super().__init__() self.port_no = port_no self.queue_id = queue_id self.tx_bytes = tx_bytes self.tx_packets = tx_packets self.tx_errors = tx_errors
class QueueStats(GenericStruct): """Implements the reply body of a port_no.""" port_no = UBInt16() #: Align to 32-bits. pad = Pad(2) queue_id = UBInt32() tx_bytes = UBInt64() tx_packets = UBInt64() tx_errors = UBInt64() def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None): """Create a QueueStats with the optional parameters below. Args: port_no (:class:`int`, :class:`~pyof.v0x01.common.phy_port.Port`): Port Number. queue_id (int): Queue ID. tx_bytes (int): Number of transmitted bytes. tx_packets (int): Number of transmitted packets. tx_errors (int): Number of packets dropped due to overrun. """ super().__init__() self.port_no = port_no self.queue_id = queue_id self.tx_bytes = tx_bytes self.tx_packets = tx_packets self.tx_errors = tx_errors
class QueueStats(GenericStruct): """Implements the reply body of a port_no.""" port_no = UBInt32() queue_id = UBInt32() tx_bytes = UBInt64() tx_packets = UBInt64() tx_errors = UBInt64() duration_sec = UBInt32() duration_nsec = UBInt32() def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None, duration_sec=None, duration_nsec=None): """The constructor just assings parameters to object attributes. Args: port_no (:class:`int`, :class:`.Port`): Port Number. queue_id (int): Queue ID. tx_bytes (int): Number of transmitted bytes. tx_packets (int): Number of transmitted packets. tx_errors (int): Number of packets dropped due to overrun. duration_sec (int): Time queue has been alive in seconds. duration_nsec (int): Time queue has been alive in nanoseconds beyond duration_sec. """ super().__init__() self.port_no = port_no self.queue_id = queue_id self.tx_bytes = tx_bytes self.tx_packets = tx_packets self.tx_errors = tx_errors self.duration_sec = duration_sec self.duration_nsec = duration_nsec
class InstructionWriteMetadata(GenericStruct): """Instruction structure for OFPIT_WRITE_METADATA.""" #: OFPIT_WRITE_METADATA instruction_type = UBInt16(InstructionType.OFPIT_WRITE_METADATA, enum_ref=InstructionType) #: Length of this struct in bytes length = UBInt16() #: Align to 64-bits pad = Pad(4) #: Metadata value to write metadata = UBInt64() #: Metadata write bitmask metadata_mask = UBInt64() def __init__(self, length=None, metadata=None, metadata_mask=None): """Instruction structure for OFPIT_WRITE_METADATA. Args: - length (int): Length of this struct in bytes. - metadata (int): Metadata value to write. - metadata_mask (int): Metadata write bitmask. """ super().__init__() self.length = length self.metadata = metadata self.metadata_mask = metadata_mask
class PortStatsPropEthernet(PortStatsPropHeader): """ Ethernet port stats property """ pad = Pad(4) rx_frame_err = UBInt64() rx_over_err = UBInt64() rx_crc_err = UBInt64() collisions = UBInt64() def __init__(self, rx_frame_err=None, rx_over_err=None, rx_crc_err=None, collisions=None): """ Create the Ethernet port stats property. :param rx_frame_err: Number of frame alignment errors. :param rx_over_err: Number of packets with RX overrun. :param rx_crc_err: Number of CRC errors. :param collisions: Number of collisions. """ super().type = PortStatsPropType.OFPPSPT_ETHERNET self.rx_frame_err = rx_frame_err self.rx_over_err = rx_over_err self.rx_crc_err = rx_crc_err self.collisions = collisions super().length = self.__sizeof__()
class TableStats(GenericStruct): """Body of reply to OFPST_TABLE request.""" table_id = UBInt8() #: Align to 32-bits. pad = Pad(3) active_count = UBInt32() lookup_count = UBInt64() matched_count = UBInt64() def __init__(self, table_id=None, name=None, max_entries=None, active_count=None, lookup_count=None, matched_count=None): """The constructor just assings parameters to object attributes. Args: table_id (int): Identifier of table. Lower numbered tables are consulted first. active_count (int): Number of active entries. lookup_count (int): Number of packets looked up in table. matched_count (int): Number of packets that hit table. """ super().__init__() self.table_id = table_id self.active_count = active_count self.lookup_count = lookup_count self.matched_count = matched_count
class AggregateStatsReply(GenericStruct): """Body of reply to OFPMP_AGGREGATE request.""" #: Number of packets in flows. packet_count = UBInt64() #: Number of bytes in flows. byte_count = UBInt64() #: Number of flows. flow_count = UBInt32() #: Align to 64 bits pad = Pad(4) def __init__(self, packet_count=None, byte_count=None, flow_count=None): """Create a AggregateStatsReply with the optional parameters below. Args: packet_count (int): Number of packets in flows byte_count (int): Number of bytes in flows flow_count (int): Number of flows """ super().__init__() self.packet_count = packet_count self.byte_count = byte_count self.flow_count = flow_count
class FlowRemoved(GenericMessage): """Flow removed (datapath -> controller).""" #: :class:`~.header.Header`: OpenFlow Header header = Header(message_type=Type.OFPT_FLOW_REMOVED) #: :class:`~.flow_match.Match`: OpenFlow Header match = Match() cookie = UBInt64() priority = UBInt16() reason = UBInt8(enum_ref=FlowRemovedReason) #: Align to 32-bits. pad = Pad(1) duration_sec = UBInt32() duration_nsec = UBInt32() idle_timeout = UBInt16() #: Align to 64-bits. pad2 = Pad(2) packet_count = UBInt64() byte_count = UBInt64() def __init__(self, xid=None, match=None, cookie=None, priority=None, reason=None, duration_sec=None, duration_nsec=None, idle_timeout=None, packet_count=None, byte_count=None): """Assign parameters to object attributes. Args: xid (int): OpenFlow Header's xid. match (Match): Fields' description. cookie (int): Opaque controller-issued identifier. priority (int): Priority level of flow entry. reason (FlowRemovedReason): Why the flow was removed. duration_sec (int): Time the flow was alive in seconds. duration_nsec (int): Time the flow was alive in nanoseconds in addition to duration_sec. idle_timeout (int): Idle timeout from original flow mod. packet_count (int): Number of packets. byte_count (int): Byte count. """ super().__init__(xid) self.match = match self.cookie = cookie self.priority = priority self.reason = reason self.duration_sec = duration_sec self.duration_nsec = duration_nsec self.idle_timeout = idle_timeout self.packet_count = packet_count self.byte_count = byte_count
class FlowStats(GenericStruct): """Body of reply to OFPST_FLOW request.""" length = UBInt16() table_id = UBInt8() #: Align to 32 bits. pad = Pad(1) duration_sec = UBInt32() duration_nsec = UBInt32() priority = UBInt16() idle_timeout = UBInt16() hard_timeout = UBInt16() flags = UBInt16() #: Align to 64-bits pad2 = Pad(4) cookie = UBInt64() packet_count = UBInt64() byte_count = UBInt64() match = Match() def __init__(self, length=None, table_id=None, duration_sec=None, duration_nsec=None, priority=None, idle_timeout=None, hard_timeout=None, flags=None, cookie=None, packet_count=None, byte_count=None, match=None): """The constructor just assings parameters to object attributes. Args: length (int): Length of this entry. table_id (int): ID of table flow came from. duration_sec (int): Time flow has been alive in seconds. duration_nsec (int): Time flow has been alive in nanoseconds in addition to duration_sec. priority (int): Priority of the entry. Only meaningful when this is not an exact-match entry. idle_timeout (int): Number of seconds idle before expiration. hard_timeout (int): Number of seconds before expiration. cookie (int): Opaque controller-issued identifier. packet_count (int): Number of packets in flow. byte_count (int): Number of bytes in flow. match (Match): Description of fields. """ super().__init__() self.length = length self.table_id = table_id self.duration_sec = duration_sec self.duration_nsec = duration_nsec self.priority = priority self.idle_timeout = idle_timeout self.hard_timeout = hard_timeout self.flags = flags self.cookie = cookie self.packet_count = packet_count self.byte_count = byte_count
class AggregateStatsRequest(GenericStruct): """Body for ofp_stats_request of type OFPST_AGGREGATE.""" #: ID of table to read (from ofp_table_stats) OFPTT_ALL for all tables. table_id = UBInt8() #: Align to 32 bits. pad = Pad(3) #: Require matching entries to include this as an output port. A value of #: OFPP_ANY indicates no restriction. out_port = UBInt32() #: Require matching entries to include this as an output group. A value of #: OFPG_ANY indicates no restriction. out_group = UBInt32() #: Align to 64 bits pad2 = Pad(4) #: Require matching entries to contain this cookie value cookie = UBInt64() #: Mask used to restrict the cookie bits that must match. A value of 0 #: indicates no restriction. cookie_mask = UBInt64() #: Fields to match. Variable size. match = Match() def __init__(self, table_id=Table.OFPTT_ALL, out_port=PortNo.OFPP_ANY, out_group=Group.OFPG_ANY, cookie=0, cookie_mask=0, match=None): """Create a AggregateStatsRequest with the optional parameters below. Args: table_id (int): ID of table to read (from ofp_table_stats) OFPTT_ALL for all tables. out_port (int): Require matching entries to include this as an output port. A value of OFPP_ANY indicates no restriction. out_group (int): Require matching entries to include this as an output group. A value of OFPG_ANY indicates no restriction. cookie (int): Require matching entries to contain this cookie value cookie_mask (int): Mask used to restrict the cookie bits that must match. A value of 0 indicates no restriction. match (~pyof.v0x04.common.flow_match.Match): Fields to match. Variable size """ super().__init__() self.table_id = table_id self.out_port = out_port self.out_group = out_group self.cookie = cookie self.cookie_mask = cookie_mask self.match = Match() if match is None else match
class RoleBaseMessage(GenericMessage): """Role basic structure for RoleRequest and RoleReply messages.""" #: :class:`~pyof.v0x04.common.header.Header` #: Type OFPT_ROLE_REQUEST/OFPT_ROLE_REPLY. header = Header() #: One of NX_ROLE_*. (:class:`~.controller2switch.common.ControllerRole`) role = UBInt32(enum_ref=ControllerRole) #: Align to 64 bits. pad = Pad(4) #: Master Election Generation Id. generation_id = UBInt64() def __init__(self, xid=None, role=None, generation_id=None): """Create a RoleBaseMessage with the optional parameters below. Args: xid (int): OpenFlow xid to the header. role (:class:`~.controller2switch.common.ControllerRole`): . generation_id (int): Master Election Generation Id. """ super().__init__(xid) self.role = role self.generation_id = generation_id
class GroupStats(GenericStruct): """Body of reply to OFPMP_GROUP request.""" length = UBInt16() #: Align to 64 bits. pad = Pad(2) group_id = UBInt32() ref_count = UBInt32() #: Align to 64 bits. pad2 = Pad(4) packet_count = UBInt64() byte_count = UBInt64() duration_sec = UBInt32() duration_nsec = UBInt32() bucket_stats = FixedTypeList(BucketCounter) def __init__(self, length=None, group_id=None, ref_count=None, packet_count=None, byte_count=None, duration_sec=None, duration_nsec=None, bucket_stats=None): """Create a GroupStats with the optional parameters below. Args: length: Length of this entry group_id: Group identifier ref_count: Number of flows or groups that directly forward to this group. packet_count: Number of packets processed by group byte_count: Number of bytes processed by group duration_sec: Time group has been alive in seconds duration_nsec: Time group has been alive in nanoseconds bucket_stats: List of stats of group buckets """ super().__init__() self.length = length self.group_id = group_id self.ref_count = ref_count self.packet_count = packet_count self.byte_count = byte_count self.duration_sec = duration_sec self.duration_nsec = duration_nsec self.bucket_stats = bucket_stats
class MyClassB(MyClassA): """Example class.""" a0 = UBInt32(0) a2 = UBInt64(2) b6 = UBInt8(6) _removed_attributes = ['a3']
class AggregateStatsRequest(GenericStruct): """Body for ofp_stats_request of type OFPST_AGGREGATE.""" #: ID of table to read (from ofp_table_stats) OFPTT_ALL for all tables. table_id = UBInt8() #: Align to 32 bits. pad = Pad(3) #: Require matching entries to include this as an output port. A value of #: OFPP_ANY indicates no restriction. out_port = UBInt32() #: Require matching entries to include this as an output group. A value of #: OFPG_ANY indicates no restriction. out_group = UBInt32() #: Align to 64 bits pad2 = Pad(4) #: Require matching entries to contain this cookie value cookie = UBInt64() #: Mask used to restrict the cookie bits that must match. A value of 0 #: indicates no restriction. cookie_mask = UBInt64() #: Fields to match. Variable size. match = Match() def __init__(self, table_id=None, out_port=None, out_group=None, cookie=None, cookie_mask=None, match=None): """The constructor just assings parameters to object attributes. Args: table_id (int): ID of table to read (from ofp_table_stats) OFPTT_ALL for all tables. out_port (int): Require matching entries to include this as an output port. A value of OFPP_ANY indicates no restriction. out_group (in): Require matching entries to include this as an output group. A value of OFPG_ANY indicates no restriction. cookie (int): Require matching entries to contain this cookie value cookie_mask (int): Mask used to restrict the cookie bits that must match. A value of 0 indicates no restriction. match (Match): Fields to match. Variable size """ super().__init__() self.table_id = table_id self.out_port = out_port self.out_group = out_group self.cookie = cookie self.cookie_mask = cookie_mask self.match = match
class FlowMod(GenericMessage): """Modifies the flow table from the controller.""" header = Header(message_type=Type.OFPT_FLOW_MOD) match = Match() cookie = UBInt64() command = UBInt16(enum_ref=FlowModCommand) idle_timeout = UBInt16() hard_timeout = UBInt16() priority = UBInt16() buffer_id = UBInt32() out_port = UBInt16(enum_ref=Port) flags = UBInt16(enum_ref=FlowModFlags) actions = ListOfActions() def __init__(self, xid=None, match=None, cookie=0, command=None, idle_timeout=0, hard_timeout=0, priority=0, buffer_id=NO_BUFFER, out_port=Port.OFPP_NONE, flags=FlowModFlags.OFPFF_CHECK_OVERLAP, actions=None): """The constructor just assings parameters to object attributes. Args: xid (int): xid to be used on the message header. match (Match): Fields to match. cookie (int): Opaque controller-issued identifier. command (FlowModCommand): One of OFPFC_*. idle_timeout (int): Idle time before discarding (seconds). hard_timeout (int): Max time before discarding (seconds). priority (int): Priority level of flow entry. buffer_idle (int): Buffered packet to apply to (or -1). Not meaningful for OFPFC_DELETE*. out_port (Port): For OFPFC_DELETE* commands, require matching entries to include this as an output port. A value of OFPP_NONE indicates no restriction. flags (FlowModFlags): One of OFPFF_*. actions (ListOfActions): The action length is inferred from the length field in the header. """ super().__init__(xid) self.match = match self.cookie = cookie self.command = command self.idle_timeout = idle_timeout self.hard_timeout = hard_timeout self.priority = priority self.buffer_id = buffer_id self.out_port = out_port self.flags = flags self.actions = [] if actions is None else actions
class BucketCounter(GenericStruct): """Used in group stats replies.""" #: Number of packets processed by bucket. packet_count = UBInt64() #: Number of bytes processed by bucket. byte_count = UBInt64() def __init__(self, packet_count=None, byte_count=None): """Create BucketCounter with the optional parameters below. Args: packet_count (int): Number of packets processed by bucket. byte_count (int): Number of bytes processed by bucket. """ super().__init__() self.packet_count = packet_count self.byte_count = byte_count
class BandStats(GenericStruct): """Band Statistics. Statistics for each meter band. """ packet_band_count = UBInt64() byte_band_count = UBInt64() def __init__(self, packet_band_count=None, byte_band_count=None): """Create a BandStats with the optional parameters below. Args: packet_band_count(int): Number of packets in band. byte_band_count(int): Number of bytes in band. """ super().__init__() self.packet_band_count = packet_band_count self.byte_band_count = byte_band_count
class FlowStatsRequest(GenericStruct): """Body for ofp_stats_request of type OFPST_FLOW.""" table_id = UBInt8() #: Align to 32 bits. pad = Pad(3) out_port = UBInt32() out_group = UBInt32() pad2 = Pad(4) cookie = UBInt64() cookie_mask = UBInt64() match = Match() def __init__(self, table_id=Table.OFPTT_ALL, out_port=PortNo.OFPP_ANY, out_group=Group.OFPG_ANY, cookie=0, cookie_mask=0, match=None): """Create a FlowStatsRequest with the optional parameters below. Args: table_id (int): ID of table to read (from pyof_table_stats) 0xff for all tables or 0xfe for emergency. out_port (:class:`int`, :class:`~pyof.v0x04.common.port.PortNo`): Require matching entries to include this as an output port. A value of :attr:`.PortNo.OFPP_ANY` indicates no restriction. out_group: Require matching entries to include this as an output group. A value of :attr:`Group.OFPG_ANY` indicates no restriction. cookie: Requires matching entries to contain this cookie value cookie_mask: Mask used to restrict the cookie bits that must match. A value of 0 indicates no restriction. match (~pyof.v0x04.common.flow_match.Match): Fields to match. """ super().__init__() self.table_id = table_id self.out_port = out_port self.out_group = out_group self.cookie = cookie self.cookie_mask = cookie_mask self.match = Match() if match is None else match
class TableStats(GenericStruct): """Body of reply to OFPST_TABLE request.""" table_id = UBInt8() #: Align to 32-bits. pad = Pad(3) name = Char(length=OFP_MAX_TABLE_NAME_LEN) wildcards = UBInt32(enum_ref=FlowWildCards) max_entries = UBInt32() active_count = UBInt32() count_lookup = UBInt64() count_matched = UBInt64() def __init__(self, table_id=None, name=None, wildcards=None, max_entries=None, active_count=None, count_lookup=None, count_matched=None): """Create a TableStats with the optional parameters below. Args: table_id (int): Identifier of table. Lower numbered tables are consulted first. name (str): Table name. wildcards (:class:`~pyof.v0x01.common.flow_match.FlowWildCards`): Bitmap of OFPFW_* wildcards that are supported by the table. max_entries (int): Max number of entries supported. active_count (int): Number of active entries. count_lookup (int): Number of packets looked up in table. count_matched (int): Number of packets that hit table. """ super().__init__() self.table_id = table_id self.name = name self.wildcards = wildcards self.max_entries = max_entries self.active_count = active_count self.count_lookup = count_lookup self.count_matched = count_matched
class InstructionWriteMetadata(Instruction): """Instruction structure for OFPIT_WRITE_METADATA.""" #: Align to 64-bits pad = Pad(4) #: Metadata value to write metadata = UBInt64() #: Metadata write bitmask metadata_mask = UBInt64() def __init__(self, metadata=0, metadata_mask=0): """Create InstructionWriteMetadata with the optional parameters below. Args: metadata (int): Metadata value to write. metadata_mask (int): Metadata write bitmask. """ super().__init__(InstructionType.OFPIT_WRITE_METADATA) self.metadata = metadata self.metadata_mask = metadata_mask
class AggregateStatsReply(GenericStruct): """Body of reply to OFPST_AGGREGATE request.""" packet_count = UBInt64() byte_count = UBInt64() flow_count = UBInt32() #: Align to 64 bits pad = Pad(4) def __init__(self, packet_count=None, byte_count=None, flow_count=None): """The constructor just assings parameters to object attributes. Args: packet_count (int): Number of packets in flows byte_count (int): Number of bytes in flows flow_count (int): Number of flows """ super().__init__() self.packet_count = packet_count self.byte_count = byte_count self.flow_count = flow_count
class QueueStats(GenericStruct): """Implements the reply body of a port_no.""" port_no = UBInt32() queue_id = UBInt32() tx_bytes = UBInt64() tx_packets = UBInt64() tx_errors = UBInt64() duration_sec = UBInt32() duration_nsec = UBInt32() def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None, duration_sec=None, duration_nsec=None): """Create a QueueStats with the optional parameters below. Args: port_no (:class:`int`, :class:`~pyof.v0x05.common.port.Port`): Port Number. queue_id (int): Queue ID. tx_bytes (int): Number of transmitted bytes. tx_packets (int): Number of transmitted packets. tx_errors (int): Number of packets dropped due to overrun. duration_sec (int): Time queue has been alive in seconds. duration_nsec (int): Time queue has been alive in nanoseconds beyond duration_sec. """ super().__init__() self.port_no = port_no self.queue_id = queue_id self.tx_bytes = tx_bytes self.tx_packets = tx_packets self.tx_errors = tx_errors self.duration_sec = duration_sec self.duration_nsec = duration_nsec
class PacketIn(GenericMessage): """Packet received on port (datapath -> controller).""" #: :class:`~.header.Header`: OpenFlow Header header = Header(message_type=Type.OFPT_PACKET_IN) #: ID assigned by datapath. buffer_id = UBInt32() #: Full length of frame. total_len = UBInt16() #: Reason packet is being sent (one of OFPR_*), reason = UBInt8(enum_ref=PacketInReason) #: ID of the table that was looked up. table_id = UBInt8() #: Cookie of the flow entry that was looked up. cookie = UBInt64() #: Packet metadata. Variable size. match = Match() #: Align to 64 bit + 16 bit pad = Pad(2) #: Ethernet frame whose length is inferred from header.length. #: The padding bytes preceding the Ethernet frame ensure that the IP #: header (if any) following the Ethernet header is 32-bit aligned. data = BinaryData() def __init__(self, xid=None, buffer_id=None, total_len=None, reason=None, table_id=None, cookie=None, match=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. reason (PacketInReason): The reason why the packet is being sent table_id (int): ID of the table that was looked up cookie (int): Cookie of the flow entry that was looked up match (:class:`~.common.flow_match.Match`): Packet metadata. Variable size. 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.reason = reason self.table_id = table_id self.cookie = cookie self.match = match self.data = data
class SwitchFeatures(GenericMessage): """Message sent by the switch device to the controller. This message is the response for a features_request message, sent by the controller to the switch device. The 'OFPT_FEATURES_REPLY' message inherits from this class, despite the strange name. """ header = Header(message_type=Type.OFPT_FEATURES_REPLY) datapath_id = UBInt64() n_buffers = UBInt32() n_tables = UBInt8() auxiliary_id = UBInt8() #: Align to 64-bits. pad = Pad(2) # Features capabilities = UBInt32(enum_ref=Capabilities) reserved = UBInt32() def __init__(self, xid=None, datapath_id=None, n_buffers=None, n_tables=None, auxiliary_id=None, capabilities=None, reserved=None): """The constructor just assings parameters to object attributes. Args: xid (int): xid to be used on the message header. datapath_id (int): Datapath unique ID. The lower 48-bits are for MAC address, while the upper 16-bits are implementer-defined. n_buffers (int): Max packets buffered at once. n_tables (int): Number of tables supported by datapath. auxiliary_id (int): Identify auxiliary connections. capabilities (int): bitmap of supported capabilities. reserved (int): Reserved. """ super().__init__(xid) self.datapath_id = datapath_id self.n_buffers = n_buffers self.n_tables = n_tables self.auxiliary_id = auxiliary_id self.capabilities = capabilities self.reserved = reserved
class FlowStatsRequest(GenericStruct): """Body for ofp_stats_request of type OFPST_FLOW.""" table_id = UBInt8() #: Align to 32 bits. pad = Pad(3) out_port = UBInt32() out_group = UBInt32() pad2 = Pad(4) cookie = UBInt64() cookie_mask = UBInt64() match = Match() def __init__(self, table_id=None, out_port=None, out_group=None, cookie=None, cookie_mask=None, match=None): """The constructor just assings parameters to object attributes. Args: table_id (int): ID of table to read (from pyof_table_stats) 0xff for all tables or 0xfe for emergency. out_port (:class:`int`, :class:`.Port`): Require matching entries to include this as an output port. A value of :attr:`.Port.OFPP_NONE` indicates no restriction. out_group: Require matching entries to include this as an output group. A value of OFPG_ANY indicates no restriction. cookie: Requires matching entries to contain this cookie value cookie_mask: Mask used to restrict the cookie bits that must match. A value of 0 indicates no restriction. match (Match): Fields to match. """ super().__init__() self.table_id = table_id self.out_port = out_port self.out_group = out_group self.cookie = cookie self.cookie_mask = cookie_mask self.match = match
class RoleRequest(RoleBaseMessage): """RoleRequest Message. When the controller wants to change its role, it uses the OFPT_ROLE_REQUEST message. """ header = Header(message_type=Type.OFPT_ROLE_REQUEST) role = UBInt32(enum_ref=ControllerRole) pad = Pad(4) generation_id = UBInt64() def __init__(self, xid=None, role=None, generation_id=None): """Create a RoleRequest with the optional parameters below. Args: xid (int): OpenFlow xid to the header. role (:class:`~.controller2switch.common.ControllerRole`): Is the new role that the controller wants to assume. generation_id (int): Master Election Generation Id. """ super().__init__(xid, role, generation_id)
class RoleStatusMsg(GenericMessage): """OpenFlow Controller Role Status Message OFPT_ROLE_REQUEST. """ #: Type OFPT_ROLE_STATUS header = Header(message_type=Type.OFPT_ROLE_STATUS) #: One of OFPCR_ROLE_* role = UBInt32(enum_ref=ControllerRole) #: One of OFPCRR_*. reason = UBInt8(enum_ref=RoleReason) #: Align to 64 bits pad = Pad(3) #: Master Election Generation Id generation_id = UBInt64() #: Role Property list properties = ListOfRoleProperties() def __init__(self, xid=None, role=ControllerRole, reason=RoleReason, generation_id=None, properties=None): """Create a message with the optional parameters below. Args: xid (int): xid to be used on the message header. role (int): the new role of the controller reason (int): one of RoleReason generation_id (int): the generation ID that was included in the role request message that triggered the role change properties: a list of role properties, describing dynamic parameters of table configuration """ super().__init__() self.header.xid = xid self.role = role self.reason = reason self.generation_id = generation_id self.properties = properties if properties else []
class FlowRemoved(GenericMessage): """Flow removed (datapath -> controller). If the controller has requested to be notified when flow entries time out or are deleted from tables, the datapath does this with the OFPT_FLOW_REMOVED message. """ #: :class:`~.header.Header`: OpenFlow Header header = Header(message_type=Type.OFPT_FLOW_REMOVED) #: Opaque controller-issued identifier. cookie = UBInt64() #: Priority level of flow entry. priority = UBInt16() #: One of OFPRR_*. reason = UBInt8(enum_ref=FlowRemovedReason) #: ID of the table table_id = UBInt8() #: Time flow was alive in seconds. duration_sec = UBInt32() #: Time flow was alive in nanoseconds beyond duration_sec. duration_nsec = UBInt32() #: Idle timeout from original flow mod. idle_timeout = UBInt16() #: Hard timeout from original flow mod. hard_timeout = UBInt16() packet_count = UBInt64() byte_count = UBInt64() #: Description of fields. Variable size. #: :class:`~.common.flow_match.Match` match = Match() def __init__(self, xid=None, cookie=None, priority=None, reason=None, table_id=None, duration_sec=None, duration_nsec=None, idle_timeout=None, hard_timeout=None, packet_count=None, byte_count=None, match=None): """Assign parameters to object attributes. Args: xid (int): OpenFlow Header's xid. cookie (int): Opaque controller-issued identifier. priority (int): Priority level of flow entry. reason (FlowRemovedReason): Why the flow was removed. table_id (int): ID of the table. duration_sec (int): Time the flow was alive in seconds. duration_nsec (int): Time the flow was alive in nanoseconds in addition to duration_sec. idle_timeout (int): Idle timeout from original flow mod. hard_timeout (int): Hard timeout from original flow mod. packet_count (int): Number of packets. byte_count (int): Byte count. match (Match): Fields' description. """ super().__init__(xid) self.cookie = cookie self.priority = priority self.reason = reason self.duration_sec = duration_sec self.duration_nsec = duration_nsec self.idle_timeout = idle_timeout self.hard_timeout = hard_timeout self.packet_count = packet_count self.byte_count = byte_count self.match = match
class TableFeatures(GenericStruct): """Abstraction of common class Table Features. Body for MultipartRequest of type OFPMP_TABLE_FEATURES. Body of reply to OFPMP_TABLE_FEATURES request. """ length = UBInt16() # /* Identifier of table. Lower numbered tables are consulted first. */ table_id = UBInt8() # /* Align to 64-bits. */ pad = Pad(5) name = Char(length=OFP_MAX_TABLE_NAME_LEN) # /* Bits of metadata table can match. */ metadata_match = UBInt64() # /* Bits of metadata table can write. */ metadata_write = UBInt64() # /* Bitmap of OFPTC_* values */ config = UBInt32() # /* Max number of entries supported. */ max_entries = UBInt32() # /* Table Feature Property list */ properties = ListOfProperty() def __init__(self, table_id=Table.OFPTT_ALL, name="", metadata_match=0xFFFFFFFFFFFFFFFF, metadata_write=0xFFFFFFFFFFFFFFFF, config=0, max_entries=0, properties=None): """Create a TableFeatures with the optional parameters below. Args: table_id(int): Indetifier of table.The default value OFPTT_ALL(``0xff``) will apply the configuration to all tables in the switch. name(Char): Characters representing the table name. metadata_match(int): Indicate the bits of the metadata field that the table can match on.The default value ``0xFFFFFFFFFFFFFFFF`` indicates that the table can match the full metadata field. metadata_write(int): Indicates the bits of the metadata field that the table can write using the OFPIT_WRITE_METADATA instruction. The default value ``0xFFFFFFFFFFFFFFFF`` indicates that the table can write the full metadata field. config(int): Field reseved for future use. max_entries(int): Describe the maximum number of flow entries that can be inserted into that table. properties(~pyof.v0x04.controller2switch.common.ListOfProperty): List of Property intances. """ super().__init__() self.table_id = table_id self.name = name self.metadata_match = metadata_match self.metadata_write = metadata_write self.config = config self.max_entries = max_entries self.properties = (ListOfProperty() if properties is None else properties) self.update_length() def pack(self, value=None): """Pack method used to update the length of instance and packing. Args: value: Structure to be packed. """ self.update_length() return super().pack(value) def update_length(self): """Update the length of current instance.""" self.length = self.get_size() def unpack(self, buff=None, offset=0): """Unpack *buff* into this object. This method will convert a binary data into a readable value according to the attribute format. Args: buff (bytes): Binary buffer. offset (int): Where to begin unpacking. Raises: :exc:`~.exceptions.UnpackException`: If unpack fails. """ length = UBInt16() length.unpack(buff, offset) super().unpack(buff[:offset+length.value], offset)
class FlowMod(GenericMessage): """Modifies the flow table from the controller.""" header = Header(message_type=Type.OFPT_FLOW_MOD) cookie = UBInt64() cookie_mask = UBInt64() # Flow actions table_id = UBInt8() command = UBInt8(enum_ref=FlowModCommand) idle_timeout = UBInt16() hard_timeout = UBInt16() priority = UBInt16() buffer_id = UBInt32() out_port = UBInt32() out_group = UBInt32() flags = UBInt16(enum_ref=FlowModFlags) pad = Pad(2) match = Match() def __init__(self, xid=None, cookie=None, cookie_mask=None, table_id=None, command=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, out_group=None, flags=None, match=None): """The constructor just assings parameters to object attributes. Args: xid (int): xid to be used on the message header. cookie (int): Opaque controller-issued identifier. cookie_mask (int): Mask used to restrict the cookie bits that must match when the command is OFPFC_MODIFY* or OFPFC_DELETE*. A value of 0 indicates no restriction. table_id (int): ID of the table to put the flow in. For OFPFC_DELETE_* commands, OFPTT_ALL can also be used to delete matching flows from all tables. command (FlowModCommand): One of OFPFC_*. idle_timeout (int): Idle time before discarding (seconds). hard_timeout (int): Max time before discarding (seconds). priority (int): Priority level of flow entry. buffer_id (int): Buffered packet to apply to, or OFP_NO_BUFFER. Not meaningful for OFPFC_DELETE*. out_port (int): For OFPFC_DELETE* commands, require matching entries to include this as an output port. A value of OFPP_ANY indicates no restriction. out_group (int): For OFPFC_DELETE* commands, require matching entries to include this as an output group. A value of OFPG_ANY indicates no restriction. flags (FlowModFlags): One of OFPFF_*. match (Match): Fields to match. Variable size. """ super().__init__(xid) self.cookie = cookie self.cookie_mask = cookie_mask self.table_id = table_id self.command = command self.idle_timeout = idle_timeout self.hard_timeout = hard_timeout self.priority = priority self.buffer_id = buffer_id self.out_port = out_port self.out_group = out_group self.flags = flags self.match = match