Search in sources :

Example 51 with ProviderId

use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.

the class VirtualProviderManager method registerProvider.

@Override
public synchronized void registerProvider(VirtualProvider virtualProvider) {
    checkNotNull(virtualProvider, "Provider cannot be null");
    checkState(!providers.containsKey(virtualProvider.id()), "Provider %s already registered", virtualProvider.id());
    // If the provider is a primary one, check for a conflict.
    ProviderId pid = virtualProvider.id();
    checkState(pid.isAncillary() || !providersByScheme.containsKey(pid.scheme()), "A primary provider with id %s is already registered", providersByScheme.get(pid.scheme()));
    providers.put(virtualProvider.id(), virtualProvider);
    // Register the provider by URI scheme only if it is not ancillary.
    if (!pid.isAncillary()) {
        providersByScheme.put(pid.scheme(), virtualProvider);
    }
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId)

Example 52 with ProviderId

use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.

the class DeviceCodec method decode.

/**
 * {@inheritDoc}
 *
 * Note: ProviderId is not part of JSON representation.
 *       Returned object will have random ProviderId set.
 */
@Override
public Device decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    DeviceId id = deviceId(json.get(ID).asText());
    // TODO: add providerId to JSON if we need to recover them.
    ProviderId pid = new ProviderId(id.uri().getScheme(), "DeviceCodec");
    Type type = Type.valueOf(json.get(TYPE).asText());
    String mfr = json.get(MFR).asText();
    String hw = json.get(HW).asText();
    String sw = json.get(SW).asText();
    String serial = json.get(SERIAL).asText();
    ChassisId chassisId = new ChassisId(json.get(CHASSIS_ID).asText());
    Annotations annotations = extractAnnotations(json, context);
    return new DefaultDevice(pid, id, type, mfr, hw, sw, serial, chassisId, annotations);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) Type(org.onosproject.net.Device.Type) ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) DeviceId(org.onosproject.net.DeviceId) DefaultDevice(org.onosproject.net.DefaultDevice)

Example 53 with ProviderId

use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.

the class LinkCodec method decode.

/**
 * {@inheritDoc}
 *
 * Note: ProviderId is not part of JSON representation.
 *       Returned object will have random ProviderId set.
 */
@Override
public Link decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    JsonCodec<ConnectPoint> codec = context.codec(ConnectPoint.class);
    // TODO: add providerId to JSON if we need to recover them.
    ProviderId pid = new ProviderId("json", "LinkCodec");
    ConnectPoint src = codec.decode(get(json, SRC), context);
    ConnectPoint dst = codec.decode(get(json, DST), context);
    Type type = Type.valueOf(json.get(TYPE).asText());
    Annotations annotations = extractAnnotations(json, context);
    return DefaultLink.builder().providerId(pid).src(src).dst(dst).type(type).annotations(annotations).build();
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) Type(org.onosproject.net.Link.Type) Annotations(org.onosproject.net.Annotations) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 54 with ProviderId

use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.

the class SimpleDeviceStore method updatePorts.

@Override
public List<DeviceEvent> updatePorts(ProviderId providerId, DeviceId deviceId, List<PortDescription> portDescriptions) {
    Device device = devices.get(deviceId);
    if (device == null) {
        log.debug("Device {} doesn't exist or hasn't been initialized yet", deviceId);
        return Collections.emptyList();
    }
    Map<ProviderId, DeviceDescriptions> descsMap = deviceDescs.get(deviceId);
    checkArgument(descsMap != null, DEVICE_NOT_FOUND, deviceId);
    List<DeviceEvent> events = new ArrayList<>();
    synchronized (descsMap) {
        DeviceDescriptions descs = descsMap.get(providerId);
        // every provider must provide DeviceDescription.
        checkArgument(descs != null, "Device description for Device ID %s from Provider %s was not found", deviceId, providerId);
        Map<PortNumber, Port> ports = getPortMap(deviceId);
        // Add new ports
        Set<PortNumber> processed = new HashSet<>();
        for (PortDescription portDescription : portDescriptions) {
            final PortNumber number = portDescription.portNumber();
            processed.add(portDescription.portNumber());
            final Port oldPort = ports.get(number);
            final Port newPort;
            // event suppression hook?
            // update description
            descs.putPortDesc(portDescription);
            newPort = composePort(device, number, descsMap);
            events.add(oldPort == null ? createPort(device, newPort, ports) : updatePort(device, oldPort, newPort, ports));
        }
        events.addAll(pruneOldPorts(device, ports, processed));
    }
    return FluentIterable.from(events).filter(notNull()).toList();
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) ArrayList(java.util.ArrayList) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) PortNumber(org.onosproject.net.PortNumber) HashSet(java.util.HashSet)

