org.openflow.protocol
Class OFMatch

java.lang.Object
  extended by org.openflow.protocol.OFMatch
All Implemented Interfaces:
java.lang.Cloneable

public class OFMatch
extends java.lang.Object
implements java.lang.Cloneable

Represents an ofp_match structure

Author:
Srini Seetharaman (srini.seetharaman@gmail.com)

Nested Class Summary
static class OFMatch.OFMatchClass
           
 
Field Summary
static short ETH_TYPE_ARP
           
static short ETH_TYPE_IPV4
           
static short ETH_TYPE_IPV6
           
static short ETH_TYPE_LLDP
           
static short ETH_TYPE_MPLS_MULTICAST
           
static short ETH_TYPE_MPLS_UNICAST
           
static short ETH_TYPE_VLAN
           
static byte IP_PROTO_ICMP
           
static byte IP_PROTO_SCTP
           
static byte IP_PROTO_TCP
           
static byte IP_PROTO_UDP
           
protected  short length
           
protected  java.util.List<OFMatchField> matchFields
           
protected  short matchLength
           
static int MINIMUM_LENGTH
           
protected  org.openflow.protocol.OFMatch.OFMatchType type
           
 
Constructor Summary
OFMatch()
          By default, create a OFMatch that matches everything (mostly because it's the least amount of work to make a valid OFMatch)
 
Method Summary
 OFMatch clone()
           
 boolean equals(java.lang.Object obj)
           
 boolean fieldExists(OFOXMFieldType matchType)
          Check if a particular match field exists
static OFMatch fromString(java.lang.String match)
          Set this OFMatch's parameters based on a comma-separated key=value pair dpctl-style string, e.g., from the output of OFMatch.toString()
 byte[] getDataLayerDestination()
          Get dl_dst
 byte[] getDataLayerSource()
          Get dl_src
 short getDataLayerType()
          Get dl_type
 short getDataLayerVirtualLan()
          Get dl_vlan
 byte getDataLayerVirtualLanPriorityCodePoint()
          Get dl_vlan_pcp
 int getInPort()
          Get in_port
 short getLength()
          Get the length of this message
 int getLengthU()
          Get the length of this message, unsigned
 java.lang.Object getMatchFieldMask(OFOXMFieldType matchType)
          Get mask of particular field
 java.util.List<OFMatchField> getMatchFields()
          Returns read-only copies of the matchfields contained in this OFMatch
 java.lang.Object getMatchFieldValue(OFOXMFieldType matchType)
          Get value of particular field
 short getMatchLength()
           
 int getNetworkDestination()
          Get nw_dst
 int getNetworkDestinationMask()
          Get nw_dst mask
 byte getNetworkProtocol()
          Get nw_proto
 int getNetworkSource()
          Get nw_src
 int getNetworkSourceMask()
          Get nw_src mask
 byte getNetworkTypeOfService()
          Get nw_tos OFMatch stores the ToS bits as 6-bits in the lower significant bits
 short getTransportDestination()
          Get tp_dst
 short getTransportSource()
          Get tp_src
 org.openflow.protocol.OFMatch.OFMatchType getType()
           
 int hashCode()
           
static OFMatch load(byte[] packetData, int inPort)
          Load and return a new OFMatch based on supplied packetData, see #loadFromPacket(byte[], short) for details.
 OFMatch loadFromPacket(byte[] packetData, int inPort)
          Initializes this OFMatch structure with the corresponding data from the specified packet.
 void readFrom(java.nio.ByteBuffer data)
           
 OFMatch setDataLayerDestination(byte[] dataLayerDestination)
          Set dl_dst
 OFMatch setDataLayerDestination(java.lang.String mac)
          Set dl_dst, but first translate to byte[] using HexString
 OFMatch setDataLayerSource(byte[] dataLayerSource)
          Set dl_src
 OFMatch setDataLayerSource(java.lang.String mac)
          Set dl_src, but first translate to byte[] using HexString
 OFMatch setDataLayerType(short dataLayerType)
          Set dl_type
 OFMatch setDataLayerVirtualLan(short vlan)
          Set dl_vlan
 OFMatch setDataLayerVirtualLanPriorityCodePoint(byte pcp)
          Set dl_vlan_pcp
 void setField(OFMatchField newMatchField)
          Sets match field.
 void setField(OFOXMFieldType matchFieldType, java.lang.Object matchFieldValue)
           
 void setField(OFOXMFieldType matchFieldType, java.lang.Object matchFieldValue, java.lang.Object matchFieldMask)
           
 OFMatch setInPort(int inPort)
          Set in_port in match
 OFMatch setMatchFields(java.util.List<OFMatchField> matchFields)
          Sets the list of matchfields this OFMatch contains
 OFMatch setNetworkDestination(int networkDestination)
          Set nw_dst
 OFMatch setNetworkDestination(short dataLayerType, int networkDestination)
          Set nw_dst
 OFMatch setNetworkDestinationMask(int networkDestination, int networkMask)
          Set nw_dst and nw_dst_mask
 OFMatch setNetworkDestinationMask(short dataLayerType, int networkDestination, int networkMask)
          Set nw_dst and nw_dst_mask
 OFMatch setNetworkProtocol(byte networkProtocol)
          Set nw_proto
 OFMatch setNetworkSource(int networkSource)
          Set nw_src
 OFMatch setNetworkSource(short dataLayerType, int networkSource)
          Set nw_src
 OFMatch setNetworkSourceMask(int networkSource, int networkMask)
          Set nw_src and nw_src_mask
 OFMatch setNetworkSourceMask(short dataLayerType, int networkSource, int networkMask)
          Set nw_src and nw_src_mask
 OFMatch setNetworkTypeOfService(byte networkTypeOfService)
          Set nw_tos OFMatch stores the DSCP and ECN separately
 OFMatch setNonWildcards(java.util.Set<OFOXMFieldType> nonWildcardedFieldTypes)
          Utility function to wildcard all fields except those specified in the set
 OFMatch setTransportDestination(byte networkProtocol, short transportDestination)
          Set tp_dst
 OFMatch setTransportDestination(short transportDestination)
          Set tp_dst
 OFMatch setTransportSource(byte networkProtocol, short transportSource)
          Set tp_src
 OFMatch setTransportSource(short transportSource)
          Set tp_src
 java.lang.String toString()
           
 void writeTo(java.nio.ByteBuffer data)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MINIMUM_LENGTH

public static int MINIMUM_LENGTH

ETH_TYPE_IPV4

public static final short ETH_TYPE_IPV4
See Also:
Constant Field Values

ETH_TYPE_IPV6

public static final short ETH_TYPE_IPV6
See Also:
Constant Field Values

ETH_TYPE_ARP

public static final short ETH_TYPE_ARP
See Also:
Constant Field Values

ETH_TYPE_VLAN

public static final short ETH_TYPE_VLAN
See Also:
Constant Field Values

ETH_TYPE_LLDP

public static final short ETH_TYPE_LLDP
See Also:
Constant Field Values

ETH_TYPE_MPLS_UNICAST

public static final short ETH_TYPE_MPLS_UNICAST
See Also:
Constant Field Values

ETH_TYPE_MPLS_MULTICAST

public static final short ETH_TYPE_MPLS_MULTICAST
See Also:
Constant Field Values

IP_PROTO_ICMP

public static final byte IP_PROTO_ICMP
See Also:
Constant Field Values

IP_PROTO_TCP

public static final byte IP_PROTO_TCP
See Also:
Constant Field Values

IP_PROTO_UDP

public static final byte IP_PROTO_UDP
See Also:
Constant Field Values

IP_PROTO_SCTP

public static final byte IP_PROTO_SCTP
See Also:
Constant Field Values

type

protected org.openflow.protocol.OFMatch.OFMatchType type

length

protected short length

matchLength

protected short matchLength

matchFields

protected java.util.List<OFMatchField> matchFields
Constructor Detail

OFMatch

public OFMatch()
By default, create a OFMatch that matches everything (mostly because it's the least amount of work to make a valid OFMatch)

Method Detail

getMatchFieldValue

public java.lang.Object getMatchFieldValue(OFOXMFieldType matchType)
Get value of particular field

Returns:

getMatchFieldMask

public java.lang.Object getMatchFieldMask(OFOXMFieldType matchType)
Get mask of particular field

Returns:

fieldExists

public boolean fieldExists(OFOXMFieldType matchType)
Check if a particular match field exists

Returns:
boolean indicating if the field value exists

getInPort

public int getInPort()
Get in_port

Returns:
integer

setInPort

public OFMatch setInPort(int inPort)
Set in_port in match

Parameters:
in_port -

getDataLayerDestination

public byte[] getDataLayerDestination()
Get dl_dst

Returns:
an arrays of bytes

setDataLayerDestination

public OFMatch setDataLayerDestination(byte[] dataLayerDestination)
Set dl_dst

Parameters:
dataLayerDestination -

setDataLayerDestination

public OFMatch setDataLayerDestination(java.lang.String mac)
Set dl_dst, but first translate to byte[] using HexString

Parameters:
mac - A colon separated string of 6 pairs of octets, e..g., "00:17:42:EF:CD:8D"

getDataLayerSource

public byte[] getDataLayerSource()
Get dl_src

Returns:
an array of bytes

setDataLayerSource

public OFMatch setDataLayerSource(byte[] dataLayerSource)
Set dl_src

Parameters:
dataLayerSource -

setDataLayerSource

public OFMatch setDataLayerSource(java.lang.String mac)
Set dl_src, but first translate to byte[] using HexString

Parameters:
mac - A colon separated string of 6 pairs of octets, e..g., "00:17:42:EF:CD:8D"

getDataLayerType

public short getDataLayerType()
Get dl_type

Returns:
ether_type

setDataLayerType

public OFMatch setDataLayerType(short dataLayerType)
Set dl_type

Parameters:
dataLayerType -

getDataLayerVirtualLan

public short getDataLayerVirtualLan()
Get dl_vlan

Returns:
vlan tag without the VLAN present bit set

setDataLayerVirtualLan

public OFMatch setDataLayerVirtualLan(short vlan)
Set dl_vlan

Parameters:
dataLayerVirtualLan - VLAN ID without the VLAN present bit set

getDataLayerVirtualLanPriorityCodePoint

public byte getDataLayerVirtualLanPriorityCodePoint()
Get dl_vlan_pcp

Returns:
VLAN PCP value

setDataLayerVirtualLanPriorityCodePoint

public OFMatch setDataLayerVirtualLanPriorityCodePoint(byte pcp)
Set dl_vlan_pcp

Parameters:
pcp -

getNetworkProtocol

public byte getNetworkProtocol()
Get nw_proto

Returns:

setNetworkProtocol

public OFMatch setNetworkProtocol(byte networkProtocol)
Set nw_proto

Parameters:
networkProtocol -

getNetworkTypeOfService

public byte getNetworkTypeOfService()
Get nw_tos OFMatch stores the ToS bits as 6-bits in the lower significant bits

Returns:
: 6-bit DSCP value (0-63) in higher bits and 2-bit ECN in lower bits

setNetworkTypeOfService

public OFMatch setNetworkTypeOfService(byte networkTypeOfService)
Set nw_tos OFMatch stores the DSCP and ECN separately

Parameters:
networkTypeOfService - TOS value with 6-bit DSCP value (0-63) in higher significant bits and ECN in the lower 2 bits

getNetworkDestination

public int getNetworkDestination()
Get nw_dst

Returns:
integer destination IP address

getNetworkDestinationMask

public int getNetworkDestinationMask()
Get nw_dst mask

Returns:
integer destination IP address mask

setNetworkDestination

public OFMatch setNetworkDestination(int networkDestination)
Set nw_dst

Parameters:
networkDestination - destination IP address

setNetworkDestination

public OFMatch setNetworkDestination(short dataLayerType,
                                     int networkDestination)
Set nw_dst

Parameters:
dataLayerType - ether type
networkDestination - destination IP address

setNetworkDestinationMask

public OFMatch setNetworkDestinationMask(int networkDestination,
                                         int networkMask)
Set nw_dst and nw_dst_mask

Parameters:
networkDestination - destination IP address
networkMask - network mask

setNetworkDestinationMask

public OFMatch setNetworkDestinationMask(short dataLayerType,
                                         int networkDestination,
                                         int networkMask)
Set nw_dst and nw_dst_mask

Parameters:
dataLayerType - ether type
networkDestination - destination IP address
networkMask - network mask

getNetworkSource

public int getNetworkSource()
Get nw_src

Returns:
integer source IP address

getNetworkSourceMask

public int getNetworkSourceMask()
Get nw_src mask

Returns:
integer source IP address mask

setNetworkSource

public OFMatch setNetworkSource(int networkSource)
Set nw_src

Parameters:
networkSource - source IP address

setNetworkSource

public OFMatch setNetworkSource(short dataLayerType,
                                int networkSource)
Set nw_src

Parameters:
dataLayerType - ether type
networkSource - source IP address

setNetworkSourceMask

public OFMatch setNetworkSourceMask(int networkSource,
                                    int networkMask)
Set nw_src and nw_src_mask

Parameters:
networkSource - source IP address
networkMask - network mask

setNetworkSourceMask

public OFMatch setNetworkSourceMask(short dataLayerType,
                                    int networkSource,
                                    int networkMask)
Set nw_src and nw_src_mask

Parameters:
dataLayerType - ether type
networkSource - source IP address
networkMask - network mask

getTransportDestination

public short getTransportDestination()
Get tp_dst

Returns:
destination port number

setTransportDestination

public OFMatch setTransportDestination(short transportDestination)
Set tp_dst

Parameters:
transportDestination - TCP destination port number

setTransportDestination

public OFMatch setTransportDestination(byte networkProtocol,
                                       short transportDestination)
Set tp_dst

Parameters:
networkProtocol - IP protocol
transportDestination - Destination Transport port number

getTransportSource

public short getTransportSource()
Get tp_src

Returns:
transportSource Source Transport port number

setTransportSource

public OFMatch setTransportSource(short transportSource)
Set tp_src

Parameters:
transportSource - TCP source port number

setTransportSource

public OFMatch setTransportSource(byte networkProtocol,
                                  short transportSource)
Set tp_src

Parameters:
networkProtocol - IP protocol
transportSource - Source Transport port number

getType

public org.openflow.protocol.OFMatch.OFMatchType getType()

getLength

public short getLength()
Get the length of this message

Returns:
length

getLengthU

public int getLengthU()
Get the length of this message, unsigned

Returns:
unsigned length

getMatchLength

public short getMatchLength()

setField

public void setField(OFMatchField newMatchField)
Sets match field. In case of existing field, checks for existing value

Parameters:
matchField - Check for uniqueness of field and add matchField

setField

public void setField(OFOXMFieldType matchFieldType,
                     java.lang.Object matchFieldValue)

setField

public void setField(OFOXMFieldType matchFieldType,
                     java.lang.Object matchFieldValue,
                     java.lang.Object matchFieldMask)

getMatchFields

public java.util.List<OFMatchField> getMatchFields()
Returns read-only copies of the matchfields contained in this OFMatch

Returns:
a list of ordered OFMatchField objects

setMatchFields

public OFMatch setMatchFields(java.util.List<OFMatchField> matchFields)
Sets the list of matchfields this OFMatch contains

Parameters:
matchFields - a list of ordered OFMatchField objects

setNonWildcards

public OFMatch setNonWildcards(java.util.Set<OFOXMFieldType> nonWildcardedFieldTypes)
Utility function to wildcard all fields except those specified in the set

Parameters:
nonWildcardedFieldTypes - set of match field types preserved, if null all fields are wildcarded

readFrom

public void readFrom(java.nio.ByteBuffer data)

writeTo

public void writeTo(java.nio.ByteBuffer data)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

clone

public OFMatch clone()
Overrides:
clone in class java.lang.Object

load

public static OFMatch load(byte[] packetData,
                           int inPort)
Load and return a new OFMatch based on supplied packetData, see #loadFromPacket(byte[], short) for details.

Parameters:
packetData -
inputPort -
Returns:

loadFromPacket

public OFMatch loadFromPacket(byte[] packetData,
                              int inPort)
Initializes this OFMatch structure with the corresponding data from the specified packet. Must specify the input port, to ensure that this.in_port is set correctly. Specify OFPort.NONE or OFPort.ANY if input port not applicable or available

Parameters:
packetData - The packet's data
inputPort - the port the packet arrived on

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

fromString

public static OFMatch fromString(java.lang.String match)
                          throws java.lang.IllegalArgumentException
Set this OFMatch's parameters based on a comma-separated key=value pair dpctl-style string, e.g., from the output of OFMatch.toString()

Supported keys/values include

KEY(s) VALUE
"in_port","input_port" integer
"dl_src","eth_src", "dl_dst","eth_dst" hex-string
"dl_type", "dl_vlan", "dl_vlan_pcp" integer
"nw_src", "nw_dst", "ip_src", "ip_dst" CIDR-style netmask
"tp_src","tp_dst" integer (max 64k)

The CIDR-style netmasks assume 32 netmask if none given, so: "128.8.128.118/32" is the same as "128.8.128.118"

Parameters:
match - a key=value comma separated string, e.g. "in_port=5,ip_dst=192.168.0.0/16,tp_src=80"
Throws:
java.lang.IllegalArgumentException - on unexpected key or value