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;
}
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");
}
}
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;
}
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;
}
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;
}
Aggregations