Refactored INT service impl to support multi-instance ONOS and fabric.p4

Change-Id: Ic82a3ab72d71a774606b25997e283b93aedc6ec9
diff --git a/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntConfig.java b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntConfig.java
index a3e6148..c5af580 100644
--- a/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntConfig.java
+++ b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntConfig.java
@@ -30,7 +30,7 @@
     /**
      * Represents a type of telemetry spec to collect in the dataplane.
      */
-    enum TelemetrySpec {
+    public enum TelemetrySpec {
         /**
          * Embeds telemetry metadata according to the INT specification.
          *
diff --git a/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntProgrammable.java b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntProgrammable.java
index 452b787..507f870 100644
--- a/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntProgrammable.java
+++ b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntProgrammable.java
@@ -16,18 +16,64 @@
 package org.onosproject.inbandtelemetry.api;
 
 import com.google.common.annotations.Beta;
+import org.onosproject.net.PortNumber;
 import org.onosproject.net.driver.HandlerBehaviour;
 
-import java.util.concurrent.CompletableFuture;
-
+/**
+ * Abstraction of a device implementing In-band Network Telemetry (INT)
+ * capabilities.
+ */
 @Beta
 public interface IntProgrammable extends HandlerBehaviour {
 
     /**
-     * Initializes the pipeline, by installing required flow rules
-     * not relevant to specific watchlist, report and event.
+     * INT functionalities that a device can implement.
      */
-    void init();
+    enum IntFunctionality {
+        /**
+         * Source functionality.
+         */
+        SOURCE,
+        /**
+         * Sink functionality.
+         */
+        SINK,
+        /**
+         * Transit functionality.
+         */
+        TRANSIT
+    }
+
+    /**
+     * Initializes the pipeline, by installing required flow rules not relevant
+     * to specific watchlist, report and event. Returns true if the operation
+     * was successful, false otherwise.
+     *
+     * @return true if successful, false otherwise
+     */
+    boolean init();
+
+    /**
+     * Configures the given port as an INT source port. Packets received via
+     * this port can be modified to add the INT header, if a corresponding  INT
+     * objective is matched. Returns true if the operation was successful, false
+     * otherwise.
+     *
+     * @param port port
+     * @return true if successful, false otherwise
+     */
+    boolean setSourcePort(PortNumber port);
+
+    /**
+     * Configures the given port as an INT sink port. Packets forwarded via this
+     * port will be stripped of the INT header and a corresponding INT report
+     * will be generated. Returns true if the operation was successful, false
+     * otherwise.
+     *
+     * @param port port
+     * @return true if successful, false otherwise
+     */
+    boolean setSinkPort(PortNumber port);
 
     /**
      * Adds a given IntObjective to the device.
@@ -35,7 +81,7 @@
      * @param obj an IntObjective
      * @return true if the objective is successfully added; false otherwise.
      */
-    CompletableFuture<Boolean> addIntObjective(IntObjective obj);
+    boolean addIntObjective(IntObjective obj);
 
     /**
      * Removes a given IntObjective entry from the device.
@@ -43,7 +89,7 @@
      * @param obj an IntObjective
      * @return true if the objective is successfully removed; false otherwise.
      */
-    CompletableFuture<Boolean> removeIntObjective(IntObjective obj);
+    boolean removeIntObjective(IntObjective obj);
 
     /**
      * Set up report-related configuration.
@@ -51,7 +97,20 @@
      * @param config a configuration regarding to the collector
      * @return true if the objective is successfully added; false otherwise.
      */
-    CompletableFuture<Boolean> setupIntConfig(IntConfig config);
+    boolean setupIntConfig(IntConfig config);
+
+    /**
+     * Clean up any INT-related configuration from the device.
+     */
+    void cleanup();
+
+    /**
+     * Returns true if this device supports the given INT functionality.
+     *
+     * @param functionality INt functionality
+     * @return true if functionality is supported, false otherwise
+     */
+    boolean supportsFunctionality(IntFunctionality functionality);
 
     //TODO: [ONOS-7616] Design IntEvent and related APIs
 }
diff --git a/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntService.java b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntService.java
index ef2e1ad..59e65c3 100644
--- a/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntService.java
+++ b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntService.java
@@ -43,13 +43,13 @@
     }
 
     /**
-     * Starts the INT functionalities in all INT-capable devices.
+     * Starts the INT functionality in all INT-capable devices.
      * This will include populating tables to process INT packets.
      */
     void startInt();
 
     /**
-     * Starts the INT functionalities in specified set of INT transit devices.
+     * Starts the INT functionality in specified set of INT transit devices.
      * <p>
      * Note: this is an experimental API, which can be either changed or removed.
      *
@@ -116,4 +116,4 @@
     Map<IntIntentId, IntIntent> getIntIntents();
 
     //TODO: [ONOS-7616] Design IntEvent and related APIs
-}
\ No newline at end of file
+}