use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class SoftRouterPipeline method processSimpleNextObjective.
/**
* Next Objectives are stored as dummy groups for retrieval later
* when Forwarding Objectives reference the next objective id. At that point
* the dummy group is fetched from the distributed store and the enclosed
* treatment is applied as a flow rule action.
*
* @param nextObj the next objective of type simple
*/
private void processSimpleNextObjective(NextObjective nextObj) {
// Simple next objective has a single treatment (not a collection)
log.debug("Received nextObj {}", nextObj.id());
// delay processing to emulate group creation
delay(50);
TrafficTreatment treatment = nextObj.next().iterator().next();
flowObjectiveStore.putNextGroup(nextObj.id(), new DummyGroup(treatment));
}
use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class SoftRouterPipeline method processVersatile.
/**
* SoftRouter has a single versatile table - the filter table.
* This table can be used to filter entries that reach the next table (FIB table).
* It can also be used to punt packets to the controller and/or bypass
* the FIB table to forward out of a port.
*
* @param fwd The forwarding objective of type versatile
* @return A collection of flow rules meant to be delivered to the flowrule
* subsystem. May return empty collection in case of failures.
*/
private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
log.debug("Received versatile fwd: to next:{}", fwd.nextId());
Collection<FlowRule> flowrules = new ArrayList<>();
if (fwd.nextId() == null && fwd.treatment() == null) {
log.error("Forwarding objective {} from {} must contain " + "nextId or Treatment", fwd.selector(), fwd.appId());
return Collections.emptySet();
}
int tableId = FILTER_TABLE;
// so that it only takes effect if the packet misses the FIB rules
if (fwd.treatment() != null && containsPunt(fwd.treatment()) && fwd.selector() != null && matchesIp(fwd.selector()) && !matchesControlTraffic(fwd.selector())) {
tableId = FIB_TABLE;
}
TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder();
if (fwd.treatment() != null) {
fwd.treatment().immediate().forEach(ins -> ttBuilder.add(ins));
}
// convert nextId to flow actions
if (fwd.nextId() != null) {
// only acceptable value is output to port
NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
if (next == null) {
log.error("next-id {} does not exist in store", fwd.nextId());
return Collections.emptySet();
}
TrafficTreatment nt = appKryo.deserialize(next.data());
if (nt == null) {
log.error("Error in deserializing next-id {}", fwd.nextId());
return Collections.emptySet();
}
for (Instruction ins : nt.allInstructions()) {
if (ins instanceof OutputInstruction) {
ttBuilder.add(ins);
}
}
}
FlowRule rule = DefaultFlowRule.builder().withSelector(fwd.selector()).withTreatment(ttBuilder.build()).forTable(tableId).makePermanent().forDevice(deviceId).fromApp(fwd.appId()).withPriority(fwd.priority()).build();
flowrules.add(rule);
return flowrules;
}
use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class SpringOpenTTP method addBucketToGroup.
private void addBucketToGroup(NextObjective nextObjective) {
log.debug("addBucketToGroup in {}: for next objective id {}", deviceId, nextObjective.id());
Collection<TrafficTreatment> treatments = nextObjective.next();
TrafficTreatment treatment = treatments.iterator().next();
final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
Group group = groupService.getGroup(deviceId, key);
if (group == null) {
log.warn("Group is not found in {} for {}", deviceId, key);
return;
}
GroupBucket bucket;
if (group.type() == GroupDescription.Type.INDIRECT) {
bucket = DefaultGroupBucket.createIndirectGroupBucket(treatment);
} else if (group.type() == GroupDescription.Type.SELECT) {
bucket = DefaultGroupBucket.createSelectGroupBucket(treatment);
} else if (group.type() == GroupDescription.Type.ALL) {
bucket = DefaultGroupBucket.createAllGroupBucket(treatment);
} else {
log.warn("Unsupported Group type {}", group.type());
return;
}
GroupBuckets bucketsToAdd = new GroupBuckets(Collections.singletonList(bucket));
log.debug("Adding buckets to group id {} of next objective id {} in device {}", group.id(), nextObjective.id(), deviceId);
groupService.addBucketsToGroup(deviceId, key, bucketsToAdd, key, appId);
}
use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class SpringOpenTTP method processEthTypeSpecificObjective.
protected Collection<FlowRule> processEthTypeSpecificObjective(ForwardingObjective fwd) {
TrafficSelector selector = fwd.selector();
EthTypeCriterion ethType = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
TrafficSelector.Builder filteredSelectorBuilder = DefaultTrafficSelector.builder();
int forTableId = -1;
if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
filteredSelectorBuilder = filteredSelectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip());
forTableId = ipv4UnicastTableId;
log.debug("processing IPv4 specific forwarding objective:{} in dev:{}", fwd.id(), deviceId);
} else {
filteredSelectorBuilder = filteredSelectorBuilder.matchEthType(Ethernet.MPLS_UNICAST).matchMplsLabel(((MplsCriterion) selector.getCriterion(Criterion.Type.MPLS_LABEL)).label());
if (selector.getCriterion(Criterion.Type.MPLS_BOS) != null) {
filteredSelectorBuilder.matchMplsBos(((MplsBosCriterion) selector.getCriterion(Type.MPLS_BOS)).mplsBos());
}
forTableId = mplsTableId;
log.debug("processing MPLS specific forwarding objective:{} in dev:{}", fwd.id(), deviceId);
}
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
if (fwd.treatment() != null) {
for (Instruction i : fwd.treatment().allInstructions()) {
treatmentBuilder.add(i);
}
}
if (fwd.nextId() != null) {
NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
if (next != null) {
SpringOpenGroup soGroup = appKryo.deserialize(next.data());
if (soGroup.dummy) {
log.debug("Adding {} flow-actions for fwd. obj. {} -> next:{} " + "in dev: {}", soGroup.treatment.allInstructions().size(), fwd.id(), fwd.nextId(), deviceId);
for (Instruction ins : soGroup.treatment.allInstructions()) {
treatmentBuilder.add(ins);
}
} else {
GroupKey key = soGroup.key;
Group group = groupService.getGroup(deviceId, key);
if (group == null) {
log.warn("The group left!");
fail(fwd, ObjectiveError.GROUPMISSING);
return Collections.emptySet();
}
treatmentBuilder.deferred().group(group.id());
log.debug("Adding OUTGROUP action to group:{} for fwd. obj. {} " + "for next:{} in dev: {}", group.id(), fwd.id(), fwd.nextId(), deviceId);
}
} else {
log.warn("processSpecific: No associated next objective object");
fail(fwd, ObjectiveError.GROUPMISSING);
return Collections.emptySet();
}
}
TrafficSelector filteredSelector = filteredSelectorBuilder.build();
TrafficTreatment treatment = treatmentBuilder.transition(aclTableId).build();
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(filteredSelector).withTreatment(treatment);
if (fwd.permanent()) {
ruleBuilder.makePermanent();
} else {
ruleBuilder.makeTemporary(fwd.timeout());
}
ruleBuilder.forTable(forTableId);
return Collections.singletonList(ruleBuilder.build());
}
use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class SpringOpenTTP method addGroup.
private void addGroup(NextObjective nextObjective) {
log.debug("addGroup with type{} for nextObjective id {}", nextObjective.type(), nextObjective.id());
List<GroupBucket> buckets;
switch(nextObjective.type()) {
case SIMPLE:
Collection<TrafficTreatment> treatments = nextObjective.next();
if (treatments.size() == 1) {
// Spring Open TTP converts simple nextObjective to flow-actions
// in a dummy group
TrafficTreatment treatment = nextObjective.next().iterator().next();
log.debug("Converting SIMPLE group for next objective id {} " + "to {} flow-actions in device:{}", nextObjective.id(), treatment.allInstructions().size(), deviceId);
flowObjectiveStore.putNextGroup(nextObjective.id(), new SpringOpenGroup(null, treatment));
}
break;
case HASHED:
// we convert MPLS ECMP groups to flow-actions for a single
// bucket(output port).
boolean mplsEcmp = false;
if (nextObjective.meta() != null) {
for (Criterion c : nextObjective.meta().criteria()) {
if (c.type() == Type.MPLS_LABEL) {
mplsEcmp = true;
}
}
}
if (mplsEcmp) {
// covert to flow-actions in a dummy group by choosing the first bucket
log.debug("Converting HASHED group for next objective id {} " + "to flow-actions in device:{}", nextObjective.id(), deviceId);
TrafficTreatment treatment = nextObjective.next().iterator().next();
flowObjectiveStore.putNextGroup(nextObjective.id(), new SpringOpenGroup(null, treatment));
} else {
// process as ECMP group
buckets = nextObjective.next().stream().map(DefaultGroupBucket::createSelectGroupBucket).collect(Collectors.toList());
if (!buckets.isEmpty()) {
final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
GroupDescription groupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.SELECT, new GroupBuckets(buckets), key, null, nextObjective.appId());
log.debug("Creating HASHED group for next objective id {}" + " in dev:{}", nextObjective.id(), deviceId);
pendingGroups.put(key, nextObjective);
groupService.addGroup(groupDescription);
verifyPendingGroupLater();
}
}
break;
case BROADCAST:
buckets = nextObjective.next().stream().map(DefaultGroupBucket::createAllGroupBucket).collect(Collectors.toList());
if (!buckets.isEmpty()) {
final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
GroupDescription groupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.ALL, new GroupBuckets(buckets), key, null, nextObjective.appId());
log.debug("Creating BROADCAST group for next objective id {} " + "in device {}", nextObjective.id(), deviceId);
pendingGroups.put(key, nextObjective);
groupService.addGroup(groupDescription);
verifyPendingGroupLater();
}
break;
case FAILOVER:
log.debug("FAILOVER next objectives not supported");
fail(nextObjective, ObjectiveError.UNSUPPORTED);
log.warn("Unsupported next objective type {}", nextObjective.type());
break;
default:
fail(nextObjective, ObjectiveError.UNKNOWN);
log.warn("Unknown next objective type {}", nextObjective.type());
}
}
Aggregations