Split CPMan into api and app submodules

Change-Id: Iacddea67ea0f7189ab918cf9e2a7a414100fc503
diff --git a/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlLoad.java b/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlLoad.java
new file mode 100644
index 0000000..b783aa6
--- /dev/null
+++ b/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlLoad.java
@@ -0,0 +1,42 @@
+/*
+ * 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.cpman;
+
+import org.onosproject.net.statistic.Load;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Data repository for control plane load information.
+ */
+public interface ControlLoad extends Load {
+
+    /**
+     * Obtains the average of the specified time duration.
+     *
+     * @param duration time duration
+     * @param unit     time unit
+     * @return average control plane metric value
+     */
+    long average(int duration, TimeUnit unit);
+
+    /**
+     * Obtains the average of all time duration.
+     *
+     * @return average control plane metric value
+     */
+    long average();
+}
diff --git a/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlMetric.java b/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlMetric.java
new file mode 100644
index 0000000..fc1640f
--- /dev/null
+++ b/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlMetric.java
@@ -0,0 +1,38 @@
+/*
+ * 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.cpman;
+
+/**
+ * Include various control plane metrics.
+ */
+public class ControlMetric {
+
+    private final ControlMetricType metricType;
+    private final MetricValue metricValue;
+
+    public ControlMetric(ControlMetricType metricType, MetricValue metricValue) {
+        this.metricType = metricType;
+        this.metricValue = metricValue;
+    }
+
+    ControlMetricType metricType() {
+        return metricType;
+    }
+
+    MetricValue metricValue() {
+        return metricValue;
+    }
+}
diff --git a/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlMetricType.java b/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlMetricType.java
new file mode 100644
index 0000000..a5dc81c
--- /dev/null
+++ b/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlMetricType.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2015-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.cpman;
+
+/**
+ * A set of metric type used in control plane.
+ */
+public enum ControlMetricType {
+
+    /* Mapped to PACKET-IN message of OpenFlow. */
+    INBOUND_PACKET,
+
+    /* Mapped to PACKET-OUT message of OpenFlow. */
+    OUTBOUND_PACKET,
+
+    /* Mapped to FLOW-MOD message of OpenFlow. */
+    FLOW_MOD_PACKET,
+
+    /* Mapped to FLOW-REMOVED message of OpenFlow. */
+    FLOW_REMOVED_PACKET,
+
+    /* Mapped to STATS-REQUEST message of OpenFlow. */
+    REQUEST_PACKET,
+
+    /* Mapped to STATS-REPLY message of OpenFlow. */
+    REPLY_PACKET,
+
+    /* Number of CPU cores. */
+    NUM_OF_CORES,
+
+    /* Number of CPUs. **/
+    NUM_OF_CPUS,
+
+    /* CPU Speed. **/
+    CPU_SPEED,
+
+    /* CPU Load. **/
+    CPU_LOAD,
+
+    /* Total Amount of CPU Up Time. **/
+    TOTAL_CPU_TIME,
+
+    /* System CPU Up Time. **/
+    SYS_CPU_TIME,
+
+    /* User CPU Up Time. **/
+    USER_CPU_TIME,
+
+    /* CPU Idle Time. **/
+    CPU_IDLE_TIME,
+
+    /* Percentage of Used Memory Amount. */
+    MEMORY_USED_PERCENTAGE,
+
+    /* Percentage of Free Memory Amount. **/
+    MEMORY_FREE_PERCENTAGE,
+
+    /* Used Memory Amount. **/
+    MEMORY_USED,
+
+    /* Free Memory Amount. **/
+    MEMORY_FREE,
+
+    /* Total Amount of Memory. **/
+    MEMORY_TOTAL,
+
+    /* Disk Read Bytes. **/
+    DISK_READ_BYTES,
+
+    /* Disk Write Bytes. **/
+    DISK_WRITE_BYTES,
+
+    /* Network Incoming Bytes. **/
+    NW_INCOMING_BYTES,
+
+    /* Network Outgoing Bytes. **/
+    NW_OUTGOING_BYTES,
+
+    /* Network Incoming Packets. **/
+    NW_INCOMING_PACKETS,
+
+    /* Network Outgoing Packets. **/
+    NW_OUTGOING_PACKETS
+}
diff --git a/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlPlaneMonitorService.java b/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlPlaneMonitorService.java
new file mode 100644
index 0000000..d4e6bc5
--- /dev/null
+++ b/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlPlaneMonitorService.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2015-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.cpman;
+
+import org.onosproject.cluster.NodeId;
+import org.onosproject.net.DeviceId;
+
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Control Plane Statistics Service Interface.
+ */
+public interface ControlPlaneMonitorService {
+
+    /**
+     * Adds a new control metric value with a certain update interval.
+     *
+     * @param controlMetric  control plane metric (e.g., control message rate, cpu, memory, etc.)
+     * @param updateInterval value update interval (time unit will be in minute)
+     * @param deviceId       {@link org.onosproject.net.DeviceId}
+     */
+    void updateMetric(ControlMetric controlMetric, Integer updateInterval, Optional<DeviceId> deviceId);
+
+    /**
+     * Adds a new control metric value with a certain update interval.
+     *
+     * @param controlMetric     control plane metric (e.g., disk and network metrics)
+     * @param updateInterval    value update interval (time unit will be in minute)
+     * @param resourceName      resource name
+     */
+    void updateMetric(ControlMetric controlMetric, Integer updateInterval, String resourceName);
+
+    /**
+     * Obtains the control plane load of a specific device.
+     *
+     * @param nodeId   node id {@link org.onosproject.cluster.NodeId}
+     * @param type     control metric type
+     * @param deviceId device id {@link org.onosproject.net.DeviceId}
+     * @return control plane load
+     */
+    ControlLoad getLoad(NodeId nodeId, ControlMetricType type, Optional<DeviceId> deviceId);
+
+    /**
+     * Obtains the control plane load of a specific device with a specific time duration.
+     *
+     * @param nodeId   node id {@link org.onosproject.cluster.NodeId}
+     * @param type     control metric type
+     * @param duration time duration
+     * @param unit     time unit
+     * @param deviceId device id {@link org.onosproject.net.Device}
+     * @return control plane load
+     */
+    ControlLoad getLoad(NodeId nodeId, ControlMetricType type, Optional<DeviceId> deviceId,
+                        int duration, TimeUnit unit);
+}
\ No newline at end of file
diff --git a/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlPlaneService.java b/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlPlaneService.java
new file mode 100644
index 0000000..663c2b7
--- /dev/null
+++ b/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlPlaneService.java
@@ -0,0 +1,22 @@
+/*
+ * 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.cpman;
+
+/**
+ * Control Plane Service interface.
+ */
+public interface ControlPlaneService {
+}
diff --git a/apps/cpman/api/src/main/java/org/onosproject/cpman/MetricValue.java b/apps/cpman/api/src/main/java/org/onosproject/cpman/MetricValue.java
new file mode 100644
index 0000000..c853ef1
--- /dev/null
+++ b/apps/cpman/api/src/main/java/org/onosproject/cpman/MetricValue.java
@@ -0,0 +1,153 @@
+/*
+ * 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.cpman;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Primitive Metric Value.
+ */
+public final class MetricValue {
+
+    private final long rate;
+    private final long load;
+    private final long count;
+
+    /**
+     * Constructor.
+     *
+     * @param rate rate
+     * @param load load
+     * @param count count
+     */
+    private MetricValue(long rate, long load, long count) {
+        this.rate = rate;
+        this.load = load;
+        this.count = count;
+    }
+
+    /**
+     * Returns rate value.
+     *
+     * @return rate
+     */
+    public long getRate() {
+        return rate;
+    }
+
+    /**
+     * Returns load value.
+     *
+     * @return load
+     */
+    public long getLoad() {
+        return load;
+    }
+
+    /**
+     * Returns count value.
+     *
+     * @return cound
+     */
+    public long getCount() {
+        return count;
+    }
+
+    /**
+     * MetricValue builder class.
+     */
+    public static final class Builder {
+        private long rate;
+        private long load;
+        private long count;
+
+        /**
+         * Sets rate value.
+         *
+         * @param rate rate value
+         * @return Builder object
+         */
+        public Builder rate(long rate) {
+            this.rate = rate;
+            return this;
+        }
+
+        /**
+         * Sets load value.
+         *
+         * @param load load value
+         * @return Builder object
+         */
+        public Builder load(long load) {
+            this.load = load;
+            return this;
+        }
+
+        /**
+         * Sets count value.
+         *
+         * @param count count value
+         * @return Builder object
+         */
+        public Builder count(long count) {
+            this.count = count;
+            return this;
+        }
+
+        /**
+         * Builds a MetricValue object.
+         *
+         * @return MetricValue object
+         */
+        public MetricValue add() {
+            return new MetricValue(rate, load, count);
+        }
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof MetricValue) {
+            MetricValue other = (MetricValue) obj;
+            if (this.rate == other.rate &&
+                    this.load == other.load &&
+                    this.count == other.count) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 1004;
+        int result = super.hashCode();
+        result = prime * result + (int) this.rate;
+        result = prime * result + (int) this.load;
+        result = prime * result + (int) this.count;
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(getClass())
+                .add("rate", Long.toHexString(rate))
+                .add("load", Long.toHexString(load))
+                .add("count", Long.toHexString(count)).toString();
+    }
+}
diff --git a/apps/cpman/api/src/main/java/org/onosproject/cpman/package-info.java b/apps/cpman/api/src/main/java/org/onosproject/cpman/package-info.java
new file mode 100644
index 0000000..6ea6835
--- /dev/null
+++ b/apps/cpman/api/src/main/java/org/onosproject/cpman/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * An application that manages the control plane.
+ */
+package org.onosproject.cpman;
\ No newline at end of file