ONOS-3655 - Initial submission for DeviceKey subsystem.

Change-Id: I14c834c65b68e49b80894efe12b1fa921fc430cc
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/key/CommunityName.java b/incubator/api/src/main/java/org/onosproject/incubator/net/key/CommunityName.java
new file mode 100644
index 0000000..24b93a0
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/key/CommunityName.java
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+/**
+ * Representation of an SNMP community name authentication token.
+ */
+public final class CommunityName {
+    private final String name;
+
+    /**
+     * Private constructor for a community name.
+     *
+     * @param name community name
+     */
+    private CommunityName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * Static method to construct a community name.
+     *
+     * @param name community name
+     * @return community name
+     */
+    static CommunityName communityName(String name) {
+        return new CommunityName(name);
+    }
+
+    /**
+     * Returns the community name.
+     *
+     * @return name
+     */
+    public String name() {
+        return name;
+    }
+}
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);
+    }
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/key/DeviceKeyAdminService.java b/incubator/api/src/main/java/org/onosproject/incubator/net/key/DeviceKeyAdminService.java
new file mode 100644
index 0000000..be7f02f
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/key/DeviceKeyAdminService.java
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+/**
+ * Service for managing device keys.
+ */
+@Beta
+public interface DeviceKeyAdminService extends DeviceKeyService {
+
+    /**
+     * Adds a new device key to the store.
+     *
+     * @param deviceKey device key to be stored
+     */
+    void addKey(DeviceKey deviceKey);
+
+    /**
+     * Removes a device key from the store using the device
+     * key identifier.
+     *
+     * @param id device key identifier used to identify the device key
+     */
+    void removeKey(DeviceKeyId id);
+}
+
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/key/DeviceKeyId.java b/incubator/api/src/main/java/org/onosproject/incubator/net/key/DeviceKeyId.java
new file mode 100644
index 0000000..2ec5c60
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/key/DeviceKeyId.java
@@ -0,0 +1,101 @@
+/*
+ * 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 java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Device key Id definition.
+ */
+public final class DeviceKeyId {
+    private final String identifier;
+
+    /**
+     * Constructor for serialization.
+     */
+    private DeviceKeyId() {
+        this.identifier = null;
+    }
+
+    /**
+     * Constructs the ID corresponding to a given string value.
+     *
+     * @param value the underlying value of this ID
+     */
+    private DeviceKeyId(String value) {
+        this.identifier = checkNotNull(value, "Device Key Id cannot be null.");
+    }
+
+    /**
+     * Static  method to construct a device key identifier.
+     *
+     * @param id for the device key identifier
+     * @return device key identifier
+     */
+    static final DeviceKeyId deviceKeyId(String id) {
+        return new DeviceKeyId(id);
+    }
+
+    /**
+     * Returns the identifier of the device key identifier.
+     *
+     * @return identifier
+     */
+    public String id() {
+        return identifier;
+    }
+
+    /**
+     * Returns the hashcode of the identifier.
+     *
+     * @return hashcode
+     */
+    @Override
+    public int hashCode() {
+        return identifier.hashCode();
+    }
+
+    /**
+     * Compares two device key identifiers for equality.
+     *
+     * @param obj to compare against
+     * @return true if the objects are equal, false otherwise.
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof DeviceKeyId) {
+            final DeviceKeyId that = (DeviceKeyId) obj;
+            return this.getClass() == that.getClass() &&
+                    Objects.equals(this.identifier, that.identifier);
+        }
+        return false;
+    }
+
+    /**
+     * Returns a string representation of a DeviceKeyId.
+     *
+     * @return string
+     */
+    public String toString() {
+        return identifier;
+    }
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/key/DeviceKeyService.java b/incubator/api/src/main/java/org/onosproject/incubator/net/key/DeviceKeyService.java
new file mode 100644
index 0000000..0372359
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/key/DeviceKeyService.java
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+/**
+ * Service for querying device keys.
+ */
+@Beta
+public interface DeviceKeyService {
+
+    /**
+     * Returns all device keys.
+     *
+     * @return collection of device keys
+     */
+    Iterable<DeviceKey> getDeviceKeys();
+
+    /**
+     * Returns the device key(s) using a device key identifier.
+     *
+     * @param id device key identifier
+     * @return collection of device keys
+     */
+    Iterable<DeviceKey> getDeviceKey(DeviceKeyId id);
+}
+
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/key/package-info.java b/incubator/api/src/main/java/org/onosproject/incubator/net/key/package-info.java
new file mode 100644
index 0000000..35e53db
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/key/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+/**
+ * Device key data model and services.
+ * This subsystem and its interfaces will change in the upcoming release.
+ */
+package org.onosproject.incubator.net.key;
\ No newline at end of file