Search in sources :

Example 46 with FlowRule

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

the class OpenstackFlowRuleManagerTest method validateFlowRule.

private void validateFlowRule(FlowRule ref) {
    assertEquals("Flow Rule size was not match", 1, fros.size());
    List<FlowRuleOperation> froList = Lists.newArrayList();
    froList.addAll(fros);
    FlowRuleOperation fro = froList.get(0);
    FlowRule fr = fro.rule();
    assertEquals("Application ID did not match", ref.appId(), fr.appId());
    assertEquals("Device ID did not match", ref.deviceId(), fr.deviceId());
    assertEquals("Selector did not match", ref.selector(), fr.selector());
    assertEquals("Treatment did not match", ref.treatment(), fr.treatment());
    assertEquals("Priority did not match", ref.priority(), fr.priority());
    assertEquals("Table ID did not match", ref.table(), fr.table());
    assertEquals("Permanent did not match", ref.isPermanent(), fr.isPermanent());
}
Also used : DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleOperation(org.onosproject.net.flow.FlowRuleOperation)

Example 47 with FlowRule

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

the class PathIntentCompiler method compile.

@Override
public List<Intent> compile(PathIntent intent, List<Intent> installable) {
    List<FlowRule> rules = new LinkedList<>();
    List<DeviceId> devices = new LinkedList<>();
    compile(this, intent, rules, devices);
    return ImmutableList.of(new FlowRuleIntent(appId, intent.key(), rules, intent.resources(), intent.type(), intent.resourceGroup()));
}
Also used : DeviceId(org.onosproject.net.DeviceId) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) LinkedList(java.util.LinkedList) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 48 with FlowRule

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

the class PointToPointIntentCompiler method createFailoverFlowRules.

/**
 * Manufactures flow rule with treatment that is defined by failover
 * group and traffic selector determined by ingress port of the intent.
 *
 * @param intent intent which is being compiled (for appId)
 * @return       a list of a singular flow rule with fast failover
 *               outport traffic treatment
 */
private List<FlowRule> createFailoverFlowRules(PointToPointIntent intent) {
    List<FlowRule> flowRules = new ArrayList<>();
    ConnectPoint ingress = intent.filteredIngressPoint().connectPoint();
    DeviceId deviceId = ingress.deviceId();
    // flow rule with failover traffic treatment
    TrafficSelector trafficSelector = DefaultTrafficSelector.builder(intent.selector()).matchInPort(ingress.port()).build();
    FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
    flowRules.add(flowRuleBuilder.withSelector(trafficSelector).withTreatment(buildFailoverTreatment(deviceId, makeGroupKey(intent.id()))).fromApp(intent.appId()).makePermanent().forDevice(deviceId).withPriority(PRIORITY).build());
    return flowRules;
}
Also used : DeviceId(org.onosproject.net.DeviceId) ArrayList(java.util.ArrayList) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 49 with FlowRule

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

the class FlowBucket method update.

/**
 * Applies the given update function to the rule.
 *
 * @param rule     the rule to update
 * @param function the update function to apply
 * @param term     the term in which the change occurred
 * @param clock    the logical clock
 * @param <T>      the result type
 * @return the update result or {@code null} if the rule was not updated
 */
public <T> T update(FlowRule rule, Function<StoredFlowEntry, T> function, long term, LogicalClock clock) {
    Map<StoredFlowEntry, StoredFlowEntry> flowEntries = flowBucket.get(rule.id());
    if (flowEntries == null) {
        flowEntries = flowBucket.computeIfAbsent(rule.id(), id -> Maps.newConcurrentMap());
    }
    AtomicReference<T> resultRef = new AtomicReference<>();
    flowEntries.computeIfPresent(new DefaultFlowEntry(rule), (k, stored) -> {
        if (stored != null) {
            T result = function.apply(stored);
            if (result != null) {
                recordUpdate(term, clock.getTimestamp());
                resultRef.set(result);
            }
        }
        return stored;
    });
    return resultRef.get();
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) FlowEntry(org.onosproject.net.flow.FlowEntry) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) FlowId(org.onosproject.net.flow.FlowId) Map(java.util.Map) FlowRule(org.onosproject.net.flow.FlowRule) ApplicationId(org.onosproject.core.ApplicationId) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) LogicalTimestamp(org.onosproject.store.LogicalTimestamp) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 50 with FlowRule

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

the class OvsOfdpaPipeline method processEthDstSpecific.

@Override
protected Collection<FlowRule> processEthDstSpecific(ForwardingObjective fwd) {
    List<FlowRule> rules = new ArrayList<>();
    // Build filtered selector
    TrafficSelector selector = fwd.selector();
    EthCriterion ethCriterion = (EthCriterion) selector.getCriterion(Criterion.Type.ETH_DST);
    VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) selector.getCriterion(VLAN_VID);
    if (vlanIdCriterion == null) {
        log.warn("Forwarding objective for bridging requires vlan. Not " + "installing fwd:{} in dev:{}", fwd.id(), deviceId);
        fail(fwd, ObjectiveError.BADPARAMS);
        return Collections.emptySet();
    }
    TrafficSelector.Builder filteredSelectorBuilder = DefaultTrafficSelector.builder();
    // Do not match MacAddress for subnet broadcast entry
    if (!ethCriterion.mac().equals(NONE) && !ethCriterion.mac().equals(BROADCAST)) {
        filteredSelectorBuilder.matchEthDst(ethCriterion.mac());
        log.debug("processing L2 forwarding objective:{} -> next:{} in dev:{}", fwd.id(), fwd.nextId(), deviceId);
    } else {
        log.debug("processing L2 Broadcast forwarding objective:{} -> next:{} " + "in dev:{} for vlan:{}", fwd.id(), fwd.nextId(), deviceId, vlanIdCriterion.vlanId());
    }
    filteredSelectorBuilder.matchVlanId(vlanIdCriterion.vlanId());
    TrafficSelector filteredSelector = filteredSelectorBuilder.build();
    if (fwd.treatment() != null) {
        log.warn("Ignoring traffic treatment in fwd rule {} meant for L2 table" + "for dev:{}. Expecting only nextId", fwd.id(), deviceId);
    }
    TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
    if (fwd.nextId() != null) {
        NextGroup next = getGroupForNextObjective(fwd.nextId());
        if (next != null) {
            List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
            // we only need the top level group's key to point the flow to it
            Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
            if (group != null) {
                treatmentBuilder.deferred().group(group.id());
            } else {
                log.warn("Group with key:{} for next-id:{} not found in dev:{}", gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
                fail(fwd, ObjectiveError.GROUPMISSING);
                return Collections.emptySet();
            }
        }
    }
    treatmentBuilder.immediate().transition(ACL_TABLE);
    TrafficTreatment filteredTreatment = treatmentBuilder.build();
    // Build bridging table entries
    FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
    flowRuleBuilder.fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(filteredSelector).withTreatment(filteredTreatment).forTable(BRIDGING_TABLE);
    if (fwd.permanent()) {
        flowRuleBuilder.makePermanent();
    } else {
        flowRuleBuilder.makeTemporary(fwd.timeout());
    }
    rules.add(flowRuleBuilder.build());
    return rules;
}
Also used : NextGroup(org.onosproject.net.behaviour.NextGroup) NextGroup(org.onosproject.net.behaviour.NextGroup) Group(org.onosproject.net.group.Group) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) ArrayList(java.util.ArrayList) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Deque(java.util.Deque) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

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