use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class InterfaceConfigCiscoIosImpl method addRateLimit.
/**
* Adds a rate limit on an interface.
*
* @param intf the name of the interface
* @param limit the limit as a percentage
* @return the result of operation
*/
@Override
public boolean addRateLimit(String intf, short limit) {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
String reply;
try {
reply = session.requestSync(addRateLimitBuilder(intf, limit));
} catch (NetconfException e) {
log.error("Failed to configure rate limit {}%% on device {} interface {}.", limit, handler().data().deviceId(), intf, e);
return false;
}
return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class InterfaceConfigCiscoIosImpl method removeTrunkMode.
/**
* Removes trunk mode configuration from an interface.
*
* @param intf the name of the interface
* @return the result of operation
*/
@Override
public boolean removeTrunkMode(String intf) {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
String reply;
try {
reply = session.requestSync(removeTrunkModeBuilder(intf));
} catch (NetconfException e) {
log.error("Failed to remove trunk mode from device {} interface {}.", handler().data().deviceId(), intf, e);
return false;
}
return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class CienaWaveserverAiPortAdmin method setAdminState.
/**
* Sets the administrative state of the given port to the given value.
*
* @param number
* port number
* @param state
* state, true for enabled, false for disabled
* @return true if successfully set
*/
private CompletableFuture<Boolean> setAdminState(PortNumber number, Boolean state) {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
String port = portIdConvert(Long.valueOf(String.valueOf(number)));
String adminState = portStateConvert(state);
try {
Map<String, Object> templateContext = new HashMap<String, Object>();
templateContext.put("port-number", port);
templateContext.put("admin-state", adminState);
Node req = (Node) TEMPLATE_MANAGER.doRequest(session, "setAdminState", templateContext, "/", XPathConstants.NODE);
XPath xp = XPathFactory.newInstance().newXPath();
// If OK element exists then it worked.
Node ok = (Node) xp.evaluate("/rpc-reply/ok", req, XPathConstants.NODE);
return CompletableFuture.completedFuture(ok != null);
} catch (XPathExpressionException | NetconfException e) {
log.error("Unable to set port admin state for port {} to {}", port, handler().data().deviceId(), adminState, e);
}
return CompletableFuture.completedFuture(false);
}
use of org.onosproject.netconf.NetconfSession in project onos by opennetworkinglab.
the class CienaWaveserverAiPortAdmin 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 {
log.debug("Querying port state for port {} from device {}", number, handler().data().deviceId());
Map<String, Object> templateContext = new HashMap<String, Object>();
templateContext.put("port-number", number.toString());
Node port = TEMPLATE_MANAGER.doRequest(session, "isEnabled", templateContext);
XPath xp = XPathFactory.newInstance().newXPath();
return CompletableFuture.completedFuture(portStateConvert(xp.evaluate("state/operational-state/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 LinkDiscoveryJuniperImpl method getLinks.
@Override
public Set<LinkDescription> getLinks() {
DeviceId localDeviceId = this.handler().data().deviceId();
NetconfSession session = lookupNetconfSession(localDeviceId);
String reply;
try {
reply = session.get(requestBuilder(REQ_LLDP_NBR_INFO));
} catch (NetconfException e) {
log.warn("Failed to retrieve lldp-neighbors-information for device {}", localDeviceId);
return ImmutableSet.of();
}
log.debug("Reply from device {} : {}", localDeviceId, reply);
Set<LinkAbstraction> linkAbstractions = parseJuniperLldp(loadXmlString(reply));
log.debug("Set of LinkAbstraction discovered {}", linkAbstractions);
DeviceService deviceService = this.handler().get(DeviceService.class);
Set<LinkDescription> descriptions = new HashSet<>();
// for each lldp neighbor create two LinkDescription
for (LinkAbstraction linkAbs : linkAbstractions) {
// find source port by local port name
Optional<Port> localPort = deviceService.getPorts(localDeviceId).stream().filter(port -> linkAbs.localPortName.equals(port.annotations().value(PORT_NAME))).findAny();
if (!localPort.isPresent()) {
log.warn("Port name {} does not exist in device {}", linkAbs.localPortName, localDeviceId);
continue;
}
// find destination device by remote chassis id
com.google.common.base.Optional<Device> dev = Iterables.tryFind(deviceService.getAvailableDevices(), input -> input.chassisId().equals(linkAbs.remoteChassisId));
if (!dev.isPresent()) {
log.warn("Device with chassis ID {} does not exist. Referenced by {}/{}", linkAbs.remoteChassisId, localDeviceId, linkAbs);
continue;
}
Device remoteDevice = dev.get();
// find destination port by interface index
Optional<Port> remotePort = deviceService.getPorts(remoteDevice.id()).stream().filter(port -> {
if (port.number().toLong() == linkAbs.remotePortIndex) {
return true;
}
if (port.annotations().value(AnnotationKeys.PORT_MAC) != null && linkAbs.remotePortId != null && port.annotations().value(AnnotationKeys.PORT_MAC).equals(linkAbs.remotePortId)) {
return true;
}
if (port.annotations().value(AnnotationKeys.PORT_NAME) != null && linkAbs.remotePortId != null && port.annotations().value(AnnotationKeys.PORT_NAME).equals(linkAbs.remotePortId)) {
return true;
}
if (port.annotations().value(AnnotationKeys.PORT_NAME) != null && linkAbs.remotePortDescription != null && port.annotations().value(AnnotationKeys.PORT_NAME).equals(linkAbs.remotePortDescription)) {
return true;
}
return false;
}).findAny();
if (!remotePort.isPresent()) {
log.warn("Port does not exist in remote device {}. Referenced by {}/{}", remoteDevice.id(), localDeviceId, linkAbs);
continue;
}
if (!localPort.get().isEnabled() || !remotePort.get().isEnabled()) {
log.debug("Ports are disabled. Cannot create a link between {}/{} and {}/{}", localDeviceId, localPort.get(), remoteDevice.id(), remotePort.get());
continue;
}
JuniperUtils.createOneWayLinkDescription(localDeviceId, localPort.get(), remoteDevice.id(), remotePort.get(), descriptions);
}
return descriptions;
}
Aggregations