Add keystone and neutron config classes and codec with unit tests

Change-Id: Ia89f5be9bac88927a383d56d56413ba23e3e5eb3
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/KeystoneConfigCodec.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/KeystoneConfigCodec.java
new file mode 100644
index 0000000..95da63a
--- /dev/null
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/KeystoneConfigCodec.java
@@ -0,0 +1,73 @@
+/*
+ * 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 com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.openstacknode.api.KeystoneConfig;
+import org.onosproject.openstacknode.api.OpenstackAuth;
+import org.onosproject.openstacknode.api.DefaultKeystoneConfig;
+
+import static org.onlab.util.Tools.nullIsIllegal;
+
+/**
+ * Keystone config codec used for serializing and de-serializing JSON string.
+ */
+public final class KeystoneConfigCodec extends JsonCodec<KeystoneConfig> {
+
+    private static final String ENDPOINT = "endpoint";
+    private static final String AUTHENTICATION = "authentication";
+
+    private static final String MISSING_MESSAGE = " is required in OpenstackNode";
+
+    @Override
+    public ObjectNode encode(KeystoneConfig entity, CodecContext context) {
+        ObjectNode result = context.mapper().createObjectNode()
+                .put(ENDPOINT, entity.endpoint());
+
+        ObjectNode authJson = context.codec(OpenstackAuth.class)
+                .encode(entity.authentication(), context);
+        result.set(AUTHENTICATION, authJson);
+
+        return result;
+    }
+
+    @Override
+    public KeystoneConfig decode(ObjectNode json, CodecContext context) {
+        if (json == null || !json.isObject()) {
+            return null;
+        }
+
+        String endpoint = nullIsIllegal(json.get(ENDPOINT).asText(),
+                ENDPOINT + MISSING_MESSAGE);
+
+        // parse authentication
+        JsonNode authJson = nullIsIllegal(json.get(AUTHENTICATION),
+                AUTHENTICATION + MISSING_MESSAGE);
+
+
+        final JsonCodec<OpenstackAuth> authCodec = context.codec(OpenstackAuth.class);
+        OpenstackAuth auth = authCodec.decode((ObjectNode) authJson.deepCopy(), context);
+
+        return DefaultKeystoneConfig.builder()
+                .endpoint(endpoint)
+                .authentication(auth)
+                .build();
+    }
+}
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/NeutronConfigCodec.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/NeutronConfigCodec.java
new file mode 100644
index 0000000..5acf180
--- /dev/null
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/NeutronConfigCodec.java
@@ -0,0 +1,61 @@
+/*
+ * 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.NeutronConfig;
+import org.onosproject.openstacknode.api.DefaultNeutronConfig;
+
+import static org.onlab.util.Tools.nullIsIllegal;
+
+/**
+ * Neutron config codec used for serializing and de-serializing JSON string.
+ */
+public final class NeutronConfigCodec extends JsonCodec<NeutronConfig> {
+
+    private static final String USE_METADATA_PROXY = "useMetadataProxy";
+    private static final String METADATA_PROXY_SECRET = "metadataProxySecret";
+
+    private static final String MISSING_MESSAGE = " is required in OpenstackNode";
+
+    @Override
+    public ObjectNode encode(NeutronConfig entity, CodecContext context) {
+        return context.mapper().createObjectNode()
+                .put(USE_METADATA_PROXY, entity.useMetadataProxy())
+                .put(METADATA_PROXY_SECRET, entity.metadataProxySecret());
+    }
+
+    @Override
+    public NeutronConfig decode(ObjectNode json, CodecContext context) {
+        if (json == null || !json.isObject()) {
+            return null;
+        }
+
+        boolean useMetadataProxy = nullIsIllegal(json.get(USE_METADATA_PROXY).asBoolean(),
+                USE_METADATA_PROXY + MISSING_MESSAGE);
+
+        String metadataProxySecret = nullIsIllegal(json.get(METADATA_PROXY_SECRET).asText(),
+                METADATA_PROXY_SECRET + MISSING_MESSAGE);
+
+        return DefaultNeutronConfig.builder()
+                .useMetadataProxy(useMetadataProxy)
+                .metadataProxySecret(metadataProxySecret)
+                .build();
+    }
+}
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 ad2f08b..d32a071 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
@@ -25,11 +25,14 @@
 import org.onosproject.net.behaviour.ControllerInfo;
 import org.onosproject.openstacknode.api.DefaultOpenstackNode;
 import org.onosproject.openstacknode.api.DpdkConfig;
