Added some useful flow-mod utilities including extensions from other projects into... 91/9891/1
authorMadhu Venugopal <mavenugo@gmail.com>
Tue, 12 Aug 2014 16:31:55 +0000 (09:31 -0700)
committerMadhu Venugopal <mavenugo@gmail.com>
Tue, 12 Aug 2014 16:31:55 +0000 (09:31 -0700)
Change-Id: I465deba06ebf5068aec69bfc643f45a3c97f570a
Signed-off-by: Madhu Venugopal <mavenugo@gmail.com>
openstack/net-virt-providers/pom.xml
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/mdsalopenflow13/OF13MdSalAction.java [new file with mode: 0644]
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/mdsalopenflow13/OF13MdSalInstruction.java
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/mdsalopenflow13/OF13MdSalMatch.java

index 3e137ffbb715d9675929df737c9bdc83ef48619d..d37ec9f111bf76dc9aee2175d8ec6f477dbc710b 100644 (file)
             <groupId>org.opendaylight.ovsdb</groupId>
             <artifactId>openstack.net-virt</artifactId>
         </dependency>
+    <dependency>
+      <groupId>org.opendaylight.openflowplugin</groupId>
+      <artifactId>openflowplugin-extension-nicira</artifactId>
+      <version>${openflowplugin-nicira.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.ovsdb</groupId>
+      <artifactId>of-extension.nx-sal</artifactId>
+      <version>1.0.0-SNAPSHOT</version>
+    </dependency>
+
     </dependencies>
 
     <build>
diff --git a/openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/mdsalopenflow13/OF13MdSalAction.java b/openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/mdsalopenflow13/OF13MdSalAction.java
new file mode 100644 (file)
index 0000000..09f2c5c
--- /dev/null
@@ -0,0 +1,258 @@
+package org.opendaylight.ovsdb.openstack.netvirt.providers.mdsalopenflow13;
+
+import java.math.BigInteger;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.dst.action._case.SetDlDstActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.DstChoice;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxArpShaCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxArpThaCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxRegCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIdCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIpv4DstCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfArpOpCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfArpSpaCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfArpTpaCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstOfEthDstCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.group.buckets.bucket.action.action.NxActionRegLoadNodesNodeGroupBucketsBucketActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.group.buckets.bucket.action.action.NxActionRegMoveNodesNodeGroupBucketsBucketActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionOutputRegNodesNodeTableFlowApplyActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionRegLoadNodesNodeTableFlowApplyActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionRegMoveNodesNodeTableFlowApplyActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.output.reg.grouping.NxOutputReg;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.output.reg.grouping.NxOutputRegBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.NxRegLoad;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.NxRegLoadBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.nx.reg.load.DstBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.NxRegMove;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.NxRegMoveBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.SrcBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.SrcChoice;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxArpShaCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxRegCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfArpSpaCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcOfEthSrcCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.ovs.nx.sal.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionResubmitNodesNodeTableFlowApplyActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.ovs.nx.sal.action.rev140714.nx.action.resubmit.grouping.NxResubmit;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.ovs.nx.sal.action.rev140714.nx.action.resubmit.grouping.NxResubmitBuilder;
+
+import com.google.common.net.InetAddresses;
+
+public final class OF13MdSalAction {
+    public static Action dropAction() {
+        return new DropActionCaseBuilder()
+            .setDropAction(new DropActionBuilder()
+                .build())
+            .build();
+    }
+
+    public static Action outputAction(NodeConnectorId id) {
+        return new OutputActionCaseBuilder()
+            .setOutputAction(new OutputActionBuilder()
+                .setOutputNodeConnector(new Uri(id.getValue()))
+                .build())
+            .build();
+    }
+
+    public static Action groupAction(Long id) {
+        return new GroupActionCaseBuilder()
+            .setGroupAction(new GroupActionBuilder()
+                .setGroupId(id)
+                .build())
+            .build();
+    }
+
+    public static Action setDlSrcAction(MacAddress mac) {
+        return new SetDlSrcActionCaseBuilder()
+            .setSetDlSrcAction(new SetDlSrcActionBuilder()
+                .setAddress(mac)
+                .build())
+            .build();
+    }
+
+    public static Action setDlDstAction(MacAddress mac) {
+        return new SetDlDstActionCaseBuilder()
+            .setSetDlDstAction(new SetDlDstActionBuilder()
+                .setAddress(mac)
+                .build())
+            .build();
+    }
+
+    public static Action decNwTtlAction() {
+        return new DecNwTtlCaseBuilder()
+            .setDecNwTtl(new DecNwTtlBuilder()
+                .build())
+            .build();
+    }
+
+    public static Action nxLoadRegAction(DstChoice dstChoice,
+                                         BigInteger value,
+                                         int endOffset,
+                                         boolean groupBucket) {
+        NxRegLoad r = new NxRegLoadBuilder()
+            .setDst(new DstBuilder()
+                .setDstChoice(dstChoice)
+                .setStart(Integer.valueOf(0))
+                .setEnd(Integer.valueOf(endOffset))
+                .build())
+            .setValue(value)
+            .build();
+        if (groupBucket) {
+            return new NxActionRegLoadNodesNodeGroupBucketsBucketActionsCaseBuilder()
+                .setNxRegLoad(r).build();
+        } else {
+            return new NxActionRegLoadNodesNodeTableFlowApplyActionsCaseBuilder()
+                .setNxRegLoad(r).build();
+        }
+    }
+
+    public static Action nxLoadRegAction(DstChoice dstChoice,
+                                         BigInteger value) {
+        return nxLoadRegAction(dstChoice, value, 31, false);
+    }
+
+    public static Action nxLoadRegAction(Class<? extends NxmNxReg> reg,
+                                         BigInteger value) {
+        return nxLoadRegAction(new DstNxRegCaseBuilder().setNxReg(reg).build(),
+                               value);
+    }
+
+    public static Action nxLoadTunIPv4Action(String ipAddress,
+                                             boolean groupBucket) {
+        int ip = InetAddresses.coerceToInteger(InetAddresses.forString(ipAddress));
+        long ipl = ip & 0xffffffffL;
+        return nxLoadRegAction(new DstNxTunIpv4DstCaseBuilder()
+                                    .setNxTunIpv4Dst(Boolean.TRUE).build(),
+                               BigInteger.valueOf(ipl),
+                               31,
+                               groupBucket);
+    }
+
+    public static Action nxLoadArpOpAction(BigInteger value) {
+        return nxLoadRegAction(new DstOfArpOpCaseBuilder()
+            .setOfArpOp(Boolean.TRUE).build(), value, 15, false);
+    }
+
+    public static Action nxLoadArpShaAction(BigInteger value) {
+        return nxLoadRegAction(new DstNxArpShaCaseBuilder()
+            .setNxArpSha(Boolean.TRUE).build(), value, 47, false);
+    }
+
+    public static Action nxLoadArpSpaAction(BigInteger value) {
+        return nxLoadRegAction(new DstOfArpSpaCaseBuilder()
+            .setOfArpSpa(Boolean.TRUE).build(), value);
+    }
+
+    public static Action nxLoadArpSpaAction(String ipAddress) {
+        int ip = InetAddresses.coerceToInteger(InetAddresses.forString(ipAddress));
+        long ipl = ip & 0xffffffffL;
+        return nxLoadArpSpaAction(BigInteger.valueOf(ipl));
+    }
+
+    public static Action nxMoveRegAction(SrcChoice srcChoice,
+                                         DstChoice dstChoice,
+                                         int endOffset,
+                                         boolean groupBucket) {
+        NxRegMove r = new NxRegMoveBuilder()
+            .setSrc(new SrcBuilder()
+                .setSrcChoice(srcChoice)
+                .setStart(Integer.valueOf(0))
+                .setEnd(Integer.valueOf(endOffset))
+                .build())
+            .setDst(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.DstBuilder()
+                .setDstChoice(dstChoice)
+                .setStart(Integer.valueOf(0))
+                .setEnd(Integer.valueOf(endOffset))
+                .build())
+            .build();
+        if (groupBucket) {
+            return new NxActionRegMoveNodesNodeGroupBucketsBucketActionsCaseBuilder()
+                .setNxRegMove(r).build();
+        } else {
+            return new NxActionRegMoveNodesNodeTableFlowApplyActionsCaseBuilder()
+                .setNxRegMove(r).build();
+        }
+    }
+
+    public static Action nxMoveRegAction(SrcChoice srcChoice,
+                                         DstChoice dstChoice) {
+        return nxMoveRegAction(srcChoice, dstChoice, 31, false);
+    }
+
+    public static Action nxMoveRegTunIdAction(Class<? extends NxmNxReg> src,
+                                              boolean groupBucket) {
+        return nxMoveRegAction(new SrcNxRegCaseBuilder()
+                                    .setNxReg(src).build(),
+                               new DstNxTunIdCaseBuilder()
+                                   .setNxTunId(Boolean.TRUE).build(),
+                               31,
+                               groupBucket);
+    }
+
+    public static Action nxMoveArpShaToArpThaAction() {
+        return nxMoveRegAction(new SrcNxArpShaCaseBuilder()
+                                   .setNxArpSha(Boolean.TRUE).build(),
+                               new DstNxArpThaCaseBuilder()
+                                   .setNxArpTha(Boolean.TRUE).build(),
+                               47, false);
+    }
+
+    public static Action nxMoveEthSrcToEthDstAction() {
+        return nxMoveRegAction(new SrcOfEthSrcCaseBuilder()
+                                   .setOfEthSrc(Boolean.TRUE).build(),
+                               new DstOfEthDstCaseBuilder()
+                                   .setOfEthDst(Boolean.TRUE).build(),
+                               47, false);
+    }
+
+    public static Action nxMoveArpSpaToArpTpaAction() {
+        return nxMoveRegAction(new SrcOfArpSpaCaseBuilder()
+                                   .setOfArpSpa(Boolean.TRUE).build(),
+                               new DstOfArpTpaCaseBuilder()
+                                   .setOfArpTpa(Boolean.TRUE).build());
+    }
+
+    public static Action nxOutputRegAction(SrcChoice srcChoice) {
+        NxOutputReg r = new NxOutputRegBuilder()
+            .setSrc(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.output.reg.grouping.nx.output.reg.SrcBuilder()
+                .setSrcChoice(srcChoice)
+                .setOfsNbits(Integer.valueOf(31))
+                .build())
+            .setMaxLen(Integer.valueOf(0xffff))
+            .build();
+        return new NxActionOutputRegNodesNodeTableFlowApplyActionsCaseBuilder()
+            .setNxOutputReg(r).build();
+    }
+
+    public static Action nxOutputRegAction(Class<? extends NxmNxReg> reg) {
+        return nxOutputRegAction(new SrcNxRegCaseBuilder().setNxReg(reg).build());
+    }
+
+    public static Action nxResubmitAction(Integer inPort, Short table) {
+        NxResubmitBuilder builder = new NxResubmitBuilder();
+        if (inPort != null) {
+            builder.setInPort(inPort);
+        }
+        if (table != null) {
+            builder.setTable(table);
+        }
+        NxResubmit r = builder.build();
+        return new NxActionResubmitNodesNodeTableFlowApplyActionsCaseBuilder().setNxResubmit(r).build();
+    }
+}
+
index 41a0f8354a6730226d5094091b1aece63fc0d84d..7246e254eacc11a21379f237e65dab492e0aff82 100644 (file)
@@ -9,7 +9,12 @@
 
 package org.opendaylight.ovsdb.openstack.netvirt.providers.mdsalopenflow13;
 
-import com.google.common.collect.Lists;
+import static org.opendaylight.ovsdb.openstack.netvirt.providers.mdsalopenflow13.OF13MdSalAction.dropAction;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
@@ -39,6 +44,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.acti
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
@@ -59,9 +66,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
+import com.google.common.collect.Lists;
 
 public class OF13MdSalInstruction {
     private static final Logger logger = LoggerFactory.getLogger(OF13MdSalInstruction.class);
@@ -842,4 +847,47 @@ public class OF13MdSalInstruction {
 
         return ib;
     }
+
+    public static ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>
+                  actionList (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action... actions) {
+
+        ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> alist
+            = new ArrayList<>();
+        int count = 0;
+        for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action : actions) {
+            alist.add(new ActionBuilder()
+            .setOrder(Integer.valueOf(count++))
+            .setAction(action)
+            .build());
+        }
+        return alist;
+    }
+
+    public static org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction
+        applyActionIns(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action... actions) {
+
+        return new ApplyActionsCaseBuilder()
+            .setApplyActions(new ApplyActionsBuilder()
+                .setAction(actionList(actions))
+                .build())
+            .build();
+    }
+
+    public static Instructions getInstructions(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction... instructions) {
+        ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction> ins
+            = new ArrayList<>();
+        int order = 0;
+        for (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction i : instructions) {
+            ins.add(new InstructionBuilder()
+                .setOrder(order++)
+                .setInstruction(i)
+                .build());
+        }
+        return new InstructionsBuilder().setInstruction(ins).build();
+    }
+
+    public static Instructions dropInstructions() {
+        return getInstructions(applyActionIns(dropAction()));
+    }
+
 }