Example 55 with ProviderId

use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.

the class SimpleDeviceStore method composePort.

/**
 * Returns a Port, merging description given from multiple Providers.
 *
 * @param device   device the port is on
 * @param number   port number
 * @param descsMap Collection of Descriptions from multiple providers
 * @return Port instance
 */
private Port composePort(Device device, PortNumber number, Map<ProviderId, DeviceDescriptions> descsMap) {
    ProviderId primary = pickPrimaryPid(descsMap);
    DeviceDescriptions primDescs = descsMap.get(primary);
    // if no primary, assume not enabled
    // TODO: revisit this default port enabled/disabled behavior
    boolean isEnabled = false;
    DefaultAnnotations annotations = DefaultAnnotations.builder().build();
    final PortDescription portDesc = primDescs.getPortDesc(number);
    if (portDesc != null) {
        isEnabled = portDesc.isEnabled();
        annotations = merge(annotations, portDesc.annotations());
    }
    for (Entry<ProviderId, DeviceDescriptions> e : descsMap.entrySet()) {
        if (e.getKey().equals(primary)) {
            continue;
        }
        // TODO: should keep track of Description timestamp
        // and only merge conflicting keys when timestamp is newer
        // Currently assuming there will never be a key conflict between
        // providers
        // annotation merging. not so efficient, should revisit later
        final PortDescription otherPortDesc = e.getValue().getPortDesc(number);
        if (otherPortDesc != null) {
            annotations = merge(annotations, otherPortDesc.annotations());
        }
    }
    return portDesc == null ? new DefaultPort(device, number, false, annotations) : new DefaultPort(device, number, isEnabled, portDesc.type(), portDesc.portSpeed(), annotations);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) DefaultPort(org.onosproject.net.DefaultPort)

Aggregations

ProviderId (org.onosproject.net.provider.ProviderId)62 DefaultDevice (org.onosproject.net.DefaultDevice)15 DeviceId (org.onosproject.net.DeviceId)13 Tunnel (org.onosproject.incubator.net.tunnel.Tunnel)12 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)12 Device (org.onosproject.net.Device)12 PortDescription (org.onosproject.net.device.PortDescription)12 TunnelProvider (org.onosproject.incubator.net.tunnel.TunnelProvider)10 DefaultPort (org.onosproject.net.DefaultPort)10 Port (org.onosproject.net.Port)10 DeviceEvent (org.onosproject.net.device.DeviceEvent)10 MastershipBasedTimestamp (org.onosproject.store.impl.MastershipBasedTimestamp)10 PortNumber (org.onosproject.net.PortNumber)9 DeviceDescription (org.onosproject.net.device.DeviceDescription)9 Timestamp (org.onosproject.store.Timestamp)9 MultiValuedTimestamp (org.onosproject.store.service.MultiValuedTimestamp)9 WallClockTimestamp (org.onosproject.store.service.WallClockTimestamp)9 DefaultTunnel (org.onosproject.incubator.net.tunnel.DefaultTunnel)7 TunnelId (org.onosproject.incubator.net.tunnel.TunnelId)7 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)7