use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class FlowStatisticManager method typedFlowEntryLoadByInstInternal.
private List<FlowEntryWithLoad> typedFlowEntryLoadByInstInternal(ConnectPoint cp, Map<FlowRule, FlowEntry> currentMap, Map<FlowRule, FlowEntry> previousMap, boolean isAllInstType, Instruction.Type instType) {
List<FlowEntryWithLoad> fel = new ArrayList<>();
currentMap.values().forEach(fe -> {
if (isAllInstType || fe.treatment().allInstructions().stream().filter(i -> i.type() == instType).findAny().isPresent()) {
long currentBytes = fe.bytes();
long previousBytes = previousMap.getOrDefault(fe, new DefaultFlowEntry(fe)).bytes();
long liveTypePollInterval = getLiveTypePollInterval(fe.liveType());
Load fLoad = new DefaultLoad(currentBytes, previousBytes, liveTypePollInterval);
fel.add(new FlowEntryWithLoad(cp, fe, fLoad));
}
});
return fel;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class StatisticManager method highestHitter.
@Override
public FlowRule highestHitter(ConnectPoint connectPoint) {
checkPermission(STATISTIC_READ);
Set<FlowEntry> hitters = statisticStore.getCurrentStatistic(connectPoint);
if (hitters.isEmpty()) {
return null;
}
FlowEntry max = hitters.iterator().next();
for (FlowEntry entry : hitters) {
if (entry.bytes() > max.bytes()) {
max = entry;
}
}
return max;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class FlowRuleProgrammableServerImpl method getFlowEntries.
@Override
public Collection<FlowEntry> getFlowEntries() {
DeviceId deviceId = getDeviceId();
checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
// Expected FlowEntries installed through ONOS
FlowRuleService flowService = getHandler().get(FlowRuleService.class);
Iterable<FlowEntry> flowEntries = flowService.getFlowEntries(deviceId);
// Hit the path that provides the server's flow rules
InputStream response = null;
try {
response = getController().get(deviceId, URL_RULE_MANAGEMENT, JSON);
} catch (ProcessingException pEx) {
log.error("Failed to get NIC flow entries from device: {}", deviceId);
return Collections.EMPTY_LIST;
}
// Load the JSON into objects
ObjectMapper mapper = new ObjectMapper();
ObjectNode objNode = null;
try {
Map<String, Object> jsonMap = mapper.readValue(response, Map.class);
JsonNode jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
objNode = (ObjectNode) jsonNode;
} catch (IOException ioEx) {
log.error("Failed to get NIC flow entries from device: {}", deviceId);
return Collections.EMPTY_LIST;
}
if (objNode == null) {
log.error("Failed to get NIC flow entries from device: {}", deviceId);
return Collections.EMPTY_LIST;
}
JsonNode scsNode = objNode.path(PARAM_RULES);
// Here we store the trully installed rules
Collection<FlowEntry> actualFlowEntries = Sets.<FlowEntry>newConcurrentHashSet();
for (JsonNode scNode : scsNode) {
String scId = get(scNode, PARAM_ID);
String rxFilter = get(scNode.path(PARAM_NIC_RX_FILTER), PARAM_NIC_RX_METHOD);
// Only Flow-based RxFilter is permitted
if (RxFilter.getByName(rxFilter) != RxFilter.FLOW) {
log.warn("Device with Rx filter {} is not managed by this driver", rxFilter.toString().toUpperCase());
continue;
}
// Each device might have multiple NICs
for (JsonNode nicNode : scNode.path(PARAM_NICS)) {
JsonNode cpusNode = nicNode.path(PARAM_CPUS);
// Each NIC can dispatch to multiple CPU cores
for (JsonNode cpuNode : cpusNode) {
String cpuId = get(cpuNode, PARAM_ID);
JsonNode rulesNode = cpuNode.path(PARAM_RULES);
// Multiple rules might correspond to each CPU core
for (JsonNode ruleNode : rulesNode) {
long ruleId = ruleNode.path(PARAM_ID).asLong();
String ruleContent = get(ruleNode, PARAM_RULE_CONTENT);
// Search for this rule ID in ONOS's store
FlowRule r = findRuleInFlowEntries(flowEntries, ruleId);
// Local rule, not present in the controller => Ignore
if (r == null) {
continue;
// Rule trully present in the data plane => Add
} else {
actualFlowEntries.add(new DefaultFlowEntry(r, FlowEntry.FlowEntryState.ADDED, 0, 0, 0));
}
}
}
}
}
return actualFlowEntries;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class FlowsWebResource method getFlowByAppId.
/**
* Gets flow rules generated by an application.
* Returns the flow rule specified by the application id.
*
* @param appId application identifier
* @return 200 OK with a collection of flows of given application id
* @onos.rsModel FlowRules
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("application/{appId}")
public Response getFlowByAppId(@PathParam("appId") String appId) {
ObjectNode root = mapper().createObjectNode();
ArrayNode flowsNode = root.putArray(FLOWS);
ApplicationService appService = get(ApplicationService.class);
ApplicationId idInstant = nullIsNotFound(appService.getId(appId), APP_ID_NOT_FOUND);
Iterable<FlowEntry> flowEntries = get(FlowRuleService.class).getFlowEntriesById(idInstant);
flowEntries.forEach(flow -> flowsNode.add(codec(FlowEntry.class).encode(flow, this)));
return ok(root).build();
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class FlowsWebResource method getPendingFlows.
/**
* Gets all pending flow entries. Returns array of all pending flow rules in the system.
*
* @return 200 OK with a collection of flows
* @onos.rsModel FlowEntries
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("pending")
public Response getPendingFlows() {
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 ((entry.state() == FlowEntry.FlowEntryState.PENDING_ADD) || (entry.state() == FlowEntry.FlowEntryState.PENDING_REMOVE)) {
flowsNode.add(codec(FlowEntry.class).encode(entry, this));
}
}
}
}
return ok(root).build();
}
Aggregations