[ONOS-7553] Support injecting physical interfaces to openstack node

Change-Id: I5d746e9b4fa6015dbaec90d27ea7e1a7fa105e31
diff --git a/apps/openstacknode/api/src/main/java/org/onosproject/openstacknode/api/OpenstackNode.java b/apps/openstacknode/api/src/main/java/org/onosproject/openstacknode/api/OpenstackNode.java
index 1b8316d..c951041 100644
--- a/apps/openstacknode/api/src/main/java/org/onosproject/openstacknode/api/OpenstackNode.java
+++ b/apps/openstacknode/api/src/main/java/org/onosproject/openstacknode/api/OpenstackNode.java
@@ -22,17 +22,21 @@
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.group.GroupKey;
 
+import java.util.Collection;
+
 /**
  * Representation of a node used in OpenstackNetworking service.
  */
 public interface OpenstackNode {
 
     /**
-     * List of valid virtual network modes.
+     * List of valid network modes.
+     * This includes both physical and virtual network types.
      */
     enum NetworkMode {
         VXLAN,
-        VLAN
+        VLAN,
+        FLAT
     }
 
     /**
@@ -166,6 +170,13 @@
     OpenstackNode updateState(NodeState newState);
 
     /**
+     * Returns a collection of physical interfaces.
+     *
+     * @return physical interfaces
+     */
+    Collection<OpenstackPhyInterface> phyIntfs();
+
+    /**
      * Builder of new node entities.
      */
     interface Builder {
@@ -240,6 +251,14 @@
          * @return openstack node builder
          */
         Builder state(NodeState state);
+
+        /**
+         * Returns openstack node builder with supplied physical interfaces.
+         *
+         * @param phyIntfs a collection of physical interfaces
+         * @return openstack node builder
+         */
+        Builder phyIntfs(Collection<OpenstackPhyInterface> phyIntfs);
     }
 }
 
diff --git a/apps/openstacknode/api/src/main/java/org/onosproject/openstacknode/api/OpenstackPhyInterface.java b/apps/openstacknode/api/src/main/java/org/onosproject/openstacknode/api/OpenstackPhyInterface.java
new file mode 100644
index 0000000..77309e9
--- /dev/null
+++ b/apps/openstacknode/api/src/main/java/org/onosproject/openstacknode/api/OpenstackPhyInterface.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2018-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.openstacknode.api;
+
+public interface OpenstackPhyInterface {
+
+    /**
+     * Returns physical network name that this interface binds to.
+     *
+     * @return physical network name
+     */
+    String network();
+
+    /**
+     * Returns name of this physical interface.
+     *
+     * @return name of this physical interface
+     */
+    String intf();
+
+    /**
+     * Builder of openstack physical interface.
+     */
+    interface Builder {
+
+        /**
+         * Builds an immutable openstack physical interface instance.
+         *
+         * @return openstack physical interface instance
+         */
+        OpenstackPhyInterface build();
+
+        /**
+         * Returns physical network that this physical interface connects with.
+         *
+         * @param network network name
+         * @return openstack physical interface builder
+         */
+        Builder network(String network);
+
+        /**
+         * Returns physical interface name.
+         *
+         * @param intf physical interface name of openstack node
+         * @return openstack physical interface builder
+         */
+        Builder intf(String intf);
+    }
+}
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackNodeCodec.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackNodeCodec.java
index 8bae1ea..3c5feba 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackNodeCodec.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackNodeCodec.java
@@ -15,6 +15,8 @@
  */
 package org.onosproject.openstacknode.codec;
 
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import org.onlab.packet.IpAddress;
 import org.onosproject.codec.CodecContext;
@@ -22,9 +24,14 @@
 import org.onosproject.net.DeviceId;
 import org.onosproject.openstacknode.api.NodeState;
 import org.onosproject.openstacknode.api.OpenstackNode;
+import org.onosproject.openstacknode.api.OpenstackPhyInterface;
 import org.onosproject.openstacknode.impl.DefaultOpenstackNode;
 import org.slf4j.Logger;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.IntStream;
+
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.onlab.util.Tools.nullIsIllegal;
 import static org.onosproject.openstacknode.api.Constants.DATA_IP;
@@ -45,6 +52,7 @@
     private static final String TYPE = "type";
     private static final String INTEGRATION_BRIDGE = "integrationBridge";
     private static final String STATE = "state";
+    private static final String PHYSICAL_INTERFACES = "phyIntfs";
 
     private static final String MISSING_MESSAGE = " is required in OpenstackNode";
 
@@ -76,6 +84,13 @@
         // TODO: need to find a way to not refer to ServiceDirectory from
         // DefaultOpenstackNode
 
