Refactor Intent subsystem to eliminate using FlowRuleBatchOperation

Change-Id: Iee76dac5fa9935713ffc370b34ac47d9286ff351
This commit is contained in:
Ray Milkey 2015-02-18 15:08:07 -08:00 committed by Gerrit Code Review
parent 97cf7c4138
commit 71ade56cbf
10 changed files with 184 additions and 178 deletions

View File

@ -103,6 +103,17 @@ public class FlowRuleOperations {
return this; return this;
} }
/**
* Appends an existing flow rule to the current stage.
*
* @param flowRuleOperation flow rule operation
* @return this
*/
public Builder operation(FlowRuleOperation flowRuleOperation) {
currentStage.add(flowRuleOperation);
return this;
}
/** /**
* Appends a flow rule modify to the current stage. * Appends a flow rule modify to the current stage.
* *

View File

@ -15,9 +15,10 @@
*/ */
package org.onosproject.net.intent; package org.onosproject.net.intent;
import org.onosproject.net.flow.FlowRuleBatchOperation;
import java.util.List; import java.util.List;
import java.util.Set;
import org.onosproject.net.flow.FlowRuleOperation;
/** /**
* Abstraction of entity capable of installing intents to the environment. * Abstraction of entity capable of installing intents to the environment.
@ -31,7 +32,7 @@ public interface IntentInstaller<T extends Intent> {
* @return flow rule operations to complete install * @return flow rule operations to complete install
* @throws IntentException if issues are encountered while installing the intent * @throws IntentException if issues are encountered while installing the intent
*/ */
List<FlowRuleBatchOperation> install(T intent); List<Set<FlowRuleOperation>> install(T intent);
/** /**
* Uninstalls the specified intent from the environment. * Uninstalls the specified intent from the environment.
@ -40,7 +41,7 @@ public interface IntentInstaller<T extends Intent> {
* @return flow rule operations to complete uninstall * @return flow rule operations to complete uninstall
* @throws IntentException if issues are encountered while uninstalling the intent * @throws IntentException if issues are encountered while uninstalling the intent
*/ */
List<FlowRuleBatchOperation> uninstall(T intent); List<Set<FlowRuleOperation>> uninstall(T intent);
/** /**
* Replaces the specified intent with a new one in the environment. * Replaces the specified intent with a new one in the environment.
@ -50,6 +51,6 @@ public interface IntentInstaller<T extends Intent> {
* @return flow rule operations to complete the replace * @return flow rule operations to complete the replace
* @throws IntentException if issues are encountered while uninstalling the intent * @throws IntentException if issues are encountered while uninstalling the intent
*/ */
List<FlowRuleBatchOperation> replace(T oldIntent, T newIntent); List<Set<FlowRuleOperation>> replace(T oldIntent, T newIntent);
} }

View File

