use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class Ciena5162PortAdmin method isEnabled.
@Override
public CompletableFuture<Boolean> isEnabled(PortNumber number) {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
try {
Map<String, Object> templateContext = new HashMap<String, Object>();
templateContext.put("port-number", number.toString());
Node port = TEMPLATE_MANAGER.doRequest(session, "logicalPort", templateContext);
XPath xp = XPathFactory.newInstance().newXPath();
return CompletableFuture.completedFuture(Boolean.valueOf(xp.evaluate("admin-status/text()", port)));
} catch (XPathExpressionException | NetconfException e) {
log.error("Unable to query port state for port {} from device {}", number, handler().data().deviceId(), e);
}
return CompletableFuture.completedFuture(false);
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class ControllerConfigJuniperImpl method retrieveResultCommand.
private String retrieveResultCommand(String command) {
NetconfSession session = getSession();
String reply;
if (session == null) {
log.error("Cannot get session : {}", command);
return null;
}
try {
reply = session.requestSync(command).trim();
log.debug(reply);
} catch (NetconfException e) {
log.debug(e.getMessage());
return null;
}
return reply;
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class FlowRuleJuniperImpl method commit.
private boolean commit() {
NetconfSession session = lookupNetconfSession(handler().data().deviceId());
String replay;
try {
replay = session.get(commitBuilder());
} catch (NetconfException e) {
throw new IllegalStateException(new NetconfException("Failed to retrieve configuration.", e));
}
return replay != null && replay.contains(OK);
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class DeviceDiscoveryJuniperImpl method discoverPortDetails.
@Override
public List<PortDescription> discoverPortDetails() {
DeviceId devId = handler().data().deviceId();
NetconfSession session = lookupNetconfSession(devId);
String reply;
try {
reply = session.get(requestBuilder(REQ_IF_INFO));
} catch (NetconfException e) {
log.warn("Failed to retrieve interface-information for device {}", devId);
return ImmutableList.of();
}
log.trace("Device {} interface-information {}", devId, reply);
List<PortDescription> descriptions = JuniperUtils.parseJuniperPorts(loadXmlString(reply));
log.debug("Device {} Discovered ports {}", devId, descriptions);
return descriptions;
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class FlowRuleJuniperImpl method manageRules.
private Collection<FlowRule> manageRules(Collection<FlowRule> rules, OperationType type) {
DeviceId deviceId = this.data().deviceId();
log.debug("{} flow entries to NETCONF device {}", type, deviceId);
NetconfSession session = lookupNetconfSession(deviceId);
Collection<FlowRule> managedRules = new HashSet<>();
for (FlowRule flowRule : rules) {
Optional<IPCriterion> ipCriterion = getIpCriterion(flowRule);
if (!ipCriterion.isPresent()) {
log.error("Currently not supported: IPv4 destination match must be used");
continue;
}
Optional<OutputInstruction> output = getOutput(flowRule);
if (!output.isPresent()) {
log.error("Currently not supported: the output action is needed");
continue;
}
getStaticRoute(deviceId, ipCriterion.get(), output.get(), flowRule.priority()).ifPresent(staticRoute -> {
// If the static route is not local, the driver tries to install
if (!staticRoute.isLocalRoute()) {
// FlowRule as installed.
if (editRoute(session, type, staticRoute)) {
managedRules.add(flowRule);
}
// If static route are local, they are not installed
// because are not required. Directly connected routes
// are automatically forwarded.
} else {
managedRules.add(flowRule);
}
});
}
return rules;
}
Aggregations