Search in sources :

Example 1 with TableStatisticsEntry

use of org.onosproject.net.flow.TableStatisticsEntry 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 TableStatisticsEntry

use of org.onosproject.net.flow.TableStatisticsEntry in project onos by opennetworkinglab.

the class TableStatisticsCommand method printTableStats.

/**
 * Prints flow table statistics.
 *
 * @param d     the device
 * @param tableStats the set of flow table statistics for that device
 */
protected void printTableStats(Device d, List<TableStatisticsEntry> tableStats) {
    boolean empty = tableStats == null || tableStats.isEmpty();
    print("deviceId=%s, tableCount=%d", d.id(), empty ? 0 : tableStats.size());
    if (!empty) {
        for (TableStatisticsEntry t : tableStats) {
            print(FORMAT, t.table(), t.activeFlowEntries(), t.hasPacketsLookedup() ? t.packetsLookedup() : NA, t.packetsMatched(), t.hasMaxSize() ? t.maxSize() : NA);
        }
    }
}
Also used : TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry)

Example 3 with TableStatisticsEntry

use of org.onosproject.net.flow.TableStatisticsEntry in project onos by opennetworkinglab.

the class TableStatisticsCommand method getSortedTableStats.

/**
 * Returns the list of table statistics sorted using the device ID URIs and table IDs.
 *
 * @param deviceService device service
 * @param flowService flow rule service
 * @return sorted table statistics list
 */
protected SortedMap<Device, List<TableStatisticsEntry>> getSortedTableStats(DeviceService deviceService, FlowRuleService flowService) {
    SortedMap<Device, List<TableStatisticsEntry>> deviceTableStats = new TreeMap<>(Comparators.ELEMENT_COMPARATOR);
    List<TableStatisticsEntry> tableStatsList;
    Iterable<Device> devices = uri == null ? deviceService.getDevices() : Collections.singletonList(deviceService.getDevice(DeviceId.deviceId(uri)));
    for (Device d : devices) {
        tableStatsList = newArrayList(flowService.getFlowTableStatistics(d.id()));
        tableStatsList.sort((p1, p2) -> Integer.valueOf(p1.tableId()).compareTo(Integer.valueOf(p2.tableId())));
        deviceTableStats.put(d, tableStatsList);
    }
    return deviceTableStats;
}
Also used : Device(org.onosproject.net.Device) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) TreeMap(java.util.TreeMap) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry)

Example 4 with TableStatisticsEntry

use of org.onosproject.net.flow.TableStatisticsEntry in project onos by opennetworkinglab.

the class ECFlowRuleStore method getTableStatistics.

@Override
public Iterable<TableStatisticsEntry> getTableStatistics(DeviceId deviceId) {
    NodeId master = mastershipService.getMasterFor(deviceId);
    if (master == null && deviceService.isAvailable(deviceId)) {
        log.warn("Failed to getTableStats: No master for {}", deviceId);
        return Collections.emptyList();
    }
    List<TableStatisticsEntry> tableStats = deviceTableStats.get(deviceId);
    if (tableStats == null) {
        return Collections.emptyList();
    }
    return ImmutableList.copyOf(tableStats);
}
Also used : NodeId(org.onosproject.cluster.NodeId) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry)

Example 5 with TableStatisticsEntry

use of org.onosproject.net.flow.TableStatisticsEntry in project onos by opennetworkinglab.

the class P4RuntimeTableStatisticsDiscovery method getTableStatistics.

@Override
public List<TableStatisticsEntry> getTableStatistics() {
    if (!setupBehaviour("getTableStatistics()")) {
        return Collections.emptyList();
    }
    FlowRuleService flowService = handler().get(FlowRuleService.class);
    PiPipelineInterpreter interpreter = getInterpreter(handler());
    PiPipelineModel model = pipeconf.pipelineModel();
    List<TableStatisticsEntry> tableStatsList;
    List<FlowEntry> rules = newArrayList(flowService.getFlowEntries(deviceId));
    Map<PiTableId, Integer> piTableFlowCount = piFlowRuleCounting(model, interpreter, rules);
    Map<PiTableId, Long> piTableMatchCount = piMatchedCounting(model, interpreter, rules);
    tableStatsList = generatePiFlowTableStatistics(piTableFlowCount, piTableMatchCount, model, deviceId);
    return tableStatsList;
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry) PiPipelineModel(org.onosproject.net.pi.model.PiPipelineModel) DefaultTableStatisticsEntry(org.onosproject.net.flow.DefaultTableStatisticsEntry) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry)

Aggregations

TableStatisticsEntry (org.onosproject.net.flow.TableStatisticsEntry)12 FlowRuleService (org.onosproject.net.flow.FlowRuleService)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 DefaultTableStatisticsEntry (org.onosproject.net.flow.DefaultTableStatisticsEntry)3 FlowEntry (org.onosproject.net.flow.FlowEntry)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 Map (java.util.Map)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 NodeId (org.onosproject.cluster.NodeId)2 Device (org.onosproject.net.Device)2 DeviceId (org.onosproject.net.DeviceId)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1