use of org.onosproject.netconf.NetconfSession 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;
}
use of org.onosproject.netconf.NetconfSession 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;
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class ControllerConfigJuniperImpl method requestCommand.
private boolean requestCommand(String command) {
NetconfSession session = getSession();
if (session == null) {
log.error("Cannot get session : {}", command);
return false;
}
try {
String reply = session.requestSync(command).trim();
log.debug(reply);
if (!isOK(reply)) {
log.error("discard changes {}", reply);
session.requestSync(buildDiscardChanges());
return false;
}
reply = session.requestSync(buildCommit()).trim();
log.debug("reply : {}", reply);
} catch (NetconfException e) {
log.debug(e.getMessage());
return false;
}
return true;
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class ClientLineTerminalDeviceDiscovery 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() {
boolean defaultAvailable = true;
SparseAnnotations annotations = DefaultAnnotations.builder().build();
log.debug("ClientLineTerminalDeviceDiscovery::discoverDeviceDetails device {}", did());
// Other option "OTN" or "OTHER", we use TERMINAL_DEVICE
org.onosproject.net.Device.Type type = Device.Type.TERMINAL_DEVICE;
// Some defaults
String vendor = "NOVENDOR";
String serialNumber = "0xCAFEBEEF";
String hwVersion = "0.2.1";
String swVersion = "0.2.1";
String chassisId = "128";
// Get the session,
NetconfSession session = getNetconfSession(did());
try {
String reply = session.get(getDeviceDetailsBuilder());
log.debug("REPLY to DeviceDescription {}", reply);
// <rpc-reply> as root node, software hardare version requires openconfig >= 2018
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);
swVersion = xconf.getString("data.components.component.state.software-version", swVersion);
hwVersion = xconf.getString("data.components.component.state.hardware-version", hwVersion);
} catch (Exception e) {
log.error("ClientLineTerminalDeviceDiscovery::discoverDeviceDetails - Failed to retrieve session {}", did());
throw new IllegalStateException(new NetconfException("Failed to retrieve version info.", e));
}
ChassisId cid = new ChassisId(Long.valueOf(chassisId, 10));
log.info("Device retrieved details");
log.info("VENDOR {}", vendor);
log.info("HWVERSION {}", hwVersion);
log.info("SWVERSION {}", swVersion);
log.info("SERIAL {}", serialNumber);
log.info("CHASSISID {}", chassisId);
return new DefaultDeviceDescription(did().uri(), type, vendor, hwVersion, swVersion, serialNumber, cid, defaultAvailable, annotations);
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class ClientLineTerminalDeviceDiscovery method discoverPortDetails.
/**
* Returns a list of PortDescriptions for the device.
*
* @return a list of descriptions.
*
* The RPC reply follows the following pattern:
* //CHECKSTYLE:OFF
* <pre>{@code
* <?xml version="1.0" encoding="UTF-8"?>
* <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="7">
* <data>
* <components xmlns="http://openconfig.net/yang/platform">
* <component>....
* </component>
* <component>....
* </component>
* </components>
* </data>
* </rpc-reply>
* }</pre>
* //CHECKSTYLE:ON
*/
@Override
public List<PortDescription> discoverPortDetails() {
try {
XPathExpressionEngine xpe = new XPathExpressionEngine();
NetconfSession session = getNetconfSession(did());
if (session == null) {
log.error("discoverPortDetails called with null session for {}", did());
return ImmutableList.of();
}
CompletableFuture<String> fut = session.rpc(getDeviceComponentsBuilder());
String rpcReply = fut.get();
XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
xconf.setExpressionEngine(xpe);
log.debug("REPLY {}", rpcReply);
HierarchicalConfiguration components = xconf.configurationAt("data/components");
return parsePorts(components);
} catch (Exception e) {
log.error("Exception discoverPortDetails() {}", did(), e);
return ImmutableList.of();
}
}
Aggregations