From 80ac8895d045501b98942e122e82724274d69f49 Mon Sep 17 00:00:00 2001 From: Mandeep Dhami <mandeep.dhami@bigswitch.com> Date: Fri, 24 Feb 2012 17:07:38 -0800 Subject: [PATCH] Updated to flush all writes when a list of incomming messages has been handled --- .../core/internal/Controller.java | 3 ++ .../core/internal/OFSwitchImpl.java | 29 ++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java index e613e2125..1626938ab 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java +++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java @@ -333,6 +333,9 @@ public class Controller Channels.fireExceptionCaught(ctx.getChannel(), ex); } } + + // Flush all flow-mods/packet-out generated from this "train" + OFSwitchImpl.flush_all(); } } diff --git a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java index 0bda63c7a..44fffddc0 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java +++ b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java @@ -142,15 +142,16 @@ public class OFSwitchImpl implements IOFSwitch { Map<OFSwitchImpl,List<OFMessage>> msg_buffer_map = local_msg_buffer.get(); List<OFMessage> msg_buffer = msg_buffer_map.get(this); if (msg_buffer == null) { - msg_buffer = new ArrayList<OFMessage>(); - msg_buffer_map.put(this, msg_buffer); + msg_buffer = new ArrayList<OFMessage>(); + msg_buffer_map.put(this, msg_buffer); } - // handleOutgoingMessage is done at the time of flushing the buffer + this.floodlightProvider.handleOutgoingMessage(this, m, bc); msg_buffer.add(m); + if ((msg_buffer.size() >= Controller.BATCH_MAX_SIZE) || ((m.getType() != OFType.PACKET_OUT) && (m.getType() != OFType.FLOW_MOD))) { - this.write(msg_buffer, bc); + this.write(msg_buffer); msg_buffer.clear(); } } @@ -159,6 +160,10 @@ public class OFSwitchImpl implements IOFSwitch { for (OFMessage m : msglist) { this.floodlightProvider.handleOutgoingMessage(this, m, bc); } + this.write(msglist); + } + + public void write(List<OFMessage> msglist) throws IOException { this.channel.write(msglist); } @@ -389,6 +394,22 @@ public class OFSwitchImpl implements IOFSwitch { return timedCache; } + public static void flush_all() { + Map<OFSwitchImpl,List<OFMessage>> msg_buffer_map = local_msg_buffer.get(); + for (OFSwitchImpl sw : msg_buffer_map.keySet()) { + List<OFMessage> msglist = msg_buffer_map.get(sw); + if (msglist.size() > 0) { + try { + sw.write(msglist); + } catch (IOException e) { + // TODO: log exception + e.printStackTrace(); + } + msglist.clear(); + } + } + } + /** * Return a lock that need to be held while processing a message. Multiple threads * can hold this lock. -- GitLab