Search in sources :

Example 46 with NetworkId

use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.

the class VirtualNetworkWebResource method removeVirtualDevice.

/**
 * Removes the virtual network device from the virtual network.
 *
 * @param networkId network identifier
 * @param deviceId  device identifier
 * @return 204 NO CONTENT
 */
@DELETE
@Path("{networkId}/devices/{deviceId}")
public Response removeVirtualDevice(@PathParam("networkId") long networkId, @PathParam("deviceId") String deviceId) {
    NetworkId nid = NetworkId.networkId(networkId);
    DeviceId did = DeviceId.deviceId(deviceId);
    vnetAdminService.removeVirtualDevice(nid, did);
    return Response.noContent().build();
}
Also used : DeviceId(org.onosproject.net.DeviceId) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 47 with NetworkId

use of org.onosproject.incubator.net.virtual.NetworkId 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)

Example 48 with NetworkId

use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.

the class SimpleVirtualGroupStore method addOrUpdateGroupEntry.

@Override
public void addOrUpdateGroupEntry(NetworkId networkId, Group group) {
    // check if this new entry is an update to an existing entry
    StoredGroupEntry existing = null;
    if (groupEntriesById.get(networkId) != null && groupEntriesById.get(networkId).get(group.deviceId()) != null) {
        existing = groupEntriesById.get(networkId).get(group.deviceId()).get(group.id());
    }
    GroupEvent event = null;
    if (existing != null) {
        synchronized (existing) {
            for (GroupBucket bucket : group.buckets().buckets()) {
                Optional<GroupBucket> matchingBucket = existing.buckets().buckets().stream().filter((existingBucket) -> (existingBucket.equals(bucket))).findFirst();
                if (matchingBucket.isPresent()) {
                    ((StoredGroupBucketEntry) matchingBucket.get()).setPackets(bucket.packets());
                    ((StoredGroupBucketEntry) matchingBucket.get()).setBytes(bucket.bytes());
                } else {
                    log.warn("addOrUpdateGroupEntry: No matching " + "buckets to update stats");
                }
            }
            existing.setLife(group.life());
            existing.setPackets(group.packets());
            existing.setBytes(group.bytes());
            if (existing.state() == Group.GroupState.PENDING_ADD) {
                existing.setState(Group.GroupState.ADDED);
                event = new GroupEvent(GroupEvent.Type.GROUP_ADDED, existing);
            } else {
                if (existing.state() == Group.GroupState.PENDING_UPDATE) {
                    existing.setState(Group.GroupState.ADDED);
                }
                event = new GroupEvent(GroupEvent.Type.GROUP_UPDATED, existing);
            }
        }
    }
    if (event != null) {
        notifyDelegate(networkId, event);
    }
}
Also used : HashMap(java.util.HashMap) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) GroupOperation(org.onosproject.net.group.GroupOperation) GroupKey(org.onosproject.net.group.GroupKey) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Component(org.osgi.service.component.annotations.Component) FluentIterable(com.google.common.collect.FluentIterable) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Activate(org.osgi.service.component.annotations.Activate) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) StoredGroupBucketEntry(org.onosproject.net.group.StoredGroupBucketEntry) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) VirtualNetworkGroupStore(org.onosproject.incubator.net.virtual.VirtualNetworkGroupStore) GroupEvent(org.onosproject.net.group.GroupEvent) Sets(com.google.common.collect.Sets) List(java.util.List) GroupStoreDelegate(org.onosproject.net.group.GroupStoreDelegate) GroupId(org.onosproject.core.GroupId) GroupBuckets(org.onosproject.net.group.GroupBuckets) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) GroupBucket(org.onosproject.net.group.GroupBucket) StoredGroupBucketEntry(org.onosproject.net.group.StoredGroupBucketEntry) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupEvent(org.onosproject.net.group.GroupEvent)

Example 49 with NetworkId

use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.

the class SimpleVirtualMastershipStore method getMastership.

