Adding command to add routes and to generate flows from them.
Enhanced FlowRuleStore and FlowRuleService with a new method.
Change-Id: I011371c1931294448e361fc1ceb120d89c14489d
diff --git a/providers/null/src/main/java/org/onosproject/provider/nil/cli/CreateNullEntity.java b/providers/null/src/main/java/org/onosproject/provider/nil/cli/CreateNullEntity.java
index ed68dfc..a9efa78 100644
--- a/providers/null/src/main/java/org/onosproject/provider/nil/cli/CreateNullEntity.java
+++ b/providers/null/src/main/java/org/onosproject/provider/nil/cli/CreateNullEntity.java
@@ -17,6 +17,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Longs;
+import org.onlab.util.Tools;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
@@ -33,9 +34,12 @@
* Base command for adding simulated entities to the custom topology simulation.
*/
public abstract class CreateNullEntity extends AbstractShellCommand {
+
protected static final String GEO = "geo";
protected static final String GRID = "grid";
+ protected static final int MAX_EDGE_PORT_TRIES = 5;
+
/**
* Validates that the simulator is custom.
*
@@ -93,14 +97,32 @@
* @return connect point available for link or host attachment
*/
protected ConnectPoint findAvailablePort(DeviceId deviceId, ConnectPoint otherPoint) {
- EdgePortService eps = get(EdgePortService.class);
HostService hs = get(HostService.class);
-
- List<ConnectPoint> points = ImmutableList
- .sortedCopyOf((l, r) -> Longs.compare(l.port().toLong(), r.port().toLong()),
- eps.getEdgePoints(deviceId));
- return points.stream()
+ return findAvailablePorts(deviceId).stream()
.filter(p -> !Objects.equals(p, otherPoint) && hs.getConnectedHosts(p).isEmpty())
.findFirst().orElse(null);
}
+
+ /**
+ * Finds an available connect points among edge ports of the specified device.
+ *
+ * @param deviceId device identifier
+ * @return list of connect points available for link or host attachments
+ */
+ protected List<ConnectPoint> findAvailablePorts(DeviceId deviceId) {
+ EdgePortService eps = get(EdgePortService.class);
+
+ // As there may be a slight delay in edge service getting updated, retry a few times
+ for (int i = 0; i < MAX_EDGE_PORT_TRIES; i++) {
+ List<ConnectPoint> points = ImmutableList
+ .sortedCopyOf((l, r) -> Longs.compare(l.port().toLong(), r.port().toLong()),
+ eps.getEdgePoints(deviceId));
+ if (!points.isEmpty()) {
+ return points;
+ }
+ Tools.delay(100);
+ }
+ return ImmutableList.of();
+ }
+
}