New SB driver for commodity servers
Monitoring enhanced with timing stats
Copy constructors for Rx filter values
Driver is updated to provide port statistics to the REST SB controller
Drastic changes to make the driver ONOS compliant. NIC statistics have become 100% compliant with PortStatistics
CPU statistics also compatible with the ONOS approach
Separated timing statistics
Style fix
NIC is included
Proper representation of a CPU. Also some refactoring
Removed unused import and added important comment
CPU vendor has become a class and the servers are now reporting more detailed CPU info
Fixed port statistics' counters for servers
Various fixes that lead to more stable behavior
Additional checks to avoid null pointer exception
Fixed potential casting issues
Updated pom with affiliation information
Updated pom with URL
Bumped rivers to version 1.12
Updated BUCK for version 1.12
NIC speed has become long and NICs are retrieved in a sorted fashion
Fixed warning
Timing statistics contain autoscale measurements
Fixed CPU vendor ID for Intel
Bumped Metron's drivers to version 1.13. Fixed origin and URL in pom.xml
Updated RestServerSBDevice to comply with the extended ONOS RestSBDevice
Total refactoring of the driver to become more generic (NFV -> Server).
Also properly separated the statistics API from implementation.
Refactored server driver and bug fix that occured when port statistics
were called before a device is properly discovered.
Statistics API and implementation are grouped again.
Removed unnecessary stuff from pom and BUCK files
Fixed checkstyle warning
Added short readme to pom.xml
New ControllerConfig behavior added
This patch adds an new ControllerConfig behavior to the server
driver, allowing external applications to get, set, and remove
a server's controller configuration.
Common functions and variables are also shared between the
two basic modules of the driver.
Fixed checkstyle warnings
Refactored controller configuration module
Consistent values returned by the methods of the driver
Unit tests for ServerControllerConfig behavior
Fixed preconditions for NULL and arguments
Improved documentation
Updated pom and BUCK
Addressed comments about sharing some more methods
Refactored the Common.java to become a base class
that extends AbstractHandlerBehaviour and can share
a unique instance of the RestSBController with child
classes. Also, after the removal of some deprecated
methods of the HTTP SB controller, I had to perform
some compatibility changes in the respective methods
of this driver.
The only problem is that my tests are now broken(??)
and I had to remove their code for now until I fix
the issues.
Expose some members and methods of BasicDriver
Renamed BasicDriver to BasicServerDriver
Change-Id: I0126adcb714f7e32695d546cf40a9de342722083
Signed-off-by: Georgios Katsikas <katsikas.gp@gmail.com>
diff --git a/drivers/server/BUCK b/drivers/server/BUCK
new file mode 100644
index 0000000..9be0e49
--- /dev/null
+++ b/drivers/server/BUCK
@@ -0,0 +1,39 @@
+COMPILE_DEPS = [
+ '//lib:CORE_DEPS',
+ '//lib:JACKSON',
+ '//lib:javax.ws.rs-api',
+ '//incubator/api:onos-incubator-api',
+ '//utils/rest:onlab-rest',
+ '//protocols/rest/api:onos-protocols-rest-api',
+]
+
+TEST_DEPS = [
+ '//lib:TEST_ADAPTERS',
+ '//core/api:onos-api-tests',
+]
+
+BUNDLES = [
+ ':onos-drivers-server',
+]
+
+REQUIRED_APPS = [
+ 'org.onosproject.restsb',
+]
+
+osgi_jar_with_tests (
+ deps = COMPILE_DEPS,
+ test_deps = TEST_DEPS,
+ resources_root = 'src/main/resources',
+ resources = glob(['src/main/resources/**']),
+)
+
+onos_app (
+ app_name = 'org.onosproject.drivers.server',
+ title = 'Server Device Drivers',
+ category = 'Drivers',
+ origin = 'KTH Royal Institute of Technology & RISE SICS',
+ url = 'https://github.com/gkatsikas/onos/tree/metron-driver',
+ description = 'ONOS southbound drivers for commodity servers',
+ included_bundles = BUNDLES,
+ required_apps = REQUIRED_APPS,
+)
diff --git a/drivers/server/features.xml b/drivers/server/features.xml
new file mode 100644
index 0000000..ba45275
--- /dev/null
+++ b/drivers/server/features.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ ~ Copyright 2017-present Open Networking Foundation
+ ~
+ ~ 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.
+ -->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
+ <feature name="${project.artifactId}" version="${project.version}"
+ description="${project.description}">
+ <feature>onos-api</feature>
+ <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
+ <bundle>mvn:${project.groupId}/onos-restsb-api/${project.version}</bundle>
+ </feature>
+</features>
diff --git a/drivers/server/pom.xml b/drivers/server/pom.xml
new file mode 100644
index 0000000..8f81931
--- /dev/null
+++ b/drivers/server/pom.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-present Open Networking Foundation
+ ~
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>onos-drivers-general</artifactId>
+ <groupId>org.onosproject</groupId>
+ <version>1.13.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>onos-drivers-server</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>ONOS southbound drivers for commodity servers</description>
+
+ <properties>
+ <onos.app.name>org.onosproject.drivers.server</onos.app.name>
+ <onos.app.origin>KTH Royal Institute of Technology & RISE SICS</onos.app.origin>
+ <onos.app.category>Drivers</onos.app.category>
+ <onos.app.title>Server Device Drivers</onos.app.title>
+ <onos.app.url>https://github.com/gkatsikas/onos/tree/metron-driver</onos.app.url>
+ <onos.app.readme>
+ Allows ONOS to manage CPU and network interface cards' (NICs)
+ resources on commodity servers.
+ </onos.app.readme>
+ <onos.app.requires>
+ org.onosproject.restsb
+ </onos.app.requires>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-restsb-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/BasicServerDriver.java b/drivers/server/src/main/java/org/onosproject/drivers/server/BasicServerDriver.java
new file mode 100644
index 0000000..e270b43
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/BasicServerDriver.java
@@ -0,0 +1,183 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.drivers.server;
+
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.protocol.rest.RestSBController;
+
+import org.onlab.osgi.ServiceNotFoundException;
+
+import org.slf4j.Logger;
+import com.fasterxml.jackson.databind.JsonNode;
+
+import java.util.EnumSet;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import static org.slf4j.LoggerFactory.getLogger;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * The basic functionality of the server driver.
+ */
+public class BasicServerDriver extends AbstractHandlerBehaviour {
+
+ private final Logger log = getLogger(getClass());
+
+ /**
+ * Resource endpoints of the server agent (REST server-side).
+ */
+ public static final MediaType JSON = MediaType.valueOf(MediaType.APPLICATION_JSON);
+ protected static final String ROOT_URL = "";
+ public static final String BASE_URL = ROOT_URL + "/metron";
+
+ /**
+ * Successful HTTP status codes.
+ */
+ private static final int STATUS_OK = Response.Status.OK.getStatusCode();
+ private static final int STATUS_CREATED = Response.Status.CREATED.getStatusCode();
+ private static final int STATUS_ACCEPTED = Response.Status.ACCEPTED.getStatusCode();
+
+ /**
+ * Messages for error handlers.
+ */
+ protected static final String MASTERSHIP_NULL = "Mastership service is null";
+ protected static final String CONTROLLER_NULL = "RestSB controller is null";
+ protected static final String DEVICE_ID_NULL = "Device ID cannot be null";
+ protected static final String HANDLER_NULL = "Handler cannot be null";
+ protected static final String DEVICE_NULL = "Device cannot be null";
+
+ /**
+ * A unique controller that handles the REST-based communication.
+ */
+ protected static RestSBController controller = null;
+ protected static DriverHandler handler = null;
+
+ public BasicServerDriver() {};
+
+ /**
+ * Initialize the REST SB controller (if not already).
+ * Creates a handler and a controller only once, and
+ * then re-uses these objects.
+ *
+ * @throws ServiceNotFoundException when either the handler
+ * or the controller cannot be retrieved.
+ */
+ private void init() {
+ // Already done
+ if ((handler != null) && (controller != null)) {
+ return;
+ }
+
+ try {
+ handler = handler();
+ checkNotNull(handler, HANDLER_NULL);
+ controller = handler.get(RestSBController.class);
+ checkNotNull(controller, CONTROLLER_NULL);
+ } catch (ServiceNotFoundException e) {
+ throw e;
+ }
+ }
+
+ /**
+ * Retrieve an instance of the REST SB controller.
+ * Method init will only be called the first time
+ * this method (or getHandler) is invoked.
+ *
+ * @return RestSBController instance
+ */
+ protected RestSBController getController() {
+ if (controller == null) {
+ init();
+ }
+
+ return controller;
+ }
+
+ /**
+ * Retrieve an instance of the driver handler.
+ * Method init will only be called the first time
+ * this method (or getController) is invoked.
+ *
+ * @return DriverHandler instance
+ */
+ protected DriverHandler getHandler() {
+ if (handler == null) {
+ init();
+ }
+
+ return handler;
+ }
+
+ /**
+ * Return all the enumeration's types in a space-separated string.
+ *
+ * @param <E> the expected class of the enum
+ * @param enumType the enum class to get its types
+ * @return String with all enumeration types
+ */
+ public static <E extends Enum<E>> String enumTypesToString(
+ Class<E> enumType) {
+ String allTypes = "";
+ for (E en : EnumSet.allOf(enumType)) {
+ allTypes += en.toString() + " ";
+ }
+
+ return allTypes.trim();
+ }
+
+ /**
+ * Return a string value after reading the input
+ * attribute from the input JSON node.
+ *
+ * @param jsonNode JSON node to read from
+ * @param attribute to lookup in the JSON node
+ * @return string value mapped to the attribute
+ */
+ public static String get(JsonNode jsonNode, String attribute) {
+ if (jsonNode == null || (attribute == null || attribute.isEmpty())) {
+ return null;
+ }
+
+ String result = "";
+
+ try {
+ result = jsonNode.get(attribute).asText();
+ } catch (Exception ex) {
+ throw new RuntimeException(
+ "Failed to read JSON attribute: " + attribute
+ );
+ }
+
+ return result;
+ }
+
+ /**
+ * Assess a given HTTP status code.
+ *
+ * @param statusCode the HTTP status code to check
+ * @return boolean status (success or failure)
+ */
+ public static boolean checkStatusCode(int statusCode) {
+ if (statusCode == STATUS_OK || statusCode == STATUS_CREATED || statusCode == STATUS_ACCEPTED) {
+ return true;
+ }
+
+ return false;
+ }
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/ServerControllerConfig.java b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerControllerConfig.java
new file mode 100644
index 0000000..e26d4be
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerControllerConfig.java
@@ -0,0 +1,249 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.drivers.server;
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.ControllerConfig;
+import org.onosproject.net.behaviour.ControllerInfo;
+import org.onosproject.mastership.MastershipService;
+
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.TpPort;
+import org.slf4j.Logger;
+
+import com.google.common.collect.Lists;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+import javax.ws.rs.ProcessingException;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Sets, gets, and removes controller configuration
+ * from a commodity server (i.e., a REST device).
+ */
+public class ServerControllerConfig extends BasicServerDriver
+ implements ControllerConfig {
+
+ private final Logger log = getLogger(getClass());
+
+ /**
+ * Resource endpoints of the server agent (REST server-side).
+ */
+ private static final String CONTROLLERS_CONF_URL = BASE_URL + "/controllers";
+
+ /**
+ * Parameters to be exchanged with the server's agent.
+ */
+ private static final String PARAM_CTRL = "controllers";
+ private static final String PARAM_CTRL_IP = "ip";
+ private static final String PARAM_CTRL_PORT = "port";
+ private static final String PARAM_CTRL_TYPE = "type";
+
+ /**
+ * Constructs controller configuration for server.
+ */
+ public ServerControllerConfig() {
+ super();
+ log.debug("Started");
+ }
+
+ @Override
+ public List<ControllerInfo> getControllers() {
+ List<ControllerInfo> controllers = Lists.newArrayList();
+
+ DeviceId deviceId = getHandler().data().deviceId();
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+
+ MastershipService mastershipService = getHandler().get(MastershipService.class);
+ checkNotNull(deviceId, MASTERSHIP_NULL);
+
+ if (!mastershipService.isLocalMaster(deviceId)) {
+ log.warn(
+ "I am not master for {}. " +
+ "Please use master {} to get controllers for this device",
+ deviceId,
+ mastershipService.getMasterFor(deviceId)
+ );
+ return controllers;
+ }
+
+ // Hit the path that provides the server's controllers
+ InputStream response = null;
+ try {
+ response = getController().get(
+ deviceId,
+ CONTROLLERS_CONF_URL,
+ JSON
+ );
+ } catch (ProcessingException pEx) {
+ log.error("Failed to get controllers of device: {}", deviceId);
+ return controllers;
+ }
+
+ // Load the JSON into objects
+ ObjectMapper mapper = new ObjectMapper();
+ Map<String, Object> jsonMap = null;
+ JsonNode jsonNode = null;
+ ObjectNode objNode = null;
+ try {
+ jsonMap = mapper.readValue(response, Map.class);
+ jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
+ objNode = (ObjectNode) jsonNode;
+ } catch (IOException ioEx) {
+ log.error("Failed to get controllers of device: {}", deviceId);
+ return controllers;
+ }
+
+ if (jsonMap == null) {
+ log.error("Failed to get controllers of device: {}", deviceId);
+ return controllers;
+ }
+
+ JsonNode ctrlNode = objNode.path(PARAM_CTRL);
+
+ // Fetch controller objects
+ for (JsonNode cn : ctrlNode) {
+ ObjectNode ctrlObjNode = (ObjectNode) cn;
+
+ // Get the attributes of a controller
+ String ctrlIpStr = get(cn, PARAM_CTRL_IP);
+ int ctrlPort = ctrlObjNode.path(PARAM_CTRL_PORT).asInt();
+ String ctrlType = get(cn, PARAM_CTRL_TYPE);
+
+ // Check data format and range
+ IpAddress ctrlIp = null;
+ try {
+ ctrlIp = IpAddress.valueOf(ctrlIpStr);
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException(e);
+ }
+
+ if ((ctrlPort < 0) || (ctrlPort > TpPort.MAX_PORT)) {
+ final String msg = "Invalid controller port: " + ctrlPort;
+ throw new IllegalArgumentException(msg);
+ }
+
+ controllers.add(
+ new ControllerInfo(ctrlIp, ctrlPort, ctrlType)
+ );
+ }
+
+ return controllers;
+ }
+
+ @Override
+ public void setControllers(List<ControllerInfo> controllers) {
+ DeviceId deviceId = getHandler().data().deviceId();
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+
+ MastershipService mastershipService = getHandler().get(MastershipService.class);
+ checkNotNull(deviceId, MASTERSHIP_NULL);
+
+ if (!mastershipService.isLocalMaster(deviceId)) {
+ log.warn(
+ "I am not master for {}. " +
+ "Please use master {} to set controllers for this device",
+ deviceId,
+ mastershipService.getMasterFor(deviceId)
+ );
+ return;
+ }
+
+ ObjectMapper mapper = new ObjectMapper();
+
+ // Create the object node to host the data
+ ObjectNode sendObjNode = mapper.createObjectNode();
+
+ // Insert header
+ ArrayNode ctrlsArrayNode = sendObjNode.putArray(PARAM_CTRL);
+
+ // Add each controller's information object
+ for (ControllerInfo ctrl : controllers) {
+ ObjectNode ctrlObjNode = mapper.createObjectNode();
+ ctrlObjNode.put(PARAM_CTRL_IP, ctrl.ip().toString());
+ ctrlObjNode.put(PARAM_CTRL_PORT, ctrl.port());
+ ctrlObjNode.put(PARAM_CTRL_TYPE, ctrl.type());
+ ctrlsArrayNode.add(ctrlObjNode);
+ }
+
+ // Post the controllers to the device
+ int response = getController().post(
+ deviceId,
+ CONTROLLERS_CONF_URL,
+ new ByteArrayInputStream(sendObjNode.toString().getBytes()),
+ JSON
+ );
+
+ if (!checkStatusCode(response)) {
+ log.error("Failed to set controllers on device {}", deviceId);
+ }
+
+ return;
+ }
+
+ @Override
+ public void removeControllers(List<ControllerInfo> controllers) {
+ DeviceId deviceId = getHandler().data().deviceId();
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+
+ MastershipService mastershipService = getHandler().get(MastershipService.class);
+ checkNotNull(deviceId, MASTERSHIP_NULL);
+
+ if (!mastershipService.isLocalMaster(deviceId)) {
+ log.warn(
+ "I am not master for {}. " +
+ "Please use master {} to remove controllers from this device",
+ deviceId,
+ mastershipService.getMasterFor(deviceId)
+ );
+ return;
+ }
+
+ /**
+ * TODO: Explicit removal of the requested controllers.
+ */
+
+ /**
+ * List of controllers is ignored for now.
+ * We just tell the server to remove its
+ * current controller information.
+ */
+ int response = getController().delete(
+ deviceId,
+ CONTROLLERS_CONF_URL,
+ null,
+ JSON
+ );
+
+ if (!checkStatusCode(response)) {
+ log.error("Failed to remove controllers from device {}", deviceId);
+ }
+
+ return;
+ }
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/ServerDevicesDiscovery.java b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerDevicesDiscovery.java
new file mode 100644
index 0000000..c5934f5
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerDevicesDiscovery.java
@@ -0,0 +1,926 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server;
+
+import org.onosproject.drivers.server.behavior.CpuStatisticsDiscovery;
+import org.onosproject.drivers.server.behavior.MonitoringStatisticsDiscovery;
+import org.onosproject.drivers.server.devices.CpuDevice;
+import org.onosproject.drivers.server.devices.CpuVendor;
+import org.onosproject.drivers.server.devices.NicDevice;
+import org.onosproject.drivers.server.devices.NicRxFilter;
+import org.onosproject.drivers.server.devices.NicRxFilter.RxFilter;
+import org.onosproject.drivers.server.devices.ServerDeviceDescription;
+import org.onosproject.drivers.server.devices.RestServerSBDevice;
+import org.onosproject.drivers.server.stats.CpuStatistics;
+import org.onosproject.drivers.server.stats.MonitoringStatistics;
+import org.onosproject.drivers.server.stats.TimingStatistics;
+
+import org.onosproject.drivers.server.impl.devices.DefaultCpuDevice;
+import org.onosproject.drivers.server.impl.devices.DefaultNicDevice;
+import org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice;
+import org.onosproject.drivers.server.impl.devices.DefaultServerDeviceDescription;
+import org.onosproject.drivers.server.impl.stats.DefaultCpuStatistics;
+import org.onosproject.drivers.server.impl.stats.DefaultMonitoringStatistics;
+import org.onosproject.drivers.server.impl.stats.DefaultTimingStatistics;
+
+import org.onlab.packet.ChassisId;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.behaviour.DevicesDiscovery;
+import org.onosproject.net.device.DeviceDescription;
+import org.onosproject.net.device.DeviceDescriptionDiscovery;
+import org.onosproject.net.device.DefaultPortStatistics;
+import org.onosproject.net.device.DefaultPortDescription;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.device.PortStatistics;
+import org.onosproject.net.device.PortStatisticsDiscovery;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.protocol.rest.RestSBDevice;
+import org.onosproject.protocol.rest.RestSBDevice.AuthenticationScheme;
+
+import org.slf4j.Logger;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.ImmutableList;
+
+import javax.ws.rs.ProcessingException;
+import java.io.InputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Discovers the device details of
+ * REST-based commodity server devices.
+ */
+public class ServerDevicesDiscovery extends BasicServerDriver
+ implements DevicesDiscovery, DeviceDescriptionDiscovery,
+ PortStatisticsDiscovery, CpuStatisticsDiscovery,
+ MonitoringStatisticsDiscovery {
+
+ private final Logger log = getLogger(getClass());
+
+ /**
+ * Resource endpoints of the server agent (REST server-side).
+ */
+ private static final String RESOURCE_DISCOVERY_URL = BASE_URL + "/resources";
+ private static final String GLOBAL_STATS_URL = BASE_URL + "/stats";
+ private static final String SERVICE_CHAINS_STATS_URL = BASE_URL + "/chains_stats"; // + /ID
+
+ /**
+ * Parameters to be exchanged with the server's agent.
+ */
+ private static final String PARAM_ID = "id";
+ private static final String PARAM_CPUS = "cpus";
+ private static final String PARAM_MANUFACTURER = "manufacturer";
+ private static final String PARAM_HW_VENDOR = "hwVersion";
+ private static final String PARAM_SW_VENDOR = "swVersion";
+ private static final String PARAM_SERIAL = "serial";
+ private static final String PARAM_NICS = "nics";
+ private static final String PARAM_TIMING_STATS = "timing_stats";
+ private static final String PARAM_TIMING_AUTOSCALE = "autoscale_timing_stats";
+
+ private static final String NIC_PARAM_ID = "id";
+ private static final String NIC_PARAM_PORT_TYPE = "portType";
+ private static final String NIC_PARAM_PORT_TYPE_FIBER = "fiber";
+ private static final String NIC_PARAM_PORT_TYPE_COPPER = "copper";
+ private static final String NIC_PARAM_SPEED = "speed";
+ private static final String NIC_PARAM_STATUS = "status";
+ private static final String NIC_PARAM_HW_ADDR = "hwAddr";
+ private static final String NIC_PARAM_RX_FILTER = "rxFilter";
+ private static final String NIC_PARAM_RX_METHOD = "method";
+ private static final String NIC_PARAM_RX_METHOD_VALUES = "values";
+
+ /**
+ * NIC statistics.
+ */
+ private static final String NIC_STATS_TX_COUNT = "txCount";
+ private static final String NIC_STATS_TX_BYTES = "txBytes";
+ private static final String NIC_STATS_TX_DROPS = "txDropped";
+ private static final String NIC_STATS_TX_ERRORS = "txErrors";
+ private static final String NIC_STATS_RX_COUNT = "rxCount";
+ private static final String NIC_STATS_RX_BYTES = "rxBytes";
+ private static final String NIC_STATS_RX_DROPS = "rxDropped";
+ private static final String NIC_STATS_RX_ERRORS = "rxErrors";
+
+ /**
+ * CPU statistics.
+ */
+ private static final String CPU_PARAM_ID = "id";
+ private static final String CPU_PARAM_VENDOR = "vendor";
+ private static final String CPU_PARAM_FREQUENCY = "frequency";
+ private static final String CPU_PARAM_LOAD = "load";
+ private static final String CPU_PARAM_STATUS = "busy";
+ private static final String CPU_STATS_BUSY_CPUS = "busyCpus";
+ private static final String CPU_STATS_FREE_CPUS = "freeCpus";
+
+ /**
+ * Timing statistics.
+ */
+ private static final String TIMING_PARAM_PARSE = "parse";
+ private static final String TIMING_PARAM_LAUNCH = "launch";
+ private static final String TIMING_PARAM_AUTOSCALE = "autoscale";
+
+ /**
+ * Auxiliary constants.
+ */
+ private static final short DISCOVERY_RETRIES = 3;
+ private static final String CPU_VENDOR_NULL = "Unsupported CPU vendor" +
+ " Choose one in: " + BasicServerDriver.enumTypesToString(CpuVendor.class);
+ private static final String NIC_RX_FILTER_NULL = "Unsupported NIC Rx filter" +
+ " Choose one in: " + BasicServerDriver.enumTypesToString(RxFilter.class);
+
+ /**
+ * Port types that usually appear in commodity servers.
+ */
+ public static final Map<String, Port.Type> PORT_TYPE_MAP =
+ Collections.unmodifiableMap(
+ new HashMap<String, Port.Type>() {
+ {
+ put(NIC_PARAM_PORT_TYPE_FIBER, Port.Type.FIBER);
+ put(NIC_PARAM_PORT_TYPE_COPPER, Port.Type.COPPER);
+ }
+ }
+ );
+
+ /**
+ * Constructs server device discovery.
+ */
+ public ServerDevicesDiscovery() {
+ super();
+ log.debug("Started");
+ }
+
+ @Override
+ public Set<DeviceId> deviceIds() {
+ // Set of devices to return
+ Set<DeviceId> devices = new HashSet<DeviceId>();
+
+ DeviceId deviceId = getHandler().data().deviceId();
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+ devices.add(deviceId);
+
+ return devices;
+ }
+
+ @Override
+ public DeviceDescription deviceDetails(DeviceId deviceId) {
+ return getDeviceDetails(deviceId);
+ }
+
+ @Override
+ public DeviceDescription discoverDeviceDetails() {
+ return getDeviceDetails(null);
+ }
+
+ /**
+ * Query a server to retrieve its features.
+ *
+ * @param deviceId the device ID to be queried
+ * @return a DeviceDescription with the device's features
+ */
+ private DeviceDescription getDeviceDetails(DeviceId deviceId) {
+ // Create a description for this server device
+ ServerDeviceDescription desc = null;
+
+ // Retrieve the device ID, if null given
+ if (deviceId == null) {
+ deviceId = getHandler().data().deviceId();
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+ }
+
+ // Get the device
+ RestSBDevice device = getController().getDevice(deviceId);
+ checkNotNull(device, DEVICE_NULL);
+
+ // Hit the path that provides the server's resources
+ InputStream response = null;
+ try {
+ response = getController().get(
+ deviceId,
+ RESOURCE_DISCOVERY_URL,
+ JSON
+ );
+ } catch (ProcessingException pEx) {
+ log.error("Failed to discover the device details of: {}", deviceId);
+ return desc;
+ }
+
+ // Load the JSON into objects
+ ObjectMapper mapper = new ObjectMapper();
+ Map<String, Object> jsonMap = null;
+ JsonNode jsonNode = null;
+ ObjectNode objNode = null;
+ try {
+ jsonMap = mapper.readValue(response, Map.class);
+ jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
+ objNode = (ObjectNode) jsonNode;
+ } catch (IOException ioEx) {
+ log.error("Failed to discover the device details of: {}", deviceId);
+ return desc;
+ }
+
+ if (jsonMap == null) {
+ log.error("Failed to discover the device details of: {}", deviceId);
+ return desc;
+ }
+
+ // Get all the attributes
+ String id = get(jsonNode, PARAM_ID);
+ String vendor = get(jsonNode, PARAM_MANUFACTURER);
+ String hw = get(jsonNode, PARAM_HW_VENDOR);
+ String sw = get(jsonNode, PARAM_SW_VENDOR);
+ String serial = get(jsonNode, PARAM_SERIAL);
+
+ // CPUs are composite attributes
+ Set<CpuDevice> cpuSet = new HashSet<CpuDevice>();
+ JsonNode cpuNode = objNode.path(PARAM_CPUS);
+
+ // Construct CPU objects
+ for (JsonNode cn : cpuNode) {
+ ObjectNode cpuObjNode = (ObjectNode) cn;
+
+ // All the CPU attributes
+ int cpuId = cpuObjNode.path(CPU_PARAM_ID).asInt();
+ String cpuVendorStr = get(cn, CPU_PARAM_VENDOR);
+ long cpuFrequency = cpuObjNode.path(CPU_PARAM_FREQUENCY).asLong();
+
+ // Verify that this is a valid vendor
+ CpuVendor cpuVendor = CpuVendor.getByName(cpuVendorStr);
+ checkNotNull(cpuVendor, CPU_VENDOR_NULL);
+
+ // Construct a CPU device
+ CpuDevice cpu = new DefaultCpuDevice(cpuId, cpuVendor, cpuFrequency);
+
+ // Add it to the set
+ cpuSet.add(cpu);
+ }
+
+ // NICs are composite attributes too
+ Set<NicDevice> nicSet = new HashSet<NicDevice>();
+ JsonNode nicNode = objNode.path(PARAM_NICS);
+
+ // Construct NIC objects
+ for (JsonNode nn : nicNode) {
+ ObjectNode nicObjNode = (ObjectNode) nn;
+
+ // All the NIC attributes
+ String nicId = get(nn, NIC_PARAM_ID);
+ int port = Integer.parseInt(nicId.replaceAll("\\D+", ""));
+ long speed = nicObjNode.path(NIC_PARAM_SPEED).asLong();
+ String portTypeStr = get(nn, NIC_PARAM_PORT_TYPE);
+ Port.Type portType = PORT_TYPE_MAP.get(portTypeStr);
+ if (portType == null) {
+ throw new RuntimeException(
+ portTypeStr + " is not a valid port type for NIC " + nicId
+ );
+ }
+ boolean status = nicObjNode.path(NIC_PARAM_STATUS).asInt() > 0;
+ String hwAddr = get(nn, NIC_PARAM_HW_ADDR);
+ JsonNode tagNode = nicObjNode.path(NIC_PARAM_RX_FILTER);
+ if (tagNode == null) {
+ throw new RuntimeException(
+ "The Rx filters of NIC " + nicId + " are not reported"
+ );
+ }
+
+ // Convert the JSON list into an array of strings
+ List<String> rxFilters = null;
+ try {
+ rxFilters = mapper.readValue(
+ tagNode.traverse(),
+ new TypeReference<ArrayList<String>>() { }
+ );
+ } catch (IOException ioEx) {
+ continue;
+ }
+
+ // Parse the array of strings and create an RxFilter object
+ NicRxFilter rxFilterMechanism = new NicRxFilter();
+ for (String s : rxFilters) {
+ // Verify that this is a valid Rx filter
+ RxFilter rf = RxFilter.getByName(s);
+ checkNotNull(rf, NIC_RX_FILTER_NULL);
+
+ rxFilterMechanism.addRxFilter(rf);
+ }
+
+ // Construct a NIC device for this server
+ NicDevice nic = new DefaultNicDevice(
+ nicId, port, portType, speed, status, hwAddr, rxFilterMechanism
+ );
+
+ // Add it to the set
+ nicSet.add(nic);
+ }
+
+ /**
+ * Construct a complete server device object.
+ * Lists of NICs and CPUs extend the information
+ * already in RestSBDevice (parent class).
+ */
+ RestServerSBDevice dev = new DefaultRestServerSBDevice(
+ device.ip(), device.port(), device.username(),
+ device.password(), device.protocol(), device.url(),
+ device.isActive(), device.testUrl().toString(),
+ vendor, hw, sw, AuthenticationScheme.BASIC, "",
+ cpuSet, nicSet
+ );
+ checkNotNull(dev, DEVICE_NULL);
+
+ // Updates the controller with the complete device information
+ getController().removeDevice(deviceId);
+ getController().addDevice((RestSBDevice) dev);
+
+ /**
+ * TODO: Create a new Device type
+ * Device.Type.COMMODITY_SERVER
+ * and add a new icon in the GUI.
+ */
+ try {
+ desc = new DefaultServerDeviceDescription(
+ new URI(id), Device.Type.OTHER, vendor,
+ hw, sw, serial, new ChassisId(),
+ cpuSet, nicSet, DefaultAnnotations.EMPTY
+ );
+ } catch (URISyntaxException uEx) {
+ log.error(
+ "Failed to create a server device description for: {}", deviceId
+ );
+ return null;
+ }
+
+ log.info("Device's {} details sent to the controller", deviceId);
+
+ return desc;
+ }
+
+ @Override
+ public List<PortDescription> discoverPortDetails() {
+ // List of port descriptions to return
+ List<PortDescription> portDescriptions = Lists.newArrayList();
+
+ // Retrieve the device ID
+ DeviceId deviceId = getHandler().data().deviceId();
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+ // .. and object
+ RestServerSBDevice device = null;
+
+ /*
+ * In case this method is called before discoverDeviceDetails,
+ * there is missing information to be gathered.
+ */
+ short i = 0;
+ while ((device == null) && (i < DISCOVERY_RETRIES)) {
+ i++;
+
+ try {
+ device = (RestServerSBDevice) getController().getDevice(deviceId);
+ } catch (ClassCastException ccEx) {
+ try {
+ Thread.sleep(1);
+ } catch (InterruptedException intEx) {
+ // Just retry
+ } finally {
+ continue;
+ }
+ }
+
+ // No device
+ if (device == null) {
+ // This method will add the device to the RestSBController
+ this.getDeviceDetails(deviceId);
+ }
+ }
+
+ if ((device == null) || (device.nics() == null)) {
+ log.error("No ports available on {}", deviceId);
+ return ImmutableList.copyOf(portDescriptions);
+ }
+
+ // Sorted list of NIC ports
+ Set<NicDevice> nics = new TreeSet(device.nics());
+
+ // Iterate through the NICs of this device to populate the list
+ long portCounter = 0;
+ for (NicDevice nic : nics) {
+ // The port number of this NIC
+ PortNumber portNumber = PortNumber.portNumber(++portCounter);
+
+ // Include the name of this device as an annotation
+ DefaultAnnotations.Builder annotations = DefaultAnnotations.builder()
+ .set(AnnotationKeys.PORT_NAME, nic.id());
+
+ // Create a port description and add it to the list
+ portDescriptions.add(
+ new DefaultPortDescription(
+ portNumber, nic.status(),
+ nic.portType(), nic.speed(),
+ annotations.build()
+ )
+ );
+
+ log.info(
+ "Port discovery on device {}: NIC {} is {} at {} Mbps",
+ deviceId, nic.port(), nic.status() ? "up" : "down",
+ nic.speed()
+ );
+ }
+
+ return ImmutableList.copyOf(portDescriptions);
+ }
+
+ @Override
+ public Collection<PortStatistics> discoverPortStatistics() {
+ // Retrieve the device ID
+ DeviceId deviceId = getHandler().data().deviceId();
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+
+ // Get port statistics for this device
+ return getPortStatistics(deviceId);
+ }
+
+ /**
+ * Query a server to retrieve its port statistics.
+ *
+ * @param deviceId the device ID to be queried
+ * @return list of (per port) PortStatistics
+ */
+ private Collection<PortStatistics> getPortStatistics(DeviceId deviceId) {
+ // List of port statistics to return
+ Collection<PortStatistics> portStats = null;
+
+ // Get global monitoring statistics
+ MonitoringStatistics monStats = getGlobalMonitoringStatistics(deviceId);
+ if (monStats == null) {
+ return portStats;
+ }
+
+ // Filter out the NIC statistics
+ portStats = monStats.nicStatisticsAll();
+ if (portStats == null) {
+ return portStats;
+ }
+
+ log.debug("Port statistics: {}", portStats.toString());
+
+ return portStats;
+ }
+
+ @Override
+ public Collection<CpuStatistics> discoverCpuStatistics() {
+ // Retrieve the device ID
+ DeviceId deviceId = getHandler().data().deviceId();
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+
+ // Get CPU statistics for this device
+ return getCpuStatistics(deviceId);
+ }
+
+ /**
+ * Query a server to retrieve its CPU statistics.
+ *
+ * @param deviceId the device ID to be queried
+ * @return list of (per core) CpuStatistics
+ */
+ private Collection<CpuStatistics> getCpuStatistics(DeviceId deviceId) {
+ // List of port statistics to return
+ Collection<CpuStatistics> cpuStats = null;
+
+ // Get global monitoring statistics
+ MonitoringStatistics monStats = getGlobalMonitoringStatistics(deviceId);
+ if (monStats == null) {
+ return cpuStats;
+ }
+
+ // Filter out the CPU statistics
+ cpuStats = monStats.cpuStatisticsAll();
+ if (cpuStats == null) {
+ return cpuStats;
+ }
+
+ log.debug("CPU statistics: {}", cpuStats.toString());
+
+ return cpuStats;
+ }
+
+ @Override
+ public MonitoringStatistics discoverGlobalMonitoringStatistics() {
+ // Retrieve the device ID
+ DeviceId deviceId = getHandler().data().deviceId();
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+
+ // Get global monitoring statistics for this device
+ return getGlobalMonitoringStatistics(deviceId);
+ }
+
+ /**
+ * Query a server to retrieve its global monitoring statistics.
+ *
+ * @param deviceId the device ID to be queried
+ * @return global monitoring statistics
+ */
+ private MonitoringStatistics getGlobalMonitoringStatistics(DeviceId deviceId) {
+ // Monitoring statistics to return
+ MonitoringStatistics monStats = null;
+
+ RestServerSBDevice device = null;
+ try {
+ device = (RestServerSBDevice) getController().getDevice(deviceId);
+ } catch (ClassCastException ccEx) {
+ log.error(
+ "Failed to retrieve global monitoring statistics from device {}",
+ deviceId
+ );
+ return monStats;
+ }
+ checkNotNull(device, DEVICE_NULL);
+
+ // Hit the path that provides the server's global resources
+ InputStream response = null;
+ try {
+ response = getController().get(
+ deviceId,
+ GLOBAL_STATS_URL,
+ JSON
+ );
+ } catch (ProcessingException pEx) {
+ log.error(
+ "Failed to retrieve global monitoring statistics from device {}",
+ deviceId
+ );
+ return monStats;
+ }
+
+ // Load the JSON into objects
+ ObjectMapper mapper = new ObjectMapper();
+ Map<String, Object> jsonMap = null;
+ JsonNode jsonNode = null;
+ ObjectNode objNode = null;
+ try {
+ jsonMap = mapper.readValue(response, Map.class);
+ jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
+ objNode = (ObjectNode) jsonNode;
+ } catch (IOException ioEx) {
+ log.error(
+ "Failed to retrieve global monitoring statistics from device {}",
+ deviceId
+ );
+ return monStats;
+ }
+
+ if (jsonMap == null) {
+ log.error(
+ "Failed to retrieve global monitoring statistics from device {}",
+ deviceId
+ );
+ return monStats;
+ }
+
+ // Get high-level CPU statistics
+ int busyCpus = objNode.path(CPU_STATS_BUSY_CPUS).asInt();
+ int freeCpus = objNode.path(CPU_STATS_FREE_CPUS).asInt();
+
+ // Get a list of CPU statistics per core
+ Collection<CpuStatistics> cpuStats = parseCpuStatistics(deviceId, objNode);
+
+ // Get a list of port statistics
+ Collection<PortStatistics> nicStats = parseNicStatistics(deviceId, objNode);
+
+ // Get zero timing statistics
+ TimingStatistics timinsgStats = getZeroTimingStatistics();
+
+ // Ready to construct the grand object
+ DefaultMonitoringStatistics.Builder statsBuilder =
+ DefaultMonitoringStatistics.builder();
+
+ statsBuilder.setDeviceId(deviceId)
+ .setTimingStatistics(timinsgStats)
+ .setCpuStatistics(cpuStats)
+ .setNicStatistics(nicStats)
+ .build();
+
+ monStats = statsBuilder.build();
+
+ log.debug("Global monitoring statistics: {}", monStats.toString());
+
+ return monStats;
+ }
+
+ @Override
+ public MonitoringStatistics discoverMonitoringStatistics(URI tcId) {
+ // Retrieve the device ID
+ DeviceId deviceId = getHandler().data().deviceId();
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+
+ // Get resource-specific monitoring statistics for this device
+ return getMonitoringStatistics(deviceId, tcId);
+ }
+
+ /**
+ * Query a server to retrieve monitoring statistics for a
+ * specific resource (i.e., traffic class).
+ *
+ * @param deviceId the device ID to be queried
+ * @param tcId the ID of the traffic class to be monitored
+ * @return resource-specific monitoring statistics
+ */
+ private MonitoringStatistics getMonitoringStatistics(DeviceId deviceId, URI tcId) {
+ // Monitoring statistics to return
+ MonitoringStatistics monStats = null;
+
+ RestServerSBDevice device = null;
+ try {
+ device = (RestServerSBDevice) getController().getDevice(deviceId);
+ } catch (ClassCastException ccEx) {
+ log.error(
+ "Failed to retrieve monitoring statistics from device {}",
+ deviceId
+ );
+ return monStats;
+ }
+ checkNotNull(device, DEVICE_NULL);
+
+ // Create a resource-specific URL
+ String scUrl = SERVICE_CHAINS_STATS_URL + "/" + tcId.toString();
+
+ // Hit the path that provides the server's specific resources
+ InputStream response = null;
+ try {
+ response = getController().get(
+ deviceId,
+ scUrl,
+ JSON
+ );
+ } catch (ProcessingException pEx) {
+ log.error(
+ "Failed to retrieve monitoring statistics from device {}",
+ deviceId
+ );
+ return monStats;
+ }
+
+ // Load the JSON into objects
+ ObjectMapper mapper = new ObjectMapper();
+ Map<String, Object> jsonMap = null;
+ JsonNode jsonNode = null;
+ ObjectNode objNode = null;
+ try {
+ jsonMap = mapper.readValue(response, Map.class);
+ jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
+ objNode = (ObjectNode) jsonNode;
+ } catch (IOException ioEx) {
+ log.error(
+ "Failed to retrieve monitoring statistics from device {}",
+ deviceId
+ );
+ return monStats;
+ }
+
+ if (jsonMap == null) {
+ log.error(
+ "Failed to retrieve monitoring statistics from device {}",
+ deviceId
+ );
+ return monStats;
+ }
+
+ // Get the ID of the traffic class
+ String id = get(jsonNode, PARAM_ID);
+
+ // And verify that this is the traffic class we want to monitor
+ if (!id.equals(tcId.toString())) {
+ throw new RuntimeException(
+ "Failed to retrieve monitoring data for traffic class " + tcId +
+ ". Traffic class ID does not agree."
+ );
+ }
+
+ // Get a list of CPU statistics per core
+ Collection<CpuStatistics> cpuStats = parseCpuStatistics(deviceId, objNode);
+
+ // Get a list of port statistics
+ Collection<PortStatistics> nicStats = parseNicStatistics(deviceId, objNode);
+
+ // Get timing statistics
+ TimingStatistics timinsgStats = parseTimingStatistics(objNode);
+
+ // Ready to construct the grand object
+ DefaultMonitoringStatistics.Builder statsBuilder =
+ DefaultMonitoringStatistics.builder();
+
+ statsBuilder.setDeviceId(deviceId)
+ .setTimingStatistics(timinsgStats)
+ .setCpuStatistics(cpuStats)
+ .setNicStatistics(nicStats)
+ .build();
+
+ monStats = statsBuilder.build();
+
+ log.debug("Monitoring statistics: {}", monStats.toString());
+
+ return monStats;
+ }
+
+ /**
+ * Parse the input JSON object, looking for CPU-related
+ * statistics. Upon success, construct and return a list
+ * of CPU statistics objects.
+ *
+ * @param deviceId the device ID that sent the JSON object
+ * @param objNode input JSON node with CPU statistics information
+ * @return list of (per core) CpuStatistics
+ */
+ private Collection<CpuStatistics> parseCpuStatistics(
+ DeviceId deviceId, JsonNode objNode) {
+ Collection<CpuStatistics> cpuStats = Lists.newArrayList();
+
+ if (objNode == null) {
+ return cpuStats;
+ }
+
+ JsonNode cpuNode = objNode.path(PARAM_CPUS);
+
+ for (JsonNode cn : cpuNode) {
+ ObjectNode cpuObjNode = (ObjectNode) cn;
+
+ // CPU ID with its load and status
+ int cpuId = cpuObjNode.path(CPU_PARAM_ID).asInt();
+ float cpuLoad = cpuObjNode.path(CPU_PARAM_LOAD).floatValue();
+ boolean isBusy = cpuObjNode.path(CPU_PARAM_STATUS).booleanValue();
+
+ // Incorporate these statistics into an object
+ DefaultCpuStatistics.Builder cpuBuilder =
+ DefaultCpuStatistics.builder();
+
+ cpuBuilder.setDeviceId(deviceId)
+ .setId(cpuId)
+ .setLoad(cpuLoad)
+ .setIsBusy(isBusy)
+ .build();
+
+ // We have statistics for this CPU core
+ cpuStats.add(cpuBuilder.build());
+ }
+
+ return cpuStats;
+ }
+
+ /**
+ * Parse the input JSON object, looking for NIC-related
+ * statistics. Upon success, construct and return a list
+ * of NIC statistics objects.
+ *
+ * @param deviceId the device ID that sent the JSON object
+ * @param objNode input JSON node with NIC statistics information
+ * @return list of (per port) PortStatistics
+ */
+ private Collection<PortStatistics> parseNicStatistics(
+ DeviceId deviceId, JsonNode objNode) {
+ Collection<PortStatistics> nicStats = Lists.newArrayList();
+
+ if (objNode == null) {
+ return nicStats;
+ }
+
+ JsonNode nicNode = objNode.path(PARAM_NICS);
+
+ for (JsonNode nn : nicNode) {
+ ObjectNode nicObjNode = (ObjectNode) nn;
+
+ // All the NIC attributes
+ String nicId = get(nn, NIC_PARAM_ID);
+ int port = Integer.parseInt(nicId.replaceAll("\\D+", ""));
+
+ long rxCount = nicObjNode.path(NIC_STATS_RX_COUNT).asLong();
+ long rxBytes = nicObjNode.path(NIC_STATS_RX_BYTES).asLong();
+ long rxDropped = nicObjNode.path(NIC_STATS_RX_DROPS).asLong();
+ long rxErrors = nicObjNode.path(NIC_STATS_RX_ERRORS).asLong();
+ long txCount = nicObjNode.path(NIC_STATS_TX_COUNT).asLong();
+ long txBytes = nicObjNode.path(NIC_STATS_TX_BYTES).asLong();
+ long txDropped = nicObjNode.path(NIC_STATS_TX_DROPS).asLong();
+ long txErrors = nicObjNode.path(NIC_STATS_TX_ERRORS).asLong();
+
+ // Incorporate these statistics into an object
+ DefaultPortStatistics.Builder nicBuilder =
+ DefaultPortStatistics.builder();
+
+ nicBuilder.setDeviceId(deviceId)
+ .setPort(port)
+ .setPacketsReceived(rxCount)
+ .setPacketsSent(txCount)
+ .setBytesReceived(rxBytes)
+ .setBytesSent(txBytes)
+ .setPacketsRxDropped(rxDropped)
+ .setPacketsRxErrors(rxErrors)
+ .setPacketsTxDropped(txDropped)
+ .setPacketsTxErrors(txErrors)
+ .build();
+
+ // We have statistics for this NIC
+ nicStats.add(nicBuilder.build());
+ }
+
+ return nicStats;
+ }
+
+ /**
+ * Parse the input JSON object, looking for timing-related
+ * statistics. Upon success, construct and return a
+ * timing statistics object.
+ *
+ * @param objNode input JSON node with timing statistics information
+ * @return TimingStatistics object or null
+ */
+ private TimingStatistics parseTimingStatistics(JsonNode objNode) {
+ TimingStatistics timinsgStats = null;
+
+ if (objNode == null) {
+ return timinsgStats;
+ }
+
+ // Get timing statistics
+ JsonNode timingNode = objNode.path(PARAM_TIMING_STATS);
+ ObjectNode timingObjNode = (ObjectNode) timingNode;
+
+ // Time (ns) to parse the controller's deployment instruction
+ long parsingTime = timingObjNode.path(TIMING_PARAM_PARSE).asLong();
+ // Time (ns) to do the deployment
+ long launchingTime = timingObjNode.path(TIMING_PARAM_LAUNCH).asLong();
+ // Total time (ns)
+ long totalTime = parsingTime + launchingTime;
+
+ // Get autoscale timing statistics
+ JsonNode autoscaleTimingNode = objNode.path(PARAM_TIMING_AUTOSCALE);
+ ObjectNode autoscaleTimingObjNode = (ObjectNode) autoscaleTimingNode;
+
+ // Time (ns) to autoscale a server's load
+ long autoscaleTime = autoscaleTimingObjNode.path(
+ TIMING_PARAM_AUTOSCALE
+ ).asLong();
+
+ DefaultTimingStatistics.Builder timingBuilder =
+ DefaultTimingStatistics.builder();
+
+ timingBuilder.setParsingTime(parsingTime)
+ .setLaunchingTime(launchingTime)
+ .setAutoscaleTime(autoscaleTime)
+ .build();
+
+ return timingBuilder.build();
+ }
+
+ /**
+ * Return a timing statistics object with zero counters.
+ * This is useful when constructing MonitoringStatistics
+ * objects that do not require timers.
+ *
+ * @return TimingStatistics object
+ */
+ private TimingStatistics getZeroTimingStatistics() {
+ DefaultTimingStatistics.Builder zeroTimingBuilder =
+ DefaultTimingStatistics.builder();
+
+ zeroTimingBuilder.setParsingTime(0)
+ .setLaunchingTime(0)
+ .setAutoscaleTime(0)
+ .build();
+
+ return zeroTimingBuilder.build();
+ }
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/ServerDriversLoader.java b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerDriversLoader.java
new file mode 100644
index 0000000..cb5cc4f
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerDriversLoader.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server;
+
+import org.apache.felix.scr.annotations.Component;
+import org.onosproject.net.driver.AbstractDriverLoader;
+
+/**
+ * Loader for server device drivers.
+ */
+@Component(immediate = true)
+public class ServerDriversLoader extends AbstractDriverLoader {
+ public ServerDriversLoader() {
+ super("/server-drivers.xml");
+ }
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/behavior/CpuStatisticsDiscovery.java b/drivers/server/src/main/java/org/onosproject/drivers/server/behavior/CpuStatisticsDiscovery.java
new file mode 100644
index 0000000..9d42f95
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/behavior/CpuStatisticsDiscovery.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.behavior;
+
+import org.onosproject.drivers.server.stats.CpuStatistics;
+
+import org.onosproject.net.driver.HandlerBehaviour;
+
+import java.util.Collection;
+
+/**
+ * Handler behaviour capable of collecting and updating CPU statistics.
+ */
+public interface CpuStatisticsDiscovery extends HandlerBehaviour {
+
+ /**
+ * Returns a list of CPU statistics.
+ *
+ * @return CPU statistics list
+ */
+ Collection<CpuStatistics> discoverCpuStatistics();
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/behavior/MonitoringStatisticsDiscovery.java b/drivers/server/src/main/java/org/onosproject/drivers/server/behavior/MonitoringStatisticsDiscovery.java
new file mode 100644
index 0000000..ba8ea2a
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/behavior/MonitoringStatisticsDiscovery.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.behavior;
+
+import org.onosproject.drivers.server.stats.MonitoringStatistics;
+
+import org.onosproject.net.driver.HandlerBehaviour;
+
+import java.net.URI;
+
+/**
+ * Handler behaviour capable of collecting and updating
+ * server monitoring statistics.
+ */
+public interface MonitoringStatisticsDiscovery extends HandlerBehaviour {
+
+ /**
+ * Returns global server monitoring statistics.
+ * These statistics include all of the traffic that
+ * goes through the NICs of the server.
+ *
+ * @return global monitoring statistics
+ */
+ MonitoringStatistics discoverGlobalMonitoringStatistics();
+
+ /**
+ * Returns monitoring statistics for a specific resource.
+ * This resource represents a specific portion of the traffic.
+ *
+ * @param tcId the ID of the traffic class to be monitored
+ * @return resource-specific monitoring statistics
+ */
+ MonitoringStatistics discoverMonitoringStatistics(URI tcId);
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/behavior/package-info.java b/drivers/server/src/main/java/org/onosproject/drivers/server/behavior/package-info.java
new file mode 100644
index 0000000..b6e40083
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/behavior/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+/**
+ * API for server's behavior.
+ */
+package org.onosproject.drivers.server.behavior;
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/devices/CpuDevice.java b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/CpuDevice.java
new file mode 100644
index 0000000..4ddd241
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/CpuDevice.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.devices;
+
+/**
+ * Represents an abstraction of a CPU core in ONOS.
+ */
+public interface CpuDevice {
+
+ /**
+ * Returns the ID of this CPU.
+ * Typically this is the order number (0...N-1)
+ * of this CPU core in the socket.
+ *
+ * @return CPU core ID
+ */
+ int id();
+
+ /**
+ * Returns the vendor of this CPU core.
+ *
+ * @return CPU core vendor
+ */
+ CpuVendor vendor();
+
+ /**
+ * Returns the frequency of this CPU core in MHz.
+ *
+ * @return CPU core frequency in MHz
+ */
+ long frequency();
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/devices/CpuVendor.java b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/CpuVendor.java
new file mode 100644
index 0000000..289b3c3
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/CpuVendor.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.devices;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Representation of a CPU vendor.
+ */
+public enum CpuVendor {
+
+ INTEL("GenuineIntel"),
+ AMD("AMD");
+
+ private String vendor;
+
+ // Statically maps CPU vendor names to enum types
+ private static final Map<String, CpuVendor> MAP =
+ new HashMap<String, CpuVendor>();
+ static {
+ for (CpuVendor cv : CpuVendor.values()) {
+ MAP.put(cv.toString().toLowerCase(), cv);
+ }
+ }
+
+ private CpuVendor(String vendor) {
+ this.vendor = vendor;
+ }
+
+ public static CpuVendor getByName(String pr) {
+ pr = pr.toLowerCase();
+ return MAP.get(pr);
+ }
+
+ @Override
+ public String toString() {
+ return this.vendor;
+ }
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/devices/MacRxFilterValue.java b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/MacRxFilterValue.java
new file mode 100644
index 0000000..b5dfe12
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/MacRxFilterValue.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.devices;
+
+import org.onlab.packet.MacAddress;
+
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * A MAC Rx filter value.
+ */
+public class MacRxFilterValue extends RxFilterValue implements Comparable {
+
+ private MacAddress mac;
+
+ public MacRxFilterValue() {
+ super();
+
+ this.mac = null;
+ }
+
+ public MacRxFilterValue(MacAddress mac) {
+ super();
+
+ checkNotNull(mac, "MAC address of Rx filter is NULL");
+
+ this.mac = mac;
+ }
+
+ public MacRxFilterValue(MacRxFilterValue other) {
+ super();
+
+ if (other.value() == null) {
+ return;
+ }
+
+ this.mac = other.value();
+ }
+
+ /**
+ * Returns the value of this Rx filter.
+ *
+ * @return MAC value
+ */
+ public MacAddress value() {
+ return this.mac;
+ }
+
+ /**
+ * Sets the value of this Rx filter.
+ *
+ * @param mac MAC value
+ */
+ public void setValue(MacAddress mac) {
+ checkNotNull(mac, "MAC address of Rx filter is NULL");
+
+ this.mac = mac;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(this.mac);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if ((obj == null) || (!(obj instanceof MacRxFilterValue))) {
+ return false;
+ }
+
+ MacRxFilterValue other = (MacRxFilterValue) obj;
+
+ return this.value().equals(other.value());
+ }
+
+ @Override
+ public int compareTo(Object other) {
+ if (this == other) {
+ return 0;
+ }
+
+ if (other == null) {
+ return -1;
+ }
+
+ if (other instanceof MacRxFilterValue) {
+ MacRxFilterValue otherRxVal = (MacRxFilterValue) other;
+
+ // Extract the digits out of the ID
+ String thisMac = this.toString();
+ String otherMac = otherRxVal.toString();
+
+ return thisMac.compareToIgnoreCase(otherMac);
+ }
+
+ return -1;
+ }
+
+ @Override
+ public String toString() {
+ return this.value().toString();
+ }
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/devices/MplsRxFilterValue.java b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/MplsRxFilterValue.java
new file mode 100644
index 0000000..21ea37d
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/MplsRxFilterValue.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.devices;
+
+import org.onlab.packet.MplsLabel;
+
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * An MPLS Rx filter value.
+ */
+public class MplsRxFilterValue extends RxFilterValue {
+
+ private MplsLabel mplsLabel;
+
+ public MplsRxFilterValue() {
+ super();
+
+ this.mplsLabel = null;
+ }
+
+ public MplsRxFilterValue(MplsLabel mplsLabel) {
+ super();
+
+ checkNotNull(mplsLabel, "MPLS label of Rx filter is NULL");
+
+ this.mplsLabel = mplsLabel;
+ }
+
+ public MplsRxFilterValue(MplsRxFilterValue other) {
+ super();
+
+ if (other.value() == null) {
+ return;
+ }
+
+ this.mplsLabel = other.value();
+ }
+
+ /**
+ * Returns the value of this Rx filter.
+ *
+ * @return MPLS label value
+ */
+ public MplsLabel value() {
+ return this.mplsLabel;
+ }
+
+ /**
+ * Sets the value of this Rx filter.
+ *
+ * @param mplsLabel MPLS label value
+ */
+ public void setValue(MplsLabel mplsLabel) {
+ checkNotNull(mplsLabel, "MPLS label of Rx filter is NULL");
+
+ this.mplsLabel = mplsLabel;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(this.mplsLabel);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if ((obj == null) || (!(obj instanceof MplsRxFilterValue))) {
+ return false;
+ }
+
+ MplsRxFilterValue other = (MplsRxFilterValue) obj;
+
+ return this.value().equals(other.value());
+ }
+
+ @Override
+ public String toString() {
+ return this.value().toString();
+ }
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/devices/NicDevice.java b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/NicDevice.java
new file mode 100644
index 0000000..0416a6c
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/NicDevice.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.devices;
+
+import org.onlab.packet.MacAddress;
+
+import static org.onosproject.net.Port.Type;
+
+/**
+ * Represents an abstraction of a
+ * network interface card (NIC) device in ONOS.
+ */
+public interface NicDevice extends Comparable {
+
+ /**
+ * Returns the ID of this NIC.
+ *
+ * @return NIC ID
+ */
+ String id();
+
+ /**
+ * Returns the port number of this NIC.
+ *
+ * @return integer port number for the NIC
+ */
+ int port();
+
+ /**
+ * Returns the type of the port of this NIC.
+ *
+ * @return port type
+ */
+ Type portType();
+
+ /**
+ * Returns the speed of the NIC in Mbps.
+ *
+ * @return integer NIC speed in Mbps
+ */
+ long speed();
+
+ /**
+ * Returns the current status of the NIC.
+ *
+ * @return boolean NIC status (up=true, down=false)
+ */
+ boolean status();
+
+ /**
+ * Sets the current status of the NIC.
+ *
+ * @param status boolean NIC status (up=true, down=false)
+ */
+ void setStatus(boolean status);
+
+ /**
+ * Returns the MAC address of the NIC.
+ *
+ * @return MacAddress hardware address of the NIC
+ */
+ MacAddress macAddress();
+
+ /**
+ * Returns the Rx filter mechanisms supported by the NIC.
+ *
+ * @return Rx filter mechanisms
+ */
+ NicRxFilter rxFilterMechanisms();
+
+ /**
+ * Sets the Rx filter mechanisms supported by the NIC.
+ *
+ * @param rxFilterMechanisms Rx filter mechanisms
+ */
+ void setRxFilterMechanisms(NicRxFilter rxFilterMechanisms);
+
+ /**
+ * Adds a new Rx filter to the NIC.
+ *
+ * @param rxFilter an Rx filter to be added to the set
+ */
+ void addRxFilterMechanism(NicRxFilter.RxFilter rxFilter);
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/devices/NicRxFilter.java b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/NicRxFilter.java
new file mode 100644
index 0000000..ffddc9b
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/NicRxFilter.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.devices;
+
+import org.apache.commons.lang.ArrayUtils;
+import com.google.common.base.MoreObjects;
+
+import java.util.Set;
+import java.util.Map;
+import java.util.HashSet;
+import java.util.HashMap;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Filtering mechanisms supported by a NIC device.
+ */
+public class NicRxFilter {
+
+ /**
+ * Supported Rx filters.
+ */
+ public enum RxFilter {
+ VLAN("vlan"),
+ MAC("mac"),
+ MPLS("mpls");
+
+ private String rxFilter;
+
+ // Statically maps primitives with enum types
+ private static final Map<String, RxFilter> MAP = new HashMap<String, RxFilter>();
+ static {
+ for (RxFilter rxFilter : RxFilter.values()) {
+ MAP.put(rxFilter.toString(), rxFilter);
+ }
+ }
+
+ public static RxFilter getByName(String rxFilter) {
+ return MAP.get(rxFilter.toLowerCase());
+ }
+
+ public static boolean isSupported(RxFilter rxFilter) {
+ return MAP.containsKey(rxFilter.toString());
+ }
+
+ private RxFilter(String rxFilter) {
+ this.rxFilter = rxFilter;
+ }
+
+ @Override
+ public String toString() {
+ return this.rxFilter;
+ }
+ }
+
+ private Set<RxFilter> rxFilters;
+
+ public NicRxFilter() {
+ this.rxFilters = new HashSet<RxFilter>();
+ }
+
+ public NicRxFilter(RxFilter rxFilter) {
+ checkNotNull(rxFilter, "NIC Rx filter is NULL");
+
+ if (!ArrayUtils.contains(RxFilter.values(), rxFilter)) {
+ throw new IllegalArgumentException(String.valueOf(rxFilter));
+ }
+
+ this.rxFilters = new HashSet<RxFilter>();
+ rxFilters.add(rxFilter);
+ }
+
+ public NicRxFilter(NicRxFilter other) {
+ checkNotNull(other, "NIC Rx filter mechanism is NULL");
+ this.rxFilters = new HashSet<RxFilter>(other.rxFilters);
+ }
+
+ /**
+ * Returns the set of Rx filters supported by this NIC.
+ *
+ * @return set of supported Rx filters
+ */
+ public Set<RxFilter> rxFilters() {
+ return this.rxFilters;
+ }
+
+ /**
+ * Adds a new Rx filter to this NIC.
+ *
+ * @param rxFilter an Rx filter to be added
+ */
+ public void addRxFilter(RxFilter rxFilter) {
+ checkNotNull(rxFilter, "NIC Rx filter is NULL");
+ this.rxFilters.add(rxFilter);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .omitNullValues()
+ .add("rxFilters", rxFilters)
+ .toString();
+ }
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/devices/RestServerSBDevice.java b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/RestServerSBDevice.java
new file mode 100644
index 0000000..a1172f8
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/RestServerSBDevice.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.devices;
+
+import org.onosproject.protocol.rest.RestSBDevice;
+
+import java.util.Collection;
+
+/**
+ * Represents an abstraction of a REST server device in ONOS.
+ */
+public interface RestServerSBDevice extends RestSBDevice {
+ /**
+ * Returns the set of CPUs of the server.
+ *
+ * @return set of CPUs
+ */
+ Collection<CpuDevice> cpus();
+
+ /**
+ * Returns the number of CPUs of the server.
+ *
+ * @return number of CPUs
+ */
+ int numberOfCpus();
+
+ /**
+ * Returns the set of NICs of the server.
+ *
+ * @return set of NICs
+ */
+ Collection<NicDevice> nics();
+
+ /**
+ * Returns the number of NICs of the server.
+ *
+ * @return number of NICs
+ */
+ int numberOfNics();
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/devices/RxFilterValue.java b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/RxFilterValue.java
new file mode 100644
index 0000000..29d2c99
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/RxFilterValue.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.devices;
+
+/**
+ * The base class that holds the value of a NIC's Rx filter.
+ */
+public abstract class RxFilterValue {
+
+ public RxFilterValue() {
+ }
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/devices/ServerDeviceDescription.java b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/ServerDeviceDescription.java
new file mode 100644
index 0000000..dced9cd
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/ServerDeviceDescription.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.devices;
+
+import org.onosproject.net.device.DeviceDescription;
+
+import java.util.Collection;
+
+/**
+ * Carrier of immutable information about a server device.
+ */
+public interface ServerDeviceDescription extends DeviceDescription {
+
+ /**
+ * The set of CPUs of the server device.
+ *
+ * @return set of CPUs of the server device
+ */
+ Collection<CpuDevice> cpus();
+
+ /**
+ * The set of NICs of the server device.
+ *
+ * @return set of NICs of the server device
+ */
+ Collection<NicDevice> nics();
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/devices/VlanRxFilterValue.java b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/VlanRxFilterValue.java
new file mode 100644
index 0000000..a984810
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/VlanRxFilterValue.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.devices;
+
+import org.onlab.packet.VlanId;
+
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * A VLAN Rx filter value.
+ */
+public class VlanRxFilterValue extends RxFilterValue {
+
+ private VlanId vlanId;
+
+ public VlanRxFilterValue() {
+ super();
+
+ this.vlanId = null;
+ }
+
+ public VlanRxFilterValue(VlanId vlanId) {
+ super();
+
+ checkNotNull(vlanId, "VLAN ID of Rx filter is NULL");
+
+ this.vlanId = vlanId;
+ }
+
+ public VlanRxFilterValue(VlanRxFilterValue other) {
+ super();
+
+ if (other.value() == null) {
+ return;
+ }
+
+ this.vlanId = other.value();
+ }
+
+ /**
+ * Returns the value of this Rx filter.
+ *
+ * @return VLAN ID value
+ */
+ public VlanId value() {
+ return this.vlanId;
+ }
+
+ /**
+ * Sets the value of this Rx filter.
+ *
+ * @param vlanId VLAN ID value
+ */
+ public void setValue(VlanId vlanId) {
+ checkNotNull(vlanId, "VLAN ID of Rx filter is NULL");
+
+ this.vlanId = vlanId;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(this.vlanId);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if ((obj == null) || (!(obj instanceof VlanRxFilterValue))) {
+ return false;
+ }
+
+ VlanRxFilterValue other = (VlanRxFilterValue) obj;
+
+ return this.value().equals(other.value());
+ }
+
+ @Override
+ public String toString() {
+ return this.value().toString();
+ }
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/devices/package-info.java b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/package-info.java
new file mode 100644
index 0000000..0828e6b
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+/**
+ * API for server devices.
+ */
+package org.onosproject.drivers.server.devices;
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/impl/devices/DefaultCpuDevice.java b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/devices/DefaultCpuDevice.java
new file mode 100644
index 0000000..79712fc
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/devices/DefaultCpuDevice.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.impl.devices;
+
+import org.onosproject.drivers.server.devices.CpuDevice;
+import org.onosproject.drivers.server.devices.CpuVendor;
+
+import org.onosproject.drivers.server.impl.stats.DefaultCpuStatistics;
+
+import com.google.common.base.MoreObjects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkArgument;
+
+import java.util.Objects;
+
+/**
+ * Default implementation for CPU core devices.
+ */
+public class DefaultCpuDevice implements CpuDevice {
+
+ private final int id;
+ private final CpuVendor vendor;
+ private final long frequency;
+
+ // Maximum CPU core frequency in MHz
+ public static final long MAX_FREQUENCY_MHZ = 4500;
+
+ public DefaultCpuDevice(int id, CpuVendor vendor, long frequency) {
+ checkArgument(
+ (id >= 0) && (id < DefaultCpuStatistics.MAX_CPU_NB),
+ "CPU core ID must be in [0, " +
+ String.valueOf(DefaultCpuStatistics.MAX_CPU_NB - 1) + "]"
+ );
+ checkNotNull(
+ vendor,
+ "CPU core vendor cannot be null"
+ );
+ checkArgument(
+ (frequency > 0) && (frequency <= MAX_FREQUENCY_MHZ),
+ "CPU core frequency (MHz) must be positive and less or equal than " +
+ MAX_FREQUENCY_MHZ + " MHz"
+ );
+
+ this.id = id;
+ this.vendor = vendor;
+ this.frequency = frequency;
+ }
+
+ @Override
+ public int id() {
+ return this.id;
+ }
+
+ @Override
+ public CpuVendor vendor() {
+ return this.vendor;
+ }
+
+ @Override
+ public long frequency() {
+ return this.frequency;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .omitNullValues()
+ .add("id", id())
+ .add("vendor", vendor())
+ .add("frequency", frequency())
+ .toString();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof CpuDevice)) {
+ return false;
+ }
+ CpuDevice device = (CpuDevice) obj;
+ return this.id() == device.id() &&
+ this.vendor() == device.vendor() &&
+ this.frequency() == device.frequency();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, vendor, frequency);
+ }
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/impl/devices/DefaultNicDevice.java b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/devices/DefaultNicDevice.java
new file mode 100644
index 0000000..d69ff23
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/devices/DefaultNicDevice.java
@@ -0,0 +1,191 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.impl.devices;
+
+import org.onosproject.drivers.server.devices.NicDevice;
+import org.onosproject.drivers.server.devices.NicRxFilter;
+
+import org.onlab.packet.MacAddress;
+
+import com.google.common.base.MoreObjects;
+
+import java.util.Objects;
+
+import static org.onosproject.net.Port.Type;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Default implementation for NIC devices.
+ */
+public class DefaultNicDevice implements NicDevice, Comparable {
+
+ private final String id;
+ private final int port;
+ private final long speed;
+ private final Type portType;
+ private boolean status;
+ private final MacAddress macAddress;
+ private NicRxFilter rxFilterMechanisms;
+
+ // 200 Gbps or 200.000 Mbps
+ public static final long MAX_SPEED = 200000;
+
+ public DefaultNicDevice(
+ String id,
+ int port,
+ Type portType,
+ long speed,
+ boolean status,
+ String macStr,
+ NicRxFilter rxFilterMechanisms) {
+ checkNotNull(id, "NIC ID cannot be null");
+ checkArgument(!id.isEmpty(), "NIC ID cannot be empty");
+ checkArgument(port >= 0, "NIC port number must be non-negative");
+ checkNotNull(portType, "NIC port type cannot be null");
+ checkArgument(
+ (speed >= 0) && (speed <= MAX_SPEED),
+ "NIC speed must be positive and less or equal than " + MAX_SPEED + " Mbps"
+ );
+ checkNotNull(macStr, "NIC MAC address cannot be null");
+ checkNotNull(rxFilterMechanisms, "NIC Rx filter mechanisms cannot be null");
+
+ // Implies a problem
+ if (speed == 0) {
+ status = false;
+ }
+
+ this.id = id;
+ this.port = port;
+ this.speed = speed;
+ this.portType = portType;
+ this.status = status;
+ this.macAddress = MacAddress.valueOf(macStr);
+ this.rxFilterMechanisms = rxFilterMechanisms;
+ }
+
+ @Override
+ public String id() {
+ return this.id;
+ }
+
+ @Override
+ public int port() {
+ return this.port;
+ }
+
+ @Override
+ public Type portType() {
+ return this.portType;
+ }
+
+ @Override
+ public long speed() {
+ return this.speed;
+ }
+
+ @Override
+ public boolean status() {
+ return this.status;
+ }
+
+ @Override
+ public void setStatus(boolean status) {
+ this.status = status;
+ }
+
+ @Override
+ public MacAddress macAddress() {
+ return this.macAddress;
+ }
+
+ @Override
+ public NicRxFilter rxFilterMechanisms() {
+ return this.rxFilterMechanisms;
+ }
+
+ @Override
+ public void setRxFilterMechanisms(NicRxFilter rxFilterMechanisms) {
+ checkNotNull(rxFilterMechanisms, "NIC Rx filter mechanisms cannot be null");
+ this.rxFilterMechanisms = rxFilterMechanisms;
+ }
+
+ @Override
+ public void addRxFilterMechanism(NicRxFilter.RxFilter rxFilter) {
+ this.rxFilterMechanisms.addRxFilter(rxFilter);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .omitNullValues()
+ .add("id", id())
+ .add("port", port())
+ .add("mac", macAddress.toString())
+ .add("portType", portType())
+ .add("speed", speed())
+ .add("status", status ? "active" : "inactive")
+ .add("rxFilters", rxFilterMechanisms())
+ .toString();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof NicDevice)) {
+ return false;
+ }
+ NicDevice device = (NicDevice) obj;
+ return this.id().equals(device.id()) &&
+ this.port() == device.port() &&
+ this.speed == device.speed() &&
+ this.macAddress.equals(device.macAddress());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, port, speed, macAddress);
+ }
+
+ @Override
+ public int compareTo(Object other) {
+ if (this == other) {
+ return 0;
+ }
+
+ if (other == null) {
+ return -1;
+ }
+
+ if (other instanceof NicDevice) {
+ NicDevice otherNic = (NicDevice) other;
+
+ if (this.port() == otherNic.port()) {
+ return 0;
+ } else if (this.port() > otherNic.port()) {
+ return 1;
+ } else {
+ return -1;
+ }
+ }
+
+ return -1;
+ }
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/impl/devices/DefaultRestServerSBDevice.java b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/devices/DefaultRestServerSBDevice.java
new file mode 100644
index 0000000..7232ed5
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/devices/DefaultRestServerSBDevice.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.impl.devices;
+
+import org.onosproject.drivers.server.devices.CpuDevice;
+import org.onosproject.drivers.server.devices.NicDevice;
+import org.onosproject.drivers.server.devices.RestServerSBDevice;
+
+import org.onosproject.protocol.rest.DefaultRestSBDevice;
+import org.onosproject.protocol.rest.RestSBDevice.AuthenticationScheme;
+import org.onlab.packet.IpAddress;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.Lists;
+
+import java.util.Objects;
+import java.util.Collection;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Default implementation for REST server devices.
+ */
+public class DefaultRestServerSBDevice
+ extends DefaultRestSBDevice implements RestServerSBDevice {
+
+ private Collection<CpuDevice> cpus = Lists.newArrayList();
+ private Collection<NicDevice> nics = Lists.newArrayList();
+
+ public DefaultRestServerSBDevice(
+ IpAddress ip, int port, String name, String password,
+ String protocol, String url, boolean isActive,
+ Collection<CpuDevice> cpus, Collection<NicDevice> nics) {
+ this(
+ ip, port, name, password, protocol, url, isActive,
+ "", "", "", "", AuthenticationScheme.BASIC, "", cpus, nics
+ );
+ }
+
+ public DefaultRestServerSBDevice(
+ IpAddress ip, int port, String name, String password,
+ String protocol, String url, boolean isActive, String testUrl,
+ String manufacturer, String hwVersion, String swVersion,
+ AuthenticationScheme authenticationScheme, String token,
+ Collection<CpuDevice> cpus, Collection<NicDevice> nics) {
+ super(
+ ip, port, name, password, protocol, url, isActive,
+ testUrl, manufacturer, hwVersion, swVersion,
+ authenticationScheme, token
+ );
+
+ checkNotNull(cpus, "Device's set of CPUs cannot be null");
+ checkNotNull(nics, "Device's set of NICs cannot be null");
+
+ this.cpus = cpus;
+ this.nics = nics;
+ }
+
+ @Override
+ public Collection<CpuDevice> cpus() {
+ return this.cpus;
+ }
+
+ @Override
+ public int numberOfCpus() {
+ return this.cpus.size();
+ }
+
+ @Override
+ public Collection<NicDevice> nics() {
+ return this.nics;
+ }
+
+ @Override
+ public int numberOfNics() {
+ return this.nics.size();
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .omitNullValues()
+ .add("url", url())
+ .add("testUrl", testUrl())
+ .add("protocol", protocol())
+ .add("username", username())
+ .add("port", port())
+ .add("ip", ip())
+ .add("manufacturer", manufacturer().orElse(null))
+ .add("hwVersion", hwVersion().orElse(null))
+ .add("swVersion", swVersion().orElse(null))
+ .add("cpus", cpus())
+ .add("nics", nics())
+ .toString();
+
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof RestServerSBDevice)) {
+ return false;
+ }
+ RestServerSBDevice device = (RestServerSBDevice) obj;
+
+ return this.username().equals(device.username()) &&
+ this.ip().equals(device.ip()) &&
+ this.port() == device.port();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(ip(), port(), cpus(), nics());
+ }
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/impl/devices/DefaultServerDeviceDescription.java b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/devices/DefaultServerDeviceDescription.java
new file mode 100644
index 0000000..50aeb02
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/devices/DefaultServerDeviceDescription.java
@@ -0,0 +1,208 @@
+/*
+ * Copyright 2014-present Open Networking Foundation
+ *
+ * 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.drivers.server.impl.devices;
+
+import org.onosproject.drivers.server.devices.CpuDevice;
+import org.onosproject.drivers.server.devices.NicDevice;
+import org.onosproject.drivers.server.devices.ServerDeviceDescription;
+
+import org.onosproject.net.device.DefaultDeviceDescription;
+import org.onosproject.net.SparseAnnotations;
+import org.onlab.packet.ChassisId;
+
+import com.google.common.base.Objects;
+
+import java.net.URI;
+import java.util.Collection;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.net.Device.Type;
+
+/**
+ * Default implementation of immutable server device description entity.
+ */
+public class DefaultServerDeviceDescription extends DefaultDeviceDescription
+ implements ServerDeviceDescription {
+
+ private final Collection<CpuDevice> cpus;
+ private final Collection<NicDevice> nics;
+
+ /**
+ * Creates a server device description using the supplied information.
+ *
+ * @param uri device URI
+ * @param type device type
+ * @param manufacturer device manufacturer
+ * @param hwVersion device HW version
+ * @param swVersion device SW version
+ * @param serialNumber device serial number
+ * @param chassis chassis id
+ * @param cpus set of CPUs
+ * @param nics set of network interface cards (NICs)
+ * @param annotations optional key/value annotations map
+ */
+ public DefaultServerDeviceDescription(
+ URI uri, Type type, String manufacturer,
+ String hwVersion, String swVersion,
+ String serialNumber, ChassisId chassis,
+ Collection<CpuDevice> cpus, Collection<NicDevice> nics,
+ SparseAnnotations... annotations) {
+ this(uri, type, manufacturer, hwVersion, swVersion, serialNumber,
+ chassis, true, cpus, nics, annotations);
+ }
+
+ /**
+ * Creates a server device description using the supplied information.
+ *
+ * @param uri device URI
+ * @param type device type
+ * @param manufacturer device manufacturer
+ * @param hwVersion device HW version
+ * @param swVersion device SW version
+ * @param serialNumber device serial number
+ * @param chassis chassis id
+ * @param cpus set of CPUs
+ * @param nics set of network interface cards (NICs)
+ * @param defaultAvailable optional whether device is by default available
+ * @param annotations optional key/value annotations map
+ */
+ public DefaultServerDeviceDescription(
+ URI uri, Type type, String manufacturer,
+ String hwVersion, String swVersion,
+ String serialNumber, ChassisId chassis,
+ boolean defaultAvailable,
+ Collection<CpuDevice> cpus, Collection<NicDevice> nics,
+ SparseAnnotations... annotations) {
+ super(
+ uri, type, manufacturer, hwVersion, swVersion,
+ serialNumber, chassis, defaultAvailable, annotations
+ );
+
+ checkNotNull(cpus, "Device's set of CPUs cannot be null");
+ checkNotNull(nics, "Device's set of NICs cannot be null");
+
+ this.cpus = cpus;
+ this.nics = nics;
+ }
+
+ /**
+ * Creates a server device description using the supplied information.
+ * @param base ServerDeviceDescription to basic information
+ * @param annotations Annotations to use.
+ */
+ public DefaultServerDeviceDescription(ServerDeviceDescription base,
+ SparseAnnotations... annotations) {
+ this(base.deviceUri(), base.type(), base.manufacturer(),
+ base.hwVersion(), base.swVersion(), base.serialNumber(),
+ base.chassisId(), base.isDefaultAvailable(),
+ base.cpus(), base.nics(),
+ annotations);
+ }
+
+ /**
+ * Creates a device description using the supplied information.
+ * @param base ServerDeviceDescription to basic information (except for type)
+ * @param type device type
+ * @param annotations Annotations to use.
+ */
+ public DefaultServerDeviceDescription(
+ ServerDeviceDescription base, Type type,
+ SparseAnnotations... annotations) {
+ this(base.deviceUri(), type, base.manufacturer(),
+ base.hwVersion(), base.swVersion(), base.serialNumber(),
+ base.chassisId(), base.isDefaultAvailable(),
+ base.cpus(), base.nics(),
+ annotations);
+ }
+
+ /**
+ * Creates a device description using the supplied information.
+ *
+ * @param base ServerDeviceDescription to basic information (except for defaultAvailable)
+ * @param defaultAvailable whether device should be made available by default
+ * @param annotations Annotations to use.
+ */
+ public DefaultServerDeviceDescription(
+ ServerDeviceDescription base,
+ boolean defaultAvailable,
+ SparseAnnotations... annotations) {
+ this(base.deviceUri(), base.type(), base.manufacturer(),
+ base.hwVersion(), base.swVersion(), base.serialNumber(),
+ base.chassisId(), defaultAvailable,
+ base.cpus(), base.nics(),
+ annotations);
+ }
+
+ @Override
+ public Collection<CpuDevice> cpus() {
+ return this.cpus;
+ }
+
+ @Override
+ public Collection<NicDevice> nics() {
+ return this.nics;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("uri", deviceUri())
+ .add("type", type())
+ .add("manufacturer", manufacturer())
+ .add("hwVersion", hwVersion())
+ .add("swVersion", swVersion())
+ .add("serial", serialNumber())
+ .add("cpus", cpus)
+ .add("nics", nics)
+ .add("annotations", annotations())
+ .toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(super.hashCode(), cpus, nics);
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if (object instanceof DefaultServerDeviceDescription) {
+ if (!super.equals(object)) {
+ return false;
+ }
+ DefaultServerDeviceDescription that = (DefaultServerDeviceDescription) object;
+ return Objects.equal(this.deviceUri(), that.deviceUri())
+ && Objects.equal(this.type(), that.type())
+ && Objects.equal(this.manufacturer(), that.manufacturer())
+ && Objects.equal(this.hwVersion(), that.hwVersion())
+ && Objects.equal(this.swVersion(), that.swVersion())
+ && Objects.equal(this.serialNumber(), that.serialNumber())
+ && Objects.equal(this.chassisId(), that.chassisId())
+ && Objects.equal(this.cpus(), that.cpus())
+ && Objects.equal(this.nics(), that.nics())
+ && Objects.equal(this.isDefaultAvailable(), that.isDefaultAvailable());
+ }
+ return false;
+ }
+
+ // Default constructor for serialization
+ DefaultServerDeviceDescription() {
+ super(null, null, null, null, null, null, null, (SparseAnnotations[]) null);
+ this.cpus = null;
+ this.nics = null;
+ }
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/impl/devices/package-info.java b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/devices/package-info.java
new file mode 100644
index 0000000..c0ba64b
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/devices/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+/**
+ * Implementation of server devices.
+ */
+package org.onosproject.drivers.server.impl.devices;
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/impl/package-info.java b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/package-info.java
new file mode 100644
index 0000000..26be5bf
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+/**
+ * Implementation of server device drivers.
+ */
+package org.onosproject.drivers.server.impl;
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/impl/stats/DefaultCpuStatistics.java b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/stats/DefaultCpuStatistics.java
new file mode 100644
index 0000000..43b7273
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/stats/DefaultCpuStatistics.java
@@ -0,0 +1,182 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.impl.stats;
+
+import org.onosproject.drivers.server.stats.CpuStatistics;
+
+import org.onosproject.net.DeviceId;
+import com.google.common.base.MoreObjects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Default implementation for CPU statistics.
+ */
+public final class DefaultCpuStatistics implements CpuStatistics {
+
+ private static final float MIN_CPU_LOAD = (float) 0.0;
+ private static final float MAX_CPU_LOAD = (float) 1.0;
+
+ // Upper limit of CPU cores in one machine
+ public static final int MAX_CPU_NB = 512;
+
+ private final DeviceId deviceId;
+
+ private final int id;
+ private final float load;
+ private final boolean isBusy;
+
+ private DefaultCpuStatistics(
+ DeviceId deviceId,
+ int id,
+ float load,
+ boolean isBusy) {
+ checkNotNull(deviceId, "Device ID is NULL");
+ checkArgument(
+ (id >= 0) && (id < MAX_CPU_NB),
+ "CPU core ID must be in [0, " + String.valueOf(MAX_CPU_NB - 1) + "]"
+ );
+ checkArgument(
+ (load >= MIN_CPU_LOAD) && (load <= MAX_CPU_LOAD),
+ "CPU load must be in [" + MIN_CPU_LOAD + ", " + MAX_CPU_LOAD + "]"
+ );
+
+ this.deviceId = deviceId;
+ this.id = id;
+ this.load = load;
+ this.isBusy = isBusy;
+ }
+
+ // Constructor for serializer
+ private DefaultCpuStatistics() {
+ this.deviceId = null;
+ this.id = 0;
+ this.load = 0;
+ this.isBusy = false;
+ }
+
+ /**
+ * Creates a builder for DefaultCpuStatistics object.
+ *
+ * @return builder object for DefaultCpuStatistics object
+ */
+ public static DefaultCpuStatistics.Builder builder() {
+ return new Builder();
+ }
+
+ @Override
+ public int id() {
+ return this.id;
+ }
+
+ @Override
+ public float load() {
+ return this.load;
+ }
+
+ @Override
+ public boolean busy() {
+ return this.isBusy;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .omitNullValues()
+ .add("device", deviceId)
+ .add("id", id())
+ .add("load", load())
+ .add("isBusy", busy())
+ .toString();
+ }
+
+ public static final class Builder {
+
+ DeviceId deviceId;
+ int id;
+ float load;
+ boolean isBusy;
+
+ private Builder() {
+
+ }
+
+ /**
+ * Sets the device identifier.
+ *
+ * @param deviceId device identifier
+ * @return builder object
+ */
+ public Builder setDeviceId(DeviceId deviceId) {
+ this.deviceId = deviceId;
+
+ return this;
+ }
+
+ /**
+ * Sets the CPU ID.
+ *
+ * @param id the CPU ID
+ * @return builder object
+ */
+ public Builder setId(int id) {
+ this.id = id;
+
+ return this;
+ }
+
+ /**
+ * Sets the CPU load.
+ *
+ * @param load CPU load
+ * @return builder object
+ */
+ public Builder setLoad(float load) {
+ this.load = load;
+
+ return this;
+ }
+
+ /**
+ * Sets the CPU status (free or busy).
+ *
+ * @param isBusy CPU status
+ * @return builder object
+ */
+ public Builder setIsBusy(boolean isBusy) {
+ this.isBusy = isBusy;
+
+ return this;
+ }
+
+ /**
+ * Creates a DefaultCpuStatistics object.
+ *
+ * @return DefaultCpuStatistics object
+ */
+ public DefaultCpuStatistics build() {
+ return new DefaultCpuStatistics(
+ deviceId,
+ id,
+ load,
+ isBusy
+ );
+ }
+ }
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/impl/stats/DefaultMonitoringStatistics.java b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/stats/DefaultMonitoringStatistics.java
new file mode 100644
index 0000000..5c1ba99
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/stats/DefaultMonitoringStatistics.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.impl.stats;
+
+import org.onosproject.drivers.server.stats.CpuStatistics;
+import org.onosproject.drivers.server.stats.MonitoringStatistics;
+import org.onosproject.drivers.server.stats.TimingStatistics;
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.device.PortStatistics;
+
+import com.google.common.base.MoreObjects;
+
+import java.util.Collection;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Default monitoring statistics for server devices.
+ * Includes CPU, NIC, and timing statistics.
+ */
+public final class DefaultMonitoringStatistics implements MonitoringStatistics {
+
+ private final DeviceId deviceId;
+
+ private final TimingStatistics timingStatistics;
+ private final Collection<CpuStatistics> cpuStatistics;
+ private final Collection<PortStatistics> nicStatistics;
+
+ private DefaultMonitoringStatistics(
+ DeviceId deviceId,
+ TimingStatistics timingStatistics,
+ Collection<CpuStatistics> cpuStatistics,
+ Collection<PortStatistics> nicStatistics) {
+ checkNotNull(deviceId, "Device ID is NULL");
+ checkNotNull(timingStatistics, "Timing statistics are NULL");
+ checkNotNull(cpuStatistics, "CPU statistics are NULL");
+ checkNotNull(nicStatistics, "NIC statistics are NULL");
+
+ this.deviceId = deviceId;
+ this.timingStatistics = timingStatistics;
+ this.cpuStatistics = cpuStatistics;
+ this.nicStatistics = nicStatistics;
+ }
+
+ // Constructor for serializer
+ private DefaultMonitoringStatistics() {
+ this.deviceId = null;
+ this.timingStatistics = null;
+ this.cpuStatistics = null;
+ this.nicStatistics = null;
+ }
+
+ /**
+ * Creates a builder for DefaultMonitoringStatistics object.
+ *
+ * @return builder object for DefaultMonitoringStatistics object
+ */
+ public static DefaultMonitoringStatistics.Builder builder() {
+ return new Builder();
+ }
+
+ @Override
+ public TimingStatistics timingStatistics() {
+ return this.timingStatistics;
+ }
+
+ @Override
+ public Collection<CpuStatistics> cpuStatisticsAll() {
+ return this.cpuStatistics;
+ }
+
+ @Override
+ public CpuStatistics cpuStatistics(int cpuId) {
+ checkArgument(
+ (cpuId >= 0) && (cpuId < DefaultCpuStatistics.MAX_CPU_NB),
+ "CPU core ID must be in [0, " +
+ String.valueOf(DefaultCpuStatistics.MAX_CPU_NB - 1) + "]"
+ );
+ for (CpuStatistics cs : this.cpuStatistics) {
+ if (cs.id() == cpuId) {
+ return cs;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Collection<PortStatistics> nicStatisticsAll() {
+ return this.nicStatistics;
+ }
+
+ @Override
+ public PortStatistics nicStatistics(int nicId) {
+ checkArgument(nicId >= 0, "NIC ID must be a non-negative integer");
+ for (PortStatistics ns : this.nicStatistics) {
+ if (ns.port() == nicId) {
+ return ns;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public int numberOfNics() {
+ return this.nicStatistics.size();
+ }
+
+ @Override
+ public int numberOfCpus() {
+ return this.cpuStatistics.size();
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .omitNullValues()
+ .add("timingStatistics", timingStatistics())
+ .add("cpuStatistics", cpuStatisticsAll())
+ .add("nicStatistics", nicStatisticsAll())
+ .toString();
+ }
+
+ public static final class Builder {
+
+ DeviceId deviceId;
+ TimingStatistics timingStatistics;
+ Collection<CpuStatistics> cpuStatistics;
+ Collection<PortStatistics> nicStatistics;
+
+ private Builder() {
+
+ }
+
+ /**
+ * Sets the device identifier.
+ *
+ * @param deviceId device identifier
+ * @return builder object
+ */
+ public Builder setDeviceId(DeviceId deviceId) {
+ this.deviceId = deviceId;
+
+ return this;
+ }
+
+ /**
+ * Sets timing statistics.
+ *
+ * @param timingStatistics timing statistics
+ * @return builder object
+ */
+ public Builder setTimingStatistics(TimingStatistics timingStatistics) {
+ this.timingStatistics = timingStatistics;
+
+ return this;
+ }
+
+ /**
+ * Sets CPU statistics.
+ *
+ * @param cpuStatistics CPU statistics
+ * @return builder object
+ */
+ public Builder setCpuStatistics(Collection<CpuStatistics> cpuStatistics) {
+ this.cpuStatistics = cpuStatistics;
+
+ return this;
+ }
+
+ /**
+ * Sets NIC statistics.
+ *
+ * @param nicStatistics NIC statistics
+ * @return builder object
+ */
+ public Builder setNicStatistics(Collection<PortStatistics> nicStatistics) {
+ this.nicStatistics = nicStatistics;
+
+ return this;
+ }
+
+ /**
+ * Creates a MonitoringStatistics object.
+ *
+ * @return DefaultMonitoringStatistics object
+ */
+ public DefaultMonitoringStatistics build() {
+ return new DefaultMonitoringStatistics(
+ deviceId,
+ timingStatistics,
+ cpuStatistics,
+ nicStatistics
+ );
+ }
+
+ }
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/impl/stats/DefaultTimingStatistics.java b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/stats/DefaultTimingStatistics.java
new file mode 100644
index 0000000..8256c5f
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/stats/DefaultTimingStatistics.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.impl.stats;
+
+import org.onosproject.drivers.server.stats.TimingStatistics;
+
+import com.google.common.base.MoreObjects;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Default implementation for timing statistics.
+ */
+public final class DefaultTimingStatistics implements TimingStatistics {
+
+ private final long deployCommandParsingTime;
+ private final long deployCommandLaunchingTime;
+ private long autoscaleTime;
+
+ private DefaultTimingStatistics(
+ long parsingTime,
+ long launchingTime,
+ long autoscaleTime) {
+ checkArgument(parsingTime >= 0, "Parsing time is negative");
+ checkArgument(launchingTime >= 0, "Launching time is negative");
+ checkArgument(autoscaleTime >= 0, "Autoscale time is negative");
+
+ this.deployCommandParsingTime = parsingTime;
+ this.deployCommandLaunchingTime = launchingTime;
+ this.autoscaleTime = autoscaleTime;
+ }
+
+ // Constructor for serializer
+ private DefaultTimingStatistics() {
+ this.deployCommandParsingTime = 0;
+ this.deployCommandLaunchingTime = 0;
+ this.autoscaleTime = 0;
+ }
+
+ /**
+ * Creates a builder for DefaultTimingStatistics object.
+ *
+ * @return builder object for DefaultTimingStatistics object
+ */
+ public static DefaultTimingStatistics.Builder builder() {
+ return new Builder();
+ }
+
+ @Override
+ public long deployCommandParsingTime() {
+ return this.deployCommandParsingTime;
+ }
+
+ @Override
+ public long deployCommandLaunchingTime() {
+ return this.deployCommandLaunchingTime;
+ }
+
+ @Override
+ public long totalDeploymentTime() {
+ return this.deployCommandParsingTime + this.deployCommandLaunchingTime;
+ }
+
+ @Override
+ public long autoscaleTime() {
+ return this.autoscaleTime;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .omitNullValues()
+ .add("parsing", this.deployCommandParsingTime())
+ .add("launching", this.deployCommandLaunchingTime())
+ .add("total", this.totalDeploymentTime())
+ .add("autoscale", this.autoscaleTime())
+ .toString();
+ }
+
+ public static final class Builder {
+
+ long deployCommandParsingTime;
+ long deployCommandLaunchingTime;
+ long autoscaleTime;
+
+ private Builder() {
+
+ }
+
+ /**
+ * Sets parsing time.
+ *
+ * @param parsingTime parsing time
+ * @return builder object
+ */
+ public Builder setParsingTime(long parsingTime) {
+ this.deployCommandParsingTime = parsingTime;
+
+ return this;
+ }
+
+ /**
+ * Sets launching time.
+ *
+ * @param launchingTime launching time
+ * @return builder object
+ */
+ public Builder setLaunchingTime(long launchingTime) {
+ this.deployCommandLaunchingTime = launchingTime;
+
+ return this;
+ }
+
+ /**
+ * Sets autoscale time.
+ *
+ * @param autoscaleTime time required to autoscale
+ * @return builder object
+ */
+ public Builder setAutoscaleTime(long autoscaleTime) {
+ this.autoscaleTime = autoscaleTime;
+
+ return this;
+ }
+
+ /**
+ * Creates a DefaultTimingStatistics object.
+ *
+ * @return DefaultTimingStatistics object
+ */
+ public DefaultTimingStatistics build() {
+ return new DefaultTimingStatistics(
+ deployCommandParsingTime,
+ deployCommandLaunchingTime,
+ autoscaleTime
+ );
+ }
+ }
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/impl/stats/package-info.java b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/stats/package-info.java
new file mode 100644
index 0000000..92c0e7d
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/impl/stats/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+/**
+ * Implementation of server device statistics.
+ */
+package org.onosproject.drivers.server.impl.stats;
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/package-info.java b/drivers/server/src/main/java/org/onosproject/drivers/server/package-info.java
new file mode 100644
index 0000000..7b4fe77
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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 for server device drivers.
+ */
+package org.onosproject.drivers.server;
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/stats/CpuStatistics.java b/drivers/server/src/main/java/org/onosproject/drivers/server/stats/CpuStatistics.java
new file mode 100644
index 0000000..9ea22b3
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/stats/CpuStatistics.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.stats;
+
+/**
+ * CPU statistics API.
+ */
+public interface CpuStatistics {
+
+ /**
+ * Returns the ID of a CPU core.
+ *
+ * @return CPU core identifier
+ */
+ int id();
+
+ /**
+ * Returns the load of this CPU core.
+ * This is a value in [0, 1].
+ * Zero means no load, while one means fully loaded.
+ *
+ * @return load of a CPU core
+ */
+ float load();
+
+ /**
+ * Returns the status (true=busy, false=free) of a CPU core.
+ *
+ * @return boolean CPU core status
+ */
+ boolean busy();
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/stats/MonitoringStatistics.java b/drivers/server/src/main/java/org/onosproject/drivers/server/stats/MonitoringStatistics.java
new file mode 100644
index 0000000..c713d01
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/stats/MonitoringStatistics.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.stats;
+
+import org.onosproject.net.device.PortStatistics;
+
+import java.util.Collection;
+
+/**
+ * Server statistics API.
+ */
+public interface MonitoringStatistics {
+
+ /**
+ * Returns timing statistics related to
+ * tasks requested by the controller.
+ *
+ * @return timing statistics
+ */
+ TimingStatistics timingStatistics();
+
+ /**
+ * Returns the CPU statistics of a server device.
+ * Includes the statistics of all CPUs.
+ *
+ * @return CPU statistics
+ */
+ Collection<CpuStatistics> cpuStatisticsAll();
+
+ /**
+ * Returns the statistics of a particular CPU
+ * of a server device.
+ *
+ * @param cpuId ID of the CPU
+ * @return CpuStatistics object for this CPU
+ */
+ CpuStatistics cpuStatistics(int cpuId);
+
+ /**
+ * Returns the NIC statistics of a server device.
+ * Includes the statistics of all NICs.
+ *
+ * @return set of PortStatistics
+ */
+ Collection<PortStatistics> nicStatisticsAll();
+
+ /**
+ * Returns the statistics of a particular NIC
+ * of a server device.
+ *
+ * @param nicId ID of the NIC
+ * @return PortStatistics object for this NIC
+ */
+ PortStatistics nicStatistics(int nicId);
+
+ /**
+ * Returns the number of CPUs being monitored.
+ *
+ * @return number of CPUs
+ */
+ int numberOfCpus();
+
+ /**
+ * Returns the number of NICs being monitored.
+ *
+ * @return number of NICs
+ */
+ int numberOfNics();
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/stats/TimingStatistics.java b/drivers/server/src/main/java/org/onosproject/drivers/server/stats/TimingStatistics.java
new file mode 100644
index 0000000..102b186
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/stats/TimingStatistics.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server.stats;
+
+/**
+ * Timing statistics API.
+ */
+public interface TimingStatistics {
+
+ /**
+ * Time (ns) to parse the controller's deployment instruction.
+ *
+ * @return time in nanoseconds to parse a 'deploy' command
+ */
+ long deployCommandParsingTime();
+
+ /**
+ * Time (ns) to launch a slave process in the dataplane.
+ *
+ * @return time in nanoseconds to launch a 'deploy' command
+ */
+ long deployCommandLaunchingTime();
+
+ /**
+ * Time (ns) to parse + launch the controller's deployment instruction.
+ * This is the sum of the above two timers.
+ *
+ * @return time in nanoseconds to parse + launch a 'deploy' command
+ */
+ long totalDeploymentTime();
+
+ /**
+ * Time (ns) to perform a local reconfiguration.
+ * (i.e., the agent autoscales the number of CPUs).
+ *
+ * @return time in nanoseconds to autoscale
+ */
+ long autoscaleTime();
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/stats/package-info.java b/drivers/server/src/main/java/org/onosproject/drivers/server/stats/package-info.java
new file mode 100644
index 0000000..b50f763
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/stats/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+
+/**
+ * API for server device statistics.
+ */
+package org.onosproject.drivers.server.stats;
diff --git a/drivers/server/src/main/resources/server-drivers.xml b/drivers/server/src/main/resources/server-drivers.xml
new file mode 100644
index 0000000..3c97a9d
--- /dev/null
+++ b/drivers/server/src/main/resources/server-drivers.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-present Open Networking Foundation
+ ~
+ ~ 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.
+ -->
+<drivers>
+ <driver name="restServer" extends="default" manufacturer="GenuineIntel" hwVersion="Intel(R) Xeon(R) CPU E5-2667 v3 @ 3.20GHz" swVersion="Click 2.1">
+ <behaviour api="org.onosproject.net.behaviour.DevicesDiscovery"
+ impl="org.onosproject.drivers.server.ServerDevicesDiscovery"/>
+
+ <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
+ impl="org.onosproject.drivers.server.ServerDevicesDiscovery"/>
+
+ <behaviour api="org.onosproject.net.behaviour.ControllerConfig"
+ impl="org.onosproject.drivers.server.ServerControllerConfig"/>
+
+ <behaviour api="org.onosproject.net.device.PortStatisticsDiscovery"
+ impl="org.onosproject.drivers.server.ServerDevicesDiscovery"/>
+
+ <behaviour api="org.onosproject.drivers.server.behavior.CpuStatisticsDiscovery"
+ impl="org.onosproject.drivers.server.ServerDevicesDiscovery"/>
+
+ <behaviour api="org.onosproject.drivers.server.behavior.MonitoringStatisticsDiscovery"
+ impl="org.onosproject.drivers.server.ServerDevicesDiscovery"/>
+ </driver>
+</drivers>
+
+
diff --git a/drivers/server/src/test/java/org/onosproject/drivers/server/RestSBControllerMock.java b/drivers/server/src/test/java/org/onosproject/drivers/server/RestSBControllerMock.java
new file mode 100644
index 0000000..915c1bb
--- /dev/null
+++ b/drivers/server/src/test/java/org/onosproject/drivers/server/RestSBControllerMock.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.drivers.server;
+
+import org.onlab.packet.IpAddress;
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.ControllerInfo;
+import org.onosproject.protocol.rest.RestSBController;
+import org.onosproject.protocol.rest.RestSBDevice;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Set;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test class for REST SB controller.
+ */
+public class RestSBControllerMock implements RestSBController {
+ /**
+ * Local memory of devices.
+ */
+ private Map<DeviceId, RestSBDevice> deviceMap = new ConcurrentHashMap<>();
+
+ /**
+ * Objects to populate our memory.
+ */
+ private DeviceId restDeviceId1;
+ private RestSBDevice restDevice1;
+ private static List<ControllerInfo> controllers;
+
+ /**
+ * Parameters to be exchanged with the server's agent.
+ */
+ private static final String PARAM_CTRL = "controllers";
+ private static final String PARAM_CTRL_IP = "ip";
+ private static final String PARAM_CTRL_PORT = "port";
+ private static final String PARAM_CTRL_TYPE = "type";
+
+ public RestSBControllerMock() {
+ restDeviceId1 = TestConfig.REST_DEV_ID1;
+ assertThat(restDeviceId1, notNullValue());
+
+ restDevice1 = TestConfig.REST_DEV1;
+ assertThat(restDevice1, notNullValue());
+
+ controllers = TestConfig.CONTROLLERS;
+ assertThat(controllers, notNullValue());
+
+ deviceMap.put(restDeviceId1, restDevice1);
+ }
+
+ @Override
+ public void addProxiedDevice(DeviceId deviceId, RestSBDevice proxy) {
+ return;
+ }
+
+ @Override
+ public void removeProxiedDevice(DeviceId deviceId) {
+ return;
+ }
+
+ @Override
+ public Set<DeviceId> getProxiedDevices(DeviceId proxyId) {
+ return null;
+ }
+
+ @Override
+ public RestSBDevice getProxySBDevice(DeviceId deviceId) {
+ return null;
+ }
+
+ @Override
+ public Map<DeviceId, RestSBDevice> getDevices() {
+ return null;
+ }
+
+ @Override
+ public RestSBDevice getDevice(DeviceId deviceInfo) {
+ return null;
+ }
+
+ @Override
+ public RestSBDevice getDevice(IpAddress ip, int port) {
+ return null;
+ }
+
+ @Override
+ public void addDevice(RestSBDevice device) {
+ return;
+ }
+
+ @Override
+ public void removeDevice(DeviceId deviceId) {
+ return;
+ }
+
+ @Override
+ public InputStream get(DeviceId device, String request, MediaType mediaType) {
+ /**
+ * We fake the HTTP get in order to
+ * emulate the expected response.
+ */
+ ObjectMapper mapper = new ObjectMapper();
+
+ // Create the object node to host the data
+ ObjectNode sendObjNode = mapper.createObjectNode();
+
+ // Insert header
+ ArrayNode ctrlsArrayNode = sendObjNode.putArray(PARAM_CTRL);
+
+ // Add each controller's information object
+ for (ControllerInfo ctrl : controllers) {
+ ObjectNode ctrlObjNode = mapper.createObjectNode();
+ ctrlObjNode.put(PARAM_CTRL_IP, ctrl.ip().toString());
+ ctrlObjNode.put(PARAM_CTRL_PORT, ctrl.port());
+ ctrlObjNode.put(PARAM_CTRL_TYPE, ctrl.type());
+ ctrlsArrayNode.add(ctrlObjNode);
+ }
+
+ return new ByteArrayInputStream(sendObjNode.toString().getBytes());
+ }
+
+ @Override
+ public int post(DeviceId device, String request, InputStream payload, MediaType mediaType) {
+ return Response.Status.OK.getStatusCode();
+ }
+
+ @Override
+ public int put(DeviceId device, String request, InputStream payload, MediaType mediaType) {
+ return Response.Status.OK.getStatusCode();
+ }
+
+ @Override
+ public int patch(DeviceId device, String request, InputStream payload, MediaType mediaType) {
+ return Response.Status.OK.getStatusCode();
+ }
+
+ @Override
+ public int delete(DeviceId device, String request, InputStream payload, MediaType mediaType) {
+ return Response.Status.OK.getStatusCode();
+ }
+
+ @Override
+ public <T> T post(DeviceId device, String request, InputStream payload,
+ MediaType mediaType, Class<T> responseClass) {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/drivers/server/src/test/java/org/onosproject/drivers/server/ServerControllerConfigTest.java b/drivers/server/src/test/java/org/onosproject/drivers/server/ServerControllerConfigTest.java
new file mode 100644
index 0000000..add6e03
--- /dev/null
+++ b/drivers/server/src/test/java/org/onosproject/drivers/server/ServerControllerConfigTest.java
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.drivers.server;
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.ControllerConfig;
+import org.onosproject.net.behaviour.ControllerInfo;
+import org.onosproject.net.driver.Behaviour;
+import org.onosproject.net.driver.DefaultDriverData;
+import org.onosproject.net.driver.Driver;
+import org.onosproject.net.driver.DriverData;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.net.driver.DriverService;
+import org.onosproject.net.driver.DriverServiceAdapter;
+import org.onosproject.mastership.MastershipServiceAdapter;
+import org.onosproject.mastership.MastershipService;
+import org.onosproject.protocol.rest.RestSBController;
+import org.onosproject.protocol.rest.RestSBDevice;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Unit tests for methods of ServerControllerConfig.
+ */
+public class ServerControllerConfigTest {
+
+ // Device information used during the tests
+ private static final String REST_SCHEME = "rest";
+ private static final String REST_DEV_TEST_IP_1 = "10.0.0.1";
+ private static final int REST_TEST_PORT = 80;
+
+ // Controller information used during the tests
+ private static final String REST_CTRL_TEST_IP_1 = "10.0.0.253";
+ private static final String REST_CTRL_TEST_IP_2 = "10.0.0.254";
+ private static final String REST_CTRL_TEST_TYPE = "tcp";
+ private static List<ControllerInfo> controllers;
+
+ // Device used during the tests
+ private DeviceId restDeviceId1;
+ private RestSBDevice restDevice1;
+
+ // Test Driver service used during the tests
+ private DriverService driverService;
+
+ // Test mastership service used during the tests
+ private MastershipService mastershipService;
+
+ // Test Rest SB controller used during the tests
+ private RestSBController controller;
+
+ @Before
+ public void setUp() throws Exception {
+ restDeviceId1 = TestConfig.REST_DEV_ID1;
+ assertThat(restDeviceId1, notNullValue());
+
+ restDevice1 = TestConfig.REST_DEV1;
+ assertThat(restDevice1, notNullValue());
+
+ controllers = TestConfig.CONTROLLERS;
+ assertThat(controllers, notNullValue());
+
+ driverService = new TestDriverService();
+ mastershipService = new TestMastershipService();
+ controller = new RestSBControllerMock();
+ }
+
+ /**
+ * Test of setControllers().
+ */
+ @Test
+ public void testSetControllers() {
+ // Get device handler
+ DriverHandler driverHandler = null;
+ try {
+ driverHandler = driverService.createHandler(restDeviceId1);
+ } catch (Exception e) {
+ throw e;
+ }
+ assertThat(driverHandler, notNullValue());
+
+ // TODO: Fix this test
+ }
+
+ /**
+ * Test of getControllers().
+ */
+ @Test
+ public void testGetControllers() {
+ // Get device handler
+ DriverHandler driverHandler = null;
+ try {
+ driverHandler = driverService.createHandler(restDeviceId1);
+ } catch (Exception e) {
+ throw e;
+ }
+ assertThat(driverHandler, notNullValue());
+
+ // Ask for the controllers of this device
+ List<ControllerInfo> receivedControllers = null;
+
+ // TODO: Fix this test
+ }
+
+ /**
+ * Test class for driver handler.
+ */
+ private class TestDriverHandler implements DriverHandler {
+
+ private final DeviceId deviceId;
+
+ TestDriverHandler(DeviceId deviceId) {
+ this.deviceId = deviceId;
+ }
+
+ @Override
+ public Driver driver() {
+ return null;
+ }
+
+ @Override
+ public DriverData data() {
+ // Just create a fake driver data
+ return new DefaultDriverData(null, deviceId);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <T extends Behaviour> T behaviour(Class<T> behaviourClass) {
+ // Let's create the behavior
+ ControllerConfig controllerConfing = null;
+ try {
+ controllerConfing = new ServerControllerConfig();
+ } catch (Exception e) {
+ // Do nothing
+ }
+
+ if (controllerConfing == null) {
+ return null;
+ }
+
+ // Set the handler
+ controllerConfing.setHandler(this);
+
+ // Done, return the behavior
+ return (T) controllerConfing;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <T> T get(Class<T> serviceClass) {
+ if (serviceClass == MastershipService.class) {
+ return (T) mastershipService;
+ } else if (serviceClass == RestSBController.class) {
+ return (T) controller;
+ }
+ return null;
+ }
+
+ @Override
+ public boolean hasBehaviour(Class<? extends Behaviour> behaviourClass) {
+ return true;
+ }
+ }
+
+ /**
+ * Test class for driver service.
+ */
+ private class TestDriverService extends DriverServiceAdapter {
+ @Override
+ public DriverHandler createHandler(DeviceId deviceId, String... credentials) {
+ return new TestDriverHandler(deviceId);
+ }
+
+ }
+
+ /**
+ * Test class for mastership service.
+ */
+ private final class TestMastershipService extends MastershipServiceAdapter {
+ @Override
+ public boolean isLocalMaster(DeviceId deviceId) {
+ return true;
+ }
+ }
+
+}
diff --git a/drivers/server/src/test/java/org/onosproject/drivers/server/ServerDriversLoaderTest.java b/drivers/server/src/test/java/org/onosproject/drivers/server/ServerDriversLoaderTest.java
new file mode 100644
index 0000000..0ca21f3
--- /dev/null
+++ b/drivers/server/src/test/java/org/onosproject/drivers/server/ServerDriversLoaderTest.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.drivers.server;
+
+import org.junit.Before;
+import org.onosproject.net.driver.AbstractDriverLoaderTest;
+
+/**
+ * Commodity server drivers loader test.
+ */
+public class ServerDriversLoaderTest extends AbstractDriverLoaderTest {
+
+ @Before
+ public void setUp() {
+ loader = new ServerDriversLoader();
+ }
+}
diff --git a/drivers/server/src/test/java/org/onosproject/drivers/server/TestConfig.java b/drivers/server/src/test/java/org/onosproject/drivers/server/TestConfig.java
new file mode 100644
index 0000000..4a7ecbf
--- /dev/null
+++ b/drivers/server/src/test/java/org/onosproject/drivers/server/TestConfig.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.drivers.server;
+
+import org.onlab.packet.IpAddress;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.ControllerInfo;
+import org.onosproject.protocol.rest.DefaultRestSBDevice;
+import org.onosproject.protocol.rest.RestSBDevice;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Common configuration for testing.
+ */
+public class TestConfig {
+
+ /**
+ * No need for a constructor, methods are static.
+ */
+ protected TestConfig() {}
+
+ /**
+ * Device information used during the tests.
+ */
+ public static final String REST_SCHEME = "rest";
+ public static final String REST_DEV_TEST_IP_1 = "10.0.0.1";
+ public static final int REST_TEST_PORT = 80;
+
+ public static final DeviceId REST_DEV_ID1 = DeviceId.deviceId(
+ REST_SCHEME + ":" + REST_DEV_TEST_IP_1 + ":" + REST_TEST_PORT
+ );
+ public static final RestSBDevice REST_DEV1 = new DefaultRestSBDevice(
+ IpAddress.valueOf(REST_DEV_TEST_IP_1),
+ REST_TEST_PORT,
+ "foo", "bar", "http", null, true
+ );
+
+ /**
+ * Controller information used during the tests.
+ */
+ public static final String REST_CTRL_TEST_IP_1 = "10.0.0.253";
+ public static final String REST_CTRL_TEST_IP_2 = "10.0.0.254";
+ public static final String REST_CTRL_TEST_TYPE = "tcp";
+
+ public static final List<ControllerInfo> CONTROLLERS = Arrays.asList(
+ new ControllerInfo(
+ IpAddress.valueOf(REST_CTRL_TEST_IP_1),
+ REST_TEST_PORT,
+ REST_CTRL_TEST_TYPE
+ ),
+ new ControllerInfo(
+ IpAddress.valueOf(REST_CTRL_TEST_IP_2),
+ REST_TEST_PORT,
+ REST_CTRL_TEST_TYPE
+ )
+ );
+
+}