Search in sources :

Example 81 with NetconfSession

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

the class AbstractTerminalDeviceFlowRuleProgrammable method applyFlowRules.

/**
 * Apply the flow entries specified in the collection rules.
 *
 * @param rules A collection of Flow Rules to be applied
 * @return The collection of added Flow Entries
 */
@Override
public Collection<FlowRule> applyFlowRules(Collection<FlowRule> rules) {
    NetconfSession session = getNetconfSession();
    if (session == null) {
        openConfigError("null session");
        return ImmutableList.of();
    }
    List<FlowRule> added = new ArrayList<>();
    for (FlowRule r : rules) {
        try {
            String connectionId = applyFlowRule(session, r);
            getConnectionCache().add(did(), connectionId, r);
            added.add(r);
        } catch (Exception e) {
            openConfigError("Error {}", e);
            continue;
        }
    }
    openConfigLog("applyFlowRules added {}", added.size());
    return added;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) ArrayList(java.util.ArrayList) FlowRule(org.onosproject.net.flow.FlowRule) NetconfException(org.onosproject.netconf.NetconfException)

Example 82 with NetconfSession

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

the class NetconfGetCommand method doExecute.

@Override
protected void doExecute() {
    DeviceId deviceId = DeviceId.deviceId(uri);
    NetconfController controller = get(NetconfController.class);
    checkNotNull(controller, "Netconf controller is null");
    NetconfDevice device = controller.getDevicesMap().get(deviceId);
    if (device == null) {
        print("Netconf device object not found for %s", deviceId);
        return;
    }
    NetconfSession session = device.getSession();
    if (session == null) {
        print("Netconf session not found for %s", deviceId);
        return;
    }
    try {
        CharSequence res = session.asyncGet().get(timeoutSec, TimeUnit.SECONDS);
        print("%s", res);
    } catch (NetconfException | InterruptedException | ExecutionException | TimeoutException e) {
        log.error("Configuration could not be retrieved", e);
        print("Error occurred retrieving configuration");
    }
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) DeviceId(org.onosproject.net.DeviceId) ExecutionException(java.util.concurrent.ExecutionException) NetconfController(org.onosproject.netconf.NetconfController) TimeoutException(java.util.concurrent.TimeoutException)

Example 83 with NetconfSession

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

the class PolatisNetconfUtility method netconfRpc.

/**
 * Makes a NETCONF RPC.
 *
 * @param handler parent driver handler
 * @param body body of RPC
 * @return the reply string
 */
public static String netconfRpc(DriverHandler handler, String body) {
    NetconfSession session = getNetconfSession(handler);
    String reply;
    try {
        reply = session.doWrappedRpc(body);
    } catch (NetconfException e) {
        throw new IllegalStateException(new NetconfException("Failed to make RPC..", e));
    }
    return reply;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException)

Example 84 with NetconfSession

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

the class PolatisNetconfUtility method getNetconfSession.

/**
 * Returns the NETCONF session of the device.
 *
 * @return session
 */
private static NetconfSession getNetconfSession(DriverHandler handler) {
    NetconfController controller = checkNotNull(handler.get(NetconfController.class));
    NetconfSession session = controller.getNetconfDevice(handler.data().deviceId()).getSession();
    if (session == null) {
        throw new IllegalStateException(new NetconfException("Failed to retrieve the netconf device."));
    }
    return session;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) NetconfController(org.onosproject.netconf.NetconfController)

Example 85 with NetconfSession

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

the class PolatisNetconfUtility 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) {
    NetconfSession session = getNetconfSession(handler);
    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)

Aggregations

NetconfSession (org.onosproject.netconf.NetconfSession)87 NetconfException (org.onosproject.netconf.NetconfException)72 NetconfController (org.onosproject.netconf.NetconfController)44 DeviceId (org.onosproject.net.DeviceId)32 XPath (javax.xml.xpath.XPath)22 XPathExpressionException (javax.xml.xpath.XPathExpressionException)18 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)18 Node (org.w3c.dom.Node)18 ArrayList (java.util.ArrayList)16 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)16 ByteArrayInputStream (java.io.ByteArrayInputStream)15 DeviceService (org.onosproject.net.device.DeviceService)13 Device (org.onosproject.net.Device)12 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)11 ChassisId (org.onlab.packet.ChassisId)10 FlowRule (org.onosproject.net.flow.FlowRule)10 HashMap (java.util.HashMap)9 PortDescription (org.onosproject.net.device.PortDescription)9 NodeList (org.w3c.dom.NodeList)9 ConnectPoint (org.onosproject.net.ConnectPoint)8