[ONOS-7621] Support injecting keystone auth info through network-cfg

Change-Id: I2439e257f0f576c46b68322b8c8f1c87fa2cc9ae
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackAuthCodec.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackAuthCodec.java
new file mode 100644
index 0000000..5556d9c
--- /dev/null
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackAuthCodec.java
@@ -0,0 +1,100 @@
+/*
+ * 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.OpenstackAuth;
+import org.onosproject.openstacknode.impl.DefaultOpenstackAuth;
+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 keystone authentication codec used for serializing and
+ * de-serializing JSON string.
+ */
+public class OpenstackAuthCodec extends JsonCodec<OpenstackAuth> {
+
+    private final Logger log = getLogger(getClass());
+
+    private static final String VERSION = "version";
+    private static final String PORT = "port";
+    private static final String PROTOCOL = "protocol";
+    private static final String USERNAME = "username";
+    private static final String PASSWORD = "password";
+    private static final String PROJECT = "project";
+    private static final String PERSPECTIVE = "perspective";
+
+    private static final String MISSING_MESSAGE = " is required in OpenstackAuth";
+
+    @Override
+    public ObjectNode encode(OpenstackAuth auth, CodecContext context) {
+        checkNotNull(auth, "Openstack auth cannot be null");
+
+        ObjectNode result = context.mapper().createObjectNode()
+                .put(VERSION, auth.version())
+                .put(PORT, auth.port())
+                .put(PROTOCOL, auth.protocol().name())
+                .put(USERNAME, auth.username())
+                .put(PASSWORD, auth.password())
+                .put(PROJECT, auth.project());
+
+        if (auth.perspective() != null) {
+            result.put(PERSPECTIVE, auth.perspective().name());
+        }
+
+        return result;
+    }
+
+    @Override
+    public OpenstackAuth decode(ObjectNode json, CodecContext context) {
+        if (json == null || !json.isObject()) {
+            return null;
+        }
+
+        String version = nullIsIllegal(json.get(VERSION).asText(),
+                VERSION + MISSING_MESSAGE);
+        Integer port = nullIsIllegal(json.get(PORT).asInt(),
+                PORT + MISSING_MESSAGE);
+        String protocol = nullIsIllegal(json.get(PROTOCOL).asText(),
+                PROTOCOL + MISSING_MESSAGE);
+        String username = nullIsIllegal(json.get(USERNAME).asText(),
+                USERNAME + MISSING_MESSAGE);
+        String password = nullIsIllegal(json.get(PASSWORD).asText(),
+                PASSWORD + MISSING_MESSAGE);
+        String project = nullIsIllegal(json.get(PROJECT).asText(),
+                PROJECT + MISSING_MESSAGE);
+
+        DefaultOpenstackAuth.Builder authBuilder = DefaultOpenstackAuth.builder()
+                .version(version)
+                .port(port)
+                .protocol(OpenstackAuth.Protocol.valueOf(protocol))
+                .username(username)
+                .password(password)
+                .project(project);
+
+        if (json.get(PERSPECTIVE) != null) {
+            authBuilder.perspective(
+                    OpenstackAuth.Perspective.valueOf(json.get(PERSPECTIVE).asText()));
+        }
+
+        return authBuilder.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 3c5feba..1d30bf6 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
@@ -23,6 +23,7 @@
 import org.onosproject.codec.JsonCodec;
 import org.onosproject.net.DeviceId;
 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.impl.DefaultOpenstackNode;
@@ -34,6 +35,7 @@
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.onlab.util.Tools.nullIsIllegal;
+import static org.onosproject.openstacknode.api.Constants.CONTROLLER;
 import static org.onosproject.openstacknode.api.Constants.DATA_IP;
 import static org.onosproject.openstacknode.api.Constants.GATEWAY;
 import static org.onosproject.openstacknode.api.Constants.HOST_NAME;
@@ -53,6 +55,7 @@
     private static final String INTEGRATION_BRIDGE = "integrationBridge";
     private static final String STATE = "state";
     private static final String PHYSICAL_INTERFACES = "phyIntfs";
+    private static final String AUTHENTICATION = "authentication";
 
     private static final String MISSING_MESSAGE = " is required in OpenstackNode";
 
@@ -64,7 +67,6 @@
                 .put(HOST_NAME, node.hostname())
                 .put(TYPE, node.type().name())
                 .put(MANAGEMENT_IP, node.managementIp().toString())
-                .put(INTEGRATION_BRIDGE, node.intgBridge().toString())
                 .put(STATE, node.state().name());
 
         OpenstackNode.NodeType type = node.type();
@@ -73,6 +75,10 @@
             result.put(UPLINK_PORT, node.uplinkPort());
         }
 
+        if (type != OpenstackNode.NodeType.CONTROLLER) {
+            result.put(INTEGRATION_BRIDGE, node.intgBridge().toString());
+        }
+
         if (node.vlanIntf() != null) {
             result.put(VLAN_INTF_NAME, node.vlanIntf());
         }
@@ -91,6 +97,12 @@
         });
         result.set(PHYSICAL_INTERFACES, phyIntfs);
 
