Fixed issue where LinkCollectionIntentInstaller was missing a flow rule
for the last hop switch.
Change-Id: I0f3d49de10dc5a6fd7cf65463d0d2e9b6d512346
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/LinkCollectionIntentInstaller.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/LinkCollectionIntentInstaller.java
index 51e0d2e..ec668dc 100644
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/LinkCollectionIntentInstaller.java
+++ b/core/net/src/main/java/org/onlab/onos/net/intent/impl/LinkCollectionIntentInstaller.java
@@ -1,5 +1,8 @@
package org.onlab.onos.net.intent.impl;
+import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder;
+import static org.slf4j.LoggerFactory.getLogger;
+
import java.util.List;
import java.util.concurrent.Future;
@@ -10,7 +13,9 @@
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.CoreService;
+import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Link;
+import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.flow.CompletedBatchOperation;
import org.onlab.onos.net.flow.DefaultFlowRule;
import org.onlab.onos.net.flow.DefaultTrafficSelector;
@@ -29,9 +34,6 @@
import com.google.common.collect.Lists;
-import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder;
-import static org.slf4j.LoggerFactory.getLogger;
-
/**
* Installer for {@link org.onlab.onos.net.intent.LinkCollectionIntent}
* path segment intents.
@@ -79,15 +81,17 @@
DefaultTrafficSelector.builder(intent.selector());
List<FlowRuleBatchEntry> rules = Lists.newLinkedList();
for (Link link : intent.links()) {
- TrafficTreatment treatment = builder()
- .setOutput(link.src().port()).build();
-
- FlowRule rule = new DefaultFlowRule(link.src().deviceId(),
- builder.build(), treatment,
- 123, appId, 600);
- rules.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, rule));
+ rules.add(createBatchEntry(FlowRuleOperation.ADD,
+ builder.build(),
+ link.src().deviceId(),
+ link.src().port()));
}
+ rules.add(createBatchEntry(FlowRuleOperation.ADD,
+ builder.build(),
+ intent.egressPoint().deviceId(),
+ intent.egressPoint().port()));
+
return applyBatch(rules);
}
@@ -98,13 +102,39 @@
List<FlowRuleBatchEntry> rules = Lists.newLinkedList();
for (Link link : intent.links()) {
- TrafficTreatment treatment = builder()
- .setOutput(link.src().port()).build();
- FlowRule rule = new DefaultFlowRule(link.src().deviceId(),
- builder.build(), treatment,
- 123, appId, 600);
- rules.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, rule));
+ rules.add(createBatchEntry(FlowRuleOperation.REMOVE,
+ builder.build(),
+ link.src().deviceId(),
+ link.src().port()));
}
+
+ rules.add(createBatchEntry(FlowRuleOperation.REMOVE,
+ builder.build(),
+ intent.egressPoint().deviceId(),
+ intent.egressPoint().port()));
+
return applyBatch(rules);
}
+
+ /**
+ * Creates a FlowRuleBatchEntry based on the provided parameters.
+ *
+ * @param operation the FlowRuleOperation to use
+ * @param selector the traffic selector
+ * @param deviceId the device ID for the flow rule
+ * @param outPort the output port of the flow rule
+ * @return the new flow rule batch entry
+ */
+ private FlowRuleBatchEntry createBatchEntry(FlowRuleOperation operation,
+ TrafficSelector selector,
+ DeviceId deviceId,
+ PortNumber outPort) {
+
+ TrafficTreatment treatment = builder().setOutput(outPort).build();
+
+ FlowRule rule = new DefaultFlowRule(deviceId,
+ selector, treatment, 123, appId, 600);
+
+ return new FlowRuleBatchEntry(operation, rule);
+ }
}