Add exception handling for unfound switch in processPacket
Change-Id: I9a9e539c02bf925ba3ab24b201d09a90e9163d96
Showing
1 changed file
with
19 additions
and
6 deletions
... | @@ -280,6 +280,8 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -280,6 +280,8 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
280 | Collection<OFGroupDescStatsEntry> groupDescStats; | 280 | Collection<OFGroupDescStatsEntry> groupDescStats; |
281 | Collection<OFPortStatsEntry> portStats; | 281 | Collection<OFPortStatsEntry> portStats; |
282 | 282 | ||
283 | + OpenFlowSwitch sw = this.getSwitch(dpid); | ||
284 | + | ||
283 | switch (msg.getType()) { | 285 | switch (msg.getType()) { |
284 | case PORT_STATUS: | 286 | case PORT_STATUS: |
285 | for (OpenFlowSwitchListener l : ofSwitchListener) { | 287 | for (OpenFlowSwitchListener l : ofSwitchListener) { |
... | @@ -292,9 +294,12 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -292,9 +294,12 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
292 | } | 294 | } |
293 | break; | 295 | break; |
294 | case PACKET_IN: | 296 | case PACKET_IN: |
297 | + if (sw == null) { | ||
298 | + log.error("Switch {} is not found", dpid); | ||
299 | + break; | ||
300 | + } | ||
295 | OpenFlowPacketContext pktCtx = DefaultOpenFlowPacketContext | 301 | OpenFlowPacketContext pktCtx = DefaultOpenFlowPacketContext |
296 | - .packetContextFromPacketIn(this.getSwitch(dpid), | 302 | + .packetContextFromPacketIn(sw, (OFPacketIn) msg); |
297 | - (OFPacketIn) msg); | ||
298 | for (PacketListener p : ofPacketListener.values()) { | 303 | for (PacketListener p : ofPacketListener.values()) { |
299 | p.handlePacket(pktCtx); | 304 | p.handlePacket(pktCtx); |
300 | } | 305 | } |
... | @@ -367,7 +372,11 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -367,7 +372,11 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
367 | if (reply instanceof OFCalientFlowStatsReply) { | 372 | if (reply instanceof OFCalientFlowStatsReply) { |
368 | // Convert Calient flow statistics to regular flow stats | 373 | // Convert Calient flow statistics to regular flow stats |
369 | // TODO: parse remaining fields such as power levels etc. when we have proper monitoring API | 374 | // TODO: parse remaining fields such as power levels etc. when we have proper monitoring API |
370 | - OFFlowStatsReply.Builder fsr = getSwitch(dpid).factory().buildFlowStatsReply(); | 375 | + if (sw == null) { |
376 | + log.error("Switch {} is not found", dpid); | ||
377 | + break; | ||
378 | + } | ||
379 | + OFFlowStatsReply.Builder fsr = sw.factory().buildFlowStatsReply(); | ||
371 | List<OFFlowStatsEntry> entries = new LinkedList<>(); | 380 | List<OFFlowStatsEntry> entries = new LinkedList<>(); |
372 | for (OFCalientFlowStatsEntry entry : ((OFCalientFlowStatsReply) msg).getEntries()) { | 381 | for (OFCalientFlowStatsEntry entry : ((OFCalientFlowStatsReply) msg).getEntries()) { |
373 | 382 | ||
... | @@ -382,7 +391,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -382,7 +391,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
382 | .getFactory(msg.getVersion()) | 391 | .getFactory(msg.getVersion()) |
383 | .instructions() | 392 | .instructions() |
384 | .applyActions(Collections.singletonList(action)); | 393 | .applyActions(Collections.singletonList(action)); |
385 | - OFFlowStatsEntry fs = getSwitch(dpid).factory().buildFlowStatsEntry() | 394 | + OFFlowStatsEntry fs = sw.factory().buildFlowStatsEntry() |
386 | .setMatch(entry.getMatch()) | 395 | .setMatch(entry.getMatch()) |
387 | .setTableId(entry.getTableId()) | 396 | .setTableId(entry.getTableId()) |
388 | .setDurationSec(entry.getDurationSec()) | 397 | .setDurationSec(entry.getDurationSec()) |
... | @@ -425,12 +434,16 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -425,12 +434,16 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
425 | } | 434 | } |
426 | break; | 435 | break; |
427 | case EXPERIMENTER: | 436 | case EXPERIMENTER: |
437 | + if (sw == null) { | ||
438 | + log.error("Switch {} is not found", dpid); | ||
439 | + break; | ||
440 | + } | ||
428 | long experimenter = ((OFExperimenter) msg).getExperimenter(); | 441 | long experimenter = ((OFExperimenter) msg).getExperimenter(); |
429 | if (experimenter == 0x748771) { | 442 | if (experimenter == 0x748771) { |
430 | // LINC-OE port stats | 443 | // LINC-OE port stats |
431 | OFCircuitPortStatus circuitPortStatus = (OFCircuitPortStatus) msg; | 444 | OFCircuitPortStatus circuitPortStatus = (OFCircuitPortStatus) msg; |
432 | - OFPortStatus.Builder portStatus = this.getSwitch(dpid).factory().buildPortStatus(); | 445 | + OFPortStatus.Builder portStatus = sw.factory().buildPortStatus(); |
433 | - OFPortDesc.Builder portDesc = this.getSwitch(dpid).factory().buildPortDesc(); | 446 | + OFPortDesc.Builder portDesc = sw.factory().buildPortDesc(); |
434 | portDesc.setPortNo(circuitPortStatus.getPortNo()) | 447 | portDesc.setPortNo(circuitPortStatus.getPortNo()) |
435 | .setHwAddr(circuitPortStatus.getHwAddr()) | 448 | .setHwAddr(circuitPortStatus.getHwAddr()) |
436 | .setName(circuitPortStatus.getName()) | 449 | .setName(circuitPortStatus.getName()) | ... | ... |
-
Please register or login to post a comment