ONOS-2488 Finished moving network config stuff out of the incubator area.

Change-Id: I62c511938fdf8f33def99ce43f0d4417b4ba1918
diff --git a/core/api/src/main/java/org/onosproject/net/config/basics/AllowedEntityConfig.java b/core/api/src/main/java/org/onosproject/net/config/basics/AllowedEntityConfig.java
new file mode 100644
index 0000000..6e6663c
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/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.net.config.basics;
+
+import org.onosproject.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/core/api/src/main/java/org/onosproject/net/config/basics/BasicDeviceConfig.java b/core/api/src/main/java/org/onosproject/net/config/basics/BasicDeviceConfig.java
new file mode 100644
index 0000000..fd8bfa3
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/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.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/core/api/src/main/java/org/onosproject/net/config/basics/BasicElementConfig.java b/core/api/src/main/java/org/onosproject/net/config/basics/BasicElementConfig.java
new file mode 100644
index 0000000..7b3248c
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/config/basics/BasicElementConfig.java
@@ -0,0 +1,130 @@
+/*
+ * 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.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";
+
+    protected static final double DEFAULT_COORD = -1.0;
+
+    /**
+     * 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, DEFAULT_COORD);
+    }
+
+    /**
+     * 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, DEFAULT_COORD);
+    }
+
+    /**
+     * 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/core/api/src/main/java/org/onosproject/net/config/basics/BasicHostConfig.java b/core/api/src/main/java/org/onosproject/net/config/basics/BasicHostConfig.java
new file mode 100644
index 0000000..2fe2b2c
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/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.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/core/api/src/main/java/org/onosproject/net/config/basics/BasicLinkConfig.java b/core/api/src/main/java/org/onosproject/net/config/basics/BasicLinkConfig.java
new file mode 100644
index 0000000..b6068ee
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/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.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 BasicLinkConfig latency(Duration latency) {
+        Long nanos = latency == null ? null : latency.toNanos();
+        return (BasicLinkConfig) 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 BasicLinkConfig bandwidth(Long bandwidth) {
+        return (BasicLinkConfig) setOrClear(BANDWIDTH, bandwidth);
+    }
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/config/basics/OpticalPortConfig.java b/core/api/src/main/java/org/onosproject/net/config/basics/OpticalPortConfig.java
new file mode 100644
index 0000000..4478ead
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/config/basics/OpticalPortConfig.java
@@ -0,0 +1,147 @@
+package org.onosproject.net.config.basics;
+
+import java.util.Optional;
+
+import org.onosproject.net.config.Config;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Port;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+
+/**
+ * Configurations for an optical port on a device.
+ */
+public class OpticalPortConfig extends Config<ConnectPoint> {
+    // optical type {OMS, OCH, ODUClt, fiber}
+    public static final String TYPE = "type";
+
+    // port name. "name" is the alphanumeric name of the port, but "port" refers
+    // to the port number used as a name string (i.e., for ports without
+    // alphanumeric names).
+    public static final String NAME = "name";
+    public static final String PORT = "port";
+    public static final String STATIC_PORT = "staticPort";
+    public static final String STATIC_LAMBDA = "staticLambda";
+
+    /**
+     * Returns the Enum value representing the type of port.
+     *
+     * @return the port type, or null if invalid or unset
+     */
+    public Port.Type type() {
+        JsonNode type = node.path(TYPE);
+        if (type.isMissingNode()) {
+            return null;
+        }
+        return Port.Type.valueOf(type.asText());
+    }
+
+    /**
+     * Returns the port name associated with this port configuration. The Name
+     * is an alphanumeric string.
+     *
+     * @return the name of this port, else, an empty string
+     */
+    public String name() {
+        return getStringValue(NAME);
+    }
+
+    /**
+     * Returns a stringified representation of the port number, configured in
+     * some port types without an alphanumeric name as the port name.
+     *
+     * @return A string representation of the port number
+     */
+    public String numberName() {
+        return getStringValue(PORT);
+    }
+
+    /**
+     * Returns the string-representation of name of the output port. This is
+     * usually an OMS port for an OCH input ports, or an OCH port for ODU input
+     * ports.
+     *
+     * @return the name of this port, else, an empty string
+     */
+    public String staticPort() {
+        return getStringValue(STATIC_PORT);
+    }
+
+    private String getStringValue(String field) {
+        JsonNode name = node.path(field);
+        return name.isMissingNode() ? "" : name.asText();
+    }
+
+    /**
+     * Returns the output lambda configured for this port. The lambda value is
+     * expressed as a frequency value.
+     *
+     * @return an Optional that may contain a frequency value.
+     */
+    public Optional<Long> staticLambda() {
+        JsonNode sl = node.path(STATIC_LAMBDA);
+        if (sl.isMissingNode()) {
+            return Optional.empty();
+        }
+        return Optional.of(sl.asLong());
+    }
+
+    /**
+     * Sets the port type, or updates it if it's already set. A null argument removes
+     * this field.
+     *
+     * @param type the port type
+     * @return this OpticalPortConfig instance
+     */
+    public OpticalPortConfig portType(Port.Type type) {
+        // if unspecified, ideally fall back on FIBER or PACKET.
+        String pt = (type == null) ? null : type.toString();
+        return (OpticalPortConfig) setOrClear(TYPE, pt);
+    }
+
+    /**
+     * Sets the port name, or updates it if already set. A null argument removes
+     * this field.
+     *
+     * @param name the port's name
+     * @return this OpticalPortConfig instance
+     */
+    public OpticalPortConfig portName(String name) {
+        return (OpticalPortConfig) setOrClear(NAME, name);
+    }
+
+    /**
+     * Sets the port name from port number, or updates it if already set. A null
+     * argument removes this field.
+     *
+     * @param name the port number, to be used as name
+     * @return this OpticalPortConfig instance
+     */
+    public OpticalPortConfig portNumberName(Long name) {
+        return (OpticalPortConfig) setOrClear(PORT, name);
+    }
+
+    /**
+     * Sets the output port name, or updates it if already set. A null argument
+     * removes this field.
+     *
+     * @param name the output port's name
+     * @return this OpticalPortConfig instance
+     */
+    public OpticalPortConfig staticPort(String name) {
+        return (OpticalPortConfig) setOrClear(STATIC_PORT, name);
+    }
+
+    /**
+     * Sets the output lambda index, or updates it if already set. A null argument
+     * removes this field.
+     *
+     * @param index the output lambda
+     * @return this OpticalPortConfig instance
+     */
+    public OpticalPortConfig staticLambda(Long index) {
+        return (OpticalPortConfig) setOrClear(STATIC_LAMBDA, index);
+    }
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/config/basics/SubjectFactories.java b/core/api/src/main/java/org/onosproject/net/config/basics/SubjectFactories.java
new file mode 100644
index 0000000..884f2e2
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/config/basics/SubjectFactories.java
@@ -0,0 +1,93 @@
+/*
+ * 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.net.config.basics;
+
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.HostId;
+import org.onosproject.net.LinkKey;
+import org.onosproject.net.config.SubjectFactory;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Set of subject factories for potential configuration subjects.
+ */
+public final class SubjectFactories {
+
+    // Construction forbidden
+    private SubjectFactories() {
+    }
+
+    // Required for resolving application identifiers
+    private static CoreService coreService;
+
+    public static final SubjectFactory<ApplicationId> APP_SUBJECT_FACTORY =
+            new SubjectFactory<ApplicationId>(ApplicationId.class, "apps") {
+                @Override
+                public ApplicationId createSubject(String key) {
+                    return coreService.registerApplication(key);
+                }
+            };
+
+    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<ConnectPoint> CONNECT_POINT_SUBJECT_FACTORY =
+            new SubjectFactory<ConnectPoint>(ConnectPoint.class, "ports") {
+                @Override
+                public ConnectPoint createSubject(String key) {
+                    return ConnectPoint.deviceConnectPoint(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]));
+                }
+            };
+
+    /**
+     * Provides reference to the core service, which is required for
+     * application subject factory.
+     *
+     * @param service core service reference
+     */
+    public static void setCoreService(CoreService service) {
+        coreService = service;
+    }
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/config/basics/package-info.java b/core/api/src/main/java/org/onosproject/net/config/basics/package-info.java
new file mode 100644
index 0000000..4d0f27e
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/config/basics/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Various basic builtin network configurations.
+ */
+package org.onosproject.net.config.basics;
\ No newline at end of file