+        if (node.authentication() != null) {
+            ObjectNode authJson = context.codec(OpenstackAuth.class)
+                    .encode(node.authentication(), context);
+            result.put(AUTHENTICATION, authJson);
+        }
+
         return result;
     }
 
@@ -100,28 +112,28 @@
             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(),
                 TYPE + MISSING_MESSAGE);
         String mIp = nullIsIllegal(json.get(MANAGEMENT_IP).asText(),
                 MANAGEMENT_IP + MISSING_MESSAGE);
-        String iBridge = nullIsIllegal(json.get(INTEGRATION_BRIDGE).asText(),
-                INTEGRATION_BRIDGE + MISSING_MESSAGE);
 
         DefaultOpenstackNode.Builder nodeBuilder = DefaultOpenstackNode.builder()
                 .hostname(hostname)
                 .type(OpenstackNode.NodeType.valueOf(type))
                 .managementIp(IpAddress.valueOf(mIp))
-                .intgBridge(DeviceId.deviceId(iBridge))
                 .state(NodeState.INIT);
 
         if (type.equals(GATEWAY)) {
             nodeBuilder.uplinkPort(nullIsIllegal(json.get(UPLINK_PORT).asText(),
                     UPLINK_PORT + MISSING_MESSAGE));
         }
+        if (!type.equals(CONTROLLER)) {
+            String iBridge = nullIsIllegal(json.get(INTEGRATION_BRIDGE).asText(),
+                    INTEGRATION_BRIDGE + MISSING_MESSAGE);
+            nodeBuilder.intgBridge(DeviceId.deviceId(iBridge));
+        }
         if (json.get(VLAN_INTF_NAME) != null) {
             nodeBuilder.vlanIntf(json.get(VLAN_INTF_NAME).asText());
         }
