use of org.onosproject.protocol.rest.RestSBDevice in project onos by opennetworkinglab.
the class ServerTableStatisticsDiscovery method getTableStatistics.
@Override
public List<TableStatisticsEntry> getTableStatistics() {
// Retrieve the device ID from the handler
DeviceId deviceId = super.getDeviceId();
checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
// Get the device
RestSBDevice device = super.getDevice(deviceId);
checkNotNull(device, MSG_DEVICE_NULL);
// Hit the path that provides the server's NIC table statistics
InputStream response = null;
try {
response = getController().get(deviceId, URL_RULE_TABLE_STATS, JSON);
} catch (ProcessingException pEx) {
log.error("Failed to get NIC table statistics from device: {}", deviceId);
return Collections.EMPTY_LIST;
}
// Load the JSON into object
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 NIC table statistics from device: {}", deviceId);
return Collections.EMPTY_LIST;
}
if (jsonNode == null) {
log.error("Failed to get NIC table statistics from device: {}", deviceId);
return Collections.EMPTY_LIST;
}
List<TableStatisticsEntry> tableStats = Lists.newArrayList();
JsonNode nicNode = objNode.path(PARAM_NICS);
for (JsonNode nn : nicNode) {
ObjectNode nicObjNode = (ObjectNode) nn;
// The index of the NIC that hosts rules table(s)
long nicIndex = nicObjNode.path(Constants.PARAM_ID).asLong();
JsonNode tableNode = nicObjNode.path(PARAM_NIC_TABLE);
if (tableNode == null) {
throw new IllegalArgumentException("No tables reported for NIC " + nicIndex);
}
for (JsonNode tn : tableNode) {
ObjectNode tableObjNode = (ObjectNode) tn;
// NIC table attributes
int tableIndex = tableObjNode.path(PARAM_ID).asInt();
checkArgument(tableIndex >= 0, MSG_NIC_TABLE_INDEX_NEGATIVE);
long tableActiveEntries = tableObjNode.path(PARAM_NIC_TABLE_ACTIVE_ENTRIES).asLong();
checkArgument(tableActiveEntries >= 0, MSG_NIC_TABLE_COUNTER_NEGATIVE);
long tablePktsLookedUp = tableObjNode.path(PARAM_NIC_TABLE_PKTS_LOOKED_UP).asLong();
checkArgument(tablePktsLookedUp >= 0, MSG_NIC_TABLE_COUNTER_NEGATIVE);
long tablePktsMatched = tableObjNode.path(PARAM_NIC_TABLE_PKTS_MATCHED).asLong();
checkArgument(tablePktsMatched >= 0, MSG_NIC_TABLE_COUNTER_NEGATIVE);
long tableMaxsize = tableObjNode.path(PARAM_NIC_TABLE_MAX_SIZE).asLong();
checkArgument(tableMaxsize >= 0, MSG_NIC_TABLE_SIZE_NEGATIVE);
// Server's device ID and NIC ID compose a NIC device ID
DeviceId nicDeviceId = DeviceId.deviceId(deviceId.toString() + ":nic" + String.valueOf(nicIndex));
TableStatisticsEntry tableStat = DefaultTableStatisticsEntry.builder().withDeviceId(nicDeviceId).withTableId(IndexTableId.of(tableIndex)).withActiveFlowEntries(tableActiveEntries).withPacketsLookedUpCount(tablePktsLookedUp).withPacketsMatchedCount(tablePktsMatched).withMaxSize(tableMaxsize > 0 ? tableMaxsize : -1).build();
tableStats.add(tableStat);
log.debug("[Device {}] NIC {} with table statistics: {}", deviceId, nicIndex, tableStat);
}
}
return ImmutableList.copyOf(tableStats);
}
use of org.onosproject.protocol.rest.RestSBDevice in project onos by opennetworkinglab.
the class RestDeviceProvider method roleChanged.
@Override
public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
log.debug("Received role {} request for device {}", newRole, deviceId);
RestSBDevice device = controller.getDevice(deviceId);
if (device != null && testDeviceConnection(device)) {
providerService.receivedRoleReply(deviceId, newRole, newRole);
} else {
log.warn("Device not present or available {}", deviceId);
providerService.receivedRoleReply(deviceId, newRole, MastershipRole.NONE);
}
}
use of org.onosproject.protocol.rest.RestSBDevice in project onos by opennetworkinglab.
the class RestDeviceProvider method getDesc.
private DeviceDescription getDesc(RestSBDevice restSBDev) {
DeviceId deviceId = restSBDev.deviceId();
Driver driver = getDriver(restSBDev);
if (restSBDev.isProxy()) {
if (driver != null && driver.hasBehaviour(DevicesDiscovery.class)) {
// Creates the driver to communicate with the server
DevicesDiscovery devicesDiscovery = devicesDiscovery(restSBDev, driver);
return devicesDiscovery.deviceDetails(deviceId);
} else {
log.warn("Driver not found for {}", restSBDev);
return null;
}
} else if (driver != null && driver.hasBehaviour(DeviceDescriptionDiscovery.class)) {
DriverHandler h = driverService.createHandler(deviceId);
DeviceDescriptionDiscovery deviceDiscovery = h.behaviour(DeviceDescriptionDiscovery.class);
return deviceDiscovery.discoverDeviceDetails();
}
ChassisId cid = new ChassisId();
String ipAddress = restSBDev.ip().toString();
SparseAnnotations annotations = DefaultAnnotations.builder().set(IPADDRESS, ipAddress).set(AnnotationKeys.PROTOCOL, REST.toUpperCase()).build();
String manufacturer = UNKNOWN;
String hwVersion = UNKNOWN;
String swVersion = UNKNOWN;
String serialNumber = UNKNOWN;
Device device = deviceService.getDevice(deviceId);
if (device != null) {
manufacturer = device.manufacturer();
hwVersion = device.hwVersion();
swVersion = device.swVersion();
serialNumber = device.serialNumber();
}
return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, manufacturer, hwVersion, swVersion, serialNumber, cid, annotations);
}
Aggregations