use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.
the class PolatisLinkDiscovery method checkPeer.
private boolean checkPeer(ConnectPoint nearEndCP, ConnectPoint peerCP, DriverHandler handler, boolean direct) {
// check peerCP exists and is available (either via device service or direct from device)
DeviceId peerDeviceID = peerCP.deviceId();
boolean result = false;
DeviceService deviceService = checkNotNull(handler.get(DeviceService.class));
if (deviceService.isAvailable(peerDeviceID)) {
log.trace("Peer device {} exists", peerDeviceID.toString());
Device device = deviceService.getDevice(peerDeviceID);
int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
List<Port> ports = deviceService.getPorts(peerDeviceID);
PortNumber farEndPortNum = peerCP.port();
Port port = deviceService.getPort(peerCP);
if (port != null) {
if (port.isEnabled()) {
log.trace("Peer port {} exists", port.number().toLong());
// check far end peer-port entry (use device service or retrieve direct from switch)
Port peerPort = deviceService.getPort(peerDeviceID, farEndPortNum);
String farEndPortPeerportData = peerPort.annotations().value(KEY_PORTPEER);
if (direct) {
log.trace("Checking device {} DIRECT", handler.data().deviceId());
// A bit of a cludge it seems but temporarily open a new NETCONF session to far-end device
NetconfController controller = checkNotNull(handler.get(NetconfController.class));
NetconfSession farEndDeviceSession = controller.getDevicesMap().get(peerDeviceID).getSession();
String reply = netconfGet(farEndDeviceSession, getPortFilter(farEndPortNum));
PortDescription peerPortDescDirect = parsePorts(reply, numInputPorts, numOutputPorts).get(0);
log.trace("peerPortDesc from device: " + peerPortDescDirect.toString());
String farEndPortPeerportDataDirect = peerPortDescDirect.annotations().value(KEY_PORTPEER);
farEndPortPeerportData = farEndPortPeerportDataDirect;
}
if (!farEndPortPeerportData.equals("")) {
if (farEndPortPeerportData.charAt(0) == '{') {
log.trace("Far-end peer-port value:" + farEndPortPeerportData);
ObjectMapper mapper = new ObjectMapper();
ConnectPoint checkNearEndCP = null;
try {
checkNearEndCP = parsePeerportDataForCP(mapper.readTree(farEndPortPeerportData));
} catch (JsonProcessingException jpe) {
log.trace("Error processing peer-port JSON: {}", jpe.toString());
}
if (nearEndCP.equals(checkNearEndCP)) {
log.trace("Reciprocal peer port entries match: nearEnd={}, farEnd={}", nearEndCP, checkNearEndCP);
result = true;
} else {
log.trace("Peer-port entry for far-end port ({}) does not match near-end " + "port number ({})", checkNearEndCP, nearEndCP);
}
}
} else {
log.trace("Null peer-port entry for far-end port ({})", peerCP);
}
} else {
log.trace("Peer port {} is DISABLED", port);
}
} else {
log.trace("Peer port {} does not exist", port);
}
} else {
log.trace("Far end device does not exist or is not available");
}
return result;
}
use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.
the class PolatisAlarmConsumer method consumeAlarms.
@Override
public List<Alarm> consumeAlarms() {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
checkNotNull(controller, "Netconf controller is null");
MastershipService mastershipService = handler.get(MastershipService.class);
deviceId = handler.data().deviceId();
List<Alarm> alarms = new ArrayList<>();
if (!mastershipService.isLocalMaster(deviceId)) {
log.warn("Not master for {} Use {} to execute command", deviceId, mastershipService.getMasterFor(deviceId));
return ImmutableList.copyOf(alarms);
}
try {
String request = xmlEmpty(KEY_SYSTEMALARMS_XMLNS);
String reply = controller.getDevicesMap().get(deviceId).getSession().get(request, null);
if (reply != null) {
alarms = parseAlarms(reply);
}
} catch (NetconfException e) {
log.error("Error reading alarms for device {} exception {}", deviceId, e);
}
return ImmutableList.copyOf(alarms);
}
use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.
the class Ciena5162PortAdmin method setAdminState.
/**
* Sets the administrative state of the given port to the given value.
*
* @param number
* port number
* @param value
* state, true for enabled, false for disabled
* @return true if successfully set
*/
private CompletableFuture<Boolean> setAdminState(PortNumber number, Boolean value) {
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.toLong());
templateContext.put("admin-state", value.toString());
Node req = (Node) TEMPLATE_MANAGER.doRequest(session, "port-admin-state", 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 {}", number, handler().data().deviceId(), value, e);
}
return CompletableFuture.completedFuture(false);
}
use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.
the class Ciena5170PortAdmin 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.NetconfController in project onos by opennetworkinglab.
the class FujitsuT100DeviceDescription method discoverPortDetails.
@Override
public List<PortDescription> discoverPortDetails() {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
String reply;
try {
reply = session.get(requestBuilder());
} catch (NetconfException e) {
log.error("Failed to retrieve port details for device {}", handler().data().deviceId());
return ImmutableList.of();
}
List<PortDescription> descriptions = parseFujitsuT100Ports(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes())));
return ImmutableList.copyOf(descriptions);
}
Aggregations