import java.util.Map;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
/**
- * Created by Martin Bobak <mbobak@cisco.com> on 8.4.2015.
+ * Registry for mapping composite-key of flow ({@link FlowRegistryKey}) from device view
+ * to flow descriptor ({@link FlowDescriptor}) as the identifier of the same flow in data store.
*/
public interface DeviceFlowRegistry extends AutoCloseable {
FlowId storeIfNecessary(FlowRegistryKey flowRegistryKey);
- void markToBeremoved(FlowRegistryKey flowRegistryKey);
+ void removeDescriptor(FlowRegistryKey flowRegistryKey);
void update(FlowRegistryKey newFlowRegistryKey,FlowDescriptor flowDescriptor);
- void removeMarked();
-
Map<FlowRegistryKey, FlowDescriptor> getAllFlowDescriptors();
@Override
import com.google.common.base.Optional;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
-import com.google.common.collect.Maps;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
-import com.romix.scala.collection.concurrent.TrieMap;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
-import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * Created by Martin Bobak <mbobak@cisco.com> on 8.4.2015.
- */
public class DeviceFlowRegistryImpl implements DeviceFlowRegistry {
private static final Logger LOG = LoggerFactory.getLogger(DeviceFlowRegistryImpl.class);
private static final String ALIEN_SYSTEM_FLOW_ID = "#UF$TABLE*";
private static final AtomicInteger UNACCOUNTED_FLOWS_COUNTER = new AtomicInteger(0);
-
private final BiMap<FlowRegistryKey, FlowDescriptor> flowRegistry = HashBiMap.create();
- @GuardedBy("marks")
- private final Collection<FlowRegistryKey> marks = new HashSet<>();
private final DataBroker dataBroker;
private final KeyedInstanceIdentifier<Node, NodeKey> instanceIdentifier;
private final List<ListenableFuture<List<Optional<FlowCapableNode>>>> lastFillFutures = new ArrayList<>();
}
};
-
public DeviceFlowRegistryImpl(final DataBroker dataBroker, final KeyedInstanceIdentifier<Node, NodeKey> instanceIdentifier) {
this.dataBroker = dataBroker;
this.instanceIdentifier = instanceIdentifier;
return flowDescriptor;
}
-
@Override
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 (flowRegistryKey) {
try {
+ LOG.trace("Storing flowDescriptor with table ID : {} and flow ID : {} for flow hash : {}",
+ flowDescriptor.getTableKey().getId(), flowDescriptor.getFlowId().getValue(), flowRegistryKey.hashCode());
flowRegistry.put(flowRegistryKey, flowDescriptor);
} catch (IllegalArgumentException ex) {
LOG.error("Flow with flowId {} already exists in table {}", flowDescriptor.getFlowId().getValue(),
}
@Override
- public void update(FlowRegistryKey newFlowRegistryKey,FlowDescriptor flowDescriptor){
- LOG.trace("Updating the entry with hash: {}", newFlowRegistryKey.hashCode());
+ public void update(final FlowRegistryKey newFlowRegistryKey, final FlowDescriptor flowDescriptor) {
synchronized (newFlowRegistryKey) {
+ LOG.trace("Updating the entry with hash: {}", newFlowRegistryKey.hashCode());
flowRegistry.forcePut(newFlowRegistryKey, flowDescriptor);
}
}
}
@Override
- public void markToBeremoved(final FlowRegistryKey flowRegistryKey) {
- synchronized (marks) {
- marks.add(flowRegistryKey);
- }
-
- LOG.trace("Flow hash {} was marked for removal.", flowRegistryKey.hashCode());
- }
-
- @Override
- public void removeMarked() {
- synchronized (marks) {
- for (FlowRegistryKey flowRegistryKey : marks) {
- LOG.trace("Removing flow descriptor for flow hash : {}", flowRegistryKey.hashCode());
- flowRegistry.remove(flowRegistryKey);
- }
-
- marks.clear();
+ public void removeDescriptor(final FlowRegistryKey flowRegistryKey) {
+ synchronized (flowRegistryKey) {
+ LOG.trace("Removing flow descriptor for flow hash : {}", flowRegistryKey.hashCode());
+ flowRegistry.remove(flowRegistryKey);
}
}
}
flowRegistry.clear();
- marks.clear();
}
@VisibleForTesting
order.verify(readOnlyTransaction).read(LogicalDatastoreType.OPERATIONAL, path);
assertTrue(allFlowDescriptors.containsKey(key));
- deviceFlowRegistry.markToBeremoved(key);
- deviceFlowRegistry.removeMarked();
+ deviceFlowRegistry.removeDescriptor(key);
}
@Test
}
@Test
- public void testRemoveMarked() throws Exception {
- deviceFlowRegistry.markToBeremoved(key);
- deviceFlowRegistry.removeMarked();
+ public void testRemoveDescriptor() throws Exception {
+ deviceFlowRegistry.removeDescriptor(key);
Assert.assertEquals(0, deviceFlowRegistry.getAllFlowDescriptors().size());
}
- @Test
- public void testRemoveMarkedNegative() throws Exception {
- final FlowAndStatisticsMapList flowStats = TestFlowHelper.createFlowAndStatisticsMapListBuilder(2).build();
- FlowRegistryKey key2 = FlowRegistryKeyFactory.create(flowStats);
- deviceFlowRegistry.markToBeremoved(key2);
- deviceFlowRegistry.removeMarked();
- Assert.assertEquals(1, deviceFlowRegistry.getAllFlowDescriptors().size());
- }
-
@Test
public void testClose() throws Exception {
- deviceFlowRegistry.markToBeremoved(key);
deviceFlowRegistry.close();
Assert.assertEquals(0, deviceFlowRegistry.getAllFlowDescriptors().size());
-
- deviceFlowRegistry.store(key, descriptor);
- Assert.assertEquals(1, deviceFlowRegistry.getAllFlowDescriptors().size());
- deviceFlowRegistry.removeMarked();
- Assert.assertEquals(1, deviceFlowRegistry.getAllFlowDescriptors().size());
}
@Test