FlowHash renamed to FlowRegistryKey 81/20981/1
authorMartin Bobak <mbobak@cisco.com>
Fri, 22 May 2015 11:46:20 +0000 (13:46 +0200)
committerMartin Bobak <mbobak@cisco.com>
Fri, 22 May 2015 12:35:51 +0000 (14:35 +0200)
This object serves as key to local flow registry and is not a hash in
the strict sense. Therefore it is renamed and will be changed in next
commits to avoid flow hash computation using HashUtils.

Change-Id: Ife23394cfe2c28149932ccdfe7c7e441466d5d59
Signed-off-by: Martin Bobak <mbobak@cisco.com>
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/registry/flow/DeviceFlowRegistry.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/registry/flow/FlowRegistryKey.java [moved from openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/registry/flow/FlowHash.java with 94% similarity]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/registry/flow/DeviceFlowRegistryImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/registry/flow/FlowHashFactory.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/registry/flow/FlowRegistryKeyFactoryTest.java [moved from openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/registry/flow/FlowHashFactoryTest.java with 87% similarity]

index 19d0475d44c5a4b8889c649b2f025e7deed82286..ab4da891c03710cddda8f6cdcbde7b1d8e89cf84 100644 (file)
@@ -17,17 +17,17 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.Fl
  */
 public interface DeviceFlowRegistry extends AutoCloseable {
 
-    FlowDescriptor retrieveIdForFlow(FlowHash flowHash);
+    FlowDescriptor retrieveIdForFlow(FlowRegistryKey flowRegistryKey);
 
-    void store(FlowHash flowHash, FlowDescriptor flowDescriptor);
+    void store(FlowRegistryKey flowRegistryKey, FlowDescriptor flowDescriptor);
 
-    FlowId storeIfNecessary(FlowHash flowHash, short tableId);
+    FlowId storeIfNecessary(FlowRegistryKey flowRegistryKey, short tableId);
 
-    void markToBeremoved(FlowHash flowHash);
+    void markToBeremoved(FlowRegistryKey flowRegistryKey);
 
     void removeMarked();
 
-    Map<FlowHash, FlowDescriptor> getAllFlowDescriptors();
+    Map<FlowRegistryKey, FlowDescriptor> getAllFlowDescriptors();
 
     @Override
     void close();
similarity index 94%
rename from openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/registry/flow/FlowHash.java
rename to openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/registry/flow/FlowRegistryKey.java
index 8d24e8d89c04918cc021bcfadadd2a16202e5f34..437faede7fa5755974e75722c8b0b079e53bd9c7 100644 (file)
@@ -14,7 +14,7 @@ import java.math.BigInteger;
  * Marker interface identifying flow stored in OFP local flow registry.
  * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 8.4.2015.
  */
-public interface FlowHash {
+public interface FlowRegistryKey {
 
     long getFlowHash();
 
index 02dceac8b5f971370f6ebac44f3af847d0eccd42..4c57c5539f5cbbfdad49a8a559dce570e131db99 100644 (file)
@@ -14,7 +14,7 @@ import java.util.HashSet;
 import java.util.Map;
 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
-import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowHash;
+import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
 import org.opendaylight.openflowplugin.impl.util.FlowUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
 import org.slf4j.Logger;
@@ -26,56 +26,56 @@ import org.slf4j.LoggerFactory;
  */
 public class DeviceFlowRegistryImpl implements DeviceFlowRegistry {
 
-    private final Map<FlowHash, FlowDescriptor> flowRegistry = new HashMap<>();
-    private final Collection<FlowHash> marks = new HashSet<>();
+    private final Map<FlowRegistryKey, FlowDescriptor> flowRegistry = new HashMap<>();
+    private final Collection<FlowRegistryKey> marks = new HashSet<>();
     private static final Logger LOG = LoggerFactory.getLogger(DeviceFlowRegistryImpl.class);
 
     @Override
-    public FlowDescriptor retrieveIdForFlow(final FlowHash flowHash) {
-        FlowDescriptor flowDescriptor = flowRegistry.get(flowHash);
+    public FlowDescriptor retrieveIdForFlow(final FlowRegistryKey flowRegistryKey) {
+        FlowDescriptor flowDescriptor = flowRegistry.get(flowRegistryKey);
         return flowDescriptor;
     }
 
 
     @Override
-    public void store(final FlowHash flowHash, final FlowDescriptor flowDescriptor) {
-        LOG.trace("Storing flowDescriptor with table ID : {} and flow ID : {} for flow hash : {}", flowDescriptor.getTableKey().getId(), flowDescriptor.getFlowId().getValue(), flowHash.hashCode());
+    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());
         synchronized (flowRegistry) {
-            flowRegistry.put(flowHash, flowDescriptor);
+            flowRegistry.put(flowRegistryKey, flowDescriptor);
         }
     }
 
     @Override
-    public FlowId storeIfNecessary(final FlowHash flowHash, final short tableId) {
+    public FlowId storeIfNecessary(final FlowRegistryKey flowRegistryKey, final short tableId) {
         FlowId alienFlowId = FlowUtil.createAlienFlowId(tableId);
         FlowDescriptor alienFlowDescriptor = FlowDescriptorFactory.create(tableId, alienFlowId);
         synchronized (flowRegistry) {
-            FlowDescriptor flowDescriptorFromRegistry = flowRegistry.get(flowHash);
+            FlowDescriptor flowDescriptorFromRegistry = flowRegistry.get(flowRegistryKey);
             if (flowDescriptorFromRegistry != null) {
                 return flowDescriptorFromRegistry.getFlowId();
             } else {
-                LOG.trace("Flow descriptor for flow hash {} wasn't found.", flowHash.hashCode());
-                flowRegistry.put(flowHash, alienFlowDescriptor);
+                LOG.trace("Flow descriptor for flow hash {} wasn't found.", flowRegistryKey.hashCode());
+                flowRegistry.put(flowRegistryKey, alienFlowDescriptor);
                 return alienFlowId;
             }
         }
     }
 
     @Override
-    public void markToBeremoved(final FlowHash flowHash) {
+    public void markToBeremoved(final FlowRegistryKey flowRegistryKey) {
         synchronized (marks) {
-            marks.add(flowHash);
+            marks.add(flowRegistryKey);
         }
-        LOG.trace("Flow hash {} was marked for removal.", flowHash.hashCode());
+        LOG.trace("Flow hash {} was marked for removal.", flowRegistryKey.hashCode());
 
     }
 
     @Override
     public void removeMarked() {
         synchronized (flowRegistry) {
-            for (FlowHash flowHash : marks) {
-                LOG.trace("Removing flowDescriptor for flow hash : {}", flowHash.hashCode());
-                flowRegistry.remove(flowHash);
+            for (FlowRegistryKey flowRegistryKey : marks) {
+                LOG.trace("Removing flowDescriptor for flow hash : {}", flowRegistryKey.hashCode());
+                flowRegistry.remove(flowRegistryKey);
             }
         }
         synchronized (marks) {
@@ -85,7 +85,7 @@ public class DeviceFlowRegistryImpl implements DeviceFlowRegistry {
 
 
     @Override
-    public Map<FlowHash, FlowDescriptor> getAllFlowDescriptors() {
+    public Map<FlowRegistryKey, FlowDescriptor> getAllFlowDescriptors() {
         return flowRegistry;
     }
 
index 9124a90cb2e430bc76081e4562422243700507f8..4e1601a00b8ba384941e8a6553561b3503106eca 100644 (file)
@@ -14,7 +14,7 @@ import com.google.common.primitives.Longs;
 import java.math.BigInteger;
 import java.util.Objects;
 import org.opendaylight.openflowplugin.api.OFConstants;
-import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowHash;
+import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
 import org.opendaylight.openflowplugin.impl.util.HashUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
 
@@ -27,9 +27,9 @@ public class FlowHashFactory {
     public FlowHashFactory() {
     }
 
-    public static FlowHash create(Flow flow, short version) {
+    public static FlowRegistryKey create(Flow flow, short version) {
         long hash = calculateHash(flow, version);
-        return new FlowHashDto(hash, flow);
+        return new FlowRegistryKeyDto(hash, flow);
     }
 
     private static long calculateHash(Flow flow, short version) {
@@ -37,7 +37,7 @@ public class FlowHashFactory {
     }
 
 
-    private static final class FlowHashDto implements FlowHash {
+    private static final class FlowRegistryKeyDto implements FlowRegistryKey {
 
         private final long flowHash;
         private final int intHashCode;
@@ -46,7 +46,7 @@ public class FlowHashFactory {
         private final int priority;
         private final BigInteger cookie;
 
-        public FlowHashDto(final long flowHash, final Flow flow) {
+        public FlowRegistryKeyDto(final long flowHash, final Flow flow) {
             this.flowHash = flowHash;
             this.intHashCode = Longs.hashCode(flowHash);
             tableId = Preconditions.checkNotNull(flow.getTableId(), "flow tableId must not be null");
@@ -65,10 +65,10 @@ public class FlowHashFactory {
             if (null == obj) {
                 return false;
             }
-            if (!(obj instanceof FlowHash)) {
+            if (!(obj instanceof FlowRegistryKey)) {
                 return false;
             }
-            FlowHash that = (FlowHash) obj;
+            FlowRegistryKey that = (FlowRegistryKey) obj;
             if (this.flowHash == that.getFlowHash()
                     && this.tableId == that.getTableId()
                     && this.priority == that.getPriority()
index 8342730fad7fe764fd6c6534974ab39f0cfae19c..aa6b59e884070b9c574a7a257113122cf4e79fc5 100644 (file)
@@ -23,7 +23,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
-import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowHash;
+import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
 import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory;
 import org.opendaylight.openflowplugin.impl.registry.flow.FlowHashFactory;
@@ -75,9 +75,9 @@ public class SalFlowServiceImpl extends CommonService implements SalFlowService
         }
 
         final DeviceContext deviceContext = getDeviceContext();
-        final FlowHash flowHash = FlowHashFactory.create(input, deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
+        final FlowRegistryKey flowRegistryKey = FlowHashFactory.create(input, deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
         final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(input.getTableId(), flowId);
-        deviceContext.getDeviceFlowRegistry().store(flowHash, flowDescriptor);
+        deviceContext.getDeviceFlowRegistry().store(flowRegistryKey, flowDescriptor);
         Futures.addCallback(future, new FutureCallback<RpcResult<AddFlowOutput>>() {
 
 
@@ -92,7 +92,7 @@ public class SalFlowServiceImpl extends CommonService implements SalFlowService
 
             @Override
             public void onFailure(final Throwable throwable) {
-                deviceContext.getDeviceFlowRegistry().markToBeremoved(flowHash);
+                deviceContext.getDeviceFlowRegistry().markToBeremoved(flowRegistryKey);
                 LOG.trace("Service call for adding flows failed, id={}.", flowId.getValue(), throwable);
             }
         });
@@ -114,8 +114,8 @@ public class SalFlowServiceImpl extends CommonService implements SalFlowService
                     public void onSuccess(final RpcResult<RemoveFlowOutput> o) {
                         final DeviceContext deviceContext = getDeviceContext();
                         getMessageSpy().spyMessage(input.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
-                        FlowHash flowHash = FlowHashFactory.create(input, deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
-                        deviceContext.getDeviceFlowRegistry().markToBeremoved(flowHash);
+                        FlowRegistryKey flowRegistryKey = FlowHashFactory.create(input, deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
+                        deviceContext.getDeviceFlowRegistry().markToBeremoved(flowRegistryKey);
                     }
 
                     @Override
@@ -175,14 +175,14 @@ public class SalFlowServiceImpl extends CommonService implements SalFlowService
                 final DeviceContext deviceContext = getDeviceContext();
                 getMessageSpy().spyMessage(input.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
                 final short version = deviceContext.getPrimaryConnectionContext().getFeatures().getVersion();
-                FlowHash flowHash = FlowHashFactory.create(original, version);
+                FlowRegistryKey flowRegistryKey = FlowHashFactory.create(original, version);
 
-                FlowHash updatedflowHash = FlowHashFactory.create(updated, version);
+                FlowRegistryKey updatedflowRegistryKey = FlowHashFactory.create(updated, version);
                 FlowId flowId = input.getFlowRef().getValue().firstKeyOf(Flow.class, FlowKey.class).getId();
                 FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(updated.getTableId(), flowId);
                 final DeviceFlowRegistry deviceFlowRegistry = deviceContext.getDeviceFlowRegistry();
-                deviceFlowRegistry.markToBeremoved(flowHash);
-                deviceFlowRegistry.store(updatedflowHash, flowDescriptor);
+                deviceFlowRegistry.markToBeremoved(flowRegistryKey);
+                deviceFlowRegistry.store(updatedflowRegistryKey, flowDescriptor);
             }
 
             @Override
index db67901af30e446dd17d7c29f367ea49a216fbd6..4727cb73fcf58b137e9e331fca506e1485f70f68 100644 (file)
@@ -23,7 +23,7 @@ import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowHash;
+import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
 import org.opendaylight.openflowplugin.impl.registry.flow.FlowHashFactory;
 import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
@@ -198,8 +198,8 @@ public final class StatisticsGatheringUtils {
                 short tableId = flowStat.getTableId();
                 final Short version = deviceContext.getPrimaryConnectionContext().getFeatures().getVersion();
 
-                final FlowHash flowHash = FlowHashFactory.create(flowBuilder.build(), version);
-                final FlowId flowId = deviceContext.getDeviceFlowRegistry().storeIfNecessary(flowHash, tableId);
+                final FlowRegistryKey flowRegistryKey = FlowHashFactory.create(flowBuilder.build(), version);
+                final FlowId flowId = deviceContext.getDeviceFlowRegistry().storeIfNecessary(flowRegistryKey, tableId);
 
                 final FlowKey flowKey = new FlowKey(flowId);
                 flowBuilder.setKey(flowKey);
@@ -24,7 +24,7 @@ import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
-import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowHash;
+import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
@@ -41,9 +41,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 @RunWith(MockitoJUnitRunner.class)
-public class FlowHashFactoryTest {
+public class FlowRegistryKeyFactoryTest {
 
-    private static final Logger LOG = LoggerFactory.getLogger(FlowHashFactoryTest.class);
+    private static final Logger LOG = LoggerFactory.getLogger(FlowRegistryKeyFactoryTest.class);
 
 
     private static final FlowsStatisticsUpdateBuilder FLOWS_STATISTICS_UPDATE_BUILDER = new FlowsStatisticsUpdateBuilder();
@@ -89,12 +89,12 @@ public class FlowHashFactoryTest {
     public void testEquals() throws Exception {
         FlowsStatisticsUpdate flowStats = FLOWS_STATISTICS_UPDATE_BUILDER.build();
 
-        HashSet<FlowHash> flowHashs = new HashSet<>();
+        HashSet<FlowRegistryKey> flowRegistryKeys = new HashSet<>();
         for (FlowAndStatisticsMapList item : flowStats.getFlowAndStatisticsMapList()) {
-            flowHashs.add(FlowHashFactory.create(item, OFConstants.OFP_VERSION_1_3));
-            flowHashs.add(FlowHashFactory.create(item, OFConstants.OFP_VERSION_1_3));
+            flowRegistryKeys.add(FlowHashFactory.create(item, OFConstants.OFP_VERSION_1_3));
+            flowRegistryKeys.add(FlowHashFactory.create(item, OFConstants.OFP_VERSION_1_3));
         }
-        assertEquals(3, flowHashs.size());
+        assertEquals(3, flowRegistryKeys.size());
     }
 
     @Test
@@ -107,7 +107,7 @@ public class FlowHashFactoryTest {
                 .setPriority(2)
                 .setTableId((short) 0);
 
-        FlowHash flow1Hash = FlowHashFactory.create(flow1Builder.build(), OFConstants.OFP_VERSION_1_3);
+        FlowRegistryKey flow1Hash = FlowHashFactory.create(flow1Builder.build(), OFConstants.OFP_VERSION_1_3);
         LOG.info("flowHash1: {}", flow1Hash.hashCode());
 
 
@@ -117,7 +117,7 @@ public class FlowHashFactoryTest {
                 .setCookie(new FlowCookie(BigInteger.valueOf(148)))
                 .setMatch(match2Builder.build());
 
-        FlowHash flow2Hash = FlowHashFactory.create(flow2Builder.build(), OFConstants.OFP_VERSION_1_3);
+        FlowRegistryKey flow2Hash = FlowHashFactory.create(flow2Builder.build(), OFConstants.OFP_VERSION_1_3);
         LOG.info("flowHash2: {}", flow2Hash.hashCode());
 
         Assert.assertNotSame(flow1Hash, flow2Hash);
@@ -155,9 +155,9 @@ public class FlowHashFactoryTest {
 
         FlowBuilder fb3 = new FlowBuilder(flow1Builder.build());
         fb3.setCookie(null);
-        FlowHash flowHash = FlowHashFactory.create(fb3.build(), OFConstants.OFP_VERSION_1_3);
-        Assert.assertNotNull(flowHash.getCookie());
-        Assert.assertEquals(OFConstants.DEFAULT_COOKIE, flowHash.getCookie());
+        FlowRegistryKey flowRegistryKey = FlowHashFactory.create(fb3.build(), OFConstants.OFP_VERSION_1_3);
+        Assert.assertNotNull(flowRegistryKey.getCookie());
+        Assert.assertEquals(OFConstants.DEFAULT_COOKIE, flowRegistryKey.getCookie());
     }
 
     @Test
@@ -165,12 +165,12 @@ public class FlowHashFactoryTest {
         FlowsStatisticsUpdate flowStats = FLOWS_STATISTICS_UPDATE_BUILDER.build();
 
         for (FlowAndStatisticsMapList item : flowStats.getFlowAndStatisticsMapList()) {
-            FlowHash flowHash = FlowHashFactory.create(item, OFConstants.OFP_VERSION_1_3);
-            FlowHash lastHash = null;
+            FlowRegistryKey flowRegistryKey = FlowHashFactory.create(item, OFConstants.OFP_VERSION_1_3);
+            FlowRegistryKey lastHash = null;
             if (null != lastHash) {
-                assertNotEquals(lastHash, flowHash);
+                assertNotEquals(lastHash, flowRegistryKey);
             } else {
-                lastHash = flowHash;
+                lastHash = flowRegistryKey;
             }
         }
     }