@ -35,7 +35,7 @@ import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.onosproject.core.IdGenerator; import org.onosproject.core.IdGenerator;
import org.onosproject.net.flow.FlowRuleBatchOperation; import org.onosproject.net.flow.FlowRuleOperation;
import org.onosproject.net.resource.LinkResourceAllocations; import org.onosproject.net.resource.LinkResourceAllocations;
/** /**
@ -319,7 +319,7 @@ public class IntentServiceTest {
} }
@Override @Override
public List<FlowRuleBatchOperation> install(TestInstallableIntent intent) { public List<Set<FlowRuleOperation>> install(TestInstallableIntent intent) {
if (fail) { if (fail) {
throw new IntentException("install failed by design"); throw new IntentException("install failed by design");
} }
@ -327,7 +327,7 @@ public class IntentServiceTest {
} }
@Override @Override
public List<FlowRuleBatchOperation> uninstall(TestInstallableIntent intent) { public List<Set<FlowRuleOperation>> uninstall(TestInstallableIntent intent) {
if (fail) { if (fail) {
throw new IntentException("remove failed by design"); throw new IntentException("remove failed by design");
} }
@ -335,7 +335,7 @@ public class IntentServiceTest {
} }
@Override @Override
public List<FlowRuleBatchOperation> replace(TestInstallableIntent intent, public List<Set<FlowRuleOperation>> replace(TestInstallableIntent intent,
TestInstallableIntent newIntent) { TestInstallableIntent newIntent) {
return null; return null;
} }

View File

@ -15,8 +15,23 @@
*/ */
package org.onosproject.net.intent.impl; package org.onosproject.net.intent.impl;
import com.google.common.collect.ImmutableList; import java.util.ArrayList;
import com.google.common.collect.ImmutableMap; import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Deactivate;
@ -27,9 +42,7 @@ import org.onosproject.core.CoreService;
import org.onosproject.core.IdGenerator; import org.onosproject.core.IdGenerator;
import org.onosproject.event.AbstractListenerRegistry; import org.onosproject.event.AbstractListenerRegistry;
import org.onosproject.event.EventDeliveryService; import org.onosproject.event.EventDeliveryService;
import org.onosproject.net.flow.FlowRule; import org.onosproject.net.flow.FlowRuleOperation;
import org.onosproject.net.flow.FlowRuleBatchEntry;
import org.onosproject.net.flow.FlowRuleBatchOperation;
import org.onosproject.net.flow.FlowRuleOperations; import org.onosproject.net.flow.FlowRuleOperations;
import org.onosproject.net.flow.FlowRuleOperationsContext; import org.onosproject.net.flow.FlowRuleOperationsContext;
import org.onosproject.net.flow.FlowRuleService; import org.onosproject.net.flow.FlowRuleService;
@ -55,21 +68,8 @@ import org.onosproject.net.intent.impl.phase.WithdrawRequest;
import org.onosproject.net.intent.impl.phase.Withdrawn; import org.onosproject.net.intent.impl.phase.Withdrawn;
import org.slf4j.Logger; import org.slf4j.Logger;
import java.util.ArrayList; import com.google.common.collect.ImmutableList;
import java.util.Collection; import com.google.common.collect.ImmutableMap;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
@ -77,7 +77,11 @@ import static java.util.concurrent.Executors.newFixedThreadPool;
import static java.util.concurrent.Executors.newSingleThreadExecutor; import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.onlab.util.Tools.groupedThreads; import static org.onlab.util.Tools.groupedThreads;
import static org.onlab.util.Tools.isNullOrEmpty; import static org.onlab.util.Tools.isNullOrEmpty;
import static org.onosproject.net.intent.IntentState.*; import static org.onosproject.net.intent.IntentState.FAILED;
import static org.onosproject.net.intent.IntentState.INSTALLED;
import static org.onosproject.net.intent.IntentState.INSTALL_REQ;
import static org.onosproject.net.intent.IntentState.WITHDRAWN;
import static org.onosproject.net.intent.IntentState.WITHDRAW_REQ;
import static org.slf4j.LoggerFactory.getLogger; import static org.slf4j.LoggerFactory.getLogger;
/** /**
@ -301,7 +305,7 @@ public class IntentManager
oldInstallables.size() == newInstallables.size(), oldInstallables.size() == newInstallables.size(),
"Old and New Intent must have equivalent installable intents."); "Old and New Intent must have equivalent installable intents.");
List<List<FlowRuleBatchOperation>> plans = new ArrayList<>(); List<List<Set<FlowRuleOperation>>> plans = new ArrayList<>();
for (int i = 0; i < newInstallables.size(); i++) { for (int i = 0; i < newInstallables.size(); i++) {
Intent newInstallable = newInstallables.get(i); Intent newInstallable = newInstallables.get(i);
registerSubclassInstallerIfNeeded(newInstallable); registerSubclassInstallerIfNeeded(newInstallable);
@ -359,7 +363,7 @@ public class IntentManager
// TODO: make this non-public due to short term hack for ONOS-1051 // TODO: make this non-public due to short term hack for ONOS-1051
public FlowRuleOperations uninstallCoordinate(IntentData current, IntentData pending) { public FlowRuleOperations uninstallCoordinate(IntentData current, IntentData pending) {
List<Intent> installables = current.installables(); List<Intent> installables = current.installables();
List<List<FlowRuleBatchOperation>> plans = new ArrayList<>(); List<List<Set<FlowRuleOperation>>> plans = new ArrayList<>();
for (Intent installable : installables) { for (Intent installable : installables) {
plans.add(getInstaller(installable).uninstall(installable)); plans.add(getInstaller(installable).uninstall(installable));
trackerService.removeTrackedResources(pending.key(), installable.resources()); trackerService.removeTrackedResources(pending.key(), installable.resources());
@ -385,35 +389,22 @@ public class IntentManager
// TODO needs tests... or maybe it's just perfect // TODO needs tests... or maybe it's just perfect
private FlowRuleOperations.Builder merge(List<List<FlowRuleBatchOperation>> plans) { private FlowRuleOperations.Builder merge(List<List<Set<FlowRuleOperation>>> plans) {
FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
// Build a batch one stage at a time // Build a batch one stage at a time
for (int stageNumber = 0;; stageNumber++) { for (int stageNumber = 0;; stageNumber++) {
// Get the sub-stage from each plan (List<FlowRuleBatchOperation>) // Get the sub-stage from each plan (List<Set<FlowRuleOperation>)
for (Iterator<List<FlowRuleBatchOperation>> itr = plans.iterator(); itr.hasNext();) { for (Iterator<List<Set<FlowRuleOperation>>> itr = plans.iterator(); itr.hasNext();) {
List<FlowRuleBatchOperation> plan = itr.next(); List<Set<FlowRuleOperation>> plan = itr.next();
if (plan.size() <= stageNumber) { if (plan.size() <= stageNumber) {
// we have consumed all stages from this plan, so remove it // we have consumed all stages from this plan, so remove it
itr.remove(); itr.remove();
continue; continue;
} }
// write operations from this sub-stage into the builder // write operations from this sub-stage into the builder
FlowRuleBatchOperation stage = plan.get(stageNumber); Set<FlowRuleOperation> stage = plan.get(stageNumber);
for (FlowRuleBatchEntry entry : stage.getOperations()) { for (FlowRuleOperation entry : stage) {
FlowRule rule = entry.target(); builder.operation(entry);
switch (entry.operator()) {
case ADD:
builder.add(rule);
break;
case REMOVE:
builder.remove(rule);
break;
case MODIFY:
builder.modify(rule);
break;
default:
break;
}
} }
} }
// we are done with the stage, start the next one... // we are done with the stage, start the next one...

View File

@ -15,9 +15,10 @@
*/ */
package org.onosproject.net.intent.impl; package org.onosproject.net.intent.impl;
import com.google.common.collect.HashMultimap; import java.util.List;
import com.google.common.collect.Lists; import java.util.Set;
import com.google.common.collect.SetMultimap; import java.util.stream.Collectors;
import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Deactivate;
@ -34,19 +35,17 @@ import org.onosproject.net.flow.DefaultFlowRule;
import org.onosproject.net.flow.DefaultTrafficSelector; import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment; import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.FlowRule; import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.FlowRuleBatchEntry; import org.onosproject.net.flow.FlowRuleOperation;
import org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation;
import org.onosproject.net.flow.FlowRuleBatchOperation;
import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.intent.IntentExtensionService; import org.onosproject.net.intent.IntentExtensionService;
import org.onosproject.net.intent.IntentInstaller; import org.onosproject.net.intent.IntentInstaller;
import org.onosproject.net.intent.LinkCollectionIntent; import org.onosproject.net.intent.LinkCollectionIntent;
import java.util.Collections; import com.google.common.collect.HashMultimap;
import java.util.List; import com.google.common.collect.ImmutableSet;
import java.util.Set; import com.google.common.collect.Lists;
import java.util.stream.Collectors; import com.google.common.collect.SetMultimap;
/** /**
* Installer for {@link org.onosproject.net.intent.LinkCollectionIntent} path * Installer for {@link org.onosproject.net.intent.LinkCollectionIntent} path
@ -76,17 +75,17 @@ public class LinkCollectionIntentInstaller
} }
@Override @Override
public List<FlowRuleBatchOperation> install(LinkCollectionIntent intent) { public List<Set<FlowRuleOperation>> install(LinkCollectionIntent intent) {
return generateBatchOperations(intent, FlowRuleOperation.ADD); return generateBatchOperations(intent, FlowRuleOperation.Type.ADD);
} }
@Override @Override
public List<FlowRuleBatchOperation> uninstall(LinkCollectionIntent intent) { public List<Set<FlowRuleOperation>> uninstall(LinkCollectionIntent intent) {
return generateBatchOperations(intent, FlowRuleOperation.REMOVE); return generateBatchOperations(intent, FlowRuleOperation.Type.REMOVE);
} }
private List<FlowRuleBatchOperation> generateBatchOperations( private List<Set<FlowRuleOperation>> generateBatchOperations(
LinkCollectionIntent intent, FlowRuleOperation operation) { LinkCollectionIntent intent, FlowRuleOperation.Type operation) {
SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create(); SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();
@ -99,23 +98,33 @@ public class LinkCollectionIntentInstaller
} }
//FIXME change to new api //FIXME change to new api
FlowRuleBatchOperation batchOperation = /* Fear of streams */
new FlowRuleBatchOperation(outputPorts /*
Set<FlowRuleBatchEntry> rules = Sets.newHashSet();
for (DeviceId deviceId : outputPorts.keys()) {
rules.add(createBatchEntry(operation,
intent, deviceId,
outputPorts.get(deviceId)));
}
*/
Set<FlowRuleOperation> rules =
outputPorts
.keys() .keys()
.stream() .stream()
.map(deviceId -> createBatchEntry(operation, .map(deviceId -> createBatchEntry(operation,
intent, deviceId, intent, deviceId,
outputPorts.get(deviceId))) outputPorts.get(deviceId)))
.collect(Collectors.toList()), null, 0); .collect(Collectors.toSet());
return Collections.singletonList(batchOperation); return Lists.newArrayList(ImmutableSet.of(rules));
} }
@Override @Override
public List<FlowRuleBatchOperation> replace(LinkCollectionIntent oldIntent, public List<Set<FlowRuleOperation>> replace(LinkCollectionIntent oldIntent,
LinkCollectionIntent newIntent) { LinkCollectionIntent newIntent) {
// FIXME: implement this in a more intelligent/less brute force way // FIXME: implement this in a more intelligent/less brute force way
List<FlowRuleBatchOperation> batches = Lists.newArrayList(); List<Set<FlowRuleOperation>> batches = Lists.newArrayList();
batches.addAll(uninstall(oldIntent)); batches.addAll(uninstall(oldIntent));
batches.addAll(install(newIntent)); batches.addAll(install(newIntent));
return batches; return batches;
@ -130,7 +139,7 @@ public class LinkCollectionIntentInstaller
* @param outPorts the set of output ports for the flow rule * @param outPorts the set of output ports for the flow rule
* @return the new flow rule batch entry * @return the new flow rule batch entry
*/ */
private FlowRuleBatchEntry createBatchEntry(FlowRuleOperation operation, private FlowRuleOperation createBatchEntry(FlowRuleOperation.Type operation,
LinkCollectionIntent intent, LinkCollectionIntent intent,
DeviceId deviceId, DeviceId deviceId,
Set<PortNumber> outPorts) { Set<PortNumber> outPorts) {
@ -151,6 +160,6 @@ public class LinkCollectionIntentInstaller
new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)), new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)),
0, true); 0, true);
return new FlowRuleBatchEntry(operation, rule); return new FlowRuleOperation(rule, operation);
} }
} }

