Search in sources :

Example 16 with FlowRuleService

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 17 with FlowRuleService

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry) ItemNotFoundException(org.onlab.util.ItemNotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 18 with FlowRuleService

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;
}
Also used : FabricCapabilities(org.onosproject.pipelines.fabric.impl.behaviour.FabricCapabilities) FlowRuleService(org.onosproject.net.flow.FlowRuleService)

Example 19 with FlowRuleService

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 20 with FlowRuleService

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

FlowRuleService (org.onosproject.net.flow.FlowRuleService)51 FlowEntry (org.onosproject.net.flow.FlowEntry)23 CoreService (org.onosproject.core.CoreService)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)16 DeviceService (org.onosproject.net.device.DeviceService)16 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)14 Produces (javax.ws.rs.Produces)14 ApplicationId (org.onosproject.core.ApplicationId)13 Device (org.onosproject.net.Device)13 Path (javax.ws.rs.Path)12 FlowRule (org.onosproject.net.flow.FlowRule)12 GET (javax.ws.rs.GET)11 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)11 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)10 List (java.util.List)9 TrafficSelector (org.onosproject.net.flow.TrafficSelector)9 DeviceId (org.onosproject.net.DeviceId)8 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)7 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)7 IOException (java.io.IOException)6