use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class AdvaTerminalDeviceDiscovery 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 {
NetconfSession session = getNetconfSession(did());
if (session == null) {
log.error("discoverPortDetails called with null session for {}", did());
return ImmutableList.of();
}
CompletableFuture<String> fut = session.rpc(getTerminalDeviceBuilder());
String rpcReply = fut.get();
XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
xconf.setExpressionEngine(new XPathExpressionEngine());
HierarchicalConfiguration logicalChannels = xconf.configurationAt("data/terminal-device/logical-channels");
return parseLogicalChannels(logicalChannels);
} catch (Exception e) {
log.error("Exception discoverPortDetails() {}", did(), e);
return ImmutableList.of();
}
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class NokiaOpenConfigDeviceDiscovery method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
DeviceId did = data().deviceId();
NetconfSession ns = getNetconfSessionAndLogin(did, USER_NAME, PASSWORD);
if (ns == null) {
log.error("DiscoverDeviceDetails called with null session for {}", did);
return null;
}
log.info("Discovering device details {}", handler().data().deviceId());
String hwVersion = "1830", swVersion = "OpenAgent";
try {
String reply = ns.requestSync(buildGetSystemSoftwareRpc());
XMLConfiguration cfg = (XMLConfiguration) XmlConfigParser.loadXmlString(getDataOfRpcReply(reply));
hwVersion = cfg.getString("components.component.state.description");
swVersion = cfg.getString("components.component.state.version");
} catch (NetconfException e) {
log.error("Error discovering device details on {}", data().deviceId(), e);
}
return new DefaultDeviceDescription(handler().data().deviceId().uri(), Device.Type.ROADM_OTN, "NOKIA", hwVersion, swVersion, "", new ChassisId("1"));
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class NokiaOpenConfigDeviceDiscovery method getNetconfSessionAndLogin.
/**
* Login to the device by providing the correct user and password in order to configure the device
* Returns the NetconfSession with the device for which the method was called.
*
* @param deviceId device indetifier
* @param userName
* @param passwd
* @return The netconf session or null
*/
private NetconfSession getNetconfSessionAndLogin(DeviceId deviceId, String userName, String passwd) {
NetconfController nc = handler().get(NetconfController.class);
NetconfDevice ndev = nc.getDevicesMap().get(deviceId);
if (ndev == null) {
log.debug("netconf device " + deviceId + " is not found, returning null session");
return null;
}
NetconfSession ns = ndev.getSession();
if (ns == null) {
log.error("discoverPorts called with null session for {}", deviceId);
return null;
}
try {
String reply = ns.requestSync(buildLoginRpc(userName, passwd));
if (reply.contains("<ok/>")) {
return ns;
} else {
log.debug(reply);
return null;
}
} catch (NetconfException e) {
log.error("can not login to device", e);
}
return ns;
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class OpenConfigDeviceDiscovery method discoverPorts.
private List<PortDescription> discoverPorts() throws ConfigurationException, IOException {
DeviceId did = data().deviceId();
NetconfSession ns = Optional.ofNullable(handler().get(NetconfController.class)).map(c -> c.getNetconfDevice(did)).map(NetconfDevice::getSession).orElseThrow(() -> new IllegalStateException("No NetconfSession found for " + did));
// TODO convert this method into non-blocking form?
String reply = ns.asyncGet().join().toString();
// workaround until asyncGet().join() start failing exceptionally
String data = null;
if (reply.startsWith("<data")) {
data = reply;
}
if (data == null) {
log.error("No valid response found from {}:\n{}", did, reply);
return ImmutableList.of();
}
XMLConfiguration cfg = new XMLConfiguration();
cfg.load(CharSource.wrap(data).openStream());
return discoverPorts(cfg);
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class OpenconfigBitErrorRateState method getPostFecBer.
/**
* Get the BER value post FEC.
*
* @param deviceId the device identifier
* @param port the port identifier
* @return the decimal value of BER
*/
@Override
public Optional<Double> getPostFecBer(DeviceId deviceId, PortNumber port) {
NetconfSession session = NetconfSessionUtility.getNetconfSession(deviceId, getController());
checkNotNull(session);
String postFecBerFilter = generateBerFilter(deviceId, port, POST_FEC_BER_TAG);
String rpcRequest = getConfigOperation(postFecBerFilter);
log.debug("RPC call for fetching Post FEC BER : {}", rpcRequest);
XMLConfiguration xconf = NetconfSessionUtility.executeRpc(session, rpcRequest);
if (xconf == null) {
log.error("Error in executing Post FEC BER RPC");
return Optional.empty();
}
try {
HierarchicalConfiguration config = xconf.configurationAt("data/components/component/transceiver/state/" + POST_FEC_BER_TAG);
if (config == null || config.getString("instant") == null) {
return Optional.empty();
}
double ber = Float.valueOf(config.getString("instant")).doubleValue();
return Optional.of(ber);
} catch (IllegalArgumentException e) {
log.error("Error in fetching configuration : {}", e.getMessage());
return Optional.empty();
}
}
Aggregations