use of org.projectfloodlight.openflow.protocol.OFGroupStatsReply in project onos by opennetworkinglab.
the class OpenFlowGroupProvider method pushGroupMetrics.
private void pushGroupMetrics(Dpid dpid, OFStatsReply statsReply) {
DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid));
OpenFlowSwitch sw = controller.getSwitch(dpid);
boolean containsGroupStats = false;
if (sw != null && sw.features() != null) {
containsGroupStats = sw.features().getCapabilities().contains(OFCapabilities.GROUP_STATS);
}
OFGroupStatsReply groupStatsReply = null;
OFGroupDescStatsReply groupDescStatsReply = null;
if (containsGroupStats) {
synchronized (groupStats) {
if (statsReply.getStatsType() == OFStatsType.GROUP) {
OFStatsReply reply = groupStats.get(statsReply.getXid() + 1);
if (reply != null) {
groupStatsReply = (OFGroupStatsReply) statsReply;
groupDescStatsReply = (OFGroupDescStatsReply) reply;
groupStats.remove(statsReply.getXid() + 1);
} else {
groupStats.put(statsReply.getXid(), statsReply);
}
} else if (statsReply.getStatsType() == OFStatsType.GROUP_DESC) {
OFStatsReply reply = groupStats.get(statsReply.getXid() - 1);
if (reply != null) {
groupStatsReply = (OFGroupStatsReply) reply;
groupDescStatsReply = (OFGroupDescStatsReply) statsReply;
groupStats.remove(statsReply.getXid() - 1);
} else {
groupStats.put(statsReply.getXid(), statsReply);
}
}
}
} else if (statsReply.getStatsType() == OFStatsType.GROUP_DESC) {
// We are only requesting group desc stats; see GroupStatsCollector.java:sendGroupStatisticRequests()
groupDescStatsReply = (OFGroupDescStatsReply) statsReply;
}
if (providerService != null && groupDescStatsReply != null) {
Collection<Group> groups = buildGroupMetrics(deviceId, groupStatsReply, groupDescStatsReply);
providerService.pushGroupMetrics(deviceId, groups);
for (Group group : groups) {
pendingGroupOperations.remove(group.id());
pendingXidMaps.remove(group.id());
}
}
}
use of org.projectfloodlight.openflow.protocol.OFGroupStatsReply 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