Add default drop rule in OF1.0 switches.

Default drop rule has the lowest priority and matches everything. This means
if a packet doesn't match any rules in the flow table, it is dropped. This
brings OF1.0 behaviour into line with OF1.3+ behaviour.

Change-Id: Id73839907a664bdccbc7a5eb904a8edd2a6222e7
diff --git a/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/DriverManager.java b/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/DriverManager.java
index f7c547c..1307f4a 100644
--- a/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/DriverManager.java
+++ b/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/DriverManager.java
@@ -25,6 +25,7 @@
 import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver;
 import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriverFactory;
 import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
+import org.projectfloodlight.openflow.protocol.OFFlowAdd;
 import org.projectfloodlight.openflow.protocol.OFMessage;
 import org.projectfloodlight.openflow.protocol.OFPortDesc;
 import org.projectfloodlight.openflow.protocol.OFVersion;
@@ -39,6 +40,8 @@
 
     private static final Logger log = LoggerFactory.getLogger(DriverManager.class);
 
+    private static final int LOWEST_PRIORITY = 0;
+
     /**
      * Return an IOFSwitch object based on switch's manufacturer description
      * from OFDescStatsReply.
@@ -98,7 +101,13 @@
             }
 
             @Override
-            public void startDriverHandshake() {}
+            public void startDriverHandshake() {
+                if (factory().getVersion() == OFVersion.OF_10) {
+                    OFFlowAdd.Builder fmBuilder = factory().buildFlowAdd();
+                    fmBuilder.setPriority(LOWEST_PRIORITY);
+                    write(fmBuilder.build());
+                }
+            }
 
             @Override
             public void processDriverHandshakeMessage(OFMessage m) {}
diff --git a/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/OFSwitchImplOVS10.java b/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/OFSwitchImplOVS10.java
index 6f20afe..a017abe 100644
--- a/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/OFSwitchImplOVS10.java
+++ b/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/OFSwitchImplOVS10.java
@@ -15,15 +15,16 @@
  */
 package org.onosproject.openflow.drivers;
 
+import java.util.Collections;
+import java.util.List;
+
 import org.onosproject.openflow.controller.Dpid;
 import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch;
 import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
+import org.projectfloodlight.openflow.protocol.OFFlowAdd;
 import org.projectfloodlight.openflow.protocol.OFMessage;
 import org.projectfloodlight.openflow.protocol.OFPortDesc;
 
-import java.util.Collections;
-import java.util.List;
-
 /**
  * OFDescriptionStatistics Vendor (Manufacturer Desc.): Nicira, Inc. Make
  * (Hardware Desc.) : Open vSwitch Model (Datapath Desc.) : None Software :
@@ -31,6 +32,8 @@
  */
 public class OFSwitchImplOVS10 extends AbstractOpenFlowSwitch {
 
+    private static final int LOWEST_PRIORITY = 0;
+
     public OFSwitchImplOVS10(Dpid dpid, OFDescStatsReply desc) {
         super(dpid);
         setSwitchDescription(desc);
@@ -53,7 +56,11 @@
     }
 
     @Override
-    public void startDriverHandshake() {}
+    public void startDriverHandshake() {
+        OFFlowAdd.Builder fmBuilder = factory().buildFlowAdd();
+        fmBuilder.setPriority(LOWEST_PRIORITY);
+        write(fmBuilder.build());
+    }
 
     @Override
     public boolean isDriverHandshakeComplete() {
diff --git a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/OpenFlowRuleProvider.java b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/OpenFlowRuleProvider.java
index d7bf539..8a77e50 100644
--- a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/OpenFlowRuleProvider.java
+++ b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/OpenFlowRuleProvider.java
@@ -15,11 +15,24 @@
  */
 package org.onosproject.provider.of.flow.impl;
 
-import com.google.common.base.MoreObjects;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Sets;
+import static com.google.common.base.Preconditions.checkState;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.stream.Collectors;
 
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
@@ -71,24 +84,11 @@
 import org.projectfloodlight.openflow.types.OFPort;
 import org.slf4j.Logger;
 
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.stream.Collectors;
-
-import static com.google.common.base.Preconditions.checkState;
-import static org.slf4j.LoggerFactory.getLogger;
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Sets;
 
 /**
  * Provider which uses an OpenFlow controller to detect network
@@ -99,6 +99,8 @@
 
     enum BatchState { STARTED, FINISHED, CANCELLED };
 
+    private static final int LOWEST_PRIORITY = 0;
+
     private final Logger log = getLogger(getClass());
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -344,10 +346,13 @@
         }
 
         private boolean tableMissRule(Dpid dpid, OFFlowStatsEntry reply) {
-            if (reply.getVersion().equals(OFVersion.OF_10) ||
-                    reply.getMatch().getMatchFields().iterator().hasNext()) {
+            if (reply.getMatch().getMatchFields().iterator().hasNext()) {
                 return false;
             }
+            if (reply.getVersion().equals(OFVersion.OF_10)) {
+                return reply.getPriority() == LOWEST_PRIORITY
+                        && reply.getActions().isEmpty();
+            }
             for (OFInstruction ins : reply.getInstructions()) {
                 if (ins.getType() == OFInstructionType.APPLY_ACTIONS) {
                     OFInstructionApplyActions apply = (OFInstructionApplyActions) ins;