use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.
the class CienaWaveserverAiDeviceDescription method discoverPortDetails.
@Override
public List<PortDescription> discoverPortDetails() {
log.info("Adding ports for Waveserver Ai device");
List<PortDescription> ports = new ArrayList<>();
Device device = getDevice(handler().data().deviceId());
NetconfSession session = getNetconfSession();
try {
XPath xp = XPathFactory.newInstance().newXPath();
Node nodeListItem;
Node node = TEMPLATE_MANAGER.doRequest(session, "discoverPortDetails");
NodeList nodeList = (NodeList) xp.evaluate("waveserver-ports/ports", node, XPathConstants.NODESET);
int count = nodeList.getLength();
for (int i = 0; i < count; ++i) {
nodeListItem = nodeList.item(i);
DefaultAnnotations annotationPort = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, xp.evaluate("port-id/text()", nodeListItem)).set(AnnotationKeys.PROTOCOL, xp.evaluate("id/type/text()", nodeListItem)).build();
String port = xp.evaluate("port-id/text()", nodeListItem);
ports.add(DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(portIdConvert(port), port)).isEnabled(portStateConvert(xp.evaluate("state/operational-state/text()", nodeListItem))).portSpeed(portSpeedToLong(xp.evaluate("id/speed/text()", nodeListItem))).type(Port.Type.PACKET).annotations(annotationPort).build());
}
} catch (NetconfException | XPathExpressionException e) {
log.error("Unable to retrieve port information for device {}, {}", device.chassisId(), e);
}
return ImmutableList.copyOf(ports);
}
use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.
the class CienaWaveserverAiDeviceDescriptionTest method testDiscoverPortDetails.
@Test
public void testDiscoverPortDetails() {
List<PortDescription> result = new ArrayList<>();
List<PortDescription> expectResult = getExpectedPorts();
try {
XPath xp = XPathFactory.newInstance().newXPath();
Node nodeListItem;
Node node = doRequest("/response/discoverPortDetails.xml", "/rpc-reply/data");
NodeList nodeList = (NodeList) xp.evaluate("waveserver-ports/ports", node, XPathConstants.NODESET);
int count = nodeList.getLength();
for (int i = 0; i < count; ++i) {
nodeListItem = nodeList.item(i);
DefaultAnnotations annotationPort = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, xp.evaluate("port-id/text()", nodeListItem)).set(AnnotationKeys.PROTOCOL, xp.evaluate("id/type/text()", nodeListItem)).build();
String port = xp.evaluate("port-id/text()", nodeListItem);
result.add(DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(portIdConvert(port), port)).isEnabled(portStateConvert(xp.evaluate("state/operational-state/text()", nodeListItem))).portSpeed(portSpeedToLong(xp.evaluate("id/speed/text()", nodeListItem))).type(Port.Type.PACKET).annotations(annotationPort).build());
}
} catch (XPathExpressionException e) {
e.printStackTrace();
}
assertEquals(expectResult, result);
}
use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.
the class GnmiDeviceStateSubscriber method handleOperStatusUpdate.
private void handleOperStatusUpdate(DeviceId deviceId, Update update, long timestamp) {
Path path = update.getPath();
// first element should be "interface"
String interfaceName = path.getElem(1).getKeyOrDefault("name", null);
if (interfaceName == null) {
log.error("No interface present in gNMI update, abort");
log.debug("gNMI update:\n{}", update);
return;
}
List<Port> portsFromDevice = deviceService.getPorts(deviceId);
portsFromDevice.forEach(port -> {
if (!port.number().name().equals(interfaceName)) {
return;
}
DefaultAnnotations portAnnotations = DefaultAnnotations.builder().putAll(port.annotations()).set(LAST_CHANGE, String.valueOf(timestamp)).build();
// Port/Interface name is identical in OpenConfig model, but not in ONOS
// This might cause some problem if we use one name to different port
PortDescription portDescription = DefaultPortDescription.builder().portSpeed(port.portSpeed()).withPortNumber(port.number()).isEnabled(update.getVal().getStringVal().equals("UP")).type(port.type()).annotations(portAnnotations).build();
providerService.portStatusChanged(deviceId, portDescription);
});
}
Aggregations