BUG-6458: 44/44244/8
authorShuva Kar <shuva.jyoti.kar@ericsson.com>
Thu, 18 Aug 2016 11:00:27 +0000 (16:30 +0530)
committerShuva Jyoti Kar <shuva.jyoti.kar@ericsson.com>
Thu, 18 Aug 2016 16:42:10 +0000 (16:42 +0000)
The issue occurred since during update the older
flowregistry key wasnot getting removed when the
newer one was getting stored. This was because the
match/priority/cookie all forms part of the flow-registry
key.

Change-Id: Ibed34e79b6310723f7c8078bf54b8a2b4f9ab2b2
Signed-off-by: Shuva Kar <shuva.jyoti.kar@ericsson.com>
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/registry/flow/DeviceFlowRegistry.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/registry/flow/DeviceFlowRegistryImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImpl.java

index 9506c96d512bd35d0b52a9221a2a817dbe26b427..8823319f10ceeff12f235cc6caccc0119efd796b 100644 (file)
@@ -34,6 +34,8 @@ public interface DeviceFlowRegistry extends AutoCloseable {
 
     void markToBeremoved(FlowRegistryKey flowRegistryKey);
 
+    void update(FlowRegistryKey newFlowRegistryKey,FlowDescriptor flowDescriptor);
+
     void removeMarked();
 
     Map<FlowRegistryKey, FlowDescriptor> getAllFlowDescriptors();
index 3ac3173dc9c867e0252d962384869f6c49ff47d5..c44f1e3e9c0cb6cb7c08f25adb58fd843414f54d 100644 (file)
@@ -178,15 +178,25 @@ public class DeviceFlowRegistryImpl implements DeviceFlowRegistry {
     public void store(final FlowRegistryKey flowRegistryKey, final FlowDescriptor flowDescriptor) {
         LOG.trace("Storing flowDescriptor with table ID : {} and flow ID : {} for flow hash : {}",
                 flowDescriptor.getTableKey().getId(), flowDescriptor.getFlowId().getValue(), flowRegistryKey.hashCode());
-        try {
-            flowRegistry.put(flowRegistryKey, flowDescriptor);
-        } catch (IllegalArgumentException ex) {
-            LOG.error("Flow with flowId {} already exists in table {}", flowDescriptor.getFlowId().getValue(),
-                    flowDescriptor.getTableKey().getId());
-            final FlowId newFlowId = createAlienFlowId(flowDescriptor.getTableKey().getId());
-            final FlowDescriptor newFlowDescriptor = FlowDescriptorFactory.
-                    create(flowDescriptor.getTableKey().getId(), newFlowId);
-            flowRegistry.put(flowRegistryKey, newFlowDescriptor);
+        synchronized (flowRegistryKey) {
+            try {
+                flowRegistry.put(flowRegistryKey, flowDescriptor);
+            } catch (IllegalArgumentException ex) {
+                LOG.error("Flow with flowId {} already exists in table {}", flowDescriptor.getFlowId().getValue(),
+                        flowDescriptor.getTableKey().getId());
+                final FlowId newFlowId = createAlienFlowId(flowDescriptor.getTableKey().getId());
+                final FlowDescriptor newFlowDescriptor = FlowDescriptorFactory.
+                        create(flowDescriptor.getTableKey().getId(), newFlowId);
+                flowRegistry.put(flowRegistryKey, newFlowDescriptor);
+            }
+        }
+    }
+
+    @Override
+    public void update(FlowRegistryKey newFlowRegistryKey,FlowDescriptor flowDescriptor){
+        LOG.trace("Updating the entry with hash: {}", newFlowRegistryKey.hashCode());
+        synchronized (newFlowRegistryKey) {
+            flowRegistry.forcePut(newFlowRegistryKey, flowDescriptor);
         }
     }
 
index db4fb135fdf9d95467c0b7eeee9334b323b63284..b9fa55bb3cafa8c379c412765ca654b29d4c89e1 100644 (file)
@@ -252,7 +252,8 @@ public class SalFlowServiceImpl implements SalFlowService, ItemLifeCycleSource {
                 // this is either an add or an update
                 final FlowId flowId = flowRef.getValue().firstKeyOf(Flow.class, FlowKey.class).getId();
                 final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(updated.getTableId(), flowId);
-                deviceFlowRegistry.store(updatedflowRegistryKey, flowDescriptor);
+
+                deviceFlowRegistry.update(updatedflowRegistryKey, flowDescriptor);
 
                 if (itemLifecycleListener != null) {
                     KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,