Bug-2827: role switch proposal
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / session / SessionContextOFImpl.java
index 4d743f3a8c10759c1f8b0e2f62333e16c374db00..899e1f66c5874d5fb61ff94b7d15fc758a7da6d9 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.openflowplugin.openflow.md.core.session;
 
+import com.google.common.base.Preconditions;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -18,14 +19,14 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicLong;
 
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-
-import java.util.concurrent.TimeUnit;
-
-import org.opendaylight.openflowplugin.openflow.md.ModelDrivenSwitch;
-import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
-import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
+import org.opendaylight.openflowplugin.api.openflow.md.ModelDrivenSwitch;
+import org.opendaylight.openflowplugin.api.openflow.md.core.ConnectionConductor;
+import org.opendaylight.openflowplugin.api.openflow.md.core.NotificationEnqueuer;
+import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
+import org.opendaylight.openflowplugin.api.openflow.md.core.session.IMessageDispatchService;
+import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
+import org.opendaylight.openflowplugin.api.openflow.md.core.session.SwitchSessionKeyOF;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ControllerRole;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping;
 import org.opendaylight.yangtools.concepts.CompositeObjectRegistration;
@@ -37,6 +38,7 @@ public class SessionContextOFImpl implements SessionContext {
 
     private GetFeaturesOutput features;
     private ConnectionConductor primaryConductor;
+    private NotificationEnqueuer notificationEnqueuer;
     private ConcurrentHashMap<SwitchConnectionDistinguisher, ConnectionConductor> auxiliaryConductors;
     private boolean valid;
     private SwitchSessionKeyOF sessionKey;
@@ -44,11 +46,10 @@ public class SessionContextOFImpl implements SessionContext {
     private final AtomicLong xid;
     private final Map<Long, PortGrouping> physicalPorts;
     private final Map<Long, Boolean> portBandwidth;
-    private Cache<TransactionKey, Object> bulkTransactionCache = CacheBuilder.newBuilder()
-            .softValues().maximumSize(1000).expireAfterWrite(2000, TimeUnit.MILLISECONDS).concurrencyLevel(1).build();
     private CompositeObjectRegistration<ModelDrivenSwitch> providerRegistration;
     private int seed;
-    
+    private ControllerRole roleOnDevice = ControllerRole.OFPCRROLEEQUAL;
+
 
     /**
      * default ctor
@@ -83,11 +84,6 @@ public class SessionContextOFImpl implements SessionContext {
     public Set<Entry<SwitchConnectionDistinguisher, ConnectionConductor>> getAuxiliaryConductors() {
         return Collections.unmodifiableSet(auxiliaryConductors.entrySet());
     }
-    
-    @Override
-    public Cache<TransactionKey, Object> getbulkTransactionCache() {
-        return bulkTransactionCache;
-    }
 
     @Override
     public GetFeaturesOutput getFeatures() {
@@ -132,7 +128,7 @@ public class SessionContextOFImpl implements SessionContext {
     public void setSessionKey(SwitchSessionKeyOF sessionKey) {
         this.sessionKey = sessionKey;
     }
-    
+
     /**
      * @param seed the seed to set
      */
@@ -159,7 +155,7 @@ public class SessionContextOFImpl implements SessionContext {
     public Map<Long, PortGrouping> getPhysicalPorts() {
         return this.physicalPorts;
     }
-    
+
     @Override
     public Map<Long, Boolean> getPortsBandwidth() {
         return this.portBandwidth;
@@ -214,20 +210,50 @@ public class SessionContextOFImpl implements SessionContext {
         }
         return result;
     }
-    
+
     @Override
     public void setProviderRegistration(
             CompositeObjectRegistration<ModelDrivenSwitch> providerRegistration) {
                 this.providerRegistration = providerRegistration;
     }
-    
+
     @Override
     public CompositeObjectRegistration<ModelDrivenSwitch> getProviderRegistration() {
         return providerRegistration;
     }
-    
+
     @Override
     public int getSeed() {
         return seed;
     }
+
+    /**
+     * @param notificationEnqueuer the notificationEnqueuer to set
+     */
+    public void setNotificationEnqueuer(
+            NotificationEnqueuer notificationEnqueuer) {
+        this.notificationEnqueuer = notificationEnqueuer;
+    }
+
+    @Override
+    public NotificationEnqueuer getNotificationEnqueuer() {
+        return notificationEnqueuer;
+    }
+
+    /**
+     * @return the roleOnDevice
+     */
+    @Override
+    public ControllerRole getRoleOnDevice() {
+        return roleOnDevice;
+    }
+
+    /**
+     * @param roleOnDevice the roleOnDevice to set
+     */
+    @Override
+    public void setRoleOnDevice(ControllerRole roleOnDevice) {
+        Preconditions.checkNotNull("Proposed controller role can not be empty.", roleOnDevice);
+        this.roleOnDevice = roleOnDevice;
+    }
 }