Refer to external bridge and gateway IP from k8s node store

Change-Id: I7dab97ead59e3746b67e6e3bedc3a2c6fea41bf1
diff --git a/apps/k8s-networking/app/src/main/java/org/onosproject/k8snetworking/impl/K8sNetworkHandler.java b/apps/k8s-networking/app/src/main/java/org/onosproject/k8snetworking/impl/K8sNetworkHandler.java
new file mode 100644
index 0000000..e311027
--- /dev/null
+++ b/apps/k8s-networking/app/src/main/java/org/onosproject/k8snetworking/impl/K8sNetworkHandler.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2019-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.k8snetworking.impl;
+
+import org.onosproject.cfg.ComponentConfigService;
+import org.onosproject.cluster.ClusterService;
+import org.onosproject.cluster.LeadershipService;
+import org.onosproject.cluster.NodeId;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.k8snetworking.api.DefaultK8sNetwork;
+import org.onosproject.k8snetworking.api.K8sNetwork;
+import org.onosproject.k8snetworking.api.K8sNetworkAdminService;
+import org.onosproject.k8snode.api.K8sNode;
+import org.onosproject.k8snode.api.K8sNodeEvent;
+import org.onosproject.k8snode.api.K8sNodeListener;
+import org.onosproject.k8snode.api.K8sNodeService;
+import org.onosproject.mastership.MastershipService;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.driver.DriverService;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.slf4j.Logger;
+
+import java.util.Objects;
+import java.util.concurrent.ExecutorService;
+
+import static java.util.concurrent.Executors.newSingleThreadExecutor;
+import static org.onlab.util.Tools.groupedThreads;
+import static org.onosproject.k8snetworking.api.Constants.K8S_NETWORKING_APP_ID;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Provides implementation of initializes the kubernetes network.
+ */
+@Component(immediate = true)
+public class K8sNetworkHandler {
+
+    private final Logger log = getLogger(getClass());
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected CoreService coreService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected ComponentConfigService configService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected DeviceService deviceService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected DriverService driverService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected LeadershipService leadershipService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected MastershipService mastershipService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected ClusterService clusterService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected K8sNodeService k8sNodeService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected K8sNetworkAdminService k8sNetworkService;
+
+    private final InternalK8sNodeListener k8sNodeListener =
+            new InternalK8sNodeListener();
+    private final ExecutorService eventExecutor = newSingleThreadExecutor(
+            groupedThreads(this.getClass().getSimpleName(), "event-handler", log));
+
+    private ApplicationId appId;
+    private NodeId localNodeId;
+
+    @Activate
+    protected void activate() {
+        appId = coreService.registerApplication(K8S_NETWORKING_APP_ID);
+
+        localNodeId = clusterService.getLocalNode().id();
+        leadershipService.runForLeadership(appId.name());
+        k8sNodeService.addListener(k8sNodeListener);
+
+        log.info("Started");
+    }
+
+    @Deactivate
+    protected void deactivate() {
+        k8sNodeService.removeListener(k8sNodeListener);
+        leadershipService.withdraw(appId.name());
+        eventExecutor.shutdown();
+
+        log.info("Stopped");
+    }
+
+    private class InternalK8sNodeListener implements K8sNodeListener {
+
+        private boolean isRelevantHelper() {
+            return Objects.equals(localNodeId, leadershipService.getLeader(appId.name()));
+        }
+
+        @Override
+        public void event(K8sNodeEvent event) {
+            switch (event.type()) {
+                case K8S_NODE_CREATED:
+                    eventExecutor.execute(() -> processNodeCreation(event.subject()));
+                    break;
+                case K8S_NODE_REMOVED:
+                    eventExecutor.execute(() -> processNodeRemoval(event.subject()));
+                    break;
+                default:
+                    break;
+            }
+        }
+
+        private void processNodeCreation(K8sNode k8sNode) {
+            if (!isRelevantHelper()) {
+                return;
+            }
+
+            K8sNetwork network = k8sNetworkService.network(k8sNode.hostname());
+            if (network == null) {
+                K8sNetwork.Builder nBuilder = DefaultK8sNetwork.builder()
+                        .networkId(k8sNode.hostname())
+                        .name(k8sNode.hostname())
+                        .cidr(k8sNode.podCidr());
+                k8sNetworkService.createNetwork(nBuilder.build());
+            }
+        }
+
+        private void processNodeRemoval(K8sNode k8sNode) {
+            if (!isRelevantHelper()) {
+                return;
+            }
+
+            K8sNetwork network = k8sNetworkService.network(k8sNode.hostname());
+            if (network != null) {
+                k8sNetworkService.removeNetwork(k8sNode.hostname());
+            }
+        }
+    }
+}
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 ff0f9de..7910500 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
@@ -24,11 +24,6 @@
 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;
 
