use of org.onosproject.drivers.server.devices.RestServerSBDevice 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.RestServerSBDevice 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.RestServerSBDevice in project onos by opennetworkinglab.
the class ServerDevicesDiscovery method parseNicStatistics.
/**
* 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) {
if ((deviceId == null) || (objNode == null)) {
return Collections.EMPTY_LIST;
}
RestServerSBDevice device = null;
try {
device = (RestServerSBDevice) getDevice(deviceId);
} catch (ClassCastException ccEx) {
return Collections.EMPTY_LIST;
}
if (device == null) {
return Collections.EMPTY_LIST;
}
Collection<PortStatistics> nicStats = Lists.newArrayList();
JsonNode nicNode = objNode.path(PARAM_NICS);
if (nicNode.isMissingNode()) {
return nicStats;
}
for (JsonNode nn : nicNode) {
ObjectNode nicObjNode = (ObjectNode) nn;
// All the NIC attributes
String nicName = get(nn, PARAM_NAME);
checkArgument(!Strings.isNullOrEmpty(nicName), MSG_NIC_NAME_NULL);
long portNumber = device.portNumberFromName(nicName);
checkArgument(portNumber >= 0, MSG_NIC_PORT_NUMBER_NEGATIVE);
long rxCount = nicObjNode.path(PARAM_NIC_STATS_RX_COUNT).asLong();
long rxBytes = nicObjNode.path(PARAM_NIC_STATS_RX_BYTES).asLong();
long rxDropped = nicObjNode.path(PARAM_NIC_STATS_RX_DROPS).asLong();
long rxErrors = nicObjNode.path(PARAM_NIC_STATS_RX_ERRORS).asLong();
long txCount = nicObjNode.path(PARAM_NIC_STATS_TX_COUNT).asLong();
long txBytes = nicObjNode.path(PARAM_NIC_STATS_TX_BYTES).asLong();
long txDropped = nicObjNode.path(PARAM_NIC_STATS_TX_DROPS).asLong();
long txErrors = nicObjNode.path(PARAM_NIC_STATS_TX_ERRORS).asLong();
// Construct a NIC statistics object and add it to the set
nicStats.add(DefaultPortStatistics.builder().setDeviceId(deviceId).setPort(PortNumber.portNumber(portNumber)).setPacketsReceived(rxCount).setPacketsSent(txCount).setBytesReceived(rxBytes).setBytesSent(txBytes).setPacketsRxDropped(rxDropped).setPacketsRxErrors(rxErrors).setPacketsTxDropped(txDropped).setPacketsTxErrors(txErrors).build());
}
return nicStats;
}
Aggregations