use of org.onosproject.incubator.net.virtual.VirtualNetworkEvent in project onos by opennetworkinglab.
the class DistributedVirtualNetworkStore method bindPort.
@Override
public void bindPort(NetworkId networkId, DeviceId deviceId, PortNumber portNumber, ConnectPoint realizedBy) {
Set<VirtualPort> virtualPortSet = networkIdVirtualPortSetMap.get(networkId);
Optional<VirtualPort> virtualPortOptional = virtualPortSet.stream().filter(p -> p.element().id().equals(deviceId) && p.number().equals(portNumber)).findFirst();
checkState(virtualPortOptional.isPresent(), "The virtual port has not been added.");
VirtualDevice device = deviceIdVirtualDeviceMap.get(new VirtualDeviceId(networkId, deviceId));
checkNotNull(device, "The device has not been created for deviceId: " + deviceId);
VirtualPort vPort = virtualPortOptional.get();
virtualPortSet.remove(vPort);
vPort = new DefaultVirtualPort(networkId, device, portNumber, realizedBy);
virtualPortSet.add(vPort);
networkIdVirtualPortSetMap.put(networkId, virtualPortSet);
notifyDelegate(new VirtualNetworkEvent(VirtualNetworkEvent.Type.VIRTUAL_PORT_UPDATED, networkId, device, vPort));
}
use of org.onosproject.incubator.net.virtual.VirtualNetworkEvent in project onos by opennetworkinglab.
the class DistributedVirtualNetworkStore method addPort.
@Override
public VirtualPort addPort(NetworkId networkId, DeviceId deviceId, PortNumber portNumber, ConnectPoint realizedBy) {
checkState(networkExists(networkId), "The network has not been added.");
Set<VirtualPort> virtualPortSet = networkIdVirtualPortSetMap.get(networkId);
if (virtualPortSet == null) {
virtualPortSet = new HashSet<>();
}
VirtualDevice device = deviceIdVirtualDeviceMap.get(new VirtualDeviceId(networkId, deviceId));
checkNotNull(device, "The device has not been created for deviceId: " + deviceId);
checkState(!virtualPortExists(networkId, deviceId, portNumber), "The requested Port Number has been added.");
VirtualPort virtualPort = new DefaultVirtualPort(networkId, device, portNumber, realizedBy);
virtualPortSet.add(virtualPort);
networkIdVirtualPortSetMap.put(networkId, virtualPortSet);
notifyDelegate(new VirtualNetworkEvent(VirtualNetworkEvent.Type.VIRTUAL_PORT_ADDED, networkId, device, virtualPort));
return virtualPort;
}
use of org.onosproject.incubator.net.virtual.VirtualNetworkEvent in project onos by opennetworkinglab.
the class DistributedVirtualNetworkStore method updatePortState.
@Override
public void updatePortState(NetworkId networkId, DeviceId deviceId, PortNumber portNumber, boolean isEnabled) {
checkState(networkExists(networkId), "No network with NetworkId %s exists.", networkId);
VirtualDevice device = deviceIdVirtualDeviceMap.get(new VirtualDeviceId(networkId, deviceId));
checkNotNull(device, "No device %s exists in NetworkId: %s", deviceId, networkId);
Set<VirtualPort> virtualPortSet = networkIdVirtualPortSetMap.get(networkId);
checkNotNull(virtualPortSet, "No port has been created for NetworkId: %s", networkId);
Optional<VirtualPort> virtualPortOptional = virtualPortSet.stream().filter(p -> p.element().id().equals(deviceId) && p.number().equals(portNumber)).findFirst();
checkState(virtualPortOptional.isPresent(), "The virtual port has not been added.");
VirtualPort oldPort = virtualPortOptional.get();
if (oldPort.isEnabled() == isEnabled) {
log.debug("No change in port state - port not updated");
return;
}
VirtualPort newPort = new DefaultVirtualPort(networkId, device, portNumber, isEnabled, oldPort.realizedBy());
virtualPortSet.remove(oldPort);
virtualPortSet.add(newPort);
networkIdVirtualPortSetMap.put(networkId, virtualPortSet);
notifyDelegate(new VirtualNetworkEvent(VirtualNetworkEvent.Type.VIRTUAL_PORT_UPDATED, networkId, device, newPort));
log.debug("port state changed from {} to {}", oldPort.isEnabled(), isEnabled);
}
use of org.onosproject.incubator.net.virtual.VirtualNetworkEvent 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));
}
}
}
Aggregations