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

Change-Id: Ic82a3ab72d71a774606b25997e283b93aedc6ec9
diff --git a/apps/inbandtelemetry/BUILD b/apps/inbandtelemetry/BUILD
new file mode 100644
index 0000000..3a6d7eb
--- /dev/null
+++ b/apps/inbandtelemetry/BUILD
@@ -0,0 +1,15 @@
+BUNDLES = [
+    "//apps/inbandtelemetry/api:onos-apps-inbandtelemetry-api",
+    "//apps/inbandtelemetry/impl:onos-apps-inbandtelemetry-impl",
+    "//apps/inbandtelemetry/app:onos-apps-inbandtelemetry-app",
+]
+
+onos_app(
+    app_name = "org.onosproject.inbandtelemetry",
+    category = "Monitoring",
+    description = "Provides managements of INT-capable devices. Specifies flows to enable INT and" +
+                  "types of metadata to collect. Sets up INT-related information.",
+    included_bundles = BUNDLES,
+    title = "P4 In-band Network Telemetry Service",
+    url = "http://onosproject.org",
+)
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
+}
diff --git a/apps/inbandtelemetry/app/BUILD b/apps/inbandtelemetry/app/BUILD
new file mode 100644
index 0000000..3391ffa
--- /dev/null
+++ b/apps/inbandtelemetry/app/BUILD
@@ -0,0 +1,11 @@
+COMPILE_DEPS = CORE_DEPS + KRYO + JACKSON + [
+    "//core/store/serializers:onos-core-serializers",
+    "//apps/inbandtelemetry/api:onos-apps-inbandtelemetry-api",
+]
+
+TEST_DEPS = TEST_REST
+
+osgi_jar_with_tests(
+    test_deps = TEST_DEPS,
+    deps = COMPILE_DEPS,
+)
diff --git a/apps/inbandtelemetry/app/src/main/java/org/onosproject/inbandtelemetry/app/IntControl.java b/apps/inbandtelemetry/app/src/main/java/org/onosproject/inbandtelemetry/app/IntControl.java
deleted file mode 100644
index efd3590..0000000
--- a/apps/inbandtelemetry/app/src/main/java/org/onosproject/inbandtelemetry/app/IntControl.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2015-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.inbandtelemetry.app;
-
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.onosproject.core.CoreService;
-import org.onosproject.inbandtelemetry.api.IntService;
-import org.onosproject.net.host.HostService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Component(immediate = true)
-public class IntControl {
-    private final Logger log = LoggerFactory.getLogger(getClass());
-//    private ApplicationId appId;
-//    private static final int collectorPort = 1234;
-//    private static final IpAddress collectorIp = IpAddress.valueOf("10.0.0.3");
-
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    protected CoreService coreService;
-
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    protected IntService intService;
-
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    protected HostService hostService;
-
-    @Activate
-    protected void activate() {
-        coreService.registerApplication("org.onosproject.inbandtelemetry.app");
-        log.info("Started");
-    }
-
-    @Deactivate
-    protected void deactivate() {
-        log.info("Stopped");
-    }
-}
diff --git a/apps/inbandtelemetry/app/src/main/java/org/onosproject/inbandtelemetry/app/package-info.java b/apps/inbandtelemetry/app/src/main/java/org/onosproject/inbandtelemetry/app/package-info.java
deleted file mode 100644
index 859bdf7..0000000
--- a/apps/inbandtelemetry/app/src/main/java/org/onosproject/inbandtelemetry/app/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2015-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.
- */
-
-/**
- * IntService sample application.
- */
-package org.onosproject.inbandtelemetry.app;
diff --git a/apps/inbandtelemetry/app/src/main/resources/app/view/intApp/intApp.css b/apps/inbandtelemetry/app/src/main/resources/app/view/intApp/intApp.css
index 1cfd447..7c2bbe2 100644
--- a/apps/inbandtelemetry/app/src/main/resources/app/view/intApp/intApp.css
+++ b/apps/inbandtelemetry/app/src/main/resources/app/view/intApp/intApp.css
@@ -58,6 +58,10 @@
     text-align: center;
 }
 
+#ov-int-app-main input {
+    padding: 4px;
+    font-size: inherit;
+}
 
 .light #ov-int-app-main .int-app-config-button {
     color: white;
@@ -68,8 +72,25 @@
     background-color: #aaa;
 }
 /*---------------------------------------------------------------------------*/
+#ov-int-app-main hr {
+    border: 0;
+    height: 1px;
+    background: #333;
+}
+
 #ov-int-app-main h2 {
     display: inline-block;
