ONOS-3931: move "org.onosproject.incubator.net.key" to "org.onosproject.net.key"
Change-Id: I90da894317583ce8d6cfb238e933ff28ad2c83ca
diff --git a/core/api/src/main/java/org/onosproject/net/key/CommunityName.java b/core/api/src/main/java/org/onosproject/net/key/CommunityName.java
new file mode 100644
index 0000000..3c3e29e
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/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.net.key;
+
+/**
+ * Representation of an SNMP community name authentication token.
+ */
+public final class CommunityName extends DeviceKey {
+ 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/core/api/src/main/java/org/onosproject/net/key/DeviceKey.java b/core/api/src/main/java/org/onosproject/net/key/DeviceKey.java
new file mode 100644
index 0000000..3f4a9fd
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/key/DeviceKey.java
@@ -0,0 +1,160 @@
+/*
+ * 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.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.
+ */
+ public 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);
+ }
+
+ /**
+ * Method to create a device key of type USERNAME_PASSWORD.
+ *
+ * @param id device key identifier
+ * @param label optional label for this device key
+ * @param username username for this device key
+ * @param password password for this device key
+ * @return device key
+ */
+ public static DeviceKey createDeviceKeyUsingUsernamePassword(DeviceKeyId id, String label,
+ String username, String password) {
+ DefaultAnnotations annotations = builder().set(AnnotationKeys.USERNAME, username)
+ .set(AnnotationKeys.PASSWORD, password).build();
+
+ return new DeviceKey(id, label, Type.USERNAME_PASSWORD, annotations);
+ }
+
+ /**
+ * Returns a username and password object from the device key.
+ *
+ * @return username and password
+ */
+ public UsernamePassword asUsernamePassword() {
+
+ // Validate that the device key is of type USERNAME_PASSWORD.
+ checkState(this.type == Type.USERNAME_PASSWORD, "This device key is not a USERNAME_PASSWORD type.");
+
+ String username = annotations().value(AnnotationKeys.USERNAME);
+ String password = annotations().value(AnnotationKeys.PASSWORD);
+ return UsernamePassword.usernamePassword(username, password);
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/key/DeviceKeyAdminService.java b/core/api/src/main/java/org/onosproject/net/key/DeviceKeyAdminService.java
new file mode 100644
index 0000000..9e4f168
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/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.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/core/api/src/main/java/org/onosproject/net/key/DeviceKeyEvent.java b/core/api/src/main/java/org/onosproject/net/key/DeviceKeyEvent.java
new file mode 100644
index 0000000..2cd1d57
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/key/DeviceKeyEvent.java
@@ -0,0 +1,69 @@
+/*
+ * 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.net.key;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.event.AbstractEvent;
+
+/**
+ * Describes device key events.
+ */
+@Beta
+public class DeviceKeyEvent extends AbstractEvent<DeviceKeyEvent.Type, DeviceKey> {
+
+ /**
+ * Type of device key events.
+ */
+ public enum Type {
+ /**
+ * Signals that a new device key has been added.
+ */
+ DEVICE_KEY_ADDED,
+
+ /**
+ * Signals that a device key has been updated or changed state.
+ */
+ DEVICE_KEY_UPDATED,
+
+ /**
+ * Signals that a device key has been removed.
+ */
+ DEVICE_KEY_REMOVED
+ }
+
+ /**
+ * Creates an event of a given type, and for the specified device key.
+ *
+ * @param type device key event type
+ * @param deviceKey event device key subject
+ */
+ public DeviceKeyEvent(Type type, DeviceKey deviceKey) {
+ super(type, deviceKey);
+ }
+
+ /**
+ * Creates an event of a given type, for the specified device key, and
+ * the current time.
+ *
+ * @param type device key event type
+ * @param deviceKey event device key subject
+ * @param time occurrence time
+ */
+ public DeviceKeyEvent(Type type, DeviceKey deviceKey, long time) {
+ super(type, deviceKey, time);
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/key/DeviceKeyId.java b/core/api/src/main/java/org/onosproject/net/key/DeviceKeyId.java
new file mode 100644
index 0000000..12c1d95
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/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.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
+ */
+ public 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/core/api/src/main/java/org/onosproject/net/key/DeviceKeyListener.java b/core/api/src/main/java/org/onosproject/net/key/DeviceKeyListener.java
new file mode 100644
index 0000000..f7f8080
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/key/DeviceKeyListener.java
@@ -0,0 +1,27 @@
+/*
+ * 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.net.key;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.event.EventListener;
+
+/**
+ * Listener for device key related events.
+ */
+@Beta
+public interface DeviceKeyListener extends EventListener<DeviceKeyEvent> {
+}
diff --git a/core/api/src/main/java/org/onosproject/net/key/DeviceKeyService.java b/core/api/src/main/java/org/onosproject/net/key/DeviceKeyService.java
new file mode 100644
index 0000000..b87530f
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/key/DeviceKeyService.java
@@ -0,0 +1,45 @@
+/*
+ * 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.net.key;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.event.ListenerService;
+
+import java.util.Collection;
+
+/**
+ * Service for querying device keys.
+ */
+@Beta
+public interface DeviceKeyService extends ListenerService<DeviceKeyEvent, DeviceKeyListener> {
+
+ /**
+ * Returns all device keys.
+ *
+ * @return Collection of device keys
+ */
+ Collection<DeviceKey> getDeviceKeys();
+
+ /**
+ * Returns the device key using a device key identifier.
+ *
+ * @param deviceKeyId device key identifier
+ * @return device key
+ */
+ DeviceKey getDeviceKey(DeviceKeyId deviceKeyId);
+}
+
diff --git a/core/api/src/main/java/org/onosproject/net/key/DeviceKeyStore.java b/core/api/src/main/java/org/onosproject/net/key/DeviceKeyStore.java
new file mode 100644
index 0000000..c9b1194
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/key/DeviceKeyStore.java
@@ -0,0 +1,57 @@
+/*
+ * 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.net.key;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.store.Store;
+
+import java.util.Collection;
+
+/**
+ * Manages inventory of device keys; not intended for direct use.
+ */
+@Beta
+public interface DeviceKeyStore extends Store<DeviceKeyEvent, DeviceKeyStoreDelegate> {
+ /**
+ * Creates or updates a device key.
+ *
+ * @param deviceKey device key
+ */
+ void createOrUpdateDeviceKey(DeviceKey deviceKey);
+
+ /**
+ * Deletes a device key by a specific device key identifier.
+ *
+ * @param deviceKeyId device key unique identifier
+ */
+ void deleteDeviceKey(DeviceKeyId deviceKeyId);
+
+ /**
+ * Returns all device keys.
+ *
+ * @return set of device keys
+ */
+ Collection<DeviceKey> getDeviceKeys();
+
+ /**
+ * Returns the device key matching a device key identifier.
+ *
+ * @param deviceKeyId device key unique identifier
+ * @return device key
+ */
+ DeviceKey getDeviceKey(DeviceKeyId deviceKeyId);
+}
diff --git a/core/api/src/main/java/org/onosproject/net/key/DeviceKeyStoreDelegate.java b/core/api/src/main/java/org/onosproject/net/key/DeviceKeyStoreDelegate.java
new file mode 100644
index 0000000..e78912b
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/key/DeviceKeyStoreDelegate.java
@@ -0,0 +1,27 @@
+/*
+ * 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.net.key;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.store.StoreDelegate;
+
+/**
+ * Device key store delegate abstraction.
+ */
+@Beta
+public interface DeviceKeyStoreDelegate extends StoreDelegate<DeviceKeyEvent> {
+}
diff --git a/core/api/src/main/java/org/onosproject/net/key/UsernamePassword.java b/core/api/src/main/java/org/onosproject/net/key/UsernamePassword.java
new file mode 100644
index 0000000..d496fc35
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/key/UsernamePassword.java
@@ -0,0 +1,65 @@
+/*
+ * 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.net.key;
+
+/**
+ * Representation of a username and password.
+ */
+public final class UsernamePassword extends DeviceKey {
+ private final String username;
+ private final String password;
+
+ /**
+ * Private constructor for a username and password.
+ *
+ * @param username user's name
+ * @param password user's password
+ */
+ private UsernamePassword(String username, String password) {
+ this.username = username;
+ this.password = password;
+ }
+
+ /**
+ * Static method to construct a username / password.
+ *
+ * @param username user's name
+ * @param password user's password
+ * @return username and password
+ */
+ static UsernamePassword usernamePassword(String username, String password) {
+ return new UsernamePassword(username, password);
+ }
+
+ /**
+ * Returns the username.
+ *
+ * @return username
+ */
+ public String username() {
+ return username;
+ }
+
+ /**
+ * Returns the password.
+ *
+ * @return password
+ */
+ public String password() {
+ return password;
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/key/package-info.java b/core/api/src/main/java/org/onosproject/net/key/package-info.java
new file mode 100644
index 0000000..0e88963
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/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.net.key;
\ No newline at end of file