Only pop internally assigned VLANs before sending ARP to controller

Change-Id: I066e03ad9a491ad99816a976bc5561667878031a
(cherry picked from commit ec8e062dba5ef681951ea0a879ee475aa490ac8d)
diff --git a/drivers/default/src/main/java/org/onosproject/driver/pipeline/CpqdOfdpa2Pipeline.java b/drivers/default/src/main/java/org/onosproject/driver/pipeline/CpqdOfdpa2Pipeline.java
index 15729c5..effa88f 100644
--- a/drivers/default/src/main/java/org/onosproject/driver/pipeline/CpqdOfdpa2Pipeline.java
+++ b/drivers/default/src/main/java/org/onosproject/driver/pipeline/CpqdOfdpa2Pipeline.java
@@ -56,6 +56,7 @@
 import org.onosproject.net.group.Group;
 import org.onosproject.net.group.GroupKey;
 import org.onosproject.net.group.GroupService;
+import org.onosproject.net.packet.PacketPriority;
 import org.slf4j.Logger;
 
 import java.util.ArrayList;
@@ -254,13 +255,9 @@
         selector.matchVlanId(vidCriterion.vlanId());
         treatment.transition(TMAC_TABLE);
 
-        VlanId storeVlan = null;
         if (vidCriterion.vlanId() == VlanId.NONE) {
             // untagged packets are assigned vlans
             treatment.pushVlan().setVlanId(assignedVlan);
-            storeVlan = assignedVlan;
-        } else {
-            storeVlan = vidCriterion.vlanId();
         }
 
         // ofdpa cannot match on ALL portnumber, so we need to use separate
@@ -289,6 +286,25 @@
                     .forTable(VLAN_TABLE).build();
             rules.add(rule);
         }
+
+        // Emulating OFDPA behavior by popping off internal assigned VLAN
+        // before sending to controller
+        TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder()
+                .matchEthType(Ethernet.TYPE_ARP)
+                .matchVlanId(assignedVlan);
+        TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder()
+                .popVlan()
+                .punt();
+        FlowRule internalVlan = DefaultFlowRule.builder()
+                .forDevice(deviceId)
+                .withSelector(sbuilder.build())
+                .withTreatment(tbuilder.build())
+                .withPriority(PacketPriority.CONTROL.priorityValue() + 1)
+                .fromApp(applicationId)
+                .makePermanent()
+                .forTable(ACL_TABLE).build();
+        rules.add(internalVlan);
+
         return rules;
     }
 
@@ -659,9 +675,6 @@
                 if (ins instanceof OutputInstruction) {
                     OutputInstruction o = (OutputInstruction) ins;
                     if (o.port() == PortNumber.CONTROLLER) {
-                        // emulating real ofdpa behavior by popping off internal
-                        // vlan before sending to controller
-                        ttBuilder.popVlan();
                         ttBuilder.add(o);
                     } else {
                         log.warn("Only allowed treatments in versatile forwarding "