Search in sources :

Example 11 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class OplinkOpticalDeviceDescription method parsePorts.

private List<PortDescription> parsePorts(String content) {
    List<HierarchicalConfiguration> subtrees = configsAt(content, KEY_DATA_PORTS);
    List<PortDescription> portDescriptions = Lists.newArrayList();
    for (HierarchicalConfiguration portConfig : subtrees) {
        portDescriptions.add(parsePort(portConfig));
    }
    return portDescriptions;
}
Also used : OmsPortHelper.omsPortDescription(org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription) PortDescription(org.onosproject.net.device.PortDescription) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 12 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class TapiDeviceDescriptionDiscovery method parseTapiPorts.

protected List<PortDescription> parseTapiPorts(JsonNode tapiContext) {
    List<PortDescription> ports = Lists.newArrayList();
    /*
         This annotations are used to store persistent mapping information between TAPI SIP's uuid
         and ONOS device portNumbers. This is needed to be publicly available at least within ODTN app
         when connectivity services will be sent to OLS Controller.
         */
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
    Iterator<JsonNode> iter = tapiContext.get(CONTEXT).get(SERVICE_INTERFACE_POINT).iterator();
    while (iter.hasNext()) {
        JsonNode sipAttributes = iter.next();
        if (checkValidEndpoint(sipAttributes)) {
            String uuid = sipAttributes.get(UUID).textValue();
            String[] uuidSeg = uuid.split("-");
            PortNumber portNumber = PortNumber.portNumber(uuidSeg[uuidSeg.length - 1]);
            annotations.set(UUID, uuid);
            JsonNode mcPool = sipAttributes.get(MEDIA_CHANNEL_SERVICE_INTERFACE_POINT_SPEC).get(MC_POOL);
            // We get the first OCH signal as reported by the device.
            OchSignal ochSignal = getOchSignal(mcPool).iterator().next();
            // add och port
            ports.add(ochPortDescription(portNumber, true, OduSignalType.ODU4, false, ochSignal, annotations.build()));
        } else {
            log.error("SIP {} is not valid", sipAttributes);
        }
    }
    log.debug("PortList: {}", ports);
    return ImmutableList.copyOf(ports);
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) OchPortHelper.ochPortDescription(org.onosproject.net.optical.device.OchPortHelper.ochPortDescription) PortDescription(org.onosproject.net.device.PortDescription) TapiDeviceHelper.getOchSignal(org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.getOchSignal) OchSignal(org.onosproject.net.OchSignal) JsonNode(com.fasterxml.jackson.databind.JsonNode) PortNumber(org.onosproject.net.PortNumber)

Example 13 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class ECDeviceStore method refreshDevicePortCache.

private List<DeviceEvent> refreshDevicePortCache(ProviderId providerId, DeviceId deviceId, Optional<PortNumber> portNumber) {
    Device device = devices.get(deviceId);
    checkArgument(device != null, DEVICE_NOT_FOUND, deviceId);
    List<DeviceEvent> events = Lists.newArrayList();
    Map<PortNumber, Port> ports = devicePorts.computeIfAbsent(deviceId, key -> Maps.newConcurrentMap());
    List<PortDescription> descriptions = Lists.newArrayList();
    portDescriptions.entrySet().forEach(e -> {
        PortKey key = e.getKey();
        PortDescription value = e.getValue();
        if (key.deviceId().equals(deviceId) && key.providerId().equals(providerId)) {
            if (portNumber.isPresent()) {
                if (portNumber.get().equals(key.portNumber())) {
                    descriptions.add(value);
                }
            } else {
                descriptions.add(value);
            }
        }
    });
    for (PortDescription description : descriptions) {
        final PortNumber number = description.portNumber();
        ports.compute(number, (k, existingPort) -> {
            Port newPort = composePort(device, number);
            if (existingPort == null) {
                events.add(new DeviceEvent(PORT_ADDED, device, newPort));
            } else {
                if (existingPort.isEnabled() != newPort.isEnabled() || existingPort.type() != newPort.type() || existingPort.portSpeed() != newPort.portSpeed() || !AnnotationsUtil.isEqual(existingPort.annotations(), newPort.annotations())) {
                    events.add(new DeviceEvent(PORT_UPDATED, device, newPort));
                }
            }
            return newPort;
        });
    }
    return events;
}
Also used : 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) PortDescription(org.onosproject.net.device.PortDescription) PortNumber(org.onosproject.net.PortNumber)

