*/
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();
* Marker interface identifying flow stored in OFP local flow registry.
* Created by Martin Bobak <mbobak@cisco.com> on 8.4.2015.
*/
-public interface FlowHash {
+public interface FlowRegistryKey {
long getFlowHash();
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;
*/
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) {
@Override
- public Map<FlowHash, FlowDescriptor> getAllFlowDescriptors() {
+ public Map<FlowRegistryKey, FlowDescriptor> getAllFlowDescriptors() {
return flowRegistry;
}
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;
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) {
}
- private static final class FlowHashDto implements FlowHash {
+ private static final class FlowRegistryKeyDto implements FlowRegistryKey {
private final long flowHash;
private final int intHashCode;
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");
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()
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;
}
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>>() {
@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);
}
});
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
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
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;
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);
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;
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();
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
.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());
.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);
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
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;
}
}
}