Fix: allow to invoke service IP from local k8s node

Change-Id: I8c39703f35319bb51bbd175e7ff717d5e6ec5250
diff --git a/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/impl/DefaultK8sNodeHandler.java b/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/impl/DefaultK8sNodeHandler.java
index 83e537c..f31301f 100644
--- a/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/impl/DefaultK8sNodeHandler.java
+++ b/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/impl/DefaultK8sNodeHandler.java
@@ -74,6 +74,9 @@
 import static org.onosproject.k8snode.api.Constants.GRE_TUNNEL;
 import static org.onosproject.k8snode.api.Constants.INTEGRATION_BRIDGE;
 import static org.onosproject.k8snode.api.Constants.INTEGRATION_TO_EXTERNAL_BRIDGE;
+import static org.onosproject.k8snode.api.Constants.INTEGRATION_TO_LOCAL_BRIDGE;
+import static org.onosproject.k8snode.api.Constants.LOCAL_BRIDGE;
+import static org.onosproject.k8snode.api.Constants.LOCAL_TO_INTEGRATION_BRIDGE;
 import static org.onosproject.k8snode.api.Constants.PHYSICAL_EXTERNAL_BRIDGE;
 import static org.onosproject.k8snode.api.Constants.VXLAN;
 import static org.onosproject.k8snode.api.Constants.VXLAN_TUNNEL;
@@ -196,6 +199,9 @@
         if (!deviceService.isAvailable(k8sNode.extBridge())) {
             createBridge(k8sNode, EXTERNAL_BRIDGE, k8sNode.extBridge());
         }
+        if (!deviceService.isAvailable(k8sNode.localBridge())) {
+            createBridge(k8sNode, LOCAL_BRIDGE, k8sNode.localBridge());
+        }
     }
 
     @Override
@@ -328,23 +334,43 @@
             return;
         }
 
-        PatchDescription brIntPatchDesc =
+        // integration bridge -> external bridge
+        PatchDescription brIntExtPatchDesc =
                 DefaultPatchDescription.builder()
                 .deviceId(INTEGRATION_BRIDGE)
                 .ifaceName(INTEGRATION_TO_EXTERNAL_BRIDGE)
                 .peer(PHYSICAL_EXTERNAL_BRIDGE)
                 .build();
 
-        PatchDescription brExtPatchDesc =
+        // external bridge -> integration bridge
+        PatchDescription brExtIntPatchDesc =
                 DefaultPatchDescription.builder()
                 .deviceId(EXTERNAL_BRIDGE)
                 .ifaceName(PHYSICAL_EXTERNAL_BRIDGE)
                 .peer(INTEGRATION_TO_EXTERNAL_BRIDGE)
                 .build();
 
+        // integration bridge -> local bridge
+        PatchDescription brIntLocalPatchDesc =
+                DefaultPatchDescription.builder()
+                        .deviceId(INTEGRATION_BRIDGE)
+                        .ifaceName(INTEGRATION_TO_LOCAL_BRIDGE)
+                        .peer(LOCAL_TO_INTEGRATION_BRIDGE)
+                        .build();
+
+        // local bridge -> integration bridge
+        PatchDescription brLocalIntPatchDesc =
+                DefaultPatchDescription.builder()
+                        .deviceId(LOCAL_BRIDGE)
+                        .ifaceName(LOCAL_TO_INTEGRATION_BRIDGE)
+                        .peer(INTEGRATION_TO_LOCAL_BRIDGE)
+                        .build();
+
         InterfaceConfig ifaceConfig = device.as(InterfaceConfig.class);
-        ifaceConfig.addPatchMode(INTEGRATION_TO_EXTERNAL_BRIDGE, brIntPatchDesc);
-        ifaceConfig.addPatchMode(PHYSICAL_EXTERNAL_BRIDGE, brExtPatchDesc);
+        ifaceConfig.addPatchMode(INTEGRATION_TO_EXTERNAL_BRIDGE, brIntExtPatchDesc);
+        ifaceConfig.addPatchMode(PHYSICAL_EXTERNAL_BRIDGE, brExtIntPatchDesc);
+        ifaceConfig.addPatchMode(INTEGRATION_TO_LOCAL_BRIDGE, brIntLocalPatchDesc);
+        ifaceConfig.addPatchMode(LOCAL_TO_INTEGRATION_BRIDGE, brLocalIntPatchDesc);
     }
 
     /**
@@ -436,7 +462,8 @@
 
                 return k8sNode.intgBridge() != null && k8sNode.extBridge() != null &&
                         deviceService.isAvailable(k8sNode.intgBridge()) &&
-                        deviceService.isAvailable(k8sNode.extBridge());
+                        deviceService.isAvailable(k8sNode.extBridge()) &&
+                        deviceService.isAvailable(k8sNode.localBridge());
             case DEVICE_CREATED:
                 if (k8sNode.dataIp() != null &&
                         !isIntfEnabled(k8sNode, VXLAN_TUNNEL)) {
@@ -505,6 +532,9 @@
         // delete external bridge from the node
         client.dropBridge(EXTERNAL_BRIDGE);
 
+        // delete local bridge from the node
+        client.dropBridge(LOCAL_BRIDGE);
+
         // disconnect ovsdb
         client.disconnect();
     }
@@ -597,6 +627,7 @@
                         }
 
                         // TODO: also need to check the external bridge's availability
+                        // TODO: also need to check the local bridge's availability
                         if (deviceService.isAvailable(device.id())) {
                             log.debug("Integration bridge created on {}",
                                     k8sNode.hostname());