+    margin: 15px 0px 15px;
+}
+
+#ov-int-app-main h3 {
+    display: inline-block;
+    margin-bottom: 10px;
+}
+
+#ov-int-app-main h4 {
+    display: inline-block;
+    margin-bottom: 10px;
 }
 /* #ov-int-app-main .table-body{
     display: inline-block;
diff --git a/apps/inbandtelemetry/app/src/main/resources/app/view/intApp/intApp.html b/apps/inbandtelemetry/app/src/main/resources/app/view/intApp/intApp.html
index 42717e0..8c39cdc 100644
--- a/apps/inbandtelemetry/app/src/main/resources/app/view/intApp/intApp.html
+++ b/apps/inbandtelemetry/app/src/main/resources/app/view/intApp/intApp.html
@@ -1,62 +1,128 @@
 <!-- partial HTML -->
 <div id="ov-int-app-main">
-    <div class="config-panel">
-        <div>
-            Collector IP
-            <input type="text" required pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$" ng-model="collectorIp">
+    <div class="tabular-header">
+        <h2 style="font-weight: bold">In-band Network Telemetry (INT) Control
+            Application</h2>
+    </div>
 
-            Collector Port
-            <input type="text" required pattern="^[0-9]{0,5}$" ng-model="collectorPort">
-        </div>
-    </div>
-    <div class="config-button-panel">
-        <div class = "int-app-config-button" ng-click="sendIntConfigString()">
-            Deploy
-        </div>
-    </div>
     <hr>
-    <div class="input-panel">
-        <div>
-            Src Address
-            <input type="text" required pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}(/[0-9]{1,2})?$" ng-model="ip4SrcPrefix">
 
-            Dst Address
-            <input type="text" required pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}(/[0-9]{1,2})?$" ng-model="ip4DstPrefix">
-
-            Src Port
-            <input type="text" required pattern="^[0-9]{0,5}$" ng-model="l4SrcPort">
-
-            Dst Port
-            <input type="text" required pattern="^[0-9]{0,5}$" ng-model="l4DstPort">
-
-            Protocol
-            <select name="protocol" ng-model="protocol">
-                <option selected disabled hidden style="display: none" value=''></option>
-                <option value="TCP">TCP</option>
-                <option value="UDP">UDP</option>
-            </select>
+    <div class="tabular-header">
+        <h2>
+            INT Collector Configuration
+        </h2>
+        <div class="config-panel">
+            <h3>
+                Collector IPv4 address and UDP port
+            </h3>
+            <div>
+                <input type="text" required
+                       pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"
+                       ng-model="collectorIp" placeholder="IPv4 address">
+                :
+                <input type="text" required pattern="^[0-9]{0,5}$"
+                       ng-model="collectorPort" placeholder="port">
+            </div>
         </div>
-        <div>
-            <input type="checkbox" ng-model= "metaSwId">Switch Id
-            <input type="checkbox" ng-model= "metaPortId">Port Id
-            <input type="checkbox" ng-model= "metaHopLatency">Hop Latency
-            <input type="checkbox" ng-model= "metaQOccupancy">Queue Occupancy
-            <input type="checkbox" ng-model= "metaIngressTstamp">Ingress Timestamp
-            <input type="checkbox" ng-model= "metaEgressTstamp">Egress Timestamp
-            <!--<input type="checkbox" ng-model= "metaQCongestion">Queue Congestion Status-->
-            <input type="checkbox" ng-model= "metaEgressTx">Egress Port Tx Utilization
+        <div class="config-button-panel">
+            <div class="int-app-config-button" ng-click="sendIntConfigString()">
+                Apply Configuration
+            </div>
         </div>
     </div>
 
-    <div class="button-panel">
-        <div class = "int-app-button" ng-click="sendIntIntentString()">
-            Deploy
+    <hr>
+
+    <div class="tabular-header">
+        <h2>
+            INT Watchlist Rules
+        </h2>
+
+        <div>
+            <div class="input-panel">
+                <h3>
+                    Create New Watchlist Rule
+                </h3>
+                <div>
+                    <label>
+                        <input placeholder="Source IP address" type="text"
+                               required
+                               pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}(/[0-9]{1,2})?$"
+                               ng-model="ip4SrcPrefix">
+                    </label>
+                    <label>
+                        <input placeholder="Dest IP address" type="text"
+                               required
+                               pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}(/[0-9]{1,2})?$"
+                               ng-model="ip4DstPrefix">
+                    </label>
+                    <label>
+                        <input placeholder="Source port" type="text" required
+                               pattern="^[0-9]{0,5}$"
+                               ng-model="l4SrcPort">
+                    </label>
+                    <label>
+                        <input placeholder="Dest port" type="text" required
+                               pattern="^[0-9]{0,5}$"
+                               ng-model="l4DstPort">
+                    </label>
+                    <label>
+                        Protocol
+                        <select name="protocol" ng-model="protocol">
+                            <option selected disabled hidden
+                                    style="display: none" value=''></option>
+                            <option value="TCP">TCP</option>
+                            <option value="UDP">UDP</option>
+                        </select>
+                    </label>
+                </div>
+                <div>
+                    <label>
+                        <input type="checkbox" ng-model="metaSwId">
+                        Switch ID
+                    </label>
+                    <label>
+                        <input type="checkbox" ng-model="metaPortId">
+                        Port IDs
+                    </label>
+                    <label>
+                        <input type="checkbox" ng-model="metaHopLatency">
+                        Hop Latency
+                    </label>
+                    <label>
+                        <input type="checkbox" ng-model="metaQOccupancy">
+                        Queue Occupancy
+                    </label>
+                    <label>
+                        <input type="checkbox" ng-model="metaIngressTstamp">
+                        Ingress Timestamp
+                    </label>
+                    <label>
+                        <input type="checkbox" ng-model="metaEgressTstamp">
+                        Egress Timestamp
+                    </label>
+                    <label>
+                        <input type="checkbox" ng-model="metaQCongestion">
+                        Queue Congestion Status
+                    </label>
+                    <label>
+                        <input type="checkbox" ng-model="metaEgressTx">
+                        Egress Port Tx Utilization
+                    </label>
+                </div>
+            </div>
+        </div>
+
+        <div class="button-panel">
+            <div class="int-app-button" ng-click="sendIntIntentString()">
+                Apply Watchlist Rule
+            </div>
         </div>
     </div>
     <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
     <div class='int-app-main-intents'>
         <div class="tabular-header">
-            <h2>Installed INT Intents ({{tableData.length}} total)</h2>
+            <h2>Installed Watchlist Rules ({{tableData.length}} total)</h2>
             <div class="ctrl-btns">
                 <div class="refresh" ng-class="{active: autoRefresh}"
                      icon icon-id="refresh" icon-size="36"
@@ -77,13 +143,13 @@
             <div class="table-header" onos-sortable-header>
                 <table>
                     <tr>
-                        <td colId="id" sortable>ID </td>
-                        <td colId="srcAddr" sortable>Src Address </td>
-                        <td colId="dstAddr" sortable>Dst Address </td>
-                        <td colId="srcPort" sortable>Src Port </td>
-                        <td colId="dstPort" sortable>Dst Port </td>
-                        <td colId="protocol" sortable>Protocol </td>
-                        <td colId="metadata" sortable>Metadata </td>
+                        <td colId="id" sortable>ID</td>
+                        <td colId="srcAddr" sortable>Src Address</td>
+                        <td colId="dstAddr" sortable>Dst Address</td>
+                        <td colId="srcPort" sortable>Src Port</td>
+                        <td colId="dstPort" sortable>Dst Port</td>
+                        <td colId="protocol" sortable>Protocol</td>
+                        <td colId="metadata" sortable>Metadata</td>
                     </tr>
                 </table>
             </div>
diff --git a/apps/inbandtelemetry/impl/BUILD b/apps/inbandtelemetry/impl/BUILD
new file mode 100644
index 0000000..b3a1d46
--- /dev/null
+++ b/apps/inbandtelemetry/impl/BUILD
@@ -0,0 +1,12 @@
+COMPILE_DEPS = CORE_DEPS + KRYO + [
+    "//core/store/serializers:onos-core-serializers",
+    "//pipelines/basic:onos-pipelines-basic",
+    "//apps/inbandtelemetry/api:onos-apps-inbandtelemetry-api",
+]
+
+TEST_DEPS = TEST_ADAPTERS
+
+osgi_jar_with_tests(
+    test_deps = TEST_DEPS,
+    deps = COMPILE_DEPS,
+)
diff --git a/apps/inbandtelemetry/impl/src/main/java/org/onosproject/inbandtelemetry/impl/IntManager.java b/apps/inbandtelemetry/impl/src/main/java/org/onosproject/inbandtelemetry/impl/IntManager.java
deleted file mode 100644
index 5cf32da..0000000
--- a/apps/inbandtelemetry/impl/src/main/java/org/onosproject/inbandtelemetry/impl/IntManager.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * Copyright 2015-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.inbandtelemetry.impl;
-
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.apache.felix.scr.annotations.Service;
-import org.onlab.util.KryoNamespace;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.inbandtelemetry.api.IntConfig;
-import org.onosproject.inbandtelemetry.api.IntIntent;
-import org.onosproject.inbandtelemetry.api.IntIntentId;
-import org.onosproject.inbandtelemetry.api.IntObjective;
-import org.onosproject.inbandtelemetry.api.IntProgrammable;
-import org.onosproject.inbandtelemetry.api.IntService;
-import org.onosproject.net.Device;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.flow.FlowRuleService;
-import org.onosproject.net.host.HostEvent;
-import org.onosproject.net.host.HostListener;
-import org.onosproject.net.host.HostService;
-import org.onosproject.store.serializers.KryoNamespaces;
-import org.onosproject.store.service.AtomicIdGenerator;
-import org.onosproject.store.service.ConsistentMap;
-import org.onosproject.store.service.Serializer;
-import org.onosproject.store.service.StorageService;
-import org.slf4j.Logger;
-
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * Implementation of IntService, for controlling INT-capable pipelines.
- */
-@Component(immediate = true)
-@Service
-public class IntManager implements IntService {
-    private final String appName = "org.onosproject.inbandtelemetry";
-    private ApplicationId appId;
-    private final Logger log = getLogger(getClass());
-    private ConsistentMap<IntIntentId, IntIntent> intentConsistentMap;
-    private ConsistentMap<DeviceId, IntDeviceRole> deviceRoleConsistentMap;
-    private IntConfig cfg;
-    private AtomicIdGenerator intentIds;
-
-    private InternalHostListener hostListener = new InternalHostListener();
-
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    private CoreService coreService;
-
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    private DeviceService deviceService;
-
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    private StorageService storageService;
-
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    private HostService hostService;
-
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    private FlowRuleService flowRuleService;
-
-    @Activate
-    public void activate() {
-        appId = coreService.registerApplication(appName);
-
-        KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
-                .register(KryoNamespaces.API)
-                .register(IntIntent.class)
-                .register(IntIntentId.class)
-                .register(IntDeviceRole.class)
-                .register(IntIntent.IntHeaderType.class)
-                .register(IntIntent.IntMetadataType.class)
-                .register(IntIntent.IntReportType.class)
-                .register(IntIntent.TelemetryMode.class);
-
-        intentConsistentMap = storageService.<IntIntentId, IntIntent>consistentMapBuilder()
-                .withSerializer(Serializer.using(serializer.build()))
-                .withName("int-intents")
-                .withApplicationId(appId)
-                .withPurgeOnUninstall()
-                .build();
-
-        deviceRoleConsistentMap = storageService.<DeviceId, IntDeviceRole>consistentMapBuilder()
-                .withSerializer(Serializer.using(serializer.build()))
-                .withName("int-device-roles")
-                .withApplicationId(appId)
-                .withPurgeOnUninstall()
-                .build();
-
-        // Assign IntDeviceRole to each device
-        deviceService.getAvailableDevices().forEach(device ->
-                deviceRoleConsistentMap.put(device.id(),
-                                            hostService.getConnectedHosts(device.id()).isEmpty() ?
-                                                    IntDeviceRole.TRANSIT :
-                                                    IntDeviceRole.SOURCE_SINK)
-        );
-        hostService.addListener(hostListener);
-        intentIds = storageService.getAtomicIdGenerator("int-intent-id-generator");
-        startInt();
-        log.info("Started", appId.id());
-    }
-
-    @Deactivate
-    public void deactivate() {
-        hostService.removeListener(hostListener);
-        log.info("Deactivated");
-    }
-
-    @Override
-    public void startInt() {
-        deviceService.getAvailableDevices().forEach(device -> {
-            if (device.is(IntProgrammable.class)) {
-                IntProgrammable intDevice = device.as(IntProgrammable.class);
-                intDevice.init();
-            }
-        });
-    }
-
-    @Override
-    public void startInt(Set<DeviceId> deviceIds) {
-        deviceIds.forEach(deviceId -> {
-            Device device = deviceService.getDevice(deviceId);
-            if (device.is(IntProgrammable.class) &&
-                    getIntRole(deviceId) == IntDeviceRole.TRANSIT) {
-                IntProgrammable intDevice = device.as(IntProgrammable.class);
-                intDevice.init();
-            }
-        });
-    }
-
-    @Override
-    public void stopInt() {
-        flowRuleService.removeFlowRulesById(appId);
-    }
-
-    @Override
-    public void stopInt(Set<DeviceId> deviceIds) {
-
-    }
-
-    @Override
-    public void setConfig(IntConfig cfg) {
-        this.cfg = cfg;
-        deviceService.getAvailableDevices().forEach(device -> {
-            if (device.is(IntProgrammable.class)) {
-                IntProgrammable intDevice = device.as(IntProgrammable.class);
-                intDevice.setupIntConfig(cfg);
-            }
-        });
-    }
-
-    @Override
-    public IntConfig getConfig() {
-        return cfg;
-    }
-
-    @Override
-    public IntIntentId installIntIntent(IntIntent intent) {
-        Integer intentId = (int) intentIds.nextId();
-        IntIntentId intIntentId = IntIntentId.valueOf(intentId);
-        intentConsistentMap.put(intIntentId, intent);
-
-        // Convert IntIntent into an IntObjective
-        IntObjective obj = new IntObjective.Builder()
-                .withSelector(intent.selector())
-                .withMetadataTypes(intent.metadataTypes())
-                .withHeaderType(intent.headerType())
-                .build();
-
-        // Install IntObjective on each INT source device
-        deviceService.getAvailableDevices().forEach(device -> {
-            if (device.is(IntProgrammable.class)
-                    && deviceRoleConsistentMap.get(device.id()).value() == IntDeviceRole.SOURCE_SINK) {
-                IntProgrammable intDevice = device.as(IntProgrammable.class);
-                intDevice.addIntObjective(obj);
-            }
-        });
-        return intIntentId;
-    }
-
-    @Override
-    public void removeIntIntent(IntIntentId intentId) {
-        IntIntent intent = intentConsistentMap.remove(intentId).value();
-
-        // Convert IntIntent into an IntObjective
-        IntObjective obj = new IntObjective.Builder()
-                .withSelector(intent.selector())
-                .withMetadataTypes(intent.metadataTypes())
-                .withHeaderType(intent.headerType())
-                .build();
-
-        // Remove IntObjective on each INT source device
-        deviceService.getAvailableDevices().forEach(device -> {
-            if (device.is(IntProgrammable.class)
-                    && deviceRoleConsistentMap.get(device.id()).value() == IntDeviceRole.SOURCE_SINK) {
-                IntProgrammable intDevice = device.as(IntProgrammable.class);
-                intDevice.removeIntObjective(obj);
-            }
-        });
-    }
-
-    @Override
-    public IntIntent getIntIntent(IntIntentId intentId) {
-        return Optional.ofNullable(intentConsistentMap.get(intentId).value()).orElse(null);
-    }
-
-    @Override
-    public Map<IntIntentId, IntIntent> getIntIntents() {
-        return intentConsistentMap.asJavaMap();
-    }
-
-    private IntDeviceRole getIntRole(DeviceId deviceId) {
-        return deviceRoleConsistentMap.get(deviceId).value();
-    }
-
-    private void setIntRole(DeviceId deviceId, IntDeviceRole role) {
-        deviceRoleConsistentMap.put(deviceId, role);
-    }
-
-    private class InternalHostListener implements HostListener {
-        @Override
-        public void event(HostEvent event) {
-            DeviceId deviceId = event.subject().location().deviceId();
-            if (!deviceService.getDevice(deviceId).is(IntProgrammable.class)) {
-                return;
-            }
-            switch (event.type()) {
-                case HOST_ADDED:
-                    // When a host is attached to the switch, we can configure it
-                    // to work as SOURCE_SINK switch.
-                    if (deviceRoleConsistentMap.getOrDefault(deviceId, IntDeviceRole.TRANSIT).value()
-                            != IntDeviceRole.SOURCE_SINK) {
-                        setIntRole(deviceId, IntDeviceRole.SOURCE_SINK);
-                    }
-                    break;
-                default:
-                    break;
-            }
-        }
-    }
-
-}
diff --git a/apps/inbandtelemetry/impl/src/main/java/org/onosproject/inbandtelemetry/impl/SimpleIntManager.java b/apps/inbandtelemetry/impl/src/main/java/org/onosproject/inbandtelemetry/impl/SimpleIntManager.java
new file mode 100644
index 0000000..56ee52b
--- /dev/null
+++ b/apps/inbandtelemetry/impl/src/main/java/org/onosproject/inbandtelemetry/impl/SimpleIntManager.java
@@ -0,0 +1,527 @@
+/*
+ * Copyright 2015-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.inbandtelemetry.impl;
+
+import com.google.common.collect.Maps;
+import com.google.common.util.concurrent.Striped;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onlab.util.KryoNamespace;
+import org.onlab.util.SharedScheduledExecutors;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.inbandtelemetry.api.IntConfig;
+import org.onosproject.inbandtelemetry.api.IntIntent;
+import org.onosproject.inbandtelemetry.api.IntIntentId;
+import org.onosproject.inbandtelemetry.api.IntObjective;
+import org.onosproject.inbandtelemetry.api.IntProgrammable;
+import org.onosproject.inbandtelemetry.api.IntService;
+import org.onosproject.mastership.MastershipService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.MastershipRole;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DeviceEvent;
+import org.onosproject.net.device.DeviceListener;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.host.HostEvent;
+import org.onosproject.net.host.HostListener;
+import org.onosproject.net.host.HostService;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.AtomicIdGenerator;
+import org.onosproject.store.service.AtomicValue;
+import org.onosproject.store.service.AtomicValueEvent;
+import org.onosproject.store.service.AtomicValueEventListener;
+import org.onosproject.store.service.ConsistentMap;
+import org.onosproject.store.service.MapEvent;
+import org.onosproject.store.service.MapEventListener;
+import org.onosproject.store.service.Serializer;
+import org.onosproject.store.service.StorageService;
+import org.onosproject.store.service.Versioned;
+import org.slf4j.Logger;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.locks.Lock;
+import java.util.stream.Collectors;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Simple implementation of IntService, for controlling INT-capable pipelines.
+ * <p>
+ * All INT intents are converted to an equivalent INT objective and applied to
+ * all SOURCE_SINK devices. A device is deemed SOURCE_SINK if it has at least
+ * one host attached.
+ * <p>
+ * The implementation listens for different types of events and when required it
+ * configures a device by cleaning-up any previous state and applying the new
+ * one.
+ */
+@Component(immediate = true)
+@Service
+public class SimpleIntManager implements IntService {
+
+    private final Logger log = getLogger(getClass());
+
+    private static final int CONFIG_EVENT_DELAY = 5; // Seconds.
+
+    private static final String APP_NAME = "org.onosproject.inbandtelemetry";
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    private CoreService coreService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    private DeviceService deviceService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    private StorageService storageService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    private MastershipService mastershipService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    private HostService hostService;
+
+    private final Striped<Lock> deviceLocks = Striped.lock(10);
+
+    private final ConcurrentMap<DeviceId, ScheduledFuture<?>> scheduledDeviceTasks = Maps.newConcurrentMap();
+
+    // Distributed state.
+    private ConsistentMap<IntIntentId, IntIntent> intentMap;
+    private ConsistentMap<DeviceId, Long> devicesToConfigure;
+    private AtomicValue<IntConfig> intConfig;
+    private AtomicValue<Boolean> intStarted;
+    private AtomicIdGenerator intentIds;
+
+    // Event listeners.
+    private final InternalHostListener hostListener = new InternalHostListener();
+    private final InternalDeviceListener deviceListener = new InternalDeviceListener();
+    private final InternalIntentMapListener intentMapListener = new InternalIntentMapListener();
+    private final InternalIntConfigListener intConfigListener = new InternalIntConfigListener();
+    private final InternalIntStartedListener intStartedListener = new InternalIntStartedListener();
+    private final InternalDeviceToConfigureListener devicesToConfigureListener =
+            new InternalDeviceToConfigureListener();
+
+    @Activate
+    public void activate() {
+
+        final ApplicationId appId = coreService.registerApplication(APP_NAME);
+
+        KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
+                .register(KryoNamespaces.API)
+                .register(IntIntent.class)
+                .register(IntIntentId.class)
+                .register(IntDeviceRole.class)
+                .register(IntIntent.IntHeaderType.class)
+                .register(IntIntent.IntMetadataType.class)
+                .register(IntIntent.IntReportType.class)
+                .register(IntIntent.TelemetryMode.class)
+                .register(IntConfig.class)
+                .register(IntConfig.TelemetrySpec.class);
+
+        devicesToConfigure = storageService.<DeviceId, Long>consistentMapBuilder()
+                .withSerializer(Serializer.using(serializer.build()))
+                .withName("onos-int-devices-to-configure")
+                .withApplicationId(appId)
+                .withPurgeOnUninstall()
+                .build();
+        devicesToConfigure.addListener(devicesToConfigureListener);
+
+        intentMap = storageService.<IntIntentId, IntIntent>consistentMapBuilder()
+                .withSerializer(Serializer.using(serializer.build()))
+                .withName("onos-int-intents")
+                .withApplicationId(appId)
+                .withPurgeOnUninstall()
+                .build();
+        intentMap.addListener(intentMapListener);
+
+        intStarted = storageService.<Boolean>atomicValueBuilder()
+                .withSerializer(Serializer.using(serializer.build()))
+                .withName("onos-int-started")
+                .withApplicationId(appId)
+                .build()
+                .asAtomicValue();
+        intStarted.addListener(intStartedListener);
+
+        intConfig = storageService.<IntConfig>atomicValueBuilder()
+                .withSerializer(Serializer.using(serializer.build()))
+                .withName("onos-int-config")
+                .withApplicationId(appId)
+                .build()
+                .asAtomicValue();
+        intConfig.addListener(intConfigListener);
+
+        intentIds = storageService.getAtomicIdGenerator("int-intent-id-generator");
+
+        // Bootstrap config for already existing devices.
+        triggerAllDeviceConfigure();
+
+        hostService.addListener(hostListener);
+        deviceService.addListener(deviceListener);
+
+        startInt();
+        log.info("Started", appId.id());
+    }
+
+    @Deactivate
+    public void deactivate() {
+        deviceService.removeListener(deviceListener);
+        hostService.removeListener(hostListener);
+        intentIds = null;
+        intConfig.removeListener(intConfigListener);
+        intConfig = null;
+        intStarted.removeListener(intStartedListener);
+        intStarted = null;
+        intentMap.removeListener(intentMapListener);
+        intentMap = null;
+        devicesToConfigure.removeListener(devicesToConfigureListener);
+        devicesToConfigure.destroy();
+        devicesToConfigure = null;
+        // Cancel tasks (if any).
+        scheduledDeviceTasks.values().forEach(f -> {
+            f.cancel(true);
+            if (!f.isDone()) {
+                try {
+                    f.get(1, TimeUnit.SECONDS);
+                } catch (InterruptedException | ExecutionException | TimeoutException e) {
+                    // Don't care, we are terminating the service anyways.
+                }
+            }
+        });
+        // Clean up INT rules from existing devices.
+        deviceService.getDevices().forEach(d -> cleanupDevice(d.id()));
+        log.info("Deactivated");
+    }
+
+    @Override
+    public void startInt() {
+        // Atomic value event will trigger device configure.
+        intStarted.set(true);
+    }
+
+    @Override
+    public void startInt(Set<DeviceId> deviceIds) {
+        log.warn("Starting INT for a subset of devices is not supported");
+    }
+
+    @Override
+    public void stopInt() {
+        // Atomic value event will trigger device configure.
+        intStarted.set(false);
+    }
+
+    @Override
+    public void stopInt(Set<DeviceId> deviceIds) {
+        log.warn("Stopping INT for a subset of devices is not supported");
+    }
+
+    @Override
+    public void setConfig(IntConfig cfg) {
+        checkNotNull(cfg);
+        // Atomic value event will trigger device configure.
+        intConfig.set(cfg);
+    }
+
+    @Override
+    public IntConfig getConfig() {
+        return intConfig.get();
+    }
+
+    @Override
+    public IntIntentId installIntIntent(IntIntent intent) {
+        checkNotNull(intent);
+        final Integer intentId = (int) intentIds.nextId();
+        final IntIntentId intIntentId = IntIntentId.valueOf(intentId);
+        // Intent map event will trigger device configure.
+        intentMap.put(intIntentId, intent);
+        return intIntentId;
+    }
+
+    @Override
+    public void removeIntIntent(IntIntentId intentId) {
+        checkNotNull(intentId);
+        // Intent map event will trigger device configure.
+        intentMap.remove(intentId).value();
+    }
+
+    @Override
+    public IntIntent getIntIntent(IntIntentId intentId) {
+        return Optional.ofNullable(intentMap.get(intentId).value()).orElse(null);
+    }
+
+    @Override
+    public Map<IntIntentId, IntIntent> getIntIntents() {
+        return intentMap.asJavaMap();
+    }
+
+    private boolean isConfigTaskValid(DeviceId deviceId, long creationTime) {
+        Versioned<?> versioned = devicesToConfigure.get(deviceId);
+        return versioned != null && versioned.creationTime() == creationTime;
+    }
+
+    private boolean isIntStarted() {
+        return intStarted.get();
+    }
+
+    private boolean isNotIntConfigured() {
+        return intConfig.get() == null;
+    }
+
+    private boolean isIntProgrammable(DeviceId deviceId) {
+        final Device device = deviceService.getDevice(deviceId);
+        return device != null && device.is(IntProgrammable.class);
+    }
+
+    private void triggerDeviceConfigure(DeviceId deviceId) {
+        if (isIntProgrammable(deviceId)) {
+            devicesToConfigure.put(deviceId, System.nanoTime());
+        }
+    }
+
+    private void triggerAllDeviceConfigure() {
+        deviceService.getDevices().forEach(d -> triggerDeviceConfigure(d.id()));
+    }
+
+    private void configDeviceTask(DeviceId deviceId, long creationTime) {
+        if (isConfigTaskValid(deviceId, creationTime)) {
+            // Task outdated.
+            return;
+        }
+        if (!deviceService.isAvailable(deviceId)) {
+            return;
+        }
+        final MastershipRole role = mastershipService.requestRoleForSync(deviceId);
+        if (!role.equals(MastershipRole.MASTER)) {
+            return;
+        }
+        deviceLocks.get(deviceId).lock();
+        try {
+            // Clean up first.
+            cleanupDevice(deviceId);
+            if (!configDevice(deviceId)) {
+                // Clean up if fails.
+                cleanupDevice(deviceId);
+                return;
+            }
+            devicesToConfigure.remove(deviceId);
+        } finally {
+            deviceLocks.get(deviceId).unlock();
+        }
+    }
+
+    private void cleanupDevice(DeviceId deviceId) {
+        final Device device = deviceService.getDevice(deviceId);
+        if (device == null || !device.is(IntProgrammable.class)) {
+            return;
+        }
+        device.as(IntProgrammable.class).cleanup();
+    }
+
+    private boolean configDevice(DeviceId deviceId) {
+        // Returns true if config was successful, false if not and a clean up is
+        // needed.
+        final Device device = deviceService.getDevice(deviceId);
+        if (device == null || !device.is(IntProgrammable.class)) {
+            return true;
+        }
+
+        if (isNotIntConfigured()) {
+            log.warn("Missing INT config, aborting programming of INT device {}", deviceId);
+            return true;
+        }
+
+        final boolean isEdge = !hostService.getConnectedHosts(deviceId).isEmpty();
+        final IntDeviceRole intDeviceRole = isEdge
+                ? IntDeviceRole.SOURCE_SINK
+                : IntDeviceRole.TRANSIT;
+
+        log.info("Started programming of INT device {} with role {}...",
+                 deviceId, intDeviceRole);
+
+        final IntProgrammable intProg = device.as(IntProgrammable.class);
+
+        if (!isIntStarted()) {
+            // Leave device with no INT configuration.
+            return true;
+        }
+
+        if (!intProg.init()) {
+            log.warn("Unable to init INT pipeline on {}", deviceId);
+            return false;
+        }
+
+        if (intDeviceRole != IntDeviceRole.SOURCE_SINK) {
+            // Stop here, no more configuration needed for transit devices.
+            return true;
+        }
+
+        if (intProg.supportsFunctionality(IntProgrammable.IntFunctionality.SINK)) {
+            if (!intProg.setupIntConfig(intConfig.get())) {
+                log.warn("Unable to apply INT report config on {}", deviceId);
+                return false;
+            }
+        }
+
+        // Port configuration.
+        final Set<PortNumber> hostPorts = deviceService.getPorts(deviceId)
+                .stream()
+                .map(port -> new ConnectPoint(deviceId, port.number()))
+                .filter(cp -> !hostService.getConnectedHosts(cp).isEmpty())
+                .map(ConnectPoint::port)
+                .collect(Collectors.toSet());
+
+        for (PortNumber port : hostPorts) {
+            if (intProg.supportsFunctionality(IntProgrammable.IntFunctionality.SOURCE)) {
+                log.info("Setting port {}/{} as INT source port...", deviceId, port);
+                if (!intProg.setSourcePort(port)) {
+                    log.warn("Unable to set INT source port {} on {}", port, deviceId);
+                    return false;
+                }
+            }
+            if (intProg.supportsFunctionality(IntProgrammable.IntFunctionality.SINK)) {
+                log.info("Setting port {}/{} as INT sink port...", deviceId, port);
+                if (!intProg.setSinkPort(port)) {
+                    log.warn("Unable to set INT sink port {} on {}", port, deviceId);
+                    return false;
+                }
+            }
+        }
+
+        if (!intProg.supportsFunctionality(IntProgrammable.IntFunctionality.SOURCE)) {
+            // Stop here, no more configuration needed for sink devices.
+            return true;
+        }
+
+        // Apply intents.
+        // This is a trivial implementation where we simply get the
+        // corresponding INT objective from an intent and we apply to all source
+        // device.
+        final Collection<IntObjective> objectives = intentMap.values().stream()
+                .map(v -> getIntObjective(v.value()))
+                .collect(Collectors.toList());
+        int appliedCount = 0;
+        for (IntObjective objective : objectives) {
+            if (intProg.addIntObjective(objective)) {
+                appliedCount = appliedCount + 1;
+            }
+        }
+
+        log.info("Completed programming of {}, applied {} INT objectives of {} total",
+                 deviceId, appliedCount, objectives.size());
+
+        return true;
+    }
+
+    private IntObjective getIntObjective(IntIntent intent) {
+        return new IntObjective.Builder()
+                .withSelector(intent.selector())
+                .withMetadataTypes(intent.metadataTypes())
+                .withHeaderType(intent.headerType())
+                .build();
+    }
+
+    /* Event listeners which trigger device configuration. */
+
+    private class InternalHostListener implements HostListener {
+        @Override
+        public void event(HostEvent event) {
+            final DeviceId deviceId = event.subject().location().deviceId();
+            triggerDeviceConfigure(deviceId);
+        }
+    }
+
+    private class InternalDeviceListener implements DeviceListener {
+        @Override
+        public void event(DeviceEvent event) {
+            switch (event.type()) {
+                case DEVICE_ADDED:
+                case DEVICE_UPDATED:
+                case DEVICE_REMOVED:
+                case DEVICE_SUSPENDED:
+                case DEVICE_AVAILABILITY_CHANGED:
+                case PORT_ADDED:
+                case PORT_UPDATED:
+                case PORT_REMOVED:
+                    triggerDeviceConfigure(event.subject().id());
+                    return;
+                case PORT_STATS_UPDATED:
+                    return;
+                default:
+                    log.warn("Unknown device event type {}", event.type());
+            }
+        }
+    }
+
+    private class InternalIntentMapListener
+            implements MapEventListener<IntIntentId, IntIntent> {
+        @Override
+        public void event(MapEvent<IntIntentId, IntIntent> event) {
+            triggerAllDeviceConfigure();
+        }
+    }
+
+    private class InternalIntConfigListener
+            implements AtomicValueEventListener<IntConfig> {
+        @Override
+        public void event(AtomicValueEvent<IntConfig> event) {
+            triggerAllDeviceConfigure();
+        }
+    }
+
+    private class InternalIntStartedListener
+            implements AtomicValueEventListener<Boolean> {
+        @Override
+        public void event(AtomicValueEvent<Boolean> event) {
+            triggerAllDeviceConfigure();
+        }
+    }
+
+    private class InternalDeviceToConfigureListener
+            implements MapEventListener<DeviceId, Long> {
+        @Override
+        public void event(MapEvent<DeviceId, Long> event) {
+            if (event.type().equals(MapEvent.Type.REMOVE) ||
+                    event.newValue() == null) {
+                return;
+            }
+            // Schedule task in the future. Wait for events for this device to
+            // stabilize.
+            final DeviceId deviceId = event.key();
+            final long creationTime = event.newValue().creationTime();
+            ScheduledFuture<?> newTask = SharedScheduledExecutors.newTimeout(
+                    () -> configDeviceTask(deviceId, creationTime),
+                    CONFIG_EVENT_DELAY, TimeUnit.SECONDS);
+            ScheduledFuture<?> oldTask = scheduledDeviceTasks.put(deviceId, newTask);
+            if (oldTask != null) {
+                oldTask.cancel(false);
+            }
+        }
+    }
+}
diff --git a/modules.bzl b/modules.bzl
index 37229ee..8c9110e 100644
--- a/modules.bzl
+++ b/modules.bzl
@@ -249,6 +249,7 @@
     "//apps/layout:onos-apps-layout-oar",
     "//apps/imr:onos-apps-imr-oar",
     "//apps/nodemetrics:onos-apps-nodemetrics-oar",
