Search in sources :

Example 46 with FlowEntry

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;
}
Also used : SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) TypedFlowEntryWithLoad(org.onosproject.net.statistic.TypedFlowEntryWithLoad) FlowEntryWithLoad(org.onosproject.net.statistic.FlowEntryWithLoad) Comparators(org.onosproject.utils.Comparators) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) AppGuard.checkPermission(org.onosproject.security.AppGuard.checkPermission) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultLoad(org.onosproject.net.statistic.DefaultLoad) PollInterval(org.onosproject.net.statistic.PollInterval) DefaultTypedFlowEntry(org.onosproject.net.flow.DefaultTypedFlowEntry) HashMap(java.util.HashMap) ConnectPoint(org.onosproject.net.ConnectPoint) Load(org.onosproject.net.statistic.Load) ArrayList(java.util.ArrayList) SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) Component(org.osgi.service.component.annotations.Component) Port(org.onosproject.net.Port) Map(java.util.Map) Activate(org.osgi.service.component.annotations.Activate) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) Instruction(org.onosproject.net.flow.instructions.Instruction) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) MoreObjects(com.google.common.base.MoreObjects) TypedFlowEntryWithLoad(org.onosproject.net.statistic.TypedFlowEntryWithLoad) Set(java.util.Set) FlowEntryWithLoad(org.onosproject.net.statistic.FlowEntryWithLoad) Collectors(java.util.stream.Collectors) FlowStatisticService(org.onosproject.net.statistic.FlowStatisticService) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) List(java.util.List) StatisticStore(org.onosproject.net.statistic.StatisticStore) TreeMap(java.util.TreeMap) Predicate(com.google.common.base.Predicate) FlowRule(org.onosproject.net.flow.FlowRule) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) TypedStoredFlowEntry(org.onosproject.net.flow.TypedStoredFlowEntry) STATISTIC_READ(org.onosproject.security.AppPermission.Type.STATISTIC_READ) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) Reference(org.osgi.service.component.annotations.Reference) DefaultLoad(org.onosproject.net.statistic.DefaultLoad) Load(org.onosproject.net.statistic.Load) SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) TypedFlowEntryWithLoad(org.onosproject.net.statistic.TypedFlowEntryWithLoad) FlowEntryWithLoad(org.onosproject.net.statistic.FlowEntryWithLoad) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) ArrayList(java.util.ArrayList) DefaultLoad(org.onosproject.net.statistic.DefaultLoad)

Example 47 with FlowEntry

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;
}
Also used : FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 48 with FlowEntry

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;
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) NicFlowRule(org.onosproject.drivers.server.devices.nic.NicFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(javax.ws.rs.ProcessingException)

Example 49 with FlowEntry

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

Example 50 with FlowEntry

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

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