@Override
public MastershipInfo getMastership(NetworkId networkId, DeviceId deviceId) {
    Map<DeviceId, NodeId> masterMap = getMasterMap(networkId);
    Map<DeviceId, AtomicInteger> termMap = getTermMap(networkId);
    Map<DeviceId, List<NodeId>> backups = getBackups(networkId);
    ImmutableMap.Builder<NodeId, MastershipRole> roleBuilder = ImmutableMap.builder();
    NodeId master = masterMap.get(deviceId);
    if (master != null) {
        roleBuilder.put(master, MastershipRole.MASTER);
    }
    backups.getOrDefault(deviceId, Collections.emptyList()).forEach(nodeId -> roleBuilder.put(nodeId, MastershipRole.STANDBY));
    clusterService.getNodes().stream().filter(node -> !masterMap.containsValue(node.id())).filter(node -> !backups.get(deviceId).contains(node.id())).forEach(node -> roleBuilder.put(node.id(), MastershipRole.NONE));
    return new MastershipInfo(termMap.getOrDefault(deviceId, new AtomicInteger(NOTHING)).get(), Optional.ofNullable(master), roleBuilder.build());
}
Also used : HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MastershipEvent(org.onosproject.mastership.MastershipEvent) Component(org.osgi.service.component.annotations.Component) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Node(org.onosproject.cluster.Node) VersionService(org.onosproject.core.VersionService) BACKUPS_CHANGED(org.onosproject.mastership.MastershipEvent.Type.BACKUPS_CHANGED) Map(java.util.Map) Version(org.onosproject.core.Version) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Activate(org.osgi.service.component.annotations.Activate) IpAddress(org.onlab.packet.IpAddress) NodeId(org.onosproject.cluster.NodeId) ClusterEventListener(org.onosproject.cluster.ClusterEventListener) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) MASTER_CHANGED(org.onosproject.mastership.MastershipEvent.Type.MASTER_CHANGED) ImmutableMap(com.google.common.collect.ImmutableMap) MastershipRole(org.onosproject.net.MastershipRole) Deactivate(org.osgi.service.component.annotations.Deactivate) VirtualNetworkMastershipStore(org.onosproject.incubator.net.virtual.VirtualNetworkMastershipStore) MastershipInfo(org.onosproject.mastership.MastershipInfo) Set(java.util.Set) Instant(java.time.Instant) MastershipTerm(org.onosproject.mastership.MastershipTerm) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) List(java.util.List) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) RoleInfo(org.onosproject.cluster.RoleInfo) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) MastershipStoreDelegate(org.onosproject.mastership.MastershipStoreDelegate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DeviceId(org.onosproject.net.DeviceId) NodeId(org.onosproject.cluster.NodeId) MastershipInfo(org.onosproject.mastership.MastershipInfo) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) MastershipRole(org.onosproject.net.MastershipRole) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 50 with NetworkId

use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.

the class SimpleVirtualMeterStore method updateMeter.

@Override
public CompletableFuture<MeterStoreResult> updateMeter(NetworkId networkId, Meter meter) {
    ConcurrentMap<MeterKey, MeterData> meters = getMetersByNetwork(networkId);
    ConcurrentMap<MeterKey, CompletableFuture<MeterStoreResult>> futures = getFuturesByNetwork(networkId);
    CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
    MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
    futures.put(key, future);
    MeterData data = new MeterData(meter, null, local);
    try {
        if (meters.computeIfPresent(key, (k, v) -> data) == null) {
            future.complete(MeterStoreResult.fail(MeterFailReason.INVALID_METER));
        }
    } catch (StorageException e) {
        future.completeExceptionally(e);
    }
    return future;
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) StorageException(org.onosproject.store.service.StorageException) DefaultMeter(org.onosproject.net.meter.DefaultMeter) MeterFeatures(org.onosproject.net.meter.MeterFeatures) CompletableFuture(java.util.concurrent.CompletableFuture) Collections2(com.google.common.collect.Collections2) MeterStoreDelegate(org.onosproject.net.meter.MeterStoreDelegate) ConcurrentMap(java.util.concurrent.ConcurrentMap) Component(org.osgi.service.component.annotations.Component) MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Activate(org.osgi.service.component.annotations.Activate) MeterFailReason(org.onosproject.net.meter.MeterFailReason) NodeId(org.onosproject.cluster.NodeId) Meter(org.onosproject.net.meter.Meter) MeterEvent(org.onosproject.net.meter.MeterEvent) Logger(org.slf4j.Logger) MeterFeaturesKey(org.onosproject.net.meter.MeterFeaturesKey) MeterOperation(org.onosproject.net.meter.MeterOperation) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Maps(com.google.common.collect.Maps) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) VirtualNetworkMeterStore(org.onosproject.incubator.net.virtual.VirtualNetworkMeterStore) TIMEOUT(org.onosproject.net.meter.MeterFailReason.TIMEOUT) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MeterKey(org.onosproject.net.meter.MeterKey) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) CompletableFuture(java.util.concurrent.CompletableFuture) StorageException(org.onosproject.store.service.StorageException)

Aggregations

NetworkId (org.onosproject.incubator.net.virtual.NetworkId)50 DeviceId (org.onosproject.net.DeviceId)23 Test (org.junit.Test)21 WebTarget (javax.ws.rs.client.WebTarget)20 Matchers.containsString (org.hamcrest.Matchers.containsString)20 HostResourceTest (org.onosproject.rest.resources.HostResourceTest)20 LinksResourceTest (org.onosproject.rest.resources.LinksResourceTest)20 ResourceTest (org.onosproject.rest.resources.ResourceTest)20 Activate (org.osgi.service.component.annotations.Activate)11 Logger (org.slf4j.Logger)11 LoggerFactory.getLogger (org.slf4j.LoggerFactory.getLogger)11 Set (java.util.Set)10 Component (org.osgi.service.component.annotations.Component)10 Deactivate (org.osgi.service.component.annotations.Deactivate)10 HashSet (java.util.HashSet)9 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)9 ConnectPoint (org.onosproject.net.ConnectPoint)9 PortNumber (org.onosproject.net.PortNumber)9 Reference (org.osgi.service.component.annotations.Reference)9 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)9