Implemented a globally unique next id generator in FlowObjectStore
Change-Id: Ib98b2996e1ebcca56ad816ea94f25d838c5f4d44
Showing
5 changed files
with
31 additions
and
1 deletions
| ... | @@ -348,7 +348,7 @@ public class BgpRouter { | ... | @@ -348,7 +348,7 @@ public class BgpRouter { |
| 348 | groupService.addGroup(groupDescription); | 348 | groupService.addGroup(groupDescription); |
| 349 | */ | 349 | */ |
| 350 | 350 | ||
| 351 | - nextHops.put(nextHop.ip(), entry.hashCode()); | 351 | + nextHops.put(nextHop.ip(), flowObjectiveService.allocateNextId()); |
| 352 | 352 | ||
| 353 | } | 353 | } |
| 354 | 354 | ... | ... |
| ... | @@ -47,4 +47,10 @@ public interface FlowObjectiveService { | ... | @@ -47,4 +47,10 @@ public interface FlowObjectiveService { |
| 47 | */ | 47 | */ |
| 48 | void next(DeviceId deviceId, NextObjective nextObjective); | 48 | void next(DeviceId deviceId, NextObjective nextObjective); |
| 49 | 49 | ||
| 50 | + /** | ||
| 51 | + * Obtains a globally unique next objective. | ||
| 52 | + * @return an integer | ||
| 53 | + */ | ||
| 54 | + int allocateNextId(); | ||
| 55 | + | ||
| 50 | } | 56 | } | ... | ... |
| ... | @@ -38,4 +38,11 @@ public interface FlowObjectiveStore | ... | @@ -38,4 +38,11 @@ public interface FlowObjectiveStore |
| 38 | * @return a next group | 38 | * @return a next group |
| 39 | */ | 39 | */ |
| 40 | NextGroup getNextGroup(Integer nextId); | 40 | NextGroup getNextGroup(Integer nextId); |
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * Allocates a next objective id. This id is globally unique | ||
| 44 | + * | ||
| 45 | + * @return an integer | ||
| 46 | + */ | ||
| 47 | + int allocateNextId(); | ||
| 41 | } | 48 | } | ... | ... |
| ... | @@ -170,6 +170,11 @@ public class FlowObjectiveManager implements FlowObjectiveService { | ... | @@ -170,6 +170,11 @@ public class FlowObjectiveManager implements FlowObjectiveService { |
| 170 | } | 170 | } |
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | + @Override | ||
| 174 | + public int allocateNextId() { | ||
| 175 | + return flowObjectiveStore.allocateNextId(); | ||
| 176 | + } | ||
| 177 | + | ||
| 173 | private boolean queueObjective(DeviceId deviceId, ForwardingObjective fwd) { | 178 | private boolean queueObjective(DeviceId deviceId, ForwardingObjective fwd) { |
| 174 | if (fwd.nextId() != null && | 179 | if (fwd.nextId() != null && |
| 175 | flowObjectiveStore.getNextGroup(fwd.nextId()) == null) { | 180 | flowObjectiveStore.getNextGroup(fwd.nextId()) == null) { | ... | ... |
| ... | @@ -28,6 +28,7 @@ import org.onosproject.net.flowobjective.FlowObjectiveStore; | ... | @@ -28,6 +28,7 @@ import org.onosproject.net.flowobjective.FlowObjectiveStore; |
| 28 | import org.onosproject.net.flowobjective.FlowObjectiveStoreDelegate; | 28 | import org.onosproject.net.flowobjective.FlowObjectiveStoreDelegate; |
| 29 | import org.onosproject.net.flowobjective.ObjectiveEvent; | 29 | import org.onosproject.net.flowobjective.ObjectiveEvent; |
| 30 | import org.onosproject.store.AbstractStore; | 30 | import org.onosproject.store.AbstractStore; |
| 31 | +import org.onosproject.store.service.AtomicCounter; | ||
| 31 | import org.onosproject.store.service.ConsistentMap; | 32 | import org.onosproject.store.service.ConsistentMap; |
| 32 | import org.onosproject.store.service.Serializer; | 33 | import org.onosproject.store.service.Serializer; |
| 33 | import org.onosproject.store.service.StorageService; | 34 | import org.onosproject.store.service.StorageService; |
| ... | @@ -52,6 +53,8 @@ public class DistributedFlowObjectiveStore | ... | @@ -52,6 +53,8 @@ public class DistributedFlowObjectiveStore |
| 52 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 53 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 53 | protected StorageService storageService; | 54 | protected StorageService storageService; |
| 54 | 55 | ||
| 56 | + private AtomicCounter nextIds; | ||
| 57 | + | ||
| 55 | @Activate | 58 | @Activate |
| 56 | public void activate() { | 59 | public void activate() { |
| 57 | nextGroups = storageService.<Integer, byte[]>consistentMapBuilder() | 60 | nextGroups = storageService.<Integer, byte[]>consistentMapBuilder() |
| ... | @@ -62,6 +65,10 @@ public class DistributedFlowObjectiveStore | ... | @@ -62,6 +65,10 @@ public class DistributedFlowObjectiveStore |
| 62 | .build())) | 65 | .build())) |
| 63 | .build(); | 66 | .build(); |
| 64 | 67 | ||
| 68 | + nextIds = storageService.atomicCounterBuilder() | ||
| 69 | + .withName("next-objective-counter") | ||
| 70 | + .build(); | ||
| 71 | + | ||
| 65 | log.info("Started"); | 72 | log.info("Started"); |
| 66 | } | 73 | } |
| 67 | 74 | ||
| ... | @@ -86,4 +93,9 @@ public class DistributedFlowObjectiveStore | ... | @@ -86,4 +93,9 @@ public class DistributedFlowObjectiveStore |
| 86 | } | 93 | } |
| 87 | return null; | 94 | return null; |
| 88 | } | 95 | } |
| 96 | + | ||
| 97 | + @Override | ||
| 98 | + public int allocateNextId() { | ||
| 99 | + return (int) nextIds.incrementAndGet(); | ||
| 100 | + } | ||
| 89 | } | 101 | } | ... | ... |
-
Please register or login to post a comment