Kenji HIKICHI
Committed by Gerrit Code Review

[ONOS-4606] Avoid generating incorrect NetworkId

Change-Id: I7b474e368cde8e46e3c903326a8052ce555c0c85
......@@ -18,6 +18,8 @@ package org.onosproject.incubator.net.virtual;
import com.google.common.annotations.Beta;
import org.onlab.util.Identifier;
import java.util.Objects;
/**
* Representation of network identity.
*/
......@@ -34,6 +36,15 @@ public final class NetworkId extends Identifier<Long> {
*/
public static final NetworkId PHYSICAL = networkId(0L);
/**
* Checks if the id is for virtual network.
*
* @return true if the id is for virtual network.
*/
public final boolean isVirtualNetworkId() {
return (!Objects.equals(this, NONE) && !Objects.equals(this, PHYSICAL));
}
// Public construction is prohibited
private NetworkId(long id) {
super(id);
......
......@@ -256,9 +256,13 @@ public class DistributedVirtualNetworkStore
* @return NetworkId network identifier
*/
private NetworkId genNetworkId() {
return NetworkId.networkId(idGenerator.getNewId());
}
NetworkId networkId;
do {
networkId = NetworkId.networkId(idGenerator.getNewId());
} while (!networkId.isVirtualNetworkId());
return networkId;
}
@Override
public void removeNetwork(NetworkId networkId) {
......