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));
}
}
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();
}
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;
}
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;
}
}
Aggregations