Search in sources :

Example 1 with OFGroupStatsEntry

use of org.projectfloodlight.openflow.protocol.OFGroupStatsEntry 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 OFGroupStatsEntry

use of org.projectfloodlight.openflow.protocol.OFGroupStatsEntry in project onos by opennetworkinglab.

the class OpenFlowGroupProvider method buildGroupMetrics.

private Collection<Group> buildGroupMetrics(DeviceId deviceId, OFGroupStatsReply groupStatsReply, OFGroupDescStatsReply groupDescStatsReply) {
    Map<Integer, Group> groups = Maps.newHashMap();
    Dpid dpid = Dpid.dpid(deviceId.uri());
    for (OFGroupDescStatsEntry entry : groupDescStatsReply.getEntries()) {
        int id = entry.getGroup().getGroupNumber();
        GroupId groupId = new GroupId(id);
        GroupDescription.Type type = getGroupType(entry.getGroupType());
        GroupBuckets buckets = new GroupBucketEntryBuilder(dpid, entry.getBuckets(), entry.getGroupType(), driverService).build();
        DefaultGroup group = new DefaultGroup(groupId, deviceId, type, buckets);
        groups.put(id, group);
    }
    if (groupStatsReply == null) {
        return groups.values();
    }
    for (OFGroupStatsEntry entry : groupStatsReply.getEntries()) {
        int groupId = entry.getGroup().getGroupNumber();
        DefaultGroup group = (DefaultGroup) groups.get(groupId);
        if (group != null) {
            group.setBytes(entry.getByteCount().getValue());
            group.setLife(entry.getDurationSec());
            group.setPackets(entry.getPacketCount().getValue());
            group.setReferenceCount(entry.getRefCount());
            int bucketIndex = 0;
            for (OFBucketCounter bucketStats : entry.getBucketStats()) {
                ((StoredGroupBucketEntry) group.buckets().buckets().get(bucketIndex)).setPackets(bucketStats.getPacketCount().getValue());
                ((StoredGroupBucketEntry) group.buckets().buckets().get(bucketIndex)).setBytes(entry.getBucketStats().get(bucketIndex).getByteCount().getValue());
                bucketIndex++;
            }
        }
    }
    return groups.values();
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) Dpid(org.onosproject.openflow.controller.Dpid) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupId(org.onosproject.core.GroupId) GroupDescription(org.onosproject.net.group.GroupDescription) OFGroupStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupStatsEntry) OFBucketCounter(org.projectfloodlight.openflow.protocol.OFBucketCounter) StoredGroupBucketEntry(org.onosproject.net.group.StoredGroupBucketEntry)

Example 3 with OFGroupStatsEntry

use of org.projectfloodlight.openflow.protocol.OFGroupStatsEntry in project onos by opennetworkinglab.

the class DefaultOFSwitch method ofGroupStatsEntry.

private OFGroupStatsEntry ofGroupStatsEntry(Group group) {
    List<OFBucketCounter> ofBucketCounters = Lists.newArrayList();
    group.buckets().buckets().forEach(groupBucket -> {
        ofBucketCounters.add(FACTORY.bucketCounter(U64.of(groupBucket.packets()), U64.of(groupBucket.bytes())));
    });
    OFGroupStatsEntry entry = FACTORY.buildGroupStatsEntry().setGroup(OFGroup.of(group.id().id())).setDurationSec(group.life()).setPacketCount(U64.of(group.packets())).setByteCount(U64.of(group.bytes())).setRefCount(group.referenceCount()).setBucketStats(ofBucketCounters).build();
    return entry;
}
Also used : OFGroupStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupStatsEntry) OFBucketCounter(org.projectfloodlight.openflow.protocol.OFBucketCounter)

Example 4 with OFGroupStatsEntry

use of org.projectfloodlight.openflow.protocol.OFGroupStatsEntry in project onos by opennetworkinglab.

the class OpenFlowControllerImpl method processStatsReply.

private void processStatsReply(Dpid dpid, OFStatsReply reply) {
    switch(reply.getStatsType()) {
        case QUEUE:
            Collection<OFQueueStatsEntry> queueStatsEntries = publishQueueStats(dpid, (OFQueueStatsReply) reply);
            if (queueStatsEntries != null) {
                OFQueueStatsReply.Builder rep = OFFactories.getFactory(reply.getVersion()).buildQueueStatsReply();
                rep.setEntries(ImmutableList.copyOf(queueStatsEntries));
                rep.setXid(reply.getXid());
                executorMsgs.execute(new OFMessageHandler(dpid, rep.build()));
            }
            break;
        case PORT_DESC:
            for (OpenFlowSwitchListener l : ofSwitchListener) {
                l.switchChanged(dpid);
            }
            break;
        case FLOW:
            Collection<OFFlowStatsEntry> flowStats = publishFlowStats(dpid, (OFFlowStatsReply) reply);
            if (flowStats != null) {
                OFFlowStatsReply.Builder rep = OFFactories.getFactory(reply.getVersion()).buildFlowStatsReply();
                rep.setEntries(ImmutableList.copyOf(flowStats));
                rep.setXid(reply.getXid());
                executorMsgs.execute(new OFMessageHandler(dpid, rep.build()));
            }
            break;
        case FLOW_LIGHTWEIGHT:
            Collection<OFFlowLightweightStatsEntry> flowLightweightStats = publishFlowStatsLightweight(dpid, (OFFlowLightweightStatsReply) reply);
            if (flowLightweightStats != null) {
                OFFlowLightweightStatsReply.Builder rep = OFFactories.getFactory(reply.getVersion()).buildFlowLightweightStatsReply();
                rep.setEntries(ImmutableList.copyOf(flowLightweightStats));
                rep.setXid(reply.getXid());
                executorMsgs.execute(new OFMessageHandler(dpid, rep.build()));
            }
            break;
        case TABLE:
            Collection<OFTableStatsEntry> tableStats = publishTableStats(dpid, (OFTableStatsReply) reply);
            if (tableStats != null) {
                OFTableStatsReply.Builder rep = OFFactories.getFactory(reply.getVersion()).buildTableStatsReply();
                rep.setEntries(ImmutableList.copyOf(tableStats));
                executorMsgs.execute(new OFMessageHandler(dpid, rep.build()));
            }
            break;
        case GROUP:
            Collection<OFGroupStatsEntry> groupStats = publishGroupStats(dpid, (OFGroupStatsReply) reply);
            if (groupStats != null) {
                OFGroupStatsReply.Builder rep = OFFactories.getFactory(reply.getVersion()).buildGroupStatsReply();
                rep.setEntries(ImmutableList.copyOf(groupStats));
                rep.setXid(reply.getXid());
                executorMsgs.execute(new OFMessageHandler(dpid, rep.build()));
            }
            break;
        case GROUP_DESC:
            Collection<OFGroupDescStatsEntry> groupDescStats = publishGroupDescStats(dpid, (OFGroupDescStatsReply) reply);
            if (groupDescStats != null) {
                OFGroupDescStatsReply.Builder rep = OFFactories.getFactory(reply.getVersion()).buildGroupDescStatsReply();
                rep.setEntries(ImmutableList.copyOf(groupDescStats));
                rep.setXid(reply.getXid());
                executorMsgs.execute(new OFMessageHandler(dpid, rep.build()));
            }
            break;
        case PORT:
            executorMsgs.execute(new OFMessageHandler(dpid, reply));
            break;
        case METER:
            executorMsgs.execute(new OFMessageHandler(dpid, reply));
            break;
        case EXPERIMENTER:
            if (reply instanceof OFCalientFlowStatsReply) {
                OpenFlowSwitch sw = this.getSwitch(dpid);
                // TODO: parse remaining fields such as power levels etc. when we have proper monitoring API
                if (sw == null) {
                    log.error("Switch {} is not found", dpid);
                    break;
                }
                OFFlowStatsReply.Builder fsr = sw.factory().buildFlowStatsReply();
                List<OFFlowStatsEntry> entries = new ArrayList<>();
                for (OFCalientFlowStatsEntry entry : ((OFCalientFlowStatsReply) reply).getEntries()) {
                    // Single instruction, i.e., output to port
                    OFActionOutput action = sw.factory().actions().buildOutput().setPort(entry.getOutPort()).build();
                    OFInstruction instruction = sw.factory().instructions().applyActions(Collections.singletonList(action));
                    OFFlowStatsEntry fs = sw.factory().buildFlowStatsEntry().setMatch(entry.getMatch()).setTableId(entry.getTableId()).setDurationSec(entry.getDurationSec()).setDurationNsec(entry.getDurationNsec()).setPriority(entry.getPriority()).setIdleTimeout(entry.getIdleTimeout()).setHardTimeout(entry.getHardTimeout()).setFlags(entry.getFlags()).setCookie(entry.getCookie()).setInstructions(Collections.singletonList(instruction)).build();
                    entries.add(fs);
                }
                fsr.setEntries(entries);
                flowStats = publishFlowStats(dpid, fsr.build());
                if (flowStats != null) {
                    OFFlowStatsReply.Builder rep = sw.factory().buildFlowStatsReply();
                    rep.setEntries(ImmutableList.copyOf(flowStats));
                    executorMsgs.execute(new OFMessageHandler(dpid, rep.build()));
                }
            } else {
                executorMsgs.execute(new OFMessageHandler(dpid, reply));
            }
            break;
        default:
            log.warn("Discarding unknown stats reply type {}", reply.getStatsType());
            break;
    }
}
Also used : OpenFlowSwitchListener(org.onosproject.openflow.controller.OpenFlowSwitchListener) OFQueueStatsEntry(org.projectfloodlight.openflow.protocol.OFQueueStatsEntry) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) OFFlowLightweightStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowLightweightStatsEntry) ArrayList(java.util.ArrayList) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) OFFlowLightweightStatsReply(org.projectfloodlight.openflow.protocol.OFFlowLightweightStatsReply) OFCalientFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFCalientFlowStatsEntry) OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) OFActionOutput(org.projectfloodlight.openflow.protocol.action.OFActionOutput) OFCalientFlowStatsReply(org.projectfloodlight.openflow.protocol.OFCalientFlowStatsReply) OFTableStatsReply(org.projectfloodlight.openflow.protocol.OFTableStatsReply) OFGroupStatsReply(org.projectfloodlight.openflow.protocol.OFGroupStatsReply) OFGroupStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupStatsEntry) OFTableStatsEntry(org.projectfloodlight.openflow.protocol.OFTableStatsEntry) OFGroupDescStatsReply(org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply) OFQueueStatsReply(org.projectfloodlight.openflow.protocol.OFQueueStatsReply)

Aggregations

OFGroupStatsEntry (org.projectfloodlight.openflow.protocol.OFGroupStatsEntry)4 OFGroupDescStatsEntry (org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry)3 ArrayList (java.util.ArrayList)2 Group (org.onosproject.net.group.Group)2 OFBucketCounter (org.projectfloodlight.openflow.protocol.OFBucketCounter)2 OFFlowStatsEntry (org.projectfloodlight.openflow.protocol.OFFlowStatsEntry)2 OFTableStatsEntry (org.projectfloodlight.openflow.protocol.OFTableStatsEntry)2 GroupId (org.onosproject.core.GroupId)1 Port (org.onosproject.net.Port)1 PortStatistics (org.onosproject.net.device.PortStatistics)1 FlowEntry (org.onosproject.net.flow.FlowEntry)1 TableStatisticsEntry (org.onosproject.net.flow.TableStatisticsEntry)1 DefaultGroup (org.onosproject.net.group.DefaultGroup)1 GroupBuckets (org.onosproject.net.group.GroupBuckets)1 GroupDescription (org.onosproject.net.group.GroupDescription)1 StoredGroupBucketEntry (org.onosproject.net.group.StoredGroupBucketEntry)1 Dpid (org.onosproject.openflow.controller.Dpid)1 OpenFlowSwitch (org.onosproject.openflow.controller.OpenFlowSwitch)1 OpenFlowSwitchListener (org.onosproject.openflow.controller.OpenFlowSwitchListener)1 OFCalientFlowStatsEntry (org.projectfloodlight.openflow.protocol.OFCalientFlowStatsEntry)1