View File

@ -1,7 +1,5 @@
package org.onosproject.net.intent.impl; package org.onosproject.net.intent.impl;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -22,11 +20,9 @@ import org.onosproject.net.flow.DefaultFlowRule;
import org.onosproject.net.flow.DefaultTrafficSelector; import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment; import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.FlowRule; import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.FlowRuleBatchEntry; import org.onosproject.net.flow.FlowRuleOperation;
import org.onosproject.net.flow.FlowRuleBatchOperation;
import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation;
import org.onosproject.net.flow.criteria.Criteria.EthTypeCriterion; import org.onosproject.net.flow.criteria.Criteria.EthTypeCriterion;
import org.onosproject.net.flow.criteria.Criterion; import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.criteria.Criterion.Type; import org.onosproject.net.flow.criteria.Criterion.Type;
@ -44,11 +40,13 @@ import org.onosproject.net.resource.ResourceAllocation;
import org.onosproject.net.resource.ResourceType; import org.onosproject.net.resource.ResourceType;
import org.slf4j.Logger; import org.slf4j.Logger;
import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
/** /**
* Installer for {@link MplsPathIntent packet path connectivity intents}. * Installer for {@link MplsPathIntent packet path connectivity intents}.
*/ */
@ -83,29 +81,26 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent>
} }
@Override @Override
public List<FlowRuleBatchOperation> install(MplsPathIntent intent) { public List<Set<FlowRuleOperation>> install(MplsPathIntent intent) {
LinkResourceAllocations allocations = assignMplsLabel(intent); LinkResourceAllocations allocations = assignMplsLabel(intent);
return generateRules(intent, allocations, FlowRuleOperation.ADD); return generateRules(intent, allocations, FlowRuleOperation.Type.ADD);
} }
@Override @Override
public List<FlowRuleBatchOperation> uninstall(MplsPathIntent intent) { public List<Set<FlowRuleOperation>> uninstall(MplsPathIntent intent) {
LinkResourceAllocations allocations = resourceService LinkResourceAllocations allocations = resourceService
.getAllocations(intent.id()); .getAllocations(intent.id());
resourceService.releaseResources(allocations); resourceService.releaseResources(allocations);
List<FlowRuleBatchOperation> rules = generateRules(intent, return generateRules(intent, allocations, FlowRuleOperation.Type.REMOVE);
allocations,
FlowRuleOperation.REMOVE);
return rules;
} }
@Override @Override
public List<FlowRuleBatchOperation> replace(MplsPathIntent oldIntent, public List<Set<FlowRuleOperation>> replace(MplsPathIntent oldIntent,
MplsPathIntent newIntent) { MplsPathIntent newIntent) {
List<FlowRuleBatchOperation> batches = Lists.newArrayList(); List<Set<FlowRuleOperation>> batches = Lists.newArrayList();
batches.addAll(uninstall(oldIntent)); batches.addAll(uninstall(oldIntent));
batches.addAll(install(newIntent)); batches.addAll(install(newIntent));
return batches; return batches;
@ -145,9 +140,9 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent>
return null; return null;
} }
private List<FlowRuleBatchOperation> generateRules(MplsPathIntent intent, private List<Set<FlowRuleOperation>> generateRules(MplsPathIntent intent,
LinkResourceAllocations allocations, LinkResourceAllocations allocations,
FlowRuleOperation operation) { FlowRuleOperation.Type operation) {
Iterator<Link> links = intent.path().links().iterator(); Iterator<Link> links = intent.path().links().iterator();
Link srcLink = links.next(); Link srcLink = links.next();
@ -155,7 +150,7 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent>
Link link = links.next(); Link link = links.next();
// List of flow rules to be installed // List of flow rules to be installed
List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); Set<FlowRuleOperation> rules = Sets.newHashSet();
// Ingress traffic // Ingress traffic
// Get the new MPLS label // Get the new MPLS label
@ -187,13 +182,13 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent>
prev = link.dst(); prev = link.dst();
} }
return Lists.newArrayList(new FlowRuleBatchOperation(rules, null, 0)); return Lists.newArrayList(ImmutableSet.of(rules));
} }
private FlowRuleBatchEntry ingressFlow(PortNumber inPort, Link link, private FlowRuleOperation ingressFlow(PortNumber inPort, Link link,
MplsPathIntent intent, MplsPathIntent intent,
MplsLabel label, MplsLabel label,
FlowRuleOperation operation) { FlowRuleOperation.Type operation) {
TrafficSelector.Builder ingressSelector = DefaultTrafficSelector TrafficSelector.Builder ingressSelector = DefaultTrafficSelector
.builder(intent.selector()); .builder(intent.selector());
@ -213,16 +208,16 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent>
// Add the output action // Add the output action
treat.setOutput(link.src().port()); treat.setOutput(link.src().port());
return flowRuleBatchEntry(intent, link.src().deviceId(), return flowRuleOperation(intent, link.src().deviceId(),
ingressSelector.build(), treat.build(), ingressSelector.build(), treat.build(),
operation); operation);
} }
private FlowRuleBatchEntry transitFlow(PortNumber inPort, Link link, private FlowRuleOperation transitFlow(PortNumber inPort, Link link,
MplsPathIntent intent, MplsPathIntent intent,
MplsLabel prevLabel, MplsLabel prevLabel,
MplsLabel outLabel, MplsLabel outLabel,
FlowRuleOperation operation) { FlowRuleOperation.Type operation) {
// Ignore the ingress Traffic Selector and use only the MPLS label // Ignore the ingress Traffic Selector and use only the MPLS label
// assigned in the previous link // assigned in the previous link
@ -238,14 +233,14 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent>
} }
treat.setOutput(link.src().port()); treat.setOutput(link.src().port());
return flowRuleBatchEntry(intent, link.src().deviceId(), return flowRuleOperation(intent, link.src().deviceId(),
selector.build(), treat.build(), operation); selector.build(), treat.build(), operation);
} }
private FlowRuleBatchEntry egressFlow(PortNumber inPort, Link link, private FlowRuleOperation egressFlow(PortNumber inPort, Link link,
MplsPathIntent intent, MplsPathIntent intent,
MplsLabel prevLabel, MplsLabel prevLabel,
FlowRuleOperation operation) { FlowRuleOperation.Type operation) {
// egress point: either set the egress MPLS label or pop the // egress point: either set the egress MPLS label or pop the
// MPLS label based on the intent annotations // MPLS label based on the intent annotations
@ -272,15 +267,15 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent>
} }
treat.setOutput(link.src().port()); treat.setOutput(link.src().port());
return flowRuleBatchEntry(intent, link.src().deviceId(), return flowRuleOperation(intent, link.src().deviceId(),
selector.build(), treat.build(), operation); selector.build(), treat.build(), operation);
} }
protected FlowRuleBatchEntry flowRuleBatchEntry(MplsPathIntent intent, protected FlowRuleOperation flowRuleOperation(MplsPathIntent intent,
DeviceId deviceId, DeviceId deviceId,
TrafficSelector selector, TrafficSelector selector,
TrafficTreatment treat, TrafficTreatment treat,
FlowRuleOperation operation) { FlowRuleOperation.Type operation) {
FlowRule rule = new DefaultFlowRule( FlowRule rule = new DefaultFlowRule(
deviceId, deviceId,
selector, selector,
@ -289,8 +284,7 @@ public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent>
appId, appId,
0, 0,
true); true);
return new FlowRuleBatchEntry(operation, rule, intent.id() return new FlowRuleOperation(rule, operation);
.fingerprint());
} }
} }

