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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations