use of org.onosproject.drivers.server.devices.nic.NicDevice in project onos by opennetworkinglab.
the class ServerDevicesDiscovery method getDeviceDetails.
/**
* 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) {
// Retrieve the device ID, if null given
if (deviceId == null) {
deviceId = getDeviceId();
checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
}
// Get the device
RestSBDevice device = getDevice(deviceId);
checkNotNull(device, MSG_DEVICE_NULL);
// Hit the path that provides the server's resources
InputStream response = null;
try {
response = getController().get(deviceId, URL_SRV_RESOURCE_DISCOVERY, JSON);
} catch (ProcessingException pEx) {
log.error("Failed to discover the device details of: {}", deviceId);
return null;
}
// 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 null;
}
if (jsonMap == null) {
log.error("Failed to discover the device details of: {}", deviceId);
return null;
}
// 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);
long chassisId = objNode.path(PARAM_CHASSIS_ID).asLong();
// Pass the southbound protocol as an annotation
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
annotations.set(AnnotationKeys.PROTOCOL, "REST");
// Parse CPU devices
Collection<CpuDevice> cpuSet = parseCpuDevices(objNode);
// Parse memory hierarchy device
MemoryHierarchyDevice memHierarchyDev = parseMemoryHierarchyDevice(objNode);
// Parse CPU cache hierachy device
CpuCacheHierarchyDevice cacheHierarchyDev = parseCpuCacheHierarchyDevice(objNode);
// NICs are composite attributes too
Collection<NicDevice> nicSet = parseNicDevices(mapper, objNode, annotations);
// Construct a server device,
// i.e., a RestSBDevice extended with CPU, cache, memory, and NIC information
RestServerSBDevice dev = new DefaultRestServerSBDevice(device.ip(), device.port(), device.username(), device.password(), device.protocol(), device.url(), device.isActive(), device.testUrl().orElse(""), vendor, hw, sw, cpuSet, cacheHierarchyDev, memHierarchyDev, nicSet);
checkNotNull(dev, MSG_DEVICE_NULL);
// Set alive
raiseDeviceReconnect(dev);
// Updates the controller with the complete device information
getController().removeDevice(deviceId);
getController().addDevice((RestSBDevice) dev);
// Create a description for this server device
ServerDeviceDescription desc = null;
try {
desc = new DefaultServerDeviceDescription(new URI(id), Device.Type.SERVER, vendor, hw, sw, serial, new ChassisId(chassisId), cpuSet, cacheHierarchyDev, memHierarchyDev, nicSet, annotations.build());
} 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;
}
use of org.onosproject.drivers.server.devices.nic.NicDevice in project onos by opennetworkinglab.
the class ServerDevicesDiscovery method discoverPortDetails.
@Override
public List<PortDescription> discoverPortDetails() {
// Retrieve the device ID
DeviceId deviceId = getDeviceId();
checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
// .. and object
RestServerSBDevice device = null;
try {
device = (RestServerSBDevice) getDevice(deviceId);
} catch (ClassCastException ccEx) {
log.error("Failed to discover ports for device {}", deviceId);
return Collections.EMPTY_LIST;
}
if (device == null) {
log.error("No device with ID {} is available for port discovery", deviceId);
return Collections.EMPTY_LIST;
}
if ((device.nics() == null) || (device.nics().size() == 0)) {
log.error("No ports available on {}", deviceId);
return Collections.EMPTY_LIST;
}
// List of port descriptions to return
List<PortDescription> portDescriptions = Lists.newArrayList();
// Sorted list of NIC ports
Set<NicDevice> nics = new TreeSet(device.nics());
// Iterate through the NICs of this device to populate the list
for (NicDevice nic : nics) {
// Include the name of this device as an annotation
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, nic.name());
// Create a port description and add it to the list
portDescriptions.add(DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(nic.portNumber())).isEnabled(nic.status()).type(nic.portType()).portSpeed(nic.speed()).annotations(annotations.build()).build());
log.info("Port discovery on device {}: NIC {} is {} at {} Mbps", deviceId, nic.portNumber(), nic.status() ? "up" : "down", nic.speed());
}
return ImmutableList.copyOf(portDescriptions);
}
use of org.onosproject.drivers.server.devices.nic.NicDevice in project onos by opennetworkinglab.
the class ServerPortAdmin method isEnabled.
@Override
public CompletableFuture<Boolean> isEnabled(PortNumber number) {
// Retrieve the device ID
DeviceId deviceId = super.getDeviceId();
checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
// ...and the device itself
RestServerSBDevice device = null;
try {
device = (RestServerSBDevice) getDevice(deviceId);
} catch (ClassCastException ccEx) {
log.error("Failed to discover ports for device {}", deviceId);
return completedFuture(false);
}
// Iterate server's NICs to find the correct port
for (NicDevice nic : device.nics()) {
if (nic.portNumber() == number.toLong()) {
return completedFuture(nic.status());
}
}
return completedFuture(false);
}
use of org.onosproject.drivers.server.devices.nic.NicDevice in project onos by opennetworkinglab.
the class ServerInterfaceConfig method getInterfaces.
@Override
public List<DeviceInterfaceDescription> getInterfaces() {
// Retrieve the device ID
DeviceId deviceId = getDeviceId();
checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
// .. and the device itself
RestServerSBDevice device = null;
try {
device = (RestServerSBDevice) getDevice(deviceId);
} catch (ClassCastException ccEx) {
log.error("Failed to get interfaces for device {}", deviceId);
return Collections.EMPTY_LIST;
}
if (device == null) {
log.error("No device with ID {} is available for interface discovery", deviceId);
return Collections.EMPTY_LIST;
}
if ((device.nics() == null) || (device.nics().size() == 0)) {
log.error("No interfaces available on {}", deviceId);
return Collections.EMPTY_LIST;
}
// List of port descriptions to return
List<DeviceInterfaceDescription> intfDescriptions = Lists.newArrayList();
// Sorted list of NIC ports
Set<NicDevice> nics = new TreeSet(device.nics());
// Iterate through the NICs of this device to populate the list
for (NicDevice nic : nics) {
List<VlanId> devVlanIds = getVlanIdListForDevice(nic);
Mode devMode = getDeviceMode(devVlanIds);
// Create an interface description and add it to the list
intfDescriptions.add(new DefaultDeviceInterfaceDescription(nic.name(), devMode, devVlanIds, RATE_LIMIT_STATUS, NO_LIMIT));
}
return ImmutableList.copyOf(intfDescriptions);
}
use of org.onosproject.drivers.server.devices.nic.NicDevice in project onos by opennetworkinglab.
the class ServerDevicesDiscovery method parseNicDevices.
/**
* Parse the input JSON object, looking for NIC-related
* information. Upon success, construct and return a list
* of NIC devices.
*
* @param mapper input JSON object mapper
* @param objNode input JSON node with NIC device information
* @param annotations device annotations
* @return list of CPU devices
*/
private Collection<NicDevice> parseNicDevices(ObjectMapper mapper, ObjectNode objNode, DefaultAnnotations.Builder annotations) {
Collection<NicDevice> nicSet = Sets.newHashSet();
JsonNode nicNode = objNode.path(PARAM_NICS);
// Construct NIC objects
for (JsonNode nn : nicNode) {
ObjectNode nicObjNode = (ObjectNode) nn;
// All the NIC attributes
String nicName = get(nn, PARAM_NAME);
long nicIndex = nicObjNode.path(PARAM_ID).asLong();
long speed = nicObjNode.path(PARAM_SPEED).asLong();
String portTypeStr = get(nn, PARAM_NIC_PORT_TYPE);
boolean status = nicObjNode.path(PARAM_STATUS).asInt() > 0;
String hwAddr = get(nn, PARAM_NIC_HW_ADDR);
JsonNode tagNode = nicObjNode.path(PARAM_NIC_RX_FILTER);
if (tagNode == null) {
throw new IllegalArgumentException("The Rx filters of NIC " + nicName + " 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;
}
// Store NIC name to number mapping as an annotation
annotations.set(nicName, Long.toString(nicIndex));
// Construct a NIC device and add it to the set
nicSet.add(DefaultNicDevice.builder().setName(nicName).setPortNumber(nicIndex).setPortNumber(nicIndex).setPortType(portTypeStr).setSpeed(speed).setStatus(status).setMacAddress(hwAddr).setRxFilters(rxFilters).build());
}
return nicSet;
}
Aggregations