Support [ONOS-4593] and implement [ONOS-4594]

Changes:
- Adds extension to sp2mp intents;
- Adds extension to linkcollection intents;
- Adds extension to sp2mp compiler;
- Adds extension to linkcollection compiler;
- Adds re-ordering of the actions;
- Adds unit tests for both sp2mp intents and linkcollection intents;

Change-Id: Ib925e9066682e077a0bb4bbfd20a4382623b7541
diff --git a/core/api/src/main/java/org/onosproject/net/intent/SinglePointToMultiPointIntent.java b/core/api/src/main/java/org/onosproject/net/intent/SinglePointToMultiPointIntent.java
index 51dfcb8..4b17c66 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/SinglePointToMultiPointIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/SinglePointToMultiPointIntent.java
@@ -17,14 +17,18 @@
 
 import com.google.common.annotations.Beta;
 import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 
+import com.google.common.collect.Sets;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
 
-import java.util.Collections;
+import java.util.Map;
 import java.util.Set;
 import java.util.List;
 
@@ -39,6 +43,10 @@
 
     private final ConnectPoint ingressPoint;
     private final Set<ConnectPoint> egressPoints;
+    /**
+     * To manage multiple treatments use case.
+     */
+    private final Map<ConnectPoint, TrafficTreatment> egressTreatments;
 
     /**
      * Creates a new single-to-multi point connectivity intent.
@@ -51,27 +59,32 @@
      * @param egressPoints set of ports on which traffic will egress
      * @param constraints constraints to apply to the intent
      * @param priority priority to use for flows generated by this intent
+     * @param egressTreatments map to store the association egress to treatment
      * @throws NullPointerException if {@code ingressPoint} or
      *             {@code egressPoints} is null
      * @throws IllegalArgumentException if the size of {@code egressPoints} is
      *             not more than 1
      */
     private SinglePointToMultiPointIntent(ApplicationId appId,
-            Key key,
-            TrafficSelector selector, TrafficTreatment treatment,
-            ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints,
-            List<Constraint> constraints,
-            int priority) {
-        super(appId, key, Collections.emptyList(), selector, treatment, constraints,
-                priority);
+                                          Key key,
+                                          TrafficSelector selector,
+                                          TrafficTreatment treatment,
+                                          ConnectPoint ingressPoint,
+                                          Set<ConnectPoint> egressPoints,
+                                          List<Constraint> constraints,
+                                          int priority,
+                                          Map<ConnectPoint, TrafficTreatment> egressTreatments) {
+        super(appId, key, ImmutableList.of(), selector, treatment, constraints,
+              priority);
         checkNotNull(egressPoints);
         checkNotNull(ingressPoint);
         checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
         checkArgument(!egressPoints.contains(ingressPoint),
                 "Set of egresses should not contain ingress (ingress: %s)", ingressPoint);
 
-        this.ingressPoint = checkNotNull(ingressPoint);
-        this.egressPoints = egressPoints;
+        this.ingressPoint = ingressPoint;
+        this.egressPoints = Sets.newHashSet(egressPoints);
+        this.egressTreatments = egressTreatments;
     }
 
     /**
@@ -92,6 +105,7 @@
     public static final class Builder extends ConnectivityIntent.Builder {
         ConnectPoint ingressPoint;
         Set<ConnectPoint> egressPoints;
+        Map<ConnectPoint, TrafficTreatment> egressTreatments = ImmutableMap.of();
 
         private Builder() {
             // Hide constructor
@@ -152,6 +166,18 @@
         }
 
         /**
+         * Sets the treatments of the single point to multi point intent
+         * that will be built.
+         *
+         * @param egressTreatments the multiple treatments
+         * @return this builder
+         */
+        public Builder treatments(Map<ConnectPoint, TrafficTreatment> egressTreatments) {
+            this.egressTreatments = ImmutableMap.copyOf(egressTreatments);
+            return this;
+        }
+
+        /**
          * Builds a single point to multi point intent from the
          * accumulated parameters.
          *
@@ -159,6 +185,12 @@
          */
         public SinglePointToMultiPointIntent build() {
 
+            if (treatment != null && !treatment.allInstructions().isEmpty() &&
+                    !treatment.equals(DefaultTrafficTreatment.emptyTreatment()) &&
+                    egressTreatments != null && !egressTreatments.isEmpty()) {
+                throw new IllegalArgumentException("Treatment and Multiple Treatments are both set");
+            }
+
             return new SinglePointToMultiPointIntent(
                     appId,
                     key,
@@ -167,7 +199,8 @@
                     ingressPoint,
                     egressPoints,
                     constraints,
-                    priority
+                    priority,
+                    egressTreatments
             );
         }
     }
@@ -179,6 +212,7 @@
         super();
         this.ingressPoint = null;
         this.egressPoints = null;
+        this.egressTreatments = null;
     }
 
     /**
@@ -200,6 +234,14 @@
         return egressPoints;
     }
 
+    /**
+     * Returns the multiple treatments jointly with their connection points.
+     * @return multiple treatments
+     */
+    public Map<ConnectPoint, TrafficTreatment> egressTreatments() {
+        return egressTreatments;
+    }
+
     @Override
     public String toString() {
         return MoreObjects.toStringHelper(getClass())
@@ -212,6 +254,7 @@
                 .add("treatment", treatment())
                 .add("ingress", ingressPoint)
                 .add("egress", egressPoints)
+                .add("treatments", egressTreatments)
                 .add("constraints", constraints())
                 .toString();
     }