[SDFAB-90] Implement priority mechanism in the Policy framework.

Change-Id: I738956566bfcf1bd5e2d4fcd9bfef153b5fb674a
diff --git a/api/src/main/java/org/onosproject/segmentrouting/policy/api/PolicyService.java b/api/src/main/java/org/onosproject/segmentrouting/policy/api/PolicyService.java
index 2e188ab..9b93870 100644
--- a/api/src/main/java/org/onosproject/segmentrouting/policy/api/PolicyService.java
+++ b/api/src/main/java/org/onosproject/segmentrouting/policy/api/PolicyService.java
@@ -23,7 +23,9 @@
 public interface PolicyService {
     /**
      * Traffic match priority.
+     * @deprecated in version 3.0.2
      */
+    @Deprecated
     int TRAFFIC_MATCH_PRIORITY = 60000;
 
     /**
diff --git a/api/src/main/java/org/onosproject/segmentrouting/policy/api/TrafficMatch.java b/api/src/main/java/org/onosproject/segmentrouting/policy/api/TrafficMatch.java
index 83098fe..bcad3bd 100644
--- a/api/src/main/java/org/onosproject/segmentrouting/policy/api/TrafficMatch.java
+++ b/api/src/main/java/org/onosproject/segmentrouting/policy/api/TrafficMatch.java
@@ -34,17 +34,34 @@
     private TrafficMatchId trafficMatchId;
     private TrafficSelector trafficSelector;
     private PolicyId policyId;
+    private TrafficMatchPriority trafficMatchPriority;
 
     /**
      * Builds a traffic match.
      *
-     * @param trafficselector the traffic selector
-     * @param policyid the associated policy id
+     * @param trafficSelector the traffic selector
+     * @param policyId the associated policy id
+     * @deprecated in version 3.0.2
      */
-    public TrafficMatch(TrafficSelector trafficselector, PolicyId policyid) {
-        trafficSelector = trafficselector;
-        trafficMatchId = TrafficMatchId.trafficMatchId(computeTrafficMatchId());
-        policyId = policyid;
+    public TrafficMatch(TrafficSelector trafficSelector, PolicyId policyId) {
+        this.trafficSelector = trafficSelector;
+        this.trafficMatchId = TrafficMatchId.trafficMatchId(computeTrafficMatchId());
+        this.policyId = policyId;
+        this.trafficMatchPriority = new TrafficMatchPriority(PolicyService.TRAFFIC_MATCH_PRIORITY);
+    }
+
+    /**
+     * Builds a traffic match.
+     *
+     * @param trafficSelector the traffic selector
+     * @param policyId the associated policy id
+     * @param trafficMatchPriority the priority
+     */
+    public TrafficMatch(TrafficSelector trafficSelector, PolicyId policyId, TrafficMatchPriority trafficMatchPriority) {
+        this.trafficSelector = trafficSelector;
+        this.trafficMatchId = TrafficMatchId.trafficMatchId(computeTrafficMatchId());
+        this.policyId = policyId;
+        this.trafficMatchPriority = trafficMatchPriority;
     }
 
     /**
@@ -74,9 +91,18 @@
         return trafficSelector;
     }
 
+    /**
+     * Returns the priority.
+     *
+     * @return the priority
+     */
+    public TrafficMatchPriority trafficMatchPriority() {
+        return trafficMatchPriority;
+    }
+
     @Override
     public int hashCode() {
-        return Objects.hash(trafficMatchId, trafficSelector, policyId);
+        return Objects.hash(trafficMatchId, trafficSelector, policyId, trafficMatchPriority);
     }
 
     @Override
@@ -88,7 +114,8 @@
             final TrafficMatch other = (TrafficMatch) obj;
             return Objects.equals(this.trafficMatchId, other.trafficMatchId) &&
                     Objects.equals(trafficSelector, other.trafficSelector) &&
-                    Objects.equals(policyId, other.policyId);
+                    Objects.equals(policyId, other.policyId) &&
+                    Objects.equals(trafficMatchPriority, other.trafficMatchPriority);
         }
         return false;
     }
@@ -99,6 +126,7 @@
                 .add("trafficMatchId", trafficMatchId)
                 .add("trafficSelector", trafficSelector)
                 .add("policyId", policyId)
+                .add("trafficMatchPriority", trafficMatchPriority)
                 .toString();
     }
 
diff --git a/api/src/main/java/org/onosproject/segmentrouting/policy/api/TrafficMatchPriority.java b/api/src/main/java/org/onosproject/segmentrouting/policy/api/TrafficMatchPriority.java
new file mode 100644
index 0000000..206c0b3
--- /dev/null
+++ b/api/src/main/java/org/onosproject/segmentrouting/policy/api/TrafficMatchPriority.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2021-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.segmentrouting.policy.api;
+
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Priorities for traffic match.
+ */
+public final class TrafficMatchPriority {
+    /**
+     * Priority of the TrafficMatch.
+     */
+    private final int priority;
+
+    /**
+     * Lowest allowable priority value.
+     */
+    public static final int MIN = 50000;
+
+    /**
+     * Medium priority value.
+     */
+    public static final int MEDIUM = 55000;
+
+    /**
+     * Highest allowable priority value.
+     */
+    public static final int MAX = 60000;
+
+    private static final String ILLEGAL_PRIORITY_MESSAGE = "The priority value is out of range.";
+
+    /**
+     * Using arbitrary or pre-defined value.
+     *
+     * @param priority A arbitrary or pre-defined priority value.
+     * @throws IllegalArgumentException if priority value less or greater than lower/upper bound.
+     */
+    public TrafficMatchPriority(int priority) throws IllegalArgumentException {
+        if (priority < MIN || priority > MAX) {
+            throw new IllegalArgumentException(ILLEGAL_PRIORITY_MESSAGE);
+        } else {
+            this.priority = priority;
+        }
+    }
+
+    /**
+     * Get priority value.
+     *
+     * @return the priority value.
+     */
+    public int priority() {
+        return this.priority;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(priority);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof TrafficMatchPriority) {
+            final TrafficMatchPriority other = (TrafficMatchPriority) obj;
+            return this.priority() == other.priority();
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this)
+                .add("priority", priority)
+                .toString();
+    }
+}