ONOS-537 Provided maxLen setting to make sure packet data is sent with packet-in message. Also added support for TrafficTreatment.Builder.punt();

Change-Id: I9f5577cf83b4d25c79459e56492be747a245397c
diff --git a/core/api/src/main/java/org/onosproject/net/PortNumber.java b/core/api/src/main/java/org/onosproject/net/PortNumber.java
index e2db835..d508771 100644
--- a/core/api/src/main/java/org/onosproject/net/PortNumber.java
+++ b/core/api/src/main/java/org/onosproject/net/PortNumber.java
@@ -37,6 +37,7 @@
     public static final PortNumber FLOOD = new PortNumber(-5);
     public static final PortNumber ALL = new PortNumber(-4);
     public static final PortNumber LOCAL = new PortNumber(-2);
+    public static final PortNumber CONTROLLER = new PortNumber(-3);
 
     private final long number;
 
diff --git a/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java b/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
index d3dcca0..638f00d 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
@@ -15,19 +15,18 @@
  */
 package org.onosproject.net.flow;
 
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Objects;
-
-import org.onosproject.net.PortNumber;
-import org.onosproject.net.flow.instructions.Instruction;
-import org.onosproject.net.flow.instructions.Instructions;
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableList;
 import org.onlab.packet.IpAddress;
 import org.onlab.packet.MacAddress;
 import org.onlab.packet.VlanId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.flow.instructions.Instruction;
+import org.onosproject.net.flow.instructions.Instructions;
 
-import com.google.common.base.MoreObjects;
-import com.google.common.collect.ImmutableList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
 
 /**
  * Default traffic treatment implementation.
@@ -152,8 +151,13 @@
         }
 
         @Override
-        public void drop() {
-            add(Instructions.createDrop());
+        public Builder drop() {
+            return add(Instructions.createDrop());
+        }
+
+        @Override
+        public Builder punt() {
+            return add(Instructions.createOutput(PortNumber.CONTROLLER));
         }
 
         @Override
diff --git a/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java b/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
index 281dc86..e7eb85d 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
@@ -49,9 +49,18 @@
         Builder add(Instruction instruction);
 
         /**
-         * Adds a drop instruction and does not return a builder.
+         * Adds a drop instruction.
+         *
+         * @return a treatment builder
          */
-        public void drop();
+        public Builder drop();
+
+        /**
+         * Adds a punt-to-controller instruction.
+         *
+         * @return a treatment builder
+         */
+        public Builder punt();
 
         /**
          * Set the output port.
@@ -111,18 +120,21 @@
 
         /**
          * Push MPLS ether type.
+         *
          * @return a treatment builder.
          */
         public Builder pushMpls();
 
         /**
          * Pops MPLS ether type.
+         *
          * @return a treatment builder.
          */
         public Builder popMpls();
 
         /**
          * Sets the mpls label.
+         *
          * @param mplsLabel MPLS label.
          * @return a treatment builder.
          */
diff --git a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer10.java b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer10.java
index 4df3e83..f29fe79 100644
--- a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer10.java
+++ b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer10.java
@@ -15,11 +15,8 @@
  */
 package org.onosproject.provider.of.flow.impl;
 
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Optional;
-
+import org.onlab.packet.Ip4Address;
+import org.onosproject.net.PortNumber;
 import org.onosproject.net.flow.FlowRule;
 import org.onosproject.net.flow.TrafficTreatment;
 import org.onosproject.net.flow.instructions.Instruction;
@@ -30,13 +27,13 @@
 import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction;
 import org.onosproject.net.flow.instructions.L3ModificationInstruction;
 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
-import org.onlab.packet.Ip4Address;
 import org.projectfloodlight.openflow.protocol.OFFactory;
 import org.projectfloodlight.openflow.protocol.OFFlowAdd;
 import org.projectfloodlight.openflow.protocol.OFFlowDelete;
 import org.projectfloodlight.openflow.protocol.OFFlowMod;
 import org.projectfloodlight.openflow.protocol.OFFlowModFlags;
 import org.projectfloodlight.openflow.protocol.action.OFAction;
+import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
 import org.projectfloodlight.openflow.protocol.match.Match;
 import org.projectfloodlight.openflow.types.IPv4Address;
 import org.projectfloodlight.openflow.types.MacAddress;
@@ -48,12 +45,18 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Optional;
+
 /**
  * Flow mod builder for OpenFlow 1.0.
  */
 public class FlowModBuilderVer10 extends FlowModBuilder {
 
     private static final Logger log = LoggerFactory.getLogger(FlowModBuilderVer10.class);
+    private static final int OFPCML_NO_BUFFER = 0xffff;
 
     private final TrafficTreatment treatment;
 
@@ -151,8 +154,12 @@
                 break;
             case OUTPUT:
                 OutputInstruction out = (OutputInstruction) i;
-                acts.add(factory().actions().buildOutput().setPort(
-                        OFPort.of((int) out.port().toLong())).build());
+                OFActionOutput.Builder action = factory().actions().buildOutput()
+                        .setPort(OFPort.of((int) out.port().toLong()));
+                if (out.port().equals(PortNumber.CONTROLLER)) {
+                    action.setMaxLen(OFPCML_NO_BUFFER);
+                }
+                acts.add(action.build());
                 break;
             case L0MODIFICATION:
             case GROUP: