Search in sources :

Example 1 with FlowEntryState

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

the class VirtualFlowsListCommand method compilePredicate.

/**
 * Compiles a predicate to find matching flows based on the command
 * arguments.
 */
private void compilePredicate() {
    if (state != null && !state.equals(ANY)) {
        final FlowEntryState feState = FlowEntryState.valueOf(state.toUpperCase());
        predicate = predicate.and(f -> f.state().equals(feState));
    }
    if (table != null) {
        final int tableId = Integer.parseInt(table);
        predicate = predicate.and(f -> f.tableId() == tableId);
    }
}
Also used : StringFilter(org.onlab.util.StringFilter) Comparators(org.onosproject.utils.Comparators) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) ArrayList(java.util.ArrayList) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowRuleStatusCompleter(org.onosproject.cli.net.FlowRuleStatusCompleter) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) JsonNode(com.fasterxml.jackson.databind.JsonNode) PlaceholderCompleter(org.onosproject.cli.PlaceholderCompleter) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Device(org.onosproject.net.Device) Predicate(java.util.function.Predicate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Argument(org.apache.karaf.shell.api.action.Argument) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) TreeMap(java.util.TreeMap) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) SortedMap(java.util.SortedMap) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState)

Example 2 with FlowEntryState

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

the class FlowsListCommand method compilePredicate.

/**
 * Compiles a predicate to find matching flows based on the command
 * arguments.
 */
private void compilePredicate() {
    if (state != null && !state.equals(ANY)) {
        final FlowEntryState feState = FlowEntryState.valueOf(state.toUpperCase());
        predicate = predicate.and(f -> f.state().equals(feState));
    }
    if (table != null) {
        final int tableId = Integer.parseInt(table);
        predicate = predicate.and(f -> f.tableId() == tableId);
    }
}
Also used : StringFilter(org.onlab.util.StringFilter) Comparators(org.onosproject.utils.Comparators) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) ArrayList(java.util.ArrayList) FlowRuleService(org.onosproject.net.flow.FlowRuleService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) JsonNode(com.fasterxml.jackson.databind.JsonNode) PlaceholderCompleter(org.onosproject.cli.PlaceholderCompleter) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Device(org.onosproject.net.Device) Predicate(java.util.function.Predicate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Argument(org.apache.karaf.shell.api.action.Argument) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) TreeMap(java.util.TreeMap) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) BufferedReader(java.io.BufferedReader) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) SortedMap(java.util.SortedMap) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState)

Example 3 with FlowEntryState

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

the class FlowRuleManagerTest method validateState.

private boolean validateState(Map<FlowRule, FlowEntryState> expected) {
    Map<FlowRule, FlowEntryState> expectedToCheck = new HashMap<>(expected);
    Iterable<FlowEntry> rules = service.getFlowEntries(DID);
    for (FlowEntry f : rules) {
        assertTrue("Unexpected FlowRule " + f, expectedToCheck.containsKey(f));
        assertEquals("FlowEntry" + f, expectedToCheck.get(f), f.state());
        expectedToCheck.remove(f);
    }
    assertEquals(Collections.emptySet(), expectedToCheck.entrySet());
    return true;
}
Also used : HashMap(java.util.HashMap) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 4 with FlowEntryState

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

the class FlowEntryBuilder method createFlowEntryForFlowMod.

private FlowEntry createFlowEntryForFlowMod(FlowEntryState... state) {
    FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
    FlowRule.Builder builder = DefaultFlowRule.builder().forDevice(deviceId).withSelector(buildSelector()).withTreatment(buildTreatment()).withPriority(flowMod.getPriority()).withIdleTimeout(flowMod.getIdleTimeout()).withCookie(flowMod.getCookie().getValue());
    if (flowMod.getVersion() != OFVersion.OF_10) {
        builder.forTable(flowMod.getTableId().getValue());
    }
    if (afsc != null) {
        FlowEntry.FlowLiveType liveType = FlowEntry.FlowLiveType.IMMEDIATE;
        return new DefaultFlowEntry(builder.build(), flowState, 0, liveType, 0, 0);
    } else {
        return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
    }
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 5 with FlowEntryState

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

the class FlowRuleStatusCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    FlowEntryState[] states = FlowEntryState.values();
    SortedSet<String> strings = delegate.getStrings();
    for (int i = 0; i < states.length; i++) {
        strings.add(states[i].toString().toLowerCase());
    }
    strings.add(FlowsListCommand.ANY);
    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
Also used : StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState)

Aggregations

FlowEntryState (org.onosproject.net.flow.FlowEntry.FlowEntryState)5 FlowEntry (org.onosproject.net.flow.FlowEntry)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 Predicate (java.util.function.Predicate)2 Collectors (java.util.stream.Collectors)2 Argument (org.apache.karaf.shell.api.action.Argument)2 Command (org.apache.karaf.shell.api.action.Command)2 Completion (org.apache.karaf.shell.api.action.Completion)2 Option (org.apache.karaf.shell.api.action.Option)2 Service (org.apache.karaf.shell.api.action.lifecycle.Service)2