Search in sources :

Example 96 with NetconfException

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;
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController)

Example 97 with NetconfException

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();
    }
}
Also used : XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) NetconfException(org.onosproject.netconf.NetconfException) XPathExpressionEngine(org.apache.commons.configuration.tree.xpath.XPathExpressionEngine) ExecutionException(java.util.concurrent.ExecutionException)

Example 98 with NetconfException

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);
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) ChassisId(org.onlab.packet.ChassisId) Device(org.onosproject.net.Device) NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfException(org.onosproject.netconf.NetconfException) SparseAnnotations(org.onosproject.net.SparseAnnotations) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) NetconfException(org.onosproject.netconf.NetconfException) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 99 with NetconfException

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;
}
Also used : XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) NetconfException(org.onosproject.netconf.NetconfException) StringWriter(java.io.StringWriter) ConfigurationException(org.apache.commons.configuration.ConfigurationException) XPathExpressionEngine(org.apache.commons.configuration.tree.xpath.XPathExpressionEngine) ExecutionException(java.util.concurrent.ExecutionException)

Example 100 with NetconfException

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();
    }
}
Also used : XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) NetconfException(org.onosproject.netconf.NetconfException) XPathExpressionEngine(org.apache.commons.configuration.tree.xpath.XPathExpressionEngine) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

NetconfException (org.onosproject.netconf.NetconfException)120 NetconfController (org.onosproject.netconf.NetconfController)65 NetconfSession (org.onosproject.netconf.NetconfSession)65 DeviceId (org.onosproject.net.DeviceId)50 XPath (javax.xml.xpath.XPath)23 DriverHandler (org.onosproject.net.driver.DriverHandler)22 XPathExpressionException (javax.xml.xpath.XPathExpressionException)19 Node (org.w3c.dom.Node)19 ByteArrayInputStream (java.io.ByteArrayInputStream)18 ArrayList (java.util.ArrayList)18 NetconfDevice (org.onosproject.netconf.NetconfDevice)18 MastershipService (org.onosproject.mastership.MastershipService)17 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)15 ExecutionException (java.util.concurrent.ExecutionException)12 Device (org.onosproject.net.Device)12 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)12 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)11 DeviceService (org.onosproject.net.device.DeviceService)11 ChassisId (org.onlab.packet.ChassisId)10 HashMap (java.util.HashMap)9