sangho
Committed by Jonathan Hart

ONOS-961: Supports GROUP_STATS and GROUP_DESC_STATS events in OpenFlowController…

… for OpenFlowGroupProvider.

Change-Id: Iea5e7a2a37a7a44367c54e99db44eb9399d48175
...@@ -46,13 +46,16 @@ import org.projectfloodlight.openflow.protocol.OFExperimenter; ...@@ -46,13 +46,16 @@ import org.projectfloodlight.openflow.protocol.OFExperimenter;
46 import org.projectfloodlight.openflow.protocol.OFFactories; 46 import org.projectfloodlight.openflow.protocol.OFFactories;
47 import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry; 47 import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
48 import org.projectfloodlight.openflow.protocol.OFFlowStatsReply; 48 import org.projectfloodlight.openflow.protocol.OFFlowStatsReply;
49 +import org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry;
50 +import org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply;
51 +import org.projectfloodlight.openflow.protocol.OFGroupStatsEntry;
52 +import org.projectfloodlight.openflow.protocol.OFGroupStatsReply;
49 import org.projectfloodlight.openflow.protocol.OFMessage; 53 import org.projectfloodlight.openflow.protocol.OFMessage;
50 import org.projectfloodlight.openflow.protocol.OFPacketIn; 54 import org.projectfloodlight.openflow.protocol.OFPacketIn;
51 import org.projectfloodlight.openflow.protocol.OFPortDesc; 55 import org.projectfloodlight.openflow.protocol.OFPortDesc;
52 import org.projectfloodlight.openflow.protocol.OFPortStatus; 56 import org.projectfloodlight.openflow.protocol.OFPortStatus;
53 import org.projectfloodlight.openflow.protocol.OFStatsReply; 57 import org.projectfloodlight.openflow.protocol.OFStatsReply;
54 import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags; 58 import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags;
55 -import org.projectfloodlight.openflow.protocol.OFStatsType;
56 import org.slf4j.Logger; 59 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory; 60 import org.slf4j.LoggerFactory;
58 61
...@@ -90,7 +93,13 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -90,7 +93,13 @@ public class OpenFlowControllerImpl implements OpenFlowController {
90 93
91 protected Set<OpenFlowEventListener> ofEventListener = Sets.newHashSet(); 94 protected Set<OpenFlowEventListener> ofEventListener = Sets.newHashSet();
92 95
93 - protected Multimap<Dpid, OFFlowStatsEntry> fullStats = 96 + protected Multimap<Dpid, OFFlowStatsEntry> fullFlowStats =
97 + ArrayListMultimap.create();
98 +
99 + protected Multimap<Dpid, OFGroupStatsEntry> fullGroupStats =
100 + ArrayListMultimap.create();
101 +
102 + protected Multimap<Dpid, OFGroupDescStatsEntry> fullGroupDescStats =
94 ArrayListMultimap.create(); 103 ArrayListMultimap.create();
95 104
96 private final Controller ctrl = new Controller(); 105 private final Controller ctrl = new Controller();
...@@ -174,7 +183,10 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -174,7 +183,10 @@ public class OpenFlowControllerImpl implements OpenFlowController {
174 183
175 @Override 184 @Override
176 public void processPacket(Dpid dpid, OFMessage msg) { 185 public void processPacket(Dpid dpid, OFMessage msg) {
177 - Collection<OFFlowStatsEntry> stats; 186 + Collection<OFFlowStatsEntry> flowStats;
187 + Collection<OFGroupStatsEntry> groupStats;
188 + Collection<OFGroupDescStatsEntry> groupDescStats;
189 +
178 switch (msg.getType()) { 190 switch (msg.getType()) {
179 case PORT_STATUS: 191 case PORT_STATUS:
180 for (OpenFlowSwitchListener l : ofSwitchListener) { 192 for (OpenFlowSwitchListener l : ofSwitchListener) {
...@@ -202,19 +214,46 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -202,19 +214,46 @@ public class OpenFlowControllerImpl implements OpenFlowController {
202 break; 214 break;
203 case STATS_REPLY: 215 case STATS_REPLY:
204 OFStatsReply reply = (OFStatsReply) msg; 216 OFStatsReply reply = (OFStatsReply) msg;
205 - if (reply.getStatsType().equals(OFStatsType.PORT_DESC)) { 217 + switch (reply.getStatsType()) {
218 + case PORT_DESC:
206 for (OpenFlowSwitchListener l : ofSwitchListener) { 219 for (OpenFlowSwitchListener l : ofSwitchListener) {
207 l.switchChanged(dpid); 220 l.switchChanged(dpid);
208 } 221 }
209 - } 222 + break;
210 - stats = publishStats(dpid, reply); 223 + case FLOW:
211 - if (stats != null) { 224 + flowStats = publishFlowStats(dpid, (OFFlowStatsReply) reply);
225 + if (flowStats != null) {
212 OFFlowStatsReply.Builder rep = 226 OFFlowStatsReply.Builder rep =
213 OFFactories.getFactory(msg.getVersion()).buildFlowStatsReply(); 227 OFFactories.getFactory(msg.getVersion()).buildFlowStatsReply();
214 - rep.setEntries(Lists.newLinkedList(stats)); 228 + rep.setEntries(Lists.newLinkedList(flowStats));
229 + executorMsgs.submit(new OFMessageHandler(dpid, rep.build()));
230 + }
231 + break;
232 + case GROUP:
233 + groupStats = publishGroupStats(dpid, (OFGroupStatsReply) reply);
234 + if (groupStats != null) {
235 + OFGroupStatsReply.Builder rep =
236 + OFFactories.getFactory(msg.getVersion()).buildGroupStatsReply();
237 + rep.setEntries(Lists.newLinkedList(groupStats));
238 + rep.setXid(reply.getXid());
239 + executorMsgs.submit(new OFMessageHandler(dpid, rep.build()));
240 + }
241 + break;
242 + case GROUP_DESC:
243 + groupDescStats = publishGroupDescStats(dpid,
244 + (OFGroupDescStatsReply) reply);
245 + if (groupDescStats != null) {
246 + OFGroupDescStatsReply.Builder rep =
247 + OFFactories.getFactory(msg.getVersion()).buildGroupDescStatsReply();
248 + rep.setEntries(Lists.newLinkedList(groupDescStats));
249 + rep.setXid(reply.getXid());
215 executorMsgs.submit(new OFMessageHandler(dpid, rep.build())); 250 executorMsgs.submit(new OFMessageHandler(dpid, rep.build()));
216 } 251 }
217 break; 252 break;
253 + default:
254 + log.warn("Unsupported stats type : {}", reply.getStatsType());
255 + }
256 + break;
218 case BARRIER_REPLY: 257 case BARRIER_REPLY:
219 executorBarrier.submit(new OFMessageHandler(dpid, msg)); 258 executorBarrier.submit(new OFMessageHandler(dpid, msg));
220 break; 259 break;
...@@ -244,16 +283,32 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -244,16 +283,32 @@ public class OpenFlowControllerImpl implements OpenFlowController {
244 } 283 }
245 } 284 }
246 285
247 - private synchronized Collection<OFFlowStatsEntry> publishStats(Dpid dpid, 286 + private synchronized Collection<OFFlowStatsEntry> publishFlowStats(Dpid dpid,
248 - OFStatsReply reply) { 287 + OFFlowStatsReply reply) {
249 //TODO: Get rid of synchronized 288 //TODO: Get rid of synchronized
250 - if (reply.getStatsType() != OFStatsType.FLOW) { 289 + fullFlowStats.putAll(dpid, reply.getEntries());
290 + if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) {
291 + return fullFlowStats.removeAll(dpid);
292 + }
251 return null; 293 return null;
252 } 294 }
253 - final OFFlowStatsReply replies = (OFFlowStatsReply) reply; 295 +
254 - fullStats.putAll(dpid, replies.getEntries()); 296 + private synchronized Collection<OFGroupStatsEntry> publishGroupStats(Dpid dpid,
297 + OFGroupStatsReply reply) {
298 + //TODO: Get rid of synchronized
299 + fullGroupStats.putAll(dpid, reply.getEntries());
300 + if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) {
301 + return fullGroupStats.removeAll(dpid);
302 + }
303 + return null;
304 + }
305 +
306 + private synchronized Collection<OFGroupDescStatsEntry> publishGroupDescStats(Dpid dpid,
307 + OFGroupDescStatsReply reply) {
308 + //TODO: Get rid of synchronized
309 + fullGroupDescStats.putAll(dpid, reply.getEntries());
255 if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { 310 if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) {
256 - return fullStats.removeAll(dpid); 311 + return fullGroupDescStats.removeAll(dpid);
257 } 312 }
258 return null; 313 return null;
259 } 314 }
......