use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class TerminalDeviceDiscovery 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);
HierarchicalConfiguration components = xconf.configurationAt("data/components");
return parsePorts(components);
} 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 NetconfAlarmProvider method activate.
@Activate
public void activate() {
providerService = providerRegistry.register(this);
controller.getNetconfDevices().forEach(id -> {
NetconfDevice device = controller.getNetconfDevice(id);
if (device.isMasterSession()) {
NetconfSession session = device.getSession();
InternalNotificationListener listener = new InternalNotificationListener(device.getDeviceInfo());
try {
session.addDeviceOutputListener(listener);
} catch (NetconfException e) {
log.error("addDeviceOutputListener Error {} ", e.getMessage());
}
idNotificationListenerMap.put(id, listener);
}
});
controller.addDeviceListener(deviceListener);
log.info("NetconfAlarmProvider Started");
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class CassiniTerminalDeviceDiscovery method discoverPortDetails.
/**
* Returns a list of PortDescriptions for the device.
*
* @return a list of descriptions.
* <p>
* 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<CharSequence> fut1 = session.asyncGet();
String rpcReplyTest = fut1.get().toString();
XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReplyTest);
xconf.setExpressionEngine(new XPathExpressionEngine());
HierarchicalConfiguration logicalChannels = xconf.configurationAt("components");
return discoverPorts(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 NokiaTerminalDevicePowerConfig method getNetconfSession.
/**
* 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 identifier
* @param userName username to access the device
* @param passwd password to access the device
* @return The netconf session or null
*/
@Override
public NetconfSession getNetconfSession(DeviceId deviceId, String userName, String passwd) {
userName = USER_NAME;
passwd = PASSWORD;
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 \n {}", deviceId);
return null;
}
try {
String reply = ns.requestSync(buildLoginRpc(userName, passwd));
if (reply.contains("<ok/>")) {
return ns;
} else {
log.debug("Reply contains this: \n {}", reply);
return null;
}
} catch (NetconfException e) {
log.error("Can NOT login to the device", e);
}
return ns;
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class ClientLineTerminalDeviceFlowRuleProgrammable method fetchConnectionsFromDevice.
/**
* Fetches list of connections from device.
*
* TODO manage allow external flow rules (allowExternalFlowRules)
* Currently removes from the device all connections that are not currently present in the DeviceConnectionCache.
*
* @return connections that are present on the device and in the DeviceConnectionCache.
*/
private List<FlowRule> fetchConnectionsFromDevice() {
List<FlowRule> confirmedRules = new ArrayList<>();
String reply;
FlowRule cacheAddRule;
FlowRule cacheDropRule;
NetconfSession session = getNetconfSession();
// Get relevant information from the device
StringBuilder requestFilter = new StringBuilder();
requestFilter.append("<components xmlns='http://openconfig.net/yang/platform'>");
requestFilter.append(" <component>");
requestFilter.append(" <name/>");
requestFilter.append(" <oc-opt-term:optical-channel " + "xmlns:oc-opt-term='http://openconfig.net/yang/terminal-device'>");
requestFilter.append(" <oc-opt-term:config/>");
requestFilter.append(" </oc-opt-term:optical-channel>");
requestFilter.append(" </component>");
requestFilter.append("</components>");
requestFilter.append("<terminal-device xmlns='http://openconfig.net/yang/terminal-device'>");
requestFilter.append(" <logical-channels>");
requestFilter.append(" <channel>");
requestFilter.append(" <index/>");
requestFilter.append(" <config>");
requestFilter.append(" <admin-state/>");
requestFilter.append(" <logical-channel-type/>");
requestFilter.append(" </config>");
requestFilter.append(" <logical-channel-assignments>");
requestFilter.append(" <assignment>");
requestFilter.append(" <config>");
requestFilter.append(" <logical-channel/>");
requestFilter.append(" </config>");
requestFilter.append(" </assignment>");
requestFilter.append(" </logical-channel-assignments>");
requestFilter.append(" </channel>");
requestFilter.append(" </logical-channels>");
requestFilter.append("</terminal-device>");
try {
reply = session.get(requestFilter.toString(), null);
// log.debug("TRANSPONDER CONNECTIONS - fetchConnectionsFromDevice {} reply {}", did(), reply);
} catch (NetconfException e) {
log.error("Failed to retrieve configuration details for device {}", handler().data().deviceId(), e);
return ImmutableList.of();
}
HierarchicalConfiguration cfg = XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes()));
List<HierarchicalConfiguration> logicalChannels = cfg.configurationsAt("data.terminal-device.logical-channels.channel");
List<HierarchicalConfiguration> components = cfg.configurationsAt("data.components.component");
// Retrieve the ENABLED line ports
List<String> enabledOpticalChannels = logicalChannels.stream().filter(r -> r.getString("config.logical-channel-type").equals(OC_TYPE_PROT_OTN)).filter(r -> r.getString("config.admin-state").equals(OPERATION_ENABLE)).map(r -> r.getString("index")).collect(Collectors.toList());
log.debug("fetchConnectionsFromDevice {} enabledOpticalChannelsIndex {}", did(), enabledOpticalChannels);
if (enabledOpticalChannels.size() != 0) {
for (String channel : enabledOpticalChannels) {
log.debug("fetchOpticalConnectionsFromDevice {} channel {}", did(), channel);
// Retrieve the corresponding central frequency from the associated component
// TODO correlate the components instead of relying on naming
Frequency centralFreq = components.stream().filter(c -> c.getString("name").equals(PREFIX_CHANNEL + channel)).map(c -> c.getDouble("optical-channel.config.frequency")).map(c -> Frequency.ofMHz(c)).findFirst().orElse(null);
confirmedRules.addAll(fetchLineConnectionFromDevice(channel, centralFreq));
}
}
// Retrieve the ENABLED client ports
List<String> enabledClientChannels = logicalChannels.stream().filter(r -> r.getString("config.logical-channel-type").equals(OC_TYPE_PROT_ETH)).filter(r -> r.getString("config.admin-state").equals(OPERATION_ENABLE)).map(r -> r.getString("index")).collect(Collectors.toList());
log.debug("fetchClientConnectionsFromDevice {} enabledClientChannelsIndex {}", did(), enabledClientChannels);
if (enabledClientChannels.size() != 0) {
for (String clientPort : enabledClientChannels) {
log.debug("fetchClientConnectionsFromDevice {} channel {}", did(), clientPort);
String linePort = logicalChannels.stream().filter(r -> r.getString("config.logical-channel-type").equals(OC_TYPE_PROT_ETH)).filter(r -> r.getString("config.admin-state").equals(OPERATION_ENABLE)).filter(r -> r.getString("index").equals(clientPort)).map(r -> r.getString("logical-channel-assignments.assignment.config.logical-channel")).findFirst().orElse(null);
// Build the corresponding flow rule as expected
// Selector including port
// Treatment including port
PortNumber clientPortNumber = PortNumber.portNumber(clientPort);
PortNumber linePortNumber = PortNumber.portNumber(linePort);
confirmedRules.addAll(fetchClientConnectionFromDevice(clientPortNumber, linePortNumber));
}
}
// Returns rules that are both on the device and on the cache
if (confirmedRules.size() != 0) {
log.info("fetchConnectionsFromDevice {} number of confirmed rules {}", did(), confirmedRules.size());
return confirmedRules;
} else {
return ImmutableList.of();
}
}
Aggregations