+    "//apps/inbandtelemetry:onos-apps-inbandtelemetry-oar",
     # "//web/gui2:onos-web-gui2-oar",
     "//apps/workflow:onos-apps-workflow-oar",
 ]
diff --git a/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/IntProgrammableImpl.java b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/IntProgrammableImpl.java
index 417043d..5ed475a 100644
--- a/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/IntProgrammableImpl.java
+++ b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/IntProgrammableImpl.java
@@ -20,24 +20,21 @@
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.onlab.util.ImmutableByteSequence;
-import org.onlab.util.SharedExecutors;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
 import org.onosproject.inbandtelemetry.api.IntConfig;
 import org.onosproject.inbandtelemetry.api.IntIntent;
 import org.onosproject.inbandtelemetry.api.IntObjective;
 import org.onosproject.inbandtelemetry.api.IntProgrammable;
-import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DeviceId;
-import org.onosproject.net.Port;
 import org.onosproject.net.PortNumber;
-import org.onosproject.net.device.DeviceService;
 import org.onosproject.net.driver.AbstractHandlerBehaviour;
 import org.onosproject.net.flow.DefaultFlowRule;
 import org.onosproject.net.flow.DefaultTrafficSelector;
 import org.onosproject.net.flow.DefaultTrafficTreatment;
 import org.onosproject.net.flow.FlowRule;
 import org.onosproject.net.flow.FlowRuleService;
+import org.onosproject.net.flow.TableId;
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
 import org.onosproject.net.flow.criteria.Criterion;
@@ -45,7 +42,6 @@
 import org.onosproject.net.flow.criteria.PiCriterion;
 import org.onosproject.net.flow.criteria.TcpPortCriterion;
 import org.onosproject.net.flow.criteria.UdpPortCriterion;
-import org.onosproject.net.host.HostService;
 import org.onosproject.net.pi.model.PiActionId;
 import org.onosproject.net.pi.model.PiMatchFieldId;
 import org.onosproject.net.pi.model.PiTableId;
@@ -53,11 +49,9 @@
 import org.onosproject.net.pi.runtime.PiActionParam;
 import org.slf4j.Logger;
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Set;
-import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
 
 import static org.slf4j.LoggerFactory.getLogger;
 
@@ -79,16 +73,19 @@
             Criterion.Type.TCP_SRC, Criterion.Type.TCP_DST,
             Criterion.Type.IP_PROTO);
 
+    private static final Set<PiTableId> TABLES_TO_CLEANUP = Sets.newHashSet(
+            IntConstants.TBL_INT_INSERT_ID,
+            IntConstants.TBL_INT_INST_0003_ID,
+            IntConstants.TBL_INT_INST_0407_ID,
+            IntConstants.TBL_SET_SOURCE_ID,
+            IntConstants.TBL_SET_SINK_ID,
+            IntConstants.TBL_INT_SOURCE_ID,
+            IntConstants.TBL_GENERATE_REPORT_ID);
+
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     private FlowRuleService flowRuleService;
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    private DeviceService deviceService;
-
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    private HostService hostService;
-
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     private CoreService coreService;
 
     private DeviceId deviceId;
@@ -134,23 +131,16 @@
                     .build();
 
     @Override
