deviceCtx should not be used where is not needed 85/19885/1
authorMartin Bobak <mbobak@cisco.com>
Fri, 8 May 2015 08:34:23 +0000 (10:34 +0200)
committerMartin Bobak <mbobak@cisco.com>
Fri, 8 May 2015 08:34:23 +0000 (10:34 +0200)
Change-Id: Iec28b063342a13aafed81ee0cae49852561ab34c
Signed-off-by: Martin Bobak <mbobak@cisco.com>
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/main/java/org/opendaylight/openflowplugin/impl/util/HashUtil.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/registry/flow/FlowHashFactoryTest.java

index 9eec7ea72342e8cafbbd0a6a87c02f0614c60ce0..7d8d7987e32ce68ecdd07e0a98369b5c05ae2626 100644 (file)
@@ -28,13 +28,13 @@ public class FlowHashFactory {
     public FlowHashFactory() {
     }
 
-    public static FlowHash create(Flow flow, DeviceContext deviceContext) {
-        long hash = calculateHash(flow, deviceContext);
+    public static FlowHash create(Flow flow, short version) {
+        long hash = calculateHash(flow, version);
         return new FlowHashDto(hash, flow);
     }
 
-    private static long calculateHash(Flow flow, DeviceContext deviceContext) {
-        return HashUtil.calculateMatchHash(flow.getMatch(), deviceContext);
+    private static long calculateHash(Flow flow, short version) {
+        return HashUtil.calculateMatchHash(flow.getMatch(), version);
     }
 
 
index b0e45a0c112df3ab0960ee5825f7e0132edecbd2..54579cbb459a2a0e7a424c558af2732b00db286d 100644 (file)
@@ -71,7 +71,7 @@ public class SalFlowServiceImpl extends CommonService implements SalFlowService
         }
 
 
-        final FlowHash flowHash = FlowHashFactory.create(input, deviceContext);
+        final FlowHash flowHash = FlowHashFactory.create(input, deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
         final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(input.getTableId(), flowId);
 
         final List<FlowModInputBuilder> ofFlowModInputs = FlowConvertor.toFlowModInputs(input, version, datapathId);
@@ -114,7 +114,7 @@ public class SalFlowServiceImpl extends CommonService implements SalFlowService
                             @Override
                             public void onSuccess(final Object o) {
                                 messageSpy.spyMessage(input.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMITTED_SUCCESS);
-                                FlowHash flowHash = FlowHashFactory.create(input, deviceContext);
+                                FlowHash flowHash = FlowHashFactory.create(input, deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
                                 deviceContext.getDeviceFlowRegistry().markToBeremoved(flowHash);
                             }
 
@@ -171,10 +171,11 @@ public class SalFlowServiceImpl extends CommonService implements SalFlowService
             @Override
             public void onSuccess(final Object o) {
                 messageSpy.spyMessage(input.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMITTED_SUCCESS);
-                FlowHash flowHash = FlowHashFactory.create(original, deviceContext);
+                short version = deviceContext.getPrimaryConnectionContext().getFeatures().getVersion();
+                FlowHash flowHash = FlowHashFactory.create(original, version);
                 deviceContext.getDeviceFlowRegistry().markToBeremoved(flowHash);
 
-                flowHash = FlowHashFactory.create(updated, deviceContext);
+                flowHash = FlowHashFactory.create(updated, version);
                 FlowId flowId = input.getFlowRef().getValue().firstKeyOf(Flow.class, FlowKey.class).getId();
                 FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(updated.getTableId(), flowId);
                 deviceContext.getDeviceFlowRegistry().store(flowHash, flowDescriptor);
index 2e3812350485e37b90ab785a5c4ac0834e5983e3..0090da642521100ee1d4c7548e52d9108ee8b539 100644 (file)
@@ -195,7 +195,7 @@ public final class StatisticsGatheringUtils {
         for (final FlowAndStatisticsMapList flowStat : flowsStatistics.getFlowAndStatisticsMapList()) {
             final FlowBuilder flowBuilder = new FlowBuilder(flowStat);
             FlowId flowId = null;
-            FlowHash flowHash = FlowHashFactory.create(flowBuilder.build(), deviceContext);
+            FlowHash flowHash = FlowHashFactory.create(flowBuilder.build(), deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
             short tableId = flowStat.getTableId();
             try {
                 FlowDescriptor flowDescriptor = deviceContext.getDeviceFlowRegistry().retrieveIdForFlow(flowHash);
index 298a4261cb75e7dc72e3d2b214e44e7cb6c94b00..14b9e3b97c4d46bdebc52f74594d0b900052e95b 100644 (file)
@@ -109,7 +109,7 @@ public final class HashUtil {
         return hash;
     }
 
-    public static long calculateMatchHash(final Match match, DeviceContext deviceContext) {
+    public static long calculateMatchHash(final Match match, short version) {
         long hash = 0;
         long subHash = 0;
         long base = 0;
@@ -131,12 +131,12 @@ public final class HashUtil {
             base++;
             if (null != match.getInPhyPort()) {
                 hash = 1 << base;
-                subHash += calculateNodeConnectorIdHash(match.getInPhyPort(), deviceContext);
+                subHash += calculateNodeConnectorIdHash(match.getInPhyPort(), version);
             }
             base++;
             if (null != match.getInPort()) {
                 hash = 1 << base;
-                subHash += calculateNodeConnectorIdHash(match.getInPort(), deviceContext);
+                subHash += calculateNodeConnectorIdHash(match.getInPort(), version);
             }
             base++;
             if (null != match.getIpMatch()) {
@@ -542,9 +542,8 @@ public final class HashUtil {
         return hash;
     }
 
-    private static long calculateNodeConnectorIdHash(final NodeConnectorId inPhyPort, DeviceContext deviceContext) {
+    private static long calculateNodeConnectorIdHash(final NodeConnectorId inPhyPort, short version) {
         long hash = 0;
-        short version = deviceContext.getDeviceState().getVersion();
         Long portFromLogicalName = OpenflowPortsUtil.getPortFromLogicalName(OpenflowVersion.get(version), inPhyPort.getValue());
         hash += portFromLogicalName.intValue();
         return hash;
index 6cfdb753124a9b99033d304cf71e824c1a61c31b..5e402dfc03cdb1f2c9a2b00c5f79f35be1e4c84d 100644 (file)
@@ -92,8 +92,8 @@ public class FlowHashFactoryTest {
 
         HashSet<FlowHash> flowHashs = new HashSet();
         for (FlowAndStatisticsMapList item : flowStats.getFlowAndStatisticsMapList()) {
-            flowHashs.add(FlowHashFactory.create(item, deviceContext));
-            flowHashs.add(FlowHashFactory.create(item, deviceContext));
+            flowHashs.add(FlowHashFactory.create(item, OFConstants.OFP_VERSION_1_3));
+            flowHashs.add(FlowHashFactory.create(item, OFConstants.OFP_VERSION_1_3));
         }
         assertEquals(3, flowHashs.size());
     }
@@ -108,7 +108,7 @@ public class FlowHashFactoryTest {
                 .setPriority(2)
                 .setTableId((short) 0);
 
-        FlowHash flow1Hash = FlowHashFactory.create(flow1Builder.build(), deviceContext);
+        FlowHash flow1Hash = FlowHashFactory.create(flow1Builder.build(), OFConstants.OFP_VERSION_1_3);
         LOG.info("flowHash1: {}", flow1Hash.hashCode());
 
 
@@ -118,7 +118,7 @@ public class FlowHashFactoryTest {
                 .setCookie(new FlowCookie(BigInteger.valueOf(148)))
                 .setMatch(match2Builder.build());
 
-        FlowHash flow2Hash = FlowHashFactory.create(flow2Builder.build(), deviceContext);
+        FlowHash flow2Hash = FlowHashFactory.create(flow2Builder.build(), OFConstants.OFP_VERSION_1_3);
         LOG.info("flowHash2: {}", flow2Hash.hashCode());
 
         Assert.assertNotSame(flow1Hash, flow2Hash);
@@ -137,7 +137,7 @@ public class FlowHashFactoryTest {
         FlowBuilder fb1 = new FlowBuilder(flow1Builder.build());
         fb1.setTableId(null);
         try {
-            FlowHashFactory.create(fb1.build(), deviceContext);
+            FlowHashFactory.create(fb1.build(), OFConstants.OFP_VERSION_1_3);
             Assert.fail("hash creation should have failed because of NPE");
         } catch (Exception e) {
             // expected
@@ -147,7 +147,7 @@ public class FlowHashFactoryTest {
         FlowBuilder fb2 = new FlowBuilder(flow1Builder.build());
         fb2.setPriority(null);
         try {
-            FlowHashFactory.create(fb2.build(), deviceContext);
+            FlowHashFactory.create(fb2.build(), OFConstants.OFP_VERSION_1_3);
             Assert.fail("hash creation should have failed because of NPE");
         } catch (Exception e) {
             // expected
@@ -156,7 +156,7 @@ public class FlowHashFactoryTest {
 
         FlowBuilder fb3 = new FlowBuilder(flow1Builder.build());
         fb3.setCookie(null);
-        FlowHash flowHash = FlowHashFactory.create(fb3.build(), deviceContext);
+        FlowHash flowHash = FlowHashFactory.create(fb3.build(), OFConstants.OFP_VERSION_1_3);
         Assert.assertNotNull(flowHash.getCookie());
         Assert.assertEquals(OFConstants.DEFAULT_COOKIE, flowHash.getCookie());
     }
@@ -166,7 +166,7 @@ public class FlowHashFactoryTest {
         FlowsStatisticsUpdate flowStats = FLOWS_STATISTICS_UPDATE_BUILDER.build();
 
         for (FlowAndStatisticsMapList item : flowStats.getFlowAndStatisticsMapList()) {
-            FlowHash flowHash = FlowHashFactory.create(item, deviceContext);
+            FlowHash flowHash = FlowHashFactory.create(item, OFConstants.OFP_VERSION_1_3);
             FlowHash lastHash = null;
             if (null != lastHash) {
                 assertNotEquals(lastHash, flowHash);