\ No newline at end of file
index e8a5d21d76edb0b0278f74b47d668ee1f39aa60a..eb39fff630ae59bc40f0cbb7bdae570952e10fd6 100644 (file)
@@ -9,6 +9,9 @@
 
 package org.opendaylight.ovsdb.openstack.netvirt.providers.mdsalopenflow13;
 
+import java.math.BigInteger;
+import java.util.ArrayList;
+
 import org.opendaylight.ovsdb.openstack.netvirt.providers.OF13Provider;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
@@ -20,6 +23,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
@@ -29,10 +33,37 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg3;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.ExtensionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg0Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg1Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg2Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg3Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg4Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg5Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg6Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg7Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIdKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.reg.grouping.NxmNxRegBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.id.grouping.NxmNxTunIdBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.math.BigInteger;
+import com.google.common.collect.ImmutableList;
 
 public class OF13MdSalMatch extends OF13Provider {
     private static final Logger logger = LoggerFactory.getLogger(OF13MdSalMatch.class);
@@ -307,4 +338,100 @@ public class OF13MdSalMatch extends OF13Provider {
         matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
         return matchBuilder;
     }
+
+
+    public static class RegMatch {
+        final Class<? extends NxmNxReg> reg;
+        final Long value;
+        public RegMatch(Class<? extends NxmNxReg> reg, Long value) {
+            super();
+            this.reg = reg;
+            this.value = value;
+        }
+        public static RegMatch of(Class<? extends NxmNxReg> reg, Long value) {
+            return new RegMatch(reg, value);
+        }
+    }
+
+    public static void addNxRegMatch(MatchBuilder match,
+                                     RegMatch... matches) {
+        ArrayList<ExtensionList> extensions = new ArrayList<>();
+        for (RegMatch rm : matches) {
+            Class<? extends ExtensionKey> key;
+            if (NxmNxReg0.class.equals(rm.reg)) {
+                key = NxmNxReg0Key.class;
+            } else if (NxmNxReg1.class.equals(rm.reg)) {
+                key = NxmNxReg1Key.class;
+            } else if (NxmNxReg2.class.equals(rm.reg)) {
+                key = NxmNxReg2Key.class;
+            } else if (NxmNxReg3.class.equals(rm.reg)) {
+                key = NxmNxReg3Key.class;
+            } else if (NxmNxReg4.class.equals(rm.reg)) {
+                key = NxmNxReg4Key.class;
+            } else if (NxmNxReg5.class.equals(rm.reg)) {
+                key = NxmNxReg5Key.class;
+            } else if (NxmNxReg6.class.equals(rm.reg)) {
+                key = NxmNxReg6Key.class;
+            } else {
+                key = NxmNxReg7Key.class;
+            }
+            NxAugMatchNodesNodeTableFlow am =
+                    new NxAugMatchNodesNodeTableFlowBuilder()
+                .setNxmNxReg(new NxmNxRegBuilder()
+                    .setReg(rm.reg)
+                    .setValue(rm.value)
+                    .build())
+                .build();
+            extensions.add(new ExtensionListBuilder()
+                .setExtensionKey(key)
+                .setExtension(new ExtensionBuilder()
+                     .addAugmentation(NxAugMatchNodesNodeTableFlow.class, am)
+                     .build())
+                .build());
+        }
+        GeneralAugMatchNodesNodeTableFlow m =
+                new GeneralAugMatchNodesNodeTableFlowBuilder()
+            .setExtensionList(extensions)
+            .build();
+        match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
+    }
+
+    public static void addNxTunIdMatch(MatchBuilder match,
+                                       int tunId) {
+        NxAugMatchNodesNodeTableFlow am =
+               new NxAugMatchNodesNodeTableFlowBuilder()
+                   .setNxmNxTunId(new NxmNxTunIdBuilder()
+                       .setValue(BigInteger.valueOf(tunId))
+                       .build())
+                   .build();
+        GeneralAugMatchNodesNodeTableFlow m =
+                new GeneralAugMatchNodesNodeTableFlowBuilder()
+            .setExtensionList(ImmutableList.of(new ExtensionListBuilder()
+                .setExtensionKey(NxmNxTunIdKey.class)
+                .setExtension(new ExtensionBuilder()
+                    .addAugmentation(NxAugMatchNodesNodeTableFlow.class, am)
+                    .build())
+                .build()))
+            .build();
+        match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
+    }
+
+    public static EthernetMatch ethernetMatch(MacAddress srcMac,
+                                              MacAddress dstMac,
+                                              Long etherType) {
+        EthernetMatchBuilder emb = new  EthernetMatchBuilder();
+        if (srcMac != null)
+            emb.setEthernetSource(new EthernetSourceBuilder()
+                .setAddress(srcMac)
+                .build());
+        if (dstMac != null)
+            emb.setEthernetDestination(new EthernetDestinationBuilder()
+                .setAddress(dstMac)
+                .build());
+        if (etherType != null)
+            emb.setEthernetType(new EthernetTypeBuilder()
+                .setType(new EtherType(etherType))
+                .build());
+        return emb.build();
+    }
 }