use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class NetconfConfigGetter method getConfiguration.
@Override
public String getConfiguration(String type) {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
DeviceId ofDeviceId = handler.data().deviceId();
Preconditions.checkNotNull(controller, "Netconf controller is null");
try {
return controller.getDevicesMap().get(ofDeviceId).getSession().getConfig(DatastoreId.datastore(type));
} catch (NetconfException e) {
log.error("Configuration could not be retrieved {}", e.getMessage());
}
return UNABLE_TO_READ_CONFIG;
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class NokiaOpenConfigDeviceDiscovery method discoverPortDetails.
@Override
public List<PortDescription> discoverPortDetails() {
DeviceId did = data().deviceId();
XMLConfiguration cfg = new XMLConfiguration();
NetconfSession ns = getNetconfSessionAndLogin(did, USER_NAME, PASSWORD);
if (ns == null) {
log.error("discoverPorts called with null session for {}", did);
return ImmutableList.of();
}
log.info("Discovering ports details {}", handler().data().deviceId());
try {
String reply = ns.requestSync(buildGetPlatformComponentsRpc());
String data = getDataOfRpcReply(reply);
if (data == null) {
log.error("No valid response found from {}:\n{}", did, reply);
return ImmutableList.of();
}
cfg.load(CharSource.wrap(data).openStream());
try {
ns.startSubscription();
log.info("Started subscription");
} catch (NetconfException e) {
log.error("NETCONF exception caught on {} when the subscription started \n {}", data().deviceId(), e);
}
return discoverPorts(cfg);
} catch (Exception e) {
log.error("Error discovering port details on {}", data().deviceId(), e);
return ImmutableList.of();
}
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class OpenRoadmDeviceDescription method discoverDeviceDetails.
/**
* Returns a DeviceDescription with Device info.
*
* @return DeviceDescription or null
*/
@Override
public DeviceDescription discoverDeviceDetails() {
boolean defaultAvailable = true;
NetconfDevice ncDevice = getNetconfDevice();
if (ncDevice == null) {
log.error("ONOS Error: Device reachable, deviceID {} is not in Map", did());
return null;
}
DefaultAnnotations.Builder annotationsBuilder = DefaultAnnotations.builder();
// Some defaults
String vendor = "UNKNOWN";
String hwVersion = "2.2.0";
String swVersion = "2.2.0";
String serialNumber = "0x0000";
String chassisId = "0";
String nodeType = "rdm";
// Get the session, if null, at least we can use the defaults.
NetconfSession session = getNetconfSession(did());
if (session != null) {
try {
String reply = session.rpc(getDeviceDetailsBuilder()).get();
XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
String nodeId = xconf.getString("data.org-openroadm-device.info.node-id", "");
if (nodeId.equals("")) {
log.error("[OPENROADM] {} org-openroadm-device node-id undefined, returning", did());
return null;
}
annotationsBuilder.set(AnnotationKeys.OPENROADM_NODEID, nodeId);
nodeType = xconf.getString("data.org-openroadm-device.info.node-type", "");
if (nodeType.equals("")) {
log.error("[OPENROADM] {} empty node-type", did());
return null;
}
vendor = xconf.getString("data.org-openroadm-device.info.vendor", vendor);
hwVersion = xconf.getString("data.org-openroadm-device.info.model", hwVersion);
swVersion = xconf.getString("data.org-openroadm-device.info.softwareVersion", swVersion);
serialNumber = xconf.getString("data.org-openroadm-device.info.serial-id", serialNumber);
chassisId = xconf.getString("data.org-openroadm-device.info.node-number", chassisId);
// GEOLOCATION
String longitudeStr = xconf.getString("data.org-openroadm-device.info.geoLocation.longitude");
String latitudeStr = xconf.getString("data.org-openroadm-device.info.geoLocation.latitude");
if (longitudeStr != null && latitudeStr != null) {
annotationsBuilder.set(org.onosproject.net.AnnotationKeys.LONGITUDE, longitudeStr).set(org.onosproject.net.AnnotationKeys.LATITUDE, latitudeStr);
}
} catch (NetconfException | InterruptedException | ExecutionException e) {
log.error("[OPENROADM] {} exception", did());
return null;
}
} else {
log.debug("[OPENROADM] - No session {}", did());
}
log.debug("[OPENROADM] {} - VENDOR {} HWVERSION {} SWVERSION {} SERIAL {} CHASSIS {}", did(), vendor, hwVersion, swVersion, serialNumber, chassisId);
ChassisId cid = new ChassisId(Long.valueOf(chassisId, 10));
/*
* OpenROADM defines multiple devices (node types). This driver has been tested with
* ROADMS, (node type, "rdm"). Other devices can also be discovered, and this code is here
* for future developments - untested - it is likely that the XML documents
* are model specific.
*/
org.onosproject.net.Device.Type type;
if (nodeType.equals("rdm")) {
type = org.onosproject.net.Device.Type.ROADM;
} else if (nodeType.equals("ila")) {
type = org.onosproject.net.Device.Type.OPTICAL_AMPLIFIER;
} else if (nodeType.equals("xpdr")) {
type = org.onosproject.net.Device.Type.TERMINAL_DEVICE;
} else if (nodeType.equals("extplug")) {
type = org.onosproject.net.Device.Type.OTHER;
} else {
log.error("[OPENROADM] {} unsupported node-type", did());
return null;
}
DeviceDescription desc = new DefaultDeviceDescription(did().uri(), type, vendor, hwVersion, swVersion, serialNumber, cid, defaultAvailable, annotationsBuilder.build());
return desc;
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class OpenRoadmDeviceDescription method getCircuitPackByName.
/**
* Get config and status info for a specific circuit pack as a
* list of XML hierarchical configs.
* @param session the NETConf session to the OpenROADM device.
* @param cpName the name of the requested circuit-pack
* @return the hierarchical conf. for the circuit pack.
*/
HierarchicalConfiguration getCircuitPackByName(NetconfSession session, String cpName) {
try {
String reply = session.rpc(getDeviceCircuitPackByNameBuilder(cpName)).get();
XMLConfiguration cpConf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
cpConf.setExpressionEngine(new XPathExpressionEngine());
List<HierarchicalConfiguration> cPacks = cpConf.configurationsAt("/data/org-openroadm-device/circuit-packs");
// It shouldn't happen they are > 1
if (cPacks.size() > 1) {
log.warn("[OPENROADM] More than one circuit pack with the same name. Using first one");
}
return cPacks.get(0);
} catch (NetconfException | InterruptedException | ExecutionException e) {
log.error("[OPENROADM] {} exception getting circuit pack {}: {}", did(), cpName, e);
return null;
}
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class OpenRoadmFlowRuleProgrammable method getDeviceConnections.
/**
* Fetches list of connections from device.
*
* @return list of connections as XML hierarchy
*/
private List<HierarchicalConfiguration> getDeviceConnections() {
NetconfSession session = getNetconfSession();
if (session == null) {
log.error("OPENROADM {}: session not found", did());
return ImmutableList.of();
}
try {
StringBuilder rb = new StringBuilder();
rb.append(ORG_OPENROADM_DEVICE_OPEN_TAG);
rb.append(" <roadm-connections/>");
rb.append(ORG_OPENROADM_DEVICE_CLOSE_TAG);
String reply = session.getConfig(DatastoreId.RUNNING, rb.toString());
log.debug("REPLY to getDeviceConnections {}", reply);
HierarchicalConfiguration cfg = XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes()));
return cfg.configurationsAt("data.org-openroadm-device.roadm-connections");
} catch (NetconfException e) {
return ImmutableList.of();
}
}
Aggregations