Bug fixes for the centec and noviflow pipelines.

Change-Id: Id0531e54060ff8e2a2321f6c49c8c16e32be45f8
diff --git a/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java b/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
index b1de540..d5b12b3 100644
--- a/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
+++ b/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
@@ -437,6 +437,7 @@
             for (FlowEntry rule : storedRules) {
                 try {
                     // there are rules in the store that aren't on the switch
+                    log.debug("Adding rule in store, but not on switch {}", rule);
                     flowMissing(rule);
                 } catch (Exception e) {
                     log.debug("Can't add missing flow rule {}", e.getMessage());
diff --git a/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java b/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java
index 00fa550..4eb8c7a 100644
--- a/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java
+++ b/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java
@@ -329,6 +329,7 @@
                     L2ModificationInstruction.PushHeaderInstructions.class,
                     L2ModificationInstruction.ModVlanIdInstruction.class,
                     L2ModificationInstruction.ModVlanPcpInstruction.class,
+                    L2ModificationInstruction.PopVlanInstruction.class,
                     L2ModificationInstruction.ModMplsLabelInstruction.class,
                     L2ModificationInstruction.ModMplsTtlInstruction.class,
                     L3ModificationInstruction.class,
diff --git a/drivers/src/main/java/org/onosproject/driver/pipeline/CentecV350Pipeline.java b/drivers/src/main/java/org/onosproject/driver/pipeline/CentecV350Pipeline.java
index 7c29773..a7be6a1 100644
--- a/drivers/src/main/java/org/onosproject/driver/pipeline/CentecV350Pipeline.java
+++ b/drivers/src/main/java/org/onosproject/driver/pipeline/CentecV350Pipeline.java
@@ -14,6 +14,7 @@
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
 import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
 import org.onosproject.net.behaviour.NextGroup;
 import org.onosproject.net.behaviour.Pipeliner;
 import org.onosproject.net.behaviour.PipelinerContext;
@@ -78,7 +79,7 @@
     protected static final int ROUTE_TABLE = 3;
 
     private static final long DEFAULT_METADATA = 100;
-    private static final long DEFAULT_METADATA_MASK = 0xff;
+    private static final long DEFAULT_METADATA_MASK = 0xffffffffffffffffL;
 
     // Priority used in PORT_VLAN Table, the only priority accepted is PORT_VLAN_TABLE_PRIORITY.
     // The packet passed PORT+VLAN check will goto FILTER Table.
@@ -424,8 +425,22 @@
                         .forTable(PORT_VLAN_TABLE).build();
                 ops = install ? ops.add(rule) : ops.remove(rule);
             } else if (c.type() == Criterion.Type.IPV4_DST) {
-                // TODO: not needed now? Why not?
-                fail(filt, ObjectiveError.UNSUPPORTED);
+                IPCriterion ipaddr = (IPCriterion) c;
+                log.debug("adding IP filtering rules in FILTER table: {}", ipaddr.ip());
+                TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
+                TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
+                selector.matchEthType(Ethernet.TYPE_IPV4);
+                selector.matchIPDst(ipaddr.ip()); // router IPs to the controller
+                treatment.setOutput(PortNumber.CONTROLLER);
+                FlowRule rule = DefaultFlowRule.builder()
+                        .forDevice(deviceId)
+                        .withSelector(selector.build())
+                        .withTreatment(treatment.build())
+                        .withPriority(FILTER_TABLE_CONTROLLER_PRIORITY)
+                        .fromApp(applicationId)
+                        .makePermanent()
+                        .forTable(FILTER_TABLE).build();
+                ops =  install ? ops.add(rule) : ops.remove(rule);
             } else {
                 log.warn("Driver does not currently process filtering condition"
                         + " of type: {}", c.type());
diff --git a/drivers/src/main/java/org/onosproject/driver/pipeline/SoftRouterPipeline.java b/drivers/src/main/java/org/onosproject/driver/pipeline/SoftRouterPipeline.java
index bf87dc3..2240520 100644
--- a/drivers/src/main/java/org/onosproject/driver/pipeline/SoftRouterPipeline.java
+++ b/drivers/src/main/java/org/onosproject/driver/pipeline/SoftRouterPipeline.java
@@ -260,7 +260,8 @@
         selector.matchVlanId(v.vlanId());
         selector.matchEthDst(e.mac());
         selector.matchEthType(Ethernet.TYPE_IPV4);
-        treatment.transition(FIB_TABLE);
+        treatment.popVlan();
+        treatment.transition(FIB_TABLE); // all other IPs to the FIB table
         FlowRule rule = DefaultFlowRule.builder()
                 .forDevice(deviceId)
                 .withSelector(selector.build())
@@ -272,11 +273,14 @@
         ops =  ops.add(rule);
 
         for (IPCriterion ipaddr : ips) {
-            log.debug("adding IP filtering rules in FIB table: {}", ipaddr.ip());
+            log.debug("adding IP filtering rules in FILTER table: {}", ipaddr.ip());
             selector = DefaultTrafficSelector.builder();
             treatment = DefaultTrafficTreatment.builder();
+            selector.matchInPort(p.port());
+            selector.matchVlanId(v.vlanId());
+            selector.matchEthDst(e.mac());
             selector.matchEthType(Ethernet.TYPE_IPV4);
-            selector.matchIPDst(ipaddr.ip());
+            selector.matchIPDst(ipaddr.ip()); // router IPs to the controller
             treatment.setOutput(PortNumber.CONTROLLER);
             rule = DefaultFlowRule.builder()
                     .forDevice(deviceId)
@@ -285,7 +289,7 @@
                     .withPriority(HIGHEST_PRIORITY)
                     .fromApp(applicationId)
                     .makePermanent()
-                    .forTable(FIB_TABLE).build();
+                    .forTable(FILTER_TABLE).build();
             ops =  ops.add(rule);
         }
 
@@ -474,8 +478,9 @@
      */
     private void processSimpleNextObjective(NextObjective nextObj) {
         // Simple next objective has a single treatment (not a collection)
+        TrafficTreatment treatment = nextObj.next().iterator().next();
         flowObjectiveStore.putNextGroup(nextObj.id(),
-                                        new DummyGroup(nextObj.next().iterator().next()));
+                                        new DummyGroup(treatment));
     }
 
     private class Filter {
diff --git a/drivers/src/main/resources/onos-drivers.xml b/drivers/src/main/resources/onos-drivers.xml
index 601e162..b442b0e 100644
--- a/drivers/src/main/resources/onos-drivers.xml
+++ b/drivers/src/main/resources/onos-drivers.xml
@@ -82,5 +82,8 @@
         <behaviour api="org.onosproject.net.behaviour.Pipeliner"
                    impl="org.onosproject.driver.pipeline.PicaPipeline"/>
     </driver>
+    <driver name="noviflow" extends="softrouter"
+            manufacturer="NoviFlow Inc" hwVersion="NS1132" swVersion="NW250.4.4">
+    </driver>
 </drivers>