+        ArrayNode phyIntfs = context.mapper().createArrayNode();
+        node.phyIntfs().forEach(phyIntf -> {
+            ObjectNode phyIntfJson = context.codec(OpenstackPhyInterface.class).encode(phyIntf, context);
+            phyIntfs.add(phyIntfJson);
+        });
+        result.set(PHYSICAL_INTERFACES, phyIntfs);
+
         return result;
     }
 
@@ -85,6 +100,8 @@
             return null;
         }
 
+        final JsonCodec<OpenstackPhyInterface> phyIntfCodec = context.codec(OpenstackPhyInterface.class);
+
         String hostname = nullIsIllegal(json.get(HOST_NAME).asText(),
                 HOST_NAME + MISSING_MESSAGE);
         String type = nullIsIllegal(json.get(TYPE).asText(),
@@ -112,6 +129,17 @@
             nodeBuilder.dataIp(IpAddress.valueOf(json.get(DATA_IP).asText()));
         }
 
+        // parse physical interfaces
+        List<OpenstackPhyInterface> phyIntfs = new ArrayList<>();
+        JsonNode phyIntfsJson = json.get(PHYSICAL_INTERFACES);
+        if (phyIntfsJson != null) {
+            IntStream.range(0, phyIntfsJson.size()).forEach(i -> {
+                ObjectNode intfJson = get(phyIntfsJson, i);
+                phyIntfs.add(phyIntfCodec.decode(intfJson, context));
+            });
+        }
+        nodeBuilder.phyIntfs(phyIntfs);
+
         log.trace("node is {}", nodeBuilder.build().toString());
 
         return nodeBuilder.build();
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackPhyInterfaceCodec.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackPhyInterfaceCodec.java
new file mode 100644
index 0000000..340a76d
--- /dev/null
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackPhyInterfaceCodec.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2018-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.openstacknode.codec;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.openstacknode.api.OpenstackPhyInterface;
+import org.onosproject.openstacknode.impl.DefaultOpenstackPhyInterface;
+import org.slf4j.Logger;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onlab.util.Tools.nullIsIllegal;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Openstack physical interface codec used for serializing and de-serializing JSON string.
+ */
+public final class OpenstackPhyInterfaceCodec extends JsonCodec<OpenstackPhyInterface> {
+
+    private final Logger log = getLogger(getClass());
+
+    private static final String NETWORK = "network";
+    private static final String INTERFACE = "intf";
+
+    private static final String MISSING_MESSAGE = " is required in OpenstackPhyInterface";
+
+    @Override
+    public ObjectNode encode(OpenstackPhyInterface phyIntf, CodecContext context) {
+        checkNotNull(phyIntf, "Openstack physical interface cannot be null");
+
+        return context.mapper().createObjectNode()
+                .put(NETWORK, phyIntf.network())
+                .put(INTERFACE, phyIntf.intf());
+    }
+
+    @Override
+    public OpenstackPhyInterface decode(ObjectNode json, CodecContext context) {
+        if (json == null || !json.isObject()) {
+            return null;
+        }
+
+        String network = nullIsIllegal(json.get(NETWORK).asText(),
+                NETWORK + MISSING_MESSAGE);
+        String intf = nullIsIllegal(json.get(INTERFACE).asText(),
+                INTERFACE + MISSING_MESSAGE);
+
+        return DefaultOpenstackPhyInterface.builder()
+                        .network(network)
+                        .intf(intf)
+                        .build();
+    }
+}
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNode.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNode.java
index 8927880..50f5d53 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNode.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNode.java
@@ -29,7 +29,10 @@
 import org.onosproject.net.group.GroupKey;
 import org.onosproject.openstacknode.api.NodeState;
 import org.onosproject.openstacknode.api.OpenstackNode;
+import org.onosproject.openstacknode.api.OpenstackPhyInterface;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Objects;
 
 import static com.google.common.base.Preconditions.checkArgument;
@@ -51,6 +54,7 @@
     private final String vlanIntf;
     private final String uplinkPort;
     private final NodeState state;
+    private final Collection<OpenstackPhyInterface> phyIntfs;
 
     private static final String NOT_NULL_MSG = "Node % cannot be null";
 
@@ -67,6 +71,7 @@
      * @param vlanIntf      VLAN interface
      * @param uplinkPort    uplink port name
      * @param state         node state
+     * @param phyIntfs      physical interfaces
      */
     protected DefaultOpenstackNode(String hostname, NodeType type,
                                    DeviceId intgBridge,
@@ -74,7 +79,8 @@
                                    IpAddress dataIp,
                                    String vlanIntf,
                                    String uplinkPort,
-                                   NodeState state) {
+                                   NodeState state,
+                                   Collection<OpenstackPhyInterface> phyIntfs) {
         this.hostname = hostname;
         this.type = type;
         this.intgBridge = intgBridge;
@@ -83,6 +89,7 @@
         this.vlanIntf = vlanIntf;
         this.uplinkPort = uplinkPort;
         this.state = state;
+        this.phyIntfs = phyIntfs;
     }
 
     @Override