View File

@ -15,7 +15,9 @@
*/ */
package org.onosproject.net.intent.impl; package org.onosproject.net.intent.impl;
import com.google.common.collect.Lists; import java.util.List;
import java.util.Set;
import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Deactivate;
@ -29,9 +31,7 @@ import org.onosproject.net.flow.DefaultFlowRule;
import org.onosproject.net.flow.DefaultTrafficSelector; import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment; import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.FlowRule; import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.FlowRuleBatchEntry; import org.onosproject.net.flow.FlowRuleOperation;
import org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation;
import org.onosproject.net.flow.FlowRuleBatchOperation;
import org.onosproject.net.flow.FlowRuleService; import org.onosproject.net.flow.FlowRuleService;
import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.flow.TrafficTreatment;
@ -49,7 +49,9 @@ import org.onosproject.net.resource.ResourceType;
import org.onosproject.net.topology.TopologyService; import org.onosproject.net.topology.TopologyService;
import org.slf4j.Logger; import org.slf4j.Logger;
import java.util.List; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
import static org.slf4j.LoggerFactory.getLogger; import static org.slf4j.LoggerFactory.getLogger;
@ -92,24 +94,24 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
} }
@Override @Override
public List<FlowRuleBatchOperation> install(OpticalPathIntent intent) { public List<Set<FlowRuleOperation>> install(OpticalPathIntent intent) {
LinkResourceAllocations allocations = assignWavelength(intent); LinkResourceAllocations allocations = assignWavelength(intent);
return generateRules(intent, allocations, FlowRuleOperation.ADD); return generateRules(intent, allocations, FlowRuleOperation.Type.ADD);
} }
@Override @Override
public List<FlowRuleBatchOperation> uninstall(OpticalPathIntent intent) { public List<Set<FlowRuleOperation>> uninstall(OpticalPathIntent intent) {
LinkResourceAllocations allocations = resourceService.getAllocations(intent.id()); LinkResourceAllocations allocations = resourceService.getAllocations(intent.id());
List<FlowRuleBatchOperation> rules = generateRules(intent, allocations, FlowRuleOperation.REMOVE); List<Set<FlowRuleOperation>> rules = generateRules(intent, allocations, FlowRuleOperation.Type.REMOVE);
log.info("uninstall rules: {}", rules); log.info("uninstall rules: {}", rules);
return rules; return rules;
} }
@Override @Override
public List<FlowRuleBatchOperation> replace(OpticalPathIntent oldIntent, public List<Set<FlowRuleOperation>> replace(OpticalPathIntent oldIntent,
OpticalPathIntent newIntent) { OpticalPathIntent newIntent) {
// FIXME: implement this // FIXME: implement this
List<FlowRuleBatchOperation> batches = Lists.newArrayList(); List<Set<FlowRuleOperation>> batches = Lists.newArrayList();
batches.addAll(uninstall(oldIntent)); batches.addAll(uninstall(oldIntent));
batches.addAll(install(newIntent)); batches.addAll(install(newIntent));
return batches; return batches;
@ -123,13 +125,13 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
return retLambda; return retLambda;
} }
private List<FlowRuleBatchOperation> generateRules(OpticalPathIntent intent, private List<Set<FlowRuleOperation>> generateRules(OpticalPathIntent intent,
LinkResourceAllocations allocations, LinkResourceAllocations allocations,
FlowRuleOperation operation) { FlowRuleOperation.Type operation) {
TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
selectorBuilder.matchInPort(intent.src().port()); selectorBuilder.matchInPort(intent.src().port());
List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); Set<FlowRuleOperation> rules = Sets.newHashSet();
ConnectPoint prev = intent.src(); ConnectPoint prev = intent.src();
//FIXME check for null allocations //FIXME check for null allocations
@ -160,7 +162,7 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
100, 100,
true); true);
rules.add(new FlowRuleBatchEntry(operation, rule)); rules.add(new FlowRuleOperation(rule, operation));
prev = link.dst(); prev = link.dst();
selectorBuilder.matchInPort(link.dst().port()); selectorBuilder.matchInPort(link.dst().port());
@ -179,9 +181,9 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
appId, appId,
100, 100,
true); true);
rules.add(new FlowRuleBatchEntry(operation, rule)); rules.add(new FlowRuleOperation(rule, operation));
//FIXME change to new api //FIXME change to new api
return Lists.newArrayList(new FlowRuleBatchOperation(rules, null, 0)); return Lists.newArrayList(ImmutableSet.of(rules));
} }
} }