@@ -47,10 +42,6 @@
  */
 public class DefaultK8sNode implements K8sNode {
 
-    private static final int DEFAULT_OVSDB_PORT = 6640;
-    private static final String IP_ADDRESS = "ip_address";
-    private static final String EXT_INTF = "ext_interface";
-    private static final String EXT_GW_IP = "ext_gw_ip_address";
     private static final String PORT_MAC = "portMac";
 
     private final String hostname;
@@ -60,7 +51,11 @@
     private final IpAddress managementIp;
     private final IpAddress dataIp;
     private final K8sNodeState state;
+    private final String extIntf;
+    private final IpAddress extBridgeIp;
+    private final IpAddress extGatewayIp;
     private final MacAddress extGatewayMac;
+    private final String podCidr;
 
     private static final String NOT_NULL_MSG = "Node % cannot be null";
 
@@ -73,23 +68,33 @@
      * @param type              node type
      * @param intgBridge        integration bridge
      * @param extBridge         external bridge
+     * @param extIntf           external interface
      * @param managementIp      management IP address
      * @param dataIp            data IP address
      * @param state             node state
+     * @param extBridgeIp       external bridge IP address
+     * @param extGatewayIp      external gateway IP address
      * @param extGatewayMac     external gateway MAC address
+     * @param podCidr           POD CIDR
      */
     protected DefaultK8sNode(String hostname, Type type, DeviceId intgBridge,
-                             DeviceId extBridge, IpAddress managementIp,
-                             IpAddress dataIp, K8sNodeState state,
-                             MacAddress extGatewayMac) {
+                             DeviceId extBridge, String extIntf,
+                             IpAddress managementIp, IpAddress dataIp,
+                             K8sNodeState state, IpAddress extBridgeIp,
+                             IpAddress extGatewayIp, MacAddress extGatewayMac,
+                             String podCidr) {
         this.hostname = hostname;
         this.type = type;
         this.intgBridge = intgBridge;
         this.extBridge = extBridge;
+        this.extIntf = extIntf;
         this.managementIp = managementIp;
         this.dataIp = dataIp;
         this.state = state;
+        this.extBridgeIp = extBridgeIp;
+        this.extGatewayIp = extGatewayIp;
         this.extGatewayMac = extGatewayMac;
+        this.podCidr = podCidr;
     }
 
     @Override
@@ -118,16 +123,25 @@
     }
 
     @Override
+    public String extIntf() {
+        return extIntf;
+    }
+
+    @Override
     public K8sNode updateIntgBridge(DeviceId deviceId) {
         return new Builder()
                 .hostname(hostname)
                 .type(type)
                 .intgBridge(deviceId)
                 .extBridge(extBridge)
+                .extIntf(extIntf)
                 .managementIp(managementIp)
                 .dataIp(dataIp)
                 .state(state)
+                .extBridgeIp(extBridgeIp)
+                .extGatewayIp(extGatewayIp)
                 .extGatewayMac(extGatewayMac)
+                .podCidr(podCidr)
                 .build();
     }
 
@@ -138,10 +152,14 @@
                 .type(type)
                 .intgBridge(intgBridge)
                 .extBridge(deviceId)
+                .extIntf(extIntf)
                 .managementIp(managementIp)
                 .dataIp(dataIp)
                 .state(state)
+                .extBridgeIp(extBridgeIp)
+                .extGatewayIp(extGatewayIp)
                 .extGatewayMac(extGatewayMac)
