use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class FujitsuVoltOnuOperConfig method rebootOnu.
@Override
public String rebootOnu(String target) {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
MastershipService mastershipService = handler.get(MastershipService.class);
DeviceId ncDeviceId = handler.data().deviceId();
checkNotNull(controller, "Netconf controller is null");
String reply = null;
String[] onuId = null;
if (!mastershipService.isLocalMaster(ncDeviceId)) {
log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
return null;
}
onuId = checkIdString(target, TWO);
if (onuId == null) {
log.error("Invalid ONU identifier {}", target);
return null;
}
try {
StringBuilder request = new StringBuilder();
request.append(ANGLE_LEFT + ONU_REBOOT + SPACE);
request.append(VOLT_NE_NAMESPACE + ANGLE_RIGHT + NEW_LINE);
request.append(buildStartTag(PONLINK_ID, false)).append(onuId[FIRST_PART]).append(buildEndTag(PONLINK_ID)).append(buildStartTag(ONU_ID, false)).append(onuId[SECOND_PART]).append(buildEndTag(ONU_ID)).append(buildEndTag(ONU_REBOOT));
reply = controller.getDevicesMap().get(ncDeviceId).getSession().doWrappedRpc(request.toString());
} catch (NetconfException e) {
log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
}
return reply;
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class OpenRoadmDeviceDescription method getSrgs.
/**
* Get config and status info for the SRGs from the device as a list
* of XML hierarchical configs.
* @param session the NETConf session to the OpenROADM device.
* @return a list of hierarchical conf. each one SRG.
*/
List<HierarchicalConfiguration> getSrgs(NetconfSession session) {
try {
String reply = session.rpc(getDeviceSharedRiskGroupsBuilder()).get();
XMLConfiguration conf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
conf.setExpressionEngine(new XPathExpressionEngine());
return conf.configurationsAt("/data/org-openroadm-device/shared-risk-group");
} catch (NetconfException | InterruptedException | ExecutionException e) {
log.error("[OPENROADM] {} exception getting SRGs: {}", did(), e);
return ImmutableList.of();
}
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class TerminalDeviceDiscovery method discoverDeviceDetails.
/**
* Returns a DeviceDescription with Device info.
*
* @return DeviceDescription or null
*
* //CHECKSTYLE:OFF
* <pre>{@code
* <data>
* <components xmlns="http://openconfig.net/yang/platform">
* <component>
* <state>
* <name>FIRMWARE</name>
* <type>oc-platform-types:OPERATING_SYSTEM</type>
* <description>CTTC METRO-HAUL Emulated OpenConfig TerminalDevice</description>
* <version>0.0.1</version>
* </state>
* </component>
* </components>
* </data>
*}</pre>
* //CHECKSTYLE:ON
*/
@Override
public DeviceDescription discoverDeviceDetails() {
log.info("TerminalDeviceDiscovery::discoverDeviceDetails device {}", did());
boolean defaultAvailable = true;
SparseAnnotations annotations = DefaultAnnotations.builder().build();
// Other option "OTHER", we use ROADM for now
org.onosproject.net.Device.Type type = Device.Type.TERMINAL_DEVICE;
// Some defaults
String vendor = "NOVENDOR";
String hwVersion = "0.2.1";
String swVersion = "0.2.1";
String serialNumber = "0xCAFEBEEF";
String chassisId = "128";
// Get the session,
NetconfSession session = getNetconfSession(did());
if (session != null) {
try {
String reply = session.get(getDeviceDetailsBuilder());
// <rpc-reply> as root node
XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
vendor = xconf.getString("data/components/component/state/mfg-name", vendor);
serialNumber = xconf.getString("data/components/component/state/serial-no", serialNumber);
// Requires OpenConfig >= 2018
swVersion = xconf.getString("data/components/component/state/software-version", swVersion);
hwVersion = xconf.getString("data/components/component/state/hardware-version", hwVersion);
} catch (Exception e) {
throw new IllegalStateException(new NetconfException("Failed to retrieve version info.", e));
}
} else {
log.info("TerminalDeviceDiscovery::discoverDeviceDetails - No netconf session for {}", did());
}
log.info("VENDOR {}", vendor);
log.info("HWVERSION {}", hwVersion);
log.info("SWVERSION {}", swVersion);
log.info("SERIAL {}", serialNumber);
log.info("CHASSISID {}", chassisId);
ChassisId cid = new ChassisId(Long.valueOf(chassisId, 10));
return new DefaultDeviceDescription(did().uri(), type, vendor, hwVersion, swVersion, serialNumber, cid, defaultAvailable, annotations);
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class TerminalDevicePowerConfig method executeRpc.
/**
* Execute RPC request.
*
* @param session Netconf session
* @param message Netconf message in XML format
* @return XMLConfiguration object
*/
public XMLConfiguration executeRpc(NetconfSession session, String message) {
try {
if (log.isDebugEnabled()) {
try {
StringWriter stringWriter = new StringWriter();
XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(message);
xconf.setExpressionEngine(new XPathExpressionEngine());
xconf.save(stringWriter);
log.debug("Request {}", stringWriter.toString());
} catch (ConfigurationException e) {
log.error("XML Config Exception ", e);
}
}
CompletableFuture<String> fut = session.rpc(message);
String rpcReply = fut.get();
XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
xconf.setExpressionEngine(new XPathExpressionEngine());
if (log.isDebugEnabled()) {
try {
StringWriter stringWriter = new StringWriter();
xconf.save(stringWriter);
log.debug("Response {}", stringWriter.toString());
} catch (ConfigurationException e) {
log.error("XML Config Exception ", e);
}
}
return xconf;
} catch (NetconfException ne) {
log.error("Exception on Netconf protocol: {}.", ne);
} catch (InterruptedException ie) {
log.error("Interrupted Exception: {}.", ie);
} catch (ExecutionException ee) {
log.error("Concurrent Exception while executing Netconf operation: {}.", ee);
}
return null;
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class OpenRoadmDeviceDescription method getDegrees.
/**
* Get config and status info for the degrees from the device as a list
* of XML hierarchical configs.
* @param session the NETConf session to the OpenROADM device.
* @return a list of hierarchical conf. each one degree.
*/
List<HierarchicalConfiguration> getDegrees(NetconfSession session) {
try {
String reply = session.rpc(getDeviceDegreesBuilder()).get();
XMLConfiguration conf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
conf.setExpressionEngine(new XPathExpressionEngine());
return conf.configurationsAt("/data/org-openroadm-device/degree");
} catch (NetconfException | InterruptedException | ExecutionException e) {
log.error("[OPENROADM] {} exception getting degrees: {}", did(), e);
return ImmutableList.of();
}
}
Aggregations