Remove deprecated instructions() method in the traffic treatment class

Change-Id: I739b35bdcbf9867c639c7b6ca4006f3eeafbb055
diff --git a/cli/src/main/java/org/onosproject/cli/net/FlowsListCommand.java b/cli/src/main/java/org/onosproject/cli/net/FlowsListCommand.java
index 4ba6a5d..0ae2d82 100644
--- a/cli/src/main/java/org/onosproject/cli/net/FlowsListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/FlowsListCommand.java
@@ -123,7 +123,7 @@
         }
 
         ArrayNode instr = mapper.createArrayNode();
-        for (Instruction i : flow.treatment().instructions()) {
+        for (Instruction i : flow.treatment().allInstructions()) {
             instr.add(i.toString());
         }
 
diff --git a/cli/src/main/java/org/onosproject/cli/net/IntentsListCommand.java b/cli/src/main/java/org/onosproject/cli/net/IntentsListCommand.java
index 89877dd..f4f4d06 100644
--- a/cli/src/main/java/org/onosproject/cli/net/IntentsListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/IntentsListCommand.java
@@ -354,8 +354,8 @@
             if (!ci.selector().criteria().isEmpty()) {
                 print("    selector=%s", ci.selector().criteria());
             }
-            if (!ci.treatment().instructions().isEmpty()) {
-                print("    treatment=%s", ci.treatment().instructions());
+            if (!ci.treatment().allInstructions().isEmpty()) {
+                print("    treatment=%s", ci.treatment().allInstructions());
             }
             if (ci.constraints() != null && !ci.constraints().isEmpty()) {
                 print("    constraints=%s", ci.constraints());
@@ -423,8 +423,8 @@
             if (!ci.selector().criteria().isEmpty()) {
                 result.put("selector", ci.selector().criteria().toString());
             }
-            if (!ci.treatment().instructions().isEmpty()) {
-                result.put("treatment", ci.treatment().instructions().toString());
+            if (!ci.treatment().allInstructions().isEmpty()) {
+                result.put("treatment", ci.treatment().allInstructions().toString());
             }
         }
 
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 5b2343e..da3cac6 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
@@ -32,6 +32,8 @@
 import java.util.List;
 import java.util.Objects;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 /**
  * Default traffic treatment implementation.
  */
@@ -52,7 +54,7 @@
      * @param instructions treatment instructions
      */
     private DefaultTrafficTreatment(List<Instruction> instructions) {
-        this.immediate = ImmutableList.copyOf(instructions);
+        this.immediate = ImmutableList.copyOf(checkNotNull(instructions));
         this.deferred = ImmutableList.of();
         this.hasClear = false;
         this.table = null;
@@ -62,19 +64,14 @@
                                    List<Instruction> immediate,
                                    Instructions.TableTypeTransition table,
                                    boolean clear) {
-        this.immediate = ImmutableList.copyOf(immediate);
-        this.deferred = ImmutableList.copyOf(deferred);
+        this.immediate = ImmutableList.copyOf(checkNotNull(immediate));
+        this.deferred = ImmutableList.copyOf(checkNotNull(deferred));
         this.table = table;
         this.hasClear = clear;
 
     }
 
     @Override
-    public List<Instruction> instructions() {
-        return immediate;
-    }
-
-    @Override
     public List<Instruction> deferred() {
         return deferred;
     }
@@ -184,7 +181,7 @@
         // Creates a new builder based off an existing treatment
         //FIXME only works for immediate instruction sets.
         private Builder(TrafficTreatment treatment) {
-            for (Instruction instruction : treatment.instructions()) {
+            for (Instruction instruction : treatment.immediate()) {
                 add(instruction);
             }
         }
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 0732e35..a2254fa 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
@@ -32,14 +32,6 @@
 public interface TrafficTreatment {
 
     /**
-     * Returns list of instructions on how to treat traffic.
-     *
-     * @return list of treatment instructions
-     */
-    @Deprecated
-    List<Instruction> instructions();
-
-    /**
      * Returns the list of treatment instructions that will be applied
      * further down the pipeline.
      * @return list of treatment instructions
diff --git a/core/api/src/main/java/org/onosproject/net/flowext/DefaultFlowRuleExt.java b/core/api/src/main/java/org/onosproject/net/flowext/DefaultFlowRuleExt.java
index 721cced..c72d4db 100644
--- a/core/api/src/main/java/org/onosproject/net/flowext/DefaultFlowRuleExt.java
+++ b/core/api/src/main/java/org/onosproject/net/flowext/DefaultFlowRuleExt.java
@@ -102,7 +102,7 @@
                 .add("deviceId", deviceId())
                 .add("priority", priority())
                 .add("selector", selector().criteria())
-                .add("treatment", treatment() == null ? "N/A" : treatment().instructions())
+                .add("treatment", treatment() == null ? "N/A" : treatment().allInstructions())
                         //.add("created", created)
                 .add("flowEntryExtension", flowEntryExtension)
                 .toString();
diff --git a/core/api/src/main/java/org/onosproject/net/group/DefaultGroupBucket.java b/core/api/src/main/java/org/onosproject/net/group/DefaultGroupBucket.java
index ff1271e..e4910d5 100644
--- a/core/api/src/main/java/org/onosproject/net/group/DefaultGroupBucket.java
+++ b/core/api/src/main/java/org/onosproject/net/group/DefaultGroupBucket.java
@@ -15,15 +15,17 @@
  */
 package org.onosproject.net.group;
 
-import static com.google.common.base.MoreObjects.toStringHelper;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.Objects;
-
 import org.onosproject.core.GroupId;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.flow.instructions.Instruction;
+
+import java.util.List;
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
 
 /**
  * Group bucket implementation. A group bucket is collection of
@@ -206,9 +208,12 @@
         }
         if (obj instanceof DefaultGroupBucket) {
             DefaultGroupBucket that = (DefaultGroupBucket) obj;
+            List<Instruction> myInstructions = this.treatment.allInstructions();
+            List<Instruction> theirInstructions = that.treatment.allInstructions();
+
             return Objects.equals(type, that.type) &&
-                   this.treatment.instructions().containsAll(that.treatment.instructions()) &&
-                   that.treatment.instructions().containsAll(this.treatment.instructions());
+                   myInstructions.containsAll(theirInstructions) &&
+                   theirInstructions.containsAll(myInstructions);
         }
         return false;
     }
diff --git a/core/api/src/test/java/org/onosproject/net/flow/DefaultTrafficTreatmentTest.java b/core/api/src/test/java/org/onosproject/net/flow/DefaultTrafficTreatmentTest.java
index 1086585..ad04602 100644
--- a/core/api/src/test/java/org/onosproject/net/flow/DefaultTrafficTreatmentTest.java
+++ b/core/api/src/test/java/org/onosproject/net/flow/DefaultTrafficTreatmentTest.java
@@ -75,14 +75,24 @@
 
         final TrafficTreatment treatment1 = builder1.build();
 
-        final List<Instruction> instructions1 = treatment1.instructions();
+        final List<Instruction> instructions1 = treatment1.immediate();
         assertThat(instructions1, hasSize(9));
 
         builder1.drop();
         builder1.add(instruction1);
 
-        final List<Instruction> instructions2 = builder1.build().instructions();
+        final List<Instruction> instructions2 = builder1.build().immediate();
         assertThat(instructions2, hasSize(11));
+
+        builder1.deferred()
+                .popVlan()
+                .pushVlan()
+                .setVlanId(VlanId.vlanId((short) 5));
+
+        final List<Instruction> instructions3 = builder1.build().immediate();
+        assertThat(instructions3, hasSize(11));
+        final List<Instruction> instructions4 = builder1.build().deferred();
+        assertThat(instructions4, hasSize(3));
     }
 
     /**
diff --git a/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java b/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
index 4ae09fb..14abd83 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
@@ -93,18 +93,13 @@
      */
     public static class MockTreatment implements TrafficTreatment {
         @Override
-        public List<Instruction> instructions() {
-            return new ArrayList<>();
-        }
-
-        @Override
         public List<Instruction> deferred() {
             return null;
         }
 
         @Override
         public List<Instruction> immediate() {
-            return null;
+            return new ArrayList<>();
         }
 
         @Override
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/TrafficTreatmentCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/TrafficTreatmentCodec.java
index 786c461..23dae38 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/TrafficTreatmentCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/TrafficTreatmentCodec.java
@@ -36,12 +36,17 @@
         final ObjectNode result = context.mapper().createObjectNode();
         final ArrayNode jsonInstructions = result.putArray("instructions");
 
-        if (treatment.instructions() != null) {
-            final JsonCodec<Instruction> instructionCodec =
-                    context.codec(Instruction.class);
-            for (final Instruction instruction : treatment.instructions()) {
-                jsonInstructions.add(instructionCodec.encode(instruction, context));
-            }
+        final JsonCodec<Instruction> instructionCodec =
+                context.codec(Instruction.class);
+
+        for (final Instruction instruction : treatment.immediate()) {
+            jsonInstructions.add(instructionCodec.encode(instruction, context));
+        }
+
+        final ArrayNode jsonDeferred = result.putArray("deferred");
+
+        for (final Instruction instruction : treatment.deferred()) {
+            jsonDeferred.add(instructionCodec.encode(instruction, context));
         }
 
         return result;
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/IntentJsonMatcher.java b/core/common/src/test/java/org/onosproject/codec/impl/IntentJsonMatcher.java
index 5ae8f20..d30999d 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/IntentJsonMatcher.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/IntentJsonMatcher.java
@@ -370,7 +370,7 @@
         // check treatment
         final JsonNode jsonTreatment = jsonIntent.get("treatment");
         final TrafficTreatment treatment = connectivityIntent.treatment();
-        final List<Instruction> instructions = treatment.instructions();
+        final List<Instruction> instructions = treatment.immediate();
         final JsonNode jsonInstructions = jsonTreatment.get("instructions");
         if (jsonInstructions.size() != instructions.size()) {
             description.appendText("size of instructions array is "
diff --git a/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java b/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java
index 881961f..6669578 100644
--- a/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java
@@ -557,11 +557,6 @@
         }
 
         @Override
-        public List<Instruction> instructions() {
-            return null;
-        }
-
-        @Override
         public List<Instruction> deferred() {
             return null;
         }
diff --git a/core/net/src/test/java/org/onosproject/net/host/impl/HostMonitorTest.java b/core/net/src/test/java/org/onosproject/net/host/impl/HostMonitorTest.java
index 03276941..e8fccde 100644
--- a/core/net/src/test/java/org/onosproject/net/host/impl/HostMonitorTest.java
+++ b/core/net/src/test/java/org/onosproject/net/host/impl/HostMonitorTest.java
@@ -156,8 +156,8 @@
         OutboundPacket packet = packetService.packets.get(0);
 
         // Check the output port is correct
-        assertEquals(1, packet.treatment().instructions().size());
-        Instruction instruction = packet.treatment().instructions().get(0);
+        assertEquals(1, packet.treatment().immediate().size());
+        Instruction instruction = packet.treatment().immediate().get(0);
         assertTrue(instruction instanceof OutputInstruction);
         OutputInstruction oi = (OutputInstruction) instruction;
         assertEquals(portNum, oi.port());
@@ -225,8 +225,8 @@
         OutboundPacket packet = packetService.packets.get(0);
 
         // Check the output port is correct
-        assertEquals(1, packet.treatment().instructions().size());
-        Instruction instruction = packet.treatment().instructions().get(0);
+        assertEquals(1, packet.treatment().immediate().size());
+        Instruction instruction = packet.treatment().immediate().get(0);
         assertTrue(instruction instanceof OutputInstruction);
         OutputInstruction oi = (OutputInstruction) instruction;
         assertEquals(portNum, oi.port());
diff --git a/core/net/src/test/java/org/onosproject/net/proxyarp/impl/ProxyArpManagerTest.java b/core/net/src/test/java/org/onosproject/net/proxyarp/impl/ProxyArpManagerTest.java
index 09f4f14..5a4eb8b 100644
--- a/core/net/src/test/java/org/onosproject/net/proxyarp/impl/ProxyArpManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/proxyarp/impl/ProxyArpManagerTest.java
@@ -503,9 +503,9 @@
     private void verifyPacketOut(Ethernet expected, ConnectPoint outPort,
             OutboundPacket actual) {
         assertArrayEquals(expected.serialize(), actual.data().array());
-        assertEquals(1, actual.treatment().instructions().size());
+        assertEquals(1, actual.treatment().immediate().size());
         assertEquals(outPort.deviceId(), actual.sendThrough());
-        Instruction instruction = actual.treatment().instructions().get(0);
+        Instruction instruction = actual.treatment().immediate().get(0);
         assertTrue(instruction instanceof OutputInstruction);
         assertEquals(outPort.port(), ((OutputInstruction) instruction).port());
     }
diff --git a/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleStatisticStore.java b/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleStatisticStore.java
index 9cfa41d..e4bf7dd 100644
--- a/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleStatisticStore.java
+++ b/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleStatisticStore.java
@@ -155,15 +155,7 @@
     private ConnectPoint buildConnectPoint(FlowRule rule) {
         PortNumber port = getOutput(rule);
 
-        boolean hasGoto = rule.treatment().instructions()
-                .stream()
-                .anyMatch(i -> (i instanceof Instructions.GroupInstruction)
-                        || (i instanceof Instructions.TableTypeTransition));
-
         if (port == null) {
-            if (!hasGoto) {
-                log.debug("Rule {} has no output.", rule);
-            }
             return null;
         }
         ConnectPoint cp = new ConnectPoint(rule.deviceId(), port);
@@ -171,7 +163,7 @@
     }
 
     private PortNumber getOutput(FlowRule rule) {
-        for (Instruction i : rule.treatment().instructions()) {
+        for (Instruction i : rule.treatment().immediate()) {
             if (i.type() == Instruction.Type.OUTPUT) {
                 Instructions.OutputInstruction out = (Instructions.OutputInstruction) i;
                 return out.port();
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 e308299..d6ff82c 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
@@ -138,7 +138,7 @@
         if (treatment == null) {
             return acts;
         }
-        for (Instruction i : treatment.instructions()) {
+        for (Instruction i : treatment.immediate()) {
             switch (i.type()) {
             case DROP:
                 log.warn("Saw drop action; assigning drop action");
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 1554fa3..61757bd 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
@@ -186,24 +186,6 @@
         return fm;
     }
 
-
-    private List<OFInstruction> buildInstructions() {
-        List<OFInstruction> instructions = new LinkedList<>();
-        if (treatment == null) {
-            return instructions;
-        }
-        for (Instruction i : treatment.instructions()) {
-            switch (i.type()) {
-                case TABLE:
-                    instructions.add(buildTableGoto(((Instructions.TableTypeTransition) i)));
-                    break;
-                default:
-                    break;
-            }
-        }
-        return instructions;
-    }
-
     private List<OFAction> buildActions(List<Instruction> treatments) {
         List<OFAction> actions = new LinkedList<>();
         boolean tableFound = false;
diff --git a/providers/openflow/group/src/main/java/org/onosproject/provider/of/group/impl/GroupModBuilder.java b/providers/openflow/group/src/main/java/org/onosproject/provider/of/group/impl/GroupModBuilder.java
index 25ece46..cd88017 100644
--- a/providers/openflow/group/src/main/java/org/onosproject/provider/of/group/impl/GroupModBuilder.java
+++ b/providers/openflow/group/src/main/java/org/onosproject/provider/of/group/impl/GroupModBuilder.java
@@ -184,7 +184,7 @@
             return actions;
         }
 
-        for (Instruction i : treatment.instructions()) {
+        for (Instruction i : treatment.allInstructions()) {
             switch (i.type()) {
                 case DROP:
                     log.warn("Saw drop action; assigning drop action");
diff --git a/providers/openflow/packet/src/main/java/org/onosproject/provider/of/packet/impl/OpenFlowCorePacketContext.java b/providers/openflow/packet/src/main/java/org/onosproject/provider/of/packet/impl/OpenFlowCorePacketContext.java
index a5d7a68..5b7487b 100644
--- a/providers/openflow/packet/src/main/java/org/onosproject/provider/of/packet/impl/OpenFlowCorePacketContext.java
+++ b/providers/openflow/packet/src/main/java/org/onosproject/provider/of/packet/impl/OpenFlowCorePacketContext.java
@@ -55,7 +55,7 @@
     }
 
     private void sendPacket(Ethernet eth) {
-        List<Instruction> ins = treatmentBuilder().build().instructions();
+        List<Instruction> ins = treatmentBuilder().build().allInstructions();
         OFPort p = null;
         //TODO: support arbitrary list of treatments must be supported in ofPacketContext
         for (Instruction i : ins) {
diff --git a/providers/openflow/packet/src/main/java/org/onosproject/provider/of/packet/impl/OpenFlowPacketProvider.java b/providers/openflow/packet/src/main/java/org/onosproject/provider/of/packet/impl/OpenFlowPacketProvider.java
index 8cae352..0cf67f4 100644
--- a/providers/openflow/packet/src/main/java/org/onosproject/provider/of/packet/impl/OpenFlowPacketProvider.java
+++ b/providers/openflow/packet/src/main/java/org/onosproject/provider/of/packet/impl/OpenFlowPacketProvider.java
@@ -113,7 +113,7 @@
         //Ethernet eth = new Ethernet();
         //eth.deserialize(packet.data().array(), 0, packet.data().array().length);
         OFPortDesc p = null;
-        for (Instruction inst : packet.treatment().instructions()) {
+        for (Instruction inst : packet.treatment().allInstructions()) {
             if (inst.type().equals(Instruction.Type.OUTPUT)) {
                 p = portDesc(((OutputInstruction) inst).port());
                 OFPacketOut po = packetOut(sw, packet.data().array(), p.getPortNo());
diff --git a/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java b/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java
index a02690f..64e045d 100644
--- a/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java
@@ -298,12 +298,12 @@
             if (flow.treatment() != null) {
                 final JsonObject jsonTreatment = jsonFlow.get("treatment").asObject();
                 final JsonArray jsonInstructions = jsonTreatment.get("instructions").asArray();
-                if (flow.treatment().instructions().size() != jsonInstructions.size()) {
+                if (flow.treatment().immediate().size() != jsonInstructions.size()) {
                     reason = "instructions array size of " +
-                            Integer.toString(flow.treatment().instructions().size());
+                            Integer.toString(flow.treatment().immediate().size());
                     return false;
                 }
-                for (final Instruction instruction : flow.treatment().instructions()) {
+                for (final Instruction instruction : flow.treatment().immediate()) {
                     boolean instructionFound = false;
                     for (int instructionIndex = 0; instructionIndex < jsonInstructions.size(); instructionIndex++) {
                         final String jsonType =
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java
index 7ffc275..50e39d7 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java
@@ -534,7 +534,7 @@
         PortNumber out = link.src().port();
         for (FlowEntry entry : entries) {
             TrafficTreatment treatment = entry.treatment();
-            for (Instruction instruction : treatment.instructions()) {
+            for (Instruction instruction : treatment.allInstructions()) {
                 if (instruction.type() == Instruction.Type.OUTPUT &&
                         ((OutputInstruction) instruction).port().equals(out)) {
                     count++;
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessages.java b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessages.java
index b9b50ca..b48231e 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessages.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessages.java
@@ -528,7 +528,7 @@
         PortNumber out = link.src().port();
         for (FlowEntry entry : entries) {
             TrafficTreatment treatment = entry.treatment();
-            for (Instruction instruction : treatment.instructions()) {
+            for (Instruction instruction : treatment.allInstructions()) {
                 if (instruction.type() == Instruction.Type.OUTPUT &&
                         ((OutputInstruction) instruction).port().equals(out)) {
                     count++;