pretty builders

Change-Id: If03b60f97be1eba3803c6fcb328196a4a195c7e8
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficSelector.java b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficSelector.java
index 9ec49e4..8f68ea5 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficSelector.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficSelector.java
@@ -6,7 +6,12 @@
 import java.util.LinkedList;
 import java.util.List;
 
+import org.onlab.onos.net.PortNumber;
+import org.onlab.onos.net.flow.criteria.Criteria;
 import org.onlab.onos.net.flow.criteria.Criterion;
+import org.onlab.packet.IpPrefix;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
 import org.slf4j.Logger;
 
 public final class DefaultTrafficSelector implements TrafficSelector {
@@ -29,11 +34,47 @@
         private final List<Criterion> selector = new LinkedList<>();
 
         @Override
-        public TrafficSelector.Builder add(Criterion criterion) {
+        public Builder add(Criterion criterion) {
             selector.add(criterion);
             return this;
         }
 
+        public Builder matchInport(PortNumber port) {
+            return add(Criteria.matchInPort(port));
+        }
+
+        public Builder matchEthSrc(MacAddress addr) {
+            return add(Criteria.matchEthSrc(addr));
+        }
+
+        public Builder matchEthDst(MacAddress addr) {
+            return add(Criteria.matchEthDst(addr));
+        }
+
+        public Builder matchEthType(short ethType) {
+            return add(Criteria.matchEthType(ethType));
+        }
+
+        public Builder matchVlanId(VlanId vlanId) {
+            return add(Criteria.matchVlanId(vlanId));
+        }
+
+        public Builder matchVlanPcp(Byte vlanPcp) {
+            return add(Criteria.matchVlanPcp(vlanPcp));
+        }
+
+        public Builder matchIPProtocol(Byte proto) {
+            return add(Criteria.matchIPProtocol(proto));
+        }
+
+        public Builder matchIPSrc(IpPrefix ip) {
+            return add(Criteria.matchIPSrc(ip));
+        }
+
+        public Builder matchIPDst(IpPrefix ip) {
+            return add(Criteria.matchIPDst(ip));
+        }
+
         @Override
         public TrafficSelector build() {
             return new DefaultTrafficSelector(selector);
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficTreatment.java b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficTreatment.java
index 9de68dc..2ce233f 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficTreatment.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficTreatment.java
@@ -6,7 +6,12 @@
 import java.util.LinkedList;
 import java.util.List;
 
+import org.onlab.onos.net.PortNumber;
 import org.onlab.onos.net.flow.instructions.Instruction;
+import org.onlab.onos.net.flow.instructions.Instructions;
+import org.onlab.packet.IpPrefix;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
 import org.slf4j.Logger;
 
 public final class DefaultTrafficTreatment implements TrafficTreatment {
@@ -42,9 +47,10 @@
         // TODO: should be a list of instructions based on modification objects
         List<Instruction> modifications = new LinkedList<>();
 
-
-        @Override
         public Builder add(Instruction instruction) {
+            if (drop) {
+                return this;
+            }
             switch (instruction.type()) {
             case DROP:
                 drop = true;
@@ -67,6 +73,46 @@
         }
 
         @Override
+        public void drop() {
+            add(Instructions.createDrop());
+        }
+
+        @Override
+        public Builder setOutput(PortNumber number) {
+            return add(Instructions.createOutput(number));
+        }
+
+        @Override
+        public Builder setEthSrc(MacAddress addr) {
+            return add(Instructions.modL2Src(addr));
+        }
+
+        @Override
+        public Builder setEthDst(MacAddress addr) {
+            return add(Instructions.modL2Dst(addr));
+        }
+
+        @Override
+        public Builder setVlanId(VlanId id) {
+            return add(Instructions.modVlanId(id));
+        }
+
+        @Override
+        public Builder setVlanPcp(Byte pcp) {
+            return add(Instructions.modVlanPcp(pcp));
+        }
+
+        @Override
+        public Builder setIpSrc(IpPrefix addr) {
+            return add(Instructions.modL3Src(addr));
+        }
+
+        @Override
+        public Builder setIpDst(IpPrefix addr) {
+            return add(Instructions.modL3Dst(addr));
+        }
+
+        @Override
         public TrafficTreatment build() {
 
             //If we are dropping should we just return an emptry list?
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/TrafficSelector.java b/core/api/src/main/java/org/onlab/onos/net/flow/TrafficSelector.java
index 906e505..249d1f9 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/TrafficSelector.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/TrafficSelector.java
@@ -2,7 +2,11 @@
 
 import java.util.List;
 
+import org.onlab.onos.net.PortNumber;
 import org.onlab.onos.net.flow.criteria.Criterion;
+import org.onlab.packet.IpPrefix;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
 
 /**
  * Abstraction of a slice of network traffic.
@@ -31,6 +35,69 @@
         Builder add(Criterion criterion);
 
         /**
+         * Matches an inport.
+         * @param port the inport
+         * @return a selection builder
+         */
+        public Builder matchInport(PortNumber port);
+
+        /**
+         * Matches a l2 src address.
+         * @param addr a l2 address
+         * @return a selection builder
+         */
+        public Builder matchEthSrc(MacAddress addr);
+
+        /**
+         * Matches a l2 dst address.
+         * @param addr a l2 address
+         * @return a selection builder
+         */
+        public Builder matchEthDst(MacAddress addr);
+
+        /**
+         * Matches the ethernet type.
+         * @param ethType an ethernet type
+         * @return a selection builder
+         */
+        public Builder matchEthType(short ethType);
+
+        /**
+         * Matches the vlan id.
+         * @param vlanId a vlan id
+         * @return a selection builder
+         */
+        public Builder matchVlanId(VlanId vlanId);
+
+        /**
+         * Matches a vlan priority.
+         * @param vlanPcp a vlan priority
+         * @return a selection builder
+         */
+        public Builder matchVlanPcp(Byte vlanPcp);
+
+        /**
+         * Matches the l3 protocol.
+         * @param proto a l3 protocol
+         * @return a selection builder
+         */
+        public Builder matchIPProtocol(Byte proto);
+
+        /**
+         * Matches a l3 address.
+         * @param ip a l3 address
+         * @return a selection builder
+         */
+        public Builder matchIPSrc(IpPrefix ip);
+
+        /**
+         * Matches a l3 address.
+         * @param ip a l3 address
+         * @return a selection builder
+         */
+        public Builder matchIPDst(IpPrefix ip);
+
+        /**
          * Builds an immutable traffic selector.
          *
          * @return traffic selector
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/TrafficTreatment.java b/core/api/src/main/java/org/onlab/onos/net/flow/TrafficTreatment.java
index 068bc2c..fe21328 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/TrafficTreatment.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/TrafficTreatment.java
@@ -2,7 +2,11 @@
 
 import java.util.List;
 
+import org.onlab.onos.net.PortNumber;
 import org.onlab.onos.net.flow.instructions.Instruction;
+import org.onlab.packet.IpPrefix;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
 
 /**
  * Abstraction of network traffic treatment.
@@ -22,14 +26,67 @@
     public interface Builder {
 
         /**
-         * Adds a traffic treatment instruction. If a same type instruction has
-         * already been added, it will be replaced by this one.
-         *
-         * @param instruction new instruction
+         * Adds an instruction to the builder.
+         * @param instruction an instruction
+         * @return a treatment builder
          */
         Builder add(Instruction instruction);
 
         /**
+         * Adds a drop instruction and does not return a builder.
+         */
+        public void drop();
+
+        /**
+         * Set the output port.
+         * @param number the out port
+         * @return a treatment builder
+         */
+        public Builder setOutput(PortNumber number);
+
+        /**
+         * Sets the src l2 address.
+         * @param addr a macaddress
+         * @return a treatment builder
+         */
+        public Builder setEthSrc(MacAddress addr);
+
+        /**
+         * Sets the dst l2 address.
+         * @param addr a macaddress
+         * @return a treatment builder
+         */
+        public Builder setEthDst(MacAddress addr);
+
+        /**
+         * Sets the vlan id.
+         * @param id a vlanid
+         * @return a treatment builder
+         */
+        public Builder setVlanId(VlanId id);
+
+        /**
+         * Sets the vlan priority.
+         * @param pcp a vlan priority
+         * @return a treatment builder
+         */
+        public Builder setVlanPcp(Byte pcp);
+
+        /**
+         * Sets the src l3 address.
+         * @param addr an ip
+         * @return a treatment builder
+         */
+        public Builder setIpSrc(IpPrefix addr);
+
+        /**
+         * Sets the dst l3 address.
+         * @param addr an ip
+         * @return a treatment builder
+         */
+        public Builder setIpDst(IpPrefix addr);
+
+        /**
          * Builds an immutable traffic treatment descriptor.
          *
          * @return traffic treatment