use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class PortStatisticsImpl method discoverPortStatistics.
@Override
public Collection<PortStatistics> discoverPortStatistics() {
Collection<PortStatistics> portStatistics = Lists.newArrayList();
try {
DeviceId deviceId = handler().data().deviceId();
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(deviceId);
Optional<JsonNode> result = AristaUtils.retrieveCommandResult(handler(), SHOW_INTERFACES);
if (!result.isPresent()) {
return portStatistics;
}
JsonNode interfaces = result.get().findValue(INTERFACES);
if (interfaces == null) {
return portStatistics;
}
Iterator<Map.Entry<String, JsonNode>> ifIterator = interfaces.fields();
while (ifIterator.hasNext()) {
Map.Entry<String, JsonNode> intf = ifIterator.next();
String ifName = intf.getKey();
JsonNode interfaceNode = intf.getValue();
JsonNode interfaceCounters = interfaceNode.get(INTERFACE_COUNTERS);
if (interfaceCounters == null) {
continue;
}
ports.stream().filter(Port::isEnabled).filter(port -> {
String portName = port.annotations().value(AnnotationKeys.PORT_NAME);
return portName != null && portName.equals(ifName);
}).findAny().ifPresent(port -> portStatistics.add(buildStatisticsForPort(interfaceCounters, port.number(), deviceId)));
}
} catch (Exception e) {
log.error("Exception occurred because of", e);
}
return portStatistics;
}
use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class Ciena5162DeviceDescription method discoverPortStatistics.
@Override
public Collection<PortStatistics> discoverPortStatistics() {
List<PortStatistics> stats = new ArrayList<PortStatistics>();
DeviceId deviceId = handler().data().deviceId();
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
if (controller == null || controller.getDevicesMap() == null || controller.getDevicesMap().get(deviceId) == null) {
log.warn("NETCONF session to device {} not yet established, will be retried", deviceId);
return stats;
}
NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
try {
Node data = TEMPLATE_MANAGER.doRequest(session, "port-stats");
XPath xp = XPathFactory.newInstance().newXPath();
NodeList interfaces = (NodeList) xp.evaluate("interfaces/interface", data, XPathConstants.NODESET);
int count = interfaces.getLength();
for (int i = 0; i < count; i += 1) {
Node iface = interfaces.item(i);
if (xp.evaluate("config/type/text()", iface).equals("ettp")) {
stats.add(DefaultPortStatistics.builder().setDeviceId(deviceId).setPort(PortNumber.portNumber(xp.evaluate("name/text()", iface))).setBytesReceived(Long.valueOf(xp.evaluate("state/counters/in-octets/text()", iface))).setBytesSent(Long.valueOf(xp.evaluate("state/counters/out-octets/text()", iface))).setPacketsReceived(Long.valueOf(xp.evaluate("state/counters/in-pkts/text()", iface))).setPacketsSent(Long.valueOf(xp.evaluate("state/counters/out-pkts/text()", iface))).setPacketsTxErrors(Long.valueOf(xp.evaluate("state/counters/out-errors/text()", iface))).setPacketsRxErrors(Long.valueOf(xp.evaluate("state/counters/in-errors/text()", iface))).build());
}
}
} catch (NetconfException | XPathExpressionException e) {
log.error("Unable to retrieve port statistics for device {}, {}", deviceId, e);
}
return stats;
}
use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class CienaWaveserverAiDeviceDescriptionTest method testDiscoverPortStatistics.
@Test
public void testDiscoverPortStatistics() {
Collection<PortStatistics> result = new ArrayList<>();
Collection<PortStatistics> expectResult = getExpectedPortsStatistics();
try {
XPath xp = XPathFactory.newInstance().newXPath();
String tx = "current-bin/statistics/interface-counts/tx/";
String rx = "current-bin/statistics/interface-counts/rx/";
Node node = doRequest("/response/discoverPortStatistics.xml", "/rpc-reply/data");
NodeList nodeList = (NodeList) xp.evaluate("waveserver-pm/ethernet-performance-instances", node, XPathConstants.NODESET);
Node nodeListItem;
int count = nodeList.getLength();
for (int i = 0; i < count; ++i) {
nodeListItem = nodeList.item(i);
result.add(DefaultPortStatistics.builder().setDeviceId(mockDeviceId).setPort(PortNumber.portNumber(portIdConvert(xp.evaluate("instance-name/text()", nodeListItem)))).setBytesReceived(Long.parseLong(xp.evaluate(rx + "bytes/value/text()", nodeListItem))).setPacketsReceived(Long.parseLong(xp.evaluate(rx + "packets/value/text()", nodeListItem))).setBytesSent(Long.parseLong(xp.evaluate(tx + "bytes/value/text()", nodeListItem))).setPacketsSent(Long.parseLong(xp.evaluate(tx + "packets/value/text()", nodeListItem))).build());
}
} catch (XPathExpressionException e) {
e.printStackTrace();
}
// TODO: the builder causes this test to fail
// assertEquals(expectResult, result);
}
use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class StatsFlowRuleManager method getOverlayDstPortBasedFlowInfos.
/**
* Gets a set of flow infos by referring to overlay destination VM port.
*
* @return flow infos
*/
private Set<FlowInfo> getOverlayDstPortBasedFlowInfos() {
Set<FlowInfo> flowInfos = Sets.newConcurrentHashSet();
Set<PortNumber> instPortNums = instPortService.instancePorts().stream().map(InstancePort::portNumber).collect(Collectors.toSet());
Set<DeviceId> deviceIds = osNodeService.completeNodes(COMPUTE).stream().map(OpenstackNode::intgBridge).collect(Collectors.toSet());
deviceIds.forEach(d -> {
List<PortStatistics> stats = deviceService.getPortStatistics(d).stream().filter(s -> instPortNums.contains(s.portNumber())).collect(Collectors.toList());
stats.forEach(s -> {
InstancePort instPort = getInstancePort(d, s.portNumber());
if (instPort != null) {
flowInfos.add(buildTxFlowInfoFromInstancePort(instPort, s));
flowInfos.add(buildRxFlowInfoFromInstancePort(instPort, s));
}
});
});
return flowInfos;
}
use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class ServerDevicesDiscovery method getMonitoringStatistics.
/**
* Query a server to retrieve monitoring statistics for a
* specific resource (i.e., traffic class).
*
* @param deviceId the device ID to be queried
* @param tcId the ID of the traffic class to be monitored
* @return resource-specific monitoring statistics
*/
private MonitoringStatistics getMonitoringStatistics(DeviceId deviceId, URI tcId) {
// Monitoring statistics to return
MonitoringStatistics monStats = null;
RestServerSBDevice device = null;
try {
device = (RestServerSBDevice) getDevice(deviceId);
} catch (ClassCastException ccEx) {
log.error("Failed to retrieve monitoring statistics from device {}", deviceId);
return monStats;
}
if (device == null) {
return monStats;
}
// Create a resource-specific URL
String scUrl = URL_SERVICE_CHAINS_STATS + SLASH + tcId.toString();
// Hit the path that provides the server's specific resources
InputStream response = null;
try {
response = getController().get(deviceId, scUrl, JSON);
} catch (ProcessingException pEx) {
log.error("Failed to retrieve monitoring statistics from device {}", deviceId);
raiseDeviceDisconnect(device);
return monStats;
}
// Load the JSON into objects
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> jsonMap = null;
JsonNode jsonNode = null;
ObjectNode objNode = null;
try {
jsonMap = mapper.readValue(response, Map.class);
jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
objNode = (ObjectNode) jsonNode;
} catch (IOException ioEx) {
log.error("Failed to retrieve monitoring statistics from device {}", deviceId);
raiseDeviceDisconnect(device);
return monStats;
}
if (jsonMap == null) {
log.error("Failed to retrieve monitoring statistics from device {}", deviceId);
raiseDeviceDisconnect(device);
return monStats;
}
// Get the ID of the traffic class
String id = get(jsonNode, PARAM_ID);
// And verify that this is the traffic class we want to monitor
if (!id.equals(tcId.toString())) {
throw new IllegalStateException("Failed to retrieve monitoring data for traffic class " + tcId + ". Traffic class ID does not agree.");
}
// Get a list of CPU statistics per core
Collection<CpuStatistics> cpuStats = parseCpuStatistics(deviceId, objNode);
// Get main memory statistics
MemoryStatistics memStats = parseMemoryStatistics(deviceId, objNode);
// Get a list of port statistics
Collection<PortStatistics> nicStats = parseNicStatistics(deviceId, objNode);
// Get timing statistics
TimingStatistics timinsgStats = parseTimingStatistics(objNode);
// Construct a global monitoring statistics object out of smaller ones
monStats = DefaultMonitoringStatistics.builder().setDeviceId(deviceId).setTimingStatistics(timinsgStats).setCpuStatistics(cpuStats).setMemoryStatistics(memStats).setNicStatistics(nicStats).build();
// When a device reports monitoring data, it means it is alive
raiseDeviceReconnect(device);
log.debug("Monitoring statistics: {}", monStats.toString());
return monStats;
}
Aggregations