+                .podCidr(podCidr)
                 .build();
     }
 
@@ -161,15 +179,25 @@
     }
 
     @Override
+    public String podCidr() {
+        return podCidr;
+    }
+
+    @Override
     public K8sNode updateState(K8sNodeState newState) {
         return new Builder()
                 .hostname(hostname)
                 .type(type)
                 .intgBridge(intgBridge)
+                .extBridge(extBridge)
+                .extIntf(extIntf)
                 .managementIp(managementIp)
                 .dataIp(dataIp)
                 .state(newState)
+                .extBridgeIp(extBridgeIp)
+                .extGatewayIp(extGatewayIp)
                 .extGatewayMac(extGatewayMac)
+                .podCidr(podCidr)
                 .build();
     }
 
@@ -179,12 +207,16 @@
                 .hostname(hostname)
                 .type(type)
                 .intgBridge(intgBridge)
+                .extBridge(extBridge)
+                .extIntf(extIntf)
                 .managementIp(managementIp)
                 .dataIp(dataIp)
                 .state(state)
+                .extBridgeIp(extBridgeIp)
+                .extGatewayIp(extGatewayIp)
                 .extGatewayMac(newMac)
+                .podCidr(podCidr)
                 .build();
-
     }
 
     @Override
@@ -219,20 +251,11 @@
 
     @Override
     public PortNumber extBridgePortNum() {
-        OvsdbClientService client = getOvsClient();
-
-        if (client == null) {
+        if (this.extIntf == null) {
             return null;
         }
 
-        Interface iface = getOvsClient().getInterface(EXTERNAL_BRIDGE);
-        OvsdbMap data = (OvsdbMap) iface.getExternalIdsColumn().data();
-        String extIface = (String) data.map().get(EXT_INTF);
-        if (extIface == null) {
-            return null;
-        }
-
-        return portNumber(extBridge, extIface);
+        return portNumber(extBridge, this.extIntf);
     }
 
     @Override
@@ -242,15 +265,7 @@
 
     @Override
     public IpAddress extBridgeIp() {
-        OvsdbClientService client = getOvsClient();
-
-        if (client == null) {
-            return null;
-        }
-
-        Interface iface = getOvsClient().getInterface(EXTERNAL_BRIDGE);
-        OvsdbMap data = (OvsdbMap) iface.getExternalIdsColumn().data();
-        return IpAddress.valueOf((String) data.map().get(IP_ADDRESS));
+        return extBridgeIp;
     }
 
     @Override
@@ -260,15 +275,7 @@
 
     @Override
     public IpAddress extGatewayIp() {
-        OvsdbClientService client = getOvsClient();
-
-        if (client == null) {
-            return null;
-        }
-
-        Interface iface = getOvsClient().getInterface(EXTERNAL_BRIDGE);
-        OvsdbMap data = (OvsdbMap) iface.getExternalIdsColumn().data();
-        return IpAddress.valueOf((String) data.map().get(EXT_GW_IP));
+        return extGatewayIp;
     }
 
     @Override
@@ -289,8 +296,12 @@
                     type == that.type &&
                     intgBridge.equals(that.intgBridge) &&
                     extBridge.equals(that.extBridge) &&
+                    extIntf.equals(that.extIntf) &&
                     managementIp.equals(that.managementIp) &&
                     dataIp.equals(that.dataIp) &&
+                    extBridgeIp.equals(that.extBridgeIp) &&
+                    extGatewayIp.equals(that.extGatewayIp) &&
+                    podCidr.equals(that.podCidr) &&
                     state == that.state;
         }
 
@@ -299,8 +310,9 @@
 
     @Override
     public int hashCode() {
-        return Objects.hash(hostname, type, intgBridge, extBridge,
-                            managementIp, dataIp, state, extGatewayMac);
+        return Objects.hash(hostname, type, intgBridge, extBridge, extIntf,
+                            managementIp, dataIp, state, extBridgeIp,
+                            extGatewayIp, extGatewayMac, podCidr);
     }
 
     @Override
@@ -310,10 +322,14 @@
                 .add("type", type)
                 .add("intgBridge", intgBridge)
                 .add("extBridge", extBridge)
