Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
Conflicts:
apps/pom.xml
Change-Id: I5dc2c751086118b5137ea8a0a2b81e9de9d48fac
diff --git a/apps/mobility/pom.xml b/apps/mobility/pom.xml
new file mode 100644
index 0000000..a919ff2
--- /dev/null
+++ b/apps/mobility/pom.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-apps</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-app-mobility</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>ONOS simple Mobility app</description>
+
+</project>
diff --git a/apps/mobility/src/main/java/org/onlab/onos/mobility/HostMobility.java b/apps/mobility/src/main/java/org/onlab/onos/mobility/HostMobility.java
new file mode 100644
index 0000000..cb60405
--- /dev/null
+++ b/apps/mobility/src/main/java/org/onlab/onos/mobility/HostMobility.java
@@ -0,0 +1,118 @@
+package org.onlab.onos.mobility;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.Collection;
+import java.util.List;
+
+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.onlab.onos.ApplicationId;
+import org.onlab.onos.net.Device;
+import org.onlab.onos.net.Host;
+import org.onlab.onos.net.device.DeviceService;
+import org.onlab.onos.net.flow.FlowRule;
+import org.onlab.onos.net.flow.FlowRuleService;
+import org.onlab.onos.net.flow.criteria.Criteria.EthCriterion;
+import org.onlab.onos.net.flow.criteria.Criterion;
+import org.onlab.onos.net.flow.criteria.Criterion.Type;
+import org.onlab.onos.net.host.HostEvent;
+import org.onlab.onos.net.host.HostListener;
+import org.onlab.onos.net.host.HostService;
+import org.onlab.packet.MacAddress;
+import org.slf4j.Logger;
+
+import com.google.common.collect.Lists;
+
+
+/**
+ * Sample reactive forwarding application.
+ */
+@Component(immediate = true)
+public class HostMobility {
+
+ private final Logger log = getLogger(getClass());
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected HostService hostService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected FlowRuleService flowRuleService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceService deviceService;
+
+ private ApplicationId appId;
+
+ @Activate
+ public void activate() {
+ appId = ApplicationId.getAppId();
+ hostService.addListener(new InternalHostListener());
+ log.info("Started with Application ID {}", appId.id());
+ }
+
+ @Deactivate
+ public void deactivate() {
+ flowRuleService.removeFlowRulesById(appId);
+ log.info("Stopped");
+ }
+
+ public class InternalHostListener
+ implements HostListener {
+
+ @Override
+ public void event(HostEvent event) {
+ switch (event.type()) {
+ case HOST_ADDED:
+ case HOST_REMOVED:
+ case HOST_UPDATED:
+ // don't care if a host has been added, removed.
+ break;
+ case HOST_MOVED:
+ log.info("Host {} has moved; cleaning up.", event.subject());
+ cleanup(event.subject());
+ break;
+
+ default:
+ break;
+
+ }
+
+ }
+
+ private void cleanup(Host host) {
+ Iterable<Device> devices = deviceService.getDevices();
+ List<FlowRule> flowRules = Lists.newLinkedList();
+ for (Device device : devices) {
+ flowRules.addAll(cleanupDevice(device, host));
+ }
+ FlowRule[] flows = new FlowRule[flowRules.size()];
+ flows = flowRules.toArray(flows);
+ flowRuleService.removeFlowRules(flows);
+ }
+
+ private Collection<? extends FlowRule> cleanupDevice(Device device, Host host) {
+ List<FlowRule> flowRules = Lists.newLinkedList();
+ MacAddress mac = host.mac();
+ for (FlowRule rule : flowRuleService.getFlowEntries(device.id())) {
+ for (Criterion c : rule.selector().criteria()) {
+ if (c.type() == Type.ETH_DST || c.type() == Type.ETH_SRC) {
+ EthCriterion eth = (EthCriterion) c;
+ if (eth.mac().equals(mac)) {
+ flowRules.add(rule);
+ break;
+ }
+ }
+ }
+ }
+ //TODO: handle ip cleanup
+ return flowRules;
+ }
+
+ }
+
+}
+
+
diff --git a/apps/mobility/src/main/java/org/onlab/onos/mobility/package-info.java b/apps/mobility/src/main/java/org/onlab/onos/mobility/package-info.java
new file mode 100644
index 0000000..ea5bdf0
--- /dev/null
+++ b/apps/mobility/src/main/java/org/onlab/onos/mobility/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Trivial application that provides simple form of reactive forwarding.
+ */
+package org.onlab.onos.mobility;
diff --git a/apps/pom.xml b/apps/pom.xml
index 995a8d6..010c531 100644
--- a/apps/pom.xml
+++ b/apps/pom.xml
@@ -20,7 +20,8 @@
<module>tvue</module>
<module>fwd</module>
<module>foo</module>
- <module>config</module>
+ <module>mobility</module>
+ <module>config</module>
</modules>
<properties>
diff --git a/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java b/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
index 4babb50..89c3399 100644
--- a/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
+++ b/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
@@ -161,7 +161,7 @@
switch (stored.state()) {
case ADDED:
case PENDING_ADD:
- frp.applyFlowRule(flowRule);
+ frp.applyFlowRule(stored);
break;
case PENDING_REMOVE:
case REMOVED:
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleFlowRuleStore.java b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleFlowRuleStore.java
index 38e94aa..6b6c157 100644
--- a/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleFlowRuleStore.java
+++ b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleFlowRuleStore.java
@@ -105,11 +105,9 @@
*/
if (flowEntries.containsEntry(did, f)) {
- //synchronized (flowEntries) {
flowEntries.remove(did, f);
flowEntries.put(did, f);
flowEntriesById.remove(rule.appId(), rule);
- //}
}
}
diff --git a/features/features.xml b/features/features.xml
index c255bf2..d2d9567 100644
--- a/features/features.xml
+++ b/features/features.xml
@@ -119,6 +119,14 @@
<bundle>mvn:org.onlab.onos/onos-app-fwd/1.0.0-SNAPSHOT</bundle>
</feature>
+ <feature name="onos-app-mobility" version="1.0.0"
+ description="ONOS sample forwarding application">
+ <feature>onos-api</feature>
+ <bundle>mvn:org.onlab.onos/onos-app-mobility/1.0.0-SNAPSHOT</bundle>
+ </feature>
+
+
+
<feature name="onos-app-foo" version="1.0.0"
description="ONOS sample playground application">
<feature>onos-api</feature>
diff --git a/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowModBuilder.java b/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowModBuilder.java
index 2822f02..efe436f 100644
--- a/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowModBuilder.java
+++ b/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowModBuilder.java
@@ -93,7 +93,7 @@
OFFlowMod fm = factory.buildFlowDelete()
.setCookie(U64.of(cookie.value()))
.setBufferId(OFBufferId.NO_BUFFER)
- .setActions(actions)
+ //.setActions(actions)
.setMatch(match)
.setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
.setPriority(priority)
@@ -104,6 +104,9 @@
private List<OFAction> buildActions() {
List<OFAction> acts = new LinkedList<>();
+ if (treatment == null) {
+ return acts;
+ }
for (Instruction i : treatment.instructions()) {
switch (i.type()) {
case DROP:
diff --git a/providers/openflow/packet/src/main/java/org/onlab/onos/provider/of/packet/impl/OpenFlowPacketProvider.java b/providers/openflow/packet/src/main/java/org/onlab/onos/provider/of/packet/impl/OpenFlowPacketProvider.java
index cb7f1f9..41cb586 100644
--- a/providers/openflow/packet/src/main/java/org/onlab/onos/provider/of/packet/impl/OpenFlowPacketProvider.java
+++ b/providers/openflow/packet/src/main/java/org/onlab/onos/provider/of/packet/impl/OpenFlowPacketProvider.java
@@ -106,10 +106,6 @@
for (Instruction inst : packet.treatment().instructions()) {
if (inst.type().equals(Instruction.Type.OUTPUT)) {
p = portDesc(((OutputInstruction) inst).port());
- /*if (!sw.getPorts().contains(p)) {
- log.warn("Tried to write out non-existent port {}", p.getPortNo());
- continue;
- }*/
OFPacketOut po = packetOut(sw, eth, p.getPortNo());
sw.sendMsg(po);
}