+
+ //Hashcode generation of the extension augmentation can differ for the same object received from the datastore and
+ // the one received after deserialization of switch message. OpenFlowplugin extensions are list, and the order in
+ // which it can receive the extensions back from switch can differ and that lead to a different hashcode. In that
+ // scenario, hashcode won't match and flowRegistry return the related key. To overcome this issue, these methods
+ // make sure that key is stored only if it doesn't equals to any existing key.
+ private void addToFlowRegistry(final FlowRegistryKey flowRegistryKey, final FlowDescriptor flowDescriptor) {
+ FlowRegistryKey existingFlowRegistryKey = getExistingKey(flowRegistryKey);
+ if (existingFlowRegistryKey == null) {
+ flowRegistry.put(flowRegistryKey, flowDescriptor);
+ } else {
+ flowRegistry.put(existingFlowRegistryKey, flowDescriptor);
+ }
+ }
+
+ private void removeFromFlowRegistry(final FlowRegistryKey flowRegistryKey) {
+ FlowRegistryKey existingFlowRegistryKey = getExistingKey(flowRegistryKey);
+ if (existingFlowRegistryKey != null) {
+ flowRegistry.remove(existingFlowRegistryKey);
+ } else {
+ flowRegistry.remove(flowRegistryKey);
+ }
+ }
+
+ private FlowRegistryKey getExistingKey(final FlowRegistryKey flowRegistryKey) {
+ if (flowRegistryKey.getMatch().augmentation(GeneralAugMatchNodesNodeTableFlow.class) == null) {
+ if (flowRegistry.containsKey(flowRegistryKey)) {
+ return flowRegistryKey;
+ }
+ } else {
+ synchronized (flowRegistry) {
+ for (Map.Entry<FlowRegistryKey, FlowDescriptor> keyValueSet : flowRegistry.entrySet()) {
+ if (keyValueSet.getKey().equals(flowRegistryKey)) {
+ return keyValueSet.getKey();
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @VisibleForTesting
+ Map<FlowRegistryKey, FlowDescriptor> getAllFlowDescriptors() {
+ return flowRegistry;
+ }
+}