additional fix fro BUG-782 unregistering switch providers 60/6660/3
authorMichal Rehak <mirehak@cisco.com>
Wed, 30 Apr 2014 07:26:29 +0000 (09:26 +0200)
committermichal rehak <mirehak@cisco.com>
Wed, 7 May 2014 17:48:32 +0000 (17:48 +0000)
- CompositeObjectRegistration is stored into sessionContext upon addSession
- upon removeSession the CompositeObjectRegistration is closed

Change-Id: Ieee90f50645db12c5df198fd4501daa804a135d3
Signed-off-by: Michal Rehak <mirehak@cisco.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/SalRegistrationManager.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionContext.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionContextOFImpl.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/session/MessageDispatchServiceImplTest.java

index 7ffa5591d1a0a1c80fd0460ad3bb066dc03ff63b..84079a8bf915db352bc9e2734006c2d61bcc31b2 100644 (file)
@@ -34,6 +34,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
+import org.opendaylight.yangtools.concepts.CompositeObjectRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
 import org.slf4j.Logger;
@@ -91,7 +92,8 @@ public class SalRegistrationManager implements SessionListener, AutoCloseable {
         NodeId nodeId = nodeIdFromDatapathId(datapathId);
         ModelDrivenSwitchImpl ofSwitch = new ModelDrivenSwitchImpl(nodeId, identifier, context);
         LLDPSpeaker.getInstance().addModelDrivenSwitch(identifier, ofSwitch);
-        ofSwitch.register(providerContext);
+        CompositeObjectRegistration<ModelDrivenSwitch> registration = ofSwitch.register(providerContext);
+        context.setProviderRegistration(registration);
 
         LOG.debug("ModelDrivenSwitch for {} registered to MD-SAL.", datapathId.toString());
 
@@ -106,7 +108,10 @@ public class SalRegistrationManager implements SessionListener, AutoCloseable {
         NodeRef nodeRef = new NodeRef(identifier);
         NodeRemoved nodeRemoved = nodeRemoved(nodeRef);
         LLDPSpeaker.getInstance().removeModelDrivenSwitch(identifier);
-        LOG.debug("ModelDrivenSwitch for {} unregistred from MD-SAL.", datapathId.toString());
+        CompositeObjectRegistration<ModelDrivenSwitch> registration = context.getProviderRegistration();
+        registration.close();
+        
+        LOG.debug("ModelDrivenSwitch for {} unregistered from MD-SAL.", datapathId.toString());
         publishService.publish(nodeRemoved);
     }
 
index 09c3d94e775f45cd4b349819947c599929d84237..67154f0a54eac2ab75b63ead5be05892d5786cfc 100644 (file)
@@ -14,10 +14,13 @@ import java.util.Map.Entry;
 import java.util.Set;
 
 import com.google.common.cache.Cache;
+
+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.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
@@ -27,25 +30,25 @@ public interface SessionContext {
     /**
      * @return primary connection wrapper
      */
-    public ConnectionConductor getPrimaryConductor();
+    ConnectionConductor getPrimaryConductor();
 
     /**
      * @return the features of corresponding switch
      */
-    public GetFeaturesOutput getFeatures();
+    GetFeaturesOutput getFeatures();
 
     /**
      * @param auxiliaryKey
      *            key under which the auxiliary conductor is stored
      * @return list of auxiliary connection wrappers
      */
-    public ConnectionConductor getAuxiliaryConductor(
+    ConnectionConductor getAuxiliaryConductor(
             SwitchConnectionDistinguisher auxiliaryKey);
 
     /**
      * @return entries of all auxiliary connections wrapped in conductors in this session
      */
-    public Set<Entry<SwitchConnectionDistinguisher, ConnectionConductor>> getAuxiliaryConductors();
+    Set<Entry<SwitchConnectionDistinguisher, ConnectionConductor>> getAuxiliaryConductors();
 
     /**
      * register new auxiliary connection wrapped in {@link ConnectionConductor}
@@ -53,87 +56,87 @@ public interface SessionContext {
      * @param auxiliaryKey
      * @param conductor
      */
-    public void addAuxiliaryConductor(SwitchConnectionDistinguisher auxiliaryKey,
+    void addAuxiliaryConductor(SwitchConnectionDistinguisher auxiliaryKey,
             ConnectionConductor conductor);
 
     /**
      * @param connectionCookie
      * @return removed connectionConductor
      */
-    public ConnectionConductor removeAuxiliaryConductor(
+    ConnectionConductor removeAuxiliaryConductor(
             SwitchConnectionDistinguisher connectionCookie);
 
     /**
      * @return true if this session is valid
      */
-    public boolean isValid();
+    boolean isValid();
 
     /**
      * @param valid the valid to set
      */
-    public void setValid(boolean valid);
+    void setValid(boolean valid);
 
     /**
      * @return the sessionKey
      */
-    public SwitchConnectionDistinguisher getSessionKey();
+    SwitchConnectionDistinguisher getSessionKey();
 
     /**
      * Returns a map containing all OFPhysicalPorts of this switch.
      * @return The Map of OFPhysicalPort
      */
-    public Map<Long, PortGrouping> getPhysicalPorts();
+    Map<Long, PortGrouping> getPhysicalPorts();
     
     /**
      * Returns a map containing all bandwidths for all OFPorts of this switch.
      * @return The Map of bandwidths for all OFPorts
      */
-    public Map<Long, Boolean> getPortsBandwidth();
+    Map<Long, Boolean> getPortsBandwidth();
 
     /**
      * Returns a Set containing all port IDs of this switch.
      * @return The Set of port ID
      */
-    public Set<Long> getPorts();
+    Set<Long> getPorts();
     
     /**
      * @return the Object for this session xId
      */
-    public Cache<TransactionKey, Object> getbulkTransactionCache();
+    Cache<TransactionKey, Object> getbulkTransactionCache();
 
     /**
      * Returns OFPhysicalPort of the specified portNumber of this switch.
      * @param portNumber The port ID
      * @return OFPhysicalPort for the specified PortNumber
      */
-    public PortGrouping getPhysicalPort(Long portNumber);
+    PortGrouping getPhysicalPort(Long portNumber);
 
     /**
      * Returns the bandwidth of the specified portNumber of this switch.
      * @param portNumber the port ID
      * @return bandwidth
      */
-    public Boolean getPortBandwidth(Long portNumber);
+    Boolean getPortBandwidth(Long portNumber);
 
     /**
      * Returns True if the port is enabled,
      * @param portNumber
      * @return True if the port is enabled
      */
-    public boolean isPortEnabled(long portNumber);
+    boolean isPortEnabled(long portNumber);
 
     /**
      * Returns True if the port is enabled.
      * @param port
      * @return True if the port is enabled
      */
-    public boolean isPortEnabled(PortGrouping port);
+    boolean isPortEnabled(PortGrouping port);
 
     /**
      * Returns a list containing all enabled ports of this switch.
      * @return List containing all enabled ports of this switch
      */
-    public List<PortGrouping> getEnabledPorts();
+    List<PortGrouping> getEnabledPorts();
 
     // TODO:: add listeners here, manager will set them and conductor use them
 
@@ -142,13 +145,20 @@ public interface SessionContext {
      *
      * @return the message service
      */
-    public IMessageDispatchService getMessageDispatchService();
+    IMessageDispatchService getMessageDispatchService();
 
    /**
     * @return the unique xid for this session
     */
-    public Long getNextXid();
-
+    Long getNextXid();
 
+    /**
+     * @param registration provider composite registration
+     */
+    void setProviderRegistration(CompositeObjectRegistration<ModelDrivenSwitch> registration);
 
+    /**
+     * @return provider composite registration
+     */
+    CompositeObjectRegistration<ModelDrivenSwitch> getProviderRegistration();
 }
index 4c42c7f09ac005d55f3dc4083e1db7941248d5af..06f7b4a12263712af86e64f2f643c0110ca4e2e8 100644 (file)
@@ -20,11 +20,15 @@ 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.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
@@ -41,6 +45,7 @@ public class SessionContextOFImpl implements SessionContext {
     private final Map<Long, PortGrouping> physicalPorts;
     private final Map<Long, Boolean> portBandwidth;
     public static Cache<TransactionKey, Object> bulkTransactionCache = CacheBuilder.newBuilder().expireAfterWrite(10000, TimeUnit.MILLISECONDS).concurrencyLevel(1).build();
+    private CompositeObjectRegistration<ModelDrivenSwitch> providerRegistration;
 
 
     /**
@@ -200,4 +205,15 @@ public class SessionContextOFImpl implements SessionContext {
         }
         return result;
     }
+    
+    @Override
+    public void setProviderRegistration(
+            CompositeObjectRegistration<ModelDrivenSwitch> providerRegistration) {
+                this.providerRegistration = providerRegistration;
+    }
+    
+    @Override
+    public CompositeObjectRegistration<ModelDrivenSwitch> getProviderRegistration() {
+        return providerRegistration;
+    }
 }
index 7b7179a398afafef5266a704b3992cd0b99ebe65..6edf1be74ff0c69f0a532b4628a5c3e80351dfbd 100644 (file)
@@ -17,12 +17,12 @@ import java.util.concurrent.Future;
 
 import junit.framework.Assert;
 
-import com.google.common.cache.Cache;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
+import org.opendaylight.openflowplugin.openflow.md.ModelDrivenSwitch;
 import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
 import org.opendaylight.openflowplugin.openflow.md.core.ErrorHandler;
 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
@@ -59,9 +59,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SystemNotificationsListener;
+import org.opendaylight.yangtools.concepts.CompositeObjectRegistration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
+import com.google.common.cache.Cache;
+
 public class MessageDispatchServiceImplTest {
 
     MockSessionContext session;
@@ -180,6 +183,7 @@ class MockSessionContext implements SessionContext {
     private Map<SwitchConnectionDistinguisher, ConnectionConductor> map;
     private IMessageDispatchService messageService;
     private boolean isValid = true;
+    private CompositeObjectRegistration<ModelDrivenSwitch> registration;
 
     MockSessionContext(int conductorNum) {
         conductor = new MockConnectionConductor(conductorNum);
@@ -303,6 +307,16 @@ class MockSessionContext implements SessionContext {
         return null;
     }
 
+    @Override
+    public CompositeObjectRegistration<ModelDrivenSwitch> getProviderRegistration() {
+        return registration;
+    }
+
+    @Override
+    public void setProviderRegistration(
+            CompositeObjectRegistration<ModelDrivenSwitch> registration) {
+        this.registration = registration;
+    }
 }
 
 class MockConnectionConductor implements ConnectionConductor {