Exemplo n.º 1
0
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 unique ID. The lower 48-bits are for a MAC address, while the upper 16-bits are
    #: implemented-defined.
    datapath_id = DPID()

    #: Max packets buffered at once.
    n_buffers = UBInt32()

    #: Number of tables supported by datapath.
    n_tables = UBInt8()

    #: Identify auxiliary connections
    auxiliary_id = UBInt8()

    #: Align to 64-bits.
    pad = Pad(2)

    # Features
    #: Bitmap of support "ofp_capabilities"
    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):
        """Create a SwitchFeatures with the optional parameters below.

        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
Exemplo n.º 2
0
class MeterFeatures(GenericStruct):
    """Body of reply to OFPMP_METER_FEATURES request. Meter features."""

    max_meter = UBInt32()
    band_types = UBInt32(enum_ref=MeterBandType)
    capabilities = UBInt32(enum_ref=MeterFlags)
    max_bands = UBInt8()
    max_color = UBInt8()
    pad = Pad(2)

    def __init__(self,
                 max_meter=None,
                 band_types=None,
                 capabilities=None,
                 max_bands=None,
                 max_color=None):
        """Create a MeterFeatures with the optional parameters below.

        Args:
            max_meter(int): Maximum number of meters.
            band_types (|MeterBandType_v0x05|):
                Bitmaps of OFPMBT_* values supported.
            capabilities (|MeterFlags_v0x05|): Bitmaps of "ofp_meter_flags".
            max_bands(int): Maximum bands per meters
            max_color(int): Maximum color value
        """
        super().__init__()
        self.max_meter = max_meter
        self.band_types = band_types
        self.capabilities = capabilities
        self.max_bands = max_bands
        self.max_color = max_color
Exemplo n.º 3
0
class Header(GenericStruct):
    """Representation of an OpenFlow message Header."""

    version = UBInt8(OFP_VERSION)
    message_type = UBInt8(enum_ref=Type)
    length = UBInt16()
    xid = UBInt32()

    def __init__(self, message_type=None, length=None, xid=None):
        """Create a Header with the optional parameters below.

        Args:
            message_type (~pyof.v0x01.common.header.Type): Type of the message.
            xid (int): ID of the message. Defaults to a random integer.
            length (int): Length of the message, including the header itself.
        """
        super().__init__()
        self.message_type = message_type
        self.length = length
        self.xid = xid

    def __str__(self):
        """Get just the header type. Eg.: 'OFPT_SET_CONFIG'."""
        return self.message_type.name

    def __repr__(self):
        """Show a full representation of the Header, including version."""
        return "%s(message_type=%s, length=%r, xid=%r, version=%r)" \
            % (self.__class__.__name__, self.message_type, self.length,
               self.xid, self.version)
Exemplo n.º 4
0
class Header(GenericStruct):
    """Representation of an OpenFlow message Header."""

    version = UBInt8(OFP_VERSION)
    message_type = UBInt8(enum_ref=Type)
    length = UBInt16()
    xid = UBInt32()

    def __init__(self, message_type=None, length=None, xid=None):
        """Create a Header with the optional parameters below.

        Args:
            message_type (~pyof.v0x04.common.header.Type):
                One of the OFPT_* constants.
            length (int): Length including this ofp_header.
            xid (int): Transaction id associated with this packet. Replies use
                the same id as was in the request to facilitate pairing.
        """
        super().__init__()
        self.message_type = message_type
        self.length = length
        self.xid = xid

    def __repr__(self):
        return (f"{type(self).__name__}(version={self.version}, "
                f"xid={self.xid}, {self.message_type!s})")
Exemplo n.º 5
0
        class MyClassA(GenericStruct):
            """Example class."""

            a1 = UBInt8(1)
            a2 = UBInt16(2)
            a3 = UBInt8(3)
            a4 = UBInt16(4)
            a5 = UBInt32(5)
Exemplo n.º 6
0
class FlowMonitorRequest(GenericStruct):
    """
    Body for ofp_multipart_request of type OFPMP_FLOW_MONITOR.

     The OFPMP_FLOW_MONITOR request’s body consists of an array of zero or more
     instances of this structure. The request arranges to monitor the flows
     that match the specified criteria, which are interpreted in the same way as
     for OFPMP_FLOW.

    ’id’ identifies a particular monitor for the purpose of allowing it to be
     canceled later with OFPFMC_DELETE. ’id’ must be unique among
     existing monitors that have not already been canceled.

    """
    #: Controller-assigned ID for this monitor
    monitor_id = UBInt32()
    #: Required output port, if not OFPP_ANY
    out_port = UBInt32(enum_ref=PortNo)
    #: Required group number, if not OFPG_ANY
    out_group = UBInt32(enum_ref=Group)
    #: OFPFMF_*
    flags = UBInt16(enum_ref=FlowMonitorFlags)
    #: One table’s ID or OFPTT_ALL (all tables)
    table_id = UBInt8(enum_ref=Table)
    #: One of OFPFMC_*
    command = UBInt8(enum_ref=FlowMonitorCommand)
    #: Fields to match. Variable size
    match = Match()

    def __init__(self, monitor_id=None, out_port=PortNo.OFPP_ANY, out_group=Group.OFPG_ANY, flags=FlowMonitorFlags,
                 table_id=Table.OFPTT_ALL,
                 command=FlowMonitorCommand, match=None):
        """
        Create a FlowStatsRequest with the optional parameters below.

        Args:
            monitor_id (int): uniquely identifies a monitor for a specific controller connection within a switch
            (from pyof_table_stats)
                0xff for all tables or 0xfe for emergency.
            out_port (:class:`int`, :class:`~pyof.v0x05.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.
            table_id (int): ID of table to read (from pyof_table_stats)
                0xff for all tables or 0xfe for emergency.
            command: defines what operation must be done on that monitor
            match (~pyof.v0x05.common.flow_match.Match): Fields to match.
        """
        super().__init__()
        self.monitor_id = monitor_id
        self.out_port = out_port
        self.out_group = out_group
        self.flags = flags
        self.table_id = table_id
        self.command = command
        self.match = Match() if match is None else match
Exemplo n.º 7
0
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
Exemplo n.º 8
0
class Match(GenericStruct):
    """Describes the flow match header structure.

    These are the fields to match against flows.

    The :attr:`~match_type` field is set to :attr:`~MatchType.OFPMT_OXM` and
    :attr:`length` field is set to the actual length of match structure
    including all match fields. The payload of the OpenFlow match is a set of
    OXM Flow match fields.
    """

    #: One of OFPMT_*
    match_type = UBInt16(enum_ref=MatchType)
    #: Length of Match (excluding padding)
    length = UBInt16()
    #: Followed by:
    #:     - Exactly (length - 4) (possibly 0) bytes containing OXM TLVs, then
    #:     - Exactly ((length + 7)/8*8 - length) (between 0 and 7) bytes of
    #:         all-zero bytes
    #: In summary, ofp_match is padded as needed, to make its overall size a
    #: multiple of 8, to preserve alignement in structures using it.
    oxm_field1 = UBInt8(enum_ref=OxmOfbMatchField)
    oxm_field2 = UBInt8(enum_ref=OxmOfbMatchField)
    oxm_field3 = UBInt8(enum_ref=OxmOfbMatchField)
    oxm_field4 = UBInt8(enum_ref=OxmOfbMatchField)

    def __init__(self,
                 match_type=None,
                 length=None,
                 oxm_field1=None,
                 oxm_field2=None,
                 oxm_field3=None,
                 oxm_field4=None):
        """Describe the flow match header structure.

        Args:
            - match_type (MatchType): One of OFPMT_* (MatchType) items.
            - length (int): Length of Match (excluding padding).
            - oxm_field1 (:class:`~OXMClass`): .
            - oxm_field2 (:class:`~OXMClass`): .
            - oxm_field3 (:class:`~OXMClass`): .
            - oxm_field4 (:class:`~OXMClass`): .
        """
        super().__init__()
        self.match_type = match_type
        self.length = length
        self.oxm_field1 = oxm_field1
        self.oxm_field2 = oxm_field2
        self.oxm_field3 = oxm_field3
        self.oxm_field4 = oxm_field4
Exemplo n.º 9
0
class TableMod(GenericMessage):
    """Configure/Modify behavior of a flow table."""

    #: class:`~pyof.v0x05.common.action.ActionHeader`: OpenFlow Header
    header = Header(message_type=Type.OFPT_TABLE_MOD)
    #: ID of the table, OFPTT_ALL indicates all tables
    table_id = UBInt8()
    #: Pad to 32 bits
    pad = Pad(3)
    #: Bitmap of OFPTC_* flags
    config = UBInt32()
    #: Table Mod Property list
    properties = FixedTypeList(TableModPropHeader)

    def __init__(self, xid=None, table_id=Table.OFPTT_ALL, config=3, properties=None):
        """Assing parameters to object attributes.

        Args:
            xid (int): :class:`~pyof.v0x05.common.header.Header`'s xid.
                Defaults to random.
            table_id (int): ID of the table, OFPTT_ALL indicates all tables.
            config (int): Bitmap of OFPTC_* flags
        """

        super().__init__(xid)
        self.table_id = table_id
        # This is reserved for future used. The default value is the only valid
        # one from the Enum.
        self.config = config
        self.properties = properties
Exemplo n.º 10
0
class TableStatus(GenericMessage):
    """OpenFlow TableStatus Message OFPT_TABLE_STATUS.
      A table config has changed in the datapath.
     """

    #: :class:`~pyof.v0x05.common.action.ActionHeader`: OpenFlow Header
    header = Header(message_type=Type.OFPT_TABLE_STATUS)
    #: One of OFPTR_.*
    reason = UBInt8(enum_ref=TableReason)
    #: Pad to 64 bits
    pad = Pad(7)
    #: New table config
    table = TableDesc()

    def __init__(self, xid=None, reason=None, table=None):
        """Create a message with the optional parameters below.

        Args:
            xid (int): xid to be used on the message header.
            reason (int): One of OFPTR_*
            table (TableDesc): New table config.
        """
        super().__init__(xid)
        self.reason = reason
        self.table = table
Exemplo n.º 11
0
    def test_error_experimenter_message(self):
        """
        Testing the Experimenter Message.
        This function will test all code values for this enum class.
        :return: None
        """
        MAX_VALUE = 5
        # Max number of IDs to be created in the test
        MAX_NUM_ID = 20

        type = 0xffff

        for id in range(0, MAX_NUM_ID):

            # Generate a random int number between 2 and 250
            exp_code = random.randint(2, 250)

            # Generate a random int number between 2 and 120 and then convert it in binary
            data = UBInt8(random.randint(2, 120)).pack()

            # Generate a random int number between 2 and 250
            xid = random.randint(2, 250)

            test_value = b'\x05\x01\x00\x11' + UBInt32(xid).pack() + UBInt16(type).pack() + \
                        UBInt16(exp_code).pack() + UBInt32(id).pack() + data

            self.test_error_experimenter_message.__init__(
                xid, exp_code, id, data)

            test_object_error_messages = self.test_error_experimenter_message.pack(
            )

            self.assertEqual(test_value, test_object_error_messages)
Exemplo n.º 12
0
class MeterBandDscpRemark(GenericStruct):
    """OFPMBT_DSCP_REMARK band - Remark DSCP in the IP header."""

    band_type = UBInt16(MeterBandType.OFPMBT_DSCP_REMARK,
                        enum_ref=MeterBandType)
    length = UBInt16()
    rate = UBInt32()
    burst_size = UBInt32()
    prec_level = UBInt8()
    pad = Pad(3)

    def __init__(self,
                 length=None,
                 rate=None,
                 burst_size=None,
                 prec_level=None):
        """Instance attributes assignment.

        Args:
            length (int): Length in bytes of this band.
            rate (int): Rate for remarking packets.
            burst_size (int): Size of bursts.
            prec_level (int): Number of precendence level to substract.
        """
        super().__init__()
        self.length = length
        self.rate = rate
        self.burst_size = burst_size
        self.prec_level = prec_level
Exemplo n.º 13
0
class GroupDescStats(GenericStruct):
    """Body of reply to OFPMP_GROUP_DESC request."""

    length = UBInt16()
    group_type = UBInt8()
    #: Pad to 64 bits.
    pad = Pad(1)
    group_id = UBInt32()
    buckets = FixedTypeList(Bucket)

    def __init__(self,
                 length=None,
                 group_type=None,
                 group_id=None,
                 buckets=None):
        """Create a GroupDescStats with the optional parameters below.

        Args:
            length (int): Length of this entry.
            group_type (|GroupType_v0x05|): One of OFPGT_*.
            group_id (int): Group identifier.
            buckets (|ListOfBuckets_v0x05|): List of buckets in group.
        """
        super().__init__()
        self.length = length
        self.group_type = group_type
        self.group_id = group_id
        self.buckets = buckets
Exemplo n.º 14
0
class TableDesc(GenericStruct):
    """Body of reply to OFPMP_TABLE_DESC request."""

    length = UBInt16()
    table_id = UBInt8()
    pad = Pad(1)
    config = UBInt32()
    properties = ListOfTableModProperties()

    def __init__(self,
                 length=None,
                 table_id=None,
                 config=None,
                 properties=None):
        """Body of reply to OFPMP_TABLE_DESC request

            Args:
                length(int): Length is padded to 64 bits.
                table_id(int): Identifier of table. lowe numbered tables
                config(int): Bitmap of OFPTC_* values.
                properties(TableModPropHeader list): Table Mod Property list - 0 or more.
        """
        super().__init__()
        self.length = length
        self.table_id = table_id
        self.config = config
        self.properties = properties if properties else []
Exemplo n.º 15
0
class ActionNWTos(ActionHeader):
    """Action structure for :attr:`ActionType.OFPAT_SET_NW_TOS`.

    .. note:: The nw_tos field is the 6 upper bits of the ToS field to set,
              in the original bit positions (shifted to the left by 2).
    """

    nw_tos_type = UBInt16(enum_ref=ActionType)
    length = UBInt16(8)
    nw_tos = UBInt8()
    #: Pad for bit alignment.
    pad = Pad(3)

    def __init__(self, nw_tos_type=None, nw_tos=None):
        """The following constructor parameters are optional.

        Args:
            nw_tos_type (ActionType): :attr:`~ActionType.OFPAT_SET_NW_SRC` or
                :attr:`~ActionType.OFPAT_SET_NW_DST`.
            nw_tos (int): IP ToS (DSCP field, 6 bits).
        """
        super().__init__()
        self.nw_tos_type = nw_tos_type
        self.nw_tos = nw_tos

    def allowed_types():
       """Return the Allowed Action Type

       Returns:
           action_types (list): list of allowed types
       """
       return [ActionType.OFPAT_SET_NW_TOS]
Exemplo n.º 16
0
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
Exemplo n.º 17
0
class ActionVlanPCP(ActionHeader):
    """Action structure for :attr:`ActionType.OFPAT_SET_VLAN_PCP`."""

    action_type = UBInt16(ActionType.OFPAT_SET_VLAN_PCP, enum_ref=ActionType)
    length = UBInt16(8)
    vlan_pcp = UBInt8()
    #: Pad for bit alignment.
    pad = Pad(3)

    def __init__(self, vlan_pcp=None):
        """The following constructor parameters are optional.

        Args:
            vlan_pcp (int): VLAN Priority.

        .. note:: The vlan_pcp field is 8 bits long,
                  but only the lower 3 bits have meaning.
        """
        super().__init__()
        self.vlan_pcp = vlan_pcp

    def allowed_types():
       """Return the Allowed Action Type

       Returns:
           action_types (list): list of allowed types
       """
       return [ActionType.OFPAT_SET_VLAN_PCP]
Exemplo n.º 18
0
class GroupMod(GenericMessage):
    """Group setup and teardown (controller -> datapath)."""

    header = Header(message_type=Type.OFPT_GROUP_MOD)
    command = UBInt16(enum_ref=GroupModCommand)
    group_type = UBInt8()
    #: Pad to 64 bits.
    pad = Pad(1)
    group_id = UBInt32()
    buckets = ListOfBuckets()

    def __init__(self,
                 xid=None,
                 command=None,
                 group_type=None,
                 group_id=None,
                 buckets=None):
        """Create a GroupMod with the optional parameters below.

        Args:
            xid (int): Header's transaction id. Defaults to random.
            command (GroupModCommand): One of OFPGC_*.
            group_type (GroupType): One of OFPGT_*.
            group_id (int): Group identifier.
            buckets (:class:`ListOfBuckets`): The length of the bucket
                array is inferred from the length field in the header.
        """
        super().__init__(xid)
        self.command = command
        self.group_type = group_type
        self.group_id = group_id
        self.buckets = buckets
Exemplo n.º 19
0
class FlowStatsRequest(GenericStruct):
    """Body for ofp_stats_request of type OFPST_FLOW."""

    match = Match()
    table_id = UBInt8()
    #: Align to 32 bits.
    pad = Pad(1)
    out_port = UBInt16()

    def __init__(self, match=None, table_id=0xff, out_port=Port.OFPP_NONE):
        """Create a FlowStatsRequest with the optional parameters below.

        Args:
            match (:class:`~pyof.v0x01.common.flow_match.Match`):
                Fields to match.
            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.v0x01.common.phy_port.Port`):
                Require matching entries to include this as an output port.
                A value of :attr:`.Port.OFPP_NONE` indicates no restriction.
        """
        super().__init__()
        self.match = Match() if match is None else match
        self.table_id = table_id
        self.out_port = out_port
Exemplo n.º 20
0
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
Exemplo n.º 21
0
        class MyClassB(MyClassA):
            """Example class."""

            a0 = UBInt32(0)
            a2 = UBInt64(2)
            b6 = UBInt8(6)

            _removed_attributes = ['a3']
Exemplo n.º 22
0
 def unpack(self, buffer, offset=0):
     header = UBInt16()
     header.unpack(buffer[offset:offset+2])
     self.type = header.value >> 9
     length = header.value & 511 
     begin, end = offset + 2, offset + 2 + length
     sub_type = UBInt8()
     sub_type.unpack(buffer[begin:begin+1])
     self.sub_type = sub_type.value
     self.sub_value = BinaryData(buffer[begin+1:end])
Exemplo n.º 23
0
    def value(self):
        """Return sub type and sub value as binary data.

        Returns:
            :class:`~pyof.foundation.basic_types.BinaryData`:
                BinaryData calculated.

        """
        binary = UBInt8(self.sub_type).pack() + self.sub_value.pack()
        return BinaryData(binary)
Exemplo n.º 24
0
class Header(GenericStruct):
    """Representation of an OpenFlow message Header."""

    version = UBInt8(OFP_VERSION)
    message_type = UBInt8(enum_ref=Type)
    length = UBInt16()
    xid = UBInt32()

    def __init__(self, message_type=None, length=None, xid=None):
        """Create a Header with the optional parameters below.

        Args:
            message_type (~pyof.v0x01.common.header.Type): Type of the message.
            xid (int): ID of the message. Defaults to a random integer.
            length (int): Length of the message, including the header itself.
        """
        super().__init__()
        self.message_type = message_type
        self.length = length
        self.xid = xid
Exemplo n.º 25
0
class Header(GenericStruct):
    """Representation of an OpenFlow message Header."""

    version = UBInt8(OFP_VERSION)
    message_type = UBInt8(enum_ref=Type)
    length = UBInt16()
    xid = UBInt32()

    def __init__(self, message_type=None, length=None, xid=randint(0, MAXID)):
        """The constructor takes the optional parameters below.

        Args:
            message_type (Type): Type of the message.
            xid (int): ID of the message. Defaults to a random integer.
            length (int): Length of the message, including the header itself.
        """
        super().__init__()
        self.message_type = message_type
        self.length = length
        self.xid = xid
Exemplo n.º 26
0
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
Exemplo n.º 27
0
    def setUp(self):
        """

        :return: None
        """
        self.type = UBInt8(3)
        self.length = UBInt16(6)
        self.xid = UBInt32(23)
        self.data = BinaryData(b'001100111101')
        self.test_object = EchoRequest()
        self.test_object.header.__init__(self.type,self.length,self.xid)
        self.test_object1 = EchoRequest(23, b'001100111101')
Exemplo n.º 28
0
class Header(GenericStruct):
    """Representation of an OpenFlow message Header."""

    version = UBInt8(OFP_VERSION)
    message_type = UBInt8(enum_ref=Type)
    length = UBInt16()
    xid = UBInt32()

    def __init__(self, message_type=None, length=None, xid=randint(0, MAXID)):
        """The constructor takes the optional parameters below.

        Args:
            message_type (Type): One of the OFPT_ constants.
            length (int): Length including this ofp_header.
            xid (int): Transaction id associated with this packet. Replies use
                the same id as was in the request to facilitate pairing.
        """
        super().__init__()
        self.message_type = message_type
        self.length = length
        self.xid = xid
Exemplo n.º 29
0
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
Exemplo n.º 30
0
class ActionSetField(GenericStruct):
    """Action structure for OFPAT_SET_FIELD."""

    #: OFPAT_SET_FIELD.
    action_type = UBInt16(ActionType.OFPAT_SET_FIELD, enum_ref=ActionType)
    #: Length is padded to 64 bits.
    length = UBInt16()
    #: Followed by:
    #:     - Exactly oxm_len bytes containing a single OXM TLV, then
    #:     - Exactly ((oxm_len + 4) + 7)/8*8 - (oxm_len + 4) (between 0 and 7)
    #:       bytes of all-zero bytes

    #: OXM TLV - Make compiler happy
    field1 = UBInt8()
    field2 = UBInt8()
    field3 = UBInt8()
    field4 = UBInt8()

    def __init__(self,
                 length=None,
                 field1=None,
                 field2=None,
                 field3=None,
                 field4=None):
        """Action structure for OFPAT_SET_FIELD.

        Args:
            length (int): length padded to 64 bits.
            field1 (int): OXM field.
            field2 (int): OXM field.
            field3 (int): OXM field.
            field4 (int): OXM field.
        """
        super().__init__()
        self.length = length
        self.field1 = field1
        self.field2 = field2
        self.field3 = field3
        self.field4 = field4