View File

@ -17,6 +17,7 @@ package org.onosproject.net.intent.impl;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set;
import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Component;
@ -31,9 +32,7 @@ import org.onosproject.net.Link;
import org.onosproject.net.flow.DefaultFlowRule; import org.onosproject.net.flow.DefaultFlowRule;
import org.onosproject.net.flow.DefaultTrafficSelector; import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.FlowRule; import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.FlowRuleBatchEntry; import org.onosproject.net.flow.FlowRuleOperation;
import org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation;
import org.onosproject.net.flow.FlowRuleBatchOperation;
import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.intent.Constraint; import org.onosproject.net.intent.Constraint;
@ -46,7 +45,9 @@ import org.onosproject.net.resource.LinkResourceRequest;
import org.onosproject.net.resource.LinkResourceService; import org.onosproject.net.resource.LinkResourceService;
import org.slf4j.Logger; import org.slf4j.Logger;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
import static org.slf4j.LoggerFactory.getLogger; import static org.slf4j.LoggerFactory.getLogger;
@ -82,14 +83,14 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
} }
@Override @Override
public List<FlowRuleBatchOperation> install(PathIntent intent) { public List<Set<FlowRuleOperation>> install(PathIntent intent) {
LinkResourceAllocations allocations = allocateResources(intent); LinkResourceAllocations allocations = allocateResources(intent);
TrafficSelector.Builder builder = TrafficSelector.Builder builder =
DefaultTrafficSelector.builder(intent.selector()); DefaultTrafficSelector.builder(intent.selector());
Iterator<Link> links = intent.path().links().iterator(); Iterator<Link> links = intent.path().links().iterator();
ConnectPoint prev = links.next().dst(); ConnectPoint prev = links.next().dst();
List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); Set<FlowRuleOperation> rules = Sets.newHashSet();
// TODO Generate multiple batches // TODO Generate multiple batches
while (links.hasNext()) { while (links.hasNext()) {
builder.matchInPort(prev.port()); builder.matchInPort(prev.port());
@ -104,23 +105,21 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
appId, appId,
new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)), new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)),
0, true); 0, true);
rules.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, rule, rules.add(new FlowRuleOperation(rule, FlowRuleOperation.Type.ADD));
intent.id().fingerprint()));
prev = link.dst(); prev = link.dst();
} }
//FIXME this should change to new api.
return Lists.newArrayList(new FlowRuleBatchOperation(rules, null, 0)); return Lists.newArrayList(ImmutableSet.of(rules));
} }
@Override @Override
public List<FlowRuleBatchOperation> uninstall(PathIntent intent) { public List<Set<FlowRuleOperation>> uninstall(PathIntent intent) {
deallocateResources(intent); deallocateResources(intent);
TrafficSelector.Builder builder = TrafficSelector.Builder builder =
DefaultTrafficSelector.builder(intent.selector()); DefaultTrafficSelector.builder(intent.selector());
Iterator<Link> links = intent.path().links().iterator(); Iterator<Link> links = intent.path().links().iterator();
ConnectPoint prev = links.next().dst(); ConnectPoint prev = links.next().dst();
List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); Set<FlowRuleOperation> rules = Sets.newHashSet();
// TODO Generate multiple batches // TODO Generate multiple batches
while (links.hasNext()) { while (links.hasNext()) {
builder.matchInPort(prev.port()); builder.matchInPort(prev.port());
@ -133,18 +132,17 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
builder.build(), treatment, 123, appId, builder.build(), treatment, 123, appId,
new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)), new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)),
0, true); 0, true);
rules.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, rule, rules.add(new FlowRuleOperation(rule, FlowRuleOperation.Type.REMOVE));
intent.id().fingerprint()));
prev = link.dst(); prev = link.dst();
} }
// FIXME this should change to new api // FIXME this should change to new api
return Lists.newArrayList(new FlowRuleBatchOperation(rules, null, 0)); return Lists.newArrayList(ImmutableSet.of(rules));
} }
@Override @Override
public List<FlowRuleBatchOperation> replace(PathIntent oldIntent, PathIntent newIntent) { public List<Set<FlowRuleOperation>> replace(PathIntent oldIntent, PathIntent newIntent) {
// FIXME: implement this // FIXME: implement this
List<FlowRuleBatchOperation> batches = Lists.newArrayList(); List<Set<FlowRuleOperation>> batches = Lists.newArrayList();
batches.addAll(uninstall(oldIntent)); batches.addAll(uninstall(oldIntent));
batches.addAll(install(newIntent)); batches.addAll(install(newIntent));
return batches; return batches;

View File

@ -16,6 +16,7 @@
package org.onosproject.net.intent.impl; package org.onosproject.net.intent.impl;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
@ -32,9 +33,7 @@ import org.onosproject.core.impl.TestCoreManager;
import org.onosproject.event.impl.TestEventDispatcher; import org.onosproject.event.impl.TestEventDispatcher;
import org.onosproject.net.NetworkResource; import org.onosproject.net.NetworkResource;
import org.onosproject.net.flow.FlowRule; import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.FlowRuleBatchEntry; import org.onosproject.net.flow.FlowRuleOperation;
import org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation;
import org.onosproject.net.flow.FlowRuleBatchOperation;
import org.onosproject.net.intent.Intent; import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentCompiler; import org.onosproject.net.intent.IntentCompiler;
import org.onosproject.net.intent.IntentEvent; import org.onosproject.net.intent.IntentEvent;
@ -195,45 +194,45 @@ public class IntentManagerTest {
private static class TestIntentInstaller implements IntentInstaller<MockInstallableIntent> { private static class TestIntentInstaller implements IntentInstaller<MockInstallableIntent> {
@Override @Override
public List<FlowRuleBatchOperation> install(MockInstallableIntent intent) { public List<Set<org.onosproject.net.flow.FlowRuleOperation>> install(MockInstallableIntent intent) {
FlowRule fr = new IntentTestsMocks.MockFlowRule(intent.number().intValue()); FlowRule fr = new IntentTestsMocks.MockFlowRule(intent.number().intValue());
List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); Set<FlowRuleOperation> rules = ImmutableSet.of(
rules.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, fr)); new FlowRuleOperation(fr, FlowRuleOperation.Type.ADD));
return Lists.newArrayList(new FlowRuleBatchOperation(rules, fr.deviceId(), 0)); return Lists.newArrayList(ImmutableSet.of(rules));
} }
@Override @Override
public List<FlowRuleBatchOperation> uninstall(MockInstallableIntent intent) { public List<Set<FlowRuleOperation>> uninstall(MockInstallableIntent intent) {
FlowRule fr = new IntentTestsMocks.MockFlowRule(intent.number().intValue()); FlowRule fr = new IntentTestsMocks.MockFlowRule(intent.number().intValue());
List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); Set<FlowRuleOperation> rules = ImmutableSet.of(
rules.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, fr)); new FlowRuleOperation(fr, FlowRuleOperation.Type.REMOVE));
return Lists.newArrayList(new FlowRuleBatchOperation(rules, fr.deviceId(), 0)); return Lists.newArrayList(ImmutableSet.of(rules));
} }
@Override @Override
public List<FlowRuleBatchOperation> replace(MockInstallableIntent oldIntent, MockInstallableIntent newIntent) { public List<Set<FlowRuleOperation>> replace(MockInstallableIntent oldIntent, MockInstallableIntent newIntent) {
FlowRule fr = new IntentTestsMocks.MockFlowRule(oldIntent.number().intValue()); FlowRule fr = new IntentTestsMocks.MockFlowRule(oldIntent.number().intValue());
FlowRule fr2 = new IntentTestsMocks.MockFlowRule(newIntent.number().intValue()); FlowRule fr2 = new IntentTestsMocks.MockFlowRule(newIntent.number().intValue());
List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); Set<FlowRuleOperation> rules = ImmutableSet.of(
rules.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, fr)); new FlowRuleOperation(fr, FlowRuleOperation.Type.REMOVE),
rules.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, fr2)); new FlowRuleOperation(fr2, FlowRuleOperation.Type.ADD));
return Lists.newArrayList(new FlowRuleBatchOperation(rules, fr.deviceId(), 0)); return Lists.newArrayList(ImmutableSet.of(rules));
} }
} }
private static class TestIntentErrorInstaller implements IntentInstaller<MockInstallableIntent> { private static class TestIntentErrorInstaller implements IntentInstaller<MockInstallableIntent> {
@Override @Override
public List<FlowRuleBatchOperation> install(MockInstallableIntent intent) { public List<Set<FlowRuleOperation>> install(MockInstallableIntent intent) {
throw new IntentInstallationException("install() always fails"); throw new IntentInstallationException("install() always fails");
} }
@Override @Override
public List<FlowRuleBatchOperation> uninstall(MockInstallableIntent intent) { public List<Set<FlowRuleOperation>> uninstall(MockInstallableIntent intent) {
throw new IntentRemovalException("uninstall() always fails"); throw new IntentRemovalException("uninstall() always fails");
} }
@Override @Override
public List<FlowRuleBatchOperation> replace(MockInstallableIntent oldIntent, MockInstallableIntent newIntent) { public List<Set<FlowRuleOperation>> replace(MockInstallableIntent oldIntent, MockInstallableIntent newIntent) {
throw new IntentInstallationException("replace() always fails"); throw new IntentInstallationException("replace() always fails");
} }
} }