+                .add("extIntf", extIntf)
                 .add("managementIp", managementIp)
                 .add("dataIp", dataIp)
                 .add("state", state)
+                .add("extBridgeIp", extBridgeIp)
+                .add("extGatewayIp", extGatewayIp)
                 .add("extGatewayMac", extGatewayMac)
+                .add("podCidr", podCidr)
                 .toString();
     }
 
@@ -344,18 +360,6 @@
                 .findAny().orElse(null);
     }
 
-    private OvsdbClientService getOvsClient() {
-        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;
-        }
-
-        return client;
-    }
-
     /**
      * Returns new builder instance.
      *
@@ -377,10 +381,14 @@
                 .type(node.type())
                 .intgBridge(node.intgBridge())
                 .extBridge(node.extBridge())
+                .extIntf(node.extIntf())
                 .managementIp(node.managementIp())
                 .dataIp(node.dataIp())
                 .state(node.state())
-                .extGatewayMac(node.extGatewayMac());
+                .extBridgeIp(node.extBridgeIp())
+                .extGatewayIp(node.extGatewayIp())
+                .extGatewayMac(node.extGatewayMac())
+                .podCidr(node.podCidr());
     }
 
     public static final class Builder implements K8sNode.Builder {
@@ -393,7 +401,11 @@
         private IpAddress dataIp;
         private K8sNodeState state;
         private K8sApiConfig apiConfig;
+        private String extIntf;
+        private IpAddress extBridgeIp;
+        private IpAddress extGatewayIp;
         private MacAddress extGatewayMac;
+        private String podCidr;
 
         // private constructor not intended to use from external
         private Builder() {
@@ -410,10 +422,14 @@
                     type,
                     intgBridge,
                     extBridge,
+                    extIntf,
                     managementIp,
                     dataIp,
                     state,
-                    extGatewayMac);
+                    extBridgeIp,
+                    extGatewayIp,
+                    extGatewayMac,
+                    podCidr);
         }
 
         @Override
@@ -441,6 +457,12 @@
         }
 
         @Override
+        public Builder extIntf(String intf) {
+            this.extIntf = intf;
+            return this;
+        }
+
+        @Override
         public Builder managementIp(IpAddress managementIp) {
             this.managementIp = managementIp;
             return this;
@@ -459,9 +481,27 @@
         }
 
         @Override
+        public Builder extBridgeIp(IpAddress extBridgeIp) {
+            this.extBridgeIp = extBridgeIp;
+            return this;
+        }
+
+        @Override
+        public Builder extGatewayIp(IpAddress extGatewayIp) {
+            this.extGatewayIp = extGatewayIp;
+            return this;
+        }
+
+        @Override
         public Builder extGatewayMac(MacAddress extGatewayMac) {
             this.extGatewayMac = extGatewayMac;
             return this;
         }
+
+        @Override
+        public Builder podCidr(String podCidr) {
+            this.podCidr = podCidr;
+            return this;
+        }
     }
 }
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 8d6f57c..18e943a 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
@@ -76,6 +76,13 @@
     DeviceId extBridge();
 
     /**
+     * Returns the external interface name.
+     *
+     * @return external interface name
+     */
+    String extIntf();
+
+    /**
      * Returns new kubernetes node instance with given integration bridge.
      *
      * @param deviceId  integration bridge device ID
@@ -113,6 +120,13 @@
     K8sNodeState state();
 
     /**
+     * Returns the POD CIDR of the node.
+     *
+     * @return POD CIDR (e.g., 10.10.0.0/24)
+     */
+    String podCidr();
+
+    /**
      * Returns new kubernetes node instance with given state.
      *
      * @param newState updated state
@@ -257,6 +271,14 @@
         Builder extBridge(DeviceId deviceId);
 
         /**
+         * Returns kubernetes node builder with supplied external interface.
+         *
+         * @param intf external interface
+         * @return kubernetes node builder
+         */
+        Builder extIntf(String intf);
+
+        /**
          * Returns kubernetes node builder with supplied management IP address.
          *
          * @param managementIp management IP address
@@ -281,11 +303,35 @@
         Builder state(K8sNodeState state);
 
         /**
+         * Returns kubernetes node builder with supplied external bridge IP.
+         *
+         * @param extBridgeIp external bridge IP
+         * @return kubernetes node builder
+         */
+        Builder extBridgeIp(IpAddress extBridgeIp);
+
+        /**
+         * Returns kubernetes node builder with supplied gateway IP.
+         *
+         * @param extGatewayIp external gateway IP
+         * @return kubernetes node builder
+         */
+        Builder extGatewayIp(IpAddress extGatewayIp);
+
+        /**
          * Returns kubernetes node builder with supplied external gateway MAC.
          *
          * @param extGatewayMac external gateway MAC address
          * @return kubernetes node builder
          */
         Builder extGatewayMac(MacAddress extGatewayMac);
