[ONOS-2860] ONOSFW L3 uses ARP table as arp proxy. It need modify ARP
request packet to response packet. OpenFlow protocol provides some
extension action to support it. e.g. move and load. But for now OpenFlow
java implementation doesn't support for them.

Change-Id: I30506f9230bb7ec75952893fdb07d15a866b877d
diff --git a/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatmentType.java b/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatmentType.java
index 1ba5897..f597a46 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatmentType.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatmentType.java
@@ -40,7 +40,11 @@
         NICIRA_SET_NSH_CH1(34),
         NICIRA_SET_NSH_CH2(35),
         NICIRA_SET_NSH_CH3(36),
-        NICIRA_SET_NSH_CH4(37);
+        NICIRA_SET_NSH_CH4(37),
+        NICIRA_MOV_ARP_SHA_TO_THA(2),
+        NICIRA_MOV_ARP_SPA_TO_TPA(3),
+        NICIRA_MOV_ETH_SRC_TO_DST(4),
+        NICIRA_MOV_IP_SRC_TO_DST(5);
 
         private ExtensionTreatmentType type;
 
diff --git a/drivers/src/main/java/org/onosproject/driver/extensions/DefaultMoveExtensionTreatment.java b/drivers/src/main/java/org/onosproject/driver/extensions/DefaultMoveExtensionTreatment.java
new file mode 100644
index 0000000..f0840c8
--- /dev/null
+++ b/drivers/src/main/java/org/onosproject/driver/extensions/DefaultMoveExtensionTreatment.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2015 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 java.util.Map;
+import java.util.Objects;
+
+import org.onlab.util.KryoNamespace;
+import org.onosproject.net.flow.AbstractExtension;
+import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.Maps;
+
+/**
+ * Default implementation of Move treatment.
+ */
+public class DefaultMoveExtensionTreatment extends AbstractExtension
+        implements MoveExtensionTreatment {
+
+    private int srcOfs;
+    private int dstOfs;
+    private int nBits;
+    private int src;
+    private int dst;
+    private ExtensionTreatmentType type;
+
+    private final KryoNamespace appKryo = new KryoNamespace.Builder()
+            .register(byte[].class).register(Integer.class).register(Map.class)
+            .build();
+
+    /**
+     * Creates a new move Treatment.
+     *
+     * @param srcOfs source offset
+     * @param dstOfs destination offset
+     * @param nBits nbits
+     * @param src source
+     * @param dst destination
+     */
+    public DefaultMoveExtensionTreatment(int srcOfs, int dstOfs, int nBits,
+                                         int src, int dst, ExtensionTreatmentType type) {
+        this.srcOfs = srcOfs;
+        this.dstOfs = dstOfs;
+        this.nBits = nBits;
+        this.src = src;
+        this.dst = dst;
+        this.type = type;
+    }
+
+    @Override
+    public ExtensionTreatmentType type() {
+        return type;
+    }
+
+    @Override
+    public byte[] serialize() {
+        Map<String, Integer> values = Maps.newHashMap();
+        values.put("srcOfs", srcOfs);
+        values.put("dstOfs", dstOfs);
+        values.put("nBits", nBits);
+        values.put("src", src);
+        values.put("dst", dst);
+        values.put("type", ExtensionTreatmentType.ExtensionTreatmentTypes.valueOf(type.toString()).ordinal());
+        return appKryo.serialize(values);
+    }
+
+    @Override
+    public void deserialize(byte[] data) {
+        Map<String, Integer> values = appKryo.deserialize(data);
+        srcOfs = values.get("srcOfs");
+        dstOfs = values.get("dstOfs");
+        nBits = values.get("nBits");
+        src = values.get("src");
+        dst = values.get("dst");
+        type = new ExtensionTreatmentType(values.get("type").intValue());
+    }
+
+    @Override
+    public int srcOffset() {
+        return srcOfs;
+    }
+
+    @Override
+    public int dstOffset() {
+        return dstOfs;
+    }
+
+    @Override
+    public int src() {
+        return src;
+    }
+
+    @Override
+    public int dst() {
+        return dst;
+    }
+
+    @Override
+    public int nBits() {
+        return nBits;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(srcOfs, dstOfs, src, dst, nBits);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof DefaultMoveExtensionTreatment) {
+            DefaultMoveExtensionTreatment that = (DefaultMoveExtensionTreatment) obj;
+            return Objects.equals(srcOfs, that.srcOfs)
+                    && Objects.equals(dstOfs, that.dstOfs)
+                    && Objects.equals(src, that.src)
+                    && Objects.equals(dst, that.dst)
+                    && Objects.equals(nBits, that.nBits);
+
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(getClass()).add("srcOfs", srcOfs)
+                .add("dstOfs", dstOfs).add("nBits", nBits).add("src", src)
+                .add("dst", dst).toString();
+    }
+}
diff --git a/drivers/src/main/java/org/onosproject/driver/extensions/MoveExtensionTreatment.java b/drivers/src/main/java/org/onosproject/driver/extensions/MoveExtensionTreatment.java
new file mode 100644
index 0000000..b67e1be
--- /dev/null
+++ b/drivers/src/main/java/org/onosproject/driver/extensions/MoveExtensionTreatment.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2015 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.onosproject.net.flow.instructions.ExtensionTreatment;
+
+/**
+ * The abstraction of Move Treatment.
+ */
+public interface MoveExtensionTreatment extends ExtensionTreatment {
+
+    /**
+     * Returns SRC_OFS field of move extension action.
+     *
+     * @return SRC_OFS
+     */
+    int srcOffset();
+
+    /**
+     * Returns DST_OFS field of move extension action.
+     *
+     * @return DST_OFS
+     */
+    int dstOffset();
+
+    /**
+     * Returns SRC field of move extension action.
+     *
+     * @return SRC
+     */
+    int src();
+
+    /**
+     * Returns DST field of move extension action.
+     *
+     * @return DST
+     */
+    int dst();
+
+    /**
+     * Returns N_BITS field of move extension action.
+     *
+     * @return N_BITS
+     */
+    int nBits();
+}
diff --git a/drivers/src/main/java/org/onosproject/driver/extensions/NiciraExtensionTreatmentInterpreter.java b/drivers/src/main/java/org/onosproject/driver/extensions/NiciraExtensionTreatmentInterpreter.java
index bfca861..5e374d9 100644
--- a/drivers/src/main/java/org/onosproject/driver/extensions/NiciraExtensionTreatmentInterpreter.java
+++ b/drivers/src/main/java/org/onosproject/driver/extensions/NiciraExtensionTreatmentInterpreter.java
@@ -68,6 +68,22 @@
                 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
             return true;
         }
