Search in sources :

Example 41 with FlowRule

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

the class KryoSerializerTest method testFlowRuleBatchEntry.

@Test
public void testFlowRuleBatchEntry() {
    final FlowRule rule1 = DefaultFlowRule.builder().forDevice(DID1).withSelector(DefaultTrafficSelector.emptySelector()).withTreatment(DefaultTrafficTreatment.emptyTreatment()).withPriority(0).fromApp(new DefaultApplicationId(1, "1")).makeTemporary(1).build();
    final FlowRuleBatchEntry entry1 = new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1);
    final FlowRuleBatchEntry entry2 = new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1, 100L);
    testSerializedEquals(entry1);
    testSerializedEquals(entry2);
}
Also used : FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) Test(org.junit.Test)

Example 42 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 43 with FlowRule

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

the class TapiFlowRuleProgrammable method getFlowsFromConnectivityServices.

// Currently uused because get is a blocking call on ADVA
private Collection<FlowEntry> getFlowsFromConnectivityServices(DeviceId deviceId) {
    Set<String> uuids = getUuids(deviceId, handler());
    if (uuids.isEmpty()) {
        return ImmutableList.of();
    }
    DeviceConnectionCache cache = getConnectionCache();
    if (cache.get(deviceId) == null) {
        return ImmutableList.of();
    }
    List<FlowEntry> entries = new ArrayList<>();
    uuids.forEach(uuid -> {
        FlowRule rule = cache.get(deviceId, uuid);
        if (rule != null) {
            entries.add(new DefaultFlowEntry(rule, FlowEntry.FlowEntryState.ADDED, 0, 0, 0));
        } else {
            log.info("Non existing rule for uuid {}", uuid);
        }
    });
    return entries;
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) ArrayList(java.util.ArrayList) DeviceConnectionCache(org.onosproject.drivers.odtn.impl.DeviceConnectionCache) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 44 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)

Example 45 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)

Aggregations

FlowRule (org.onosproject.net.flow.FlowRule)351 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)226 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)207 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)207 TrafficSelector (org.onosproject.net.flow.TrafficSelector)174 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)174 Test (org.junit.Test)133 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)90 Intent (org.onosproject.net.intent.Intent)88 DeviceId (org.onosproject.net.DeviceId)87 List (java.util.List)86 Collection (java.util.Collection)68 Collectors (java.util.stream.Collectors)68 CoreService (org.onosproject.core.CoreService)66 VlanId (org.onlab.packet.VlanId)65 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)61 Collections (java.util.Collections)60 FlowEntry (org.onosproject.net.flow.FlowEntry)59 MplsCriterion (org.onosproject.net.flow.criteria.MplsCriterion)56 ArrayList (java.util.ArrayList)54