Committed by
Jonathan Hart
ONOS-961: Supports GROUP_STATS and GROUP_DESC_STATS events in OpenFlowController…
… for OpenFlowGroupProvider. Change-Id: Iea5e7a2a37a7a44367c54e99db44eb9399d48175
Showing
1 changed file
with
76 additions
and
21 deletions
... | @@ -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,17 +214,44 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -202,17 +214,44 @@ 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()) { |
206 | - for (OpenFlowSwitchListener l : ofSwitchListener) { | 218 | + case PORT_DESC: |
207 | - l.switchChanged(dpid); | 219 | + for (OpenFlowSwitchListener l : ofSwitchListener) { |
208 | - } | 220 | + l.switchChanged(dpid); |
209 | - } | 221 | + } |
210 | - stats = publishStats(dpid, reply); | 222 | + break; |
211 | - if (stats != null) { | 223 | + case FLOW: |
212 | - OFFlowStatsReply.Builder rep = | 224 | + flowStats = publishFlowStats(dpid, (OFFlowStatsReply) reply); |
213 | - OFFactories.getFactory(msg.getVersion()).buildFlowStatsReply(); | 225 | + if (flowStats != null) { |
214 | - rep.setEntries(Lists.newLinkedList(stats)); | 226 | + OFFlowStatsReply.Builder rep = |
215 | - executorMsgs.submit(new OFMessageHandler(dpid, rep.build())); | 227 | + OFFactories.getFactory(msg.getVersion()).buildFlowStatsReply(); |
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()); | ||
250 | + executorMsgs.submit(new OFMessageHandler(dpid, rep.build())); | ||
251 | + } | ||
252 | + break; | ||
253 | + default: | ||
254 | + log.warn("Unsupported stats type : {}", reply.getStatsType()); | ||
216 | } | 255 | } |
217 | break; | 256 | break; |
218 | case BARRIER_REPLY: | 257 | case BARRIER_REPLY: |
... | @@ -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()); |
251 | - return null; | 290 | + if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { |
291 | + return fullFlowStats.removeAll(dpid); | ||
252 | } | 292 | } |
253 | - final OFFlowStatsReply replies = (OFFlowStatsReply) reply; | 293 | + return null; |
254 | - fullStats.putAll(dpid, replies.getEntries()); | 294 | + } |
295 | + | ||
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 | } | ... | ... |
-
Please register or login to post a comment