added disconnect delegator to conductor, session invalidation 34/1934/1
authorMichal Rehak <mirehak@cisco.com>
Mon, 14 Oct 2013 11:14:14 +0000 (13:14 +0200)
committerMichal Rehak <mirehak@cisco.com>
Wed, 16 Oct 2013 15:55:59 +0000 (17:55 +0200)
added findbugs report profile
added switchIdleEvent handling
added handling of disconnect caused by switch

Change-Id: Iee9a3cfdd5514da6ad877e48a6407140ad02f4d4
Signed-off-by: Michal Rehak <mirehak@cisco.com>
13 files changed:
commons/pom.xml
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductor.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImpl.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConfigurationFactory.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/SwitchConnectionDistinguisher.java [moved from openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/SwitchConnectionDestinguisher.java with 90% similarity]
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/OFSessionUtil.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionContext.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionContextOFImpl.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionManager.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionManagerOFImpl.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SwitchSessionKeyOFImpl.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/session/SwitchConnectionCookieOFImplTest.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/session/SwitchSessionKeyOFImplTest.java

index 1827f7d40a0d0e8b80a324999b2a8d377933c200..73ebe47aacbaa6b5f40ae9654a3fdd2706579dc5 100755 (executable)
         </pluginManagement>
     </build>
 
+    <profiles>
+      <profile>
+        <id>findbugsReport</id>
+        <reporting>
+          <plugins>
+            <plugin>
+              <groupId>org.codehaus.mojo</groupId>
+              <artifactId>findbugs-maven-plugin</artifactId>
+              <version>2.5.2</version>
+            </plugin>
+          </plugins>
+        </reporting>
+      </profile>
+    </profiles>
+
     <repositories>
         <!-- OpenDayLight Released artifact -->
         <repository>
index bd33944458afa9ff5f52bdbe5bb10ecb83ed77be..fec9ea98e695e14eaed7899c4d9e596cdb25d60d 100644 (file)
@@ -8,6 +8,10 @@
 
 package org.opendaylight.openflowplugin.openflow.md.core;
 
+import java.util.concurrent.Future;
+
+import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
+
 
 /**
  * @author mirehak
@@ -49,4 +53,33 @@ public interface ConnectionConductor {
      * @param conductorState
      */
     public void setConductorState(CONDUCTOR_STATE conductorState);
+
+    /**
+     * terminates owned connection
+     * @return future result of disconnect action
+     */
+    public Future<Boolean> disconnect();
+
+    /**
+     * assign corresponding {@link SessionContext} to this conductor (to handle disconnect caused by switch)
+     * @param context
+     */
+    public void setSessionContext(SessionContext context);
+
+    /**
+     * assign corresponding {@link SwitchConnectionDistinguisher} to this conductor
+     * to handle disconnect caused by switch. This involves auxiliary conductors only.
+     * @param auxiliaryKey
+     */
+    public void setConnectionCookie(SwitchConnectionDistinguisher auxiliaryKey);
+
+    /**
+     * @return the sessionContext
+     */
+    public SessionContext getSessionContext();
+
+    /**
+     * @return the auxiliaryKey (null if this is a primary connection)
+     */
+    public SwitchConnectionDistinguisher getAuxiliaryKey();
 }
index b906117f6a3bd297af4e7502863fa213fcd1dda3..5e92a111c2c762b43cecaa991372e7b6914a3c8e 100644 (file)
@@ -15,6 +15,10 @@ import java.util.concurrent.TimeUnit;
 
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
+import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
+import org.opendaylight.openflowplugin.openflow.md.core.session.SessionManager;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
@@ -30,7 +34,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEvent;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SystemNotificationsListener;
+import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -53,6 +59,10 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
     private ConnectionConductor.CONDUCTOR_STATE conductorState;
     private Short version;
 
+    private SwitchConnectionDistinguisher auxiliaryKey;
+
+    private SessionContext sessionContext;
+
     /**
      * @param connectionAdapter
      */
@@ -143,7 +153,8 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
                             + rpcFeatures.getResult().getDatapathId());
                     conductorState = CONDUCTOR_STATE.WORKING;
 
