Search in sources :

Example 1 with DefaultVirtualPort

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);
}
Also used : DeviceId(org.onosproject.net.DeviceId) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort)

Example 2 with DefaultVirtualPort

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));
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort) ConsistentMap(org.onosproject.store.service.ConsistentMap) HostLocation(org.onosproject.net.HostLocation) CoreService(org.onosproject.core.CoreService) BiFunction(java.util.function.BiFunction) PortNumber(org.onosproject.net.PortNumber) TunnelId(org.onosproject.incubator.net.tunnel.TunnelId) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) StorageService(org.onosproject.store.service.StorageService) Map(java.util.Map) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) IdGenerator(org.onosproject.core.IdGenerator) Set(java.util.Set) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) Key(org.onosproject.net.intent.Key) VirtualNetworkStoreDelegate(org.onosproject.incubator.net.virtual.VirtualNetworkStoreDelegate) DefaultVirtualLink(org.onosproject.incubator.net.virtual.DefaultVirtualLink) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink) VirtualNetworkIntent(org.onosproject.incubator.net.virtual.VirtualNetworkIntent) Optional(java.util.Optional) DefaultVirtualDevice(org.onosproject.incubator.net.virtual.DefaultVirtualDevice) DeviceId(org.onosproject.net.DeviceId) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) VirtualNetworkEvent(org.onosproject.incubator.net.virtual.VirtualNetworkEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) KryoNamespace(org.onlab.util.KryoNamespace) VirtualNetworkStore(org.onosproject.incubator.net.virtual.VirtualNetworkStore) MapEventListener(org.onosproject.store.service.MapEventListener) HashSet(java.util.HashSet) Component(org.osgi.service.component.annotations.Component) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Intent(org.onosproject.net.intent.Intent) Activate(org.osgi.service.component.annotations.Activate) HostId(org.onosproject.net.HostId) IpAddress(org.onlab.packet.IpAddress) TenantId(org.onosproject.net.TenantId) Logger(org.slf4j.Logger) SetEvent(org.onosproject.store.service.SetEvent) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) SetEventListener(org.onosproject.store.service.SetEventListener) DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) DistributedSet(org.onosproject.store.service.DistributedSet) MapEvent(org.onosproject.store.service.MapEvent) AbstractStore(org.onosproject.store.AbstractStore) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) DefaultVirtualDevice(org.onosproject.incubator.net.virtual.DefaultVirtualDevice) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) VirtualNetworkEvent(org.onosproject.incubator.net.virtual.VirtualNetworkEvent) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort)

Example 3 with DefaultVirtualPort

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;
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort) DefaultVirtualDevice(org.onosproject.incubator.net.virtual.DefaultVirtualDevice) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) VirtualNetworkEvent(org.onosproject.incubator.net.virtual.VirtualNetworkEvent) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort)

Example 4 with DefaultVirtualPort

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);
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort) ConsistentMap(org.onosproject.store.service.ConsistentMap) HostLocation(org.onosproject.net.HostLocation) CoreService(org.onosproject.core.CoreService) BiFunction(java.util.function.BiFunction) PortNumber(org.onosproject.net.PortNumber) TunnelId(org.onosproject.incubator.net.tunnel.TunnelId) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) StorageService(org.onosproject.store.service.StorageService) Map(java.util.Map) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) IdGenerator(org.onosproject.core.IdGenerator) Set(java.util.Set) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) Key(org.onosproject.net.intent.Key) VirtualNetworkStoreDelegate(org.onosproject.incubator.net.virtual.VirtualNetworkStoreDelegate) DefaultVirtualLink(org.onosproject.incubator.net.virtual.DefaultVirtualLink) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink) VirtualNetworkIntent(org.onosproject.incubator.net.virtual.VirtualNetworkIntent) Optional(java.util.Optional) DefaultVirtualDevice(org.onosproject.incubator.net.virtual.DefaultVirtualDevice) DeviceId(org.onosproject.net.DeviceId) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) VirtualNetworkEvent(org.onosproject.incubator.net.virtual.VirtualNetworkEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) KryoNamespace(org.onlab.util.KryoNamespace) VirtualNetworkStore(org.onosproject.incubator.net.virtual.VirtualNetworkStore) MapEventListener(org.onosproject.store.service.MapEventListener) HashSet(java.util.HashSet) Component(org.osgi.service.component.annotations.Component) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Intent(org.onosproject.net.intent.Intent) Activate(org.osgi.service.component.annotations.Activate) HostId(org.onosproject.net.HostId) IpAddress(org.onlab.packet.IpAddress) TenantId(org.onosproject.net.TenantId) Logger(org.slf4j.Logger) SetEvent(org.onosproject.store.service.SetEvent) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) SetEventListener(org.onosproject.store.service.SetEventListener) DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) DistributedSet(org.onosproject.store.service.DistributedSet) MapEvent(org.onosproject.store.service.MapEvent) AbstractStore(org.onosproject.store.AbstractStore) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) DefaultVirtualDevice(org.onosproject.incubator.net.virtual.DefaultVirtualDevice) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) VirtualNetworkEvent(org.onosproject.incubator.net.virtual.VirtualNetworkEvent) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort)

Aggregations

DefaultVirtualPort (org.onosproject.incubator.net.virtual.DefaultVirtualPort)4 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)4 DefaultVirtualDevice (org.onosproject.incubator.net.virtual.DefaultVirtualDevice)3 NetworkId (org.onosproject.incubator.net.virtual.NetworkId)3 VirtualNetworkEvent (org.onosproject.incubator.net.virtual.VirtualNetworkEvent)3 VirtualNetworkService (org.onosproject.incubator.net.virtual.VirtualNetworkService)3 VirtualPort (org.onosproject.incubator.net.virtual.VirtualPort)3 ConnectPoint (org.onosproject.net.ConnectPoint)3 DeviceId (org.onosproject.net.DeviceId)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Sets (com.google.common.collect.Sets)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Set (java.util.Set)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 BiFunction (java.util.function.BiFunction)2