Search in sources :

Example 11 with NetconfController

use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.

the class FujitsuVoltNniLinkConfig method getNniLinks.

@Override
public String getNniLinks(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;
    if (!mastershipService.isLocalMaster(ncDeviceId)) {
        log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
        return null;
    }
    try {
        StringBuilder request = new StringBuilder();
        request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE).append(ANGLE_RIGHT + NEW_LINE).append(buildStartTag(VOLT_PORTS));
        if (target != null) {
            int nni;
            try {
                nni = Integer.parseInt(target);
                if (nni <= ZERO) {
                    log.error("Invalid integer for nnilink-id:{}", target);
                    return null;
                }
            } catch (NumberFormatException e) {
                log.error("Non-number input for nnilink-id:{}", target);
                return null;
            }
            request.append(buildStartTag(ETH_NNILINK_PORTS)).append(buildStartTag(ETH_NNILINK_PORT)).append(buildStartTag(NNILINK_ID, false)).append(target).append(buildEndTag(NNILINK_ID)).append(buildEndTag(ETH_NNILINK_PORT)).append(buildEndTag(ETH_NNILINK_PORTS));
        } else {
            request.append(buildEmptyTag(ETH_NNILINK_PORTS));
        }
        request.append(buildEndTag(VOLT_PORTS)).append(VOLT_NE_CLOSE);
        reply = controller.getDevicesMap().get(ncDeviceId).getSession().get(request.toString(), REPORT_ALL);
    } 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 12 with NetconfController

use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.

the class FujitsuVoltPonLinkConfig method getPonLinks.

@Override
public String getPonLinks(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;
    if (!mastershipService.isLocalMaster(ncDeviceId)) {
        log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
        return null;
    }
    try {
        StringBuilder request = new StringBuilder();
        request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE);
        request.append(ANGLE_RIGHT + NEW_LINE);
        request.append(buildStartTag(VOLT_PORTS));
        if (target != null) {
            int pon;
            try {
                pon = Integer.parseInt(target);
                if (pon <= ZERO) {
                    log.error("Invalid integer for ponlink-id:{}", target);
                    return null;
                }
            } catch (NumberFormatException e) {
                log.error("Non-number input for ponlink-id:{}", target);
                return null;
            }
            request.append(buildStartTag(GPON_PONLINK_PORTS)).append(buildStartTag(GPON_PONLINK_PORT)).append(buildStartTag(PONLINK_ID, false)).append(target).append(buildEndTag(PONLINK_ID)).append(buildEndTag(GPON_PONLINK_PORT)).append(buildEndTag(GPON_PONLINK_PORTS));
        } else {
            request.append(buildEmptyTag(GPON_PONLINK_PORTS));
        }
        request.append(buildEndTag(VOLT_PORTS));
        request.append(VOLT_NE_CLOSE);
        reply = controller.getDevicesMap().get(ncDeviceId).getSession().get(request.toString(), REPORT_ALL);
    } 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 13 with NetconfController

use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.

the class OplinkNetconfUtility method netconfEditConfig.

/**
 * Retrieves session reply information for edit config operation.
 *
 * @param handler parent driver handler
 * @param mode selected mode to change the configuration
 * @param cfg the new configuration to be set
 * @return the reply string
 */
public static boolean netconfEditConfig(DriverHandler handler, String mode, String cfg) {
    NetconfController controller = checkNotNull(handler.get(NetconfController.class));
    NetconfSession session = controller.getNetconfDevice(handler.data().deviceId()).getSession();
    boolean reply = false;
    try {
        reply = session.editConfig(DatastoreId.RUNNING, mode, cfg);
    } catch (NetconfException e) {
        throw new IllegalStateException(new NetconfException("Failed to edit configuration.", e));
    }
    return reply;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) NetconfController(org.onosproject.netconf.NetconfController)

Example 14 with NetconfController

use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.

the class OplinkNetconfUtility method netconfGetConfig.

/**
 * Retrieves session reply information for get config operation.
 *
 * @param handler parent driver handler
 * @param filter the filter string of xml content
 * @return the reply string
 */
public static String netconfGetConfig(DriverHandler handler, String filter) {
    NetconfController controller = checkNotNull(handler.get(NetconfController.class));
    NetconfSession session = controller.getNetconfDevice(handler.data().deviceId()).getSession();
    String reply;
    try {
        reply = session.getConfig(DatastoreId.RUNNING, filter);
    } catch (NetconfException e) {
        throw new IllegalStateException(new NetconfException("Failed to retrieve configuration.", e));
    }
    return reply;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) NetconfController(org.onosproject.netconf.NetconfController)

Example 15 with NetconfController

use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.

the class OpenRoadmNetconfHandlerBehaviour method getNetconfDevice.

/**
 * Get the device instance for which the methods apply.
 *
 * @return The device instance
 */
protected NetconfDevice getNetconfDevice() {
    NetconfController controller = checkNotNull(handler().get(NetconfController.class));
    NetconfDevice ncDevice = controller.getDevicesMap().get(did());
    return ncDevice;
}
Also used : NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfController(org.onosproject.netconf.NetconfController)

Aggregations

NetconfController (org.onosproject.netconf.NetconfController)80 NetconfException (org.onosproject.netconf.NetconfException)61 DeviceId (org.onosproject.net.DeviceId)42 NetconfSession (org.onosproject.netconf.NetconfSession)39 DriverHandler (org.onosproject.net.driver.DriverHandler)22 MastershipService (org.onosproject.mastership.MastershipService)20 NetconfDevice (org.onosproject.netconf.NetconfDevice)20 XPath (javax.xml.xpath.XPath)16 XPathExpressionException (javax.xml.xpath.XPathExpressionException)16 Node (org.w3c.dom.Node)16 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ConnectPoint (org.onosproject.net.ConnectPoint)9 NodeList (org.w3c.dom.NodeList)8 DeviceService (org.onosproject.net.device.DeviceService)7 Device (org.onosproject.net.Device)6 PortDescription (org.onosproject.net.device.PortDescription)5 HashSet (java.util.HashSet)4 DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)4