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