initial impl of criteria
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/criteria/Criteria.java b/core/api/src/main/java/org/onlab/onos/net/flow/criteria/Criteria.java
index ff1ac25..24c49bb 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/criteria/Criteria.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/criteria/Criteria.java
@@ -1,23 +1,41 @@
package org.onlab.onos.net.flow.criteria;
+import org.onlab.onos.net.PortNumber;
+import org.onlab.onos.net.flow.criteria.Criterion.Type;
+import org.onlab.packet.IPAddress;
+import org.onlab.packet.MACAddress;
+import org.onlab.packet.VLANID;
+
/**
* Factory class to create various traffic selection criteria.
*/
public final class Criteria {
+ //TODO: incomplete type implementation. Need to implement complete list from Criterion
+
// Ban construction
private Criteria() {
}
/**
+ * Creates a match on IN_PORT field using the specified value.
+ *
+ * @param port inport value
+ * @return match criterion
+ */
+ public static Criterion matchInPort(PortNumber port) {
+ return new PortCriterion(port);
+ }
+
+ /**
* Creates a match on ETH_SRC field using the specified value. This value
* may be a wildcard mask.
*
* @param macValue MAC address value or wildcard mask
* @return match criterion
*/
- public static Criterion matchEthSrc(MACValue macValue) {
- return null;
+ public static Criterion matchEthSrc(MACAddress mac) {
+ return new EthCriterion(mac, Type.ETH_SRC);
}
/**
@@ -27,11 +45,214 @@
* @param macValue MAC address value or wildcard mask
* @return match criterion
*/
- public static Criterion matchEthDst(MACValue macValue) {
- return null;
+ public static Criterion matchEthDst(MACAddress mac) {
+ return new EthCriterion(mac, Type.ETH_DST);
+ }
+
+ /**
+ * Creates a match on ETH_TYPE field using the specified value.
+ *
+ * @param ethType eth type value
+ * @return match criterion
+ */
+ public static Criterion matchEthType(Short ethType) {
+ return new EthTypeCriterion(ethType);
+ }
+
+ /**
+ * Creates a match on VLAN ID field using the specified value.
+ *
+ * @param vlanId vlan id value
+ * @return match criterion
+ */
+ public static Criterion matchVlanId(VLANID vlanId) {
+ return new VlanIdCriterion(vlanId);
+ }
+
+ /**
+ * Creates a match on VLAN PCP field using the specified value.
+ *
+ * @param vlanPcp vlan pcp value
+ * @return match criterion
+ */
+ public static Criterion matchVlanId(Byte vlanPcp) {
+ return new VlanPcpCriterion(vlanPcp);
+ }
+
+ /**
+ * Creates a match on IP proto field using the specified value.
+ *
+ * @param proto ip protocol value
+ * @return match criterion
+ */
+ public static Criterion matchIPProtocol(Byte proto) {
+ return new IPProtocolCriterion(proto);
+ }
+
+ /**
+ * Creates a match on IP src field using the specified value.
+ *
+ * @param ip ip src value
+ * @return match criterion
+ */
+ public static Criterion matchIPSrc(IPAddress ip) {
+ return new IPCriterion(ip, Type.IPV4_SRC);
+ }
+
+ /**
+ * Creates a match on IP dst field using the specified value.
+ *
+ * @param ip ip src value
+ * @return match criterion
+ */
+ public static Criterion matchIPDst(IPAddress ip) {
+ return new IPCriterion(ip, Type.IPV4_DST);
}
- // Dummy to illustrate the concept for now; delete ASAP
- private static class MACValue { }
+ /*
+ * Implementations of criteria.
+ */
+
+ public static final class PortCriterion implements Criterion {
+ private final PortNumber port;
+
+ public PortCriterion(PortNumber port) {
+ this.port = port;
+ }
+
+ @Override
+ public Type type() {
+ return Type.IN_PORT;
+ }
+
+ public PortNumber port() {
+ return this.port;
+ }
+ }
+
+
+ public static final class EthCriterion implements Criterion {
+ private final MACAddress mac;
+ private final Type type;
+
+ public EthCriterion(MACAddress mac, Type type) {
+ this.mac = mac;
+ this.type = type;
+ }
+
+ @Override
+ public Type type() {
+ return this.type;
+ }
+
+ public MACAddress mac() {
+ return this.mac;
+ }
+ }
+
+ public static final class EthTypeCriterion implements Criterion {
+
+ private final Short ethType;
+
+ public EthTypeCriterion(Short ethType) {
+ this.ethType = ethType;
+ }
+
+ @Override
+ public Type type() {
+ return Type.ETH_TYPE;
+ }
+
+ public Short ethType() {
+ return ethType;
+ }
+
+ }
+
+
+ public static final class IPCriterion implements Criterion {
+
+ private final IPAddress ip;
+ private final Type type;
+
+ public IPCriterion(IPAddress ip, Type type) {
+ this.ip = ip;
+ this.type = type;
+ }
+
+ @Override
+ public Type type() {
+ return this.type;
+ }
+
+ public IPAddress ip() {
+ return this.ip;
+ }
+
+
+ }
+
+
+ public static final class IPProtocolCriterion implements Criterion {
+
+ private final Byte proto;
+
+ public IPProtocolCriterion(Byte protocol) {
+ this.proto = protocol;
+ }
+
+ @Override
+ public Type type() {
+ return Type.IP_PROTO;
+ }
+
+ public Byte protocol() {
+ return proto;
+ }
+
+ }
+
+
+ public static final class VlanPcpCriterion implements Criterion {
+
+ private final Byte vlanPcp;
+
+ public VlanPcpCriterion(Byte vlanPcp) {
+ this.vlanPcp = vlanPcp;
+ }
+
+ @Override
+ public Type type() {
+ return Type.VLAN_PCP;
+ }
+
+ public Byte protocol() {
+ return vlanPcp;
+ }
+
+ }
+
+
+ public static final class VlanIdCriterion implements Criterion {
+
+
+ private final VLANID vlanId;
+
+ public VlanIdCriterion(VLANID vlanId) {
+ this.vlanId = vlanId;
+ }
+
+ @Override
+ public Type type() {
+ return Type.VLAN_VID;
+ }
+
+ public VLANID vlanId() {
+ return vlanId;
+ }
+
+ }
+
+
}