View File

@ -17,9 +17,10 @@ package org.onosproject.net.intent.impl;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set;
import org.junit.Test; import org.junit.Test;
import org.onosproject.net.flow.FlowRuleBatchOperation; import org.onosproject.net.flow.FlowRuleOperation;
import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.intent.AbstractIntentTest; import org.onosproject.net.intent.AbstractIntentTest;
@ -96,9 +97,9 @@ public class PathConstraintCalculationTest extends AbstractIntentTest {
* *
* @param compiledIntents list of compiled intents * @param compiledIntents list of compiled intents
* @param resourceService service to use for resource allocation requests * @param resourceService service to use for resource allocation requests
* @return * @return fow rule entries
*/ */
private List<FlowRuleBatchOperation> installIntents(List<Intent> compiledIntents, private List<Set<FlowRuleOperation>> installIntents(List<Intent> compiledIntents,
LinkResourceService resourceService) { LinkResourceService resourceService) {
final PathIntent path = (PathIntent) compiledIntents.get(0); final PathIntent path = (PathIntent) compiledIntents.get(0);
@ -192,7 +193,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest {
assertThat(compiledIntents, notNullValue()); assertThat(compiledIntents, notNullValue());
assertThat(compiledIntents, hasSize(1)); assertThat(compiledIntents, hasSize(1));
final List<FlowRuleBatchOperation> flowOperations = final List<Set<FlowRuleOperation>> flowOperations =
installIntents(compiledIntents, resourceService); installIntents(compiledIntents, resourceService);
assertThat(flowOperations, notNullValue()); assertThat(flowOperations, notNullValue());
@ -241,7 +242,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest {
assertThat(compiledIntents, notNullValue()); assertThat(compiledIntents, notNullValue());
assertThat(compiledIntents, hasSize(1)); assertThat(compiledIntents, hasSize(1));
final List<FlowRuleBatchOperation> flowOperations = final List<Set<FlowRuleOperation>> flowOperations =
installIntents(compiledIntents, resourceService); installIntents(compiledIntents, resourceService);
assertThat(flowOperations, notNullValue()); assertThat(flowOperations, notNullValue());