Example 14 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class ECDeviceStore method composePort.

/**
 * Returns a Port, merging descriptions from multiple Providers.
 *
 * @param device   device the port is on
 * @param number   port number
 * @return Port instance
 */
private Port composePort(Device device, PortNumber number) {
    Map<ProviderId, PortDescription> descriptions = Maps.newHashMap();
    portDescriptions.entrySet().forEach(entry -> {
        PortKey portKey = entry.getKey();
        if (portKey.deviceId().equals(device.id()) && portKey.portNumber().equals(number)) {
            descriptions.put(portKey.providerId(), entry.getValue());
        }
    });
    ProviderId primary = getPrimaryProviderId(device.id());
    PortDescription primaryDescription = descriptions.get(primary);
    // if no primary, assume not enabled
    boolean isEnabled = false;
    DefaultAnnotations annotations = DefaultAnnotations.builder().build();
    if (primaryDescription != null) {
        isEnabled = primaryDescription.isEnabled();
        annotations = merge(annotations, primaryDescription.annotations());
    }
    Port updated = null;
    for (Entry<ProviderId, PortDescription> e : descriptions.entrySet()) {
        if (e.getKey().equals(primary)) {
            continue;
        }
        annotations = merge(annotations, e.getValue().annotations());
        updated = buildTypedPort(device, number, isEnabled, e.getValue(), annotations);
    }
    if (primaryDescription == null) {
        return updated == null ? new DefaultPort(device, number, false, annotations) : updated;
    }
    return updated == null ? buildTypedPort(device, number, isEnabled, primaryDescription, annotations) : updated;
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) PortDescription(org.onosproject.net.device.PortDescription) DefaultPort(org.onosproject.net.DefaultPort)

Example 15 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class GossipDeviceStore method updatePortStatus.

@Override
public synchronized DeviceEvent updatePortStatus(ProviderId providerId, DeviceId deviceId, PortDescription portDescription) {
    final Timestamp newTimestamp;
    try {
        newTimestamp = deviceClockService.getTimestamp(deviceId);
    } catch (IllegalStateException e) {
        log.info("Timestamp was not available for device {}", deviceId);
        log.debug("  discarding {}", portDescription);
        // See updatePorts comment
        return null;
    }
    final Timestamped<PortDescription> deltaDesc = new Timestamped<>(portDescription, newTimestamp);
    final DeviceEvent event;
    Timestamped<PortDescription> mergedDesc;
    final Map<ProviderId, DeviceDescriptions> device = getOrCreateDeviceDescriptionsMap(deviceId);
    synchronized (device) {
        event = updatePortStatusInternal(providerId, deviceId, deltaDesc);
        mergedDesc = device.get(providerId).getPortDesc(portDescription.portNumber());
        // on delete the port is removed, thus using latest known description
        if (mergedDesc == null) {
            mergedDesc = new Timestamped<>(portDescription, newTimestamp);
        }
    }
    if (event != null) {
        log.debug("Notifying peers of a port status update topology event for providerId: {} and deviceId: {}", providerId, deviceId);
        notifyPeers(new InternalPortStatusEvent(providerId, deviceId, mergedDesc));
    }
    return event;
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceEvent(org.onosproject.net.device.DeviceEvent) PortDescription(org.onosproject.net.device.PortDescription) Timestamped(org.onosproject.store.impl.Timestamped) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp)

Aggregations

PortDescription (org.onosproject.net.device.PortDescription)81 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)41 Test (org.junit.Test)25 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)25 PortNumber (org.onosproject.net.PortNumber)24 DeviceId (org.onosproject.net.DeviceId)23 ArrayList (java.util.ArrayList)22 Port (org.onosproject.net.Port)22 DeviceEvent (org.onosproject.net.device.DeviceEvent)14 ProviderId (org.onosproject.net.provider.ProviderId)13 Device (org.onosproject.net.Device)12 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)11 DefaultPort (org.onosproject.net.DefaultPort)9 DeviceService (org.onosproject.net.device.DeviceService)9 NetconfSession (org.onosproject.netconf.NetconfSession)8 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 OduCltPortHelper.oduCltPortDescription (org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription)7 OmsPortHelper.omsPortDescription (org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription)7 OchPortHelper.ochPortDescription (org.onosproject.net.optical.device.OchPortHelper.ochPortDescription)6