-                    OFSessionUtil.registerSession(this, rpcFeatures.getResult(), version);
+                    OFSessionUtil.registerSession(this,
+                            rpcFeatures.getResult(), version);
                     LOG.info("handshake SETTLED");
                 }
             } catch (Exception e) {
@@ -191,6 +202,44 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
         // TODO Auto-generated method stub
     }
 
+    @Override
+    public void onSwitchIdleEvent(SwitchIdleEvent notification) {
+        if (!CONDUCTOR_STATE.WORKING.equals(conductorState)) {
+            // idle state in any other conductorState than WORKING means real
+            // problem and wont
+            // be handled by echoReply
+            // TODO: invalidate this connection + notify
+        } else {
+            LOG.debug("first idle state occured");
+            EchoInputBuilder builder = new EchoInputBuilder();
+            builder.setVersion(version);
+            // TODO: get xid from sessionContext
+            builder.setXid(42L);
+
+            Future<RpcResult<EchoOutput>> echoReplyFuture = connectionAdapter
+                    .echo(builder.build());
+
+            try {
+                // TODO: read timeout from config
+                RpcResult<EchoOutput> echoReplyValue = echoReplyFuture.get(5,
+                        TimeUnit.SECONDS);
+                if (echoReplyValue.isSuccessful()) {
+                    conductorState = CONDUCTOR_STATE.WORKING;
+                } else {
+                    for (RpcError replyError : echoReplyValue.getErrors()) {
+                        Throwable cause = replyError.getCause();
+                        LOG.error(
+                                "while receiving echoReply in TIMEOUTING state: "
+                                        + cause.getMessage(), cause);
+                    }
+                }
+            } catch (Exception e) {
+                LOG.error("while waiting for echoReply in TIMEOUTING state: "
+                        + e.getMessage(), e);
+            }
+        }
+    }
+
     /**
      * @param conductorState
      *            the connectionState to set
@@ -217,7 +266,8 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
 
     @Override
     public void onDisconnectEvent(DisconnectEvent arg0) {
-        // TODO Auto-generated method stub
+        SessionManager sessionManager = OFSessionUtil.getSessionManager();
+        sessionManager.invalidateOnDisconnect(this);
     }
 
     protected short proposeVersion(short remoteVersion) {
@@ -239,4 +289,29 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
     public Short getVersion() {
         return version;
     }
+
+    @Override
+    public Future<Boolean> disconnect() {
+        return connectionAdapter.disconnect();
+    }
+
+    @Override
+    public void setConnectionCookie(SwitchConnectionDistinguisher auxiliaryKey) {
+        this.auxiliaryKey = auxiliaryKey;
+    }
+
+    @Override
+    public void setSessionContext(SessionContext sessionContext) {
+        this.sessionContext = sessionContext;
+    }
+
+    @Override
+    public SwitchConnectionDistinguisher getAuxiliaryKey() {
+        return auxiliaryKey;
+    }
+
+    @Override
+    public SessionContext getSessionContext() {
+        return sessionContext;
+    }
 }
index dfa5807499ae9eea0f42a29406c109f06d5ffd3f..9d5fad43b24ceae9b775b4488bfc4161a94209d0 100644 (file)
@@ -49,6 +49,16 @@ public abstract class ConnectionConfigurationFactory {
                 // TODO:: TCP/UDP ...
                 return null;
             }
+
+            @Override
+            public long getSwitchIdleTimeout() {
+                return 5000;
+            }
+
+            @Override
+            public Object getSslContext() {
+                return null;
+            }
         };
     }
 
@@ -11,7 +11,7 @@ package org.opendaylight.openflowplugin.openflow.md.core;
 /**
  * @author mirehak
  */
