From 5b02ebd2fe814c3dbe1a8f03f216daf3d15e0c03 Mon Sep 17 00:00:00 2001 From: Alex Reimers <alex@bigswitch.com> Date: Fri, 11 May 2012 14:45:45 -0700 Subject: [PATCH] Fix a null pointer exception in DeviceManagerImpl [Bug #436: Resolved]. --- build.xml | 2 +- .../internal/DeviceManagerImpl.java | 2 ++ .../topology/NodePortTuple.java | 30 +++++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/build.xml b/build.xml index 58f4b71df..c94be94c1 100644 --- a/build.xml +++ b/build.xml @@ -111,7 +111,7 @@ debug="true" srcdir="${source}:${packetstreamer-gen}" destdir="${build}"> - </javac> + </javac> </target> <target name="compile-tests" depends="compile-test"/> diff --git a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java index ed47ecb66..a5b8352aa 100755 --- a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java +++ b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java @@ -621,6 +621,7 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe protected boolean inSamePortChannel(SwitchPortTuple swPort1, SwitchPortTuple swPort2) { IOFSwitch sw = swPort1.getSw(); + if (sw == null) return false; String portName = sw.getPort(swPort1.getPort()).getName(); String key = sw.getStringId() + portName; String portChannel1 = portChannelMap.get(key); @@ -628,6 +629,7 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe return false; sw = swPort2.getSw(); + if (sw == null) return false; portName = sw.getPort(swPort2.getPort()).getName(); key = sw.getStringId() + portName; String portChannel2 = portChannelMap.get(key); diff --git a/src/main/java/net/floodlightcontroller/topology/NodePortTuple.java b/src/main/java/net/floodlightcontroller/topology/NodePortTuple.java index a2fc7dfea..07f492688 100644 --- a/src/main/java/net/floodlightcontroller/topology/NodePortTuple.java +++ b/src/main/java/net/floodlightcontroller/topology/NodePortTuple.java @@ -1,15 +1,41 @@ package net.floodlightcontroller.topology; +import net.floodlightcontroller.linkdiscovery.SwitchPortTuple; + import org.openflow.util.HexString; +/** + * A NodePortTuple is similar to a SwitchPortTuple + * but it only stores IDs instead of references + * to the actual objects. + * @author srini + */ public class NodePortTuple { - protected long nodeId; - protected short portId; + protected long nodeId; // switch DPID + protected short portId; // switch port id + /** + * Creates a NodePortTuple + * @param nodeId The DPID of the switch + * @param portId The port of the switch + */ public NodePortTuple(long nodeId, short portId) { this.nodeId = nodeId; this.portId = portId; } + + /** + * Creates a NodePortTuple from the same information + * in a SwitchPortTuple + * @param swt + */ + public NodePortTuple(SwitchPortTuple swt) { + if (swt.getSw() != null) + this.nodeId = swt.getSw().getId(); + else + this.nodeId = 0; + this.portId = swt.getPort(); + } public long getNodeId() { return nodeId; -- GitLab