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 a4df782793add16a68126571f016431273b7d113..3749756ff04ff7d4b5ce5720a427f2a53f22d960 100644 (file)
@@ -8,12 +8,26 @@
 
 package org.opendaylight.openflowplugin.openflow.md.core.session;
 
-import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+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.SwitchConnectionDestinguisher;
+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.PortGrouping;
+import org.opendaylight.yangtools.concepts.CompositeObjectRegistration;
 
 /**
  * @author mirehak
@@ -22,13 +36,27 @@ public class SessionContextOFImpl implements SessionContext {
 
     private GetFeaturesOutput features;
     private ConnectionConductor primaryConductor;
-    private ConcurrentHashMap<Object, ConnectionConductor> auxiliaryConductors;
+    private NotificationEnqueuer notificationEnqueuer;
+    private ConcurrentHashMap<SwitchConnectionDistinguisher, ConnectionConductor> auxiliaryConductors;
+    private boolean valid;
+    private SwitchSessionKeyOF sessionKey;
+    private IMessageDispatchService mdService;
+    private final AtomicLong xid;
+    private final Map<Long, PortGrouping> physicalPorts;
+    private final Map<Long, Boolean> portBandwidth;
+    private CompositeObjectRegistration<ModelDrivenSwitch> providerRegistration;
+    private int seed;
+    
 
     /**
      * default ctor
      */
     public SessionContextOFImpl() {
         auxiliaryConductors = new ConcurrentHashMap<>();
+        mdService = new MessageDispatchServiceImpl(this);
+        xid = new AtomicLong();
+        this.physicalPorts = new HashMap<Long, PortGrouping>();
+        this.portBandwidth = new HashMap<Long, Boolean>();
     }
 
     @Override
@@ -38,22 +66,22 @@ 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
     public GetFeaturesOutput getFeatures() {
         return features;
@@ -77,7 +105,135 @@ 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(SwitchSessionKeyOF sessionKey) {
+        this.sessionKey = sessionKey;
+    }
+    
+    /**
+     * @param seed the seed to set
+     */
+    public void setSeed(int seed) {
+        this.seed = seed;
+    }
+
+    @Override
+    public SwitchSessionKeyOF getSessionKey() {
+        return sessionKey;
+    }
+
+    @Override
+    public IMessageDispatchService getMessageDispatchService() {
+        return mdService;
+    }
+
+    @Override
+    public Long getNextXid() {
+        return xid.incrementAndGet();
+    }
+
+    @Override
+    public Map<Long, PortGrouping> getPhysicalPorts() {
+        return this.physicalPorts;
+    }
+    
+    @Override
+    public Map<Long, Boolean> getPortsBandwidth() {
+        return this.portBandwidth;
+    }
+
+    @Override
+    public Set<Long> getPorts() {
+        return this.physicalPorts.keySet();
+    }
+
+    @Override
+    public PortGrouping getPhysicalPort(Long portNumber) {
+        return this.physicalPorts.get(portNumber);
+    }
+
+    @Override
+    public Boolean getPortBandwidth(Long portNumber) {
+        return this.portBandwidth.get(portNumber);
+    }
+
+    @Override
+    public boolean isPortEnabled(long portNumber) {
+        return isPortEnabled(physicalPorts.get(portNumber));
+    }
+
+    @Override
+    public boolean isPortEnabled(PortGrouping port) {
+        if (port == null) {
+            return false;
+        }
+        if (port.getConfig().isPortDown()) {
+            return false;
+        }
+        if (port.getState().isLinkDown()) {
+            return false;
+        }
+        if (port.getState().isBlocked()) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public List<PortGrouping> getEnabledPorts() {
+        List<PortGrouping> result = new ArrayList<PortGrouping>();
+        synchronized (this.physicalPorts) {
+            for (PortGrouping port : physicalPorts.values()) {
+                if (isPortEnabled(port)) {
+                    result.add(port);
+                }
+            }
+        }
+        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;
+    }
 }