Implemented a globally unique next id generator in FlowObjectStore
Change-Id: Ib98b2996e1ebcca56ad816ea94f25d838c5f4d44
diff --git a/apps/bgprouter/src/main/java/org/onosproject/bgprouter/BgpRouter.java b/apps/bgprouter/src/main/java/org/onosproject/bgprouter/BgpRouter.java
index 069fc50..462bcc0 100644
--- a/apps/bgprouter/src/main/java/org/onosproject/bgprouter/BgpRouter.java
+++ b/apps/bgprouter/src/main/java/org/onosproject/bgprouter/BgpRouter.java
@@ -348,7 +348,7 @@
groupService.addGroup(groupDescription);
*/
- nextHops.put(nextHop.ip(), entry.hashCode());
+ nextHops.put(nextHop.ip(), flowObjectiveService.allocateNextId());
}
diff --git a/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveService.java b/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveService.java
index 690fcc7..fd6ac55 100644
--- a/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveService.java
+++ b/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveService.java
@@ -47,4 +47,10 @@
*/
void next(DeviceId deviceId, NextObjective nextObjective);
+ /**
+ * Obtains a globally unique next objective.
+ * @return an integer
+ */
+ int allocateNextId();
+
}
diff --git a/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveStore.java b/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveStore.java
index e667618..033558c 100644
--- a/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveStore.java
+++ b/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveStore.java
@@ -38,4 +38,11 @@
* @return a next group
*/
NextGroup getNextGroup(Integer nextId);
+
+ /**
+ * Allocates a next objective id. This id is globally unique
+ *
+ * @return an integer
+ */
+ int allocateNextId();
}
diff --git a/core/net/src/main/java/org/onosproject/net/flowobjective/impl/FlowObjectiveManager.java b/core/net/src/main/java/org/onosproject/net/flowobjective/impl/FlowObjectiveManager.java
index 17b0aa7..6b84bfa 100644
--- a/core/net/src/main/java/org/onosproject/net/flowobjective/impl/FlowObjectiveManager.java
+++ b/core/net/src/main/java/org/onosproject/net/flowobjective/impl/FlowObjectiveManager.java
@@ -170,6 +170,11 @@
}
}
+ @Override
+ public int allocateNextId() {
+ return flowObjectiveStore.allocateNextId();
+ }
+
private boolean queueObjective(DeviceId deviceId, ForwardingObjective fwd) {
if (fwd.nextId() != null &&
flowObjectiveStore.getNextGroup(fwd.nextId()) == null) {
diff --git a/core/store/dist/src/main/java/org/onosproject/store/flowobjective/impl/DistributedFlowObjectiveStore.java b/core/store/dist/src/main/java/org/onosproject/store/flowobjective/impl/DistributedFlowObjectiveStore.java
index 94d72ec..8dbc634 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/flowobjective/impl/DistributedFlowObjectiveStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/flowobjective/impl/DistributedFlowObjectiveStore.java
@@ -28,6 +28,7 @@
import org.onosproject.net.flowobjective.FlowObjectiveStoreDelegate;
import org.onosproject.net.flowobjective.ObjectiveEvent;
import org.onosproject.store.AbstractStore;
+import org.onosproject.store.service.AtomicCounter;
import org.onosproject.store.service.ConsistentMap;
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.StorageService;
@@ -52,6 +53,8 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected StorageService storageService;
+ private AtomicCounter nextIds;
+
@Activate
public void activate() {
nextGroups = storageService.<Integer, byte[]>consistentMapBuilder()
@@ -62,6 +65,10 @@
.build()))
.build();
+ nextIds = storageService.atomicCounterBuilder()
+ .withName("next-objective-counter")
+ .build();
+
log.info("Started");
}
@@ -86,4 +93,9 @@
}
return null;
}
+
+ @Override
+ public int allocateNextId() {
+ return (int) nextIds.incrementAndGet();
+ }
}