-public interface SwitchConnectionDestinguisher {
+public interface SwitchConnectionDistinguisher {
     /**
      * @return encoded switch session identifier
      */
index ad48183b63f01bdc1b422e160211527f3d3acb07..9a7eebba2e306b7ef3190475081c27e3947c0972 100644 (file)
@@ -11,7 +11,7 @@ package org.opendaylight.openflowplugin.openflow.md.core.session;
 import java.math.BigInteger;
 
 import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
-import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDestinguisher;
+import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -31,7 +31,7 @@ public abstract class OFSessionUtil {
      */
     public static void registerSession(ConnectionConductor connectionConductor,
             GetFeaturesOutput features, short version) {
-        SwitchConnectionDestinguisher sessionKey = createSwitchSessionKey(features
+        SwitchConnectionDistinguisher sessionKey = createSwitchSessionKey(features
                 .getDatapathId());
         SessionContext sessionContext = getSessionManager().getSessionContext(
                 sessionKey);
@@ -47,6 +47,9 @@ public abstract class OFSessionUtil {
             SessionContextOFImpl context = new SessionContextOFImpl();
             context.setPrimaryConductor(connectionConductor);
             context.setFeatures(features);
+            context.setSessionKey(sessionKey);
+            connectionConductor.setSessionContext(context);
+            context.setValid(true);
             getSessionManager().addSessionContext(sessionKey, context);
         } else {
             // handle auxiliary
@@ -55,7 +58,7 @@ public abstract class OFSessionUtil {
                         + dumpDataPathId(features.getDatapathId()));
             } else {
                 // register auxiliary conductor into existing sessionContext
-                SwitchConnectionDestinguisher auxiliaryKey = createConnectionCookie(features);
+                SwitchConnectionDistinguisher auxiliaryKey = createConnectionCookie(features);
                 if (sessionContext.getAuxiliaryConductor(auxiliaryKey) != null) {
                     LOG.warn("duplicate datapathId+auxiliary occured while registering switch session: "
                             + dumpDataPathId(features.getDatapathId())
@@ -67,6 +70,8 @@ public abstract class OFSessionUtil {
 
                 sessionContext.addAuxiliaryConductor(auxiliaryKey,
                         connectionConductor);
+                connectionConductor.setSessionContext(sessionContext);
+                connectionConductor.setConnectionCookie(auxiliaryKey);
             }
         }
     }
@@ -83,7 +88,7 @@ public abstract class OFSessionUtil {
      * @param datapathId
      * @return new session key
      */
-    public static SwitchConnectionDestinguisher createSwitchSessionKey(
+    public static SwitchConnectionDistinguisher createSwitchSessionKey(
             BigInteger datapathId) {
         SwitchSessionKeyOFImpl key = new SwitchSessionKeyOFImpl();
         key.setDatapathId(datapathId);
@@ -96,7 +101,7 @@ public abstract class OFSessionUtil {
      * @return connection cookie key
      * @see #createConnectionCookie(BigInteger, short)
      */
-    public static SwitchConnectionDestinguisher createConnectionCookie(
+    public static SwitchConnectionDistinguisher createConnectionCookie(
             GetFeaturesOutput features) {
         return createConnectionCookie(features.getDatapathId(),
                 features.getAuxiliaryId());
@@ -107,7 +112,7 @@ public abstract class OFSessionUtil {
      * @param auxiliaryId
      * @return connection cookie key
      */
-    public static SwitchConnectionDestinguisher createConnectionCookie(
+    public static SwitchConnectionDistinguisher createConnectionCookie(
             BigInteger datapathId, short auxiliaryId) {
         SwitchConnectionCookieOFImpl cookie = null;
         if (auxiliaryId != 0) {
index 56fe3f75e123e4803032f71c026427950ae0f8ff..e42e13ac4182613a27fb4ae28fb676afab2e774c 100644 (file)
@@ -8,10 +8,11 @@
 
 package org.opendaylight.openflowplugin.openflow.md.core.session;
 
-import java.util.Iterator;
+import java.util.Map.Entry;
+import java.util.Set;
 
 import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
-import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDestinguisher;
+import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
 
 /**
@@ -35,12 +36,12 @@ public interface SessionContext {
      * @return list of auxiliary connection wrappers
      */
     public ConnectionConductor getAuxiliaryConductor(
-            SwitchConnectionDestinguisher auxiliaryKey);
+            SwitchConnectionDistinguisher auxiliaryKey);
 
     /**
-     * @return iterator through all auxiliary connections wrapped in conductors
+     * @return entries of all auxiliary connections wrapped in conductors in this session
      */
-    public Iterator<ConnectionConductor> getAuxiliaryConductors();
+    public Set<Entry<SwitchConnectionDistinguisher, ConnectionConductor>> getAuxiliaryConductors();
 
     /**
      * register new auxiliary connection wrapped in {@link ConnectionConductor}
@@ -48,7 +49,7 @@ public interface SessionContext {
      * @param auxiliaryKey
      * @param conductor
      */
-    public void addAuxiliaryConductor(SwitchConnectionDestinguisher auxiliaryKey,
+    public void addAuxiliaryConductor(SwitchConnectionDistinguisher auxiliaryKey,
             ConnectionConductor conductor);
 
     /**
@@ -56,7 +57,22 @@ public interface SessionContext {
      * @return removed connectionConductor
      */
     public ConnectionConductor removeAuxiliaryConductor(
-            SwitchConnectionDestinguisher connectionCookie);
+            SwitchConnectionDistinguisher connectionCookie);
+
+    /**
+     * @return true if this session is valid
+     */
+    public boolean isValid();
+
+    /**
+     * @param valid the valid to set
+     */
+    public void setValid(boolean valid);
+
+    /**
+     * @return the sessionKey
+     */
+    public SwitchConnectionDistinguisher getSessionKey();
 
     // TODO:: add listeners here, manager will set them and conductor use them
 
index a4df782793add16a68126571f016431273b7d113..1349dd425362d9eac8ade47f019f4e9ffbff01db 100644 (file)
@@ -8,11 +8,13 @@
 
 package org.opendaylight.openflowplugin.openflow.md.core.session;
 
-import java.util.Iterator;
+import java.util.Collections;
+import java.util.Map.Entry;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
-import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDestinguisher;
+import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
 
 /**
@@ -22,7 +24,9 @@ public class SessionContextOFImpl implements SessionContext {
 
     private GetFeaturesOutput features;
     private ConnectionConductor primaryConductor;
-    private ConcurrentHashMap<Object, ConnectionConductor> auxiliaryConductors;
+    private ConcurrentHashMap<SwitchConnectionDistinguisher, ConnectionConductor> auxiliaryConductors;
+    private boolean valid;
+    private SwitchConnectionDistinguisher sessionKey;
 
     /**
      * default ctor
@@ -38,20 +42,20 @@ public class SessionContextOFImpl implements SessionContext {
 
     @Override
     public ConnectionConductor getAuxiliaryConductor(
-            SwitchConnectionDestinguisher auxiliaryKey) {
+            SwitchConnectionDistinguisher auxiliaryKey) {
         return auxiliaryConductors.get(auxiliaryKey);
     }
 
     @Override
     public void addAuxiliaryConductor(
-            SwitchConnectionDestinguisher auxiliaryKey,
+            SwitchConnectionDistinguisher auxiliaryKey,
             ConnectionConductor conductor) {
         auxiliaryConductors.put(auxiliaryKey, conductor);
     }
 
     @Override
-    public Iterator<ConnectionConductor> getAuxiliaryConductors() {
-        return auxiliaryConductors.values().iterator();
+    public Set<Entry<SwitchConnectionDistinguisher, ConnectionConductor>> getAuxiliaryConductors() {
+        return Collections.unmodifiableSet(auxiliaryConductors.entrySet());
     }
 
     @Override
@@ -77,7 +81,29 @@ public class SessionContextOFImpl implements SessionContext {
 
     @Override
     public ConnectionConductor removeAuxiliaryConductor(
-            SwitchConnectionDestinguisher connectionCookie) {
+            SwitchConnectionDistinguisher connectionCookie) {
         return auxiliaryConductors.remove(connectionCookie);
     }
+
+    @Override
+    public boolean isValid() {
+        return valid;
+    }
+
+    @Override
+    public void setValid(boolean valid) {
+        this.valid = valid;
+    }
+
+    /**
+     * @param sessionKey the sessionKey to set
+     */
+    public void setSessionKey(SwitchConnectionDistinguisher sessionKey) {
+        this.sessionKey = sessionKey;
+    }
+
+    @Override
+    public SwitchConnectionDistinguisher getSessionKey() {
+        return sessionKey;
+    }
 }
index 094c29c924f0cc828b36c46880457e517a0b223a..0dacd5dc16a9ec903a40418b611ff5cc9e10607e 100644 (file)
@@ -9,7 +9,8 @@
 package org.opendaylight.openflowplugin.openflow.md.core.session;
 
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
-import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDestinguisher;
+import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
+import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
 
 /**
  * @author mirehak
@@ -22,14 +23,14 @@ public interface SessionManager {
      *         primary connection
      */
     public SessionContext getSessionContext(
-            SwitchConnectionDestinguisher sessionKey);
+            SwitchConnectionDistinguisher sessionKey);
 
     /**
      * disconnect all underlying {@link ConnectionAdapter}s and notify listeners
      *
-     * @param fullKey
+     * @param sessionKey
      */
-    public void invalidateSessionContext(SwitchConnectionDestinguisher fullKey);
+    public void invalidateSessionContext(SwitchConnectionDistinguisher sessionKey);
 
     /**
      * register session context
@@ -37,8 +38,8 @@ public interface SessionManager {
      * @param sessionKey
      * @param context
      */
-    public void addSessionContext(SwitchConnectionDestinguisher sessionKey,
-            SessionContextOFImpl context);
+    public void addSessionContext(SwitchConnectionDistinguisher sessionKey,
+            SessionContext context);
 
     /**
      * disconnect particular auxiliary {@link ConnectionAdapter}, identified by
@@ -47,6 +48,11 @@ public interface SessionManager {
      * @param sessionKey
      * @param connectionCookie
      */
-    public void invalidateAuxiliary(SwitchConnectionDestinguisher sessionKey,
-            SwitchConnectionDestinguisher connectionCookie);
+    public void invalidateAuxiliary(SwitchConnectionDistinguisher sessionKey,
+            SwitchConnectionDistinguisher connectionCookie);
+
+    /**
+     * @param connectionConductor
+     */
+    public void invalidateOnDisconnect(ConnectionConductor connectionConductor);
 }
index e978d7ce504d9113a3406d250758e6ccea4bda52..3e9bb32fbaff0ed254e08e5e4e1678e5294196c9 100644 (file)
@@ -8,10 +8,11 @@
 
 package org.opendaylight.openflowplugin.openflow.md.core.session;
 
+import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
-import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDestinguisher;
+import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -23,7 +24,7 @@ public class SessionManagerOFImpl implements SessionManager {
     private static final Logger LOG = LoggerFactory
             .getLogger(SessionManagerOFImpl.class);
     private static SessionManagerOFImpl instance;
-    private ConcurrentHashMap<SwitchConnectionDestinguisher, SessionContext> sessionLot;
+    private ConcurrentHashMap<SwitchConnectionDistinguisher, SessionContext> sessionLot;
 
     /**
      * @return singleton instance
@@ -41,26 +42,65 @@ public class SessionManagerOFImpl implements SessionManager {
 
     @Override
     public SessionContext getSessionContext(
-            SwitchConnectionDestinguisher sessionKey) {
+            SwitchConnectionDistinguisher sessionKey) {
         return sessionLot.get(sessionKey);
     }
 
     @Override
-    public void invalidateSessionContext(SwitchConnectionDestinguisher fullKey) {
-        // TODO:: do some invalidating and disconnecting and notifying
+    public void invalidateSessionContext(
+            SwitchConnectionDistinguisher sessionKey) {
+        SessionContext context = getSessionContext(sessionKey);
+        if (context == null) {
+            LOG.warn("context for invalidation not found");
+        } else {
+            for (Entry<SwitchConnectionDistinguisher, ConnectionConductor> auxEntry : context
+                    .getAuxiliaryConductors()) {
+                invalidateAuxiliary(sessionKey, auxEntry.getKey());
+            }
+            context.getPrimaryConductor().disconnect();
+            context.setValid(false);
+            sessionLot.remove(sessionKey);
+            // TODO:: notify listeners
+        }
+    }
+
+    private void invalidateDeadSessionContext(SessionContext sessionContext) {
+        if (sessionContext == null) {
+            LOG.warn("context for invalidation not found");
+        } else {
+            for (Entry<SwitchConnectionDistinguisher, ConnectionConductor> auxEntry : sessionContext
+                    .getAuxiliaryConductors()) {
+                invalidateAuxiliary(sessionContext, auxEntry.getKey(), true);
+            }
+            sessionContext.setValid(false);
+            sessionLot.remove(sessionContext.getSessionKey(), sessionContext);
+            // TODO:: notify listeners
+        }
     }
 
     @Override
-    public void addSessionContext(SwitchConnectionDestinguisher sessionKey,
-            SessionContextOFImpl context) {
+    public void addSessionContext(SwitchConnectionDistinguisher sessionKey,
+            SessionContext context) {
         sessionLot.put(sessionKey, context);
         // TODO:: notify listeners
     }
 
     @Override
-    public void invalidateAuxiliary(SwitchConnectionDestinguisher sessionKey,
-            SwitchConnectionDestinguisher connectionCookie) {
+    public void invalidateAuxiliary(SwitchConnectionDistinguisher sessionKey,
+            SwitchConnectionDistinguisher connectionCookie) {
         SessionContext context = getSessionContext(sessionKey);
+        invalidateAuxiliary(context, connectionCookie, true);
+
+    }
+
+    /**
+     * @param context
+     * @param connectionCookie
+     * @param disconnect
+     *            true if auxiliary connection is to be disconnected
+     */
+    private static void invalidateAuxiliary(SessionContext context,
+            SwitchConnectionDistinguisher connectionCookie, boolean disconnect) {
         if (context == null) {
             LOG.warn("context for invalidation not found");
         } else {
@@ -69,9 +109,21 @@ public class SessionManagerOFImpl implements SessionManager {
             if (auxiliaryConductor == null) {
                 LOG.warn("auxiliary conductor not found");
             } else {
-                // TODO:: disconnect, notify
+                if (disconnect) {
+                    auxiliaryConductor.disconnect();
+                }
             }
         }
+    }
+
+    @Override
+    public void invalidateOnDisconnect(ConnectionConductor conductor) {
+        if (conductor.getAuxiliaryKey() == null) {
+            invalidateDeadSessionContext(conductor.getSessionContext());
+        } else {
+            invalidateAuxiliary(conductor.getSessionContext(),
+                    conductor.getAuxiliaryKey(), false);
+        }
 
     }
 
index 17fde93e02ff19cea6cecb1a678f84d0fe6056cd..50e7c69704628b30821634d73baa63ae4828e12e 100644 (file)
@@ -13,12 +13,12 @@ import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.Arrays;
 
-import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDestinguisher;
+import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
 
 /**
  * @author mirehak
  */
-public class SwitchSessionKeyOFImpl implements SwitchConnectionDestinguisher {
+public class SwitchSessionKeyOFImpl implements SwitchConnectionDistinguisher {
 
     protected byte[] encodedId;
     private BigInteger datapathId;
index b45e7b46f325bddb19cb4205861b97a81b1848b6..ac7930d6f77e17f5efd28c5654aefe7a6611ffd8 100644 (file)
@@ -16,7 +16,7 @@ import java.util.Map;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDestinguisher;
+import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -105,7 +105,7 @@ public class SwitchConnectionCookieOFImplTest {
                 (short) 21);
         key4.initId();
 
-        Map<SwitchConnectionDestinguisher, Integer> keyLot = new HashMap<>();
+        Map<SwitchConnectionDistinguisher, Integer> keyLot = new HashMap<>();
         keyLot.put(key1, System.identityHashCode(key1));
         Assert.assertEquals(1, keyLot.size());
         keyLot.put(key2, System.identityHashCode(key2));
index 69cfc2b8cfe73ceb90c6faa22777c639773aa81c..408af7db97aaa7174f778dbe3e50b05f4f78412d 100644 (file)
@@ -16,7 +16,7 @@ import java.util.Map;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDestinguisher;
+import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -98,7 +98,7 @@ public class SwitchSessionKeyOFImplTest {
         SwitchSessionKeyOFImpl key3 = createSwitchSessionKey("123456789");
         key3.initId();
 
-        Map<SwitchConnectionDestinguisher, Integer> keyLot = new HashMap<>();
+        Map<SwitchConnectionDistinguisher, Integer> keyLot = new HashMap<>();
         keyLot.put(key1, System.identityHashCode(key1));
         Assert.assertEquals(1, keyLot.size());
         keyLot.put(key2, System.identityHashCode(key2));