@@ -133,6 +145,10 @@
         List<OpenstackPhyInterface> phyIntfs = new ArrayList<>();
         JsonNode phyIntfsJson = json.get(PHYSICAL_INTERFACES);
         if (phyIntfsJson != null) {
+
+            final JsonCodec<OpenstackPhyInterface>
+                    phyIntfCodec = context.codec(OpenstackPhyInterface.class);
+
             IntStream.range(0, phyIntfsJson.size()).forEach(i -> {
                 ObjectNode intfJson = get(phyIntfsJson, i);
                 phyIntfs.add(phyIntfCodec.decode(intfJson, context));
@@ -140,6 +156,16 @@
         }
         nodeBuilder.phyIntfs(phyIntfs);
 
+        // parse authentication
+        JsonNode authJson = json.get(AUTHENTICATION);
+        if (json.get(AUTHENTICATION) != null) {
+
+            final JsonCodec<OpenstackAuth> authCodec = context.codec(OpenstackAuth.class);
+
+            OpenstackAuth auth = authCodec.decode((ObjectNode) authJson.deepCopy(), context);
+            nodeBuilder.authentication(auth);
+        }
+
         log.trace("node is {}", nodeBuilder.build().toString());
 
         return nodeBuilder.build();
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackAuth.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackAuth.java
new file mode 100644
index 0000000..3257353
--- /dev/null
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackAuth.java
@@ -0,0 +1,225 @@
+/*
+ * 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.OpenstackAuth;
+
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+public class DefaultOpenstackAuth implements OpenstackAuth {
+
+    private final String version;
+    private final Integer port;
+    private final Protocol protocol;
+    private final String username;
+    private final String password;
+    private final String project;
+    private final Perspective perspective;
+
+    private static final String NOT_NULL_MSG = "% cannot be null";
+
+    /**
+     * A default constructor of keystone authentication instance.
+     *
+     * @param version       version number
+     * @param port          endpoint port number
+     * @param protocol      endpoint protocol type
+     * @param username      keystone username
+     * @param password      keystone password
+     * @param project       project name
+     * @param perspective   user perspective
+     */
+    protected DefaultOpenstackAuth(String version, Integer port, Protocol protocol,
+                                   String username, String password, String project,
+                                   Perspective perspective) {
+
+        this.version = version;
+        this.port = port;
+        this.protocol = protocol;
+        this.username = username;
+        this.password = password;
+        this.project = project;
+        this.perspective = perspective;
+    }
+
+    @Override
+    public String version() {
+        return version;
+    }
+
+    @Override
+    public Integer port() {
+        return port;
+    }
+
+    @Override
+    public Protocol protocol() {
+        return protocol;
+    }
+
+    @Override
+    public String username() {
+        return username;
+    }
+
+    @Override
+    public String password() {
+        return password;
+    }
+
+    @Override
+    public String project() {
+        return project;
+    }
+
+    @Override
+    public Perspective perspective() {
+        return perspective;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+
+        if (obj instanceof DefaultOpenstackAuth) {
+            DefaultOpenstackAuth that = (DefaultOpenstackAuth) obj;
+            return Objects.equals(version, that.version) &&
+                    Objects.equals(port, that.port) &&
+                    Objects.equals(protocol, that.protocol) &&
+                    Objects.equals(username, that.username) &&
+                    Objects.equals(password, that.password) &&
+                    Objects.equals(project, that.project) &&
+                    Objects.equals(perspective, that.perspective);
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(version,
+                port,
+                protocol,
+                username,
+                password,
+                project,
+                perspective);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(getClass())
+                .add("version", version)
+                .add("port", port)
+                .add("protocol", protocol)
+                .add("username", username)
+                .add("password", password)
+                .add("project", project)
+                .add("perspective", perspective)
+                .toString();
+    }
+
+    /**
+     * Returns new builder instance.
+     *
+     * @return keystone authentication instance builder
+     */
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    /**
+     * A builder class for openstack authentication.
+     */
+    public static final class Builder implements OpenstackAuth.Builder {
+
+        private String version;
+        private Integer port;
+        private Protocol protocol;
+        private String username;
+        private String password;
+        private String project;
+        private Perspective perspective;
+
+        // private constructor not intended to use from external
+        private Builder() {
+        }
+
+        @Override
+        public OpenstackAuth build() {
+            checkArgument(version != null, NOT_NULL_MSG, "version");
+            checkArgument(port != null, NOT_NULL_MSG, "port");
+            checkArgument(protocol != null, NOT_NULL_MSG, "protocol");
+            checkArgument(username != null, NOT_NULL_MSG, "username");
+            checkArgument(password != null, NOT_NULL_MSG, "password");
+            checkArgument(project != null, NOT_NULL_MSG, "project");
+
+            return new DefaultOpenstackAuth(version,
+                    port,
+                    protocol,
+                    username,
+                    password,
+                    project,
+                    perspective);
+        }
+
+        @Override
+        public Builder version(String version) {
+            this.version = version;
+            return this;
+        }
+
+        @Override
+        public Builder port(Integer port) {
+            this.port = port;
+            return this;
+        }
+
+        @Override
+        public Builder protocol(Protocol protocol) {
+            this.protocol = protocol;
+            return this;
+        }
+
+        @Override
+        public Builder username(String username) {
+            this.username = username;
+            return this;
+        }
+
+        @Override
+        public Builder password(String password) {
+            this.password = password;
+            return this;
+        }
+
+        @Override
+        public Builder project(String project) {
+            this.project = project;
+            return this;
+        }
+
+        @Override
+        public Builder perspective(Perspective perspective) {
+            this.perspective = perspective;
+            return this;
+        }
+    }
+}
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 c632847..f05d58b 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
@@ -28,6 +28,7 @@
 import org.onosproject.net.group.DefaultGroupKey;
 import org.onosproject.net.group.GroupKey;
 import org.onosproject.openstacknode.api.NodeState;
+import org.onosproject.openstacknode.api.OpenstackAuth;
 import org.onosproject.openstacknode.api.OpenstackNode;
 import org.onosproject.openstacknode.api.OpenstackPhyInterface;
 
@@ -56,6 +57,7 @@
     private final String uplinkPort;
     private final NodeState state;
     private final Collection<OpenstackPhyInterface> phyIntfs;
+    private final OpenstackAuth auth;
 
     private static final String NOT_NULL_MSG = "Node % cannot be null";
 
@@ -73,6 +75,7 @@
      * @param uplinkPort    uplink port name
      * @param state         node state
      * @param phyIntfs      physical interfaces
+     * @param auth          keystone authentication info
      */
     protected DefaultOpenstackNode(String hostname, NodeType type,
                                    DeviceId intgBridge,
@@ -81,7 +84,8 @@
                                    String vlanIntf,
                                    String uplinkPort,
                                    NodeState state,
-                                   Collection<OpenstackPhyInterface> phyIntfs) {
+                                   Collection<OpenstackPhyInterface> phyIntfs,
+                                   OpenstackAuth auth) {
         this.hostname = hostname;
         this.type = type;
         this.intgBridge = intgBridge;
@@ -91,6 +95,7 @@
         this.uplinkPort = uplinkPort;
         this.state = state;
         this.phyIntfs = phyIntfs;
+        this.auth = auth;
     }
 
     @Override
@@ -229,7 +234,8 @@
                     Objects.equals(dataIp, that.dataIp) &&
                     Objects.equals(uplinkPort, that.uplinkPort) &&
                     Objects.equals(vlanIntf, that.vlanIntf) &&
-                    Objects.equals(phyIntfs, that.phyIntfs);
+                    Objects.equals(phyIntfs, that.phyIntfs) &&
+                    Objects.equals(auth, that.auth);
         }
         return false;
     }
