CORD-389 Fix for Accton 6712 deployment

Related to this topic:
- Disable the meter collector since right now it is not supported
- Implement extension VLAN ID selector/treatment for OFDPA
    Since it requires two special flow entries to match untagged packets
        0x1ffe/no mask (filtering rule, need to go first)
        0x0000/0x1fff setvid 0x0ffe (assignment rule, need to go second)
- Not able to point /32 IP address to ECMP group. Use /31 instead.

In addition:
- Implement serializer for ExtensionCriterion

Change-Id: I621b3ad14014d7e6945c014cdae4f7cd2939288e
diff --git a/drivers/default/src/main/java/org/onosproject/driver/extensions/OfdpaExtensionSelectorInterpreter.java b/drivers/default/src/main/java/org/onosproject/driver/extensions/OfdpaExtensionSelectorInterpreter.java
new file mode 100644
index 0000000..4a9d0ff
--- /dev/null
+++ b/drivers/default/src/main/java/org/onosproject/driver/extensions/OfdpaExtensionSelectorInterpreter.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.driver.extensions;
+
+import org.onlab.packet.VlanId;
+import org.onosproject.net.behaviour.ExtensionSelectorResolver;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.net.flow.criteria.ExtensionSelector;
+import org.onosproject.net.flow.criteria.ExtensionSelectorType;
+import org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes;
+import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
+import org.projectfloodlight.openflow.protocol.OFFactory;
+import org.projectfloodlight.openflow.protocol.match.MatchField;
+import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
+import org.projectfloodlight.openflow.protocol.oxm.OFOxmVlanVid;
+import org.projectfloodlight.openflow.protocol.oxm.OFOxmVlanVidMasked;
+import org.projectfloodlight.openflow.types.OFVlanVidMatch;
+import org.projectfloodlight.openflow.types.VlanVid;
+
+/**
+ * Interpreter for OFDPA OpenFlow selector extensions.
+ */
+public class OfdpaExtensionSelectorInterpreter extends AbstractHandlerBehaviour
+        implements ExtensionSelectorInterpreter, ExtensionSelectorResolver {
+
+    @Override
+    public boolean supported(ExtensionSelectorType extensionSelectorType) {
+        if (extensionSelectorType.equals(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) {
+        ExtensionSelectorType type = extensionSelector.type();
+        if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
+            VlanId vlanId = ((OfdpaMatchVlanVid) extensionSelector).vlanId();
+            // Special VLAN 0x0000/0x1FFF required by OFDPA
+            if (vlanId.toShort() == 0x0000) {
+                OFVlanVidMatch vid = OFVlanVidMatch.ofRawVid(vlanId.toShort());
+                OFVlanVidMatch mask = OFVlanVidMatch.ofRawVid((short) 0x1FFF);
+                return factory.oxms().vlanVidMasked(vid, mask);
+            // Normal case
+            } else if (vlanId.equals(VlanId.ANY)) {
+                return factory.oxms().vlanVidMasked(OFVlanVidMatch.PRESENT, OFVlanVidMatch.PRESENT);
+            } else if (vlanId.equals(VlanId.NONE)) {
+                return factory.oxms().vlanVid(OFVlanVidMatch.NONE);
+            } else {
+                return factory.oxms().vlanVid(OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vlanId.toShort())));
+            }
+        }
+        throw new UnsupportedOperationException(
+                "Unexpected ExtensionSelector: " + extensionSelector.toString());
+    }
+
+    @Override
+    public ExtensionSelector mapOxm(OFOxm<?> oxm) {
+        VlanId vlanId;
+
+        if (oxm.getMatchField().equals(MatchField.VLAN_VID)) {
+            if (oxm.isMasked()) {
+                OFVlanVidMatch vid = ((OFOxmVlanVidMasked) oxm).getValue();
+                OFVlanVidMatch mask = ((OFOxmVlanVidMasked) oxm).getMask();
+
+                if (vid.equals(OFVlanVidMatch.ofRawVid((short) 0))) {
+                    vlanId = VlanId.vlanId((short) 0);
+                } else if (vid.equals(OFVlanVidMatch.PRESENT) &&
+                        mask.equals(OFVlanVidMatch.PRESENT)) {
+                    vlanId = VlanId.ANY;
+                } else {
+                    vlanId = VlanId.vlanId(vid.getVlan());
+                }
+            } else {
+                OFVlanVidMatch vid = ((OFOxmVlanVid) oxm).getValue();
+
+                if (!vid.isPresentBitSet()) {
+                    vlanId = VlanId.NONE;
+                } else {
+                    vlanId = VlanId.vlanId(vid.getVlan());
+                }
+            }
+            return new OfdpaMatchVlanVid(vlanId);
+        }
+        throw new UnsupportedOperationException(
+                "Unexpected OXM: " + oxm.toString());
+    }
+
+    @Override
+    public ExtensionSelector getExtensionSelector(ExtensionSelectorType type) {
+        if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
+            return new OfdpaMatchVlanVid();
+        }
+        throw new UnsupportedOperationException(
+                "Driver does not support extension type " + type.toString());
+    }
+}
diff --git a/drivers/default/src/main/java/org/onosproject/driver/extensions/OfdpaExtensionTreatmentInterpreter.java b/drivers/default/src/main/java/org/onosproject/driver/extensions/OfdpaExtensionTreatmentInterpreter.java
new file mode 100644
index 0000000..45e6beb
--- /dev/null
+++ b/drivers/default/src/main/java/org/onosproject/driver/extensions/OfdpaExtensionTreatmentInterpreter.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.driver.extensions;
+
+import org.onlab.packet.VlanId;
+import org.onosproject.net.behaviour.ExtensionTreatmentResolver;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.net.flow.instructions.ExtensionTreatment;
+import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
+import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
+import org.projectfloodlight.openflow.protocol.OFActionType;
+import org.projectfloodlight.openflow.protocol.OFFactory;
+import org.projectfloodlight.openflow.protocol.action.OFAction;
+import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
+import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
+import org.projectfloodlight.openflow.protocol.oxm.OFOxmVlanVid;
+import org.projectfloodlight.openflow.types.OFVlanVidMatch;
+
+/**
+ * Interpreter for OFDPA OpenFlow treatment extensions.
+ */
+public class OfdpaExtensionTreatmentInterpreter  extends AbstractHandlerBehaviour
+        implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver {
+    @Override
+    public boolean supported(ExtensionTreatmentType extensionTreatmentType) {
+        if (extensionTreatmentType.equals(
+                ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) {
+        ExtensionTreatmentType type = extensionTreatment.type();
+        if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) {
+            VlanId vlanId = ((OfdpaSetVlanVid) extensionTreatment).vlanId();
+            // NOTE: OFDPA requires isPresent bit set to zero.
+            OFVlanVidMatch match = OFVlanVidMatch.ofRawVid(vlanId.toShort());
+            return factory.actions().setField(factory.oxms().vlanVid(match));
+        }
+        throw new UnsupportedOperationException(
+                "Unexpected ExtensionTreatment: " + extensionTreatment.toString());
+    }
+
+    @Override
+    public ExtensionTreatment mapAction(OFAction action) {
+        if (action.getType().equals(OFActionType.SET_FIELD)) {
+            OFActionSetField setFieldAction = (OFActionSetField) action;
+            OFOxm<?> oxm = setFieldAction.getField();
+            switch (oxm.getMatchField().id) {
+                case VLAN_VID:
+                    OFOxmVlanVid vlanVid = (OFOxmVlanVid) oxm;
+                    return new OfdpaSetVlanVid(VlanId.vlanId(vlanVid.getValue().getRawVid()));
+                default:
+                    throw new UnsupportedOperationException(
+                            "Driver does not support extension type " + oxm.getMatchField().id);
+            }
+        }
+        throw new UnsupportedOperationException(
+                "Unexpected OFAction: " + action.toString());
+    }
+
+    @Override
+    public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) {
+        if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) {
+            return new OfdpaSetVlanVid();
+        }
+        throw new UnsupportedOperationException(
+                "Driver does not support extension type " + type.toString());
+    }
+}
diff --git a/drivers/default/src/main/java/org/onosproject/driver/extensions/OfdpaMatchVlanVid.java b/drivers/default/src/main/java/org/onosproject/driver/extensions/OfdpaMatchVlanVid.java
new file mode 100644
index 0000000..0c3b7fa
--- /dev/null
+++ b/drivers/default/src/main/java/org/onosproject/driver/extensions/OfdpaMatchVlanVid.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.driver.extensions;
+
+import com.google.common.base.MoreObjects;
+import org.onlab.packet.VlanId;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.net.flow.AbstractExtension;
+import org.onosproject.net.flow.criteria.ExtensionSelector;
+import org.onosproject.net.flow.criteria.ExtensionSelectorType;
+
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * OFDPA VLAN ID extension match.
+ */
+public class OfdpaMatchVlanVid extends AbstractExtension implements ExtensionSelector {
+    private VlanId vlanId;
+
+    private static final KryoNamespace APPKRYO = new KryoNamespace.Builder()
+            .register(VlanId.class)
+            .build();
+
+    /**
+     * OFDPA VLAN ID extension match.
+     */
+    protected OfdpaMatchVlanVid() {
+        vlanId = null;
+    }
+
+    /**
+     * Constructs a new VLAN ID match with given VLAN ID.
+     *
+     * @param vlanId VLAN ID
+     */
+    public OfdpaMatchVlanVid(VlanId vlanId) {
+        checkNotNull(vlanId);
+        this.vlanId = vlanId;
+    }
+
+    /**
+     * Gets the VLAN ID.
+     *
+     * @return VLAN ID
+     */
+    public VlanId vlanId() {
+        return vlanId;
+    }
+
+    @Override
+    public ExtensionSelectorType type() {
+        return ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type();
+    }
+
+    @Override
+    public void deserialize(byte[] data) {
+        vlanId = APPKRYO.deserialize(data);
+    }
+
+    @Override
+    public byte[] serialize() {
+        return APPKRYO.serialize(vlanId);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(vlanId);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof OfdpaMatchVlanVid) {
+            OfdpaMatchVlanVid that = (OfdpaMatchVlanVid) obj;
+            return Objects.equals(vlanId, that.vlanId);
+
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(getClass())
+                .add("vlanId", vlanId)
+                .toString();
+    }
+}
diff --git a/drivers/default/src/main/java/org/onosproject/driver/extensions/OfdpaSetVlanVid.java b/drivers/default/src/main/java/org/onosproject/driver/extensions/OfdpaSetVlanVid.java
new file mode 100644
index 0000000..f9693c4
--- /dev/null
+++ b/drivers/default/src/main/java/org/onosproject/driver/extensions/OfdpaSetVlanVid.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.driver.extensions;
+
+import com.google.common.base.MoreObjects;
+import org.onlab.packet.VlanId;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.net.flow.AbstractExtension;
+import org.onosproject.net.flow.instructions.ExtensionTreatment;
+import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
+
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * OFDPA set VLAN ID extension instruction.
+ */
+public class OfdpaSetVlanVid extends AbstractExtension implements ExtensionTreatment {
+    private VlanId vlanId;
+
+    private static final KryoNamespace APPKRYO = new KryoNamespace.Builder()
+            .register(VlanId.class)
+            .build();
+
+    /**
+     * Constructs a new set VLAN ID instruction.
+     */
+    protected OfdpaSetVlanVid() {
+        vlanId = null;
+    }
+
+    /**
+     * Constructs a new set VLAN ID instruction with given VLAN ID.
+     *
+     * @param vlanId VLAN ID
+     */
+    public OfdpaSetVlanVid(VlanId vlanId) {
+        checkNotNull(vlanId);
+        this.vlanId = vlanId;
+    }
+
+    /**
+     * Gets the VLAN ID.
+     *
+     * @return VLAN ID
+     */
+    public VlanId vlanId() {
+        return vlanId;
+    }
+
+    @Override
+    public ExtensionTreatmentType type() {
+        return ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type();
+    }
+
+    @Override
+    public void deserialize(byte[] data) {
+        vlanId = APPKRYO.deserialize(data);
+    }
+
+    @Override
+    public byte[] serialize() {
+        return APPKRYO.serialize(vlanId);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(vlanId);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof OfdpaSetVlanVid) {
+            OfdpaSetVlanVid that = (OfdpaSetVlanVid) obj;
+            return Objects.equals(vlanId, that.vlanId);
+
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(getClass())
+                .add("vlanId", vlanId)
+                .toString();
+    }
+}