+        if (extensionTreatmentType.equals(
+                ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) {
+            return true;
+        }
+        if (extensionTreatmentType.equals(
+                ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) {
+            return true;
+        }
+        if (extensionTreatmentType.equals(
+                ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) {
+            return true;
+        }
+        if (extensionTreatmentType.equals(
+                ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
+            return true;
+        }
         return false;
     }
 
@@ -103,6 +119,12 @@
         if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
             // TODO this will be implemented later
         }
+        if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())
+                || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())
+                || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())
+                || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
+           // TODO this will be implemented later
+        }
         return null;
     }
 
@@ -146,6 +168,18 @@
                 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
             return new NiciraSetNshContextHeader(type);
         }
+        if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) {
+            return NiciraMoveTreatmentFactory.createNiciraMovArpShaToTha();
+        }
+        if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) {
+            return NiciraMoveTreatmentFactory.createNiciraMovArpSpaToTpa();
+        }
+        if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) {
+            return NiciraMoveTreatmentFactory.createNiciraMovEthSrcToDst();
+        }
+        if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
+            return NiciraMoveTreatmentFactory.createNiciraMovIpSrcToDst();
+        }
         throw new UnsupportedOperationException(
                 "Driver does not support extension type " + type.toString());
     }
diff --git a/drivers/src/main/java/org/onosproject/driver/extensions/NiciraMoveTreatmentFactory.java b/drivers/src/main/java/org/onosproject/driver/extensions/NiciraMoveTreatmentFactory.java
new file mode 100644
index 0000000..ac42a3b
--- /dev/null
+++ b/drivers/src/main/java/org/onosproject/driver/extensions/NiciraMoveTreatmentFactory.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2015 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.onosproject.net.flow.instructions.ExtensionTreatment;
+import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
+
+/**
+ * The factory of move treatment.
+ */
+public final class NiciraMoveTreatmentFactory {
+
+    /**
+     * Public constructor is prohibited.
+     */
+    private NiciraMoveTreatmentFactory() {
+
+    }
+
+    /**
+     * Creates a move treatment that move arp sha to tha.
+     *
+     * @return ExtensionTreatment
+     */
+    public static ExtensionTreatment createNiciraMovArpShaToTha() {
+        int srcOfs = 0;
+        int dstOfs = 0;
+        int nBits = 48;
+        int srcSha = 0x00012206;
+        int dstTha = 0x00012406;
+        return new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, srcSha,
+                                                 dstTha,
+                                                 ExtensionTreatmentType.ExtensionTreatmentTypes
+                                                 .NICIRA_MOV_ARP_SHA_TO_THA.type());
+    }
+
+    /**
+     * Creates a move treatment that move arp spa to tpa.
+     *
+     * @return ExtensionTreatment
+     */
+    public static ExtensionTreatment createNiciraMovArpSpaToTpa() {
+        int srcOfs = 0;
+        int dstOfs = 0;
+        int nBits = 32;
+        int srcSpa = 0x00002004;
+        int dstTpa = 0x00002204;
+        return new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, srcSpa,
+                                                 dstTpa,
+                                                 ExtensionTreatmentType.ExtensionTreatmentTypes
+                                                 .NICIRA_MOV_ARP_SPA_TO_TPA.type());
+    }
+
+    /**
+     * Creates a move treatment that move eth src to dst.
+     *
+     * @return ExtensionTreatment
+     */
+    public static ExtensionTreatment createNiciraMovEthSrcToDst() {
+        int srcOfs = 0;
+        int dstOfs = 0;
+        int nBits = 48;
+        int srcEth = 0x00000406;
+        int dstEth = 0x00000206;
+        return new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, srcEth,
+                                                 dstEth,
+                                                 ExtensionTreatmentType.ExtensionTreatmentTypes
+                                                 .NICIRA_MOV_ETH_SRC_TO_DST.type());
+    }
+
+    /**
+     * Creates a move treatment that move ip src to dst.
+     *
+     * @return ExtensionTreatment
+     */
+    public static ExtensionTreatment createNiciraMovIpSrcToDst() {
+        int srcOfs = 0;
+        int dstOfs = 0;
+        int nBits = 32;
+        int srcIp = 0x00000e04;
+        int dstIp = 0x00001006;
+        return new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, srcIp,
+                                                 dstIp,
+                                                 ExtensionTreatmentType.ExtensionTreatmentTypes
+                                                 .NICIRA_MOV_IP_SRC_TO_DST.type());
+    }
+}