use of org.onosproject.net.flowobjective.Objective in project onos by opennetworkinglab.
the class VirtualNetworkFlowObjectiveManagerTest method nextObjective.
/**
* Tests adding a next objective.
*/
@Test
public void nextObjective() {
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
NextObjective nextObjective = DefaultNextObjective.builder().withId(service1.allocateNextId()).fromApp(NetTestTools.APP_ID).addTreatment(treatment).withType(NextObjective.Type.BROADCAST).makePermanent().add(new ObjectiveContext() {
@Override
public void onSuccess(Objective objective) {
assertEquals("1 next map entry expected", 1, service1.getNextMappings().size());
assertEquals("0 next map entry expected", 0, service2.getNextMappings().size());
}
});
service1.next(VDID1, nextObjective);
}
use of org.onosproject.net.flowobjective.Objective in project onos by opennetworkinglab.
the class FlowObjectiveIntentInstallerTest method createFlowObjectiveIntents.
/**
* Creates flow objective Intents.
*
* @return the flow objective intents
*/
private List<Intent> createFlowObjectiveIntents() {
TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(CP1.port()).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(CP2.port()).build();
FilteringObjective filt = DefaultFilteringObjective.builder().addCondition(selector.getCriterion(Criterion.Type.IN_PORT)).withPriority(DEFAULT_PRIORITY).fromApp(APP_ID).permit().add();
NextObjective next = DefaultNextObjective.builder().withMeta(selector).addTreatment(treatment).makePermanent().withPriority(DEFAULT_PRIORITY).fromApp(APP_ID).withType(NextObjective.Type.SIMPLE).withId(NEXT_ID_1).add();
ForwardingObjective fwd = DefaultForwardingObjective.builder().withSelector(selector).fromApp(APP_ID).withPriority(DEFAULT_PRIORITY).makePermanent().withFlag(ForwardingObjective.Flag.SPECIFIC).nextStep(NEXT_ID_1).add();
List<Objective> objectives = ImmutableList.of(filt, next, fwd);
List<DeviceId> deviceIds = ImmutableList.of(CP1.deviceId(), CP1.deviceId(), CP1.deviceId());
List<NetworkResource> resources = ImmutableList.of(CP1.deviceId());
Intent intent = new FlowObjectiveIntent(APP_ID, KEY1, deviceIds, objectives, resources, RG1);
return ImmutableList.of(intent);
}
use of org.onosproject.net.flowobjective.Objective in project onos by opennetworkinglab.
the class IntentFilter method getFlowEntries.
/**
* Finds all flow entries created by FlowObjectiveIntent.
*
* @param intent FlowObjectiveIntent Object
* @return set of flow entries created by FlowObjectiveIntent
*/
private List<FlowEntry> getFlowEntries(FlowObjectiveIntent intent) {
List<FlowEntry> flowEntries = new ArrayList<>();
Iterator<Objective> objectives = intent.objectives().iterator();
Iterator<DeviceId> devices = intent.devices().iterator();
DefaultNextObjective nextObjective = null;
DefaultForwardingObjective forwardObjective;
Objective objective;
DeviceId deviceId;
FlowEntry flowEntry;
while (objectives.hasNext()) {
objective = objectives.next();
deviceId = devices.next();
if (objective instanceof NextObjective) {
nextObjective = (DefaultNextObjective) objective;
} else if (objective instanceof ForwardingObjective) {
forwardObjective = (DefaultForwardingObjective) objective;
FlowRule.Builder builder = DefaultFlowRule.builder().forDevice(deviceId).withSelector(forwardObjective.selector()).withPriority(intent.priority()).fromApp(intent.appId()).makePermanent();
if (nextObjective != null) {
builder.withTreatment(nextObjective.next().iterator().next());
}
FlowRule flowRule = builder.build();
flowEntry = getFlowEntry(flowRule);
if (flowEntry != null) {
flowEntries.add(flowEntry);
}
}
}
return flowEntries;
}
use of org.onosproject.net.flowobjective.Objective in project onos by opennetworkinglab.
the class AbstractCorsaPipeline method next.
@Override
public void next(NextObjective nextObjective) {
switch(nextObjective.type()) {
case SIMPLE:
Collection<TrafficTreatment> treatments = nextObjective.next();
if (treatments.size() == 1) {
TrafficTreatment treatment = treatments.iterator().next();
CorsaTrafficTreatment corsaTreatment = processNextTreatment(treatment);
final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
if (corsaTreatment.type() == CorsaTrafficTreatmentType.GROUP) {
GroupBucket bucket = DefaultGroupBucket.createIndirectGroupBucket(corsaTreatment.treatment());
GroupBuckets buckets = new GroupBuckets(Collections.singletonList(bucket));
// group id == null, let group service determine group id
GroupDescription groupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.INDIRECT, buckets, key, null, nextObjective.appId());
groupService.addGroup(groupDescription);
pendingGroups.put(key, nextObjective);
} else if (corsaTreatment.type() == CorsaTrafficTreatmentType.ACTIONS) {
pendingNext.put(nextObjective.id(), nextObjective);
flowObjectiveStore.putNextGroup(nextObjective.id(), new CorsaGroup(key));
nextObjective.context().ifPresent(context -> context.onSuccess(nextObjective));
}
}
break;
case HASHED:
case BROADCAST:
case FAILOVER:
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());
}
}
use of org.onosproject.net.flowobjective.Objective in project onos by opennetworkinglab.
the class LinkCollectionIntentFlowObjectiveCompilerTest method singleHopTestForSp.
/**
* Single point to multiple point intent with only one switch.
* We test the proper compilation of sp2mp with
* trivial selector, trivial treatment and 1 hop.
*/
@Test
public void singleHopTestForSp() {
Set<Link> testLinks = ImmutableSet.of();
Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(of1p1, vlan100Selector));
Set<FilteredConnectPoint> egress = ImmutableSet.of(new FilteredConnectPoint(of1p2, vlan100Selector), new FilteredConnectPoint(of1p3, vlan100Selector));
LinkCollectionIntent intent = LinkCollectionIntent.builder().appId(appId).selector(ethDstSelector).treatment(treatment).links(testLinks).filteredIngressPoints(ingress).filteredEgressPoints(egress).applyTreatmentOnEgress(true).resourceGroup(resourceGroup2).build();
List<Intent> result = compiler.compile(intent, Collections.emptyList());
assertThat(result, hasSize(1));
assertThat(result.get(0), instanceOf(FlowObjectiveIntent.class));
FlowObjectiveIntent foIntent = (FlowObjectiveIntent) result.get(0);
List<Objective> objectives = foIntent.objectives();
assertThat(objectives, hasSize(3));
TrafficSelector expectSelector = DefaultTrafficSelector.builder(ethDstSelector).matchInPort(PortNumber.portNumber(1)).matchVlanId(VLAN_100).build();
List<TrafficTreatment> expectTreatments = ImmutableList.of(DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(2)).build(), DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(3)).build());
/*
* First set of objective
*/
filteringObjective = (FilteringObjective) objectives.get(0);
forwardingObjective = (ForwardingObjective) objectives.get(1);
nextObjective = (NextObjective) objectives.get(2);
PortCriterion inPortCriterion = (PortCriterion) expectSelector.getCriterion(Criterion.Type.IN_PORT);
// test case for first filtering objective
checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, vlan100Selector.criteria());
// test case for first next objective
checkNext(nextObjective, BROADCAST, expectTreatments, expectSelector, ADD);
// test case for first forwarding objective
checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
}
Aggregations