Brian Stanke
Committed by Gerrit Code Review

ONOS-2184 - Implementation of virtual network topology provider.

Change-Id: I846ba56c138187c6e5435692798e709b74a78020
......@@ -37,6 +37,7 @@ public abstract class TestDeviceParams {
protected static final DeviceId DID2 = deviceId("of:bar");
protected static final DeviceId DID3 = deviceId("of:who");
protected static final DeviceId DID4 = deviceId("of:what");
protected static final DeviceId DID5 = deviceId("of:when");
protected static final MacAddress MAC1 = MacAddress.valueOf("00:11:00:00:00:01");
protected static final MacAddress MAC2 = MacAddress.valueOf("00:22:00:00:00:02");
protected static final VlanId VLAN1 = VlanId.vlanId((short) 11);
......
......@@ -31,15 +31,12 @@ import org.onosproject.incubator.net.virtual.VirtualNetworkService;
import org.onosproject.incubator.net.virtual.VirtualNetworkStore;
import org.onosproject.incubator.net.virtual.VirtualPort;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.EncapsulationType;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.constraint.EncapsulationConstraint;
import org.onosproject.net.intent.impl.IntentCompilationException;
import org.onosproject.net.topology.TopologyService;
import org.slf4j.Logger;
......@@ -93,12 +90,32 @@ public class VirtualNetworkIntentCompiler
Optional<Path> path = getPaths(intent).stream()
.findFirst();
if (path != null && path.isPresent()) {
path.get().links().forEach(link -> {
Intent physicalIntent = createPtPtIntent(intent, link);
intents.add(physicalIntent);
List<Link> links = path.get().links();
// store the virtual intent to physical intent tunnelId mapping
store.addTunnelId(intent, TunnelId.valueOf(physicalIntent.key().toString()));
// First create an intent between the intent ingress CP and the first link source CP,
// only if the two CPs are not the same.
Link firstLink = links.get(0);
if (!intent.ingressPoint().equals(firstLink.src())) {
intents.add(createPtPtIntent(intent, intent.ingressPoint(), firstLink.src()));
}
// Next create an intent between the intent egress CP and the last link destination CP,
// only if the two CPs are not the same.
Link lastLink = links.get(links.size() - 1);
if (!intent.egressPoint().equals(lastLink.dst())) {
intents.add(createPtPtIntent(intent, lastLink.dst(), intent.egressPoint()));
}
// Now loop through all of the virtual links in the path and create an intent.
// An intent is also created connecting two virtual links.
final int[] index = {0};
links.forEach(link -> {
intents.add(createPtPtIntent(intent, link.src(), link.dst()));
if (index[0] > 0) {
Link previousLink = links.get(index[0] - 1);
intents.add(createPtPtIntent(intent, previousLink.dst(), link.src()));
}
index[0]++;
});
} else {
throw new IntentCompilationException("Unable to find a path for intent " + intent);
......@@ -124,7 +141,7 @@ public class VirtualNetworkIntentCompiler
}
/**
* Encodes the key using the network identifier, application identifer, source and destination
* Encodes the key using the network identifier, application identifier, source and destination
* connect points.
*
* @param networkId virtual network identifier
......@@ -133,26 +150,26 @@ public class VirtualNetworkIntentCompiler
* @param dst destination connect point
* @return encoded key
*/
private static Key encodeKey(NetworkId networkId, ApplicationId applicationId, ConnectPoint src, ConnectPoint dst) {
String key = String.format(KEY_FORMAT, networkId, src, dst);
return Key.of(key, applicationId);
}
/**
* Creates a point-to-point intent from the virtual network intent and virtual link.
* Creates a point-to-point intent using the virtual network intent between the source and destination
* connect point.
*
* @param intent virtual network intent
* @param link virtual link
* @param src source connect point
* @param dst destination connect point
* @return point to point intent
*/
private Intent createPtPtIntent(VirtualNetworkIntent intent, Link link) {
ConnectPoint ingressPoint = mapVirtualToPhysicalPort(intent.networkId(), link.src());
ConnectPoint egressPoint = mapVirtualToPhysicalPort(intent.networkId(), link.dst());
private Intent createPtPtIntent(VirtualNetworkIntent intent, ConnectPoint src, ConnectPoint dst) {
ConnectPoint ingressPoint = mapVirtualToPhysicalPort(intent.networkId(), src);
ConnectPoint egressPoint = mapVirtualToPhysicalPort(intent.networkId(), dst);
Key intentKey = encodeKey(intent.networkId(), intent.appId(), ingressPoint, egressPoint);
List<Constraint> constraints = new ArrayList<>();
constraints.add(new EncapsulationConstraint(EncapsulationType.VLAN));
// TODO Currently there can only be one intent between the ingress and egress across
// all virtual networks. We may want to support multiple intents between the same src/dst pairs.
PointToPointIntent physicalIntent = PointToPointIntent.builder()
......@@ -160,11 +177,16 @@ public class VirtualNetworkIntentCompiler
.appId(intent.appId())
.ingressPoint(ingressPoint)
.egressPoint(egressPoint)
.constraints(constraints)
.constraints(intent.constraints())
.selector(intent.selector())
.treatment(intent.treatment())
.build();
log.debug("Submitting physical intent: " + physicalIntent);
intentService.submit(physicalIntent);
// Store the physical intent against this virtual intent.
store.addTunnelId(intent, TunnelId.valueOf(physicalIntent.key().toString()));
return physicalIntent;
}
......
......@@ -39,13 +39,11 @@ import org.onosproject.incubator.net.virtual.impl.VirtualNetworkManager;
import org.onosproject.incubator.store.virtual.impl.DistributedVirtualNetworkStore;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultPort;
import org.onosproject.net.EncapsulationType;
import org.onosproject.net.Link;
import org.onosproject.net.NetTestTools;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.TestDeviceParams;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.FakeIntentManager;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentExtensionService;
......@@ -53,10 +51,8 @@ import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.intent.TestableIntentService;
import org.onosproject.net.intent.constraint.EncapsulationConstraint;
import org.onosproject.store.service.TestStorageService;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
......@@ -192,6 +188,9 @@ public class VirtualNetworkIntentCompilerTest extends TestDeviceParams {
return virtualNetwork;
}
/**
* Tests the virtual network intent compiler.
*/
@Test
public void testCompiler() {
compiler.activate();
......@@ -199,20 +198,16 @@ public class VirtualNetworkIntentCompilerTest extends TestDeviceParams {
Key intentKey = Key.of("test", APP_ID);
List<Constraint> constraints = new ArrayList<>();
constraints.add(new EncapsulationConstraint(EncapsulationType.VLAN));
VirtualNetworkIntent virtualIntent = VirtualNetworkIntent.builder()
.networkId(virtualNetwork.id())
.key(intentKey)
.appId(APP_ID)
.ingressPoint(cp1)
.egressPoint(cp5)
.constraints(constraints)
.ingressPoint(cp2)
.egressPoint(cp6)
.build();
List<Intent> compiled = compiler.compile(virtualIntent, Collections.emptyList());
assertEquals("The virtual intents size is not as expected.", 2, compiled.size());
assertEquals("The virtual intents size is not as expected.", 5, compiled.size());
compiler.deactivate();
}
......
......@@ -26,6 +26,18 @@ import org.onosproject.net.provider.Provider;
public interface VirtualNetworkProvider extends Provider {
/**
* Indicates whether or not the specified connect points on the underlying
* network are traversable/reachable.
*
* @param src source connection point
* @param dst destination connection point
* @return true if the destination is reachable from the source
*/
boolean isTraversable(ConnectPoint src, ConnectPoint dst);
// TODO: Further enhance this interface to support the virtual intent programming across this boundary.
/**
* Creates a network tunnel for all traffic from the specified source
* connection point to the indicated destination connection point.
*
......
......@@ -19,6 +19,8 @@ import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.provider.ProviderService;
import java.util.Set;
/**
* Service through which virtual network providers can inject information into
* the core.
......@@ -26,6 +28,18 @@ import org.onosproject.net.provider.ProviderService;
public interface VirtualNetworkProviderService extends ProviderService<VirtualNetworkProvider> {
/**
* Set of separate topology clusters expressed in terms of connect points which
* belong to the same SCC of the underlying topology.
*
* @param clusters set of sets of mutually reachable connection points;
* the outer sets are not mutually reachable
*/
void topologyChanged(Set<Set<ConnectPoint>> clusters);
// TBD: Is the above sufficient to determine health/viability of virtual entities based on
// clustering (SCC) of the physical ones?
/**
* This method is used to notify the VirtualNetwork service that a tunnel is now ACTIVE.
*
* @param networkId network identifier
......
......@@ -108,6 +108,11 @@ public class PtToPtIntentVirtualNetworkProvider extends AbstractProvider
}
@Override
public boolean isTraversable(ConnectPoint src, ConnectPoint dst) {
return false;
}
@Override
public TunnelId createTunnel(NetworkId networkId, ConnectPoint src, ConnectPoint dst) {
checkNotNull(networkId, NETWORK_ID_NULL);
checkNotNull(src, CONNECT_POINT_NULL);
......
......@@ -46,7 +46,7 @@ import java.util.Optional;
import static com.google.common.base.Preconditions.*;
/**
* intent service implementation built on the virtual network service.
* Intent service implementation built on the virtual network service.
*/
public class VirtualNetworkIntentService extends AbstractListenerManager<IntentEvent, IntentListener>
implements IntentService, VnetService {
......@@ -148,18 +148,17 @@ public class VirtualNetworkIntentService extends AbstractListenerManager<IntentE
public void withdraw(Intent intent) {
checkNotNull(intent, INTENT_NULL);
// Withdraws the physical intents created due to the virtual intents.
store.getTunnelIds(intent)
.forEach(tunnelId -> {
Key intentKey = Key.of(tunnelId.id(), intent.appId());
Intent physicalIntent = intentService.getIntent(intentKey);
checkNotNull(physicalIntent, INTENT_NULL);
// Withdraw the physical intent(s)
log.info("Withdrawing pt-pt intent: " + physicalIntent);
intentService.withdraw(physicalIntent);
});
store.getTunnelIds(intent).forEach(tunnelId -> {
Key intentKey = Key.of(tunnelId.id(), intent.appId());
Intent physicalIntent = intentService.getIntent(intentKey);
checkNotNull(physicalIntent, INTENT_NULL);
// Withdraw the physical intent(s)
log.debug("Withdrawing pt-pt intent: " + physicalIntent);
intentService.withdraw(physicalIntent);
});
// Now withdraw the virtual intent
log.info("Withdrawing virtual intent: " + intent);
log.debug("Withdrawing virtual intent: " + intent);
intentService.withdraw(intent);
}
......
......@@ -27,6 +27,7 @@ import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.incubator.net.virtual.DefaultVirtualLink;
import org.onosproject.incubator.net.virtual.NetworkId;
import org.onosproject.incubator.net.virtual.TenantId;
import org.onosproject.incubator.net.virtual.VirtualDevice;
......@@ -76,7 +77,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
@Service
public class VirtualNetworkManager
extends AbstractListenerProviderRegistry<VirtualNetworkEvent, VirtualNetworkListener,
VirtualNetworkProvider, VirtualNetworkProviderService>
VirtualNetworkProvider, VirtualNetworkProviderService>
implements VirtualNetworkService, VirtualNetworkAdminService, VirtualNetworkProviderRegistry {
private final Logger log = LoggerFactory.getLogger(getClass());
......@@ -197,7 +198,36 @@ public class VirtualNetworkManager
checkNotNull(networkId, NETWORK_NULL);
checkNotNull(src, LINK_POINT_NULL);
checkNotNull(dst, LINK_POINT_NULL);
return store.addLink(networkId, src, dst, Link.State.ACTIVE, null);
ConnectPoint physicalSrc = mapVirtualToPhysicalPort(networkId, src);
checkNotNull(physicalSrc, LINK_POINT_NULL);
ConnectPoint physicalDst = mapVirtualToPhysicalPort(networkId, dst);
checkNotNull(physicalDst, LINK_POINT_NULL);
VirtualNetworkProvider provider = getProvider(DefaultVirtualLink.PID);
Link.State state = Link.State.INACTIVE;
if (provider != null) {
boolean traversable = provider.isTraversable(physicalSrc, physicalDst);
state = traversable ? Link.State.ACTIVE : Link.State.INACTIVE;
}
return store.addLink(networkId, src, dst, state, null);
}
/**
* Maps the virtual connect point to a physical connect point.
*
* @param networkId network identifier
* @param virtualCp virtual connect point
* @return physical connect point
*/
private ConnectPoint mapVirtualToPhysicalPort(NetworkId networkId,
ConnectPoint virtualCp) {
Set<VirtualPort> ports = store.getPorts(networkId, virtualCp.deviceId());
for (VirtualPort port : ports) {
if (port.number().equals(virtualCp.port())) {
return new ConnectPoint(port.realizedBy().element().id(), port.realizedBy().number());
}
}
return null;
}
/**
......@@ -441,16 +471,73 @@ public class VirtualNetworkManager
return new InternalVirtualNetworkProviderService(provider);
}
// Service issued to registered virtual network providers so that they
// can interact with the core.
/**
* Service issued to registered virtual network providers so that they
* can interact with the core.
*/
private class InternalVirtualNetworkProviderService
extends AbstractProviderService<VirtualNetworkProvider>
implements VirtualNetworkProviderService {
/**
* Constructor.
* @param provider virtual network provider
*/
InternalVirtualNetworkProviderService(VirtualNetworkProvider provider) {
super(provider);
}
@Override
public void topologyChanged(Set<Set<ConnectPoint>> clusters) {
Set<TenantId> tenantIds = getTenantIds();
tenantIds.forEach(tenantId -> {
Set<VirtualNetwork> virtualNetworks = getVirtualNetworks(tenantId);
virtualNetworks.forEach(virtualNetwork -> {
Set<VirtualLink> virtualLinks = getVirtualLinks(virtualNetwork.id());
virtualLinks.forEach(virtualLink -> {
if (isVirtualLinkInCluster(virtualNetwork.id(), virtualLink, clusters)) {
store.updateLink(virtualLink, virtualLink.tunnelId(), Link.State.ACTIVE);
} else {
store.updateLink(virtualLink, virtualLink.tunnelId(), Link.State.INACTIVE);
}
});
});
});
}
/**
* Determines if the virtual link (both source and destination connect point) is in a cluster.
*
* @param networkId virtual network identifier
* @param virtualLink virtual link
* @param clusters topology clusters
* @return true if the virtual link is in a cluster.
*/
private boolean isVirtualLinkInCluster(NetworkId networkId, VirtualLink virtualLink,
Set<Set<ConnectPoint>> clusters) {
ConnectPoint srcPhysicalCp = mapVirtualToPhysicalPort(networkId, virtualLink.src());
ConnectPoint dstPhysicalCp = mapVirtualToPhysicalPort(networkId, virtualLink.dst());
final boolean[] foundSrc = {false};
final boolean[] foundDst = {false};
clusters.forEach(connectPoints -> {
connectPoints.forEach(connectPoint -> {
if (connectPoint.equals(srcPhysicalCp)) {
foundSrc[0] = true;
} else if (connectPoint.equals(dstPhysicalCp)) {
foundDst[0] = true;
}
});
if (foundSrc[0] && foundDst[0]) {
return;
}
});
return foundSrc[0] && foundDst[0];
}
@Override
public void tunnelUp(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId tunnelId) {
ConnectPoint srcVirtualCp = mapPhysicalToVirtualToPort(networkId, src);
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.virtual.impl;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.incubator.net.virtual.DefaultVirtualLink;
import org.onosproject.incubator.net.virtual.NetworkId;
import org.onosproject.incubator.net.virtual.VirtualNetworkProvider;
import org.onosproject.incubator.net.virtual.VirtualNetworkProviderRegistry;
import org.onosproject.incubator.net.virtual.VirtualNetworkProviderService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import org.onosproject.net.link.LinkEvent;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.topology.Topology;
import org.onosproject.net.topology.TopologyCluster;
import org.onosproject.net.topology.TopologyEvent;
import org.onosproject.net.topology.TopologyListener;
import org.onosproject.net.topology.TopologyService;
import org.slf4j.Logger;
import java.util.HashSet;
import java.util.Set;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Virtual network topology provider.
*/
@Component(immediate = true)
@Service
public class VirtualNetworkTopologyProvider extends AbstractProvider implements VirtualNetworkProvider {
private final Logger log = getLogger(VirtualNetworkTopologyProvider.class);
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected VirtualNetworkProviderRegistry providerRegistry;
private VirtualNetworkProviderService providerService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected TopologyService topologyService;
protected TopologyListener topologyListener = new InternalTopologyListener();
/**
* Default constructor.
*/
public VirtualNetworkTopologyProvider() {
super(DefaultVirtualLink.PID);
}
@Activate
public void activate() {
providerService = providerRegistry.register(this);
topologyService.addListener(topologyListener);
log.info("Started");
}
@Deactivate
public void deactivate() {
topologyService.removeListener(topologyListener);
providerRegistry.unregister(this);
providerService = null;
log.info("Stopped");
}
@Override
public boolean isTraversable(ConnectPoint src, ConnectPoint dst) {
final boolean[] foundSrc = new boolean[1];
final boolean[] foundDst = new boolean[1];
Topology topology = topologyService.currentTopology();
Set<Path> paths = topologyService.getPaths(topology, src.deviceId(), dst.deviceId());
paths.forEach(path -> {
foundDst[0] = false;
foundSrc[0] = false;
// Traverse the links in each path to determine if both the src and dst connection
// point are in the path, if so then this src/dst pair are traversable.
path.links().forEach(link -> {
if (link.src().equals(src)) {
foundSrc[0] = true;
}
if (link.dst().equals(dst)) {
foundDst[0] = true;
}
});
if (foundSrc[0] && foundDst[0]) {
return;
}
});
return foundSrc[0] && foundDst[0];
}
@Override
public TunnelId createTunnel(NetworkId networkId, ConnectPoint src, ConnectPoint dst) {
return null;
}
@Override
public void destroyTunnel(NetworkId networkId, TunnelId tunnelId) {
}
/**
* Returns a set of set of interconnected connect points in the default topology.
* The inner set represents the interconnected connect points, and the outerset
* represents separate clusters.
*
* @param topology the default topology
* @return set of set of interconnected connect points.
*/
protected Set<Set<ConnectPoint>> getConnectPoints(Topology topology) {
Set<Set<ConnectPoint>> clusters = new HashSet<>();
Set<TopologyCluster> topologyClusters = topologyService.getClusters(topology);
topologyClusters.forEach(topologyCluster -> {
Set<ConnectPoint> connectPointSet = new HashSet<>();
Set<Link> clusterLinks = topologyService.getClusterLinks(topology, topologyCluster);
clusterLinks.forEach(link -> {
connectPointSet.add(link.src());
connectPointSet.add(link.dst());
});
if (!connectPointSet.isEmpty()) {
clusters.add(connectPointSet);
}
});
return clusters;
}
/**
* Topology event listener.
*/
private class InternalTopologyListener implements TopologyListener {
@Override
public void event(TopologyEvent event) {
if (!isRelevant(event)) {
return;
}
Topology topology = event.subject();
providerService.topologyChanged(getConnectPoints(topology));
}
@Override
public boolean isRelevant(TopologyEvent event) {
final boolean[] relevant = {false};
if (event.type().equals(TopologyEvent.Type.TOPOLOGY_CHANGED)) {
event.reasons().forEach(event1 -> {
// Only LinkEvents are relevant events, ie: DeviceEvents and others are ignored.
if (event1 instanceof LinkEvent) {
relevant[0] = true;
return;
}
});
}
return relevant[0];
}
}
}
......@@ -220,6 +220,11 @@ public class PtToPtIntentVirtualNetworkProviderTest {
}
@Override
public void topologyChanged(Set<Set<ConnectPoint>> clusters) {
}
@Override
public void tunnelUp(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId tunnelId) {
// Release one permit on the created semaphore since the tunnelUp method was called.
created.release();
......
......@@ -31,6 +31,7 @@ import org.onosproject.incubator.net.virtual.VirtualLink;
import org.onosproject.incubator.net.virtual.VirtualNetwork;
import org.onosproject.incubator.store.virtual.impl.DistributedVirtualNetworkStore;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultPort;
import org.onosproject.net.Link;
import org.onosproject.net.NetTestTools;
import org.onosproject.net.PortNumber;
......@@ -97,7 +98,13 @@ public class VirtualNetworkLinkServiceTest extends TestDeviceParams {
VirtualDevice dstVirtualDevice =
manager.createVirtualDevice(virtualNetwork.id(), DID2);
ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1));
manager.createVirtualPort(virtualNetwork.id(), src.deviceId(), src.port(),
new DefaultPort(srcVirtualDevice, src.port(), true));
ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2));
manager.createVirtualPort(virtualNetwork.id(), dst.deviceId(), dst.port(),
new DefaultPort(dstVirtualDevice, dst.port(), true));
VirtualLink link1 = manager.createVirtualLink(virtualNetwork.id(), src, dst);
VirtualLink link2 = manager.createVirtualLink(virtualNetwork.id(), dst, src);
......@@ -107,12 +114,12 @@ public class VirtualNetworkLinkServiceTest extends TestDeviceParams {
Iterator<Link> it = linkService.getLinks().iterator();
assertEquals("The link set size did not match.", 2, Iterators.size(it));
// test the getActiveLinks() method where all links are ACTIVE
// test the getActiveLinks() method where all links are INACTIVE
Iterator<Link> it2 = linkService.getActiveLinks().iterator();
assertEquals("The link set size did not match.", 2, Iterators.size(it2));
assertEquals("The link set size did not match.", 0, Iterators.size(it2));
// test the getActiveLinks() method where one link is ACTIVE
virtualNetworkManagerStore.updateLink(link1, link1.tunnelId(), Link.State.INACTIVE);
virtualNetworkManagerStore.updateLink(link1, link1.tunnelId(), Link.State.ACTIVE);
Iterator<Link> it3 = linkService.getActiveLinks().iterator();
assertEquals("The link set size did not match.", 1, Iterators.size(it3));
......
......@@ -31,6 +31,7 @@ import org.onosproject.incubator.net.virtual.VirtualLink;
import org.onosproject.incubator.net.virtual.VirtualNetwork;
import org.onosproject.incubator.store.virtual.impl.DistributedVirtualNetworkStore;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultPort;
import org.onosproject.net.DeviceId;
import org.onosproject.net.DisjointPath;
import org.onosproject.net.Link;
......@@ -108,11 +109,29 @@ public class VirtualNetworkTopologyServiceTest extends TestDeviceParams {
manager.createVirtualDevice(virtualNetwork.id(), DID4);
ConnectPoint cp1 = new ConnectPoint(virtualDevice1.id(), PortNumber.portNumber(1));
manager.createVirtualPort(virtualNetwork.id(), cp1.deviceId(), cp1.port(),
new DefaultPort(virtualDevice1, cp1.port(), true));
ConnectPoint cp2 = new ConnectPoint(virtualDevice1.id(), PortNumber.portNumber(2));
manager.createVirtualPort(virtualNetwork.id(), cp2.deviceId(), cp2.port(),
new DefaultPort(virtualDevice1, cp2.port(), true));
ConnectPoint cp3 = new ConnectPoint(virtualDevice2.id(), PortNumber.portNumber(3));
manager.createVirtualPort(virtualNetwork.id(), cp3.deviceId(), cp3.port(),
new DefaultPort(virtualDevice2, cp3.port(), true));
ConnectPoint cp4 = new ConnectPoint(virtualDevice2.id(), PortNumber.portNumber(4));
manager.createVirtualPort(virtualNetwork.id(), cp4.deviceId(), cp4.port(),
new DefaultPort(virtualDevice2, cp4.port(), true));
ConnectPoint cp5 = new ConnectPoint(virtualDevice3.id(), PortNumber.portNumber(5));
manager.createVirtualPort(virtualNetwork.id(), cp5.deviceId(), cp5.port(),
new DefaultPort(virtualDevice3, cp5.port(), true));
ConnectPoint cp6 = new ConnectPoint(virtualDevice3.id(), PortNumber.portNumber(6));
manager.createVirtualPort(virtualNetwork.id(), cp6.deviceId(), cp6.port(),
new DefaultPort(virtualDevice3, cp6.port(), true));
VirtualLink link1 = manager.createVirtualLink(virtualNetwork.id(), cp1, cp3);
virtualNetworkManagerStore.updateLink(link1, link1.tunnelId(), Link.State.ACTIVE);
VirtualLink link2 = manager.createVirtualLink(virtualNetwork.id(), cp3, cp1);
......@@ -177,7 +196,12 @@ public class VirtualNetworkTopologyServiceTest extends TestDeviceParams {
topology = topologyService.currentTopology();
ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1));
manager.createVirtualPort(virtualNetwork.id(), src.deviceId(), src.port(),
new DefaultPort(srcVirtualDevice, src.port(), true));
ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2));
manager.createVirtualPort(virtualNetwork.id(), dst.deviceId(), dst.port(),
new DefaultPort(dstVirtualDevice, dst.port(), true));
VirtualLink link1 = manager.createVirtualLink(virtualNetwork.id(), src, dst);
// test the isLatest() method where a new link has been added to the current topology.
......