[SDFAB-834] Add application filtering to ONOS UPF programmable APIs

Change-Id: I3e3d44d5d160470c3f4bfca32e7a83e194d155d8
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/upf/UpfTerminationUplink.java b/core/api/src/main/java/org/onosproject/net/behaviour/upf/UpfTerminationUplink.java
index f759202..1c6dd56 100644
--- a/core/api/src/main/java/org/onosproject/net/behaviour/upf/UpfTerminationUplink.java
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/upf/UpfTerminationUplink.java
@@ -26,20 +26,22 @@
 /**
  * A structure representing the UE Termination in the uplink direction on the
  * UPF-programmable device.
- * Provides means to configure the traffic behavior (e.g. set Traffic Class).
+ * Provide means to configure the traffic behavior (e.g. set Traffic Class).
  */
 @Beta
 public final class UpfTerminationUplink implements UpfEntity {
     // Match Keys
     private final Ip4Address ueSessionId; // UE Session ID, use UE IP address to uniquely identify a session.
+    private final byte applicationId; // Application ID defaults to DEFAULT_APP_ID
     // Action parameters
     private final Integer ctrId;  // Counter ID unique to this UPF Termination Rule
     private final Byte trafficClass;
     private final boolean dropping;
 
-    private UpfTerminationUplink(Ip4Address ueSessionId, Integer ctrId, Byte trafficClass,
+    private UpfTerminationUplink(Ip4Address ueSessionId, byte applicationId, Integer ctrId, Byte trafficClass,
                                  boolean dropping) {
         this.ueSessionId = ueSessionId;
+        this.applicationId = applicationId;
         this.ctrId = ctrId;
         this.trafficClass = trafficClass;
         this.dropping = dropping;
@@ -65,13 +67,14 @@
         // Safe comparisons between potentially null objects
         return this.dropping == that.dropping &&
                 Objects.equals(this.ueSessionId, that.ueSessionId) &&
+                Objects.equals(this.applicationId, that.applicationId) &&
                 Objects.equals(this.ctrId, that.ctrId) &&
                 Objects.equals(this.trafficClass, that.trafficClass);
     }
 
     @Override
     public int hashCode() {
-        return Objects.hash(ueSessionId, ctrId, trafficClass, dropping);
+        return Objects.hash(ueSessionId, applicationId, ctrId, trafficClass, dropping);
     }
 
     /**
@@ -84,6 +87,15 @@
     }
 
     /**
+     * Get the application ID associated with UPF Termination rule.
+     *
+     * @return Application ID
+     */
+    public byte applicationId() {
+        return applicationId;
+    }
+
+    /**
      * Get PDR Counter ID associated with UPF Termination rule.
      *
      * @return PDR counter cell ID
@@ -117,19 +129,27 @@
 
     @Override
     public String toString() {
-        return "TerminationUL{" + matchString() + "->" + actionString() + "}";
+        return "TerminationUL{" + matchString() + " -> " + actionString() + "}";
     }
 
     private String matchString() {
-        return "Match(ue_addr=" + this.ueSessionId() + ")";
+        return "Match(ue_addr=" + this.ueSessionId() + ", app_id=" + this.applicationId() + ")";
     }
 
     private String actionString() {
-        return "(CTR_ID=" + this.counterId() + ", TC=" + this.trafficClass() + ")";
+        String fwd = "FWD";
+        if (this.needsDropping()) {
+            fwd = "DROP";
+        }
+        return "(" + fwd +
+                ", CTR_ID=" + this.counterId() +
+                ", TC=" + this.trafficClass() +
+                ")";
     }
 
     public static class Builder {
         private Ip4Address ueSessionId = null;
+        private Byte applicationId = null;
         private Integer ctrId = null;
         private Byte trafficClass = null;
         private boolean dropping = false;
@@ -150,6 +170,17 @@
         }
 
         /**
+         * Set the ID of the application.
+         *
+         * @param applicationId Application ID
+         * @return This builder object
+         */
+        public Builder withApplicationId(byte applicationId) {
+            this.applicationId = applicationId;
+            return this;
+        }
+
+        /**
          * Set the dataplane counter cell ID.
          *
          * @param ctrId PDR counter cell ID
@@ -174,7 +205,7 @@
         /**
          * Sets whether to drop uplink UPF termination traffic or not.
          *
-         * @param dropping True if request to buffer, false otherwise
+         * @param dropping True if request to drop, false otherwise
          * @return This builder object
          */
         public Builder needsDropping(boolean dropping) {
@@ -185,11 +216,15 @@
         public UpfTerminationUplink build() {
             // Match fields must be provided
             checkNotNull(ueSessionId, "UE session ID must be provided");
-
+            if (applicationId == null) {
+                applicationId = DEFAULT_APP_ID;
+            }
             checkNotNull(ctrId, "Counter ID must be provided");
             // TODO: should we verify that when dropping no other fields are provided
             return new UpfTerminationUplink(
-                    this.ueSessionId, this.ctrId, this.trafficClass, this.dropping);
+                    this.ueSessionId, this.applicationId, this.ctrId,
+                    this.trafficClass, this.dropping
+            );
         }
 
     }