diff --git a/src/main/java/net/floodlightcontroller/core/IOFSwitch.java b/src/main/java/net/floodlightcontroller/core/IOFSwitch.java index 623287ad2e0dc44b5cf80619bd42b093564a7b95..d63624cbd80848777e676e2aefa8bd2164e21534 100644 --- a/src/main/java/net/floodlightcontroller/core/IOFSwitch.java +++ b/src/main/java/net/floodlightcontroller/core/IOFSwitch.java @@ -84,11 +84,16 @@ public interface IOFSwitch { public Channel getChannel(); /** - * Returns the cached OFFeaturesReply message returned by the switch during - * the initial handshake. + * Returns switch features from features Reply * @return */ - public OFFeaturesReply getFeaturesReply(); + public int getBuffers(); + + public int getActions(); + + public int getCapabilities(); + + public byte getTables(); /** * Set the OFFeaturesReply message returned by the switch during initial diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java index cd0b511a7009b0ee56bb892d0781bfebd890e453..b866c7069b336a58dbfedfc774387f7319d60a84 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java +++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java @@ -1723,14 +1723,13 @@ public class Controller implements IFloodlightProviderService, } // Write out the switch features info - OFFeaturesReply featuresReply = sw.getFeaturesReply(); - long capabilities = U32.f(featuresReply.getCapabilities()); + long capabilities = U32.f(sw.getCapabilities()); switchInfo.put(SWITCH_CAPABILITIES, capabilities); - long buffers = U32.f(featuresReply.getBuffers()); + long buffers = U32.f(sw.getBuffers()); switchInfo.put(SWITCH_BUFFERS, buffers); - long tables = U32.f(featuresReply.getTables()); + long tables = U32.f(sw.getTables()); switchInfo.put(SWITCH_TABLES, tables); - long actions = U32.f(featuresReply.getActions()); + long actions = U32.f(sw.getActions()); switchInfo.put(SWITCH_ACTIONS, actions); switchInfo.put(SWITCH_ACTIVE, Boolean.TRUE); diff --git a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java index df92bd77f85beaedcc57e29d4dcc9b9c7fc08483..0d73de7f11515980d75558257823a7042c9f42d6 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java +++ b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java @@ -1,5 +1,5 @@ /** -* Copyright 2011, Big Switch Networks, Inc. +* Copyright 2012, Big Switch Networks, Inc. * Originally created by David Erickson, Stanford University * * Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -89,7 +89,6 @@ public class OFSwitchImpl implements IOFSwitch { protected IFloodlightProviderService floodlightProvider; protected IThreadPoolService threadPool; protected Date connectedSince; - protected OFFeaturesReply featuresReply; protected String stringId; protected Channel channel; protected AtomicInteger transactionIdSource; @@ -123,6 +122,13 @@ public class OFSwitchImpl implements IOFSwitch { */ protected LinkedList<PendingRoleRequestEntry> pendingRoleRequests; + /* Switch features from initial featuresReply */ + protected int capabilities; + protected int buffers; + protected int actions; + protected byte tables; + protected long datapathId; + public static IOFSwitchFeatures switchFeatures; protected static final ThreadLocal<Map<OFSwitchImpl,List<OFMessage>>> local_msg_buffer = new ThreadLocal<Map<OFSwitchImpl,List<OFMessage>>>() { @@ -148,6 +154,7 @@ public class OFSwitchImpl implements IOFSwitch { } public OFSwitchImpl() { + this.stringId = null; this.attributes = new ConcurrentHashMap<Object, Object>(); this.connectedSince = new Date(); this.transactionIdSource = new AtomicInteger(); @@ -262,21 +269,19 @@ public class OFSwitchImpl implements IOFSwitch { channel.close(); } - @Override - @JsonIgnore - public OFFeaturesReply getFeaturesReply() { - return this.featuresReply; - } - @Override @JsonIgnore public void setFeaturesReply(OFFeaturesReply featuresReply) { synchronized(portLock) { - this.featuresReply = featuresReply; for (OFPhysicalPort port : featuresReply.getPorts()) { setPort(port); } - this.stringId = HexString.toHexString(featuresReply.getDatapathId()); + this.datapathId = featuresReply.getDatapathId(); + this.capabilities = featuresReply.getCapabilities(); + this.buffers = featuresReply.getBuffers(); + this.actions = featuresReply.getActions(); + this.tables = featuresReply.getTables(); + this.stringId = HexString.toHexString(this.datapathId); } } @@ -375,9 +380,9 @@ public class OFSwitchImpl implements IOFSwitch { @JsonSerialize(using=DPIDSerializer.class) @JsonProperty("dpid") public long getId() { - if (this.featuresReply == null) + if (this.stringId == null) throw new RuntimeException("Features reply has not yet been set"); - return this.featuresReply.getDatapathId(); + return this.datapathId; } @JsonIgnore @@ -391,7 +396,7 @@ public class OFSwitchImpl implements IOFSwitch { */ @Override public String toString() { - return "OFSwitchImpl [" + channel.getRemoteAddress() + " DPID[" + ((featuresReply != null) ? stringId : "?") + "]]"; + return "OFSwitchImpl [" + channel.getRemoteAddress() + " DPID[" + ((stringId != null) ? stringId : "?") + "]]"; } @Override @@ -820,4 +825,28 @@ public class OFSwitchImpl implements IOFSwitch { public void cancelFeaturesReply(int transactionId) { this.featuresFutureMap.remove(transactionId); } + + + @Override + public int getBuffers() { + return buffers; + } + + + @Override + public int getActions() { + return actions; + } + + + @Override + public int getCapabilities() { + return capabilities; + } + + + @Override + public byte getTables() { + return tables; + } } diff --git a/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java b/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java index df6ab7c7e1278652e955a98a5b485c70e9b15aa7..dc5640e10764dd6b6c5a684c68d7fe415065f56a 100644 --- a/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java +++ b/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java @@ -443,7 +443,7 @@ public abstract class ForwardingBase // If the switch doens't support buffering set the buffer id to be none // otherwise it'll be the the buffer id of the PacketIn - if (sw.getFeaturesReply().getBuffers() == 0) { + if (sw.getBuffers() == 0) { // We set the PI buffer id here so we don't have to check again below pi.setBufferId(OFPacketOut.BUFFER_ID_NONE); po.setBufferId(OFPacketOut.BUFFER_ID_NONE); diff --git a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java index da47f272bf2236862c84e6a2b51df11c98b2001f..e98680ad8a46be75d8ffe0c1be5f9129f6870e16 100644 --- a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java +++ b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java @@ -159,19 +159,18 @@ public class ControllerTest extends FloodlightTestCase { protected void setupSwitchForAddSwitch(IOFSwitch sw, long dpid) { String dpidString = HexString.toHexString(dpid); - OFFeaturesReply featuresReply = new OFFeaturesReply(); - featuresReply.setDatapathId(dpid); - featuresReply.setPorts(new ArrayList<OFPhysicalPort>()); - expect(sw.getId()).andReturn(dpid).anyTimes(); expect(sw.getStringId()).andReturn(dpidString).anyTimes(); expect(sw.getConnectedSince()).andReturn(new Date()); Channel channel = createMock(Channel.class); expect(sw.getChannel()).andReturn(channel); expect(channel.getRemoteAddress()).andReturn(null); - - expect(sw.getFeaturesReply()).andReturn(featuresReply).anyTimes(); - expect(sw.getPorts()).andReturn(new ArrayList<OFPhysicalPort>()); + + expect(sw.getCapabilities()).andReturn(0).anyTimes(); + expect(sw.getBuffers()).andReturn(0).anyTimes(); + expect(sw.getTables()).andReturn((byte)0).anyTimes(); + expect(sw.getActions()).andReturn(0).anyTimes(); + expect(sw.getPorts()).andReturn(new ArrayList<OFPhysicalPort>()).anyTimes(); } /** @@ -196,7 +195,6 @@ public class ControllerTest extends FloodlightTestCase { IOFSwitch sw = createMock(IOFSwitch.class); expect(sw.getStringId()).andReturn("00:00:00:00:00:00:00").anyTimes(); - expect(sw.getFeaturesReply()).andReturn(new OFFeaturesReply()).anyTimes(); // Build our test packet IPacket testPacket = new Ethernet() @@ -250,7 +248,6 @@ public class ControllerTest extends FloodlightTestCase { expect(test1.receive(eq(sw), eq(pi), isA(FloodlightContext.class))).andReturn(Command.STOP); //expect(test1.getId()).andReturn(0).anyTimes(); expect(sw.getStringId()).andReturn("00:00:00:00:00:00:00").anyTimes(); - expect(sw.getFeaturesReply()).andReturn(new OFFeaturesReply()).anyTimes(); replay(test1, test2, sw); controller.handleMessage(sw, pi, null); verify(test1, test2, sw); @@ -493,7 +490,6 @@ public class ControllerTest extends FloodlightTestCase { //expect(oldsw.getId()).andReturn(0L).anyTimes(); //expect(oldsw.asyncRemoveSwitchLock()).andReturn(rwlock.writeLock()).anyTimes(); //oldsw.setConnected(false); - //expect(oldsw.getFeaturesReply()).andReturn(new OFFeaturesReply()).anyTimes(); //expect(oldsw.getStringId()).andReturn("00:00:00:00:00:00:00").anyTimes(); Channel channel = createNiceMock(Channel.class); @@ -508,8 +504,11 @@ public class ControllerTest extends FloodlightTestCase { Channel channel2 = createMock(Channel.class); expect(newsw.getChannel()).andReturn(channel2); expect(channel2.getRemoteAddress()).andReturn(null); - expect(newsw.getFeaturesReply()).andReturn(new OFFeaturesReply()).anyTimes(); expect(newsw.getPorts()).andReturn(new ArrayList<OFPhysicalPort>()); + expect(newsw.getCapabilities()).andReturn(0).anyTimes(); + expect(newsw.getBuffers()).andReturn(0).anyTimes(); + expect(newsw.getTables()).andReturn((byte)0).anyTimes(); + expect(newsw.getActions()).andReturn(0).anyTimes(); controller.activeSwitches.put(0L, oldsw); replay(newsw, channel, channel2); diff --git a/src/test/java/net/floodlightcontroller/forwarding/ForwardingTest.java b/src/test/java/net/floodlightcontroller/forwarding/ForwardingTest.java index ef6a2b0535ee0471fffc01a606bb04f0f72829d3..3c2a37289b5bb25861863e95bf566ba6b6c245da 100644 --- a/src/test/java/net/floodlightcontroller/forwarding/ForwardingTest.java +++ b/src/test/java/net/floodlightcontroller/forwarding/ForwardingTest.java @@ -158,13 +158,13 @@ public class ForwardingTest extends FloodlightTestCase { // Mock switches sw1 = EasyMock.createMock(IOFSwitch.class); expect(sw1.getId()).andReturn(1L).anyTimes(); - expect(sw1.getFeaturesReply()).andReturn(swFeatures).anyTimes(); + expect(sw1.getBuffers()).andReturn(swFeatures.getBuffers()).anyTimes(); expect(sw1.getStringId()) .andReturn(HexString.toHexString(1L)).anyTimes(); sw2 = EasyMock.createMock(IOFSwitch.class); expect(sw2.getId()).andReturn(2L).anyTimes(); - expect(sw2.getFeaturesReply()).andReturn(swFeatures).anyTimes(); + expect(sw2.getBuffers()).andReturn(swFeatures.getBuffers()).anyTimes(); expect(sw2.getStringId()) .andReturn(HexString.toHexString(2L)).anyTimes(); diff --git a/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java b/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java index bacaff5046d303fc8adba34c7eb4889f9b018bbc..59e0a51b8b24e98449a8c7598c5cab019620eaea 100644 --- a/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java +++ b/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java @@ -102,12 +102,6 @@ public class OFMessageDamperMockSwitch implements IOFSwitch { return null; } - @Override - public OFFeaturesReply getFeaturesReply() { - assertTrue("Unexpected method call", false); - return null; - } - @Override public void setFeaturesReply(OFFeaturesReply featuresReply) { assertTrue("Unexpected method call", false); @@ -328,4 +322,28 @@ public class OFMessageDamperMockSwitch implements IOFSwitch { } + @Override + public int getBuffers() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int getActions() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int getCapabilities() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte getTables() { + // TODO Auto-generated method stub + return 0; + } + } \ No newline at end of file