alshabib

Implemented a globally unique next id generator in FlowObjectStore

Change-Id: Ib98b2996e1ebcca56ad816ea94f25d838c5f4d44
......@@ -348,7 +348,7 @@ public class BgpRouter {
groupService.addGroup(groupDescription);
*/
nextHops.put(nextHop.ip(), entry.hashCode());
nextHops.put(nextHop.ip(), flowObjectiveService.allocateNextId());
}
......
......@@ -47,4 +47,10 @@ public interface FlowObjectiveService {
*/
void next(DeviceId deviceId, NextObjective nextObjective);
/**
* Obtains a globally unique next objective.
* @return an integer
*/
int allocateNextId();
}
......
......@@ -38,4 +38,11 @@ public interface FlowObjectiveStore
* @return a next group
*/
NextGroup getNextGroup(Integer nextId);
/**
* Allocates a next objective id. This id is globally unique
*
* @return an integer
*/
int allocateNextId();
}
......
......@@ -170,6 +170,11 @@ public class FlowObjectiveManager implements FlowObjectiveService {
}
}
@Override
public int allocateNextId() {
return flowObjectiveStore.allocateNextId();
}
private boolean queueObjective(DeviceId deviceId, ForwardingObjective fwd) {
if (fwd.nextId() != null &&
flowObjectiveStore.getNextGroup(fwd.nextId()) == null) {
......
......@@ -28,6 +28,7 @@ import org.onosproject.net.flowobjective.FlowObjectiveStore;
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 @@ public class DistributedFlowObjectiveStore
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected StorageService storageService;
private AtomicCounter nextIds;
@Activate
public void activate() {
nextGroups = storageService.<Integer, byte[]>consistentMapBuilder()
......@@ -62,6 +65,10 @@ public class DistributedFlowObjectiveStore
.build()))
.build();
nextIds = storageService.atomicCounterBuilder()
.withName("next-objective-counter")
.build();
log.info("Started");
}
......@@ -86,4 +93,9 @@ public class DistributedFlowObjectiveStore
}
return null;
}
@Override
public int allocateNextId() {
return (int) nextIds.incrementAndGet();
}
}
......