-    public void init() {
+    public boolean init() {
         deviceId = this.data().deviceId();
         flowRuleService = handler().get(FlowRuleService.class);
-        deviceService = handler().get(DeviceService.class);
-        hostService = handler().get(HostService.class);
         coreService = handler().get(CoreService.class);
         appId = coreService.getAppId(PIPELINE_APP_NAME);
         if (appId == null) {
             log.warn("Application ID is null. Cannot initialize INT-pipeline.");
-            return;
+            return false;
         }
 
-        Set<PortNumber> hostPorts = deviceService.getPorts(deviceId).stream().filter(port ->
-             hostService.getConnectedHosts(new ConnectPoint(deviceId, port.number())).size() > 0
-        ).map(Port::number).collect(Collectors.toSet());
-        List<FlowRule> flowRules = new ArrayList<>();
-
         // process_int_transit.tb_int_insert
         PiActionParam transitIdParam = new PiActionParam(
                 IntConstants.ACT_PRM_SWITCH_ID,
@@ -173,58 +163,8 @@
                 .forDevice(deviceId)
                 .forTable(IntConstants.TBL_INT_INSERT_ID)
                 .build();
-        flowRules.add(transitFlowRule);
 
-        for (PortNumber portNumber: hostPorts) {
-            // process_set_source_sink.tb_set_source for each host-facing port
-            PiCriterion ingressCriterion = PiCriterion.builder()
-                    .matchExact(BasicConstants.HDR_IN_PORT_ID, portNumber.toLong())
-                    .build();
-            TrafficSelector srcSelector = DefaultTrafficSelector.builder()
-                    .matchPi(ingressCriterion)
-                    .build();
-            PiAction setSourceAct = PiAction.builder()
-                    .withId(IntConstants.ACT_INT_SET_SOURCE_ID)
-                    .build();
-            TrafficTreatment srcTreatment = DefaultTrafficTreatment.builder()
-                    .piTableAction(setSourceAct)
-                    .build();
-            FlowRule srcFlowRule = DefaultFlowRule.builder()
-                    .withSelector(srcSelector)
-                    .withTreatment(srcTreatment)
-                    .fromApp(appId)
-                    .withPriority(DEFAULT_PRIORITY)
-                    .makePermanent()
-                    .forDevice(deviceId)
-                    .forTable(IntConstants.TBL_SET_SOURCE_ID)
-                    .build();
-            flowRules.add(srcFlowRule);
-
-            // process_set_source_sink.tb_set_sink
-            PiCriterion egressCriterion = PiCriterion.builder()
-                    .matchExact(IntConstants.HDR_OUT_PORT_ID, portNumber.toLong())
-                    .build();
-            TrafficSelector sinkSelector = DefaultTrafficSelector.builder()
-                    .matchPi(egressCriterion)
-                    .build();
-            PiAction setSinkAct = PiAction.builder()
-                    .withId(IntConstants.ACT_INT_SET_SINK_ID)
-                    .build();
-            TrafficTreatment sinkTreatment = DefaultTrafficTreatment.builder()
-                    .piTableAction(setSinkAct)
-                    .build();
-            FlowRule sinkFlowRule = DefaultFlowRule.builder()
-                    .withSelector(sinkSelector)
-                    .withTreatment(sinkTreatment)
-                    .fromApp(appId)
-                    .withPriority(DEFAULT_PRIORITY)
-                    .makePermanent()
-                    .forDevice(deviceId)
-                    .forTable(IntConstants.TBL_SET_SINK_ID)
-                    .build();
-            flowRules.add(sinkFlowRule);
-        }
-        flowRules.forEach(flowRule -> flowRuleService.applyFlowRules(flowRule));
+        flowRuleService.applyFlowRules(transitFlowRule);
 
         // Populate tb_int_inst_0003 table
         INST_0003_ACTION_MAP.forEach((matchValue, actionId) ->
@@ -240,32 +180,103 @@
                                                                     matchValue,
                                                                     actionId,
                                                                     appId));
+
+        return true;
     }
 
     @Override
-    public CompletableFuture<Boolean> addIntObjective(IntObjective obj) {
+    public boolean setSourcePort(PortNumber port) {
+        // process_set_source_sink.tb_set_source for each host-facing port
+        PiCriterion ingressCriterion = PiCriterion.builder()
+                .matchExact(BasicConstants.HDR_IN_PORT_ID, port.toLong())
+                .build();
+        TrafficSelector srcSelector = DefaultTrafficSelector.builder()
+                .matchPi(ingressCriterion)
+                .build();
+        PiAction setSourceAct = PiAction.builder()
+                .withId(IntConstants.ACT_INT_SET_SOURCE_ID)
+                .build();
+        TrafficTreatment srcTreatment = DefaultTrafficTreatment.builder()
+                .piTableAction(setSourceAct)
+                .build();
+        FlowRule srcFlowRule = DefaultFlowRule.builder()
+                .withSelector(srcSelector)
+                .withTreatment(srcTreatment)
+                .fromApp(appId)
+                .withPriority(DEFAULT_PRIORITY)
+                .makePermanent()
+                .forDevice(deviceId)
+                .forTable(IntConstants.TBL_SET_SOURCE_ID)
+                .build();
+        flowRuleService.applyFlowRules(srcFlowRule);
+        return true;
+    }
+
+    @Override
+    public boolean setSinkPort(PortNumber port) {
+        // process_set_source_sink.tb_set_sink
+        PiCriterion egressCriterion = PiCriterion.builder()
+                .matchExact(IntConstants.HDR_OUT_PORT_ID, port.toLong())
+                .build();
+        TrafficSelector sinkSelector = DefaultTrafficSelector.builder()
+                .matchPi(egressCriterion)
+                .build();
+        PiAction setSinkAct = PiAction.builder()
+                .withId(IntConstants.ACT_INT_SET_SINK_ID)
+                .build();
+        TrafficTreatment sinkTreatment = DefaultTrafficTreatment.builder()
+                .piTableAction(setSinkAct)
+                .build();
+        FlowRule sinkFlowRule = DefaultFlowRule.builder()
+                .withSelector(sinkSelector)
+                .withTreatment(sinkTreatment)
+                .fromApp(appId)
+                .withPriority(DEFAULT_PRIORITY)
+                .makePermanent()
+                .forDevice(deviceId)
+                .forTable(IntConstants.TBL_SET_SINK_ID)
+                .build();
+        flowRuleService.applyFlowRules(sinkFlowRule);
+        return true;
+    }
+
+    @Override
+    public boolean addIntObjective(IntObjective obj) {
         // TODO: support different types of watchlist other than flow watchlist
 
-        return CompletableFuture.supplyAsync(
-                () -> processIntObjective(obj, true),
-                SharedExecutors.getPoolThreadExecutor()
-        );
+        return processIntObjective(obj, true);
     }
 
     @Override
-    public CompletableFuture<Boolean> removeIntObjective(IntObjective obj) {
-        return CompletableFuture.supplyAsync(
-                () -> processIntObjective(obj, false),
-                SharedExecutors.getPoolThreadExecutor()
-        );
+    public boolean removeIntObjective(IntObjective obj) {
+        return processIntObjective(obj, false);
     }
 
     @Override
-    public CompletableFuture<Boolean> setupIntConfig(IntConfig config) {
-        return CompletableFuture.supplyAsync(
-                () -> setupIntReportInternal(config),
-                SharedExecutors.getPoolThreadExecutor()
-        );
+    public boolean setupIntConfig(IntConfig config) {
+        return setupIntReportInternal(config);
+    }
+
+    @Override
+    public void cleanup() {
+        StreamSupport.stream(flowRuleService.getFlowEntries(
+                data().deviceId()).spliterator(), false)
+                .filter(f -> f.table().type() == TableId.Type.PIPELINE_INDEPENDENT)
+                .filter(f -> TABLES_TO_CLEANUP.contains((PiTableId) f.table()))
+                .forEach(flowRuleService::removeFlowRules);
+    }
+
+    @Override
+    public boolean supportsFunctionality(IntFunctionality functionality) {
+        switch (functionality) {
+            case SOURCE:
+            case SINK:
+            case TRANSIT:
+                return true;
+            default:
+                log.warn("Unknown functionality {}", functionality);
+                return false;
+        }
     }
 
     private void populateInstTableEntry(PiTableId tableId, PiMatchFieldId matchFieldId,
@@ -419,12 +430,12 @@
     }
 
     /**
-     * Returns a subset of Criterion from given selector,
-     * which is unsupported by this INT pipeline.
+     * Returns a subset of Criterion from given selector, which is unsupported
+     * by this INT pipeline.
      *
      * @param selector a traffic selector
-     * @return a subset of Criterion from given selector, unsupported by this INT pipeline,
-     *  empty if all criteria are supported.
+     * @return a subset of Criterion from given selector, unsupported by this
+     * INT pipeline, empty if all criteria are supported.
      */
     private Set<Criterion> unsupportedSelectors(TrafficSelector selector) {
         return selector.criteria().stream()
diff --git a/pipelines/fabric/BUCK b/pipelines/fabric/BUCK
index 168e9d8..5491289 100644
--- a/pipelines/fabric/BUCK
+++ b/pipelines/fabric/BUCK
@@ -6,6 +6,7 @@
     '//pipelines/basic:onos-pipelines-basic',
     '//core/store/serializers:onos-core-serializers',
     '//apps/inbandtelemetry/api:onos-apps-inbandtelemetry-api',
+    '//providers/general/device:onos-providers-general-device',
 ]
 
 TEST_DEPS = [
diff --git a/pipelines/fabric/BUILD b/pipelines/fabric/BUILD
index c356aae..11dad56 100644
--- a/pipelines/fabric/BUILD
+++ b/pipelines/fabric/BUILD
@@ -1,6 +1,7 @@
 COMPILE_DEPS = CORE_DEPS + KRYO + [
     "//protocols/p4runtime/model:onos-protocols-p4runtime-model",
     "//protocols/p4runtime/api:onos-protocols-p4runtime-api",
+    "//providers/general/device:onos-providers-general-device",
     "//pipelines/basic:onos-pipelines-basic",
     "//core/store/serializers:onos-core-serializers",
     "//apps/inbandtelemetry/api:onos-apps-inbandtelemetry-api",
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java
index 7c7f3fb..07bb862 100644
--- a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java
@@ -45,6 +45,8 @@
             PiMatchFieldId.of("hdr.vlan_tag.is_valid");
     public static final PiMatchFieldId HDR_ICMP_ICMP_CODE =
             PiMatchFieldId.of("hdr.icmp.icmp_code");
+    public static final PiMatchFieldId HDR_INT_HEADER_IS_VALID =
+            PiMatchFieldId.of("hdr.int_header.is_valid");
     public static final PiMatchFieldId HDR_ETHERNET_SRC_ADDR =
             PiMatchFieldId.of("hdr.ethernet.src_addr");
     public static final PiMatchFieldId HDR_ICMP_ICMP_TYPE =
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/IntProgrammableImpl.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/IntProgrammableImpl.java
index 5d95abd..15e3f01 100644
--- a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/IntProgrammableImpl.java
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/IntProgrammableImpl.java
@@ -15,27 +15,23 @@
  */
 package org.onosproject.pipelines.fabric;
 
-import com.google.common.collect.ImmutableBiMap;
 import com.google.common.collect.Sets;
-import org.onlab.util.ImmutableByteSequence;
-import org.onlab.util.SharedExecutors;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
 import org.onosproject.inbandtelemetry.api.IntConfig;
 import org.onosproject.inbandtelemetry.api.IntIntent;
 import org.onosproject.inbandtelemetry.api.IntObjective;
 import org.onosproject.inbandtelemetry.api.IntProgrammable;
-import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DeviceId;
-import org.onosproject.net.Port;
 import org.onosproject.net.PortNumber;
-import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.config.NetworkConfigService;
 import org.onosproject.net.driver.AbstractHandlerBehaviour;
 import org.onosproject.net.flow.DefaultFlowRule;
 import org.onosproject.net.flow.DefaultTrafficSelector;
 import org.onosproject.net.flow.DefaultTrafficTreatment;
 import org.onosproject.net.flow.FlowRule;
 import org.onosproject.net.flow.FlowRuleService;
+import org.onosproject.net.flow.TableId;
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
 import org.onosproject.net.flow.criteria.Criterion;
@@ -43,32 +39,32 @@
 import org.onosproject.net.flow.criteria.PiCriterion;
 import org.onosproject.net.flow.criteria.TcpPortCriterion;
 import org.onosproject.net.flow.criteria.UdpPortCriterion;
-import org.onosproject.net.host.HostService;
-import org.onosproject.net.pi.model.PiActionId;
-import org.onosproject.net.pi.model.PiMatchFieldId;
 import org.onosproject.net.pi.model.PiTableId;
 import org.onosproject.net.pi.runtime.PiAction;
 import org.onosproject.net.pi.runtime.PiActionParam;
+import org.onosproject.provider.general.device.api.GeneralProviderDeviceConfig;
 import org.slf4j.Logger;
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Set;
-import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
 
+import static org.onlab.util.ImmutableByteSequence.copyFrom;
 import static org.slf4j.LoggerFactory.getLogger;
 
+/**
+ * Implementation of INT programmable behavior for fabric.p4. Currently supports
+ * only SOURCE and TRANSIT functionalities.
+ */
 public class IntProgrammableImpl extends AbstractHandlerBehaviour implements IntProgrammable {
+
+    private final Logger log = getLogger(getClass());
+
     // TODO: change this value to the value of diameter of a network.
+    private static final int DEFAULT_PRIORITY = 10000;
     private static final int MAXHOP = 64;
     private static final int PORTMASK = 0xffff;
-    private static final int IDLE_TIMEOUT = 100;
     private static final int PKT_INSTANCE_TYPE_INGRESS_CLONE = 1;
-    // Application name of the pipeline which adds this implementation to the pipeconf
-    private static final String PIPELINE_APP_NAME = "org.onosproject.pipelines.fabric";
-    private final Logger log = getLogger(getClass());
-    private ApplicationId appId;
 
     private static final Set<Criterion.Type> SUPPORTED_CRITERION = Sets.newHashSet(
             Criterion.Type.IPV4_DST, Criterion.Type.IPV4_SRC,
@@ -76,77 +72,65 @@
             Criterion.Type.TCP_SRC, Criterion.Type.TCP_DST,
             Criterion.Type.IP_PROTO);
 
+    private static final Set<PiTableId> TABLES_TO_CLEANUP = Sets.newHashSet(
+            FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_TB_INT_INSERT,
+            FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SOURCE,
+            FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SINK,
+            FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_SOURCE_TB_INT_SOURCE,
+            FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_REPORT_TB_GENERATE_REPORT
+    );
+
     private FlowRuleService flowRuleService;
-    private HostService hostService;
     private CoreService coreService;
-
+    private NetworkConfigService cfgService;
     private DeviceId deviceId;
-    private static final int DEFAULT_PRIORITY = 10000;
-    private static final ImmutableBiMap<Integer, PiActionId> INST_0003_ACTION_MAP =
-            ImmutableBiMap.<Integer, PiActionId>builder()
-                    .put(0, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0003_I0)
-                    .put(1, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0003_I1)
-                    .put(2, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0003_I2)
-                    .put(3, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0003_I3)
-                    .put(4, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0003_I4)
-                    .put(5, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0003_I5)
-                    .put(6, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0003_I6)
-                    .put(7, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0003_I7)
-                    .put(8, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0003_I8)
-                    .put(9, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0003_I9)
-                    .put(10, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0003_I10)
-                    .put(11, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0003_I11)
-                    .put(12, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0003_I12)
-                    .put(13, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0003_I13)
-                    .put(14, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0003_I14)
-                    .put(15, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0003_I15)
-                    .build();
+    private ApplicationId appId;
 
-    private static final ImmutableBiMap<Integer, PiActionId> INST_0407_ACTION_MAP =
-            ImmutableBiMap.<Integer, PiActionId>builder()
-                    .put(0, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0407_I0)
-                    .put(1, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0407_I1)
-                    .put(2, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0407_I2)
-                    .put(3, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0407_I3)
-                    .put(4, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0407_I4)
-                    .put(5, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0407_I5)
-                    .put(6, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0407_I6)
-                    .put(7, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0407_I7)
-                    .put(8, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0407_I8)
-                    .put(9, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0407_I9)
-                    .put(10, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0407_I10)
-                    .put(11, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0407_I11)
-                    .put(12, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0407_I12)
-                    .put(13, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0407_I13)
-                    .put(14, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0407_I14)
-                    .put(15, FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INT_SET_HEADER_0407_I15)
-                    .build();
-
-    @Override
-    public void init() {
+    private boolean setupBehaviour() {
         deviceId = this.data().deviceId();
         flowRuleService = handler().get(FlowRuleService.class);
-        DeviceService deviceService = handler().get(DeviceService.class);
-        hostService = handler().get(HostService.class);
         coreService = handler().get(CoreService.class);
-        appId = coreService.getAppId(PIPELINE_APP_NAME);
+        cfgService = handler().get(NetworkConfigService.class);
+        appId = coreService.getAppId(PipeconfLoader.PIPELINE_APP_NAME);
         if (appId == null) {
-            log.warn("Application ID is null. Cannot initialize INT-pipeline.");
-            return;
+            log.warn("Application ID is null. Cannot initialize behaviour.");
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public boolean init() {
+
+        if (!setupBehaviour()) {
+            return false;
         }
 
-        Set<PortNumber> hostPorts = deviceService.getPorts(deviceId).stream()
-                .filter(port -> hostService.getConnectedHosts(
-                        new ConnectPoint(deviceId, port.number())).size() > 0
-        ).map(Port::number).collect(Collectors.toSet());
-        List<FlowRule> flowRules = new ArrayList<>();
+        final GeneralProviderDeviceConfig cfg = cfgService.getConfig(
+                deviceId, GeneralProviderDeviceConfig.class);
+        if (cfg == null) {
+            log.warn("Missing GeneralProviderDevice config for {}", deviceId);
+            return false;
+        }
+        final String switchId = cfg.protocolsInfo().containsKey("int") ?
+                cfg.protocolsInfo().get("int").configValues().get("switchId")
+                : null;
+        if (switchId == null || switchId.isEmpty()) {
+            log.warn("Missing INT device config for {}", deviceId);
+            return false;
+        }
 
-        // process_int_transit.tb_int_insert
-        PiActionParam transitIdParam = new PiActionParam(
-                FabricConstants.SWITCH_ID,
-                ImmutableByteSequence.copyFrom(
-                        Integer.parseInt(deviceId.toString().substring(
-                                deviceId.toString().length() - 2))));
+        PiActionParam transitIdParam;
+        try {
+            transitIdParam = new PiActionParam(
+                    FabricConstants.SWITCH_ID,
+                    // FIXME set switch ID from netcfg
+                    copyFrom(Integer.parseInt(switchId)));
+        } catch (NumberFormatException e) {
+            log.warn("Invalid INT switch ID for {}: {}", deviceId, switchId);
+            return false;
+        }
+
         PiAction transitAction = PiAction.builder()
                 .withId(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INIT_METADATA)
                 .withParameter(transitIdParam)
@@ -154,8 +138,14 @@
         TrafficTreatment treatment = DefaultTrafficTreatment.builder()
                 .piTableAction(transitAction)
                 .build();
+        TrafficSelector selector = DefaultTrafficSelector.builder()
+                .matchPi(PiCriterion.builder().matchExact(
+                        FabricConstants.HDR_INT_HEADER_IS_VALID, (byte) 0x01)
+                                 .build())
+                .build();
 
         FlowRule transitFlowRule = DefaultFlowRule.builder()
+                .withSelector(selector)
                 .withTreatment(treatment)
                 .fromApp(appId)
                 .withPriority(DEFAULT_PRIORITY)
@@ -163,149 +153,139 @@
                 .forDevice(deviceId)
                 .forTable(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_TB_INT_INSERT)
                 .build();
-        flowRules.add(transitFlowRule);
 
-        for (PortNumber portNumber : hostPorts) {
-            // process_set_source_sink.tb_set_source for each host-facing port
-            PiCriterion ingressCriterion = PiCriterion.builder()
-                    .matchExact(FabricConstants.STANDARD_METADATA_INGRESS_PORT, portNumber.toLong())
-                    .build();
-            TrafficSelector srcSelector = DefaultTrafficSelector.builder()
-                    .matchPi(ingressCriterion)
-                    .build();
-            PiAction setSourceAct = PiAction.builder()
-                    .withId(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_INT_SET_SOURCE)
-                    .build();
-            TrafficTreatment srcTreatment = DefaultTrafficTreatment.builder()
-                    .piTableAction(setSourceAct)
-                    .build();
-            FlowRule srcFlowRule = DefaultFlowRule.builder()
-                    .withSelector(srcSelector)
-                    .withTreatment(srcTreatment)
-                    .fromApp(appId)
-                    .withPriority(DEFAULT_PRIORITY)
-                    .makePermanent()
-                    .forDevice(deviceId)
-                    .forTable(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SOURCE)
-                    .build();
-            flowRules.add(srcFlowRule);
+        flowRuleService.applyFlowRules(transitFlowRule);
+        return true;
+    }
 
-            // process_set_source_sink.tb_set_sink
-            PiCriterion egressCriterion = PiCriterion.builder()
-                    .matchExact(FabricConstants.STANDARD_METADATA_EGRESS_PORT, portNumber.toLong())
-                    .build();
-            TrafficSelector sinkSelector = DefaultTrafficSelector.builder()
-                    .matchPi(egressCriterion)
-                    .build();
-            PiAction setSinkAct = PiAction.builder()
-                    .withId(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_INT_SET_SINK)
-                    .build();
-            TrafficTreatment sinkTreatment = DefaultTrafficTreatment.builder()
-                    .piTableAction(setSinkAct)
-                    .build();
-            FlowRule sinkFlowRule = DefaultFlowRule.builder()
-                    .withSelector(sinkSelector)
-                    .withTreatment(sinkTreatment)
-                    .fromApp(appId)
-                    .withPriority(DEFAULT_PRIORITY)
-                    .makePermanent()
-                    .forDevice(deviceId)
-                    .forTable(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SINK)
-                    .build();
-            flowRules.add(sinkFlowRule);
+    @Override
+    public boolean setSourcePort(PortNumber port) {
+
+        if (!setupBehaviour()) {
+            return false;
         }
-        flowRules.forEach(flowRule -> flowRuleService.applyFlowRules(flowRule));
 
-        // Populate tb_int_inst_0003 table
-        INST_0003_ACTION_MAP.forEach((matchValue, actionId) -> populateInstTableEntry(
-                FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_TB_INT_INST_0003,
-                FabricConstants.HDR_INT_HEADER_INSTRUCTION_MASK_0003,
-                matchValue,
-                actionId,
-                appId));
-        // Populate tb_int_inst_0407 table
-        INST_0407_ACTION_MAP.forEach((matchValue, actionId) -> populateInstTableEntry(
-                FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_TB_INT_INST_0407,
-                FabricConstants.HDR_INT_HEADER_INSTRUCTION_MASK_0407,
-                matchValue,
-                actionId,
-                appId));
-    }
-
-    @Override
-    public CompletableFuture<Boolean> addIntObjective(IntObjective obj) {
-        // TODO: support different types of watchlist other than flow watchlist
-
-        return CompletableFuture.supplyAsync(
-                () -> processIntObjective(obj, true),
-                SharedExecutors.getPoolThreadExecutor()
-        );
-    }
-
-    @Override
-    public CompletableFuture<Boolean> removeIntObjective(IntObjective obj) {
-        return CompletableFuture.supplyAsync(
-                () -> processIntObjective(obj, false),
-                SharedExecutors.getPoolThreadExecutor()
-        );
-    }
-
-    @Override
-    public CompletableFuture<Boolean> setupIntConfig(IntConfig config) {
-        return CompletableFuture.supplyAsync(
-                () -> setupIntReportInternal(config),
-                SharedExecutors.getPoolThreadExecutor()
-        );
-    }
-
-    private void populateInstTableEntry(PiTableId tableId, PiMatchFieldId matchFieldId,
-                                        int matchValue, PiActionId actionId, ApplicationId appId) {
-        PiCriterion instCriterion = PiCriterion.builder()
-                .matchExact(matchFieldId, matchValue)
+        PiCriterion ingressCriterion = PiCriterion.builder()
+                .matchExact(FabricConstants.STANDARD_METADATA_INGRESS_PORT, port.toLong())
                 .build();
-        TrafficSelector instSelector = DefaultTrafficSelector.builder()
-                .matchPi(instCriterion)
+        TrafficSelector srcSelector = DefaultTrafficSelector.builder()
+                .matchPi(ingressCriterion)
                 .build();
-        PiAction instAction = PiAction.builder()
-                .withId(actionId)
+        PiAction setSourceAct = PiAction.builder()
+                .withId(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_INT_SET_SOURCE)
                 .build();
-        TrafficTreatment instTreatment = DefaultTrafficTreatment.builder()
-                .piTableAction(instAction)
+        TrafficTreatment srcTreatment = DefaultTrafficTreatment.builder()
+                .piTableAction(setSourceAct)
                 .build();
-
-        FlowRule instFlowRule = DefaultFlowRule.builder()
-                .withSelector(instSelector)
-                .withTreatment(instTreatment)
+        FlowRule srcFlowRule = DefaultFlowRule.builder()
+                .withSelector(srcSelector)
+                .withTreatment(srcTreatment)
+                .fromApp(appId)
                 .withPriority(DEFAULT_PRIORITY)
                 .makePermanent()
                 .forDevice(deviceId)
-                .forTable(tableId)
-                .fromApp(appId)
+                .forTable(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SOURCE)
                 .build();
+        flowRuleService.applyFlowRules(srcFlowRule);
+        return true;
+    }
 
-        flowRuleService.applyFlowRules(instFlowRule);
+    @Override
+    public boolean setSinkPort(PortNumber port) {
+
+        if (!setupBehaviour()) {
+            return false;
+        }
+
+        PiCriterion egressCriterion = PiCriterion.builder()
+                .matchExact(FabricConstants.STANDARD_METADATA_EGRESS_PORT, port.toLong())
+                .build();
+        TrafficSelector sinkSelector = DefaultTrafficSelector.builder()
+                .matchPi(egressCriterion)
+                .build();
+        PiAction setSinkAct = PiAction.builder()
+                .withId(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_INT_SET_SINK)
+                .build();
+        TrafficTreatment sinkTreatment = DefaultTrafficTreatment.builder()
+                .piTableAction(setSinkAct)
+                .build();
+        FlowRule sinkFlowRule = DefaultFlowRule.builder()
+                .withSelector(sinkSelector)
+                .withTreatment(sinkTreatment)
+                .fromApp(appId)
+                .withPriority(DEFAULT_PRIORITY)
+                .makePermanent()
+                .forDevice(deviceId)
+                .forTable(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SINK)
+                .build();
+        flowRuleService.applyFlowRules(sinkFlowRule);
+        return true;
+    }
+
+    @Override
+    public boolean addIntObjective(IntObjective obj) {
+
+        if (!setupBehaviour()) {
+            return false;
+        }
+
+        return processIntObjective(obj, true);
+    }
+
+    @Override
+    public boolean removeIntObjective(IntObjective obj) {
+
+        if (!setupBehaviour()) {
+            return false;
+        }
+
+        return processIntObjective(obj, false);
+    }
+
+    @Override
+    public boolean setupIntConfig(IntConfig config) {
+
+        if (!setupBehaviour()) {
+            return false;
+        }
+
+        return setupIntReportInternal(config);
+    }
+
+    @Override
+    public void cleanup() {
+
+        if (!setupBehaviour()) {
+            return;
+        }
+
+        StreamSupport.stream(flowRuleService.getFlowEntries(
+                data().deviceId()).spliterator(), false)
+                .filter(f -> f.table().type() == TableId.Type.PIPELINE_INDEPENDENT)
+                .filter(f -> TABLES_TO_CLEANUP.contains((PiTableId) f.table()))
+                .forEach(flowRuleService::removeFlowRules);
+    }
+
+    @Override
+    public boolean supportsFunctionality(IntFunctionality functionality) {
+        // Sink not fully supported yet.
+        return functionality == IntFunctionality.SOURCE || functionality == IntFunctionality.TRANSIT;
     }
 
     private FlowRule buildWatchlistEntry(IntObjective obj) {
-        coreService = handler().get(CoreService.class);
-        appId = coreService.getAppId(PIPELINE_APP_NAME);
-        if (appId == null) {
-            log.warn("Application ID is null. Cannot initialize INT-pipeline.");
-            return null;
-        }
         int instructionBitmap = buildInstructionBitmap(obj.metadataTypes());
         PiActionParam maxHopParam = new PiActionParam(
                 FabricConstants.MAX_HOP,
-                ImmutableByteSequence.copyFrom(MAXHOP));
+                copyFrom(MAXHOP));
         PiActionParam instCntParam = new PiActionParam(
                 FabricConstants.INS_CNT,
-                ImmutableByteSequence.copyFrom(Integer.bitCount(instructionBitmap)));
+                copyFrom(Integer.bitCount(instructionBitmap)));
         PiActionParam inst0003Param = new PiActionParam(
                 FabricConstants.INS_MASK0003,
-                ImmutableByteSequence.copyFrom((instructionBitmap >> 12) & 0xF));
+                copyFrom((instructionBitmap >> 12) & 0xF));
         PiActionParam inst0407Param = new PiActionParam(
                 FabricConstants.INS_MASK0407,
-                ImmutableByteSequence.copyFrom((instructionBitmap >> 8) & 0xF));
+                copyFrom((instructionBitmap >> 8) & 0xF));
 
         PiAction intSourceAction = PiAction.builder()
                 .withId(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_SOURCE_INT_SOURCE_DSCP)
@@ -362,13 +342,13 @@
         }
 
         return DefaultFlowRule.builder()
-                .forDevice(this.data().deviceId())
+                .forDevice(deviceId)
                 .withSelector(sBuilder.build())
                 .withTreatment(instTreatment)
                 .withPriority(DEFAULT_PRIORITY)
                 .forTable(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_SOURCE_TB_INT_SOURCE)
                 .fromApp(appId)
-                .withIdleTimeout(IDLE_TIMEOUT)
+                .makePermanent()
                 .build();
     }
 
@@ -423,11 +403,9 @@
     }
 
     private boolean processIntObjective(IntObjective obj, boolean install) {
-        flowRuleService = handler().get(FlowRuleService.class);
-        deviceId = this.data().deviceId();
         if (install && !unsupportedSelectors(obj.selector()).isEmpty()) {
-            log.warn("Device {} does not support criteria {} for INT.",
-                     deviceId, unsupportedSelectors(obj.selector()));
+            log.warn("Criteria {} not supported by {} for INT watchlist",
+                     unsupportedSelectors(obj.selector()), deviceId);
             return false;
         }
 
@@ -449,42 +427,40 @@
     }
 
     private boolean setupIntReportInternal(IntConfig cfg) {
-        flowRuleService = handler().get(FlowRuleService.class);
-
-        FlowRule reportRule = buildReportEntry(cfg, PKT_INSTANCE_TYPE_INGRESS_CLONE);
-        if (reportRule != null) {
-            flowRuleService.applyFlowRules(reportRule);
-            log.info("Report entry {} has been added to {}", reportRule, this.data().deviceId());
-            return true;
-        } else {
-            log.warn("Failed to add report entry on {}", this.data().deviceId());
-            return false;
-        }
+        // Report not fully supported yet.
+        return true;
+        // FlowRule reportRule = buildReportEntry(cfg, PKT_INSTANCE_TYPE_INGRESS_CLONE);
+        // if (reportRule != null) {
+        //     flowRuleService.applyFlowRules(reportRule);
+        //     log.info("Report entry {} has been added to {}", reportRule, this.data().deviceId());
+        //     return true;
+        // } else {
+        //     log.warn("Failed to add report entry on {}", this.data().deviceId());
+        //     return false;
+        // }
     }
 
     private FlowRule buildReportEntry(IntConfig cfg, int type) {
-        coreService = handler().get(CoreService.class);
-        appId = coreService.getAppId(PIPELINE_APP_NAME);
-        if (appId == null) {
-            log.warn("Application ID is null. Cannot build report entry.");
+
+        if (!setupBehaviour()) {
             return null;
         }
 
         PiActionParam srcMacParam = new PiActionParam(
                 FabricConstants.SRC_MAC,
-                ImmutableByteSequence.copyFrom(cfg.sinkMac().toBytes()));
+                copyFrom(cfg.sinkMac().toBytes()));
         PiActionParam nextHopMacParam = new PiActionParam(
                 FabricConstants.MON_MAC,
-                ImmutableByteSequence.copyFrom(cfg.collectorNextHopMac().toBytes()));
+                copyFrom(cfg.collectorNextHopMac().toBytes()));
         PiActionParam srcIpParam = new PiActionParam(
                 FabricConstants.SRC_IP,
-                ImmutableByteSequence.copyFrom(cfg.sinkIp().toOctets()));
+                copyFrom(cfg.sinkIp().toOctets()));
         PiActionParam monIpParam = new PiActionParam(
                 FabricConstants.MON_IP,
-                ImmutableByteSequence.copyFrom(cfg.collectorIp().toOctets()));
+                copyFrom(cfg.collectorIp().toOctets()));
         PiActionParam monPortParam = new PiActionParam(
                 FabricConstants.MON_PORT,
-                ImmutableByteSequence.copyFrom(cfg.collectorPort().toInt()));
+                copyFrom(cfg.collectorPort().toInt()));
         PiAction reportAction = PiAction.builder()
                 .withId(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_REPORT_DO_REPORT_ENCAPSULATION)
                 .withParameter(srcMacParam)
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/PipeconfLoader.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/PipeconfLoader.java
index 9b54dfc..1609794 100644
--- a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/PipeconfLoader.java
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/PipeconfLoader.java
@@ -62,12 +62,11 @@
 
     private static Logger log = getLogger(PipeconfLoader.class);
 
+    static final String PIPELINE_APP_NAME = "org.onosproject.pipelines.fabric";
+
     private static final String BASE_PIPECONF_ID = "org.onosproject.pipelines";
-
     private static final String P4C_OUT_PATH = "/p4c-out";
 
-    private static final String PIPELINE_APP_NAME = "org.onosproject.pipelines.fabric";
-
     // profile/target/platform
     private static final String P4C_RES_BASE_PATH = P4C_OUT_PATH + "/%s/%s/%s/";
 
diff --git a/pipelines/fabric/src/main/resources/fabric.p4 b/pipelines/fabric/src/main/resources/fabric.p4
index 0aee32b..95b9bc8 100644
--- a/pipelines/fabric/src/main/resources/fabric.p4
+++ b/pipelines/fabric/src/main/resources/fabric.p4
@@ -50,6 +50,7 @@
 #endif // WITH_PORT_COUNTER
 
     apply {
+        _PRE_INGRESS
 #ifdef WITH_SPGW
         spgw_normalizer.apply(hdr.gtpu.isValid(), hdr.gtpu_ipv4, hdr.gtpu_udp,
                               hdr.ipv4, hdr.udp, hdr.inner_ipv4, hdr.inner_udp);
@@ -83,6 +84,7 @@
     EgressNextControl() egress_next;
 
     apply {
+        _PRE_EGRESS
         pkt_io_egress.apply(hdr, fabric_metadata, standard_metadata);
         egress_next.apply(hdr, fabric_metadata, standard_metadata);
 #ifdef WITH_SPGW
diff --git a/pipelines/fabric/src/main/resources/include/define.p4 b/pipelines/fabric/src/main/resources/include/define.p4
index 26d3167..dfde323 100644
--- a/pipelines/fabric/src/main/resources/include/define.p4
+++ b/pipelines/fabric/src/main/resources/include/define.p4
@@ -37,6 +37,14 @@
 #define _PKT_OUT_HDR_ANNOT
 #endif
 
+#ifndef _PRE_INGRESS
+#define _PRE_INGRESS
+#endif
+
+#ifndef _PRE_EGRESS
+#define _PRE_EGRESS
+#endif
+
 #ifndef IP_VER_LENGTH
 #define IP_VER_LENGTH 4
 #endif
diff --git a/pipelines/fabric/src/main/resources/include/int/int_header.p4 b/pipelines/fabric/src/main/resources/include/int/int_header.p4
index f339995..4e352ee 100644
--- a/pipelines/fabric/src/main/resources/include/int/int_header.p4
+++ b/pipelines/fabric/src/main/resources/include/int/int_header.p4
@@ -26,6 +26,8 @@
     bit<32> switch_id;
     bit<8>  new_words;
     bit<16> new_bytes;
+    bit<32> ig_tstamp;
+    bit<32> eg_tstamp;
 }
 
 // INT headers - 8 bytes
diff --git a/pipelines/fabric/src/main/resources/include/int/int_transit.p4 b/pipelines/fabric/src/main/resources/include/int/int_transit.p4
index 4d4568b..579fa07 100644
--- a/pipelines/fabric/src/main/resources/include/int/int_transit.p4
+++ b/pipelines/fabric/src/main/resources/include/int/int_transit.p4
@@ -269,11 +269,17 @@
 
     // Default action used to set switch ID.
     table tb_int_insert {
-        key = {}
+        // We don't really need a key here, however we add a dummy one as a
+        // workaround to ONOS inability to properly support default actions.
+        key = {
+            hdr.int_header.isValid(): exact @name("hdr.int_header.is_valid");
+        }
         actions = {
             init_metadata;
+            @defaultonly nop;
         }
-        size = 0;
+        const default_action = nop;
+        size = 1;
     }
 
     // Table to process instruction bits 0-3.
diff --git a/pipelines/fabric/src/main/resources/p4c-out/fabric-full/bmv2/default/bmv2.json b/pipelines/fabric/src/main/resources/p4c-out/fabric-full/bmv2/default/bmv2.json
index 246401b..c7d78e8 100644
--- a/pipelines/fabric/src/main/resources/p4c-out/fabric-full/bmv2/default/bmv2.json
+++ b/pipelines/fabric/src/main/resources/p4c-out/fabric-full/bmv2/default/bmv2.json
@@ -5013,7 +5013,7 @@
       "primitives" : []
     },
     {
-      "name" : "NoAction",
+      "name" : "nop",
       "id" : 79,
       "runtime_data" : [],
       "primitives" : []
@@ -13300,7 +13300,7 @@
           ],
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 370,
+            "line" : 374,
             "column" : 12,
             "source_fragment" : "return"
           }
@@ -13349,7 +13349,7 @@
           ],
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 378,
+            "line" : 382,
             "column" : 12,
             "source_fragment" : "hdr.ipv4.total_len = hdr.ipv4.total_len + fmeta.int_meta.new_bytes"
           }