+import org.onosproject.openstacknode.api.KeystoneConfig;
+import org.onosproject.openstacknode.api.NeutronConfig;
 import org.onosproject.openstacknode.api.NodeState;
 import org.onosproject.openstacknode.api.OpenstackAuth;
 import org.onosproject.openstacknode.api.OpenstackNode;
 import org.onosproject.openstacknode.api.OpenstackPhyInterface;
 import org.onosproject.openstacknode.api.OpenstackSshAuth;
+import org.onosproject.openstacknode.api.DefaultKeystoneConfig;
 import org.slf4j.Logger;
 
 import java.util.ArrayList;
@@ -59,8 +62,10 @@
     private static final String STATE = "state";
     private static final String PHYSICAL_INTERFACES = "phyIntfs";
     private static final String CONTROLLERS = "controllers";
+    private static final String KEYSTONE_CONFIG = "keystoneConfig";
+    private static final String ENDPOINT = "endpoint";
     private static final String AUTHENTICATION = "authentication";
-    private static final String END_POINT = "endpoint";
+    private static final String NEUTRON_CONFIG = "neutronConfig";
     private static final String SSH_AUTH = "sshAuth";
     private static final String DPDK_CONFIG = "dpdkConfig";
 
@@ -83,7 +88,18 @@
         }
 
         if (type == OpenstackNode.NodeType.CONTROLLER) {
-            result.put(END_POINT, node.endpoint());
+
+            ObjectNode keystoneConfigJson = context.codec(KeystoneConfig.class)
+                    .encode(node.keystoneConfig(), context);
+
+            result.set(KEYSTONE_CONFIG, keystoneConfigJson);
+        }
+
+        if (node.neutronConfig() != null) {
+            ObjectNode neutronConfigJson = context.codec(NeutronConfig.class)
+                    .encode(node.neutronConfig(), context);
+
+            result.set(NEUTRON_CONFIG, neutronConfigJson);
         }
 
         if (node.intgBridge() != null) {
@@ -98,28 +114,21 @@
             result.put(DATA_IP, node.dataIp().toString());
         }
 
-        // 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);
+            ObjectNode phyIntfJson =
+                    context.codec(OpenstackPhyInterface.class).encode(phyIntf, context);
             phyIntfs.add(phyIntfJson);
         });
         result.set(PHYSICAL_INTERFACES, phyIntfs);
 
         ArrayNode controllers = context.mapper().createArrayNode();
         node.controllers().forEach(controller -> {
-            ObjectNode controllerJson = context.codec(ControllerInfo.class).encode(controller, context);
+            ObjectNode controllerJson =
+                    context.codec(ControllerInfo.class).encode(controller, context);
             controllers.add(controllerJson);
         });
 
-        if (node.authentication() != null) {
-            ObjectNode authJson = context.codec(OpenstackAuth.class)
-                    .encode(node.authentication(), context);
-            result.set(AUTHENTICATION, authJson);
-        }
-
         if (node.sshAuthInfo() != null) {
             ObjectNode sshAuthJson = context.codec(OpenstackSshAuth.class)
                     .encode(node.sshAuthInfo(), context);
@@ -159,9 +168,30 @@
                     UPLINK_PORT + MISSING_MESSAGE));
         }
         if (type.equals(CONTROLLER)) {
-            String endPoint = nullIsIllegal(json.get(END_POINT).asText(),
-                    END_POINT + MISSING_MESSAGE);
-            nodeBuilder.endpoint(endPoint);
+
+            JsonNode keystoneConfigJson = json.get(KEYSTONE_CONFIG);
+
+            KeystoneConfig keystoneConfig;
+            if (keystoneConfigJson != null) {
+                final JsonCodec<KeystoneConfig> keystoneConfigCodec =
+                                        context.codec(KeystoneConfig.class);
+                keystoneConfig = keystoneConfigCodec.decode((ObjectNode)
+                                        keystoneConfigJson.deepCopy(), context);
+            } else {
+                JsonNode authJson = json.get(AUTHENTICATION);
+                final JsonCodec<OpenstackAuth> authCodec = context.codec(OpenstackAuth.class);
+                OpenstackAuth auth = authCodec.decode((ObjectNode) authJson.deepCopy(), context);
+
+                String endpoint = nullIsIllegal(json.get(ENDPOINT).asText(),
+                        ENDPOINT + MISSING_MESSAGE);
+
+                keystoneConfig = DefaultKeystoneConfig.builder()
+                        .authentication(auth)
+                        .endpoint(endpoint)
+                        .build();
+            }
+
+            nodeBuilder.keystoneConfig(keystoneConfig);
         }
         if (json.get(VLAN_INTF_NAME) != null) {
             nodeBuilder.vlanIntf(json.get(VLAN_INTF_NAME).asText());
@@ -205,30 +235,36 @@
         }
         nodeBuilder.controllers(controllers);
 
