use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class LumentumNetconfRoadmFlowRuleProgrammable method removeFlowRules.
@Override
public Collection<FlowRule> removeFlowRules(Collection<FlowRule> rules) {
NetconfSession session = getNetconfSession();
if (session == null) {
log.error("Device {} null session", did());
return ImmutableList.of();
}
// Remove the rules from the device and from the cache
List<FlowRule> removed = new ArrayList<>();
for (FlowRule r : rules) {
try {
LumentumFlowRule flowRule = new LumentumFlowRule(r, getLinePorts());
rpcDeleteConnection(flowRule);
getConnectionCache().remove(did(), r);
removed.add(r);
} catch (Exception e) {
log.error("Device {} Error {}", did(), e);
continue;
}
}
// Print out number of removed rules from the device (without receiving errors)
log.debug("Device {} removeFlowRules removed {}", did(), removed.size());
return removed;
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class CassiniTerminalDeviceDiscoveryOld 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 discoverPortDetails.
@Override
public List<PortDescription> discoverPortDetails() {
DeviceId did = data().deviceId();
XMLConfiguration cfg = new XMLConfiguration();
NetconfSession ns = getNetconfSessionAndLogin(did, USER_NAME, PASSWORD);
if (ns == null) {
log.error("discoverPorts called with null session for {}", did);
return ImmutableList.of();
}
log.info("Discovering ports details {}", handler().data().deviceId());
try {
String reply = ns.requestSync(buildGetPlatformComponentsRpc());
String data = getDataOfRpcReply(reply);
if (data == null) {
log.error("No valid response found from {}:\n{}", did, reply);
return ImmutableList.of();
}
cfg.load(CharSource.wrap(data).openStream());
try {
ns.startSubscription();
log.info("Started subscription");
} catch (NetconfException e) {
log.error("NETCONF exception caught on {} when the subscription started \n {}", data().deviceId(), e);
}
return discoverPorts(cfg);
} catch (Exception e) {
log.error("Error discovering port details on {}", data().deviceId(), e);
return ImmutableList.of();
}
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class GrooveOpenConfigDeviceDiscovery 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 InfineraOpenConfigDeviceDiscovery 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);
}
Aggregations