diff --git a/src/main/java/net/floodlightcontroller/core/IOFSwitch.java b/src/main/java/net/floodlightcontroller/core/IOFSwitch.java index 428dc7f7e07ceb0598b2854668d6705a2cfa7efe..6bc92c98fae1e9866c99606d352f6115d1b0c618 100644 --- a/src/main/java/net/floodlightcontroller/core/IOFSwitch.java +++ b/src/main/java/net/floodlightcontroller/core/IOFSwitch.java @@ -107,7 +107,28 @@ public interface IOFSwitch { public void setChannel(Channel channel); /** - * Writes to the OFMessage to the output stream. + * Write OFMessage to the output stream, subject to switch rate limiting. + * The message will be handed to the floodlightProvider for possible filtering + * and processing by message listeners + * @param msg + * @param cntx + * @throws IOException + */ + public void writeThrottled(OFMessage msg, FloodlightContext cntx) throws IOException; + + /** + * Writes the list of messages to the output stream, subject to rate limiting. + * The message will be handed to the floodlightProvider for possible filtering + * and processing by message listeners. + * @param msglist + * @param bc + * @throws IOException + */ + void writeThrottled(List<OFMessage> msglist, FloodlightContext bc) + throws IOException; + + /** + * Writes to the OFMessage to the output stream, bypassing rate limiting. * The message will be handed to the floodlightProvider for possible filtering * and processing by message listeners * @param m @@ -117,7 +138,7 @@ public interface IOFSwitch { public void write(OFMessage m, FloodlightContext bc) throws IOException; /** - * Writes the list of messages to the output stream + * Writes the list of messages to the output stream, bypassing rate limiting. * The message will be handed to the floodlightProvider for possible filtering * and processing by message listeners. * @param msglist @@ -488,5 +509,4 @@ public interface IOFSwitch { * @return */ public List<Short> getUplinkPorts(); - } diff --git a/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java b/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java index 65265ca0caae46d6424d5bc1974ea030c1d8459d..31c1ae0753637cbffff5a410f8864ca68ea81848 100644 --- a/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java +++ b/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java @@ -183,6 +183,20 @@ public abstract class OFSwitchBase implements IOFSwitch { this.channel = channel; } + @Override + public void writeThrottled(OFMessage m, FloodlightContext bc) + throws IOException { + // By default, there is no throttling + write(m, bc); + } + + @Override + public void writeThrottled(List<OFMessage> msglist, FloodlightContext bc) + throws IOException { + // By default, there is no throttling + write(msglist, bc); + } + @Override public void write(OFMessage m, FloodlightContext bc) throws IOException { @@ -202,7 +216,6 @@ public abstract class OFSwitchBase implements IOFSwitch { msg_buffer.clear(); } } - @Override @LogMessageDoc(level="WARN", message="Sending OF message that modifies switch " + diff --git a/src/main/java/net/floodlightcontroller/util/OFMessageDamper.java b/src/main/java/net/floodlightcontroller/util/OFMessageDamper.java index 5de554f273b5badb6137fe8e5221326e37b2090a..75b0b00d3a9fb082e14a18e3da34712fcdee4e36 100644 --- a/src/main/java/net/floodlightcontroller/util/OFMessageDamper.java +++ b/src/main/java/net/floodlightcontroller/util/OFMessageDamper.java @@ -134,7 +134,7 @@ public class OFMessageDamper { FloodlightContext cntx, boolean flush) throws IOException { if (! msgTypesToCache.contains(msg.getType())) { - sw.write(msg, cntx); + sw.writeThrottled(msg, cntx); if (flush) { sw.flush(); } @@ -146,7 +146,7 @@ public class OFMessageDamper { // entry exists in cache. Dampening. return false; } else { - sw.write(msg, cntx); + sw.writeThrottled(msg, cntx); if (flush) { sw.flush(); } diff --git a/src/test/java/net/floodlightcontroller/forwarding/ForwardingTest.java b/src/test/java/net/floodlightcontroller/forwarding/ForwardingTest.java index 78fb6112d0d08a927090f6d35cf924a328db8d69..6e894a359cc2da78bbbde3b523cb329e7f552210 100644 --- a/src/test/java/net/floodlightcontroller/forwarding/ForwardingTest.java +++ b/src/test/java/net/floodlightcontroller/forwarding/ForwardingTest.java @@ -357,9 +357,9 @@ public class ForwardingTest extends FloodlightTestCase { OFFlowMod fm2 = fm1.clone(); ((OFActionOutput)fm2.getActions().get(0)).setPort((short) 3); - sw1.write(capture(wc1), capture(bc1)); + sw1.writeThrottled(capture(wc1), capture(bc1)); expectLastCall().anyTimes(); - sw2.write(capture(wc2), capture(bc2)); + sw2.writeThrottled(capture(wc2), capture(bc2)); expectLastCall().anyTimes(); reset(topology); @@ -420,8 +420,8 @@ public class ForwardingTest extends FloodlightTestCase { OFActionOutput.MINIMUM_LENGTH); // Record expected packet-outs/flow-mods - sw1.write(fm1, cntx); - sw1.write(packetOut, cntx); + sw1.writeThrottled(fm1, cntx); + sw1.writeThrottled(packetOut, cntx); reset(topology); expect(topology.isIncomingBroadcastAllowed(anyLong(), anyShort())).andReturn(true).anyTimes(); @@ -473,9 +473,9 @@ public class ForwardingTest extends FloodlightTestCase { // Record expected packet-outs/flow-mods // We will inject the packet_in 3 times and expect 1 flow mod and // 3 packet outs due to flow mod dampening - sw1.write(fm1, cntx); + sw1.writeThrottled(fm1, cntx); expectLastCall().once(); - sw1.write(packetOut, cntx); + sw1.writeThrottled(packetOut, cntx); expectLastCall().times(3); reset(topology); @@ -508,7 +508,7 @@ public class ForwardingTest extends FloodlightTestCase { .anyTimes(); expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_FLOOD)) .andReturn(true).anyTimes(); - sw1.write(packetOutFlooded, cntx); + sw1.writeThrottled(packetOutFlooded, cntx); expectLastCall().once(); replay(sw1, sw2, routingEngine, topology); forwarding.receive(sw1, this.packetIn, cntx); diff --git a/src/test/java/net/floodlightcontroller/loadbalancer/LoadBalancerTest.java b/src/test/java/net/floodlightcontroller/loadbalancer/LoadBalancerTest.java index 7311ac1aadd75dd13a19637f97a7edf7ff0e552b..2aeefa45658a1d595be5f14247bac1569fe14efe 100644 --- a/src/test/java/net/floodlightcontroller/loadbalancer/LoadBalancerTest.java +++ b/src/test/java/net/floodlightcontroller/loadbalancer/LoadBalancerTest.java @@ -433,7 +433,7 @@ public class LoadBalancerTest extends FloodlightTestCase { expect(sw1.getStringId()).andReturn("00:00:00:00:00:01").anyTimes(); expect(sw1.getAttribute(IOFSwitch.PROP_FASTWILDCARDS)).andReturn((Integer)fastWildcards).anyTimes(); expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_TABLE)).andReturn(true).anyTimes(); - sw1.write(capture(wc1), capture(bc1)); + sw1.writeThrottled(capture(wc1), capture(bc1)); expectLastCall().anyTimes(); sw1.flush(); expectLastCall().anyTimes(); diff --git a/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java b/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java index 5f09dc7dc8d00471f00a8ce1e2f13da01079e568..29191365cddad3344d7390f4d363cfcd0eaf8820 100644 --- a/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java +++ b/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java @@ -102,9 +102,22 @@ public class OFMessageDamperMockSwitch implements IOFSwitch { writtenContext = bc; writtenMessage = m; } + + @Override + public void writeThrottled(OFMessage msg, FloodlightContext cntx) + throws IOException { + write(msg, cntx); + } //------------------------------------------------------- // IOFSwitch: not-implemented methods + + @Override + public void writeThrottled(List<OFMessage> msglist, FloodlightContext bc) + throws IOException { + assertTrue("Unexpected method call", false); + } + @Override public void write(List<OFMessage> msglist, FloodlightContext bc) throws IOException { @@ -420,4 +433,4 @@ public class OFMessageDamperMockSwitch implements IOFSwitch { return false; } -} \ No newline at end of file +}