use of org.onosproject.net.flow.FlowRuleService in project onos by opennetworkinglab.
the class FlowsWebResource method getTableFlows.
/**
* Gets all flow entries for a table. Returns array of all flow rules for a table.
* @param tableId table identifier
* @return 200 OK with a collection of flows
* @onos.rsModel FlowEntries
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("table/{tableId}")
public Response getTableFlows(@PathParam("tableId") int tableId) {
ObjectNode root = mapper().createObjectNode();
ArrayNode flowsNode = root.putArray(FLOWS);
FlowRuleService service = get(FlowRuleService.class);
Iterable<Device> devices = get(DeviceService.class).getDevices();
for (Device device : devices) {
Iterable<FlowEntry> flowEntries = service.getFlowEntries(device.id());
if (flowEntries != null) {
for (FlowEntry entry : flowEntries) {
if (((IndexTableId) entry.table()).id() == tableId) {
flowsNode.add(codec(FlowEntry.class).encode(entry, this));
}
}
}
}
return ok(root).build();
}
use of org.onosproject.net.flow.FlowRuleService in project onos by opennetworkinglab.
the class FlowsWebResource method getFlowByDeviceId.
/**
* Gets flow entries of a device. Returns array of all flow rules for the
* specified device.
*
* @param deviceId device identifier
* @return 200 OK with a collection of flows of given device
* @onos.rsModel FlowEntries
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
// TODO: we need to add "/device" suffix to the path to differentiate with appId
@Path("{deviceId}")
public Response getFlowByDeviceId(@PathParam("deviceId") String deviceId) {
FlowRuleService service = get(FlowRuleService.class);
ObjectNode root = mapper().createObjectNode();
ArrayNode flowsNode = root.putArray(FLOWS);
Iterable<FlowEntry> flowEntries = service.getFlowEntries(DeviceId.deviceId(deviceId));
if (flowEntries == null || !flowEntries.iterator().hasNext()) {
throw new ItemNotFoundException(DEVICE_NOT_FOUND);
}
for (FlowEntry entry : flowEntries) {
flowsNode.add(codec(FlowEntry.class).encode(entry, this));
}
return ok(root).build();
}
use of org.onosproject.net.flow.FlowRuleService in project onos by opennetworkinglab.
the class FabricBngProgrammable method setupBehaviour.
@Override
protected boolean setupBehaviour(String opName) {
if (!super.setupBehaviour(opName)) {
return false;
}
flowRuleService = handler().get(FlowRuleService.class);
bngProgService = handler().get(FabricBngProgrammableService.class);
capabilities = new FabricCapabilities(pipeconf);
if (!capabilities.supportBng()) {
log.warn("Pipeconf {} on {} does not support BNG capabilities, " + "cannot perform {}", pipeconf.id(), deviceId, opName);
return false;
}
return true;
}
use of org.onosproject.net.flow.FlowRuleService 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.FlowRuleService 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();
}
Aggregations