Search in sources :

Example 11 with PortStatistics

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;
}
Also used : DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) JsonNode(com.fasterxml.jackson.databind.JsonNode) PortStatistics(org.onosproject.net.device.PortStatistics) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) Map(java.util.Map)

Example 12 with 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;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) DeviceId(org.onosproject.net.DeviceId) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) PortStatistics(org.onosproject.net.device.PortStatistics) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) NetconfController(org.onosproject.netconf.NetconfController) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfException(org.onosproject.netconf.NetconfException)

Example 13 with PortStatistics

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);
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) PortStatistics(org.onosproject.net.device.PortStatistics) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) Test(org.junit.Test)

Example 14 with PortStatistics

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;
}
Also used : FlowInfo(org.onosproject.openstacktelemetry.api.FlowInfo) DefaultFlowInfo(org.onosproject.openstacktelemetry.api.DefaultFlowInfo) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) DriverService(org.onosproject.net.driver.DriverService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) PROP_MONITOR_OVERLAY_DEFAULT(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_MONITOR_OVERLAY_DEFAULT) FlowRuleService(org.onosproject.net.flow.FlowRuleService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) PROTOCOL_UDP(org.onlab.packet.IPv4.PROTOCOL_UDP) MastershipService(org.onosproject.mastership.MastershipService) OpenstackTelemetryService(org.onosproject.openstacktelemetry.api.OpenstackTelemetryService) PROP_EGRESS_STATS_DEFAULT(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_EGRESS_STATS_DEFAULT) OpenstackTelemetryUtil.getBooleanProperty(org.onosproject.openstacktelemetry.util.OpenstackTelemetryUtil.getBooleanProperty) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) StatsInfo(org.onosproject.openstacktelemetry.api.StatsInfo) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) DEFAULT_DATA_POINT_SIZE(org.onosproject.openstacktelemetry.api.Constants.DEFAULT_DATA_POINT_SIZE) DeviceId(org.onosproject.net.DeviceId) IPV4_DST(org.onosproject.net.flow.criteria.Criterion.Type.IPV4_DST) Dictionary(java.util.Dictionary) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) IPV4_SRC(org.onosproject.net.flow.criteria.Criterion.Type.IPV4_SRC) Host(org.onosproject.net.Host) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) DefaultStatsFlowRule(org.onosproject.openstacktelemetry.api.DefaultStatsFlowRule) ComponentContext(org.osgi.service.component.ComponentContext) STAT_FLAT_OUTBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.STAT_FLAT_OUTBOUND_TABLE) HostService(org.onosproject.net.host.HostService) ArrayList(java.util.ArrayList) VTAP_INBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.VTAP_INBOUND_TABLE) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) VXLAN(org.onosproject.openstacktelemetry.api.Constants.VXLAN) PROP_MONITOR_OVERLAY(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_MONITOR_OVERLAY) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) TCP_SRC(org.onosproject.net.flow.criteria.Criterion.Type.TCP_SRC) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) PROP_REVERSE_PATH_STATS(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_REVERSE_PATH_STATS) PROP_MONITOR_UNDERLAY(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_MONITOR_UNDERLAY) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) VlanId(org.onlab.packet.VlanId) FlowInfo(org.onosproject.openstacktelemetry.api.FlowInfo) MacAddress(org.onlab.packet.MacAddress) TCP_DST(org.onosproject.net.flow.criteria.Criterion.Type.TCP_DST) ScheduledFuture(java.util.concurrent.ScheduledFuture) CoreService(org.onosproject.core.CoreService) PROP_MONITOR_UNDERLAY_DEFAULT(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_MONITOR_UNDERLAY_DEFAULT) LoggerFactory(org.slf4j.LoggerFactory) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) StatsFlowRuleAdminService(org.onosproject.openstacktelemetry.api.StatsFlowRuleAdminService) SharedScheduledExecutors(org.onlab.util.SharedScheduledExecutors) STAT_OUTBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.STAT_OUTBOUND_TABLE) SWITCH(org.onosproject.net.Device.Type.SWITCH) IP_PROTO(org.onosproject.net.flow.criteria.Criterion.Type.IP_PROTO) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) UDP_SRC(org.onosproject.net.flow.criteria.Criterion.Type.UDP_SRC) Driver(org.onosproject.net.driver.Driver) TYPE_IPV4(org.onlab.packet.Ethernet.TYPE_IPV4) PROP_EGRESS_STATS(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_EGRESS_STATS) Device(org.onosproject.net.Device) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) VTAP_OUTBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.VTAP_OUTBOUND_TABLE) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) Optional(java.util.Optional) Queue(java.util.Queue) OPENSTACK_TELEMETRY_APP_ID(org.onosproject.openstacktelemetry.api.Constants.OPENSTACK_TELEMETRY_APP_ID) IpPrefix(org.onlab.packet.IpPrefix) DefaultStatsInfo(org.onosproject.openstacktelemetry.api.DefaultStatsInfo) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) PortStatistics(org.onosproject.net.device.PortStatistics) VTAP_FLAT_OUTBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.VTAP_FLAT_OUTBOUND_TABLE) VLAN(org.onosproject.openstacktelemetry.api.Constants.VLAN) CONTROLLER(org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) Activate(org.osgi.service.component.annotations.Activate) LinkedList(java.util.LinkedList) PROP_PORT_STATS(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_PORT_STATS) FLAT(org.onosproject.openstacktelemetry.api.Constants.FLAT) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) STAT_INBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.STAT_INBOUND_TABLE) Logger(org.slf4j.Logger) DefaultFlowInfo(org.onosproject.openstacktelemetry.api.DefaultFlowInfo) PROP_PORT_STATS_DEFAULT(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_PORT_STATS_DEFAULT) Maps(com.google.common.collect.Maps) PROP_REVERSE_PATH_STATS_DEFAULT(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_REVERSE_PATH_STATS_DEFAULT) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) StatsFlowRule(org.onosproject.openstacktelemetry.api.StatsFlowRule) Modified(org.osgi.service.component.annotations.Modified) PROTOCOL_TCP(org.onlab.packet.IPv4.PROTOCOL_TCP) UDP_DST(org.onosproject.net.flow.criteria.Criterion.Type.UDP_DST) Reference(org.osgi.service.component.annotations.Reference) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) DeviceId(org.onosproject.net.DeviceId) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) PortNumber(org.onosproject.net.PortNumber) PortStatistics(org.onosproject.net.device.PortStatistics)

