We will be using Match object when calculating identifier for flow in local flow registry.
This identifier will be normalized as soon as normalization will be introduced. That
will result into device flow registry holding normalized flow keys.
Change-Id: Ieeaf1b573a34fd94c8cd2d7e932d4db8fb5ca83e
Signed-off-by: Martin Bobak <mbobak@cisco.com>
*/
public interface FlowRegistryKey {
- long getFlowHash();
-
short getTableId();
int getPriority();
BigInteger getCookie();
+
}
@Override
public FlowId storeIfNecessary(final FlowRegistryKey flowRegistryKey, final short tableId) {
+
+
FlowId alienFlowId = FlowUtil.createAlienFlowId(tableId);
FlowDescriptor alienFlowDescriptor = FlowDescriptorFactory.create(tableId, alienFlowId);
synchronized (flowRegistry) {
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
-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.FlowRegistryKey;
import org.opendaylight.openflowplugin.impl.util.HashUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
/**
* Created by Martin Bobak <mbobak@cisco.com> on 8.4.2015.
*/
-public class FlowHashFactory {
+public class FlowRegistryKeyFactory {
- public static FlowRegistryKey create(Flow flow, short version) {
- long hash = calculateHash(flow, version);
- return new FlowRegistryKeyDto(hash, flow);
+ public FlowRegistryKeyFactory() {
+ }
+
+ public static FlowRegistryKey create(Flow flow) {
+ return new FlowRegistryKeyDto(flow);
}
private static long calculateHash(Flow flow, short version) {
private static final class FlowRegistryKeyDto implements FlowRegistryKey {
- private final long flowHash;
- private final int intHashCode;
-
private final short tableId;
private final int priority;
private final BigInteger cookie;
+ private final Match match;
- public FlowRegistryKeyDto(final long flowHash, final Flow flow) {
- this.flowHash = flowHash;
- this.intHashCode = Longs.hashCode(flowHash);
+ public FlowRegistryKeyDto(final Flow flow) {
tableId = Preconditions.checkNotNull(flow.getTableId(), "flow tableId must not be null");
priority = Preconditions.checkNotNull(flow.getPriority(), "flow priority must not be null");
+ match = Preconditions.checkNotNull(flow.getMatch(), "Match value must not be null");
cookie = MoreObjects.firstNonNull(flow.getCookie(), OFConstants.DEFAULT_FLOW_COOKIE).getValue();
}
-
@Override
- public int hashCode() {
- return intHashCode;
- }
+ public boolean equals(final Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
- @Override
- public boolean equals(final Object obj) {
- if (null == obj) {
- return false;
- }
- if (!(obj instanceof FlowRegistryKey)) {
- return false;
- }
- FlowRegistryKey that = (FlowRegistryKey) obj;
- if (this.flowHash == that.getFlowHash()
- && this.tableId == that.getTableId()
- && this.priority == that.getPriority()
- && Objects.equals(this.cookie, that.getCookie())) {
- return true;
- }
- return false;
+ final FlowRegistryKeyDto that = (FlowRegistryKeyDto) o;
+
+ if (priority != that.priority) return false;
+ if (tableId != that.tableId) return false;
+ if (!match.equals(that.match)) return false;
+
+ return true;
}
@Override
- public long getFlowHash() {
- return flowHash;
+ public int hashCode() {
+ int result = (int) tableId;
+ result = 31 * result + priority;
+ result = 31 * result + match.hashCode();
+ return result;
}
@Override
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;
+import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory;
import org.opendaylight.openflowplugin.impl.util.FlowUtil;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor;
import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
}
final DeviceContext deviceContext = getDeviceContext();
- final FlowRegistryKey flowRegistryKey = FlowHashFactory.create(input, deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
+ final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(input);
final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(input.getTableId(), flowId);
deviceContext.getDeviceFlowRegistry().store(flowRegistryKey, flowDescriptor);
Futures.addCallback(future, new FutureCallback<RpcResult<AddFlowOutput>>() {
public void onSuccess(final RpcResult<RemoveFlowOutput> o) {
final DeviceContext deviceContext = getDeviceContext();
getMessageSpy().spyMessage(input.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
- FlowRegistryKey flowRegistryKey = FlowHashFactory.create(input, deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
+ FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(input);
deviceContext.getDeviceFlowRegistry().markToBeremoved(flowRegistryKey);
}
public void onSuccess(final RpcResult<UpdateFlowOutput> o) {
final DeviceContext deviceContext = getDeviceContext();
getMessageSpy().spyMessage(input.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
- final short version = deviceContext.getPrimaryConnectionContext().getFeatures().getVersion();
- FlowRegistryKey flowRegistryKey = FlowHashFactory.create(original, version);
+ FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(original);
- FlowRegistryKey updatedflowRegistryKey = FlowHashFactory.create(updated, version);
+ FlowRegistryKey updatedflowRegistryKey = FlowRegistryKeyFactory.create(updated);
FlowId flowId = input.getFlowRef().getValue().firstKeyOf(Flow.class, FlowKey.class).getId();
FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(updated.getTableId(), flowId);
final DeviceFlowRegistry deviceFlowRegistry = deviceContext.getDeviceFlowRegistry();
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.FlowRegistryKey;
-import org.opendaylight.openflowplugin.impl.registry.flow.FlowHashFactory;
+import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory;
import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
for (final FlowAndStatisticsMapList flowStat : flowsStatistics.getFlowAndStatisticsMapList()) {
final FlowBuilder flowBuilder = new FlowBuilder(flowStat);
short tableId = flowStat.getTableId();
- final Short version = deviceContext.getPrimaryConnectionContext().getFeatures().getVersion();
- final FlowRegistryKey flowRegistryKey = FlowHashFactory.create(flowBuilder.build(), version);
+ final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(flowBuilder.build());
final FlowId flowId = deviceContext.getDeviceFlowRegistry().storeIfNecessary(flowRegistryKey, tableId);
final FlowKey flowKey = new FlowKey(flowId);
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
+
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
@RunWith(MockitoJUnitRunner.class)
public class FlowRegistryKeyFactoryTest {
HashSet<FlowRegistryKey> flowRegistryKeys = new HashSet<>();
for (FlowAndStatisticsMapList item : flowStats.getFlowAndStatisticsMapList()) {
- flowRegistryKeys.add(FlowHashFactory.create(item, OFConstants.OFP_VERSION_1_3));
- flowRegistryKeys.add(FlowHashFactory.create(item, OFConstants.OFP_VERSION_1_3));
+ flowRegistryKeys.add(FlowRegistryKeyFactory.create(item));
+ flowRegistryKeys.add(FlowRegistryKeyFactory.create(item));
}
assertEquals(3, flowRegistryKeys.size());
}
.setPriority(2)
.setTableId((short) 0);
- FlowRegistryKey flow1Hash = FlowHashFactory.create(flow1Builder.build(), OFConstants.OFP_VERSION_1_3);
+ FlowRegistryKey flow1Hash = FlowRegistryKeyFactory.create(flow1Builder.build());
LOG.info("flowHash1: {}", flow1Hash.hashCode());
.setCookie(new FlowCookie(BigInteger.valueOf(148)))
.setMatch(match2Builder.build());
- FlowRegistryKey flow2Hash = FlowHashFactory.create(flow2Builder.build(), OFConstants.OFP_VERSION_1_3);
+ FlowRegistryKey flow2Hash = FlowRegistryKeyFactory.create(flow2Builder.build());
LOG.info("flowHash2: {}", flow2Hash.hashCode());
Assert.assertNotSame(flow1Hash, flow2Hash);
FlowBuilder fb1 = new FlowBuilder(flow1Builder.build());
fb1.setTableId(null);
try {
- FlowHashFactory.create(fb1.build(), OFConstants.OFP_VERSION_1_3);
+ FlowRegistryKeyFactory.create(fb1.build());
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(), OFConstants.OFP_VERSION_1_3);
+ FlowRegistryKeyFactory.create(fb2.build());
Assert.fail("hash creation should have failed because of NPE");
} catch (Exception e) {
// expected
FlowBuilder fb3 = new FlowBuilder(flow1Builder.build());
fb3.setCookie(null);
- FlowRegistryKey flowRegistryKey = FlowHashFactory.create(fb3.build(), OFConstants.OFP_VERSION_1_3);
+ FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(fb3.build());
Assert.assertNotNull(flowRegistryKey.getCookie());
Assert.assertEquals(OFConstants.DEFAULT_COOKIE, flowRegistryKey.getCookie());
}
FlowsStatisticsUpdate flowStats = FLOWS_STATISTICS_UPDATE_BUILDER.build();
for (FlowAndStatisticsMapList item : flowStats.getFlowAndStatisticsMapList()) {
- FlowRegistryKey flowRegistryKey = FlowHashFactory.create(item, OFConstants.OFP_VERSION_1_3);
+ FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(item);
FlowRegistryKey lastHash = null;
if (null != lastHash) {
assertNotEquals(lastHash, flowRegistryKey);