Fixed bug on NIC wildcard identification

Also, handle the possibility that some flow rules might
not be installed.
Addressed comment made by ONOS member.

Change-Id: I7554f62b7bf10ac4a1301daca1886e1e8cb5d98a
Signed-off-by: Georgios Katsikas <katsikas.gp@gmail.com>
(cherry picked from commit 332985d14102c9496d9bcc9063a43d332d525516)
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/FlowRuleProgrammableServerImpl.java b/drivers/server/src/main/java/org/onosproject/drivers/server/FlowRuleProgrammableServerImpl.java
index 34947cb..7542698 100644
--- a/drivers/server/src/main/java/org/onosproject/drivers/server/FlowRuleProgrammableServerImpl.java
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/FlowRuleProgrammableServerImpl.java
@@ -40,6 +40,7 @@
 import java.io.InputStream;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -307,7 +308,8 @@
     private Collection<FlowRule> installNicFlowRules(
             DeviceId deviceId, String trafficClassId,
             Collection<FlowRule> rules) {
-        if (rules.isEmpty()) {
+        int rulesToInstall = rules.size();
+        if (rulesToInstall == 0) {
             return Collections.EMPTY_LIST;
         }
 
@@ -329,11 +331,13 @@
             new ConcurrentHashMap<Long, ArrayNode>();
 
         String nic = null;
+        Iterator<FlowRule> it = rules.iterator();
 
-        for (FlowRule rule : rules) {
-            NicFlowRule nicRule = (NicFlowRule) rule;
-            if (nicRule.isFullWildcard() && (rules.size() > 1)) {
+        while (it.hasNext()) {
+            NicFlowRule nicRule = (NicFlowRule) it.next();
+            if (nicRule.isFullWildcard() && (rulesToInstall > 1)) {
                 log.warn("Skipping wildcard rule: {}", nicRule);
+                it.remove();
                 continue;
             }
 
@@ -362,6 +366,11 @@
             ruleArrayNode.add(ruleNode);
         }
 
+        if (rules.size() == 0) {
+            log.error("Failed to install {} NIC flow rules in device {}", rulesToInstall, deviceId);
+            return Collections.EMPTY_LIST;
+        }
+
         ObjectNode nicObjNode = mapper.createObjectNode();
         nicObjNode.put("nicName", nic);
 
@@ -392,12 +401,12 @@
 
         // Upon an error, return an empty set of rules
         if (!checkStatusCode(response)) {
-            log.error("Failed to install NIC flow rules in device {}", deviceId);
+            log.error("Failed to install {} NIC flow rules in device {}", rules.size(), deviceId);
             return Collections.EMPTY_LIST;
         }
 
-        log.info("Successfully installed {} NIC flow rules in device {}",
-            rules.size(), deviceId);
+        log.info("Successfully installed {}/{} NIC flow rules in device {}",
+            rules.size(), rulesToInstall, deviceId);
 
         // .. or all of them
         return rules;
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/devices/nic/DefaultNicFlowRule.java b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/nic/DefaultNicFlowRule.java
index 8f50986..dd56570 100644
--- a/drivers/server/src/main/java/org/onosproject/drivers/server/devices/nic/DefaultNicFlowRule.java
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/nic/DefaultNicFlowRule.java
@@ -311,9 +311,9 @@
         if (((ipv4SrcAddress() != null) && !ipv4SrcAddress().isZero()) ||
             ((ipv4DstAddress() != null) && !ipv4DstAddress().isZero()) ||
             (ipv4Protocol() > 0) || (sourcePort() > 0) || (destinationPort() > 0)) {
-            return true;
+            return false;
         }
-        return false;
+        return true;
     }
 
     @Override