Committed by
Gerrit Code Review
[ONOS-4606] Avoid generating incorrect NetworkId
Change-Id: I7b474e368cde8e46e3c903326a8052ce555c0c85
Showing
2 changed files
with
17 additions
and
2 deletions
... | @@ -18,6 +18,8 @@ package org.onosproject.incubator.net.virtual; | ... | @@ -18,6 +18,8 @@ package org.onosproject.incubator.net.virtual; |
18 | import com.google.common.annotations.Beta; | 18 | import com.google.common.annotations.Beta; |
19 | import org.onlab.util.Identifier; | 19 | import org.onlab.util.Identifier; |
20 | 20 | ||
21 | +import java.util.Objects; | ||
22 | + | ||
21 | /** | 23 | /** |
22 | * Representation of network identity. | 24 | * Representation of network identity. |
23 | */ | 25 | */ |
... | @@ -34,6 +36,15 @@ public final class NetworkId extends Identifier<Long> { | ... | @@ -34,6 +36,15 @@ public final class NetworkId extends Identifier<Long> { |
34 | */ | 36 | */ |
35 | public static final NetworkId PHYSICAL = networkId(0L); | 37 | public static final NetworkId PHYSICAL = networkId(0L); |
36 | 38 | ||
39 | + /** | ||
40 | + * Checks if the id is for virtual network. | ||
41 | + * | ||
42 | + * @return true if the id is for virtual network. | ||
43 | + */ | ||
44 | + public final boolean isVirtualNetworkId() { | ||
45 | + return (!Objects.equals(this, NONE) && !Objects.equals(this, PHYSICAL)); | ||
46 | + } | ||
47 | + | ||
37 | // Public construction is prohibited | 48 | // Public construction is prohibited |
38 | private NetworkId(long id) { | 49 | private NetworkId(long id) { |
39 | super(id); | 50 | super(id); | ... | ... |
... | @@ -256,9 +256,13 @@ public class DistributedVirtualNetworkStore | ... | @@ -256,9 +256,13 @@ public class DistributedVirtualNetworkStore |
256 | * @return NetworkId network identifier | 256 | * @return NetworkId network identifier |
257 | */ | 257 | */ |
258 | private NetworkId genNetworkId() { | 258 | private NetworkId genNetworkId() { |
259 | - return NetworkId.networkId(idGenerator.getNewId()); | 259 | + NetworkId networkId; |
260 | - } | 260 | + do { |
261 | + networkId = NetworkId.networkId(idGenerator.getNewId()); | ||
262 | + } while (!networkId.isVirtualNetworkId()); | ||
261 | 263 | ||
264 | + return networkId; | ||
265 | + } | ||
262 | 266 | ||
263 | @Override | 267 | @Override |
264 | public void removeNetwork(NetworkId networkId) { | 268 | public void removeNetwork(NetworkId networkId) { | ... | ... |
-
Please register or login to post a comment