Search in sources :

Example 51 with FlowEntry

use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.

the class FlowsWebResource method deleteFlowByDeviceIdAndFlowId.

/**
 * Removes flow rule. Removes the specified flow rule.
 *
 * @param deviceId device identifier
 * @param flowId   flow rule identifier
 * @return 204 NO CONTENT
 */
@DELETE
@Path("{deviceId}/{flowId}")
public Response deleteFlowByDeviceIdAndFlowId(@PathParam("deviceId") String deviceId, @PathParam("flowId") long flowId) {
    FlowRuleService service = get(FlowRuleService.class);
    Iterable<FlowEntry> flowEntries = service.getFlowEntries(DeviceId.deviceId(deviceId));
    if (!flowEntries.iterator().hasNext()) {
        throw new ItemNotFoundException(DEVICE_NOT_FOUND);
    }
    StreamSupport.stream(flowEntries.spliterator(), false).filter(entry -> entry.id().value() == flowId).forEach(service::removeFlowRules);
    return Response.noContent().build();
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) PathParam(javax.ws.rs.PathParam) AbstractWebResource(org.onosproject.rest.AbstractWebResource) Produces(javax.ws.rs.Produces) ListMultimap(com.google.common.collect.ListMultimap) GET(javax.ws.rs.GET) DeviceService(org.onosproject.net.device.DeviceService) Path(javax.ws.rs.Path) FlowEntry(org.onosproject.net.flow.FlowEntry) ApplicationService(org.onosproject.app.ApplicationService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) MediaType(javax.ws.rs.core.MediaType) FlowRuleService(org.onosproject.net.flow.FlowRuleService) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) ApplicationId(org.onosproject.core.ApplicationId) JsonNode(com.fasterxml.jackson.databind.JsonNode) UriBuilder(javax.ws.rs.core.UriBuilder) StreamSupport(java.util.stream.StreamSupport) Tools.nullIsIllegal(org.onlab.util.Tools.nullIsIllegal) DELETE(javax.ws.rs.DELETE) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) Tools.nullIsNotFound(org.onlab.util.Tools.nullIsNotFound) Device(org.onosproject.net.Device) IndexTableId(org.onosproject.net.flow.IndexTableId) IOException(java.io.IOException) ItemNotFoundException(org.onlab.util.ItemNotFoundException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) Response(javax.ws.rs.core.Response) FlowRule(org.onosproject.net.flow.FlowRule) UriInfo(javax.ws.rs.core.UriInfo) DeviceId(org.onosproject.net.DeviceId) Tools.readTreeFromStream(org.onlab.util.Tools.readTreeFromStream) InputStream(java.io.InputStream) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry) ItemNotFoundException(org.onlab.util.ItemNotFoundException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 52 with FlowEntry

use of org.onosproject.net.flow.FlowEntry 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 53 with FlowEntry

use of org.onosproject.net.flow.FlowEntry 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 54 with FlowEntry

use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.

the class TrafficMonitor method getLinkFlowCounts.

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Counts all flow entries that egress on the links of the given device.
private Map<Link, Integer> getLinkFlowCounts(DeviceId deviceId) {
    // get the flows for the device
    List<FlowEntry> entries = new ArrayList<>();
    for (FlowEntry flowEntry : services.flow().getFlowEntries(deviceId)) {
        entries.add(flowEntry);
    }
    // get egress links from device, and include edge links
    Set<Link> links = new HashSet<>(services.link().getDeviceEgressLinks(deviceId));
    Set<Host> hosts = services.host().getConnectedHosts(deviceId);
    if (hosts != null) {
        for (Host host : hosts) {
            links.addAll(createEdgeLinks(host, false));
        }
    }
    // compile flow counts per link
    Map<Link, Integer> counts = new HashMap<>();
    for (Link link : links) {
        counts.put(link, getEgressFlows(link, entries));
    }
    return counts;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Host(org.onosproject.net.Host) FlowEntry(org.onosproject.net.flow.FlowEntry) Link(org.onosproject.net.Link) TrafficLink(org.onosproject.ui.impl.topo.util.TrafficLink) HashSet(java.util.HashSet)

Example 55 with FlowEntry

use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.

the class TrafficMonitor method getEgressFlows.

// Counts all entries that egress on the link source port.
private int getEgressFlows(Link link, List<FlowEntry> entries) {
    int count = 0;
    PortNumber out = link.src().port();
    for (FlowEntry entry : entries) {
        TrafficTreatment treatment = entry.treatment();
        for (Instruction instruction : treatment.allInstructions()) {
            if (instruction.type() == Instruction.Type.OUTPUT && ((OutputInstruction) instruction).port().equals(out)) {
                count++;
            }
        }
    }
    return count;
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) PortNumber(org.onosproject.net.PortNumber) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) FlowEntry(org.onosproject.net.flow.FlowEntry)

Aggregations

FlowEntry (org.onosproject.net.flow.FlowEntry)123 DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)61 FlowRule (org.onosproject.net.flow.FlowRule)51 Test (org.junit.Test)31 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)31 FlowRuleService (org.onosproject.net.flow.FlowRuleService)27 ArrayList (java.util.ArrayList)24 StoredFlowEntry (org.onosproject.net.flow.StoredFlowEntry)23 DeviceId (org.onosproject.net.DeviceId)20 Device (org.onosproject.net.Device)19 PortNumber (org.onosproject.net.PortNumber)17 TrafficSelector (org.onosproject.net.flow.TrafficSelector)16 Instruction (org.onosproject.net.flow.instructions.Instruction)16 DeviceService (org.onosproject.net.device.DeviceService)15 List (java.util.List)14 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)13 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 HashSet (java.util.HashSet)12 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)11