X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fregistry%2Fflow%2FDeviceFlowRegistryImpl.java;h=01a92d00f439d6a8ea68858eadff433cc5d38f16;hb=0ac8877c3539d82e55ffe49dc0a2c8bcb0c82b19;hp=3ac3173dc9c867e0252d962384869f6c49ff47d5;hpb=da5cf58ce1a5dd90aa84e2d5dd984d6cfa030a21;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/registry/flow/DeviceFlowRegistryImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/registry/flow/DeviceFlowRegistryImpl.java index 3ac3173dc9..01a92d00f4 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/registry/flow/DeviceFlowRegistryImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/registry/flow/DeviceFlowRegistryImpl.java @@ -16,20 +16,15 @@ 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; @@ -47,39 +42,33 @@ import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; 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 flowRegistry = HashBiMap.create(); - @GuardedBy("marks") - private final Collection marks = new HashSet<>(); + private final BiMap flowRegistry = Maps.synchronizedBiMap(HashBiMap.create()); private final DataBroker dataBroker; private final KeyedInstanceIdentifier instanceIdentifier; private final List>>> lastFillFutures = new ArrayList<>(); + private final Consumer flowConsumer; - // Specifies what to do with flow read from datastore - private final Consumer flowConsumer = flow -> { - // Create flow registry key from flow - final FlowRegistryKey key = FlowRegistryKeyFactory.create(flow); - - // Now, we will update the registry, but we will also try to prevent duplicate entries - if (!flowRegistry.containsKey(key)) { - LOG.trace("Found flow with table ID : {} and flow ID : {}", flow.getTableId(), flow.getId().getValue()); - final FlowDescriptor descriptor = FlowDescriptorFactory.create(flow.getTableId(), flow.getId()); - store(key, descriptor); - } - }; - - - public DeviceFlowRegistryImpl(final DataBroker dataBroker, final KeyedInstanceIdentifier instanceIdentifier) { + public DeviceFlowRegistryImpl(final short version, final DataBroker dataBroker, final KeyedInstanceIdentifier instanceIdentifier) { this.dataBroker = dataBroker; this.instanceIdentifier = instanceIdentifier; + + // Specifies what to do with flow read from datastore + flowConsumer = flow -> { + // Create flow registry key from flow + final FlowRegistryKey key = FlowRegistryKeyFactory.create(version, flow); + + // Now, we will update the registry, but we will also try to prevent duplicate entries + if (!flowRegistry.containsKey(key)) { + LOG.trace("Found flow with table ID : {} and flow ID : {}", flow.getTableId(), flow.getId().getValue()); + final FlowDescriptor descriptor = FlowDescriptorFactory.create(flow.getTableId(), flow.getId()); + store(key, descriptor); + } + }; } @Override @@ -173,23 +162,28 @@ public class DeviceFlowRegistryImpl implements DeviceFlowRegistry { 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()); try { - flowRegistry.put(flowRegistryKey, flowDescriptor); + 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(), + LOG.warn("Flow with flowId {} already exists in table {}", flowDescriptor.getFlowId().getValue(), flowDescriptor.getTableKey().getId()); - final FlowId newFlowId = createAlienFlowId(flowDescriptor.getTableKey().getId()); - final FlowDescriptor newFlowDescriptor = FlowDescriptorFactory. - create(flowDescriptor.getTableKey().getId(), newFlowId); - flowRegistry.put(flowRegistryKey, newFlowDescriptor); + final FlowId newFlowId = createAlienFlowId(flowDescriptor.getTableKey().getId()); + final FlowDescriptor newFlowDescriptor = FlowDescriptorFactory. + create(flowDescriptor.getTableKey().getId(), newFlowId); + flowRegistry.put(flowRegistryKey, newFlowDescriptor); } } + @Override + public void update(final FlowRegistryKey newFlowRegistryKey, final FlowDescriptor flowDescriptor) { + LOG.trace("Updating the entry with hash: {}", newFlowRegistryKey.hashCode()); + flowRegistry.forcePut(newFlowRegistryKey, flowDescriptor); + } + @Override public FlowId storeIfNecessary(final FlowRegistryKey flowRegistryKey) { LOG.trace("Trying to retrieve flow ID for flow hash : {}", flowRegistryKey.hashCode()); @@ -213,24 +207,9 @@ public class DeviceFlowRegistryImpl implements DeviceFlowRegistry { } @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) { + LOG.trace("Removing flow descriptor for flow hash : {}", flowRegistryKey.hashCode()); + flowRegistry.remove(flowRegistryKey); } @Override @@ -250,7 +229,6 @@ public class DeviceFlowRegistryImpl implements DeviceFlowRegistry { } flowRegistry.clear(); - marks.clear(); } @VisibleForTesting @@ -258,4 +236,4 @@ public class DeviceFlowRegistryImpl implements DeviceFlowRegistry { final String alienId = ALIEN_SYSTEM_FLOW_ID + tableId + '-' + UNACCOUNTED_FLOWS_COUNTER.incrementAndGet(); return new FlowId(alienId); } -} \ No newline at end of file +}