Implementing net config subsystem and revising its interfaces.

Added a few basic configs for device, host and links.

Added initial REST API.

Added CLI.

Tests remain to be added.

Change-Id: Ic7bba4b5ad7d553c51d69f6459b3bff146970323
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/AllowedEntityConfig.java b/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/AllowedEntityConfig.java
new file mode 100644
index 0000000..6651ad4
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/AllowedEntityConfig.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2015 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.config.basics;
+
+import org.onosproject.incubator.net.config.Config;
+
+/**
+ * Base abstraction for network entities for which admission into control
+ * domain can be selectively configured, e.g. devices, end-stations, links
+ */
+public abstract class AllowedEntityConfig<S> extends Config<S> {
+
+    private static final String ALLOWED = "allowed";
+
+    /**
+     * Indicates whether the element is allowed for admission into the control
+     * domain.
+     *
+     * @return true if element is allowed
+     */
+    public boolean isAllowed() {
+        return get(ALLOWED, true);
+    }
+
+    /**
+     * Specifies whether the element is to be allowed for admission into the
+     * control domain.
+     *
+     * @param isAllowed true to allow; false to forbid; null to clear
+     * @return self
+     */
+    public AllowedEntityConfig isAllowed(Boolean isAllowed) {
+        return (AllowedEntityConfig) setOrClear(ALLOWED, isAllowed);
+    }
+
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/BasicDeviceConfig.java b/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/BasicDeviceConfig.java
new file mode 100644
index 0000000..c3eb099
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/BasicDeviceConfig.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2015 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.config.basics;
+
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+
+/**
+ * Basic configuration for network infrastructure devices.
+ */
+public class BasicDeviceConfig extends BasicElementConfig<DeviceId> {
+
+    public static final String TYPE = "type";
+    public static final String DRIVER = "driver";
+
+    /**
+     * Returns the device type.
+     *
+     * @return device type override
+     */
+    public Device.Type type() {
+        return get(TYPE, Device.Type.SWITCH, Device.Type.class);
+    }
+
+    /**
+     * Sets the device type.
+     *
+     * @param type device type override
+     * @return self
+     */
+    public BasicDeviceConfig type(Device.Type type) {
+        return (BasicDeviceConfig) setOrClear(TYPE, type);
+    }
+
+    /**
+     * Returns the device driver name.
+     *
+     * @return driver name of null if not set
+     */
+    public String driver() {
+        return get(DRIVER, subject.toString());
+    }
+
+    /**
+     * Sets the driver name.
+     *
+     * @param driverName new driver name; null to clear
+     * @return self
+     */
+    public BasicElementConfig driver(String driverName) {
+        return (BasicElementConfig) setOrClear(DRIVER, driverName);
+    }
+
+    // TODO: device port meta-data to be configured via BasicPortsConfig
+    // TODO: device credentials/keys
+
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/BasicElementConfig.java b/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/BasicElementConfig.java
new file mode 100644
index 0000000..39f767a
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/BasicElementConfig.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2015 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.config.basics;
+
+/**
+ * Basic configuration for network elements, e.g. devices, hosts. Such elements
+ * can have a friendly name, geo-coordinates, logical rack coordinates and
+ * an owner entity.
+ */
+public abstract class BasicElementConfig<S> extends AllowedEntityConfig<S> {
+
+    public static final String NAME = "name";
+
+    public static final String LATITUDE = "latitude";
+    public static final String LONGITUDE = "longitude";
+
+    public static final String RACK_ADDRESS = "rackAddress";
+    public static final String OWNER = "owner";
+
+    /**
+     * Returns friendly label for the element.
+     *
+     * @return friendly label or element id itself if not set
+     */
+    public String name() {
+        return get(NAME, subject.toString());
+    }
+
+    /**
+     * Sets friendly label for the element.
+     *
+     * @param name new friendly label; null to clear
+     * @return self
+     */
+    public BasicElementConfig name(String name) {
+        return (BasicElementConfig) setOrClear(NAME, name);
+    }
+
+    /**
+     * Returns element latitude.
+     *
+     * @return element latitude; -1 if not set
+     */
+    public double latitude() {
+        return get(LATITUDE, -1.0);
+    }
+
+    /**
+     * Sets the element latitude.
+     *
+     * @param latitude new latitude; null to clear
+     * @return self
+     */
+    public BasicElementConfig latitude(Double latitude) {
+        return (BasicElementConfig) setOrClear(LATITUDE, latitude);
+    }
+
+    /**
+     * Returns element latitude.
+     *
+     * @return element latitude; -1 if not set
+     */
+    public double longitude() {
+        return get(LONGITUDE, -1.0);
+    }
+
+    /**
+     * Sets the element longitude.
+     *
+     * @param longitude new longitude; null to clear
+     * @return self
+     */
+    public BasicElementConfig longitude(Double longitude) {
+        return (BasicElementConfig) setOrClear(LONGITUDE, longitude);
+    }
+
+    /**
+     * Returns the element rack address.
+     *
+     * @return rack address; null if not set
+     */
+    public String rackAddress() {
+        return get(RACK_ADDRESS, null);
+    }
+
+    /**
+     * Sets element rack address.
+     *
+     * @param address new rack address; null to clear
+     * @return self
+     */
+    public BasicElementConfig rackAddress(String address) {
+        return (BasicElementConfig) setOrClear(RACK_ADDRESS, address);
+    }
+
+    /**
+     * Returns owner of the element.
+     *
+     * @return owner or null if not set
+     */
+    public String owner() {
+        return get(OWNER, null);
+    }
+
+    /**
+     * Sets the owner of the element.
+     *
+     * @param owner new owner; null to clear
+     * @return self
+     */
+    public BasicElementConfig owner(String owner) {
+        return (BasicElementConfig) setOrClear(OWNER, owner);
+    }
+
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/BasicHostConfig.java b/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/BasicHostConfig.java
new file mode 100644
index 0000000..2f4b799
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/BasicHostConfig.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2015 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.config.basics;
+
+import org.onosproject.net.HostId;
+
+/**
+ * Basic configuration for network end-station hosts.
+ */
+public class BasicHostConfig extends BasicElementConfig<HostId> {
+
+    // TODO: determine what aspects of configuration to add for hosts
+
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/BasicLinkConfig.java b/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/BasicLinkConfig.java
new file mode 100644
index 0000000..c881a7b
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/BasicLinkConfig.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2015 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.config.basics;
+
+import org.onosproject.net.Link;
+import org.onosproject.net.LinkKey;
+
+import java.time.Duration;
+
+/**
+ * Basic configuration for network infrastructure link.
+ */
+public class BasicLinkConfig extends AllowedEntityConfig<LinkKey> {
+
+    public static final String TYPE = "type";
+    public static final String LATENCY = "latency";
+    public static final String BANDWIDTH = "bandwidth";
+
+    /**
+     * Returns the link type.
+     *
+     * @return link type override
+     */
+    public Link.Type type() {
+        return get(TYPE, Link.Type.DIRECT, Link.Type.class);
+    }
+
+    /**
+     * Sets the link type.
+     *
+     * @param type link type override
+     * @return self
+     */
+    public BasicLinkConfig type(Link.Type type) {
+        return (BasicLinkConfig) setOrClear(TYPE, type);
+    }
+
+    /**
+     * Returns link latency in terms of nanos.
+     *
+     * @return link latency; -1 if not set
+     */
+    public Duration latency() {
+        return Duration.ofNanos(get(LATENCY, -1));
+    }
+
+    /**
+     * Sets the link latency.
+     *
+     * @param latency new latency; null to clear
+     * @return self
+     */
+    public BasicElementConfig latency(Duration latency) {
+        Long nanos = latency == null ? null : latency.toNanos();
+        return (BasicElementConfig) setOrClear(LATENCY, nanos);
+    }
+
+    /**
+     * Returns link bandwidth in terms of Mbps.
+     *
+     * @return link bandwidth; -1 if not set
+     */
+    public long bandwidth() {
+        return get(BANDWIDTH, -1);
+    }
+
+    /**
+     * Sets the link bandwidth.
+     *
+     * @param bandwidth new bandwidth; null to clear
+     * @return self
+     */
+    public BasicElementConfig bandwidth(Long bandwidth) {
+        return (BasicElementConfig) setOrClear(BANDWIDTH, bandwidth);
+    }
+
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/SubjectFactories.java b/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/SubjectFactories.java
new file mode 100644
index 0000000..257bd27
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/SubjectFactories.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2015 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.config.basics;
+
+import org.onosproject.core.ApplicationId;
+import org.onosproject.incubator.net.config.SubjectFactory;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.HostId;
+import org.onosproject.net.LinkKey;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Set of subject factories for potential configuration subjects.
+ */
+public final class SubjectFactories {
+
+    // Construction forbidden
+    private SubjectFactories() {
+    }
+
+    public static final SubjectFactory<ApplicationId> APP_SUBJECT_FACTORY =
+            new SubjectFactory<ApplicationId>(ApplicationId.class, "apps") {
+                @Override
+                public ApplicationId createSubject(String key) {
+                    // FIXME: figure out how to safely create sanctioned app ids
+                    return null;
+                }
+            };
+
+    public static final SubjectFactory<DeviceId> DEVICE_SUBJECT_FACTORY =
+            new SubjectFactory<DeviceId>(DeviceId.class, "devices") {
+                @Override
+                public DeviceId createSubject(String key) {
+                    return DeviceId.deviceId(key);
+                }
+            };
+
+    public static final SubjectFactory<HostId> HOST_SUBJECT_FACTORY =
+            new SubjectFactory<HostId>(HostId.class, "hosts") {
+                @Override
+                public HostId createSubject(String key) {
+                    return HostId.hostId(key);
+                }
+            };
+
+    public static final SubjectFactory<LinkKey> LINK_SUBJECT_FACTORY =
+            new SubjectFactory<LinkKey>(LinkKey.class, "links") {
+                @Override
+                public LinkKey createSubject(String key) {
+                    String[] cps = key.split("-");
+                    checkArgument(cps.length == 2, "Incorrect link key format: %s", key);
+                    return LinkKey.linkKey(ConnectPoint.deviceConnectPoint(cps[0]),
+                                           ConnectPoint.deviceConnectPoint(cps[1]));
+                }
+            };
+
+}