use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.
the class VirtualNetworkWebResource method getVirtualPorts.
// VirtualPort
/**
* Returns all virtual network ports in a virtual device in a virtual network.
*
* @param networkId network identifier
* @param deviceId virtual device identifier
* @return 200 OK with set of virtual ports, 404 not found
* @onos.rsModel VirtualPorts
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{networkId}/devices/{deviceId}/ports")
public Response getVirtualPorts(@PathParam("networkId") long networkId, @PathParam("deviceId") String deviceId) {
NetworkId nid = NetworkId.networkId(networkId);
Iterable<VirtualPort> vports = vnetService.getVirtualPorts(nid, DeviceId.deviceId(deviceId));
return ok(encodeArray(VirtualPort.class, "ports", vports)).build();
}
use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.
the class DistributedVirtualNetworkStore method removePort.
@Override
public void removePort(NetworkId networkId, DeviceId deviceId, PortNumber portNumber) {
checkState(networkExists(networkId), "The network has not been added.");
VirtualDevice device = deviceIdVirtualDeviceMap.get(new VirtualDeviceId(networkId, deviceId));
checkNotNull(device, "The device has not been created for deviceId: " + deviceId);
if (networkIdVirtualPortSetMap.get(networkId) == null) {
log.warn("No port has been created for NetworkId: {}", networkId);
return;
}
Set<VirtualPort> virtualPortSet = new HashSet<>();
networkIdVirtualPortSetMap.get(networkId).forEach(port -> {
if (port.element().id().equals(deviceId) && port.number().equals(portNumber)) {
virtualPortSet.add(port);
}
});
if (!virtualPortSet.isEmpty()) {
AtomicBoolean portRemoved = new AtomicBoolean(false);
networkIdVirtualPortSetMap.compute(networkId, (id, existingVirtualPorts) -> {
if (existingVirtualPorts == null || existingVirtualPorts.isEmpty()) {
return new HashSet<>();
} else {
portRemoved.set(true);
return new HashSet<>(Sets.difference(existingVirtualPorts, virtualPortSet));
}
});
if (portRemoved.get()) {
virtualPortSet.forEach(virtualPort -> notifyDelegate(new VirtualNetworkEvent(VirtualNetworkEvent.Type.VIRTUAL_PORT_REMOVED, networkId, device, virtualPort)));
// Remove all the virtual links connected to this virtual port
Set<VirtualLink> existingVirtualLinks = networkIdVirtualLinkSetMap.get(networkId);
if (existingVirtualLinks != null && !existingVirtualLinks.isEmpty()) {
Set<VirtualLink> virtualLinkSet = new HashSet<>();
ConnectPoint cp = new ConnectPoint(deviceId, portNumber);
existingVirtualLinks.forEach(virtualLink -> {
if (virtualLink.src().equals(cp) || virtualLink.dst().equals(cp)) {
virtualLinkSet.add(virtualLink);
}
});
virtualLinkSet.forEach(virtualLink -> removeLink(networkId, virtualLink.src(), virtualLink.dst()));
}
// Remove all the hosts connected to this virtual port
Set<HostId> hostIdSet = new HashSet<>();
hostIdVirtualHostMap.forEach((hostId, virtualHost) -> {
if (virtualHost.location().deviceId().equals(deviceId) && virtualHost.location().port().equals(portNumber)) {
hostIdSet.add(hostId);
}
});
hostIdSet.forEach(hostId -> removeHost(networkId, hostId));
}
}
}
use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.
the class VirtualNetworkManagerTest method testRemoveAllElements.
/**
* Tests when a virtual element is removed, all the other elements depending on it are also removed.
*/
@Test
public void testRemoveAllElements() {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork1 = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
VirtualDevice virtualDevice1 = manager.createVirtualDevice(virtualNetwork1.id(), DID1);
VirtualDevice virtualDevice2 = manager.createVirtualDevice(virtualNetwork1.id(), DID2);
ConnectPoint src = new ConnectPoint(virtualDevice1.id(), PortNumber.portNumber(1));
manager.createVirtualPort(virtualNetwork1.id(), src.deviceId(), src.port(), new ConnectPoint(PHYDID1, PortNumber.portNumber(1)));
ConnectPoint dst = new ConnectPoint(virtualDevice2.id(), PortNumber.portNumber(2));
manager.createVirtualPort(virtualNetwork1.id(), dst.deviceId(), dst.port(), new ConnectPoint(PHYDID2, PortNumber.portNumber(2)));
manager.createVirtualLink(virtualNetwork1.id(), src, dst);
manager.createVirtualLink(virtualNetwork1.id(), dst, src);
ConnectPoint hostCp = new ConnectPoint(DID1, P1);
manager.createVirtualPort(virtualNetwork1.id(), hostCp.deviceId(), hostCp.port(), new ConnectPoint(PHYDID1, P1));
manager.createVirtualHost(virtualNetwork1.id(), HID1, MAC1, VLAN1, LOC1, IPSET1);
// When a virtual port is removed, all virtual links connected to it should also be removed.
manager.removeVirtualPort(virtualNetwork1.id(), DID1, PortNumber.portNumber(1));
Set<VirtualLink> virtualLinks = manager.getVirtualLinks(virtualNetwork1.id());
assertTrue("The virtual link set should be empty.", virtualLinks.isEmpty());
// When a virtual port is removed, all virtual hosts located to it should also be removed.
manager.removeVirtualPort(virtualNetwork1.id(), DID1, P1);
Set<VirtualHost> virtualHosts = manager.getVirtualHosts(virtualNetwork1.id());
assertTrue("The virtual host set should be empty.", virtualHosts.isEmpty());
manager.createVirtualPort(virtualNetwork1.id(), src.deviceId(), src.port(), new ConnectPoint(PHYDID1, PortNumber.portNumber(1)));
manager.createVirtualLink(virtualNetwork1.id(), src, dst);
manager.createVirtualLink(virtualNetwork1.id(), dst, src);
manager.createVirtualPort(virtualNetwork1.id(), hostCp.deviceId(), hostCp.port(), new ConnectPoint(PHYDID1, P1));
manager.createVirtualHost(virtualNetwork1.id(), HID1, MAC1, VLAN1, LOC1, IPSET1);
// When a virtual device is removed, all virtual ports, hosts and links depended on it should also be removed.
manager.removeVirtualDevice(virtualNetwork1.id(), DID1);
Set<VirtualPort> virtualPorts = manager.getVirtualPorts(virtualNetwork1.id(), DID1);
assertTrue("The virtual port set of DID1 should be empty", virtualPorts.isEmpty());
virtualLinks = manager.getVirtualLinks(virtualNetwork1.id());
assertTrue("The virtual link set should be empty.", virtualLinks.isEmpty());
virtualHosts = manager.getVirtualHosts(virtualNetwork1.id());
assertTrue("The virtual host set should be empty.", virtualHosts.isEmpty());
// When a tenantId is removed, all the virtual networks belonging to it should also be removed.
manager.unregisterTenantId(TenantId.tenantId(tenantIdValue1));
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
Set<VirtualNetwork> virtualNetworks = manager.getVirtualNetworks(TenantId.tenantId(tenantIdValue1));
assertNotNull("The virtual network set should not be null", virtualNetworks);
assertTrue("The virtual network set should be empty.", virtualNetworks.isEmpty());
}
Aggregations