TUNNEL_ID field support in flow matching and actions

Change-Id: I886123a7c8d57dc4a3e12727ec8a9be4920da79e
diff --git a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowEntryBuilder.java b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowEntryBuilder.java
index 4605564..6760462 100644
--- a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowEntryBuilder.java
+++ b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowEntryBuilder.java
@@ -72,6 +72,7 @@
 import org.projectfloodlight.openflow.types.Masked;
 import org.projectfloodlight.openflow.types.OFVlanVidMatch;
 import org.projectfloodlight.openflow.types.U32;
+import org.projectfloodlight.openflow.types.U64;
 import org.projectfloodlight.openflow.types.U8;
 import org.projectfloodlight.openflow.types.VlanPcp;
 import org.slf4j.Logger;
@@ -402,6 +403,11 @@
             OFOxm<U32> labelId = (OFOxm<U32>) oxm;
             builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
             break;
+        case TUNNEL_ID:
+            @SuppressWarnings("unchecked")
+            OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
+            builder.setTunnelId(tunnelId.getValue().getValue());
+            break;
         case ARP_OP:
         case ARP_SHA:
         case ARP_SPA:
@@ -451,7 +457,6 @@
         case SCTP_SRC:
         case TCP_DST:
         case TCP_SRC:
-        case TUNNEL_ID:
         case UDP_DST:
         case UDP_SRC:
         default:
@@ -640,7 +645,7 @@
                 break;
             case IPV6_EXTHDR:
                 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
-                                            .getValue());
+                        .getValue());
                 break;
             case OCH_SIGID:
                 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
@@ -653,13 +658,16 @@
                 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
                 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
                 break;
+            case TUNNEL_ID:
+                long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
+                builder.matchTunnelId(tunnelId);
+                break;
             case ARP_OP:
             case ARP_SHA:
             case ARP_SPA:
             case ARP_THA:
             case ARP_TPA:
             case MPLS_TC:
-            case TUNNEL_ID:
             default:
                 log.warn("Match type {} not yet implemented.", field.id);
             }
diff --git a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilder.java b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilder.java
index d34fd5e..d9d02ff 100644
--- a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilder.java
+++ b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilder.java
@@ -44,6 +44,7 @@
 import org.onosproject.net.flow.criteria.PortCriterion;
 import org.onosproject.net.flow.criteria.SctpPortCriterion;
 import org.onosproject.net.flow.criteria.TcpPortCriterion;
+import org.onosproject.net.flow.criteria.TunnelIdCriterion;
 import org.onosproject.net.flow.criteria.UdpPortCriterion;
 import org.onosproject.net.flow.criteria.VlanIdCriterion;
 import org.onosproject.net.flow.criteria.VlanPcpCriterion;
@@ -72,6 +73,7 @@
 import org.projectfloodlight.openflow.types.TransportPort;
 import org.projectfloodlight.openflow.types.U16;
 import org.projectfloodlight.openflow.types.U32;
+import org.projectfloodlight.openflow.types.U64;
 import org.projectfloodlight.openflow.types.U8;
 import org.projectfloodlight.openflow.types.VlanPcp;
 import org.projectfloodlight.openflow.types.VlanVid;
@@ -392,6 +394,11 @@
                 byte signalType = OpenFlowValueMapper.lookupOchSignalType(sc.signalType());
                 mBuilder.setExact(MatchField.OCH_SIGTYPE, U8.of(signalType));
                 break;
+            case TUNNEL_ID:
+                TunnelIdCriterion tunnelId = (TunnelIdCriterion) c;
+                mBuilder.setExact(MatchField.TUNNEL_ID,
+                                  U64.of(tunnelId.tunnelId()));
+                break;
             case ARP_OP:
             case ARP_SHA:
             case ARP_SPA:
@@ -400,7 +407,6 @@
             case MPLS_BOS:
             case MPLS_TC:
             case PBB_ISID:
-            case TUNNEL_ID:
             default:
                 log.warn("Match type {} not yet implemented.", c.type());
             }
diff --git a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer13.java b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer13.java
index 63fc63a..7bbc375 100644
--- a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer13.java
+++ b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer13.java
@@ -35,6 +35,7 @@
 import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction;
 import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction;
 import org.onosproject.net.flow.instructions.L2ModificationInstruction.PushHeaderInstructions;
+import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction;
 import org.onosproject.net.flow.instructions.L3ModificationInstruction;
 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
@@ -336,6 +337,10 @@
                 PushHeaderInstructions pushVlanInstruction = (PushHeaderInstructions) l2m;
                 return factory().actions().pushVlan(
                         EthType.of(pushVlanInstruction.ethernetType().toShort()));
+            case TUNNEL_ID:
+                ModTunnelIdInstruction tunnelId = (ModTunnelIdInstruction) l2m;
+                oxm = factory().oxms().tunnelId(U64.of(tunnelId.tunnelId()));
+                break;
             default:
                 log.warn("Unimplemented action type {}.", l2m.subtype());
                 break;