use of org.onosproject.net.flow.TableStatisticsEntry 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.net.flow.TableStatisticsEntry in project onos by opennetworkinglab.
the class StatisticsWebResource method getTableStatistics.
/**
* Gets table statistics for all tables of all devices.
*
* @onos.rsModel StatisticsFlowsTables
* @return 200 OK with JSON encoded array of table statistics
*/
@GET
@Path("flows/tables")
@Produces(MediaType.APPLICATION_JSON)
public Response getTableStatistics() {
final FlowRuleService service = get(FlowRuleService.class);
final Iterable<Device> devices = get(DeviceService.class).getDevices();
final ObjectNode root = mapper().createObjectNode();
final ArrayNode rootArrayNode = root.putArray("statistics");
for (final Device device : devices) {
final ObjectNode deviceStatsNode = mapper().createObjectNode();
deviceStatsNode.put("device", device.id().toString());
final ArrayNode statisticsNode = deviceStatsNode.putArray("table");
final Iterable<TableStatisticsEntry> tableStatsEntries = service.getFlowTableStatistics(device.id());
if (tableStatsEntries != null) {
for (final TableStatisticsEntry entry : tableStatsEntries) {
statisticsNode.add(codec(TableStatisticsEntry.class).encode(entry, this));
}
}
rootArrayNode.add(deviceStatsNode);
}
return ok(root).build();
}
use of org.onosproject.net.flow.TableStatisticsEntry in project onos by opennetworkinglab.
the class StatisticsWebResource method getTableStatisticsByDeviceId.
/**
* Gets table statistics for all tables of a specified device.
*
* @onos.rsModel StatisticsFlowsTables
* @param deviceId device ID
* @return 200 OK with JSON encoded array of table statistics
*/
@GET
@Path("flows/tables/{deviceId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getTableStatisticsByDeviceId(@PathParam("deviceId") String deviceId) {
final FlowRuleService service = get(FlowRuleService.class);
final Iterable<TableStatisticsEntry> tableStatisticsEntries = service.getFlowTableStatistics(DeviceId.deviceId(deviceId));
final ObjectNode root = mapper().createObjectNode();
final ArrayNode rootArrayNode = root.putArray("statistics");
final ObjectNode deviceStatsNode = mapper().createObjectNode();
deviceStatsNode.put("device", deviceId);
final ArrayNode statisticsNode = deviceStatsNode.putArray("table");
for (final TableStatisticsEntry entry : tableStatisticsEntries) {
statisticsNode.add(codec(TableStatisticsEntry.class).encode(entry, this));
}
rootArrayNode.add(deviceStatsNode);
return ok(root).build();
}
use of org.onosproject.net.flow.TableStatisticsEntry in project onos by opennetworkinglab.
the class DefaultOFSwitch method processStatsRequest.
@Override
public void processStatsRequest(Channel channel, OFMessage msg) {
if (msg.getType() != OFType.STATS_REQUEST) {
log.warn("Ignoring message of type {}.", msg.getType());
return;
}
OFStatsRequest ofStatsRequest = (OFStatsRequest) msg;
OFStatsReply ofStatsReply = null;
switch(ofStatsRequest.getStatsType()) {
case PORT_DESC:
List<OFPortDesc> portDescs = new ArrayList<>();
Set<Port> ports = ofSwitchService.ports(networkId, deviceId);
ports.forEach(port -> {
OFPortDesc ofPortDesc = portDesc(port);
portDescs.add(ofPortDesc);
});
ofStatsReply = FACTORY.buildPortDescStatsReply().setXid(msg.getXid()).setEntries(portDescs).build();
break;
case PORT:
OFPortStatsRequest portStatsRequest = (OFPortStatsRequest) msg;
OFPort ofPort = portStatsRequest.getPortNo();
List<OFPortStatsEntry> portStatsEntries = new ArrayList<>();
List<PortStatistics> portStatistics = ofSwitchService.getPortStatistics(networkId, deviceId);
if (ofPort.equals(OFPort.ANY)) {
portStatistics.forEach(portStatistic -> {
OFPortStatsEntry ofPortStatsEntry = portStatsEntry(portStatistic);
portStatsEntries.add(ofPortStatsEntry);
});
}
ofStatsReply = FACTORY.buildPortStatsReply().setEntries(portStatsEntries).setXid(msg.getXid()).build();
break;
case METER_FEATURES:
OFMeterFeatures ofMeterFeatures = FACTORY.buildMeterFeatures().build();
ofStatsReply = FACTORY.buildMeterFeaturesStatsReply().setXid(msg.getXid()).setFeatures(ofMeterFeatures).build();
break;
case FLOW:
List<OFFlowStatsEntry> flowStatsEntries = new ArrayList<>();
List<FlowEntry> flowStats = ofSwitchService.getFlowEntries(networkId, deviceId);
flowStats.forEach(flowEntry -> {
OFFlowStatsEntry ofFlowStatsEntry = ofFlowStatsEntry(flowEntry);
flowStatsEntries.add(ofFlowStatsEntry);
});
ofStatsReply = FACTORY.buildFlowStatsReply().setEntries(flowStatsEntries).setXid(msg.getXid()).build();
break;
case TABLE:
List<OFTableStatsEntry> ofTableStatsEntries = new ArrayList<>();
List<TableStatisticsEntry> tableStats = ofSwitchService.getFlowTableStatistics(networkId, deviceId);
tableStats.forEach(tableStatisticsEntry -> {
OFTableStatsEntry ofFlowStatsEntry = ofFlowTableStatsEntry(tableStatisticsEntry);
ofTableStatsEntries.add(ofFlowStatsEntry);
});
ofStatsReply = FACTORY.buildTableStatsReply().setEntries(ofTableStatsEntries).setXid(msg.getXid()).build();
break;
case GROUP:
List<Group> groupStats = ofSwitchService.getGroups(networkId, deviceId);
List<OFGroupStatsEntry> ofGroupStatsEntries = new ArrayList<>();
groupStats.forEach(group -> {
OFGroupStatsEntry entry = ofGroupStatsEntry(group);
ofGroupStatsEntries.add(entry);
});
ofStatsReply = FACTORY.buildGroupStatsReply().setEntries(ofGroupStatsEntries).setXid(msg.getXid()).build();
break;
case GROUP_DESC:
List<OFGroupDescStatsEntry> ofGroupDescStatsEntries = new ArrayList<>();
List<Group> groupStats2 = ofSwitchService.getGroups(networkId, deviceId);
groupStats2.forEach(group -> {
OFGroupDescStatsEntry entry = ofGroupDescStatsEntry(group);
ofGroupDescStatsEntries.add(entry);
});
ofStatsReply = FACTORY.buildGroupDescStatsReply().setEntries(ofGroupDescStatsEntries).setXid(msg.getXid()).build();
break;
case DESC:
ofStatsReply = FACTORY.buildDescStatsReply().setXid(msg.getXid()).build();
break;
default:
log.debug("Functionality not yet supported for type {} statsType{} msg {}", msg.getType(), ofStatsRequest.getStatsType(), msg);
break;
}
if (ofStatsReply != null) {
log.trace("request {}; reply {}", msg, ofStatsReply);
channel.writeAndFlush(Collections.singletonList(ofStatsReply));
}
}
use of org.onosproject.net.flow.TableStatisticsEntry in project onos by opennetworkinglab.
the class DistributedVirtualFlowRuleStore method getTableStatistics.
@Override
public Iterable<TableStatisticsEntry> getTableStatistics(NetworkId networkId, DeviceId deviceId) {
MastershipService mastershipService = vnaService.get(networkId, MastershipService.class);
NodeId master = mastershipService.getMasterFor(deviceId);
if (master == null) {
log.debug("Failed to getTableStats: No master for {}", deviceId);
return Collections.emptyList();
}
if (deviceTableStats.get(networkId) == null) {
deviceTableStats.put(networkId, Maps.newConcurrentMap());
}
List<TableStatisticsEntry> tableStats = deviceTableStats.get(networkId).get(deviceId);
if (tableStats == null) {
return Collections.emptyList();
}
return ImmutableList.copyOf(tableStats);
}
Aggregations