-        // parse authentication
-        JsonNode authJson = json.get(AUTHENTICATION);
-        if (authJson != null) {
+        // parse neutron config
+        JsonNode neutronConfigJson = json.get(NEUTRON_CONFIG);
+        if (neutronConfigJson != null) {
+            final JsonCodec<NeutronConfig> neutronConfigJsonCodec =
+                                context.codec(NeutronConfig.class);
 
-            final JsonCodec<OpenstackAuth> authCodec = context.codec(OpenstackAuth.class);
-
-            OpenstackAuth auth = authCodec.decode((ObjectNode) authJson.deepCopy(), context);
-            nodeBuilder.authentication(auth);
+            NeutronConfig neutronConfig =
+                    neutronConfigJsonCodec.decode((ObjectNode)
+                            neutronConfigJson.deepCopy(), context);
+            nodeBuilder.neutronConfig(neutronConfig);
         }
 
         // parse ssh authentication
         JsonNode sshAuthJson = json.get(SSH_AUTH);
         if (sshAuthJson != null) {
-            final JsonCodec<OpenstackSshAuth> sshAuthJsonCodec = context.codec(OpenstackSshAuth.class);
+            final JsonCodec<OpenstackSshAuth> sshAuthJsonCodec =
+                                context.codec(OpenstackSshAuth.class);
 
-            OpenstackSshAuth sshAuth = sshAuthJsonCodec.decode((ObjectNode) sshAuthJson.deepCopy(), context);
+            OpenstackSshAuth sshAuth = sshAuthJsonCodec.decode((ObjectNode)
+                            sshAuthJson.deepCopy(), context);
             nodeBuilder.sshAuthInfo(sshAuth);
         }
 
         JsonNode dpdkConfigJson = json.get(DPDK_CONFIG);
         if (dpdkConfigJson != null) {
-            final JsonCodec<DpdkConfig> dpdkConfigJsonCodec = context.codec(DpdkConfig.class);
+            final JsonCodec<DpdkConfig> dpdkConfigJsonCodec =
+                                context.codec(DpdkConfig.class);
 
-            DpdkConfig dpdkConfig = dpdkConfigJsonCodec.decode((ObjectNode) dpdkConfigJson.deepCopy(), context);
+            DpdkConfig dpdkConfig = dpdkConfigJsonCodec.decode((ObjectNode)
+                                dpdkConfigJson.deepCopy(), context);
             nodeBuilder.dpdkConfig(dpdkConfig);
         }
 
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/util/OpenstackNodeUtil.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/util/OpenstackNodeUtil.java
index 720cfd6..311eba4 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/util/OpenstackNodeUtil.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/util/OpenstackNodeUtil.java
@@ -55,7 +55,6 @@
     private static final String DOMAIN_DEFAULT = "default";
     private static final String KEYSTONE_V2 = "v2.0";
     private static final String KEYSTONE_V3 = "v3";
-    private static final String IDENTITY_PATH = "identity/";
     private static final String SSL_TYPE = "SSL";
 
     private static final int HEX_LENGTH = 16;
@@ -110,7 +109,7 @@
      * @return a connected openstack client
      */
     public static OSClient getConnectedClient(OpenstackNode osNode) {
-        OpenstackAuth auth = osNode.authentication();
+        OpenstackAuth auth = osNode.keystoneConfig().authentication();
         String endpoint = buildEndpoint(osNode);
         Perspective perspective = auth.perspective();
 
@@ -221,12 +220,12 @@
      */
     private static String buildEndpoint(OpenstackNode node) {
 
-        OpenstackAuth auth = node.authentication();
+        OpenstackAuth auth = node.keystoneConfig().authentication();
 
         StringBuilder endpointSb = new StringBuilder();
         endpointSb.append(auth.protocol().name().toLowerCase());
         endpointSb.append("://");
-        endpointSb.append(node.endpoint());
+        endpointSb.append(node.keystoneConfig().endpoint());
         return endpointSb.toString();
     }
 
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 4361317..bb92eb3 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
@@ -24,12 +24,16 @@
 import org.onosproject.net.behaviour.ControllerInfo;
 import org.onosproject.openstacknode.api.DpdkConfig;
 import org.onosproject.openstacknode.api.DpdkInterface;
+import org.onosproject.openstacknode.api.KeystoneConfig;
+import org.onosproject.openstacknode.api.NeutronConfig;
 import org.onosproject.openstacknode.api.OpenstackAuth;
 import org.onosproject.openstacknode.api.OpenstackNode;
 import org.onosproject.openstacknode.api.OpenstackPhyInterface;
 import org.onosproject.openstacknode.api.OpenstackSshAuth;
 import org.onosproject.openstacknode.codec.DpdkConfigCodec;
 import org.onosproject.openstacknode.codec.DpdkInterfaceCodec;
+import org.onosproject.openstacknode.codec.KeystoneConfigCodec;
+import org.onosproject.openstacknode.codec.NeutronConfigCodec;
 import org.onosproject.openstacknode.codec.OpenstackAuthCodec;
 import org.onosproject.openstacknode.codec.OpenstackControllerCodec;
 import org.onosproject.openstacknode.codec.OpenstackNodeCodec;
@@ -58,6 +62,8 @@
         codecService.registerCodec(OpenstackSshAuth.class, new OpenstackSshAuthCodec());
         codecService.registerCodec(DpdkInterface.class, new DpdkInterfaceCodec());
         codecService.registerCodec(DpdkConfig.class, new DpdkConfigCodec());
+        codecService.registerCodec(KeystoneConfig.class, new KeystoneConfigCodec());
+        codecService.registerCodec(NeutronConfig.class, new NeutronConfigCodec());
 
         log.info("Started");
     }
@@ -71,6 +77,8 @@
         codecService.unregisterCodec(OpenstackSshAuth.class);
         codecService.unregisterCodec(DpdkConfig.class);
         codecService.unregisterCodec(DpdkInterface.class);
+        codecService.unregisterCodec(KeystoneConfig.class);
+        codecService.unregisterCodec(NeutronConfig.class);
 
         log.info("Stopped");
     }
