Implement core API's methods. 77/48877/13
authorJozef Bacigal <jozef.bacigal@pantheon.tech>
Mon, 21 Nov 2016 11:30:37 +0000 (12:30 +0100)
committerJozef Bacigal <jozef.bacigal@pantheon.tech>
Thu, 9 Mar 2017 09:35:26 +0000 (10:35 +0100)
Change-Id: I3005c82e2cdea0cf719c5f500041ad3ad9ce4480
Signed-off-by: Jozef Bacigal <jozef.bacigal@pantheon.tech>
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/OFPManager.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/lifecycle/ContextChain.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/lifecycle/ContextChainHolder.java
openflowplugin-api/src/main/yang/openflow-provider-config.yang
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/lifecycle/ContextChainHolderImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/lifecycle/ContextChainImpl.java

index a857cb201e635b22568600f5877d075cc63a412b..c7c76dfa622b396f11d8964b01616f462cd81139 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.openflowplugin.api.openflow;
 
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceLifecycleSupervisor;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceRemovedHandler;
@@ -31,6 +32,10 @@ public interface OFPManager extends
         DeviceRemovedHandler,
         AutoCloseable {
 
+    default void createContext(final DeviceInfo deviceInfo) {
+        //TODO: remove default after implementation in all managers !!!
+    }
+
     @Override
     void close();
 }
index 8821e81564ec6d7b83e8e119d4b9842bbacaab57..f64bf84925b840ed40a2a45f017f24b0de4e90ba 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.openflowplugin.api.openflow.lifecycle;
 
 import java.util.concurrent.Future;
 import org.opendaylight.openflowplugin.api.openflow.OFPContext;
+import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 
 /**
  * Chain of contexts, hold references to the contexts
@@ -42,4 +43,10 @@ public interface ContextChain extends AutoCloseable {
     @Override
     void close();
 
+    /**
+     * Change connection if connection were drop and rebuild
+     * @param connectionContext
+     */
+    void changePrimaryConnection(final ConnectionContext connectionContext);
+
 }
index f017787cae4736c31e0f810e6d8360bbb669a66f..d043c7ea2188d75f071dcfeb9259d60cfcec5768 100644 (file)
@@ -19,10 +19,15 @@ public interface ContextChainHolder {
 
     <T extends OFPManager> void addManager(final T manager);
     Future<Void> createContextChain(final DeviceInfo deviceInfo);
-    Future<Void> pairConnection(final DeviceInfo deviceInfo);
     Future<Void> connectionLost(final DeviceInfo deviceInfo);
     void destroyContextChain(final DeviceInfo deviceInfo);
 
-    void addConnection(final ConnectionContext connectionContext);
+    /**
+     * This method will pair up connection with existing context chain
+     * If context chain doesn't exist will create context chain a set this connection as primary to the new created context chain
+     * If context chain cannot be created close connection and destroy context chain
+     * @param connectionContext new connection
+     */
+    void pairConnection(final ConnectionContext connectionContext);
 
 }
index eedf355e0e65194a7527ef6bfb80cdc0e0b48c85..b30519a14f9ba05d8aaf5c9fac3b3ada87a7c137 100644 (file)
@@ -23,6 +23,9 @@ module openflow-provider-config {
             enum WORKING_SLAVE {
                 description "Context chain is working as SLAVE";
             }
+            enum ON_HOLD {
+                description "Context chain is on hold, after connection lost";
+            }
         }
     }
 
@@ -152,6 +155,12 @@ module openflow-provider-config {
                 default WORKING_SLAVE;
             }
 
+            leaf number-of-needed-managers {
+                description "chceck number for needed managers";
+                type uint16;
+                default 3;
+            }
+
         }
 
     }
index 1d4e10abdeebbd4f7c2e0b45d2e240fdd458937b..7bee5599f8a5da03e2a3fc49cf09760ba926fd2a 100644 (file)
@@ -7,7 +7,10 @@
  */
 package org.opendaylight.openflowplugin.impl.lifecycle;
 
+import com.google.common.base.Verify;
+import com.google.common.util.concurrent.Futures;
 import java.util.HashSet;
+import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.Future;
@@ -31,30 +34,46 @@ public class ContextChainHolderImpl implements ContextChainHolder {
 
     @Override
     public <T extends OFPManager> void addManager(final T manager) {
+        managers.add(manager);
     }
 
     @Override
     public Future<Void> createContextChain(final DeviceInfo deviceInfo) {
-        return null;
-    }
-
-    @Override
-    public Future<Void> pairConnection(final DeviceInfo deviceInfo) {
+        Verify.verify(this.checkAllManagers(),"Not all manager were set.");
         return null;
     }
 
     @Override
     public Future<Void> connectionLost(final DeviceInfo deviceInfo) {
+        if (!this.checkChainContext(deviceInfo)) {
+            return Futures.immediateFuture(null);
+        }
         return null;
     }
 
     @Override
     public void destroyContextChain(final DeviceInfo deviceInfo) {
+        ContextChain chain = contextChainMap.get(deviceInfo);
+        if (Objects.nonNull(chain)) {
+            chain.close();
+        }
     }
 
     @Override
-    public void addConnection(final ConnectionContext connectionContext) {
+    public void pairConnection(final ConnectionContext connectionContext) {
+        DeviceInfo deviceInfo = connectionContext.getDeviceInfo();
+        latestConnections.put(deviceInfo, connectionContext);
+        if (checkChainContext(deviceInfo)) {
+            contextChainMap.get(deviceInfo).changePrimaryConnection(connectionContext);
+        }
+    }
+
+    private boolean checkAllManagers() {
+        return config.getNumberOfNeededManagers().equals(managers.size());
+    }
 
+    private boolean checkChainContext(final DeviceInfo deviceInfo) {
+        return contextChainMap.containsKey(deviceInfo);
     }
 
 }
index f9cab12faccdeb81facd2ea77e46a2995a47d7a6..dfc6d67c0558418a1c9907424a6049f44ed4e225 100644 (file)
@@ -11,6 +11,7 @@ import java.util.HashSet;
 import java.util.Set;
 import java.util.concurrent.Future;
 import org.opendaylight.openflowplugin.api.openflow.OFPContext;
+import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChain;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.ContextChainState;
 
@@ -18,6 +19,7 @@ public class ContextChainImpl implements ContextChain {
 
     private Set<OFPContext> contexts = new HashSet<>();
     private final ContextChainState contextChainState;
+    private ConnectionContext primaryConnectionContext;
 
     public ContextChainImpl(final ContextChainState contextChainState) {
         this.contextChainState = contextChainState;
@@ -47,4 +49,9 @@ public class ContextChainImpl implements ContextChain {
     public void close() {
 
     }
+
+    @Override
+    public void changePrimaryConnection(final ConnectionContext connectionContext) {
+        this.primaryConnectionContext = connectionContext;
+    }
 }