Search in sources :

Example 1 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class DefaultOFSwitch method processStatsRequest.

@Override
public void processStatsRequest(Channel channel, OFMessage msg) {
    if (msg.getType() != OFType.STATS_REQUEST) {
        log.warn("Ignoring message of type {}.", msg.getType());
        return;
    }
    OFStatsRequest ofStatsRequest = (OFStatsRequest) msg;
    OFStatsReply ofStatsReply = null;
    switch(ofStatsRequest.getStatsType()) {
        case PORT_DESC:
            List<OFPortDesc> portDescs = new ArrayList<>();
            Set<Port> ports = ofSwitchService.ports(networkId, deviceId);
            ports.forEach(port -> {
                OFPortDesc ofPortDesc = portDesc(port);
                portDescs.add(ofPortDesc);
            });
            ofStatsReply = FACTORY.buildPortDescStatsReply().setXid(msg.getXid()).setEntries(portDescs).build();
            break;
        case PORT:
            OFPortStatsRequest portStatsRequest = (OFPortStatsRequest) msg;
            OFPort ofPort = portStatsRequest.getPortNo();
            List<OFPortStatsEntry> portStatsEntries = new ArrayList<>();
            List<PortStatistics> portStatistics = ofSwitchService.getPortStatistics(networkId, deviceId);
            if (ofPort.equals(OFPort.ANY)) {
                portStatistics.forEach(portStatistic -> {
                    OFPortStatsEntry ofPortStatsEntry = portStatsEntry(portStatistic);
                    portStatsEntries.add(ofPortStatsEntry);
                });
            }
            ofStatsReply = FACTORY.buildPortStatsReply().setEntries(portStatsEntries).setXid(msg.getXid()).build();
            break;
        case METER_FEATURES:
            OFMeterFeatures ofMeterFeatures = FACTORY.buildMeterFeatures().build();
            ofStatsReply = FACTORY.buildMeterFeaturesStatsReply().setXid(msg.getXid()).setFeatures(ofMeterFeatures).build();
            break;
        case FLOW:
            List<OFFlowStatsEntry> flowStatsEntries = new ArrayList<>();
            List<FlowEntry> flowStats = ofSwitchService.getFlowEntries(networkId, deviceId);
            flowStats.forEach(flowEntry -> {
                OFFlowStatsEntry ofFlowStatsEntry = ofFlowStatsEntry(flowEntry);
                flowStatsEntries.add(ofFlowStatsEntry);
            });
            ofStatsReply = FACTORY.buildFlowStatsReply().setEntries(flowStatsEntries).setXid(msg.getXid()).build();
            break;
        case TABLE:
            List<OFTableStatsEntry> ofTableStatsEntries = new ArrayList<>();
            List<TableStatisticsEntry> tableStats = ofSwitchService.getFlowTableStatistics(networkId, deviceId);
            tableStats.forEach(tableStatisticsEntry -> {
                OFTableStatsEntry ofFlowStatsEntry = ofFlowTableStatsEntry(tableStatisticsEntry);
                ofTableStatsEntries.add(ofFlowStatsEntry);
            });
            ofStatsReply = FACTORY.buildTableStatsReply().setEntries(ofTableStatsEntries).setXid(msg.getXid()).build();
            break;
        case GROUP:
            List<Group> groupStats = ofSwitchService.getGroups(networkId, deviceId);
            List<OFGroupStatsEntry> ofGroupStatsEntries = new ArrayList<>();
            groupStats.forEach(group -> {
                OFGroupStatsEntry entry = ofGroupStatsEntry(group);
                ofGroupStatsEntries.add(entry);
            });
            ofStatsReply = FACTORY.buildGroupStatsReply().setEntries(ofGroupStatsEntries).setXid(msg.getXid()).build();
            break;
        case GROUP_DESC:
            List<OFGroupDescStatsEntry> ofGroupDescStatsEntries = new ArrayList<>();
            List<Group> groupStats2 = ofSwitchService.getGroups(networkId, deviceId);
            groupStats2.forEach(group -> {
                OFGroupDescStatsEntry entry = ofGroupDescStatsEntry(group);
                ofGroupDescStatsEntries.add(entry);
            });
            ofStatsReply = FACTORY.buildGroupDescStatsReply().setEntries(ofGroupDescStatsEntries).setXid(msg.getXid()).build();
            break;
        case DESC:
            ofStatsReply = FACTORY.buildDescStatsReply().setXid(msg.getXid()).build();
            break;
        default:
            log.debug("Functionality not yet supported for type {} statsType{} msg {}", msg.getType(), ofStatsRequest.getStatsType(), msg);
            break;
    }
    if (ofStatsReply != null) {
        log.trace("request {}; reply {}", msg, ofStatsReply);
        channel.writeAndFlush(Collections.singletonList(ofStatsReply));
    }
}
Also used : OFStatsReply(org.projectfloodlight.openflow.protocol.OFStatsReply) OFGroup(org.projectfloodlight.openflow.types.OFGroup) Group(org.onosproject.net.group.Group) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) Port(org.onosproject.net.Port) OFPort(org.projectfloodlight.openflow.types.OFPort) ArrayList(java.util.ArrayList) OFPortStatsRequest(org.projectfloodlight.openflow.protocol.OFPortStatsRequest) FlowEntry(org.onosproject.net.flow.FlowEntry) OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) OFStatsRequest(org.projectfloodlight.openflow.protocol.OFStatsRequest) PortStatistics(org.onosproject.net.device.PortStatistics) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) OFGroupStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupStatsEntry) OFTableStatsEntry(org.projectfloodlight.openflow.protocol.OFTableStatsEntry) OFPort(org.projectfloodlight.openflow.types.OFPort) OFPortStatsEntry(org.projectfloodlight.openflow.protocol.OFPortStatsEntry) OFMeterFeatures(org.projectfloodlight.openflow.protocol.OFMeterFeatures)

