Bug-2827: role switch proposal
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / session / OFSessionUtil.java
index 41b4fae9068175f0b1809a674eb6e85a22f54658..d7d0e6761effc9f8d59e0613f634264d24208500 100644 (file)
@@ -14,11 +14,14 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
-import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
-import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator;
-import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
-import org.opendaylight.openflowplugin.openflow.md.core.TranslatorKey;
-import org.opendaylight.openflowplugin.openflow.md.queue.PopListener;
+import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
+import org.opendaylight.openflowplugin.api.openflow.md.core.session.SwitchSessionKeyOF;
+import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductorImpl;
+import org.opendaylight.openflowplugin.api.openflow.md.core.IMDMessageTranslator;
+import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
+import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
+import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
+import org.opendaylight.openflowplugin.api.openflow.md.queue.PopListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 import org.opendaylight.yangtools.yang.binding.DataObject;
@@ -38,9 +41,9 @@ public abstract class OFSessionUtil {
      * @param features
      * @param version
      */
-    public static void registerSession(ConnectionConductor connectionConductor,
+    public static void registerSession(ConnectionConductorImpl connectionConductor,
             GetFeaturesOutput features, short version) {
-        SwitchConnectionDistinguisher sessionKey = createSwitchSessionKey(features
+        SwitchSessionKeyOF sessionKey = createSwitchSessionKey(features
                 .getDatapathId());
         SessionContext sessionContext = getSessionManager().getSessionContext(sessionKey);
         if (LOG.isDebugEnabled()) {
@@ -57,10 +60,11 @@ public abstract class OFSessionUtil {
             // register new session context (based primary conductor)
             SessionContextOFImpl context = new SessionContextOFImpl();
             context.setPrimaryConductor(connectionConductor);
+            context.setNotificationEnqueuer(connectionConductor);
             context.setFeatures(features);
             context.setSessionKey(sessionKey);
+            context.setSeed((int) System.currentTimeMillis());
             connectionConductor.setSessionContext(context);
-            context.setValid(true);
             getSessionManager().addSessionContext(sessionKey, context);
         } else {
             // handle auxiliary
@@ -69,7 +73,7 @@ public abstract class OFSessionUtil {
                         + dumpDataPathId(features.getDatapathId()));
             } else {
                 // register auxiliary conductor into existing sessionContext
-                SwitchConnectionDistinguisher auxiliaryKey = createConnectionCookie(features);
+                SwitchConnectionDistinguisher auxiliaryKey = createConnectionCookie(features, sessionContext.getSeed());
                 if (sessionContext.getAuxiliaryConductor(auxiliaryKey) != null) {
                     LOG.warn("duplicate datapathId+auxiliary occured while registering switch session: "
                             + dumpDataPathId(features.getDatapathId())
@@ -109,46 +113,44 @@ public abstract class OFSessionUtil {
      * @param datapathId
      * @return new session key
      */
-    public static SwitchConnectionDistinguisher createSwitchSessionKey(
+    public static SwitchSessionKeyOF createSwitchSessionKey(
             BigInteger datapathId) {
-        SwitchSessionKeyOFImpl key = new SwitchSessionKeyOFImpl();
+        SwitchSessionKeyOF key = new SwitchSessionKeyOF();
         key.setDatapathId(datapathId);
-        key.initId();
         return key;
     }
 
     /**
      * @param features
+     * @param seed 
      * @return connection cookie key
-     * @see #createConnectionCookie(BigInteger, short)
+     * @see #createConnectionCookie(BigInteger,short, int)
      */
     public static SwitchConnectionDistinguisher createConnectionCookie(
-            GetFeaturesOutput features) {
+            GetFeaturesOutput features, int seed) {
         return createConnectionCookie(features.getDatapathId(),
-                features.getAuxiliaryId());
+                features.getAuxiliaryId(), seed);
     }
 
     /**
      * @param datapathId
      * @param auxiliaryId
+     * @param seed 
      * @return connection cookie key
      */
     public static SwitchConnectionDistinguisher createConnectionCookie(
-            BigInteger datapathId, short auxiliaryId) {
+            BigInteger datapathId, short auxiliaryId, int seed) {
         SwitchConnectionCookieOFImpl cookie = null;
-        if (auxiliaryId != 0) {
-            cookie = new SwitchConnectionCookieOFImpl();
-            cookie.setDatapathId(datapathId);
-            cookie.setAuxiliaryId(auxiliaryId);
-            cookie.initId();
-        }
+        cookie = new SwitchConnectionCookieOFImpl();
+        cookie.setAuxiliaryId(auxiliaryId);
+        cookie.init(datapathId.intValue() + seed);
         return cookie;
     }
 
     /**
      * @return session manager singleton instance
      */
-    public static SessionManager getSessionManager() {
+    public static ConjunctSessionManager getSessionManager() {
         return SessionManagerOFImpl.getInstance();
     }
     
@@ -170,8 +172,21 @@ public abstract class OFSessionUtil {
      * @return pop listener Map
      */
     public static Map<Class<? extends DataObject>, Collection<PopListener<DataObject>>> getPopListenerMapping() {
-        // TODO Auto-generated method stub
         return getSessionManager().getPopListenerMapping();
     }
 
+    /**
+     * @return extension converters provider
+     */
+    public static ExtensionConverterProvider getExtensionConvertorProvider() {
+        return getSessionManager().getExtensionConverterProvider();
+    }
+
+    /**
+     * @return collection of all sessions
+     */
+    public static Collection<SessionContext> getAllSessions() {
+        return getSessionManager().getAllSessions();
+    }
+
 }