@@ -220,7 +227,8 @@
                     Objects.equals(managementIp, that.managementIp) &&
                     Objects.equals(dataIp, that.dataIp) &&
                     Objects.equals(uplinkPort, that.uplinkPort) &&
-                    Objects.equals(vlanIntf, that.vlanIntf);
+                    Objects.equals(vlanIntf, that.vlanIntf) &&
+                    Objects.equals(phyIntfs, that.phyIntfs);
         }
         return false;
     }
@@ -233,7 +241,8 @@
                 managementIp,
                 dataIp,
                 vlanIntf,
-                uplinkPort);
+                uplinkPort,
+                phyIntfs);
     }
 
     @Override
@@ -247,6 +256,7 @@
                 .add("vlanIntf", vlanIntf)
                 .add("uplinkPort", uplinkPort)
                 .add("state", state)
+                .add("phyIntfs", phyIntfs)
                 .toString();
     }
 
@@ -261,9 +271,20 @@
                 .vlanIntf(vlanIntf)
                 .uplinkPort(uplinkPort)
                 .state(newState)
+                .phyIntfs(phyIntfs)
                 .build();
     }
 
+    @Override
+    public Collection<OpenstackPhyInterface> phyIntfs() {
+
+        if (phyIntfs == null) {
+            return new ArrayList<>();
+        }
+
+        return phyIntfs;
+    }
+
     /**
      * Returns new builder instance.
      *
@@ -288,7 +309,8 @@
                 .dataIp(osNode.dataIp())
                 .vlanIntf(osNode.vlanIntf())
                 .uplinkPort(osNode.uplinkPort())
-                .state(osNode.state());
+                .state(osNode.state())
+                .phyIntfs(osNode.phyIntfs());
     }
 
     /**
@@ -304,6 +326,7 @@
         private String vlanIntf;
         private String uplinkPort;
         private NodeState state;
+        private Collection<OpenstackPhyInterface> phyIntfs;
 
         // private constructor not intended to use from external
         private Builder() {
@@ -331,7 +354,8 @@
                     dataIp,
                     vlanIntf,
                     uplinkPort,
-                    state);
+                    state,
+                    phyIntfs);
         }
 
         @Override
@@ -383,6 +407,12 @@
             this.state = state;
             return this;
         }
+
+        @Override
+        public Builder phyIntfs(Collection<OpenstackPhyInterface> phyIntfs) {
+            this.phyIntfs = phyIntfs;
+            return this;
+        }
     }
 }
 
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandler.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandler.java
index 939b628..025757e 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandler.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandler.java
@@ -59,6 +59,7 @@
 import org.onosproject.openstacknode.api.OpenstackNodeHandler;
 import org.onosproject.openstacknode.api.OpenstackNodeListener;
 import org.onosproject.openstacknode.api.OpenstackNodeService;
+import org.onosproject.openstacknode.api.OpenstackPhyInterface;
 import org.onosproject.ovsdb.controller.OvsdbClientService;
 import org.onosproject.ovsdb.controller.OvsdbController;
 import org.onosproject.ovsdb.controller.OvsdbNodeId;
@@ -210,6 +211,13 @@
                     !isIntfEnabled(osNode, osNode.vlanIntf())) {
                 addSystemInterface(osNode, INTEGRATION_BRIDGE, osNode.vlanIntf());
             }
+
+            osNode.phyIntfs().forEach(i -> {
+                if (!isIntfEnabled(osNode, i.intf())) {
+                    addSystemInterface(osNode, INTEGRATION_BRIDGE, i.intf());
+                }
+            });
+
         } catch (Exception e) {
             log.error("Exception occurred because of {}", e.toString());
         }
@@ -384,6 +392,13 @@
                         !isIntfEnabled(osNode, osNode.uplinkPort())) {
                     return false;
                 }
+
+                for (OpenstackPhyInterface intf : osNode.phyIntfs()) {
+                    if (intf != null && !isIntfEnabled(osNode, intf.intf())) {
+                        return false;
+                    }
+                }
+
                 return true;
             case COMPLETE:
             case INCOMPLETE:
@@ -508,7 +523,8 @@
                         if (osNode.state() == DEVICE_CREATED && (
                                 Objects.equals(portName, DEFAULT_TUNNEL) ||
                                 Objects.equals(portName, osNode.vlanIntf()) ||
-                                Objects.equals(portName, osNode.uplinkPort()))) {
+                                Objects.equals(portName, osNode.uplinkPort()) ||
+                                        containsPhyIntf(osNode, portName))) {
                             log.debug("Interface {} added to {}", portName, event.subject().id());
                             bootstrapNode(osNode);
                         }
@@ -521,7 +537,8 @@
                         if (osNode.state() == COMPLETE && (
                                 Objects.equals(portName, DEFAULT_TUNNEL) ||
                                 Objects.equals(portName, osNode.vlanIntf()) ||
-                                        Objects.equals(portName, osNode.uplinkPort()))) {
+                                        Objects.equals(portName, osNode.uplinkPort()) ||
+                                        containsPhyIntf(osNode, portName))) {
                             log.warn("Interface {} removed from {}", portName, event.subject().id());
                             setState(osNode, INCOMPLETE);
                         }
@@ -537,6 +554,24 @@
     }
 
     /**
+     * Checks whether the openstack node contains the given physical interface.
+     *
+     * @param osNode openstack node
+     * @param portName physical interface
+     * @return true if openstack node contains the given physical interface,
+     *          false otherwise
+     */
+    private boolean containsPhyIntf(OpenstackNode osNode, String portName) {
+        for (OpenstackPhyInterface phyIntf : osNode.phyIntfs()) {
+            if (Objects.equals(portName, phyIntf.intf())) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    /**
      * An internal openstack node listener.
      * The notification is triggered by OpenstackNodeStore.
      */
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackPhyInterface.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackPhyInterface.java
new file mode 100644
index 0000000..f4238a3
--- /dev/null
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackPhyInterface.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2018-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.openstacknode.impl;
+
+import com.google.common.base.MoreObjects;
+import org.onosproject.openstacknode.api.OpenstackPhyInterface;
+
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+public class DefaultOpenstackPhyInterface implements OpenstackPhyInterface {
+
+    private final String network;
+    private final String intf;
+
+    private static final String NOT_NULL_MSG = "% cannot be null";
+
+    /**
+     * A default constructor of Openstack physical interface.
+     *
+     * @param network   network that this physical interface connects with
+     * @param intf      name of physical interface
+     */
+    protected DefaultOpenstackPhyInterface(String network, String intf) {
+        this.network = network;
+        this.intf = intf;
+    }
+
+    @Override
+    public String network() {
+        return network;
+    }
+
+    @Override
+    public String intf() {
+        return intf;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+
+        if (obj instanceof DefaultOpenstackPhyInterface) {
+            DefaultOpenstackPhyInterface that = (DefaultOpenstackPhyInterface) obj;
+            return Objects.equals(network, that.network) &&
+                    Objects.equals(intf, that.intf);
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(network, intf);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(getClass())
+                .add("network", network)
+                .add("intf", intf)
+                .toString();
+    }
+
+    /**
+     * Returns new builder instance.
+     *
+     * @return openstack physical interface builder
+     */
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    /**
+     * A builder class for openstack physical interface.
+     */
+    public static final class Builder implements OpenstackPhyInterface.Builder {
+
+        private String network;
+        private String intf;
+
+        // private constructor not intended to use from external
+        private Builder() {
+        }
+
+        @Override
+        public OpenstackPhyInterface build() {
+            checkArgument(network != null, NOT_NULL_MSG, "network");
+            checkArgument(intf != null, NOT_NULL_MSG, "intf");
+
+            return new DefaultOpenstackPhyInterface(network, intf);
+        }
+
+        @Override
+        public OpenstackPhyInterface.Builder network(String network) {
+            this.network = network;
+            return this;
+        }
+
+        @Override
+        public OpenstackPhyInterface.Builder intf(String intf) {
+            this.intf = intf;
+            return this;
+        }
+    }
+}
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DistributedOpenstackNodeStore.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DistributedOpenstackNodeStore.java
index 0b67d73..d3c2ce4 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DistributedOpenstackNodeStore.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DistributedOpenstackNodeStore.java
@@ -30,6 +30,7 @@
 import org.onosproject.openstacknode.api.OpenstackNodeEvent;
 import org.onosproject.openstacknode.api.OpenstackNodeStore;
 import org.onosproject.openstacknode.api.OpenstackNodeStoreDelegate;
+import org.onosproject.openstacknode.api.OpenstackPhyInterface;
 import org.onosproject.store.AbstractStore;
 import org.onosproject.store.serializers.KryoNamespaces;
 import org.onosproject.store.service.ConsistentMap;
@@ -40,6 +41,7 @@
 import org.onosproject.store.service.Versioned;
 import org.slf4j.Logger;
 
+import java.util.Collection;
 import java.util.Set;
 import java.util.concurrent.ExecutorService;
 
@@ -75,6 +77,9 @@
             .register(DefaultOpenstackNode.class)
             .register(OpenstackNode.NodeType.class)
             .register(NodeState.class)
+            .register(OpenstackPhyInterface.class)
+            .register(DefaultOpenstackPhyInterface.class)
+            .register(Collection.class)
             .build();
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/web/OpenstackNodeCodecRegister.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/web/OpenstackNodeCodecRegister.java
index 70df974..420e87a 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/web/OpenstackNodeCodecRegister.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/web/OpenstackNodeCodecRegister.java
@@ -22,7 +22,9 @@
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.onosproject.codec.CodecService;
 import org.onosproject.openstacknode.api.OpenstackNode;
+import org.onosproject.openstacknode.api.OpenstackPhyInterface;
 import org.onosproject.openstacknode.codec.OpenstackNodeCodec;
+import org.onosproject.openstacknode.codec.OpenstackPhyInterfaceCodec;
 
 import static org.slf4j.LoggerFactory.getLogger;
 
@@ -40,6 +42,7 @@
     @Activate
     protected void activate() {
         codecService.registerCodec(OpenstackNode.class, new OpenstackNodeCodec());
+        codecService.registerCodec(OpenstackPhyInterface.class, new OpenstackPhyInterfaceCodec());
 
         log.info("Started");
     }
@@ -47,6 +50,7 @@
     @Deactivate
     protected void deactivate() {
         codecService.unregisterCodec(OpenstackNode.class);
+        codecService.unregisterCodec(OpenstackPhyInterface.class);
 
         log.info("Stopped");
     }
diff --git a/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackNodeCodecTest.java b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackNodeCodecTest.java
index e009209..cea17c4 100644
--- a/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackNodeCodecTest.java
+++ b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackNodeCodecTest.java
@@ -18,6 +18,7 @@
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.ImmutableList;
 import org.hamcrest.MatcherAssert;
 import org.junit.Before;
 import org.junit.Test;
@@ -29,7 +30,9 @@
 import org.onosproject.net.DeviceId;
 import org.onosproject.openstacknode.api.NodeState;
 import org.onosproject.openstacknode.api.OpenstackNode;
+import org.onosproject.openstacknode.api.OpenstackPhyInterface;
 import org.onosproject.openstacknode.impl.DefaultOpenstackNode;
+import org.onosproject.openstacknode.impl.DefaultOpenstackPhyInterface;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -51,6 +54,7 @@
 public class OpenstackNodeCodecTest {
     MockCodecContext context;
     JsonCodec<OpenstackNode> openstackNodeCodec;
+    JsonCodec<OpenstackPhyInterface> openstackPhyIntfJsonCodec;
     final CoreService mockCoreService = createMock(CoreService.class);
     private static final String REST_APP_ID = "org.onosproject.rest";
 
@@ -58,7 +62,10 @@
     public void setUp() {
         context = new MockCodecContext();
         openstackNodeCodec = new OpenstackNodeCodec();
+        openstackPhyIntfJsonCodec = new OpenstackPhyInterfaceCodec();
+
         assertThat(openstackNodeCodec, notNullValue());
+        assertThat(openstackPhyIntfJsonCodec, notNullValue());
 
         expect(mockCoreService.registerApplication(REST_APP_ID))
                 .andReturn(APP_ID).anyTimes();
@@ -68,6 +75,16 @@
 
     @Test
     public void testOpenstackNodeEncode() {
+
+        OpenstackPhyInterface phyIntf1 = DefaultOpenstackPhyInterface.builder()
+                                .network("mgmtnetwork")
+                                .intf("eth3")
+                                .build();
+        OpenstackPhyInterface phyIntf2 = DefaultOpenstackPhyInterface.builder()
+                                .network("oamnetwork")
+                                .intf("eth4")
+                                .build();
+
         OpenstackNode node = DefaultOpenstackNode.builder()
                                 .hostname("compute")
                                 .type(OpenstackNode.NodeType.COMPUTE)
@@ -76,6 +93,7 @@
                                 .intgBridge(DeviceId.deviceId("br-int"))
                                 .vlanIntf("vxlan")
                                 .dataIp(IpAddress.valueOf("20.20.20.2"))
+                                .phyIntfs(ImmutableList.of(phyIntf1, phyIntf2))
                                 .build();
 
         ObjectNode nodeJson = openstackNodeCodec.encode(node, context);
@@ -92,6 +110,16 @@
         assertThat(node.dataIp().toString(), is("172.16.130.4"));
         assertThat(node.intgBridge().toString(), is("of:00000000000000a1"));
         assertThat(node.vlanIntf(), is("eth2"));
+        assertThat(node.phyIntfs().size(), is(2));
+
+        node.phyIntfs().forEach(intf -> {
+            if (intf.network().equals("mgmtnetwork")) {
+                assertThat(intf.intf(), is("eth3"));
+            }
+            if (intf.network().equals("oamnetwork")) {
+                assertThat(intf.intf(), is("eth4"));
+            }
+        });
     }
 
     /**
@@ -133,6 +161,9 @@
         @Override
         @SuppressWarnings("unchecked")
         public <T> JsonCodec<T> codec(Class<T> entityClass) {
+            if (entityClass == OpenstackPhyInterface.class) {
+                return (JsonCodec<T>) openstackPhyIntfJsonCodec;
+            }
             return manager.getCodec(entityClass);
         }
 
diff --git a/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackNodeJsonMatcher.java b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackNodeJsonMatcher.java
index 74382b1..b9c4464 100644
--- a/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackNodeJsonMatcher.java
+++ b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackNodeJsonMatcher.java
@@ -20,6 +20,7 @@
 import org.hamcrest.TypeSafeDiagnosingMatcher;
 import org.onosproject.openstacknode.api.Constants;
 import org.onosproject.openstacknode.api.OpenstackNode;
+import org.onosproject.openstacknode.api.OpenstackPhyInterface;
 
 import static org.onosproject.openstacknode.api.Constants.DATA_IP;
 import static org.onosproject.openstacknode.api.Constants.MANAGEMENT_IP;
@@ -33,6 +34,7 @@
     private final OpenstackNode node;
     private static final String INTEGRATION_BRIDGE = "integrationBridge";
     private static final String STATE = "state";
+    private static final String PHYSICAL_INTERFACES = "phyIntfs";
 
     private OpenstackNodeJsonMatcher(OpenstackNode node) {
         this.node = node;
@@ -100,6 +102,32 @@
             }
         }
 
+        // check physical interfaces
+        JsonNode jsonPhyIntfs = jsonNode.get(PHYSICAL_INTERFACES);
+        if (jsonPhyIntfs != null) {
+            if (jsonPhyIntfs.size() != node.phyIntfs().size()) {
+                description.appendText("physical interface size was " + jsonPhyIntfs.size());
+                return false;
+            }
+
+            for (OpenstackPhyInterface phyIntf : node.phyIntfs()) {
+                boolean intfFound = false;
+                for (int intfIndex = 0; intfIndex < jsonPhyIntfs.size(); intfIndex++) {
+                    OpenstackPhyInterfaceJsonMatcher intfMatcher =
+                            OpenstackPhyInterfaceJsonMatcher.matchesOpenstackPhyInterface(phyIntf);
+                    if (intfMatcher.matches(jsonPhyIntfs.get(intfIndex))) {
+                        intfFound = true;
+                        break;
+                    }
+                }
+
+                if (!intfFound) {
+                    description.appendText("PhyIntf not found " + phyIntf.toString());
+                    return false;
+                }
+            }
+        }
+
         return true;
     }
 
diff --git a/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackPhyInterfaceJsonMatcher.java b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackPhyInterfaceJsonMatcher.java
new file mode 100644
index 0000000..09955bd
--- /dev/null
+++ b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackPhyInterfaceJsonMatcher.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2018-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.openstacknode.codec;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.onosproject.openstacknode.api.OpenstackPhyInterface;
+
+public final class OpenstackPhyInterfaceJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode> {
+
+    private final OpenstackPhyInterface phyIntf;
+    private static final String NETWORK = "network";
+    private static final String INTERFACE = "intf";
+
+    private OpenstackPhyInterfaceJsonMatcher(OpenstackPhyInterface phyIntf) {
+        this.phyIntf = phyIntf;
+    }
+
+    @Override
+    protected boolean matchesSafely(JsonNode jsonNode, Description description) {
+
+        // check network name
+        String jsonNetwork = jsonNode.get(NETWORK).asText();
+        String network = phyIntf.network();
+        if (!jsonNetwork.equals(network)) {
+            description.appendText("network name was " + jsonNetwork);
+            return false;
+        }
+
+        // check interface name
+        String jsonIntf = jsonNode.get(INTERFACE).asText();
+        String intf = phyIntf.intf();
+        if (!jsonIntf.equals(intf)) {
+            description.appendText("interface name was " + jsonIntf);
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public void describeTo(Description description) {
+        description.appendText(phyIntf.toString());
+    }
+
+    /**
+     * Factory to allocate an openstack physical interface matcher.
+     *
+     * @param phyIntf openstack physical interface object we are looking for
+     * @return matcher
+     */
+    public static OpenstackPhyInterfaceJsonMatcher
+                    matchesOpenstackPhyInterface(OpenstackPhyInterface phyIntf) {
+        return new OpenstackPhyInterfaceJsonMatcher(phyIntf);
+    }
+}
diff --git a/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandlerTest.java b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandlerTest.java
index 9c55df3..fccfd1b 100644
--- a/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandlerTest.java
+++ b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandlerTest.java
@@ -18,6 +18,7 @@
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
 import com.google.common.util.concurrent.MoreExecutors;
 import org.junit.After;
 import org.junit.Before;
@@ -69,6 +70,7 @@
 import org.onosproject.net.provider.ProviderId;
 import org.onosproject.openstacknode.api.NodeState;
 import org.onosproject.openstacknode.api.OpenstackNode;
+import org.onosproject.openstacknode.api.OpenstackPhyInterface;
 import org.onosproject.ovsdb.controller.OvsdbClientService;
 import org.onosproject.ovsdb.controller.OvsdbController;
 
@@ -144,6 +146,10 @@
 
     private static final String GATEWAY_UPLINK_PORT = "eth0";
 
+    private static final Set<OpenstackPhyInterface> COMPUTE_1_PHY_INTFS = createPhyIntfs();
+    private static final Set<OpenstackPhyInterface> COMPUTE_2_PHY_INTFS = createPhyIntfs();
+    private static final Set<OpenstackPhyInterface> COMPUTE_3_PHY_INTFS = createPhyIntfs();
+
     private static final Device COMPUTE_1_INTG_DEVICE = createOpenFlowDevice(1, INTEGRATION_BRIDGE);
     private static final Device COMPUTE_2_INTG_DEVICE = createOpenFlowDevice(2, INTEGRATION_BRIDGE);
     private static final Device COMPUTE_3_INTG_DEVICE = createOpenFlowDevice(3, INTEGRATION_BRIDGE);
@@ -161,7 +167,8 @@
             COMPUTE,
             COMPUTE_1_INTG_DEVICE,
             COMPUTE_1_IP,
-            INIT
+            INIT,
+            COMPUTE_1_PHY_INTFS
     );
 
     private static final OpenstackNode COMPUTE_2 = createNode(
@@ -169,7 +176,8 @@
             COMPUTE,
             COMPUTE_2_INTG_DEVICE,
             COMPUTE_2_IP,
-            DEVICE_CREATED
+            DEVICE_CREATED,
+            COMPUTE_2_PHY_INTFS
     );
 
     private static final OpenstackNode COMPUTE_3 = createNode(
@@ -177,10 +185,11 @@
             COMPUTE,
             COMPUTE_3_INTG_DEVICE,
             COMPUTE_3_IP,
-            COMPLETE
+            COMPLETE,
+            COMPUTE_3_PHY_INTFS
     );
 
-    private static final OpenstackNode GATEWAY_1 = createNode(
+    private static final OpenstackNode GATEWAY_1 = createGatewayNode(
             GATEWAY_1_HOSTNAME,
             GATEWAY,
             GATEWAY_1_INTG_DEVICE,
@@ -189,7 +198,7 @@
             INIT
     );
 
-    private static final OpenstackNode GATEWAY_2 = createNode(
+    private static final OpenstackNode GATEWAY_2 = createGatewayNode(
             GATEWAY_2_HOSTNAME,
             GATEWAY,
             GATEWAY_2_INTG_DEVICE,
@@ -198,7 +207,7 @@
             DEVICE_CREATED
     );
 
-    private static final OpenstackNode GATEWAY_3 = createNode(
+    private static final OpenstackNode GATEWAY_3 = createGatewayNode(
             GATEWAY_3_HOSTNAME,
             GATEWAY,
             GATEWAY_3_INTG_DEVICE,
@@ -382,21 +391,26 @@
                 DefaultAnnotations.builder().set(PORT_NAME, portName).build());
     }
 
+    private static Set<OpenstackPhyInterface> createPhyIntfs() {
+        return Sets.newConcurrentHashSet();
+    }
+
     private static OpenstackNode createNode(String hostname,
                                             OpenstackNode.NodeType type,
                                             Device intgBridge,
                                             IpAddress ipAddr,
-                                            NodeState state) {
+                                            NodeState state,
+                                            Set<OpenstackPhyInterface> phyIntfs) {
         return new TestOpenstackNode(
                 hostname,
                 type,
                 intgBridge.id(),
                 ipAddr,
                 ipAddr,
-                null, null, state);
+                null, null, state, phyIntfs);
     }
 
-    private static OpenstackNode createNode(String hostname,
+    private static OpenstackNode createGatewayNode(String hostname,
                                             OpenstackNode.NodeType type,
                                             Device intgBridge,
                                             IpAddress ipAddr,
@@ -408,7 +422,7 @@
                 intgBridge.id(),
                 ipAddr,
                 ipAddr,
-                null, uplinkPort, state);
+                null, uplinkPort, state, null);
     }
 
     private static final class TestDevice extends DefaultDevice {
@@ -465,7 +479,8 @@
                                   IpAddress dataIp,
                                   String vlanIntf,
                                   String uplinkPort,
-                                  NodeState state) {
+                                  NodeState state,
+                                  Set<OpenstackPhyInterface> phyIntfs) {
             super(hostname,
                     type,
                     intgBridge,
@@ -473,7 +488,8 @@
                     dataIp,
                     vlanIntf,
                     uplinkPort,
-                    state);
+                    state,
+                    phyIntfs);
         }
 
         @Override
diff --git a/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/impl/DefaultOpenstackPhyInterfaceTest.java b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/impl/DefaultOpenstackPhyInterfaceTest.java
new file mode 100644
index 0000000..55a7077
--- /dev/null
+++ b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/impl/DefaultOpenstackPhyInterfaceTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2018-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.openstacknode.impl;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Test;
+import org.onosproject.openstacknode.api.OpenstackPhyInterface;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+/**
+ * Unit tests for DefaultOpenstackPhyInterface.
+ */
+public class DefaultOpenstackPhyInterfaceTest {
+
+    private static final String NETWORK_1 = "mgmtnetwork";
+    private static final String NETWORK_2 = "oamnetwork";
+    private static final String INTERFACE_1 = "eth3";
+    private static final String INTERFACE_2 = "eth4";
+
+    private static final OpenstackPhyInterface OS_PHY_INTF_1 =
+            new DefaultOpenstackPhyInterface(NETWORK_1, INTERFACE_1);
+    private static final OpenstackPhyInterface OS_PHY_INTF_2 =
+            new DefaultOpenstackPhyInterface(NETWORK_1, INTERFACE_1);
+    private static final OpenstackPhyInterface OS_PHY_INTF_3 =
+            new DefaultOpenstackPhyInterface(NETWORK_2, INTERFACE_2);
+
+    @Test
+    public void testEquality() {
+        new EqualsTester().addEqualityGroup(OS_PHY_INTF_1, OS_PHY_INTF_2)
+                .addEqualityGroup(OS_PHY_INTF_3)
+                .testEquals();
+    }
+
+    @Test
+    public void testConstruction() {
+        DefaultOpenstackPhyInterface phyIntf = (DefaultOpenstackPhyInterface)
+                OS_PHY_INTF_1;
+
+        assertThat(phyIntf.network(), is(NETWORK_1));
+        assertThat(phyIntf.intf(), is(INTERFACE_1));
+    }
+}
\ No newline at end of file
diff --git a/apps/openstacknode/app/src/test/resources/org/onosproject/openstacknode/codec/OpenstackNode.json b/apps/openstacknode/app/src/test/resources/org/onosproject/openstacknode/codec/OpenstackNode.json
index dfa07e3..ff561c6 100644
--- a/apps/openstacknode/app/src/test/resources/org/onosproject/openstacknode/codec/OpenstackNode.json
+++ b/apps/openstacknode/app/src/test/resources/org/onosproject/openstacknode/codec/OpenstackNode.json
@@ -1,8 +1,18 @@
 {
-  "hostname" : "compute-01",
-  "type" : "COMPUTE",
-  "managementIp" : "172.16.130.4",
-  "dataIp" : "172.16.130.4",
-  "vlanPort" : "eth2",
-  "integrationBridge" : "of:00000000000000a1"
+  "hostname": "compute-01",
+  "type": "COMPUTE",
+  "managementIp": "172.16.130.4",
+  "dataIp": "172.16.130.4",
+  "vlanPort": "eth2",
+  "integrationBridge": "of:00000000000000a1",
+  "phyIntfs": [
+    {
+      "network": "mgmtnetwork",
+      "intf": "eth3"
+    },
+    {
+      "network": "oamnetwork",
+      "intf": "eth4"
+    }
+  ]
 }
\ No newline at end of file
diff --git a/apps/openstacknode/network-cfg.json b/apps/openstacknode/network-cfg.json
index a9918d9..f22216e 100644
--- a/apps/openstacknode/network-cfg.json
+++ b/apps/openstacknode/network-cfg.json
@@ -9,7 +9,17 @@
                                 "managementIp" : "172.16.130.4",
                                 "dataIp" : "172.16.130.4",
                                 "vlanPort" : "eth2",
-                                "integrationBridge" : "of:00000000000000a1"
+                                "integrationBridge" : "of:00000000000000a1",
+                                "phyIntfs": [
+                                      {
+                                          "network": "mgmtnetwork",
+                                          "intf": "eth3"
+                                      },
+                                      {
+                                          "network": "oamnetwork",
+                                          "intf": "eth4"
+                                      }
+                                ]
                         },
                         {
                                 "hostname" : "compute-02",
@@ -17,7 +27,17 @@
                                 "managementIp" : "172.16.130.6",
                                 "dataIp" : "172.16.130.6",
                                 "vlanPort" : "eth2",
-                                "integrationBridge" : "of:00000000000000a2"
+                                "integrationBridge" : "of:00000000000000a2",
+                                "phyIntfs": [
+                                      {
+                                        "network": "mgmtnetwork",
+                                        "intf": "eth3"
+                                      },
+                                      {
+                                        "network": "oamnetwork",
+                                        "intf": "eth4"
+                                      }
+                                ]
                         },
                         {
                                 "hostname" : "gateway-01",