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);
}
}
- 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);
@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);
}
@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);
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);
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;
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()) {
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;
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());
}
.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());
.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);
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
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
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());
}
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);