@@ -13398,7 +13398,7 @@
           ],
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 375,
+            "line" : 379,
             "column" : 8,
             "source_fragment" : "hdr.int_header.total_hop_cnt = hdr.int_header.total_hop_cnt + 1"
           }
@@ -13447,7 +13447,7 @@
           ],
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 381,
+            "line" : 385,
             "column" : 12,
             "source_fragment" : "hdr.udp.len = hdr.udp.len + fmeta.int_meta.new_bytes"
           }
@@ -13496,7 +13496,7 @@
           ],
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 384,
+            "line" : 388,
             "column" : 12,
             "source_fragment" : "hdr.intl4_shim.len_words = hdr.intl4_shim.len_words + fmeta.int_meta.new_words"
           }
@@ -15829,25 +15829,32 @@
             "column" : 10,
             "source_fragment" : "tb_int_insert"
           },
-          "key" : [],
+          "key" : [
+            {
+              "match_type" : "exact",
+              "name" : "hdr.int_header.is_valid",
+              "target" : ["int_header", "$valid$"],
+              "mask" : null
+            }
+          ],
           "match_type" : "exact",
           "type" : "simple",
-          "max_size" : 1024,
+          "max_size" : 1,
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [85, 76],
-          "actions" : ["FabricEgress.process_int_main.process_int_transit.init_metadata", "NoAction"],
+          "action_ids" : [85, 79],
+          "actions" : ["FabricEgress.process_int_main.process_int_transit.init_metadata", "nop"],
           "base_default_next" : "node_94",
           "next_tables" : {
             "FabricEgress.process_int_main.process_int_transit.init_metadata" : "node_94",
-            "NoAction" : "node_94"
+            "nop" : "node_94"
           },
           "default_entry" : {
-            "action_id" : 76,
-            "action_const" : false,
+            "action_id" : 79,
+            "action_const" : true,
             "action_data" : [],
-            "action_entry_const" : false
+            "action_entry_const" : true
           }
         },
         {
@@ -15878,7 +15885,7 @@
           "id" : 59,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 280,
+            "line" : 284,
             "column" : 10,
             "source_fragment" : "tb_int_inst_0003"
           },