Example 15 with PortStatistics

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;
}
Also used : DefaultTimingStatistics(org.onosproject.drivers.server.impl.stats.DefaultTimingStatistics) TimingStatistics(org.onosproject.drivers.server.stats.TimingStatistics) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultMonitoringStatistics(org.onosproject.drivers.server.impl.stats.DefaultMonitoringStatistics) MonitoringStatistics(org.onosproject.drivers.server.stats.MonitoringStatistics) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DefaultRestServerSBDevice(org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatistics(org.onosproject.net.device.PortStatistics) MemoryStatistics(org.onosproject.drivers.server.stats.MemoryStatistics) DefaultMemoryStatistics(org.onosproject.drivers.server.impl.stats.DefaultMemoryStatistics) DefaultCpuStatistics(org.onosproject.drivers.server.impl.stats.DefaultCpuStatistics) CpuStatistics(org.onosproject.drivers.server.stats.CpuStatistics) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(javax.ws.rs.ProcessingException)

Aggregations

PortStatistics (org.onosproject.net.device.PortStatistics)52 DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)26 DeviceId (org.onosproject.net.DeviceId)14 PortNumber (org.onosproject.net.PortNumber)14 DeviceService (org.onosproject.net.device.DeviceService)14 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 Device (org.onosproject.net.Device)10 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)8 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 Port (org.onosproject.net.Port)7 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 PortStatisticsDiscovery (org.onosproject.net.device.PortStatisticsDiscovery)6 ConnectPoint (org.onosproject.net.ConnectPoint)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Maps (com.google.common.collect.Maps)4 Collection (java.util.Collection)4 Set (java.util.Set)4