Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProvider.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProvider.java
index 9d31631..ca22c4f 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProvider.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProvider.java
@@ -17,6 +17,15 @@
*/
void applyFlowRule(FlowRule... flowRules);
+ /**
+ * Instructs the provider to remove the specified flow rules to their
+ * respective devices.
+ * @param flowRules one or more flow rules
+ * throws SomeKindOfException that indicates which ones were applied and
+ * which ones failed
+ */
+ void removeFlowRule(FlowRule... flowRules);
+
/**
* Returns the collection of flow entries currently applied on the given
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;
+ }
+
+ }
+
+
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/criteria/Criterion.java b/core/api/src/main/java/org/onlab/onos/net/flow/criteria/Criterion.java
index d105f7c..567e100 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/criteria/Criterion.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/criteria/Criterion.java
@@ -1,5 +1,6 @@
package org.onlab.onos.net.flow.criteria;
+
/**
* Representation of a single header field selection.
*/
@@ -92,6 +93,12 @@
IPV6_EXTHDR
}
+ /**
+ * Returns the type of criterion.
+ * @return type of criterion
+ */
+ public Type type();
+
// TODO: Create factory class 'Criteria' that will have various factory
// to create specific criterions.
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/criteria/package-info.java b/core/api/src/main/java/org/onlab/onos/net/flow/criteria/package-info.java
new file mode 100644
index 0000000..82eb210
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/criteria/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Traffic selection criteria model.
+ */
+package org.onlab.onos.net.flow.criteria;
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/instructions/Instructions.java b/core/api/src/main/java/org/onlab/onos/net/flow/instructions/Instructions.java
index 5acac3e..270704e 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/instructions/Instructions.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/instructions/Instructions.java
@@ -10,6 +10,7 @@
import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPProtoInstruction;
import org.onlab.packet.IPAddress;
import org.onlab.packet.MACAddress;
+import org.onlab.packet.VLANID;
/**
* Factory class for creating various traffic treatment instructions.
*/
@@ -74,7 +75,7 @@
* @param vlanId the vlan id to modify to.
* @return a L2 modification
*/
- public static L2ModificationInstruction modVlanId(Short vlanId) {
+ public static L2ModificationInstruction modVlanId(VLANID vlanId) {
checkNotNull(vlanId, "VLAN id cannot be null");
return new L2ModificationInstruction.ModVlanIdInstruction(vlanId);
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/instructions/L2ModificationInstruction.java b/core/api/src/main/java/org/onlab/onos/net/flow/instructions/L2ModificationInstruction.java
index 348c30f..da86e13 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/instructions/L2ModificationInstruction.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/instructions/L2ModificationInstruction.java
@@ -1,6 +1,7 @@
package org.onlab.onos.net.flow.instructions;
import org.onlab.packet.MACAddress;
+import org.onlab.packet.VLANID;
/**
* Abstraction of a single traffic treatment step.
@@ -100,9 +101,9 @@
*/
public static final class ModVlanIdInstruction extends L2ModificationInstruction {
- public final Short vlanId;
+ public final VLANID vlanId;
- public ModVlanIdInstruction(Short vlanId) {
+ public ModVlanIdInstruction(VLANID vlanId) {
this.vlanId = vlanId;
}
@@ -111,7 +112,7 @@
return L2SubType.VLAN_ID;
}
- public Short vlanId() {
+ public VLANID vlanId() {
return this.vlanId;
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/instructions/package-info.java b/core/api/src/main/java/org/onlab/onos/net/flow/instructions/package-info.java
new file mode 100644
index 0000000..01b68ad
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/instructions/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Traffic treatment model.
+ */
+package org.onlab.onos.net.flow.instructions;
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManager.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManager.java
new file mode 100644
index 0000000..267af5b
--- /dev/null
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManager.java
@@ -0,0 +1,132 @@
+package org.onlab.onos.net.trivial.flow.impl;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onlab.onos.event.AbstractListenerRegistry;
+import org.onlab.onos.event.EventDeliveryService;
+import org.onlab.onos.net.Device;
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.device.DeviceService;
+import org.onlab.onos.net.flow.FlowEntry;
+import org.onlab.onos.net.flow.FlowRule;
+import org.onlab.onos.net.flow.FlowRuleEvent;
+import org.onlab.onos.net.flow.FlowRuleListener;
+import org.onlab.onos.net.flow.FlowRuleProvider;
+import org.onlab.onos.net.flow.FlowRuleProviderRegistry;
+import org.onlab.onos.net.flow.FlowRuleProviderService;
+import org.onlab.onos.net.flow.FlowRuleService;
+import org.onlab.onos.net.provider.AbstractProviderRegistry;
+import org.onlab.onos.net.provider.AbstractProviderService;
+import org.slf4j.Logger;
+
+@Component(immediate = true)
+@Service
+public class SimpleFlowRuleManager
+extends AbstractProviderRegistry<FlowRuleProvider, FlowRuleProviderService>
+implements FlowRuleService, FlowRuleProviderRegistry {
+
+ private final Logger log = getLogger(getClass());
+
+ private final AbstractListenerRegistry<FlowRuleEvent, FlowRuleListener>
+ listenerRegistry = new AbstractListenerRegistry<>();
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ private EventDeliveryService eventDispatcher;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ private DeviceService deviceService;
+
+ @Activate
+ public void activate() {
+ eventDispatcher.addSink(FlowRuleEvent.class, listenerRegistry);
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ eventDispatcher.removeSink(FlowRuleEvent.class);
+ log.info("Stopped");
+ }
+
+ @Override
+ public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
+ //TODO: store rules somewhere and return them here
+ return null;
+ }
+
+ @Override
+ public void applyFlowRules(FlowRule... flowRules) {
+ for (int i = 0; i < flowRules.length; i++) {
+ FlowRule f = flowRules[0];
+ final Device device = deviceService.getDevice(f.deviceId());
+ final FlowRuleProvider frp = getProvider(device.providerId());
+ //TODO: store rules somewhere
+ frp.applyFlowRule(f);
+ }
+
+
+ }
+
+ @Override
+ public void removeFlowRules(FlowRule... flowRules) {
+ for (int i = 0; i < flowRules.length; i++) {
+ FlowRule f = flowRules[0];
+ final Device device = deviceService.getDevice(f.deviceId());
+ final FlowRuleProvider frp = getProvider(device.providerId());
+ //TODO: remove stored rules from wherever they are
+ frp.removeFlowRule(f);
+ }
+
+ }
+
+ @Override
+ public void addListener(FlowRuleListener listener) {
+ listenerRegistry.addListener(listener);
+ }
+
+ @Override
+ public void removeListener(FlowRuleListener listener) {
+ listenerRegistry.removeListener(listener);
+ }
+
+ @Override
+ protected FlowRuleProviderService createProviderService(
+ FlowRuleProvider provider) {
+ return new InternalFlowRuleProviderService(provider);
+ }
+
+ private class InternalFlowRuleProviderService
+ extends AbstractProviderService<FlowRuleProvider>
+ implements FlowRuleProviderService {
+
+ protected InternalFlowRuleProviderService(FlowRuleProvider provider) {
+ super(provider);
+ }
+
+ @Override
+ public void flowRemoved(FlowRule flowRule) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void flowMissing(FlowRule flowRule) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void flowAdded(FlowRule flowRule) {
+ // TODO Auto-generated method stub
+
+ }
+
+ }
+
+}
diff --git a/of/api/src/main/java/org/onlab/onos/of/controller/OpenFlowSwitchEvent.java b/of/api/src/main/java/org/onlab/onos/of/controller/OpenFlowSwitchEvent.java
deleted file mode 100644
index 281d505..0000000
--- a/of/api/src/main/java/org/onlab/onos/of/controller/OpenFlowSwitchEvent.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.onlab.onos.of.controller;
-
-/**
- * Meta events that can happen at a switch.
- *
- */
-public enum OpenFlowSwitchEvent {
- /**
- * The switch connected.
- */
- SWITCH_CONNECTED,
-
- /**
- * The switch disconnected.
- */
- SWITCH_DISCONNECTED
-}
diff --git a/providers/of/pom.xml b/providers/of/pom.xml
index fd03891..30a5c16 100644
--- a/providers/of/pom.xml
+++ b/providers/of/pom.xml
@@ -21,6 +21,7 @@
<module>link</module>
<module>host</module>
<module>packet</module>
+ <module>flow</module>
</modules>
<dependencies>