Refactor UPF entities to have consistent naming and string representations

Also, add slice ID into applications and interfaces entities

Change-Id: I159bcf04af1504b4e5c7210aa1402218fae3eb8f
(cherry picked from commit de1f1f7806716ac6e368e55eaf0b887ab89530d4)
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/upf/UpfInterface.java b/core/api/src/main/java/org/onosproject/net/behaviour/upf/UpfInterface.java
index f697d15..cf10ae1 100644
--- a/core/api/src/main/java/org/onosproject/net/behaviour/upf/UpfInterface.java
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/upf/UpfInterface.java
@@ -31,10 +31,13 @@
 public final class UpfInterface implements UpfEntity {
     private final Ip4Prefix prefix;
     private final Type type;
+    // TODO: move to SliceId object when slice APIs will be promoted to ONOS core.
+    private final int sliceId;
 
-    private UpfInterface(Ip4Prefix prefix, Type type) {
+    private UpfInterface(Ip4Prefix prefix, Type type, int sliceId) {
         this.prefix = prefix;
         this.type = type;
+        this.sliceId = sliceId;
     }
 
     public static Builder builder() {
@@ -43,17 +46,7 @@
 
     @Override
     public String toString() {
-        String typeStr;
-        if (type.equals(Type.ACCESS)) {
-            typeStr = "Access";
-        } else if (type.equals(Type.CORE)) {
-            typeStr = "Core";
-        } else if (type.equals(Type.DBUF)) {
-            typeStr = "Dbuf-Receiver";
-        } else {
-            typeStr = "UNKNOWN";
-        }
-        return String.format("Interface{%s, %s}", typeStr, prefix);
+        return String.format("UpfInterface(type=%s, prefix=%s, slice_id=%s)", type.toString(), prefix, sliceId);
     }
 
     @Override
@@ -68,43 +61,58 @@
             return false;
         }
         UpfInterface that = (UpfInterface) obj;
-        return (this.type.equals(that.type) &&
-                this.prefix.equals(that.prefix));
+        return this.type.equals(that.type) &&
+                this.prefix.equals(that.prefix) &&
+                this.sliceId == that.sliceId;
     }
 
     @Override
     public int hashCode() {
-        return Objects.hash(prefix, type);
+        return Objects.hash(prefix, type, sliceId);
     }
 
     /**
      * Create a core-facing UPF Interface from the given address, which will be treated as a /32 prefix.
-     *
      * @param address the address of the new core-facing interface
+     * @param sliceId the slice if of the new interface
      * @return a new UPF interface
      */
-    public static UpfInterface createS1uFrom(Ip4Address address) {
-        return builder().setAccess().setPrefix(Ip4Prefix.valueOf(address, 32)).build();
+    public static UpfInterface createS1uFrom(Ip4Address address, int sliceId) {
+        return builder()
+                .setAccess()
+                .setPrefix(Ip4Prefix.valueOf(address, 32))
+                .setSliceId(sliceId)
+                .build();
     }
 
     /**
      * Create a core-facing UPF Interface from the given IP prefix.
      *
      * @param prefix the prefix of the new core-facing interface
+     * @param sliceId the slice if of the new interface
      * @return a new UPF interface
      */
-    public static UpfInterface createUePoolFrom(Ip4Prefix prefix) {
-        return builder().setCore().setPrefix(prefix).build();
+    public static UpfInterface createUePoolFrom(Ip4Prefix prefix, int sliceId) {
+        return builder()
+                .setCore()
+                .setPrefix(prefix)
+                .setSliceId(sliceId)
+                .build();
     }
 
     /**
      * Create a dbuf-receiving UPF interface from the given IP address.
      *
      * @param address the address of the dbuf-receiving interface
+     * @param sliceId the slice if of the new interface
      * @return a new UPF interface
      */
-    public static UpfInterface createDbufReceiverFrom(Ip4Address address) {
-        return UpfInterface.builder().setDbufReceiver().setAddress(address).build();
+    public static UpfInterface createDbufReceiverFrom(Ip4Address address, int sliceId) {
+        return builder()
+                .setDbufReceiver()
+                .setAddress(address)
+                .setSliceId(sliceId)
+                .build();
     }
 
     /**
@@ -117,6 +125,15 @@
     }
 
     /**
+     * Get the slice ID of this interface.
+     *
+     * @return the slice ID
+     */
+    public int sliceId() {
+        return sliceId;
+    }
+
+    /**
      * Check if this UPF interface is for packets traveling from UEs.
      * This will be true for S1U interface table entries.
      *
@@ -187,6 +204,7 @@
     public static class Builder {
         private Ip4Prefix prefix;
         private Type type;
+        private Integer sliceId;
 
         public Builder() {
             type = Type.UNKNOWN;
@@ -204,6 +222,17 @@
         }
 
         /**
+         * Set the slice ID of this interface.
+         *
+         * @param sliceId the slice ID
+         * @return this builder object
+         */
+        public Builder setSliceId(int sliceId) {
+            this.sliceId = sliceId;
+            return this;
+        }
+
+        /**
          * Set the IPv4 prefix of this interface, by turning the given address into a /32 prefix.
          *
          * @param address the interface address that will become a /32 prefix
@@ -245,8 +274,9 @@
         }
 
         public UpfInterface build() {
-            checkNotNull(prefix);
-            return new UpfInterface(prefix, type);
+            checkNotNull(prefix, "The IPv4 prefix must be provided");
+            checkNotNull(sliceId, "Slice ID must be provided");
+            return new UpfInterface(prefix, type, sliceId);
         }
     }
 }