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();
}
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();
}
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();
}
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;
}
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;
}
Aggregations