Search in sources :

Example 36 with FlowRule

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

the class FlowRuleDriverProvider method executeBatch.

@Override
public void executeBatch(FlowRuleBatchOperation batch) {
    ImmutableList.Builder<FlowRule> toAdd = ImmutableList.builder();
    ImmutableList.Builder<FlowRule> toRemove = ImmutableList.builder();
    for (FlowRuleBatchEntry fbe : batch.getOperations()) {
        if (fbe.operator() == ADD || fbe.operator() == MODIFY) {
            toAdd.add(fbe.target());
        } else if (fbe.operator() == REMOVE) {
            toRemove.add(fbe.target());
        }
    }
    ImmutableList<FlowRule> rulesToAdd = toAdd.build();
    ImmutableList<FlowRule> rulesToRemove = toRemove.build();
    Collection<FlowRule> added = ImmutableList.of();
    if (!rulesToAdd.isEmpty()) {
        added = applyFlowRules(batch.deviceId(), rulesToAdd);
    }
    Collection<FlowRule> removed = ImmutableList.of();
    if (!rulesToRemove.isEmpty()) {
        removed = removeFlowRules(batch.deviceId(), rulesToRemove);
    }
    Set<FlowRule> failedRules = Sets.union(Sets.difference(copyOf(rulesToAdd), copyOf(added)), Sets.difference(copyOf(rulesToRemove), copyOf(removed)));
    CompletedBatchOperation status = new CompletedBatchOperation(failedRules.isEmpty(), failedRules, batch.deviceId());
    providerService.batchOperationCompleted(batch.id(), status);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) FlowRule(org.onosproject.net.flow.FlowRule) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation)

Example 37 with FlowRule

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

the class FlowRuleManager method getFlowRulesByGroupId.

@Override
public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) {
    checkPermission(FLOWRULE_READ);
    Set<FlowRule> matches = Sets.newHashSet();
    long toLookUp = ((long) appId.id() << 16) | groupId;
    for (Device d : deviceService.getDevices()) {
        for (FlowEntry flowEntry : store.getFlowEntries(d.id())) {
            if ((flowEntry.id().value() >>> 32) == toLookUp) {
                matches.add(flowEntry);
            }
        }
    }
    return matches;
}
Also used : Device(org.onosproject.net.Device) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 38 with FlowRule

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

the class OplinkOpticalUtility method fromFlowRule.

/**
 * Transforms a flow FlowRule object to an OplinkCrossConnect object.
 * @param behaviour the parent driver handler
 * @param rule FlowRule object
 * @return cross connect object
 */
public static OplinkCrossConnect fromFlowRule(HandlerBehaviour behaviour, FlowRule rule) {
    // TrafficSelector
    Set<Criterion> criterions = rule.selector().criteria();
    int channel = criterions.stream().filter(c -> c instanceof OchSignalCriterion).map(c -> ((OchSignalCriterion) c).lambda().spacingMultiplier()).findAny().orElse(null);
    PortNumber inPort = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
    // TrafficTreatment
    List<Instruction> instructions = rule.treatment().immediate();
    PortNumber outPort = instructions.stream().filter(c -> c instanceof Instructions.OutputInstruction).map(c -> ((Instructions.OutputInstruction) c).port()).findAny().orElse(null);
    int attenuation = instructions.stream().filter(c -> c instanceof Instructions.ExtensionInstructionWrapper).map(c -> ((Instructions.ExtensionInstructionWrapper) c).extensionInstruction()).filter(c -> c instanceof OplinkAttenuation).map(c -> ((OplinkAttenuation) c).getAttenuation()).findAny().orElse(DEFAULT_ATT);
    return new OplinkCrossConnect(inPort, outPort, channel, attenuation);
}
Also used : GridType(org.onosproject.net.GridType) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) HandlerBehaviour(org.onosproject.net.driver.HandlerBehaviour) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) OplinkAttenuation(org.onosproject.driver.extensions.OplinkAttenuation) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) Frequency(org.onlab.util.Frequency) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OchSignalType(org.onosproject.net.OchSignalType) Instructions(org.onosproject.net.flow.instructions.Instructions) Instruction(org.onosproject.net.flow.instructions.Instruction) Range(com.google.common.collect.Range) Set(java.util.Set) Lambda(org.onosproject.net.Lambda) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) ChannelSpacing(org.onosproject.net.ChannelSpacing) Instructions(org.onosproject.net.flow.instructions.Instructions) OplinkAttenuation(org.onosproject.driver.extensions.OplinkAttenuation) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Instruction(org.onosproject.net.flow.instructions.Instruction) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) PortNumber(org.onosproject.net.PortNumber)