Example 2 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class OpenstackVmStatsCommand method printPortStatsDelta.

private void printPortStatsDelta(String vmDeviceId, Iterable<PortStatistics> portStats, Set<PortNumber> portNumbers) {
    final String formatDelta = "   port=%s, pktRx=%s, pktTx=%s, bytesRx=%s, bytesTx=%s," + " rateRx=%s, rateTx=%s, pktRxDrp=%s, pktTxDrp=%s, interval=%s";
    print("VM Device ID: %s", vmDeviceId);
    for (PortStatistics stat : sortByPort(portStats)) {
        if (portNumbers.contains(stat.portNumber())) {
            float duration = ((float) stat.durationSec()) + (((float) stat.durationNano()) / TimeUnit.SECONDS.toNanos(1));
            float rateRx = stat.bytesReceived() * 8 / duration;
            float rateTx = stat.bytesSent() * 8 / duration;
            print(formatDelta, stat.portNumber(), stat.packetsReceived(), stat.packetsSent(), stat.bytesReceived(), stat.bytesSent(), String.format("%.1f", rateRx), String.format("%.1f", rateTx), stat.packetsRxDropped(), stat.packetsTxDropped(), String.format("%.3f", duration));
        }
    }
}
Also used : PortStatistics(org.onosproject.net.device.PortStatistics)

Example 3 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 4 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class DevicePortStatsCommand method jsonPortStats.

/**
 * Produces JSON array containing portstats of the specified device.
 *
 * @param deviceId  device id
 * @param portStats collection of port statistics
 * @return JSON array
 */
private JsonNode jsonPortStats(DeviceId deviceId, ObjectMapper mapper, Iterable<PortStatistics> portStats) {
    ObjectNode result = mapper.createObjectNode();
    ArrayNode portStatsNode = mapper.createArrayNode();
    for (PortStatistics stat : sortByPort(portStats)) {
        if (isIrrelevant(stat)) {
            continue;
        }
        if (nonzero && stat.isZero()) {
            continue;
        }
        portStatsNode.add(mapper.createObjectNode().put("port", stat.portNumber().toString()).put("pktRx", stat.packetsReceived()).put("pktTx", stat.packetsSent()).put("bytesRx", stat.bytesReceived()).put("bytesTx", stat.bytesSent()).put("pktRxDrp", stat.packetsRxDropped()).put("pktTxDrp", stat.packetsTxDropped()).put("Dur", stat.durationSec()).set("annotations", annotations(mapper, stat.annotations())));
    }
    result.put("deviceId", deviceId.toString());
    result.set("portStats", portStatsNode);
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PortStatistics(org.onosproject.net.device.PortStatistics)

Example 5 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class DevicePortStatsCommand method jsonPortStatsDelta.

/**
 * Produces JSON array containing delta portstats of the specified device id.
 *
 * @param deviceId  device id
 * @param portStats collection of port statistics
 * @return JSON array
 */
private JsonNode jsonPortStatsDelta(DeviceId deviceId, ObjectMapper mapper, Iterable<PortStatistics> portStats) {
    ObjectNode result = mapper.createObjectNode();
    ArrayNode portStatsNode = mapper.createArrayNode();
    for (PortStatistics stat : sortByPort(portStats)) {
        if (isIrrelevant(stat)) {
            continue;
        }
        if (nonzero && stat.isZero()) {
            continue;
        }
        float duration = ((float) stat.durationSec()) + (((float) stat.durationNano()) / TimeUnit.SECONDS.toNanos(1));
        float rateRx = stat.bytesReceived() * 8 / duration;
        float rateTx = stat.bytesSent() * 8 / duration;
        portStatsNode.add(mapper.createObjectNode().put("port", stat.portNumber().toString()).put("pktRx", stat.packetsReceived()).put("pktTx", stat.packetsSent()).put("bytesRx", stat.bytesReceived()).put("bytesTx", stat.bytesSent()).put("rateRx", String.format("%.1f", rateRx)).put("rateTx", String.format("%.1f", rateTx)).put("pktRxDrp", stat.packetsRxDropped()).put("pktTxDrp", stat.packetsTxDropped()).put("interval", String.format("%.3f", duration)));
    }
    result.put("deviceId", deviceId.toString());
    result.set("portStats", portStatsNode);
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PortStatistics(org.onosproject.net.device.PortStatistics)

Aggregations

PortStatistics (org.onosproject.net.device.PortStatistics)47 DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)26 PortNumber (org.onosproject.net.PortNumber)14 DeviceService (org.onosproject.net.device.DeviceService)14 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 DeviceId (org.onosproject.net.DeviceId)11 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)8 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 Device (org.onosproject.net.Device)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