@@ -15896,7 +15903,7 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 77],
+          "action_ids" : [86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 76],
           "actions" : ["FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i0", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i1", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i2", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i3", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i4", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i5", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i6", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i7", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i8", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i9", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i10", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i11", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i12", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i13", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i14", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i15", "NoAction"],
           "base_default_next" : "FabricEgress.process_int_main.process_int_transit.tb_int_inst_0407",
           "next_tables" : {
@@ -15919,7 +15926,7 @@
             "NoAction" : "FabricEgress.process_int_main.process_int_transit.tb_int_inst_0407"
           },
           "default_entry" : {
-            "action_id" : 77,
+            "action_id" : 76,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
@@ -16140,7 +16147,7 @@
           "id" : 60,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 324,
+            "line" : 328,
             "column" : 10,
             "source_fragment" : "tb_int_inst_0407"
           },
@@ -16158,7 +16165,7 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 78],
+          "action_ids" : [102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 77],
           "actions" : ["FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i0", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i1", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i2", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i3", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i4", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i5", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i6", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i7", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i8", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i9", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i10", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i11", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i12", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i13", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i14", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i15", "NoAction"],
           "base_default_next" : "tbl_act_34",
           "next_tables" : {
@@ -16181,7 +16188,7 @@
             "NoAction" : "tbl_act_34"
           },
           "default_entry" : {
-            "action_id" : 78,
+            "action_id" : 77,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
@@ -16505,7 +16512,7 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [118, 79],
+          "action_ids" : [118, 78],
           "actions" : ["FabricEgress.process_int_main.process_int_report.do_report_encapsulation", "NoAction"],
           "base_default_next" : "node_108",
           "next_tables" : {
@@ -16513,7 +16520,7 @@
             "NoAction" : "node_108"
           },
           "default_entry" : {
-            "action_id" : 79,
+            "action_id" : 78,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
@@ -16957,7 +16964,7 @@
           "id" : 32,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 369,
+            "line" : 373,
             "column" : 12,
             "source_fragment" : "fmeta.int_meta.transit == false"
           },
@@ -17014,7 +17021,7 @@
           "id" : 34,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 377,
+            "line" : 381,
             "column" : 12,
             "source_fragment" : "hdr.ipv4.isValid()"
           },
@@ -17037,7 +17044,7 @@
           "id" : 35,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 380,
+            "line" : 384,
             "column" : 12,
             "source_fragment" : "hdr.udp.isValid()"
           },
@@ -17060,7 +17067,7 @@
           "id" : 36,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 383,
+            "line" : 387,
             "column" : 12,
             "source_fragment" : "hdr.intl4_shim.isValid()"
           },
diff --git a/pipelines/fabric/src/main/resources/p4c-out/fabric-full/bmv2/default/p4info.txt b/pipelines/fabric/src/main/resources/p4c-out/fabric-full/bmv2/default/p4info.txt
index 5fcf0f6..943fb1c1 100644
--- a/pipelines/fabric/src/main/resources/p4c-out/fabric-full/bmv2/default/p4info.txt
+++ b/pipelines/fabric/src/main/resources/p4c-out/fabric-full/bmv2/default/p4info.txt
@@ -518,14 +518,21 @@
     name: "FabricEgress.process_int_main.process_int_transit.tb_int_insert"
     alias: "tb_int_insert"
   }
+  match_fields {
+    id: 1
+    name: "hdr.int_header.is_valid"
+    bitwidth: 1
+    match_type: EXACT
+  }
   action_refs {
     id: 16780783
   }
   action_refs {
-    id: 16800567
+    id: 16819938
     annotations: "@defaultonly()"
   }
-  size: 1024
+  const_default_action_id: 16819938
+  size: 1
   idle_timeout_behavior: NO_TIMEOUT
 }
 tables {
diff --git a/pipelines/fabric/src/main/resources/p4c-out/fabric-int/bmv2/default/bmv2.json b/pipelines/fabric/src/main/resources/p4c-out/fabric-int/bmv2/default/bmv2.json
index a179079..293212f 100644
--- a/pipelines/fabric/src/main/resources/p4c-out/fabric-int/bmv2/default/bmv2.json
+++ b/pipelines/fabric/src/main/resources/p4c-out/fabric-int/bmv2/default/bmv2.json
@@ -3608,7 +3608,7 @@
       "primitives" : []
     },
     {
-      "name" : "NoAction",
+      "name" : "nop",
       "id" : 53,
       "runtime_data" : [],
       "primitives" : []
@@ -10280,7 +10280,7 @@
           ],
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 370,
+            "line" : 374,
             "column" : 12,
             "source_fragment" : "return"
           }