Example 39 with FlowRule

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

the class TapiFlowRuleProgrammable method getFlowEntries.

@Override
public Collection<FlowEntry> getFlowEntries() {
    DeviceId deviceId = did();
    // TODO this is a blocking call on ADVA OLS, right now using cache.
    // return getFlowsFromConnectivityServices(deviceId);
    List<FlowEntry> entries = new ArrayList<>();
    Set<FlowRule> rules = getConnectionCache().get(deviceId);
    if (rules != null) {
        rules.forEach(rule -> {
            entries.add(new DefaultFlowEntry(rule, FlowEntry.FlowEntryState.ADDED, 0, 0, 0));
        });
    }
    return entries;
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) DeviceId(org.onosproject.net.DeviceId) ArrayList(java.util.ArrayList) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 40 with FlowRule

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

the class TapiFlowRuleProgrammable method removeFlowRules.

@Override
public Collection<FlowRule> removeFlowRules(Collection<FlowRule> rules) {
    DeviceId deviceId = handler().data().deviceId();
    RestSBController controller = checkNotNull(handler().get(RestSBController.class));
    ImmutableList.Builder<FlowRule> removed = ImmutableList.builder();
    rules.forEach(flowRule -> {
        DeviceConnection conn = getConnectionCache().get(deviceId, flowRule.id());
        if (conn == null || conn.getId() == null) {
            log.warn("Can't find associate device connection for flow {} and device {}", flowRule.id(), deviceId);
            return;
        }
        CompletableFuture<Integer> flowRemoval = CompletableFuture.supplyAsync(() -> controller.delete(deviceId, CONN_REQ_REMOVE_DATA_API + conn.getId(), null, MediaType.APPLICATION_JSON_TYPE));
        flowRemoval.thenApply(result -> {
            if (result == HttpStatus.SC_NO_CONTENT) {
                getConnectionCache().remove(deviceId, flowRule);
                removed.add(flowRule);
            } else {
                log.error("Can't remove flow {}, result {}", flowRule, result);
            }
            return result;
        });
    });
    // TODO workaround for blocking call on ADVA OLS shoudl return removed
    return rules;
}
Also used : DeviceId(org.onosproject.net.DeviceId) RestSBController(org.onosproject.protocol.rest.RestSBController) ImmutableList(com.google.common.collect.ImmutableList) DeviceConnection(org.onosproject.drivers.odtn.impl.DeviceConnection) FlowRule(org.onosproject.net.flow.FlowRule)

Aggregations

FlowRule (org.onosproject.net.flow.FlowRule)432 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)279 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)226 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)225 TrafficSelector (org.onosproject.net.flow.TrafficSelector)193 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)189 Test (org.junit.Test)173 List (java.util.List)101 DeviceId (org.onosproject.net.DeviceId)101 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)90 Intent (org.onosproject.net.intent.Intent)88 Collection (java.util.Collection)75 Collectors (java.util.stream.Collectors)75 CoreService (org.onosproject.core.CoreService)72 Collections (java.util.Collections)70 VlanId (org.onlab.packet.VlanId)65 FlowEntry (org.onosproject.net.flow.FlowEntry)63 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)61 PortNumber (org.onosproject.net.PortNumber)57 ArrayList (java.util.ArrayList)56