ONOS-3655 - Initial submission for DeviceKey subsystem.

Change-Id: I14c834c65b68e49b80894efe12b1fa921fc430cc
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/key/DeviceKey.java b/incubator/api/src/main/java/org/onosproject/incubator/net/key/DeviceKey.java
new file mode 100644
index 0000000..51d042b
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/key/DeviceKey.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * 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.incubator.net.key;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.AbstractAnnotated;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.DefaultAnnotations;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+import static org.onosproject.net.DefaultAnnotations.builder;
+
+/**
+ * Abstraction of a device key.
+ */
+@Beta
+public class DeviceKey extends AbstractAnnotated {
+
+    // device key identifier
+    private final DeviceKeyId deviceKeyId;
+    // label of the device key
+    private String label;
+
+    /**
+     * type of the device key.
+     */
+    enum Type {
+        COMMUNITY_NAME, USERNAME_PASSWORD, SSL_KEY
+    }
+
+    private Type type;
+
+    /**
+     * Constructor for serialization.
+     */
+    DeviceKey() {
+        this.deviceKeyId = null;
+        this.label = null;
+        this.type = null;
+    }
+
+    /**
+     * Private constructor for a device key.
+     *
+     * @param id          device key identifier
+     * @param label       optional label for this device key
+     * @param type        to be assigned to this device key
+     * @param annotations name/value pairs for this device key
+     */
+    private DeviceKey(DeviceKeyId id, String label, Type type, Annotations... annotations) {
+        super(annotations);
+        checkNotNull(id, "The DeviceKeyId cannot be null.");
+        this.deviceKeyId = id;
+        this.label = label;
+        this.type = type;
+    }
+
+    /**
+     * Returns the device key identifier of the device key.
+     *
+     * @return device key identifier
+     */
+    public DeviceKeyId deviceKeyId() {
+        return deviceKeyId;
+    }
+
+    /**
+     * Returns the label of device key.
+     *
+     * @return label
+     */
+    public String label() {
+        return label;
+    }
+
+    /**
+     * Returns the type of the device key.
+     *
+     * @return type
+     */
+    public Type type() {
+        return type;
+    }
+
+    /**
+     * Method to create a device key of type CommunityName.
+     *
+     * @param id    device key identifier
+     * @param label optional label for this device key
+     * @param name  community name for this device key
+     * @return device key
+     */
+    public static DeviceKey createDeviceKeyUsingCommunityName(DeviceKeyId id, String label, String name) {
+        DefaultAnnotations annotations = builder().set(AnnotationKeys.NAME, name).build();
+
+        return new DeviceKey(id, label, Type.COMMUNITY_NAME, annotations);
+    }
+
+    /**
+     * Returns a community name object from the device key.
+     *
+     * @return community name
+     */
+    public CommunityName asCommunityName() {
+
+        // Validate that the device key is of type COMMUNITY_NAME.
+        checkState(this.type == Type.COMMUNITY_NAME, "This device key is not a COMMUNITY_NAME type.");
+
+        String name = annotations().value(AnnotationKeys.NAME);
+        return CommunityName.communityName(name);
+    }
+}