[ONOS-6302] Fix wrong flow rules when install flow rule Intents

Change-Id: I8ef42e53c0bd718b5d955e1fc572b8361825234f
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentInstaller.java b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentInstaller.java
index 0fd57a9..66d11e7 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentInstaller.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentInstaller.java
@@ -360,8 +360,8 @@
                         } else if (uIntent instanceof FlowRuleIntent && installIntent instanceof FlowRuleIntent) {
                             //FIXME we can further optimize this by doing the filtering on a flow-by-flow basis
                             //      (direction can be implied from intent state)
-                            return ((FlowRuleIntent) uIntent).flowRules()
-                                    .containsAll(((FlowRuleIntent) installIntent).flowRules());
+                            return !flowRuleIntentChanged(((FlowRuleIntent) uIntent),
+                                                          ((FlowRuleIntent) installIntent));
                         } else {
                             return false;
                         }
@@ -393,6 +393,30 @@
         }
 
         /**
+         * Determines whether there is any flow rule changed
+         * (i.e., different set of flow rules or different treatments)
+         * between FlowRuleIntents to be uninstalled and to be installed.
+         *
+         * @param uninstallIntent FlowRuleIntent to uninstall
+         * @param installIntent FlowRuleIntent to install
+         * @return true if flow rules which to be uninstalled
+         * contains all flow rules which to be installed.
+         */
+        private boolean flowRuleIntentChanged(FlowRuleIntent uninstallIntent,
+                                              FlowRuleIntent installIntent) {
+            Collection<FlowRule> flowRulesToUninstall = uninstallIntent.flowRules();
+            Collection<FlowRule> flowRulesToInstall = installIntent.flowRules();
+
+            // Check if any flow rule changed
+            for (FlowRule flowRuleToInstall : flowRulesToInstall) {
+                if (flowRulesToUninstall.stream().noneMatch(flowRuleToInstall::exactMatch)) {
+                    return true;
+                }
+            }
+            return false;
+        }
+
+        /**
          * Applies the specified intent data, if present, to the network using the
          * specified context.
          *