use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class CzechLightDiscovery method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
NetconfSession session = getNetconfSession();
if (session == null) {
log.error("Cannot request NETCONF session for {}", data().deviceId());
return null;
}
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
final var noDevice = new DefaultDeviceDescription(handler().data().deviceId().uri(), Device.Type.OTHER, null, null, null, null, null, annotations.build());
try {
Boolean isLineDegree = false, isAddDrop = false, isCoherentAddDrop = false, isInlineAmp = false;
var data = doGetXPath(getNetconfSession(), YANGLIB_XML_PREFIX, YANGLIB_XMLNS, YANGLIB_XPATH_FILTER);
if (!data.containsKey(YANGLIB_KEY_REVISION)) {
log.error("Not talking to a supported CzechLight device, is that a teapot?");
return noDevice;
}
final var revision = data.getString(YANGLIB_KEY_REVISION);
if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_ROADM_DEVICE)) {
if (!revision.equals(MOD_ROADM_DEVICE_DATE)) {
log.error("Revision mismatch for YANG module {}: got {}", MOD_ROADM_DEVICE, revision);
return noDevice;
}
final var features = data.getStringArray(YANGLIB_PATH_QUERY_FEATURES);
isLineDegree = Arrays.stream(features).anyMatch(s -> s.equals(MOD_ROADM_FEATURE_LINE_DEGREE));
isAddDrop = Arrays.stream(features).anyMatch(s -> s.equals(MOD_ROADM_FEATURE_FLEX_ADD_DROP));
if (!isLineDegree && !isAddDrop) {
log.error("Device type not recognized, but {} YANG model is present. Reported YANG features: {}", MOD_ROADM_DEVICE, String.join(", ", features));
return noDevice;
}
} else if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_COHERENT_A_D)) {
if (!revision.equals(MOD_COHERENT_A_D_DATE)) {
log.error("Revision mismatch for YANG module {}: got {}", MOD_COHERENT_A_D, revision);
return noDevice;
}
isCoherentAddDrop = true;
} else if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_INLINE_AMP)) {
if (!revision.equals(MOD_INLINE_AMP_DATE)) {
log.error("Revision mismatch for YANG module {}: got {}", MOD_INLINE_AMP, revision);
return noDevice;
}
isInlineAmp = true;
}
if (isLineDegree) {
log.info("Talking to a Line/Degree ROADM node");
annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.LINE_DEGREE.toString());
} else if (isAddDrop) {
log.info("Talking to an Add/Drop ROADM node");
annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.ADD_DROP_FLEX.toString());
} else if (isCoherentAddDrop) {
log.info("Talking to a Coherent Add/Drop ROADM node");
annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.COHERENT_ADD_DROP.toString());
} else if (isInlineAmp) {
log.info("Talking to an inline ampifier, not a ROADM, but we will fake it as a ROADM for now");
annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.INLINE_AMP.toString());
} else {
log.error("Device type not recognized");
return noDevice;
}
} catch (NetconfException e) {
log.error("Cannot request ietf-yang-library data", e);
return noDevice;
}
// FIXME: initialize these
String vendor = "CzechLight";
String hwVersion = "n/a";
String swVersion = "n/a";
String serialNumber = "n/a";
ChassisId chassisId = null;
return new DefaultDeviceDescription(handler().data().deviceId().uri(), Device.Type.ROADM, vendor, hwVersion, swVersion, serialNumber, chassisId, annotations.build());
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class CzechLightFlowRuleProgrammable method getFlowEntries.
@Override
public Collection<FlowEntry> getFlowEntries() {
if (deviceType() == CzechLightDiscovery.DeviceType.INLINE_AMP || deviceType() == CzechLightDiscovery.DeviceType.COHERENT_ADD_DROP) {
final var data = getConnectionCache().get(data().deviceId());
if (data == null) {
return new ArrayList<>();
}
return data.stream().map(rule -> new DefaultFlowEntry(rule)).collect(Collectors.toList());
}
HierarchicalConfiguration xml;
try {
xml = doGetSubtree(CzechLightDiscovery.CHANNEL_DEFS_FILTER + CzechLightDiscovery.MC_ROUTING_FILTER);
} catch (NetconfException e) {
log.error("Cannot read data from NETCONF: {}", e);
return new ArrayList<>();
}
final var allChannels = MediaChannelDefinition.parseChannelDefinitions(xml);
Collection<FlowEntry> list = new ArrayList<>();
final var allMCs = xml.configurationsAt("data.media-channels");
allMCs.stream().map(cfg -> confToMCRouting(ELEMENT_ADD, allChannels, cfg)).filter(Objects::nonNull).forEach(flow -> {
log.debug("{}: found ADD: {}", data().deviceId(), flow.toString());
list.add(new DefaultFlowEntry(asFlowRule(Direction.ADD, flow), FlowEntry.FlowEntryState.ADDED));
});
allMCs.stream().map(cfg -> confToMCRouting(ELEMENT_DROP, allChannels, cfg)).filter(Objects::nonNull).forEach(flow -> {
log.debug("{}: found DROP: {}", data().deviceId(), flow.toString());
list.add(new DefaultFlowEntry(asFlowRule(Direction.DROP, flow), FlowEntry.FlowEntryState.ADDED));
});
return list;
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class CzechLightFlowRuleProgrammable method removeFlowRules.
@Override
public Collection<FlowRule> removeFlowRules(Collection<FlowRule> rules) {
if (deviceType() == CzechLightDiscovery.DeviceType.INLINE_AMP || deviceType() == CzechLightDiscovery.DeviceType.COHERENT_ADD_DROP) {
rules.forEach(rule -> {
log.debug("{}: asked to remove {} (whole C-band is always forwarded by the HW)", data().deviceId(), rule);
getConnectionCache().remove(data().deviceId(), rule);
});
return rules;
}
HierarchicalConfiguration xml;
try {
xml = doGetSubtree(CzechLightDiscovery.CHANNEL_DEFS_FILTER + CzechLightDiscovery.MC_ROUTING_FILTER);
} catch (NetconfException e) {
log.error("Cannot read data from NETCONF: {}", e);
return new ArrayList<>();
}
final var allChannels = MediaChannelDefinition.parseChannelDefinitions(xml);
var hopefullyRemoved = new ArrayList<FlowRule>();
// temporary store because both ADD and DROP must go into the same <media-channel> list item
var changes = new TreeMap<String, String>();
rules.forEach(rule -> {
final String element = inputPortFromFlow(rule).toLong() == CzechLightDiscovery.PORT_COMMON ? ELEMENT_DROP : ELEMENT_ADD;
final var och = ochSignalFromFlow(rule);
final var channel = allChannels.entrySet().stream().filter(entry -> MediaChannelDefinition.mcMatches(entry, och)).findAny().orElse(null);
if (channel == null) {
log.error("Cannot find what channel to remove for the following flow rule at {}:", data().deviceId());
rule.selector().criteria().forEach(criteria -> log.error(" criteria {}", criteria.toString()));
rule.treatment().allInstructions().forEach(instruction -> log.error(" instruction {}", instruction.toString()));
} else {
log.info("{}: Removing {} MC {}", data().deviceId(), element, channel.getKey());
changes.put(channel.getKey(), changes.getOrDefault(channel.getKey(), "") + "<" + element + " nc:operation=\"remove\"/>");
hopefullyRemoved.add(rule);
}
});
if (!hopefullyRemoved.isEmpty()) {
var sb = new StringBuilder();
changes.forEach((channel, data) -> {
sb.append(CzechLightDiscovery.XML_MC_OPEN);
sb.append("<channel>");
sb.append(channel);
sb.append("</channel>");
sb.append(data);
sb.append(CzechLightDiscovery.XML_MC_CLOSE);
});
doEditConfig(NETCONF_OP_NONE, sb.toString());
}
return hopefullyRemoved;
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class CzechLightPowerConfig method setTargetPower.
// Used by the ROADM app to set the "attenuation" parameter
@Override
public void setTargetPower(PortNumber port, T component, double power) {
switch(deviceType()) {
case LINE_DEGREE:
case ADD_DROP_FLEX:
if (!(component instanceof OchSignal)) {
log.error("Cannot set target power on anything but a Media Channel");
return;
}
HierarchicalConfiguration xml;
try {
xml = doGetSubtree(CzechLightDiscovery.CHANNEL_DEFS_FILTER + CzechLightDiscovery.MC_ROUTING_FILTER);
} catch (NetconfException e) {
log.error("Cannot read data from NETCONF: {}", e);
return;
}
final var allChannels = MediaChannelDefinition.parseChannelDefinitions(xml);
final var och = ((OchSignal) component);
final var channel = allChannels.entrySet().stream().filter(entry -> MediaChannelDefinition.mcMatches(entry, och)).findAny().orElse(null);
if (channel == null) {
log.error("Cannot map OCh definition {} to a channel from the channel plan", och);
return;
}
final String element = port.toLong() == CzechLightDiscovery.PORT_COMMON ? "add" : "drop";
log.debug("{}: setting power for MC {} to {}", data().deviceId(), channel.getKey().toUpperCase(), power);
var sb = new StringBuilder();
sb.append(CzechLightDiscovery.XML_MC_OPEN);
sb.append("<channel>");
sb.append(channel.getKey());
sb.append("</channel>");
sb.append("<");
sb.append(element);
sb.append("><power>");
sb.append(power);
sb.append("</power></");
sb.append(element);
sb.append(">");
sb.append(CzechLightDiscovery.XML_MC_CLOSE);
doEditConfig("merge", sb.toString());
return;
default:
log.error("Target power is only supported on WSS-based devices");
return;
}
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class Ciena5170DeviceDescription method getLinks.
@Override
public Set<LinkDescription> getLinks() {
log.debug("LINKS CHECKING ...");
Set<LinkDescription> links = new HashSet<LinkDescription>();
DeviceId deviceId = handler().data().deviceId();
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
if (controller == null || controller.getDevicesMap() == null || controller.getDevicesMap().get(deviceId) == null) {
log.warn("NETCONF session to device {} not yet established, cannot load links, will be retried", deviceId);
return links;
}
NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
try {
DeviceService deviceService = this.handler().get(DeviceService.class);
Iterable<Device> devices = deviceService.getAvailableDevices();
Map<String, Device> lookup = new HashMap<String, Device>();
for (Device d : devices) {
lookup.put(d.chassisId().toString().toUpperCase(), d);
}
Node logicalPorts = TEMPLATE_MANAGER.doRequest(session, "link-info");
XPath xp = XPathFactory.newInstance().newXPath();
NodeList ifaces = (NodeList) xp.evaluate("interfaces/interface", logicalPorts, XPathConstants.NODESET);
int count = ifaces.getLength();
Node iface;
Node destChassis;
for (int i = 0; i < count; i += 1) {
iface = ifaces.item(i);
if (xp.evaluate("config/type/text()", iface).equals("ettp")) {
destChassis = (Node) xp.evaluate("state/lldp-remote-port-operational/chassis-id", iface, XPathConstants.NODE);
if (destChassis != null) {
Device dest = lookup.get(destChassis.getTextContent().toUpperCase());
if (dest != null) {
links.add(new DefaultLinkDescription(new ConnectPoint(dest.id(), PortNumber.portNumber(xp.evaluate("state/lldp-remote-port-operational/port-id/text()", iface))), new ConnectPoint(deviceId, PortNumber.portNumber(xp.evaluate("name/text()", iface))), Link.Type.DIRECT, true));
} else {
log.warn("DEST chassisID not found: chassis {} port {}", destChassis.getTextContent().toUpperCase(), xp.evaluate("name/text()", iface));
}
} else {
log.debug("NO LINK for {}", xp.evaluate("name/text()", iface));
}
}
}
} catch (NetconfException | XPathExpressionException e) {
log.error("Unable to retrieve links for device {}, {}", deviceId, e);
}
return links;
}
Aggregations