From 49207d43d523a2434aa4b92b4a2664312e3dad27 Mon Sep 17 00:00:00 2001 From: Gregor Maier <gregor.maier@bigswitch.com> Date: Tue, 1 Jan 2013 23:32:48 -0800 Subject: [PATCH] Add helper method that checks if an attribute equals a given object. --- .../floodlightcontroller/core/IOFSwitch.java | 10 ++++++++++ .../core/OFSwitchBase.java | 20 +++++++++++++++---- .../util/OFMessageDamperMockSwitch.java | 6 ++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/floodlightcontroller/core/IOFSwitch.java b/src/main/java/net/floodlightcontroller/core/IOFSwitch.java index bf8975672..fb7cd7d44 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 95f20f424..8998472cf 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 95fc5aced..6fd8e0922 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 -- GitLab