@@ -243,7 +249,8 @@
                 dataIp,
                 vlanIntf,
                 uplinkPort,
-                phyIntfs);
+                phyIntfs,
+                auth);
     }
 
     @Override
@@ -258,6 +265,7 @@
                 .add("uplinkPort", uplinkPort)
                 .add("state", state)
                 .add("phyIntfs", phyIntfs)
+                .add("auth", auth)
                 .toString();
     }
 
@@ -273,6 +281,7 @@
                 .uplinkPort(uplinkPort)
                 .state(newState)
                 .phyIntfs(phyIntfs)
+                .authentication(auth)
                 .build();
     }
 
@@ -304,6 +313,12 @@
         }
 
     }
+
+    @Override
+    public OpenstackAuth authentication() {
+        return auth;
+    }
+
     /**
      * Returns new builder instance.
      *
@@ -329,7 +344,8 @@
                 .vlanIntf(osNode.vlanIntf())
                 .uplinkPort(osNode.uplinkPort())
                 .state(osNode.state())
-                .phyIntfs(osNode.phyIntfs());
+                .phyIntfs(osNode.phyIntfs())
+                .authentication(osNode.authentication());
     }
 
     /**
@@ -346,6 +362,7 @@
         private String uplinkPort;
         private NodeState state;
         private Collection<OpenstackPhyInterface> phyIntfs;
+        private OpenstackAuth auth;
 
         // private constructor not intended to use from external
         private Builder() {
@@ -355,16 +372,24 @@
         public DefaultOpenstackNode build() {
             checkArgument(hostname != null, NOT_NULL_MSG, "hostname");
             checkArgument(type != null, NOT_NULL_MSG, "type");
-            checkArgument(intgBridge != null, NOT_NULL_MSG, "integration bridge");
+
             checkArgument(managementIp != null, NOT_NULL_MSG, "management IP");
             checkArgument(state != null, NOT_NULL_MSG, "state");
 
+            if (type != NodeType.CONTROLLER) {
+                checkArgument(intgBridge != null, NOT_NULL_MSG, "integration bridge");
+
+                if (dataIp == null && Strings.isNullOrEmpty(vlanIntf)) {
+                    throw new IllegalArgumentException("Either data IP or VLAN interface is required");
+                }
+            } else {
+                // we force controller node to have COMPLETE state for now
+                state = NodeState.COMPLETE;
+            }
+
             if (type == NodeType.GATEWAY && uplinkPort == null) {
                 throw new IllegalArgumentException("Uplink port is required for gateway node");
             }
-            if (dataIp == null && Strings.isNullOrEmpty(vlanIntf)) {
-                throw new IllegalArgumentException("Either data IP or VLAN interface is required");
-            }
 
             return new DefaultOpenstackNode(hostname,
                     type,
@@ -374,7 +399,8 @@
                     vlanIntf,
                     uplinkPort,
                     state,
-                    phyIntfs);
+                    phyIntfs,
+                    auth);
         }
 
         @Override
@@ -432,6 +458,12 @@
             this.phyIntfs = phyIntfs;
             return this;
         }
+
+        @Override
+        public Builder authentication(OpenstackAuth auth) {
+            this.auth = auth;
+            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 025757e..b9e193a 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
@@ -51,7 +51,6 @@
 import org.onosproject.net.device.DeviceService;
 import org.onosproject.net.flow.instructions.ExtensionPropertyException;
 import org.onosproject.net.flow.instructions.ExtensionTreatment;
-
 import org.onosproject.openstacknode.api.NodeState;
 import org.onosproject.openstacknode.api.OpenstackNode;
 import org.onosproject.openstacknode.api.OpenstackNodeAdminService;
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 d3c2ce4..be49135 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
@@ -50,11 +50,14 @@
 import static org.onlab.util.Tools.groupedThreads;
 import static org.onosproject.openstacknode.api.NodeState.COMPLETE;
 import static org.onosproject.openstacknode.api.NodeState.INCOMPLETE;
+import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER;
 import static org.onosproject.openstacknode.api.OpenstackNodeEvent.Type.OPENSTACK_NODE_COMPLETE;
 import static org.onosproject.openstacknode.api.OpenstackNodeEvent.Type.OPENSTACK_NODE_CREATED;
 import static org.onosproject.openstacknode.api.OpenstackNodeEvent.Type.OPENSTACK_NODE_INCOMPLETE;
 import static org.onosproject.openstacknode.api.OpenstackNodeEvent.Type.OPENSTACK_NODE_REMOVED;
 import static org.onosproject.openstacknode.api.OpenstackNodeEvent.Type.OPENSTACK_NODE_UPDATED;
+import static org.onosproject.store.service.MapEvent.Type.INSERT;
+import static org.onosproject.store.service.MapEvent.Type.UPDATE;
 import static org.slf4j.LoggerFactory.getLogger;
 
 /**
@@ -79,6 +82,9 @@
             .register(NodeState.class)
             .register(OpenstackPhyInterface.class)
             .register(DefaultOpenstackPhyInterface.class)
+            .register(DefaultOpenstackAuth.class)
+            .register(DefaultOpenstackAuth.Perspective.class)
+            .register(DefaultOpenstackAuth.Protocol.class)
             .register(Collection.class)
             .build();
 
@@ -159,6 +165,24 @@
 
         @Override
         public void event(MapEvent<String, OpenstackNode> event) {
+
+            OpenstackNode node;
+
+            if (event.type() == INSERT || event.type() == UPDATE) {
+                node = event.newValue().value();
+            } else {
+                node = event.oldValue().value();
+            }
+
+            // we do not notify the controller node related event
+            // controller node event should be handled in different way
+            if (node.type() == CONTROLLER) {
+                // TODO: need to find a way to check the controller node availability
+                log.info("node {} is detected", node.hostname());
+
+                return;
+            }
+
             switch (event.type()) {
                 case INSERT:
                     log.debug("OpenStack node created {}", event.newValue());
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 420e87a..c1609a9 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
@@ -21,8 +21,10 @@
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.onosproject.codec.CodecService;
+import org.onosproject.openstacknode.api.OpenstackAuth;
 import org.onosproject.openstacknode.api.OpenstackNode;
 import org.onosproject.openstacknode.api.OpenstackPhyInterface;
+import org.onosproject.openstacknode.codec.OpenstackAuthCodec;
 import org.onosproject.openstacknode.codec.OpenstackNodeCodec;
 import org.onosproject.openstacknode.codec.OpenstackPhyInterfaceCodec;
 
@@ -42,6 +44,7 @@
     @Activate
     protected void activate() {
         codecService.registerCodec(OpenstackNode.class, new OpenstackNodeCodec());
+        codecService.registerCodec(OpenstackAuth.class, new OpenstackAuthCodec());
         codecService.registerCodec(OpenstackPhyInterface.class, new OpenstackPhyInterfaceCodec());
 
         log.info("Started");
@@ -50,6 +53,7 @@
     @Deactivate
     protected void deactivate() {
         codecService.unregisterCodec(OpenstackNode.class);
+        codecService.unregisterCodec(OpenstackAuth.class);
         codecService.unregisterCodec(OpenstackPhyInterface.class);
 
         log.info("Stopped");