Bug 1764 - moved Session related interfaces to openflowplugin-api
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / session / SessionContextOFImpl.java
index f53ca2676f0599fca4392812f267b2454945f8f2..3749756ff04ff7d4b5ce5720a427f2a53f22d960 100644 (file)
@@ -18,11 +18,16 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicLong;
 
-import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
-import org.opendaylight.openflowplugin.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.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.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Port;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping;
+import org.opendaylight.yangtools.concepts.CompositeObjectRegistration;
 
 /**
  * @author mirehak
@@ -31,13 +36,17 @@ public class SessionContextOFImpl implements SessionContext {
 
     private GetFeaturesOutput features;
     private ConnectionConductor primaryConductor;
+    private NotificationEnqueuer notificationEnqueuer;
     private ConcurrentHashMap<SwitchConnectionDistinguisher, ConnectionConductor> auxiliaryConductors;
     private boolean valid;
-    private SwitchConnectionDistinguisher sessionKey;
+    private SwitchSessionKeyOF sessionKey;
     private IMessageDispatchService mdService;
     private final AtomicLong xid;
-    private final Map<Long, Port> physicalPorts;
+    private final Map<Long, PortGrouping> physicalPorts;
     private final Map<Long, Boolean> portBandwidth;
+    private CompositeObjectRegistration<ModelDrivenSwitch> providerRegistration;
+    private int seed;
+    
 
     /**
      * default ctor
@@ -46,7 +55,7 @@ public class SessionContextOFImpl implements SessionContext {
         auxiliaryConductors = new ConcurrentHashMap<>();
         mdService = new MessageDispatchServiceImpl(this);
         xid = new AtomicLong();
-        this.physicalPorts = new HashMap<Long, Port>();
+        this.physicalPorts = new HashMap<Long, PortGrouping>();
         this.portBandwidth = new HashMap<Long, Boolean>();
     }
 
@@ -72,7 +81,7 @@ public class SessionContextOFImpl implements SessionContext {
     public Set<Entry<SwitchConnectionDistinguisher, ConnectionConductor>> getAuxiliaryConductors() {
         return Collections.unmodifiableSet(auxiliaryConductors.entrySet());
     }
-
+    
     @Override
     public GetFeaturesOutput getFeatures() {
         return features;
@@ -113,12 +122,19 @@ public class SessionContextOFImpl implements SessionContext {
     /**
      * @param sessionKey the sessionKey to set
      */
-    public void setSessionKey(SwitchConnectionDistinguisher sessionKey) {
+    public void setSessionKey(SwitchSessionKeyOF sessionKey) {
         this.sessionKey = sessionKey;
     }
+    
+    /**
+     * @param seed the seed to set
+     */
+    public void setSeed(int seed) {
+        this.seed = seed;
+    }
 
     @Override
-    public SwitchConnectionDistinguisher getSessionKey() {
+    public SwitchSessionKeyOF getSessionKey() {
         return sessionKey;
     }
 
@@ -133,9 +149,14 @@ public class SessionContextOFImpl implements SessionContext {
     }
 
     @Override
-    public Map<Long, Port> getPhysicalPorts() {
+    public Map<Long, PortGrouping> getPhysicalPorts() {
         return this.physicalPorts;
     }
+    
+    @Override
+    public Map<Long, Boolean> getPortsBandwidth() {
+        return this.portBandwidth;
+    }
 
     @Override
     public Set<Long> getPorts() {
@@ -143,7 +164,7 @@ public class SessionContextOFImpl implements SessionContext {
     }
 
     @Override
-    public Port getPhysicalPort(Long portNumber) {
+    public PortGrouping getPhysicalPort(Long portNumber) {
         return this.physicalPorts.get(portNumber);
     }
 
@@ -158,7 +179,7 @@ public class SessionContextOFImpl implements SessionContext {
     }
 
     @Override
-    public boolean isPortEnabled(Port port) {
+    public boolean isPortEnabled(PortGrouping port) {
         if (port == null) {
             return false;
         }
@@ -175,10 +196,10 @@ public class SessionContextOFImpl implements SessionContext {
     }
 
     @Override
-    public List<Port> getEnabledPorts() {
-        List<Port> result = new ArrayList<Port>();
+    public List<PortGrouping> getEnabledPorts() {
+        List<PortGrouping> result = new ArrayList<PortGrouping>();
         synchronized (this.physicalPorts) {
-            for (Port port : physicalPorts.values()) {
+            for (PortGrouping port : physicalPorts.values()) {
                 if (isPortEnabled(port)) {
                     result.add(port);
                 }
@@ -186,39 +207,33 @@ public class SessionContextOFImpl implements SessionContext {
         }
         return result;
     }
-
+    
     @Override
-    public void processPortStatusMsg(PortStatus msg) {
-        Port port = msg;
-        if (msg.getReason().getIntValue() == 2) {
-            updatePhysicalPort(port);
-        } else if (msg.getReason().getIntValue() == 0) {
-            updatePhysicalPort(port);
-        } else if (msg.getReason().getIntValue() == 1) {
-            deletePhysicalPort(port);
-        }
-
+    public void setProviderRegistration(
+            CompositeObjectRegistration<ModelDrivenSwitch> providerRegistration) {
+                this.providerRegistration = providerRegistration;
     }
-
-    private void updatePhysicalPort(Port port) {
-        Long portNumber = port.getPortNo();
-        physicalPorts.put(portNumber, port);
-        portBandwidth
-                .put(portNumber,
-                        ( (port.getCurrentFeatures().is_100gbFd())
-                          |(port.getCurrentFeatures().is_100mbFd()) | (port.getCurrentFeatures().is_100mbHd())
-                          | (port.getCurrentFeatures().is_10gbFd()) | (port.getCurrentFeatures().is_10mbFd())
-                          | (port.getCurrentFeatures().is_10mbHd()) | (port.getCurrentFeatures().is_1gbFd())
-                          | (port.getCurrentFeatures().is_1gbHd()) | (port.getCurrentFeatures().is_1tbFd())
-                          | (port.getCurrentFeatures().is_40gbFd()) | (port.getCurrentFeatures().isAutoneg())
-                          | (port.getCurrentFeatures().isCopper()) | (port.getCurrentFeatures().isFiber())
-                          | (port.getCurrentFeatures().isOther()) | (port.getCurrentFeatures().isPause())
-                          | (port.getCurrentFeatures().isPauseAsym()) ) );
+    
+    @Override
+    public CompositeObjectRegistration<ModelDrivenSwitch> getProviderRegistration() {
+        return providerRegistration;
     }
-
-    private void deletePhysicalPort(Port port) {
-        Long portNumber = port.getPortNo();
-        physicalPorts.remove(portNumber);
-        portBandwidth.remove(portNumber);
+    
+    @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;
     }
 }