use of org.onosproject.net.behaviour.NextGroup in project onos by opennetworkinglab.
the class SpringOpenTTP method next.
@Override
public void next(NextObjective nextObjective) {
NextGroup nextGroup = flowObjectiveStore.getNextGroup(nextObjective.id());
switch(nextObjective.op()) {
case ADD:
if (nextGroup != null) {
log.warn("Cannot add next {} that already exists in device {}", nextObjective.id(), deviceId);
return;
}
log.debug("Processing NextObjective id{} in dev{} - add group", nextObjective.id(), deviceId);
addGroup(nextObjective);
break;
case ADD_TO_EXISTING:
if (nextGroup != null) {
log.debug("Processing NextObjective id{} in dev{} - add bucket", nextObjective.id(), deviceId);
addBucketToGroup(nextObjective);
} else {
log.warn("Cannot add to group that does not exist");
}
break;
case REMOVE:
if (nextGroup == null) {
log.warn("Cannot remove next {} that does not exist in device {}", nextObjective.id(), deviceId);
return;
}
log.debug("Processing NextObjective id{} in dev{} - remove group", nextObjective.id(), deviceId);
removeGroup(nextObjective);
break;
case REMOVE_FROM_EXISTING:
if (nextGroup == null) {
log.warn("Cannot remove from next {} that does not exist in device {}", nextObjective.id(), deviceId);
return;
}
log.debug("Processing NextObjective id{} in dev{} - remove bucket", nextObjective.id(), deviceId);
removeBucketFromGroup(nextObjective);
break;
default:
log.warn("Unsupported operation {}", nextObjective.op());
}
}
use of org.onosproject.net.behaviour.NextGroup in project onos by opennetworkinglab.
the class SpringOpenTTP method removeBucketFromGroup.
private void removeBucketFromGroup(NextObjective nextObjective) {
log.debug("removeBucketFromGroup in {}: for next objective id {}", deviceId, nextObjective.id());
NextGroup nextGroup = flowObjectiveStore.getNextGroup(nextObjective.id());
if (nextGroup != null) {
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 removeBuckets = new GroupBuckets(Collections.singletonList(bucket));
log.debug("Removing buckets from group id {} of next objective id {} in device {}", group.id(), nextObjective.id(), deviceId);
groupService.removeBucketsFromGroup(deviceId, key, removeBuckets, key, appId);
}
}
use of org.onosproject.net.behaviour.NextGroup 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.behaviour.NextGroup in project onos by opennetworkinglab.
the class SimpleVirtualFlowObjectiveStore method getAllGroups.
@Override
public Map<Integer, NextGroup> getAllGroups(NetworkId networkId) {
ConcurrentMap<Integer, byte[]> nextGroups = getNextGroups(networkId);
Map<Integer, NextGroup> nextGroupMappings = new HashMap<>();
for (int key : nextGroups.keySet()) {
NextGroup nextGroup = getNextGroup(networkId, key);
if (nextGroup != null) {
nextGroupMappings.put(key, nextGroup);
}
}
return nextGroupMappings;
}
use of org.onosproject.net.behaviour.NextGroup in project onos by opennetworkinglab.
the class AbstractCorsaPipeline method processSpecificRoute.
private Collection<FlowRule> processSpecificRoute(ForwardingObjective fwd) {
TrafficSelector filteredSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(((IPCriterion) fwd.selector().getCriterion(Criterion.Type.IPV4_DST)).ip()).build();
TrafficTreatment.Builder tb = processSpecificRoutingTreatment();
if (fwd.nextId() != null) {
NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
GroupKey key = appKryo.deserialize(next.data());
Group group = groupService.getGroup(deviceId, key);
if (group == null) {
log.warn("The group left!");
fail(fwd, ObjectiveError.GROUPMISSING);
return ImmutableSet.of();
}
tb.group(group.id());
} else {
log.error("Missing NextObjective ID for ForwardingObjective {}", fwd.id());
fail(fwd, ObjectiveError.BADPARAMS);
return ImmutableSet.of();
}
Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(filteredSelector).withTreatment(tb.build());
ruleBuilder = processSpecificRoutingRule(ruleBuilder);
if (fwd.permanent()) {
ruleBuilder.makePermanent();
} else {
ruleBuilder.makeTemporary(fwd.timeout());
}
return Collections.singletonList(ruleBuilder.build());
}
Aggregations