diff --git a/src/main/java/net/floodlightcontroller/core/IOFSwitch.java b/src/main/java/net/floodlightcontroller/core/IOFSwitch.java index bf897567280040891f82cf0997dd793a33b1af6b..fb7cd7d44d2167386a78534725956737adffdaad 100644 --- a/src/main/java/net/floodlightcontroller/core/IOFSwitch.java +++ b/src/main/java/net/floodlightcontroller/core/IOFSwitch.java @@ -374,6 +374,16 @@ public interface IOFSwitch { * @return value for name */ Object getAttribute(String name); + + /** + * Check if the given attribute is present and if so whether it is equal + * to "other" + * @param name the name of the attribute to check + * @param other the object to compare the attribute against. + * @return true iff the specified attribute is set and equals() the given + * other object. + */ + boolean attributeEquals(String name, Object other); /** * Set properties for switch specific behavior diff --git a/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java b/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java index 95f20f424e1a8e9b698067ab64a711a9be0a3f09..8998472cfc808bbcf5dac4e8b4f1c08f953626d4 100644 --- a/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java +++ b/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java @@ -147,13 +147,20 @@ public abstract class OFSwitchBase implements IOFSwitch { this.setAttribute(PROP_SUPPORTS_OFPP_TABLE, new Boolean(true)); } + + @Override + public boolean attributeEquals(String name, Object other) { + Object attr = this.attributes.get(name); + if (attr == null) + return false; + return attr.equals(other); + } + @Override public Object getAttribute(String name) { - if (this.attributes.containsKey(name)) { - return this.attributes.get(name); - } - return null; + // returns null if key doesn't exist + return this.attributes.get(name); } @Override @@ -172,6 +179,7 @@ public abstract class OFSwitchBase implements IOFSwitch { return this.attributes.containsKey(name); } + @Override @JsonIgnore public void setChannel(Channel channel) { this.channel = channel; @@ -452,6 +460,7 @@ public abstract class OFSwitchBase implements IOFSwitch { this.floodlightProvider = floodlightProvider; } + @Override @JsonIgnore public void setThreadPoolService(IThreadPoolService tp) { this.threadPool = tp; @@ -560,6 +569,7 @@ public abstract class OFSwitchBase implements IOFSwitch { * switch list from being modified out from under the listeners. * @return */ + @Override @JsonIgnore public Lock getListenerReadLock() { return listenerLock.readLock(); @@ -572,6 +582,7 @@ public abstract class OFSwitchBase implements IOFSwitch { * message from the switch. * @return */ + @Override @JsonIgnore public Lock getListenerWriteLock() { return listenerLock.writeLock(); @@ -581,6 +592,7 @@ public abstract class OFSwitchBase implements IOFSwitch { * Get the IP Address for the switch * @return the inet address */ + @Override @JsonSerialize(using=ToStringSerializer.class) public SocketAddress getInetAddress() { return channel.getRemoteAddress(); diff --git a/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java b/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java index 95fc5acedea46df21d8c9b0476dbbc3ee33a7ce3..6fd8e092226b8cebd4988bc0073b4ed9a912d2e6 100644 --- a/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java +++ b/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java @@ -398,4 +398,10 @@ public class OFMessageDamperMockSwitch implements IOFSwitch { return null; } + @Override + public boolean attributeEquals(String name, Object other) { + fail("Unexpected method call"); + return false; + } + } \ No newline at end of file