use of org.onosproject.net.Port 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.Port 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.Port in project onos by opennetworkinglab.
the class LumentumNetconfRoadmDiscovery method parseLumentumRoadmPorts.
/**
* Parses a configuration and returns a set of ports.
*
* @param cfg a hierarchical configuration
* @return a list of port descriptions
*/
protected List<PortDescription> parseLumentumRoadmPorts(HierarchicalConfiguration cfg) {
List<PortDescription> portDescriptions = Lists.newArrayList();
List<HierarchicalConfiguration> ports = cfg.configurationsAt(PHYSICAL_PORT);
ports.stream().forEach(pcfg -> {
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
// Load port number
PortNumber portNum = PortNumber.portNumber(pcfg.getString(DN).substring(pcfg.getString(DN).lastIndexOf(DN_PORT) + 5));
// Load port state
String maintenanceState = pcfg.getString(MAINTENANCE_STATE);
boolean isEnabled = ((maintenanceState != null) && (maintenanceState).equals(IN_SERVICE));
// Load port type (FIBER/COPPER)
Port.Type type = null;
for (Object o : pcfg.getList(PORT_EXTENSION)) {
String s = (String) o;
if (s.contains(OPTICAL_INPUT) || s.contains(OPTICAL_OUTPUT)) {
type = Port.Type.FIBER;
log.debug("Loaded OPTICAL port {}", portNum);
} else if (s.contains(PORT_ETHERNET) || s.contains(PORT_PLUGGABLE)) {
type = Port.Type.COPPER;
log.debug("Loaded PACKET port {}", portNum);
}
}
// Load port speed of Ethernet interface, expressed in Mb/s
// should be the speed of optical port
Long speed = 0L;
if (type != null) {
if (type.equals(Port.Type.COPPER)) {
String speedString = pcfg.getString(PORT_SPEED);
log.debug("--- port {} loaded speed {}", portNum, speedString);
if (speedString != null) {
if (speedString.contains("Mb")) {
speed = Long.parseLong(speedString.substring(speedString.lastIndexOf("speed_") + 6, speedString.lastIndexOf("Mb")));
}
if (speedString.contains("Gb")) {
speed = 1000 * Long.parseLong(speedString.substring(speedString.lastIndexOf("speed_") + 6, speedString.lastIndexOf("Gb")));
}
} else {
log.error("Lumentum NETCONF - Port speed of Ethernet port not correctly loaded");
}
}
} else {
log.error("Port Type not correctly loaded");
}
/**
* Setting the reverse port value for the unidirectional ports.
*
* In this device each port includes an input fiber and an output fiber.
* The 20 input fibers are numbered from MIN_MUX_PORT = 4101 to MAX_MUX_PORT = 4120.
* The 20 output fibers are numbered from MIN_DEM_PORT = 5201 to MAX_DEM_PORT = 5220.
*
* Where port 520x is always the reverse of 410x.
*/
if ((portNum.toLong() >= MIN_MUX_PORT) && (portNum.toLong() <= MAX_MUX_PORT)) {
Long reversePortId = portNum.toLong() + DELTA_MUX_DEM_PORT;
annotations.set(OpticalPathIntent.REVERSE_PORT_ANNOTATION_KEY, reversePortId.toString());
}
if ((portNum.toLong() >= MIN_DEM_PORT) && (portNum.toLong() <= MAX_DEM_PORT)) {
Long reversePortId = portNum.toLong() - DELTA_MUX_DEM_PORT;
annotations.set(OpticalPathIntent.REVERSE_PORT_ANNOTATION_KEY, reversePortId.toString());
}
// Load other information
pcfg.getKeys().forEachRemaining(k -> {
if (!k.contains(DN) && !k.contains(PORT_SPEED) && !k.contains(PORT_EXTENSION) && !k.contains(MAINTENANCE_STATE)) {
String value = pcfg.getString(k);
if (!value.isEmpty()) {
k = StringUtils.replaceEach(k, new String[] { "loteeth:", "lotep:", "lotepopt:", "config.", "=", ":", "state." }, new String[] { "", "", "", "", "", "", "" });
annotations.set(k, value);
// To visualize port name in the ROADM app GUI
if (k.equals(PORT_NAME)) {
annotations.set(AnnotationKeys.PORT_NAME, value);
}
}
}
});
log.debug("Lumentum NETCONF - retrieved port {},{},{},{},{}", portNum, isEnabled, type, speed, annotations.build());
if ((type == Port.Type.FIBER) && ((annotations.build().value(AnnotationKeys.PORT_NAME)).contains(MUX_PORT_NAME) || (annotations.build().value(AnnotationKeys.PORT_NAME)).contains(DEMUX_PORT_NAME) || (annotations.build().value(AnnotationKeys.PORT_NAME)).contains(LINE_PORT_NAME))) {
// These are the ports supporting OchSignals
portDescriptions.add(omsPortDescription(portNum, isEnabled, START_CENTER_FREQ_50, END_CENTER_FREQ_50, CHANNEL_SPACING_50.frequency(), annotations.build()));
} else {
// These are COPPER ports, or FIBER ports not supporting OchSignals
DefaultPortDescription.Builder portDescriptionBuilder = DefaultPortDescription.builder();
portDescriptionBuilder.withPortNumber(portNum).isEnabled(isEnabled).type(type).portSpeed(speed).annotations(annotations.build());
portDescriptions.add(portDescriptionBuilder.build());
}
});
return portDescriptions;
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class LumentumSdnRoadmFlowRuleProgrammable method removeFlowRules.
@Override
public Collection<FlowRule> removeFlowRules(Collection<FlowRule> rules) {
try {
snmp = new LumentumSnmpDevice(data().deviceId());
} catch (IOException e) {
log.error("Failed to connect to device: ", e);
}
// Line ports
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(data().deviceId());
List<PortNumber> linePorts = ports.subList(ports.size() - 2, ports.size()).stream().map(p -> p.number()).collect(Collectors.toList());
// Apply the valid rules on the device
Collection<FlowRule> removed = rules.stream().map(r -> new CrossConnectFlowRule(r, linePorts)).filter(xc -> removeCrossConnect(xc)).collect(Collectors.toList());
// Remove flow rule from cache
CrossConnectCache cache = this.handler().get(CrossConnectCache.class);
removed.forEach(xc -> cache.remove(Objects.hash(data().deviceId(), xc.selector(), xc.treatment())));
return removed;
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class LumentumSdnRoadmFlowRuleProgrammable method applyFlowRules.
@Override
public Collection<FlowRule> applyFlowRules(Collection<FlowRule> rules) {
try {
snmp = new LumentumSnmpDevice(data().deviceId());
} catch (IOException e) {
log.error("Failed to connect to device: ", e);
}
// Line ports
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(data().deviceId());
List<PortNumber> linePorts = ports.subList(ports.size() - 2, ports.size()).stream().map(p -> p.number()).collect(Collectors.toList());
// Apply the valid rules on the device
Collection<FlowRule> added = rules.stream().map(r -> new CrossConnectFlowRule(r, linePorts)).filter(xc -> installCrossConnect(xc)).collect(Collectors.toList());
// Cache the cookie/priority
CrossConnectCache cache = this.handler().get(CrossConnectCache.class);
added.forEach(xc -> cache.set(Objects.hash(data().deviceId(), xc.selector(), xc.treatment()), xc.id(), xc.priority()));
return added;
}
Aggregations