@@ -10329,7 +10329,7 @@
           ],
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 378,
+            "line" : 382,
             "column" : 12,
             "source_fragment" : "hdr.ipv4.total_len = hdr.ipv4.total_len + fmeta.int_meta.new_bytes"
           }
@@ -10378,7 +10378,7 @@
           ],
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 375,
+            "line" : 379,
             "column" : 8,
             "source_fragment" : "hdr.int_header.total_hop_cnt = hdr.int_header.total_hop_cnt + 1"
           }
@@ -10427,7 +10427,7 @@
           ],
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 381,
+            "line" : 385,
             "column" : 12,
             "source_fragment" : "hdr.udp.len = hdr.udp.len + fmeta.int_meta.new_bytes"
           }
@@ -10476,7 +10476,7 @@
           ],
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 384,
+            "line" : 388,
             "column" : 12,
             "source_fragment" : "hdr.intl4_shim.len_words = hdr.intl4_shim.len_words + fmeta.int_meta.new_words"
           }
@@ -11971,25 +11971,32 @@
             "column" : 10,
             "source_fragment" : "tb_int_insert"
           },
-          "key" : [],
+          "key" : [
+            {
+              "match_type" : "exact",
+              "name" : "hdr.int_header.is_valid",
+              "target" : ["int_header", "$valid$"],
+              "mask" : null
+            }
+          ],
           "match_type" : "exact",
           "type" : "simple",
-          "max_size" : 1024,
+          "max_size" : 1,
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [58, 51],
-          "actions" : ["FabricEgress.process_int_main.process_int_transit.init_metadata", "NoAction"],
+          "action_ids" : [58, 53],
+          "actions" : ["FabricEgress.process_int_main.process_int_transit.init_metadata", "nop"],
           "base_default_next" : "node_60",
           "next_tables" : {
             "FabricEgress.process_int_main.process_int_transit.init_metadata" : "node_60",
-            "NoAction" : "node_60"
+            "nop" : "node_60"
           },
           "default_entry" : {
-            "action_id" : 51,
-            "action_const" : false,
+            "action_id" : 53,
+            "action_const" : true,
             "action_data" : [],
-            "action_entry_const" : false
+            "action_entry_const" : true
           }
         },
         {
@@ -12020,7 +12027,7 @@
           "id" : 36,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 280,
+            "line" : 284,
             "column" : 10,
             "source_fragment" : "tb_int_inst_0003"
           },
@@ -12038,7 +12045,7 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 52],
+          "action_ids" : [59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 51],
           "actions" : ["FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i0", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i1", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i2", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i3", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i4", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i5", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i6", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i7", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i8", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i9", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i10", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i11", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i12", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i13", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i14", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i15", "NoAction"],
           "base_default_next" : "FabricEgress.process_int_main.process_int_transit.tb_int_inst_0407",
           "next_tables" : {
@@ -12061,7 +12068,7 @@
             "NoAction" : "FabricEgress.process_int_main.process_int_transit.tb_int_inst_0407"
           },
           "default_entry" : {
-            "action_id" : 52,
+            "action_id" : 51,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
@@ -12282,7 +12289,7 @@
           "id" : 37,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 324,
+            "line" : 328,
             "column" : 10,
             "source_fragment" : "tb_int_inst_0407"
           },
@@ -12300,7 +12307,7 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 53],
+          "action_ids" : [75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 52],
           "actions" : ["FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i0", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i1", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i2", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i3", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i4", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i5", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i6", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i7", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i8", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i9", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i10", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i11", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i12", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i13", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i14", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i15", "NoAction"],
           "base_default_next" : "tbl_act_18",
           "next_tables" : {
@@ -12323,7 +12330,7 @@
             "NoAction" : "tbl_act_18"
           },
           "default_entry" : {
-            "action_id" : 53,
+            "action_id" : 52,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
@@ -12997,7 +13004,7 @@
           "id" : 21,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 369,
+            "line" : 373,
             "column" : 12,
             "source_fragment" : "fmeta.int_meta.transit == false"
           },
@@ -13054,7 +13061,7 @@
           "id" : 23,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 377,
+            "line" : 381,
             "column" : 12,
             "source_fragment" : "hdr.ipv4.isValid()"
           },
@@ -13077,7 +13084,7 @@
           "id" : 24,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 380,
+            "line" : 384,
             "column" : 12,
             "source_fragment" : "hdr.udp.isValid()"
           },
@@ -13100,7 +13107,7 @@
           "id" : 25,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 383,
+            "line" : 387,
             "column" : 12,
             "source_fragment" : "hdr.intl4_shim.isValid()"
           },
diff --git a/pipelines/fabric/src/main/resources/p4c-out/fabric-int/bmv2/default/p4info.txt b/pipelines/fabric/src/main/resources/p4c-out/fabric-int/bmv2/default/p4info.txt
index cc19487..6213234 100644
--- a/pipelines/fabric/src/main/resources/p4c-out/fabric-int/bmv2/default/p4info.txt
+++ b/pipelines/fabric/src/main/resources/p4c-out/fabric-int/bmv2/default/p4info.txt
@@ -431,14 +431,21 @@
     name: "FabricEgress.process_int_main.process_int_transit.tb_int_insert"
     alias: "tb_int_insert"
   }
+  match_fields {
+    id: 1
+    name: "hdr.int_header.is_valid"
+    bitwidth: 1
+    match_type: EXACT
+  }
   action_refs {
     id: 16780783
   }
   action_refs {
-    id: 16800567
+    id: 16819938
     annotations: "@defaultonly()"
   }
-  size: 1024
+  const_default_action_id: 16819938
+  size: 1
   idle_timeout_behavior: NO_TIMEOUT
 }
 tables {
diff --git a/pipelines/fabric/src/main/resources/p4c-out/fabric-spgw-int/bmv2/default/bmv2.json b/pipelines/fabric/src/main/resources/p4c-out/fabric-spgw-int/bmv2/default/bmv2.json
index c4f0634..97da4eb 100644
--- a/pipelines/fabric/src/main/resources/p4c-out/fabric-spgw-int/bmv2/default/bmv2.json
+++ b/pipelines/fabric/src/main/resources/p4c-out/fabric-spgw-int/bmv2/default/bmv2.json
@@ -4602,7 +4602,7 @@
       "primitives" : []
     },
     {
-      "name" : "NoAction",
+      "name" : "nop",
       "id" : 72,
       "runtime_data" : [],
       "primitives" : []
@@ -11866,7 +11866,7 @@
           ],
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 370,
+            "line" : 374,
             "column" : 12,
             "source_fragment" : "return"
           }
@@ -11915,7 +11915,7 @@
           ],
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 378,
+            "line" : 382,
             "column" : 12,
             "source_fragment" : "hdr.ipv4.total_len = hdr.ipv4.total_len + fmeta.int_meta.new_bytes"
           }
@@ -11964,7 +11964,7 @@
           ],
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 375,
+            "line" : 379,
             "column" : 8,
             "source_fragment" : "hdr.int_header.total_hop_cnt = hdr.int_header.total_hop_cnt + 1"
           }
@@ -12013,7 +12013,7 @@
           ],
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 381,
+            "line" : 385,
             "column" : 12,
             "source_fragment" : "hdr.udp.len = hdr.udp.len + fmeta.int_meta.new_bytes"
           }
@@ -12062,7 +12062,7 @@
           ],
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 384,
+            "line" : 388,
             "column" : 12,
             "source_fragment" : "hdr.intl4_shim.len_words = hdr.intl4_shim.len_words + fmeta.int_meta.new_words"
           }
@@ -14193,25 +14193,32 @@
             "column" : 10,
             "source_fragment" : "tb_int_insert"
           },
-          "key" : [],
+          "key" : [
+            {
+              "match_type" : "exact",
+              "name" : "hdr.int_header.is_valid",
+              "target" : ["int_header", "$valid$"],
+              "mask" : null
+            }
+          ],
           "match_type" : "exact",
           "type" : "simple",
-          "max_size" : 1024,
+          "max_size" : 1,
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [78, 70],
-          "actions" : ["FabricEgress.process_int_main.process_int_transit.init_metadata", "NoAction"],
+          "action_ids" : [78, 72],
+          "actions" : ["FabricEgress.process_int_main.process_int_transit.init_metadata", "nop"],
           "base_default_next" : "node_87",
           "next_tables" : {
             "FabricEgress.process_int_main.process_int_transit.init_metadata" : "node_87",
-            "NoAction" : "node_87"
+            "nop" : "node_87"
           },
           "default_entry" : {
-            "action_id" : 70,
-            "action_const" : false,
+            "action_id" : 72,
+            "action_const" : true,
             "action_data" : [],
-            "action_entry_const" : false
+            "action_entry_const" : true
           }
         },
         {
@@ -14242,7 +14249,7 @@
           "id" : 55,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 280,
+            "line" : 284,
             "column" : 10,
             "source_fragment" : "tb_int_inst_0003"
           },
@@ -14260,7 +14267,7 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 71],
+          "action_ids" : [79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 70],
           "actions" : ["FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i0", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i1", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i2", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i3", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i4", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i5", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i6", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i7", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i8", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i9", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i10", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i11", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i12", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i13", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i14", "FabricEgress.process_int_main.process_int_transit.int_set_header_0003_i15", "NoAction"],
           "base_default_next" : "FabricEgress.process_int_main.process_int_transit.tb_int_inst_0407",
           "next_tables" : {
@@ -14283,7 +14290,7 @@
             "NoAction" : "FabricEgress.process_int_main.process_int_transit.tb_int_inst_0407"
           },
           "default_entry" : {
-            "action_id" : 71,
+            "action_id" : 70,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
@@ -14504,7 +14511,7 @@
           "id" : 56,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 324,
+            "line" : 328,
             "column" : 10,
             "source_fragment" : "tb_int_inst_0407"
           },
@@ -14522,7 +14529,7 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 72],
+          "action_ids" : [95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 71],
           "actions" : ["FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i0", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i1", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i2", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i3", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i4", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i5", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i6", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i7", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i8", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i9", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i10", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i11", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i12", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i13", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i14", "FabricEgress.process_int_main.process_int_transit.int_set_header_0407_i15", "NoAction"],
           "base_default_next" : "tbl_act_32",
           "next_tables" : {
@@ -14545,7 +14552,7 @@
             "NoAction" : "tbl_act_32"
           },
           "default_entry" : {
-            "action_id" : 72,
+            "action_id" : 71,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
@@ -15245,7 +15252,7 @@
           "id" : 29,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 369,
+            "line" : 373,
             "column" : 12,
             "source_fragment" : "fmeta.int_meta.transit == false"
           },
@@ -15302,7 +15309,7 @@
           "id" : 31,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 377,
+            "line" : 381,
             "column" : 12,
             "source_fragment" : "hdr.ipv4.isValid()"
           },
@@ -15325,7 +15332,7 @@
           "id" : 32,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 380,
+            "line" : 384,
             "column" : 12,
             "source_fragment" : "hdr.udp.isValid()"
           },
@@ -15348,7 +15355,7 @@
           "id" : 33,
           "source_info" : {
             "filename" : "include/int/int_transit.p4",
-            "line" : 383,
+            "line" : 387,
             "column" : 12,
             "source_fragment" : "hdr.intl4_shim.isValid()"
           },
diff --git a/pipelines/fabric/src/main/resources/p4c-out/fabric-spgw-int/bmv2/default/p4info.txt b/pipelines/fabric/src/main/resources/p4c-out/fabric-spgw-int/bmv2/default/p4info.txt
index f9bc88d..be3e607 100644
--- a/pipelines/fabric/src/main/resources/p4c-out/fabric-spgw-int/bmv2/default/p4info.txt
+++ b/pipelines/fabric/src/main/resources/p4c-out/fabric-spgw-int/bmv2/default/p4info.txt
@@ -472,14 +472,21 @@
     name: "FabricEgress.process_int_main.process_int_transit.tb_int_insert"
     alias: "tb_int_insert"
   }
+  match_fields {
+    id: 1
+    name: "hdr.int_header.is_valid"
+    bitwidth: 1
+    match_type: EXACT
+  }
   action_refs {
     id: 16780783
   }
   action_refs {
-    id: 16800567
+    id: 16819938
     annotations: "@defaultonly()"
   }
-  size: 1024
+  const_default_action_id: 16819938
+  size: 1
   idle_timeout_behavior: NO_TIMEOUT
 }
 tables {