Install rules for handling traffic destined to gateway at k8s node

Change-Id: I3a3ce8ecc581aee7e8e70e338dbf7bf4a6c518db
diff --git a/apps/k8s-node/api/BUILD b/apps/k8s-node/api/BUILD
index 36d2da1..55de911 100644
--- a/apps/k8s-node/api/BUILD
+++ b/apps/k8s-node/api/BUILD
@@ -1,4 +1,7 @@
-COMPILE_DEPS = CORE_DEPS
+COMPILE_DEPS = CORE_DEPS + [
+    "//protocols/ovsdb/api:onos-protocols-ovsdb-api",
+    "//protocols/ovsdb/rfc:onos-protocols-ovsdb-rfc",
+]
 
 TEST_DEPS = TEST_ADAPTERS + [
     "//core/api:onos-api-tests",
diff --git a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/DefaultK8sNode.java b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/DefaultK8sNode.java
index 3e26a50..c7c08d3 100644
--- a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/DefaultK8sNode.java
+++ b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/DefaultK8sNode.java
@@ -18,10 +18,16 @@
 import com.google.common.base.MoreObjects;
 import org.onlab.osgi.DefaultServiceDirectory;
 import org.onlab.packet.IpAddress;
+import org.onlab.packet.MacAddress;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.Port;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.device.DeviceService;
+import org.onosproject.ovsdb.controller.OvsdbClientService;
+import org.onosproject.ovsdb.controller.OvsdbController;
+import org.onosproject.ovsdb.controller.OvsdbNodeId;
+import org.onosproject.ovsdb.rfc.notation.OvsdbMap;
+import org.onosproject.ovsdb.rfc.table.Interface;
 
 import java.util.Objects;
 
@@ -37,6 +43,9 @@
  */
 public class DefaultK8sNode implements K8sNode {
 
+    private static final int DEFAULT_OVSDB_PORT = 6640;
+    private static final String MAC_ADDRESS = "mac_address";
+
     private final String hostname;
     private final Type type;
     private final DeviceId intgBridge;
@@ -154,6 +163,21 @@
     }
 
     @Override
+    public MacAddress intBridgeMac() {
+        OvsdbController ovsdbController =
+                DefaultServiceDirectory.getService(OvsdbController.class);
+        OvsdbNodeId ovsdb = new OvsdbNodeId(this.managementIp, DEFAULT_OVSDB_PORT);
+        OvsdbClientService client = ovsdbController.getOvsdbClient(ovsdb);
+        if (client == null) {
+            return null;
+        }
+
+        Interface iface = client.getInterface(INTEGRATION_BRIDGE);
+        OvsdbMap data = (OvsdbMap) iface.getExternalIdsColumn().data();
+        return MacAddress.valueOf((String) data.map().get(MAC_ADDRESS));
+    }
+
+    @Override
     public boolean equals(Object obj) {
         if (this == obj) {
             return true;
diff --git a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sNode.java b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sNode.java
index 671b37a..2c539f3 100644
--- a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sNode.java
+++ b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sNode.java
@@ -16,6 +16,7 @@
 package org.onosproject.k8snode.api;
 
 import org.onlab.packet.IpAddress;
+import org.onlab.packet.MacAddress;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.PortNumber;
 
@@ -133,6 +134,13 @@
     PortNumber intBridgePortNum();
 
     /**
+     * Returns the integration bridge's MAC address.
+     *
+     * @return MAC address; null if the MAC address does not exist
+     */
+    MacAddress intBridgeMac();
+
+    /**
      * Builder of new node entity.
      */
     interface Builder {