diff --git a/src/main/java/net/floodlightcontroller/core/ImmutablePort.java b/src/main/java/net/floodlightcontroller/core/ImmutablePort.java index 406a9ebdec600a0a843a9a59f0c0bc0a24a6102c..5731b92d4ec4fd19eb889a00b0e3e88bd4f34b8c 100644 --- a/src/main/java/net/floodlightcontroller/core/ImmutablePort.java +++ b/src/main/java/net/floodlightcontroller/core/ImmutablePort.java @@ -45,6 +45,9 @@ public class ImmutablePort { if (p == null) { throw new NullPointerException("OFPhysicalPort must not be null"); } + if (p.getHardwareAddress() == null) { + throw new NullPointerException("Hardware address must not be null"); + } return new ImmutablePort( @@ -83,7 +86,7 @@ public class ImmutablePort { * * Verifies pre-conditions of arguments * Does NOT make defensive copies. Calling factory methods are required - * to copy defensively. + * to copy defensively if required. * * @param portNumber * @param hardwareAddress @@ -228,7 +231,11 @@ public class ImmutablePort { */ public String toBriefString() { return String.format("%d (%s)", portNumber, name); + } + @Override + public String toString() { + return toBriefString(); } /* (non-Javadoc) diff --git a/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java b/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java index 33b58015e38ade9f46cff261474c2a53792dbf9c..211dc57a9b895e12a24d8ec914132a9eb880e041 100644 --- a/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java +++ b/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java @@ -70,6 +70,7 @@ import org.openflow.protocol.OFStatisticsRequest; import org.openflow.protocol.OFType; import org.openflow.protocol.statistics.OFDescriptionStatistics; import org.openflow.protocol.statistics.OFStatistics; +import org.openflow.util.HexString; import org.openflow.util.U16; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -467,7 +468,7 @@ public abstract class OFSwitchBase implements IOFSwitch { */ public List<PortChangeEvent> updatePorts(Collection<ImmutablePort> newPorts) { - return compareAndUpdatePorts(newPorts, false); + return compareAndUpdatePorts(newPorts, true); } /** @@ -776,6 +777,7 @@ public abstract class OFSwitchBase implements IOFSwitch { portManager.updatePorts(immutablePorts); } this.datapathId = featuresReply.getDatapathId(); + this.stringId = HexString.toHexString(featuresReply.getDatapathId()); this.capabilities = featuresReply.getCapabilities(); this.buffers = featuresReply.getBuffers(); this.actions = featuresReply.getActions(); diff --git a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java index 5dbedbdd155c2eaaa878b22fe97c5239a3f86c0d..9f8a41ae93677589fb742696fc64ee962d4b99e6 100644 --- a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java +++ b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java @@ -1305,6 +1305,7 @@ public class ControllerTest extends FloodlightTestCase { OFFeaturesReply fr1a = createOFFeaturesReply(); fr1a.setDatapathId(1L); OFPhysicalPort p = createOFPhysicalPort("P1", 1); + ImmutablePort sw1p1 = ImmutablePort.fromOFPhysicalPort(p); List<OFPhysicalPort> ports1a = Collections.singletonList(p); fr1a.setPorts(ports1a); List<ImmutablePort> ports1aImmutable = @@ -1317,6 +1318,7 @@ public class ControllerTest extends FloodlightTestCase { List<OFPhysicalPort> ports1b = new ArrayList<OFPhysicalPort>(); ports1b.add(p); p = createOFPhysicalPort("P2", 42000); + ImmutablePort sw1p2 = ImmutablePort.fromOFPhysicalPort(p); ports1b.add(p); fr1b.setPorts(ports1b); List<ImmutablePort> ports1bImmutable = @@ -1327,6 +1329,7 @@ public class ControllerTest extends FloodlightTestCase { // and desc stats to store OFFeaturesReply fr2a = createOFFeaturesReply(); fr2a.setDatapathId(2L); + ImmutablePort sw2p1 = sw1p1; List<OFPhysicalPort> ports2a = new ArrayList<OFPhysicalPort>(ports1a); fr2a.setPorts(ports2a); List<ImmutablePort> ports2aImmutable = @@ -1336,6 +1339,7 @@ public class ControllerTest extends FloodlightTestCase { fr2b.setDatapathId(2L); p = new OFPhysicalPort(); p = createOFPhysicalPort("P1", 2); // port number changed + ImmutablePort sw2p1Changed = ImmutablePort.fromOFPhysicalPort(p); List<OFPhysicalPort> ports2b = Collections.singletonList(p); fr2b.setPorts(ports2b); @@ -1416,10 +1420,8 @@ public class ControllerTest extends FloodlightTestCase { // update switch 1 with fr1b reset(switchListener); - /* FIXME FIXME FIXME - switchListener.switchPortChanged(1L); + switchListener.switchPortChanged(1L, sw1p2, PortChangeType.ADD); expectLastCall().once(); - */ replay(switchListener); doAddSwitchToStore(1L, null, fr1b); controller.processUpdateQueueForTesting(); @@ -1494,10 +1496,9 @@ public class ControllerTest extends FloodlightTestCase { reset(switchListener); switchListener.switchActivated(2L); expectLastCall().once(); - /* FIXME FIXME FIXME - switchListener.switchPortChanged(2L); + switchListener.switchPortChanged(2L, sw2p1, PortChangeType.DELETE); + switchListener.switchPortChanged(2L, sw2p1Changed, PortChangeType.ADD); expectLastCall().once(); - */ replay(sw2); replay(switchListener); controller.switchActivated(sw2);