+
+        /**
+         * Returns kubernetes node builder with supplied POD CIDR.
+         *
+         * @param podCidr POD CIDR
+         * @return kubernetes node builder
+         */
+        Builder podCidr(String podCidr);
     }
 }
diff --git a/apps/k8s-node/api/src/test/java/org/onosproject/k8snode/api/DefaultK8sNodeTest.java b/apps/k8s-node/api/src/test/java/org/onosproject/k8snode/api/DefaultK8sNodeTest.java
index d93c8dc..166b528 100644
--- a/apps/k8s-node/api/src/test/java/org/onosproject/k8snode/api/DefaultK8sNodeTest.java
+++ b/apps/k8s-node/api/src/test/java/org/onosproject/k8snode/api/DefaultK8sNodeTest.java
@@ -49,6 +49,18 @@
     private static final IpAddress MANAGEMENT_IP = IpAddress.valueOf("10.10.10.10");
     private static final IpAddress DATA_IP = IpAddress.valueOf("20.20.20.20");
 
+    private static final String BRIDGE_INTF_1 = "eth1";
+    private static final String BRIDGE_INTF_2 = "eth2";
+
+    private static final IpAddress EXT_BRIDGE_IP_1 = IpAddress.valueOf("10.10.10.5");
+    private static final IpAddress EXT_BRIDGE_IP_2 = IpAddress.valueOf("20.20.20.5");
+
+    private static final IpAddress EXT_GATEWAY_IP_1 = IpAddress.valueOf("10.10.10.1");
+    private static final IpAddress EXT_GATEWAY_IP_2 = IpAddress.valueOf("20.20.20.1");
+
+    private static final String POD_CIDR_1 = "10.10.0.0/24";
+    private static final String POD_CIDR_2 = "20.20.0.0/24";
+
     private K8sNode refNode;
 
     private static final K8sNode K8S_NODE_1 = createNode(
@@ -56,22 +68,34 @@
             MINION,
             DEVICE_1,
             DEVICE_1,
+            BRIDGE_INTF_1,
             TEST_IP,
-            INIT);
+            INIT,
+            EXT_BRIDGE_IP_1,
+            EXT_GATEWAY_IP_1,
+            POD_CIDR_1);
     private static final K8sNode K8S_NODE_2 = createNode(
             HOSTNAME_1,
             MINION,
             DEVICE_1,
             DEVICE_1,
+            BRIDGE_INTF_1,
             TEST_IP,
-            INIT);
+            INIT,
+            EXT_BRIDGE_IP_1,
+            EXT_GATEWAY_IP_1,
+            POD_CIDR_1);
     private static final K8sNode K8S_NODE_3 = createNode(
             HOSTNAME_2,
             MINION,
             DEVICE_2,
             DEVICE_2,
+            BRIDGE_INTF_2,
             TEST_IP,
-            INIT);
+            INIT,
+            EXT_BRIDGE_IP_2,
+            EXT_GATEWAY_IP_2,
+            POD_CIDR_2);
 
     /**
      * Initial setup for this unit test.
@@ -85,7 +109,11 @@
                 .dataIp(DATA_IP)
                 .intgBridge(DEVICE_1.id())
                 .extBridge(DEVICE_1.id())
+                .extIntf(BRIDGE_INTF_1)
                 .state(COMPLETE)
+                .extBridgeIp(EXT_BRIDGE_IP_1)
+                .extGatewayIp(EXT_GATEWAY_IP_1)
+                .podCidr(POD_CIDR_1)
                 .build();
     }
 
@@ -140,9 +168,13 @@
                 .type(MINION)
                 .intgBridge(DEVICE_1.id())
                 .extBridge(DEVICE_1.id())
+                .extIntf(BRIDGE_INTF_1)
                 .managementIp(TEST_IP)
                 .dataIp(TEST_IP)
                 .state(INIT)
+                .extBridgeIp(EXT_BRIDGE_IP_1)
+                .extGatewayIp(EXT_GATEWAY_IP_1)
+                .podCidr(POD_CIDR_1)
                 .build();
     }
 
@@ -155,9 +187,13 @@
                 .hostname(HOSTNAME_1)
                 .intgBridge(DEVICE_1.id())
                 .extBridge(DEVICE_1.id())
+                .extIntf(BRIDGE_INTF_1)
                 .managementIp(TEST_IP)
                 .dataIp(TEST_IP)
                 .state(INIT)
+                .extBridgeIp(EXT_BRIDGE_IP_1)
+                .extGatewayIp(EXT_GATEWAY_IP_1)
+                .podCidr(POD_CIDR_1)
                 .build();
     }
 
@@ -172,8 +208,12 @@
                 .type(MINION)
                 .intgBridge(DEVICE_1.id())
                 .extBridge(DEVICE_1.id())
+                .extIntf(BRIDGE_INTF_1)
                 .dataIp(TEST_IP)
                 .state(INIT)
+                .extBridgeIp(EXT_BRIDGE_IP_1)
+                .extGatewayIp(EXT_GATEWAY_IP_1)
+                .podCidr(POD_CIDR_1)
                 .build();
     }
 
@@ -197,15 +237,21 @@
 
     private static K8sNode createNode(String hostname, Type type,
                                       Device intgBridge, Device extBridge,
-                                      IpAddress ipAddr, K8sNodeState state) {
+                                      String bridgeIntf, IpAddress ipAddr,
+                                      K8sNodeState state, IpAddress extBridgeIp,
+                                      IpAddress extGatewayIp, String podCidr) {
         return DefaultK8sNode.builder()
                 .hostname(hostname)
                 .type(type)
                 .intgBridge(intgBridge.id())
                 .extBridge(extBridge.id())
+                .extIntf(bridgeIntf)
                 .managementIp(ipAddr)
                 .dataIp(ipAddr)
                 .state(state)
+                .extBridgeIp(extBridgeIp)
+                .extGatewayIp(extGatewayIp)
+                .podCidr(podCidr)
                 .build();
     }
 }
diff --git a/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/codec/K8sNodeCodec.java b/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/codec/K8sNodeCodec.java
index 6676847..7c7b32b 100644
--- a/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/codec/K8sNodeCodec.java
+++ b/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/codec/K8sNodeCodec.java
@@ -44,6 +44,9 @@
     private static final String INTEGRATION_BRIDGE = "integrationBridge";
     private static final String EXTERNAL_BRIDGE = "externalBridge";
     private static final String STATE = "state";
+    private static final String EXTERNAL_INTF = "externalInterface";
+    private static final String EXTERNAL_BRIDGE_IP = "externalBridgeIp";
+    private static final String EXTERNAL_GATEWAY_IP = "externalGatewayIp";
 
     private static final String MISSING_MESSAGE = " is required in K8sNode";
 
@@ -69,6 +72,18 @@
             result.put(DATA_IP, node.dataIp().toString());
         }
 
+        if (node.extIntf() != null) {
+            result.put(EXTERNAL_INTF, node.extIntf());
+        }
+
+        if (node.extBridgeIp() != null) {
+            result.put(EXTERNAL_BRIDGE_IP, node.extBridgeIp().toString());
+        }
+
+        if (node.extGatewayIp() != null) {
+            result.put(EXTERNAL_GATEWAY_IP, node.extGatewayIp().toString());
+        }
+
         return result;
     }
 
@@ -105,6 +120,21 @@
             nodeBuilder.extBridge(DeviceId.deviceId(extBridgeJson.asText()));
         }
 
+        JsonNode extIntfJson = json.get(EXTERNAL_INTF);
+        if (extIntfJson != null) {
+            nodeBuilder.extIntf(extIntfJson.asText());
+        }
+
+        JsonNode extBridgeIpJson = json.get(EXTERNAL_BRIDGE_IP);
+        if (extBridgeIpJson != null) {
+            nodeBuilder.extBridgeIp(IpAddress.valueOf(extBridgeIpJson.asText()));
+        }
+
+        JsonNode extGatewayIpJson = json.get(EXTERNAL_GATEWAY_IP);
+        if (extGatewayIpJson != null) {
+            nodeBuilder.extGatewayIp(IpAddress.valueOf(extGatewayIpJson.asText()));
+        }
+
         log.trace("node is {}", nodeBuilder.build().toString());
 
         return nodeBuilder.build();
diff --git a/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/impl/DefaultK8sApiConfigHandler.java b/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/impl/DefaultK8sApiConfigHandler.java
index ab04556..5119500 100644
--- a/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/impl/DefaultK8sApiConfigHandler.java
+++ b/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/impl/DefaultK8sApiConfigHandler.java
@@ -38,6 +38,7 @@
 import org.osgi.service.component.annotations.ReferenceCardinality;
 import org.slf4j.Logger;
 
+import java.util.Map;
 import java.util.Objects;
 import java.util.concurrent.ExecutorService;
 
@@ -60,6 +61,9 @@
 
     private static final String INTERNAL_IP = "InternalIP";
     private static final String K8S_ROLE = "node-role.kubernetes.io";
+    private static final String EXT_BRIDGE_IP = "external.bridge.ip";
+    private static final String EXT_GATEWAY_IP = "external.gateway.ip";
+    private static final String EXT_INTF_NAME = "external.interface.name";
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY)
     protected CoreService coreService;
@@ -156,12 +160,22 @@
             }
         }
 
+        Map<String, String> annots = node.getMetadata().getAnnotations();
+
+        String extIntf = annots.get(EXT_INTF_NAME);
+        String extGatewayIpStr = annots.get(EXT_GATEWAY_IP);
+        String extBridgeIpStr = annots.get(EXT_BRIDGE_IP);
+
         return DefaultK8sNode.builder()
                 .hostname(hostname)
                 .managementIp(managementIp)
                 .dataIp(dataIp)
-                .type(nodeType)  // need to get correct node type
+                .extIntf(extIntf)
+                .type(nodeType)
                 .state(INIT)
+                .extBridgeIp(IpAddress.valueOf(extBridgeIpStr))
+                .extGatewayIp(IpAddress.valueOf(extGatewayIpStr))
+                .podCidr(node.getSpec().getPodCIDR())
                 .build();
     }
 
diff --git a/apps/k8s-node/app/src/test/java/org/onosproject/k8snode/codec/K8sNodeCodecTest.java b/apps/k8s-node/app/src/test/java/org/onosproject/k8snode/codec/K8sNodeCodecTest.java
index 7f156e8..556e462 100644
--- a/apps/k8s-node/app/src/test/java/org/onosproject/k8snode/codec/K8sNodeCodecTest.java
+++ b/apps/k8s-node/app/src/test/java/org/onosproject/k8snode/codec/K8sNodeCodecTest.java
@@ -84,6 +84,9 @@
                 .managementIp(IpAddress.valueOf("10.10.10.1"))
                 .dataIp(IpAddress.valueOf("20.20.20.2"))
                 .intgBridge(DeviceId.deviceId("kbr-int"))
+                .extIntf("eth1")
+                .extBridgeIp(IpAddress.valueOf("10.10.10.5"))
+                .extGatewayIp(IpAddress.valueOf("10.10.10.1"))
                 .build();
 
         ObjectNode nodeJson = k8sNodeCodec.encode(node, context);
@@ -104,6 +107,9 @@
         assertEquals("172.16.130.4", node.managementIp().toString());
         assertEquals("172.16.130.4", node.dataIp().toString());
         assertEquals("of:00000000000000a1", node.intgBridge().toString());
+        assertEquals("eth1", node.extIntf());
+        assertEquals("172.16.130.5", node.extBridgeIp().toString());
+        assertEquals("172.16.130.1", node.extGatewayIp().toString());
     }
 
     private K8sNode getK8sNode(String resourceName) throws IOException {
diff --git a/apps/k8s-node/app/src/test/java/org/onosproject/k8snode/codec/K8sNodeJsonMatcher.java b/apps/k8s-node/app/src/test/java/org/onosproject/k8snode/codec/K8sNodeJsonMatcher.java
index 58b15d2..b953f54 100644
--- a/apps/k8s-node/app/src/test/java/org/onosproject/k8snode/codec/K8sNodeJsonMatcher.java
+++ b/apps/k8s-node/app/src/test/java/org/onosproject/k8snode/codec/K8sNodeJsonMatcher.java
@@ -18,6 +18,7 @@
 import com.fasterxml.jackson.databind.JsonNode;
 import org.hamcrest.Description;
 import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.onlab.packet.IpAddress;
 import org.onosproject.k8snode.api.K8sNode;
 
 /**
@@ -33,6 +34,9 @@
     private static final String DATA_IP = "dataIp";
     private static final String INTEGRATION_BRIDGE = "integrationBridge";
     private static final String STATE = "state";
+    private static final String EXTERNAL_INTF = "externalInterface";
+    private static final String EXTERNAL_BRIDGE_IP = "externalBridgeIp";
+    private static final String EXTERNAL_GATEWAY_IP = "externalGatewayIp";
 
     private K8sNodeJsonMatcher(K8sNode node) {
         this.node = node;
@@ -93,6 +97,36 @@
             }
         }
 
+        // check external interface
+        JsonNode jsonExtIntf = jsonNode.get(EXTERNAL_INTF);
+        if (jsonExtIntf != null) {
+            String extIntf = node.extIntf();
+            if (!jsonExtIntf.asText().equals(extIntf)) {
+                description.appendText("External interface was " + jsonExtIntf.asText());
+                return false;
+            }
+        }
+
+        // check external bridge IP
+        JsonNode jsonExtBridgeIp = jsonNode.get(EXTERNAL_BRIDGE_IP);
+        if (jsonExtBridgeIp != null) {
+            IpAddress extBridgeIp = node.extBridgeIp();
+            if (!jsonExtBridgeIp.asText().equals(extBridgeIp.toString())) {
+                description.appendText("External bridge IP was " + jsonExtBridgeIp.asText());
+                return false;
+            }
+        }
+
+        // check external gateway IP
+        JsonNode jsonExtGatewayIp = jsonNode.get(EXTERNAL_GATEWAY_IP);
+        if (jsonExtGatewayIp != null) {
+            IpAddress extGatewayIp = node.extGatewayIp();
+            if (!jsonExtGatewayIp.asText().equals(extGatewayIp.toString())) {
+                description.appendText("External gateway IP was " + jsonExtGatewayIp.asText());
+                return false;
+            }
+        }
+
         return true;
     }
 
diff --git a/apps/k8s-node/app/src/test/resources/org/onosproject/k8snode/codec/K8sMinionNode.json b/apps/k8s-node/app/src/test/resources/org/onosproject/k8snode/codec/K8sMinionNode.json
index 9ed649e..2930bfd 100644
--- a/apps/k8s-node/app/src/test/resources/org/onosproject/k8snode/codec/K8sMinionNode.json
+++ b/apps/k8s-node/app/src/test/resources/org/onosproject/k8snode/codec/K8sMinionNode.json
@@ -4,5 +4,8 @@
   "managementIp": "172.16.130.4",
   "dataIp": "172.16.130.4",
   "integrationBridge": "of:00000000000000a1",
-  "externalBridge": "of:00000000000000b1"
+  "externalBridge": "of:00000000000000b1",
+  "externalInterface": "eth1",
+  "externalBridgeIp": "172.16.130.5",
+  "externalGatewayIp": "172.16.130.1"
 }
\ No newline at end of file