From 31b4aaeb345a642d9f9f794a662bf8a2c89b11e6 Mon Sep 17 00:00:00 2001
From: "Banse, Christian" <christian.banse@aisec.fraunhofer.de>
Date: Fri, 15 May 2015 13:32:41 +0200
Subject: [PATCH] first attempt to re-enable message listeners to receive
 outgoing OF messages

---
 .gitignore                                             |  1 +
 .../java/net/floodlightcontroller/core/OFSwitch.java   | 10 ++++++++++
 .../core/internal/IOFSwitchManager.java                |  9 +++++++++
 .../core/internal/OFSwitchManager.java                 |  5 +++++
 .../core/test/MockSwitchManager.java                   |  6 ++++++
 5 files changed, 31 insertions(+)

diff --git a/.gitignore b/.gitignore
index 914574093..3f3378df5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,4 @@ findbugs-results
 /thrift
 *.idea/*
 *.iml
+/target/
diff --git a/src/main/java/net/floodlightcontroller/core/OFSwitch.java b/src/main/java/net/floodlightcontroller/core/OFSwitch.java
index 5360eb33d..c6421ce9d 100644
--- a/src/main/java/net/floodlightcontroller/core/OFSwitch.java
+++ b/src/main/java/net/floodlightcontroller/core/OFSwitch.java
@@ -715,6 +715,7 @@ public class OFSwitch implements IOFSwitchBackend {
 		log.trace("Channel: {}, Connected: {}", connections.get(OFAuxId.MAIN).getRemoteInetAddress(), connections.get(OFAuxId.MAIN).isConnected());
 		if (isActive()) {
 			connections.get(OFAuxId.MAIN).write(m);
+			switchManager.handleOutgoingMessage(this, m);			
 		} else {
 			log.warn("Attempted to write to switch {} that is SLAVE.", this.getId().toString());
 		}
@@ -746,6 +747,7 @@ public class OFSwitch implements IOFSwitchBackend {
 	public void write(OFMessage m, LogicalOFMessageCategory category) {
 		if (isActive()) {
 			this.getConnection(category).write(m);
+			switchManager.handleOutgoingMessage(this, m);			
 		} else {
 			log.warn("Attempted to write to switch {} that is SLAVE.", this.getId().toString());
 		}
@@ -755,6 +757,10 @@ public class OFSwitch implements IOFSwitchBackend {
 	public void write(Iterable<OFMessage> msglist, LogicalOFMessageCategory category) {
 		if (isActive()) {
 			this.getConnection(category).write(msglist);
+			
+			for(OFMessage m : msglist) {
+				switchManager.handleOutgoingMessage(this, m);				
+			}
 		} else {
 			log.warn("Attempted to write to switch {} that is SLAVE.", this.getId().toString());
 		}
@@ -785,6 +791,10 @@ public class OFSwitch implements IOFSwitchBackend {
 	public void write(Iterable<OFMessage> msglist) {
 		if (isActive()) {
 			connections.get(OFAuxId.MAIN).write(msglist);
+						
+			for(OFMessage m : msglist) {
+				switchManager.handleOutgoingMessage(this, m);
+			}
 		} else {
 			log.warn("Attempted to write to switch {} that is SLAVE.", this.getId().toString());
 		}
diff --git a/src/main/java/net/floodlightcontroller/core/internal/IOFSwitchManager.java b/src/main/java/net/floodlightcontroller/core/internal/IOFSwitchManager.java
index 787acc109..03df219d9 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/IOFSwitchManager.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/IOFSwitchManager.java
@@ -5,6 +5,7 @@ import java.util.List;
 import net.floodlightcontroller.core.FloodlightContext;
 import net.floodlightcontroller.core.IOFConnectionBackend;
 import net.floodlightcontroller.core.IOFSwitch.SwitchStatus;
+import net.floodlightcontroller.core.IOFSwitch;
 import net.floodlightcontroller.core.IOFSwitchBackend;
 import net.floodlightcontroller.core.IOFSwitchDriver;
 import net.floodlightcontroller.core.LogicalOFMessageCategory;
@@ -55,6 +56,14 @@ public interface IOFSwitchManager {
      * @param bContext the Floodlight context of the message, normally null in this case.
      */
     void handleMessage(IOFSwitchBackend sw, OFMessage m, FloodlightContext bContext);
+    
+    /**
+     * Process written messages through the message listeners for the controller
+     * @param sw The switch being written to
+     * @param m the message
+     * @throws NullPointerException if switch or msg is null
+     */
+    public void handleOutgoingMessage(IOFSwitch sw, OFMessage m);    
 
     /**
      * Gets an unmodifiable collection of OFSwitchHandshakeHandlers
diff --git a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchManager.java b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchManager.java
index a1dbced1e..99a1c4e80 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchManager.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchManager.java
@@ -503,6 +503,11 @@ public class OFSwitchManager implements IOFSwitchManager, INewOFConnectionListen
 	public void handleMessage(IOFSwitchBackend sw, OFMessage m, FloodlightContext bContext) {
 		floodlightProvider.handleMessage(sw, m, bContext);
 	}
+	
+	@Override
+	public void handleOutgoingMessage(IOFSwitch sw, OFMessage m) {
+		floodlightProvider.handleOutgoingMessage(sw, m);
+	}
 
 	@Override
 	public void addOFSwitchDriver(String manufacturerDescriptionPrefix,
diff --git a/src/test/java/net/floodlightcontroller/core/test/MockSwitchManager.java b/src/test/java/net/floodlightcontroller/core/test/MockSwitchManager.java
index 2bd6d0c37..6e8f51ccf 100644
--- a/src/test/java/net/floodlightcontroller/core/test/MockSwitchManager.java
+++ b/src/test/java/net/floodlightcontroller/core/test/MockSwitchManager.java
@@ -90,6 +90,12 @@ public class MockSwitchManager implements IFloodlightModule, IOFSwitchManager, I
         // do nothing
 
     }
+    
+    @Override
+    public void handleOutgoingMessage(IOFSwitch sw, OFMessage m) {
+    	// do nothing
+    	
+    }
 
     public void setSwitchHandshakeHandlers(Map<DatapathId, OFSwitchHandshakeHandler> handlers) {
         this.switchHandlers = handlers;
-- 
GitLab