diff --git a/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/KeystoneConfigJsonMatcher.java b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/KeystoneConfigJsonMatcher.java
new file mode 100644
index 0000000..1b99ae3
--- /dev/null
+++ b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/KeystoneConfigJsonMatcher.java
@@ -0,0 +1,77 @@
+/*
+ * 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.KeystoneConfig;
+import org.onosproject.openstacknode.api.OpenstackAuth;
+
+/**
+ * Hamcrest matcher for keystone config.
+ */
+public final class KeystoneConfigJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode> {
+
+    private final KeystoneConfig keystoneConfig;
+
+    private static final String ENDPOINT = "endpoint";
+    private static final String AUTHENTICATION = "authentication";
+
+    private KeystoneConfigJsonMatcher(KeystoneConfig keystoneConfig) {
+        this.keystoneConfig = keystoneConfig;
+    }
+
+    @Override
+    protected boolean matchesSafely(JsonNode jsonNode, Description description) {
+
+        // check endpoint
+        JsonNode jsonEndpoint = jsonNode.get(ENDPOINT);
+        if (jsonEndpoint != null) {
+            String endpoint = keystoneConfig.endpoint();
+            if (!jsonEndpoint.asText().equals(endpoint)) {
+                description.appendText("endpoint was " + jsonEndpoint);
+                return false;
+            }
+        }
+
+        // check openstack auth
+        JsonNode jsonAuth = jsonNode.get(AUTHENTICATION);
+        if (jsonAuth != null) {
+            OpenstackAuth auth = keystoneConfig.authentication();
+            OpenstackAuthJsonMatcher authMatcher =
+                    OpenstackAuthJsonMatcher.matchOpenstackAuth(auth);
+            return authMatcher.matches(jsonAuth);
+        }
+
+        return true;
+    }
+
+    @Override
+    public void describeTo(Description description) {
+        description.appendText(keystoneConfig.toString());
+    }
+
+    /**
+     * Factory to allocate keystone config matcher.
+     *
+     * @param config keystone config object we are looking for
+     * @return matcher
+     */
+    public static KeystoneConfigJsonMatcher matchKeystoneConfig(KeystoneConfig config) {
+        return new KeystoneConfigJsonMatcher(config);
+    }
+}
diff --git a/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/NeutronConfigJsonMatcher.java b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/NeutronConfigJsonMatcher.java
new file mode 100644
index 0000000..185c7b6
--- /dev/null
+++ b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/NeutronConfigJsonMatcher.java
@@ -0,0 +1,77 @@
+/*
+ * 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.NeutronConfig;
+
+/**
+ * Hamcrest matcher for neutron config.
+ */
+public final class NeutronConfigJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode> {
+
+    private final NeutronConfig neutronConfig;
+
+    private static final String USE_METADATA_PROXY = "useMetadataProxy";
+    private static final String METADATA_PROXY_SECRET = "metadataProxySecret";
+
+    private NeutronConfigJsonMatcher(NeutronConfig neutronConfig) {
+        this.neutronConfig = neutronConfig;
+    }
+
+    @Override
+    protected boolean matchesSafely(JsonNode jsonNode, Description description) {
+
+        // check useMetaDataProxy
+        JsonNode jsonUseMetadataProxy = jsonNode.get(USE_METADATA_PROXY);
+        if (jsonUseMetadataProxy != null) {
+            boolean useMetadataProxy = neutronConfig.useMetadataProxy();
+            if (jsonUseMetadataProxy.asBoolean() != useMetadataProxy) {
+                description.appendText("useMetadataProxy was " + jsonUseMetadataProxy);
+                return false;
+            }
+        }
+
+        // check metadataProxySecret
+        JsonNode jsonMetadataProxySecret = jsonNode.get(METADATA_PROXY_SECRET);
+        if (jsonMetadataProxySecret != null) {
+            String metadataProxySecret = neutronConfig.metadataProxySecret();
+            if (!jsonMetadataProxySecret.asText().equals(metadataProxySecret)) {
+                description.appendText("metadataProxySecret was " + jsonUseMetadataProxy);
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public void describeTo(Description description) {
+        description.appendText(neutronConfig.toString());
+    }
+
+    /**
+     * Factory to allocate neutron config matcher.
+     *
+     * @param config neutron config object we are looking for
+     * @return matcher
+     */
+    public static NeutronConfigJsonMatcher matchNeutronConfig(NeutronConfig config) {
+        return new NeutronConfigJsonMatcher(config);
+    }
+}
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 af5fdf4..d97e47e 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
@@ -33,6 +33,8 @@
 import org.onosproject.openstacknode.api.DefaultOpenstackNode;
 import org.onosproject.openstacknode.api.DpdkConfig;
 import org.onosproject.openstacknode.api.DpdkInterface;
+import org.onosproject.openstacknode.api.KeystoneConfig;
+import org.onosproject.openstacknode.api.NeutronConfig;
 import org.onosproject.openstacknode.api.NodeState;
 import org.onosproject.openstacknode.api.OpenstackAuth;
 import org.onosproject.openstacknode.api.OpenstackNode;
@@ -40,6 +42,8 @@
 import org.onosproject.openstacknode.api.OpenstackSshAuth;
 import org.onosproject.openstacknode.impl.DefaultDpdkConfig;
 import org.onosproject.openstacknode.impl.DefaultDpdkInterface;
+import org.onosproject.openstacknode.api.DefaultKeystoneConfig;
+import org.onosproject.openstacknode.api.DefaultNeutronConfig;
 import org.onosproject.openstacknode.impl.DefaultOpenstackPhyInterface;
 import org.onosproject.openstacknode.impl.DefaultOpenstackSshAuth;
 
@@ -65,6 +69,7 @@
  */
 public class OpenstackNodeCodecTest {
     MockCodecContext context;
+
     JsonCodec<OpenstackNode> openstackNodeCodec;
     JsonCodec<OpenstackPhyInterface> openstackPhyIntfJsonCodec;
     JsonCodec<ControllerInfo> openstackControllerJsonCodec;
@@ -72,6 +77,8 @@
     JsonCodec<OpenstackSshAuth> openstackSshAuthJsonCodec;
     JsonCodec<DpdkConfig> dpdkConfigJsonCodec;
     JsonCodec<DpdkInterface> dpdkInterfaceJsonCodec;
+    JsonCodec<KeystoneConfig> keystoneConfigJsonCodec;
+    JsonCodec<NeutronConfig> neutronConfigJsonCodec;
 
     final CoreService mockCoreService = createMock(CoreService.class);
     private static final String REST_APP_ID = "org.onosproject.rest";
@@ -86,6 +93,8 @@
         openstackSshAuthJsonCodec = new OpenstackSshAuthCodec();
         dpdkConfigJsonCodec = new DpdkConfigCodec();
         dpdkInterfaceJsonCodec = new DpdkInterfaceCodec();
+        keystoneConfigJsonCodec = new KeystoneConfigCodec();
+        neutronConfigJsonCodec = new NeutronConfigCodec();
 
         assertThat(openstackNodeCodec, notNullValue());
         assertThat(openstackPhyIntfJsonCodec, notNullValue());
@@ -94,6 +103,8 @@
         assertThat(openstackSshAuthJsonCodec, notNullValue());
         assertThat(dpdkConfigJsonCodec, notNullValue());
         assertThat(dpdkInterfaceJsonCodec, notNullValue());
+        assertThat(keystoneConfigJsonCodec, notNullValue());
+        assertThat(neutronConfigJsonCodec, notNullValue());
 
         expect(mockCoreService.registerApplication(REST_APP_ID))
                 .andReturn(APP_ID).anyTimes();
@@ -257,13 +268,25 @@
                 .perspective(OpenstackAuth.Perspective.PUBLIC)
                 .build();
 
+        String endpoint = "172.16.130.10:35357/v2.0";
+
+        KeystoneConfig keystoneConfig = DefaultKeystoneConfig.builder()
+                                            .endpoint(endpoint)
+                                            .authentication(auth)
+                                            .build();
+
+        NeutronConfig neutronConfig = DefaultNeutronConfig.builder()
+                                            .useMetadataProxy(true)
+                                            .metadataProxySecret("onos")
+                                            .build();
+
         OpenstackNode node = DefaultOpenstackNode.builder()
                 .hostname("controller")
                 .type(OpenstackNode.NodeType.CONTROLLER)
                 .state(NodeState.INIT)
                 .managementIp(IpAddress.valueOf("172.16.130.10"))
-                .endpoint("keystone-end-point-url")
-                .authentication(auth)
+                .keystoneConfig(keystoneConfig)
+                .neutronConfig(neutronConfig)
                 .build();
 
         ObjectNode nodeJson = openstackNodeCodec.encode(node, context);
@@ -280,9 +303,10 @@
         assertThat(node.hostname(), is("controller"));
         assertThat(node.type().name(), is("CONTROLLER"));
         assertThat(node.managementIp().toString(), is("172.16.130.10"));
-        assertThat(node.endpoint(), is("keystone-end-point-url"));
 
-        OpenstackAuth auth = node.authentication();
+        KeystoneConfig keystoneConfig = node.keystoneConfig();
+        OpenstackAuth auth = keystoneConfig.authentication();
+        String endpoint = keystoneConfig.endpoint();
 
         assertThat(auth.version(), is("v2.0"));
         assertThat(auth.protocol(), is(OpenstackAuth.Protocol.HTTP));
@@ -290,6 +314,38 @@
         assertThat(auth.password(), is("nova"));
         assertThat(auth.project(), is("admin"));
         assertThat(auth.perspective(), is(OpenstackAuth.Perspective.PUBLIC));
+
+        assertThat(endpoint, is("172.16.130.10:35357/v2.0"));
+
+        NeutronConfig neutronConfig = node.neutronConfig();
+
+        assertThat(neutronConfig.useMetadataProxy(), is(true));
+        assertThat(neutronConfig.metadataProxySecret(), is("onos"));
+    }
+
+    /**
+     * Tests the openstack obsolete controller node decoding.
+     */
+    @Test
+    public void testOpenstackObsoleteControllerNodeDecode() throws IOException {
+        OpenstackNode node = getOpenstackNode("OpenstackObsoleteControllerNode.json");
+
+        assertThat(node.hostname(), is("controller"));
+        assertThat(node.type().name(), is("CONTROLLER"));
+        assertThat(node.managementIp().toString(), is("172.16.130.10"));
+
+        KeystoneConfig keystoneConfig = node.keystoneConfig();
+        OpenstackAuth auth = keystoneConfig.authentication();
+        String endpoint = keystoneConfig.endpoint();
+
+        assertThat(auth.version(), is("v2.0"));
+        assertThat(auth.protocol(), is(OpenstackAuth.Protocol.HTTP));
+        assertThat(auth.username(), is("admin"));
+        assertThat(auth.password(), is("nova"));
+        assertThat(auth.project(), is("admin"));
+        assertThat(auth.perspective(), is(OpenstackAuth.Perspective.PUBLIC));
+
+        assertThat(endpoint, is("172.16.130.10:35357/v2.0"));
     }
 
     /**
@@ -349,6 +405,12 @@
             if (entityClass == DpdkInterface.class) {
                 return (JsonCodec<T>) dpdkInterfaceJsonCodec;
             }
+            if (entityClass == KeystoneConfig.class) {
+                return (JsonCodec<T>) keystoneConfigJsonCodec;
+            }
+            if (entityClass == NeutronConfig.class) {
+                return (JsonCodec<T>) neutronConfigJsonCodec;
+            }
             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 6e3b473..5a94649 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
@@ -21,7 +21,6 @@
 import org.onosproject.net.behaviour.ControllerInfo;
 import org.onosproject.openstacknode.api.Constants;
 import org.onosproject.openstacknode.api.DpdkConfig;
-import org.onosproject.openstacknode.api.OpenstackAuth;
 import org.onosproject.openstacknode.api.OpenstackNode;
 import org.onosproject.openstacknode.api.OpenstackPhyInterface;
 import org.onosproject.openstacknode.api.OpenstackSshAuth;
@@ -113,17 +112,6 @@
             }
         }
 
-        // check openstack auth
-        JsonNode jsonAuth = jsonNode.get(AUTHENTICATION);
-        if (jsonAuth != null) {
-            OpenstackAuth auth = node.authentication();
-            OpenstackAuthJsonMatcher authMatcher =
-                    OpenstackAuthJsonMatcher.matchOpenstackAuth(auth);
-            if (!authMatcher.matches(jsonAuth)) {
-                return false;
-            }
-        }
-
         // check openstack ssh auth
         JsonNode jsonSshAuth = jsonNode.get(SSH_AUTH);
         if (jsonSshAuth != null) {
@@ -142,16 +130,6 @@
 
         }
 
-        // check endpoint URL
-        JsonNode jsonEndpoint = jsonNode.get(END_POINT);
-        if (jsonEndpoint != null) {
-            String endpoint = node.endpoint();
-            if (!jsonEndpoint.asText().equals(endpoint)) {
-                description.appendText("endpoint URL was " + jsonEndpoint);
-                return false;
-            }
-        }
-
         // check physical interfaces
         JsonNode jsonPhyIntfs = jsonNode.get(PHYSICAL_INTERFACES);
         if (jsonPhyIntfs != null) {
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 ebf12c0..ad5ab65 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
@@ -71,8 +71,9 @@
 import org.onosproject.net.provider.ProviderId;
 import org.onosproject.openstacknode.api.DefaultOpenstackNode;
 import org.onosproject.openstacknode.api.DpdkConfig;
+import org.onosproject.openstacknode.api.KeystoneConfig;
+import org.onosproject.openstacknode.api.NeutronConfig;
 import org.onosproject.openstacknode.api.NodeState;
-import org.onosproject.openstacknode.api.OpenstackAuth;
 import org.onosproject.openstacknode.api.OpenstackNode;
 import org.onosproject.openstacknode.api.OpenstackPhyInterface;
 import org.onosproject.openstacknode.api.OpenstackSshAuth;
@@ -501,10 +502,10 @@
                                   NodeState state,
                                   Set<OpenstackPhyInterface> phyIntfs,
                                   Set<ControllerInfo> controllers,
-                                  OpenstackAuth auth,
-                                  String endpoint,
                                   OpenstackSshAuth sshAuth,
-                                  DpdkConfig dpdkConfig) {
+                                  DpdkConfig dpdkConfig,
+                                  KeystoneConfig keystoneConfig,
+                                  NeutronConfig neutronConfig) {
             super(hostname,
                     type,
                     intgBridge,
@@ -515,10 +516,10 @@
                     state,
                     phyIntfs,
                     controllers,
-                    auth,
-                    endpoint,
                     sshAuth,
-                    dpdkConfig);
+                    dpdkConfig,
+                    keystoneConfig,
+                    neutronConfig);
         }
 
         @Override
diff --git a/apps/openstacknode/app/src/test/resources/org/onosproject/openstacknode/codec/OpenstackControllerNode.json b/apps/openstacknode/app/src/test/resources/org/onosproject/openstacknode/codec/OpenstackControllerNode.json
index c60baad..6da832d 100644
--- a/apps/openstacknode/app/src/test/resources/org/onosproject/openstacknode/codec/OpenstackControllerNode.json
+++ b/apps/openstacknode/app/src/test/resources/org/onosproject/openstacknode/codec/OpenstackControllerNode.json
@@ -2,14 +2,19 @@
   "hostname": "controller",
   "type": "CONTROLLER",
   "managementIp": "172.16.130.10",
-  "endpoint": "keystone-end-point-url",
-  "authentication": {
-    "version": "v2.0",
-    "port": 35357,
-    "protocol": "HTTP",
-    "project": "admin",
-    "username": "admin",
-    "password": "nova",
-    "perspective": "PUBLIC"
+  "keystoneConfig": {
+    "endpoint": "172.16.130.10:35357/v2.0",
+    "authentication": {
+      "version": "v2.0",
+      "protocol": "HTTP",
+      "project": "admin",
+      "username": "admin",
+      "password": "nova",
+      "perspective": "PUBLIC"
+    }
+  },
+  "neutronConfig": {
+    "useMetadataProxy": true,
+    "metadataProxySecret": "onos"
   }
 }
\ No newline at end of file
diff --git a/apps/openstacknode/app/src/test/resources/org/onosproject/openstacknode/codec/OpenstackObsoleteControllerNode.json b/apps/openstacknode/app/src/test/resources/org/onosproject/openstacknode/codec/OpenstackObsoleteControllerNode.json
new file mode 100644
index 0000000..8401f3e
--- /dev/null
+++ b/apps/openstacknode/app/src/test/resources/org/onosproject/openstacknode/codec/OpenstackObsoleteControllerNode.json
@@ -0,0 +1,18 @@
+{
+  "hostname": "controller",
+  "type": "CONTROLLER",
+  "managementIp": "172.16.130.10",
+  "neutronConfig": {
+    "useMetadataProxy": true,
+    "metadataProxySecret": "onos"
+  },
+  "endpoint": "172.16.130.10:35357/v2.0",
+  "authentication": {
+    "version": "v2.0",
+    "protocol": "HTTP",
+    "project": "admin",
+    "username": "admin",
+    "password": "nova",
+    "perspective": "PUBLIC"
+  }
+}
\ No newline at end of file