use of org.onosproject.incubator.net.virtual.DefaultVirtualPort in project onos by opennetworkinglab.
the class VirtualPortCodec method decode.
@Override
public VirtualPort decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
NetworkId nId = NetworkId.networkId(Long.parseLong(extractMember(NETWORK_ID, json)));
DeviceId dId = DeviceId.deviceId(extractMember(DEVICE_ID, json));
VirtualNetworkService vnetService = context.getService(VirtualNetworkService.class);
Set<VirtualDevice> vDevs = vnetService.getVirtualDevices(nId);
VirtualDevice vDev = vDevs.stream().filter(virtualDevice -> virtualDevice.id().equals(dId)).findFirst().orElse(null);
nullIsIllegal(vDev, dId.toString() + INVALID_VIRTUAL_DEVICE);
PortNumber portNum = PortNumber.portNumber(extractMember(PORT_NUM, json));
DeviceId physDId = DeviceId.deviceId(extractMember(PHYS_DEVICE_ID, json));
PortNumber physPortNum = PortNumber.portNumber(extractMember(PHYS_PORT_NUM, json));
ConnectPoint realizedBy = new ConnectPoint(physDId, physPortNum);
return new DefaultVirtualPort(nId, vDev, portNum, realizedBy);
}
use of org.onosproject.incubator.net.virtual.DefaultVirtualPort 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.DefaultVirtualPort 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.DefaultVirtualPort 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);
}
Aggregations