diff --git a/core/api/src/main/java/org/onosproject/net/flow/FlowRuleOperations.java b/core/api/src/main/java/org/onosproject/net/flow/FlowRuleOperations.java index 498cc056be..84e0b8be17 100644 --- a/core/api/src/main/java/org/onosproject/net/flow/FlowRuleOperations.java +++ b/core/api/src/main/java/org/onosproject/net/flow/FlowRuleOperations.java @@ -103,6 +103,17 @@ public class FlowRuleOperations { 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. * diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentInstaller.java b/core/api/src/main/java/org/onosproject/net/intent/IntentInstaller.java index 8a9577f537..b0877a0822 100644 --- a/core/api/src/main/java/org/onosproject/net/intent/IntentInstaller.java +++ b/core/api/src/main/java/org/onosproject/net/intent/IntentInstaller.java @@ -15,9 +15,10 @@ */ package org.onosproject.net.intent; -import org.onosproject.net.flow.FlowRuleBatchOperation; - import java.util.List; +import java.util.Set; + +import org.onosproject.net.flow.FlowRuleOperation; /** * Abstraction of entity capable of installing intents to the environment. @@ -31,7 +32,7 @@ public interface IntentInstaller { * @return flow rule operations to complete install * @throws IntentException if issues are encountered while installing the intent */ - List install(T intent); + List> install(T intent); /** * Uninstalls the specified intent from the environment. @@ -40,7 +41,7 @@ public interface IntentInstaller { * @return flow rule operations to complete uninstall * @throws IntentException if issues are encountered while uninstalling the intent */ - List uninstall(T intent); + List> uninstall(T intent); /** * Replaces the specified intent with a new one in the environment. @@ -50,6 +51,6 @@ public interface IntentInstaller { * @return flow rule operations to complete the replace * @throws IntentException if issues are encountered while uninstalling the intent */ - List replace(T oldIntent, T newIntent); + List> replace(T oldIntent, T newIntent); } diff --git a/core/api/src/test/java/org/onosproject/net/intent/IntentServiceTest.java b/core/api/src/test/java/org/onosproject/net/intent/IntentServiceTest.java index 7ae00aa1c4..e5a1509427 100644 --- a/core/api/src/test/java/org/onosproject/net/intent/IntentServiceTest.java +++ b/core/api/src/test/java/org/onosproject/net/intent/IntentServiceTest.java @@ -35,7 +35,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.onosproject.core.IdGenerator; -import org.onosproject.net.flow.FlowRuleBatchOperation; +import org.onosproject.net.flow.FlowRuleOperation; import org.onosproject.net.resource.LinkResourceAllocations; /** @@ -319,7 +319,7 @@ public class IntentServiceTest { } @Override - public List install(TestInstallableIntent intent) { + public List> install(TestInstallableIntent intent) { if (fail) { throw new IntentException("install failed by design"); } @@ -327,7 +327,7 @@ public class IntentServiceTest { } @Override - public List uninstall(TestInstallableIntent intent) { + public List> uninstall(TestInstallableIntent intent) { if (fail) { throw new IntentException("remove failed by design"); } @@ -335,7 +335,7 @@ public class IntentServiceTest { } @Override - public List replace(TestInstallableIntent intent, + public List> replace(TestInstallableIntent intent, TestInstallableIntent newIntent) { return null; } diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java index 84969f81b6..2f1326faf4 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java @@ -15,8 +15,23 @@ */ package org.onosproject.net.intent.impl; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +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.Component; import org.apache.felix.scr.annotations.Deactivate; @@ -27,9 +42,7 @@ import org.onosproject.core.CoreService; import org.onosproject.core.IdGenerator; import org.onosproject.event.AbstractListenerRegistry; import org.onosproject.event.EventDeliveryService; -import org.onosproject.net.flow.FlowRule; -import org.onosproject.net.flow.FlowRuleBatchEntry; -import org.onosproject.net.flow.FlowRuleBatchOperation; +import org.onosproject.net.flow.FlowRuleOperation; import org.onosproject.net.flow.FlowRuleOperations; import org.onosproject.net.flow.FlowRuleOperationsContext; 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.slf4j.Logger; -import java.util.ArrayList; -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.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 com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import static com.google.common.base.Preconditions.checkNotNull; 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 org.onlab.util.Tools.groupedThreads; 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; /** @@ -301,7 +305,7 @@ public class IntentManager oldInstallables.size() == newInstallables.size(), "Old and New Intent must have equivalent installable intents."); - List> plans = new ArrayList<>(); + List>> plans = new ArrayList<>(); for (int i = 0; i < newInstallables.size(); i++) { Intent newInstallable = newInstallables.get(i); registerSubclassInstallerIfNeeded(newInstallable); @@ -359,7 +363,7 @@ public class IntentManager // TODO: make this non-public due to short term hack for ONOS-1051 public FlowRuleOperations uninstallCoordinate(IntentData current, IntentData pending) { List installables = current.installables(); - List> plans = new ArrayList<>(); + List>> plans = new ArrayList<>(); for (Intent installable : installables) { plans.add(getInstaller(installable).uninstall(installable)); trackerService.removeTrackedResources(pending.key(), installable.resources()); @@ -385,35 +389,22 @@ public class IntentManager // TODO needs tests... or maybe it's just perfect - private FlowRuleOperations.Builder merge(List> plans) { + private FlowRuleOperations.Builder merge(List>> plans) { FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); // Build a batch one stage at a time for (int stageNumber = 0;; stageNumber++) { - // Get the sub-stage from each plan (List) - for (Iterator> itr = plans.iterator(); itr.hasNext();) { - List plan = itr.next(); + // Get the sub-stage from each plan (List) + for (Iterator>> itr = plans.iterator(); itr.hasNext();) { + List> plan = itr.next(); if (plan.size() <= stageNumber) { // we have consumed all stages from this plan, so remove it itr.remove(); continue; } // write operations from this sub-stage into the builder - FlowRuleBatchOperation stage = plan.get(stageNumber); - for (FlowRuleBatchEntry entry : stage.getOperations()) { - FlowRule rule = entry.target(); - switch (entry.operator()) { - case ADD: - builder.add(rule); - break; - case REMOVE: - builder.remove(rule); - break; - case MODIFY: - builder.modify(rule); - break; - default: - break; - } + Set stage = plan.get(stageNumber); + for (FlowRuleOperation entry : stage) { + builder.operation(entry); } } // we are done with the stage, start the next one... diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/LinkCollectionIntentInstaller.java b/core/net/src/main/java/org/onosproject/net/intent/impl/LinkCollectionIntentInstaller.java index cb6c6e4b92..ef6e8b50bf 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/LinkCollectionIntentInstaller.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/LinkCollectionIntentInstaller.java @@ -15,9 +15,10 @@ */ package org.onosproject.net.intent.impl; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Lists; -import com.google.common.collect.SetMultimap; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; 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.DefaultTrafficTreatment; import org.onosproject.net.flow.FlowRule; -import org.onosproject.net.flow.FlowRuleBatchEntry; -import org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation; -import org.onosproject.net.flow.FlowRuleBatchOperation; +import org.onosproject.net.flow.FlowRuleOperation; import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.intent.IntentExtensionService; import org.onosproject.net.intent.IntentInstaller; import org.onosproject.net.intent.LinkCollectionIntent; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.common.collect.SetMultimap; /** * Installer for {@link org.onosproject.net.intent.LinkCollectionIntent} path @@ -76,17 +75,17 @@ public class LinkCollectionIntentInstaller } @Override - public List install(LinkCollectionIntent intent) { - return generateBatchOperations(intent, FlowRuleOperation.ADD); + public List> install(LinkCollectionIntent intent) { + return generateBatchOperations(intent, FlowRuleOperation.Type.ADD); } @Override - public List uninstall(LinkCollectionIntent intent) { - return generateBatchOperations(intent, FlowRuleOperation.REMOVE); + public List> uninstall(LinkCollectionIntent intent) { + return generateBatchOperations(intent, FlowRuleOperation.Type.REMOVE); } - private List generateBatchOperations( - LinkCollectionIntent intent, FlowRuleOperation operation) { + private List> generateBatchOperations( + LinkCollectionIntent intent, FlowRuleOperation.Type operation) { SetMultimap outputPorts = HashMultimap.create(); @@ -99,23 +98,33 @@ public class LinkCollectionIntentInstaller } //FIXME change to new api - FlowRuleBatchOperation batchOperation = - new FlowRuleBatchOperation(outputPorts + /* Fear of streams */ + /* + Set rules = Sets.newHashSet(); + for (DeviceId deviceId : outputPorts.keys()) { + rules.add(createBatchEntry(operation, + intent, deviceId, + outputPorts.get(deviceId))); + } + */ + + Set rules = + outputPorts .keys() .stream() .map(deviceId -> createBatchEntry(operation, - intent, deviceId, - outputPorts.get(deviceId))) - .collect(Collectors.toList()), null, 0); + intent, deviceId, + outputPorts.get(deviceId))) + .collect(Collectors.toSet()); - return Collections.singletonList(batchOperation); + return Lists.newArrayList(ImmutableSet.of(rules)); } @Override - public List replace(LinkCollectionIntent oldIntent, + public List> replace(LinkCollectionIntent oldIntent, LinkCollectionIntent newIntent) { // FIXME: implement this in a more intelligent/less brute force way - List batches = Lists.newArrayList(); + List> batches = Lists.newArrayList(); batches.addAll(uninstall(oldIntent)); batches.addAll(install(newIntent)); return batches; @@ -130,10 +139,10 @@ public class LinkCollectionIntentInstaller * @param outPorts the set of output ports for the flow rule * @return the new flow rule batch entry */ - private FlowRuleBatchEntry createBatchEntry(FlowRuleOperation operation, - LinkCollectionIntent intent, - DeviceId deviceId, - Set outPorts) { + private FlowRuleOperation createBatchEntry(FlowRuleOperation.Type operation, + LinkCollectionIntent intent, + DeviceId deviceId, + Set outPorts) { TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment .builder(intent.treatment()); @@ -151,6 +160,6 @@ public class LinkCollectionIntentInstaller new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)), 0, true); - return new FlowRuleBatchEntry(operation, rule); + return new FlowRuleOperation(rule, operation); } } diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/MplsPathIntentInstaller.java b/core/net/src/main/java/org/onosproject/net/intent/impl/MplsPathIntentInstaller.java index 09c65510f1..9ad1fe5141 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/MplsPathIntentInstaller.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/MplsPathIntentInstaller.java @@ -1,7 +1,5 @@ package org.onosproject.net.intent.impl; -import static org.slf4j.LoggerFactory.getLogger; - import java.util.Iterator; import java.util.List; 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.DefaultTrafficTreatment; import org.onosproject.net.flow.FlowRule; -import org.onosproject.net.flow.FlowRuleBatchEntry; -import org.onosproject.net.flow.FlowRuleBatchOperation; +import org.onosproject.net.flow.FlowRuleOperation; import org.onosproject.net.flow.TrafficSelector; 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.Criterion; 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.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.Sets; +import static com.google.common.base.Preconditions.checkNotNull; +import static org.slf4j.LoggerFactory.getLogger; + /** * Installer for {@link MplsPathIntent packet path connectivity intents}. */ @@ -83,29 +81,26 @@ public class MplsPathIntentInstaller implements IntentInstaller } @Override - public List install(MplsPathIntent intent) { + public List> install(MplsPathIntent intent) { LinkResourceAllocations allocations = assignMplsLabel(intent); - return generateRules(intent, allocations, FlowRuleOperation.ADD); + return generateRules(intent, allocations, FlowRuleOperation.Type.ADD); } @Override - public List uninstall(MplsPathIntent intent) { + public List> uninstall(MplsPathIntent intent) { LinkResourceAllocations allocations = resourceService .getAllocations(intent.id()); resourceService.releaseResources(allocations); - List rules = generateRules(intent, - allocations, - FlowRuleOperation.REMOVE); - return rules; + return generateRules(intent, allocations, FlowRuleOperation.Type.REMOVE); } @Override - public List replace(MplsPathIntent oldIntent, - MplsPathIntent newIntent) { + public List> replace(MplsPathIntent oldIntent, + MplsPathIntent newIntent) { - List batches = Lists.newArrayList(); + List> batches = Lists.newArrayList(); batches.addAll(uninstall(oldIntent)); batches.addAll(install(newIntent)); return batches; @@ -145,9 +140,9 @@ public class MplsPathIntentInstaller implements IntentInstaller return null; } - private List generateRules(MplsPathIntent intent, + private List> generateRules(MplsPathIntent intent, LinkResourceAllocations allocations, - FlowRuleOperation operation) { + FlowRuleOperation.Type operation) { Iterator links = intent.path().links().iterator(); Link srcLink = links.next(); @@ -155,7 +150,7 @@ public class MplsPathIntentInstaller implements IntentInstaller Link link = links.next(); // List of flow rules to be installed - List rules = Lists.newLinkedList(); + Set rules = Sets.newHashSet(); // Ingress traffic // Get the new MPLS label @@ -187,13 +182,13 @@ public class MplsPathIntentInstaller implements IntentInstaller 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, MplsLabel label, - FlowRuleOperation operation) { + FlowRuleOperation.Type operation) { TrafficSelector.Builder ingressSelector = DefaultTrafficSelector .builder(intent.selector()); @@ -213,16 +208,16 @@ public class MplsPathIntentInstaller implements IntentInstaller // Add the output action treat.setOutput(link.src().port()); - return flowRuleBatchEntry(intent, link.src().deviceId(), - ingressSelector.build(), treat.build(), - operation); + return flowRuleOperation(intent, link.src().deviceId(), + ingressSelector.build(), treat.build(), + operation); } - private FlowRuleBatchEntry transitFlow(PortNumber inPort, Link link, + private FlowRuleOperation transitFlow(PortNumber inPort, Link link, MplsPathIntent intent, MplsLabel prevLabel, MplsLabel outLabel, - FlowRuleOperation operation) { + FlowRuleOperation.Type operation) { // Ignore the ingress Traffic Selector and use only the MPLS label // assigned in the previous link @@ -238,14 +233,14 @@ public class MplsPathIntentInstaller implements IntentInstaller } treat.setOutput(link.src().port()); - return flowRuleBatchEntry(intent, link.src().deviceId(), - selector.build(), treat.build(), operation); + return flowRuleOperation(intent, link.src().deviceId(), + selector.build(), treat.build(), operation); } - private FlowRuleBatchEntry egressFlow(PortNumber inPort, Link link, + private FlowRuleOperation egressFlow(PortNumber inPort, Link link, MplsPathIntent intent, MplsLabel prevLabel, - FlowRuleOperation operation) { + FlowRuleOperation.Type operation) { // egress point: either set the egress MPLS label or pop the // MPLS label based on the intent annotations @@ -272,15 +267,15 @@ public class MplsPathIntentInstaller implements IntentInstaller } treat.setOutput(link.src().port()); - return flowRuleBatchEntry(intent, link.src().deviceId(), - selector.build(), treat.build(), operation); + return flowRuleOperation(intent, link.src().deviceId(), + selector.build(), treat.build(), operation); } - protected FlowRuleBatchEntry flowRuleBatchEntry(MplsPathIntent intent, + protected FlowRuleOperation flowRuleOperation(MplsPathIntent intent, DeviceId deviceId, TrafficSelector selector, TrafficTreatment treat, - FlowRuleOperation operation) { + FlowRuleOperation.Type operation) { FlowRule rule = new DefaultFlowRule( deviceId, selector, @@ -289,8 +284,7 @@ public class MplsPathIntentInstaller implements IntentInstaller appId, 0, true); - return new FlowRuleBatchEntry(operation, rule, intent.id() - .fingerprint()); + return new FlowRuleOperation(rule, operation); } } diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/OpticalPathIntentInstaller.java b/core/net/src/main/java/org/onosproject/net/intent/impl/OpticalPathIntentInstaller.java index 5b226a3276..e2dc0d4211 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/OpticalPathIntentInstaller.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/OpticalPathIntentInstaller.java @@ -15,7 +15,9 @@ */ 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.Component; 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.DefaultTrafficTreatment; import org.onosproject.net.flow.FlowRule; -import org.onosproject.net.flow.FlowRuleBatchEntry; -import org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation; -import org.onosproject.net.flow.FlowRuleBatchOperation; +import org.onosproject.net.flow.FlowRuleOperation; import org.onosproject.net.flow.FlowRuleService; import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficTreatment; @@ -49,7 +49,9 @@ import org.onosproject.net.resource.ResourceType; import org.onosproject.net.topology.TopologyService; 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.slf4j.LoggerFactory.getLogger; @@ -92,24 +94,24 @@ public class OpticalPathIntentInstaller implements IntentInstaller install(OpticalPathIntent intent) { + public List> install(OpticalPathIntent intent) { LinkResourceAllocations allocations = assignWavelength(intent); - return generateRules(intent, allocations, FlowRuleOperation.ADD); + return generateRules(intent, allocations, FlowRuleOperation.Type.ADD); } @Override - public List uninstall(OpticalPathIntent intent) { + public List> uninstall(OpticalPathIntent intent) { LinkResourceAllocations allocations = resourceService.getAllocations(intent.id()); - List rules = generateRules(intent, allocations, FlowRuleOperation.REMOVE); + List> rules = generateRules(intent, allocations, FlowRuleOperation.Type.REMOVE); log.info("uninstall rules: {}", rules); return rules; } @Override - public List replace(OpticalPathIntent oldIntent, + public List> replace(OpticalPathIntent oldIntent, OpticalPathIntent newIntent) { // FIXME: implement this - List batches = Lists.newArrayList(); + List> batches = Lists.newArrayList(); batches.addAll(uninstall(oldIntent)); batches.addAll(install(newIntent)); return batches; @@ -123,13 +125,13 @@ public class OpticalPathIntentInstaller implements IntentInstaller generateRules(OpticalPathIntent intent, - LinkResourceAllocations allocations, - FlowRuleOperation operation) { + private List> generateRules(OpticalPathIntent intent, + LinkResourceAllocations allocations, + FlowRuleOperation.Type operation) { TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); selectorBuilder.matchInPort(intent.src().port()); - List rules = Lists.newLinkedList(); + Set rules = Sets.newHashSet(); ConnectPoint prev = intent.src(); //FIXME check for null allocations @@ -160,7 +162,7 @@ public class OpticalPathIntentInstaller implements IntentInstaller { } @Override - public List install(PathIntent intent) { + public List> install(PathIntent intent) { LinkResourceAllocations allocations = allocateResources(intent); TrafficSelector.Builder builder = DefaultTrafficSelector.builder(intent.selector()); Iterator links = intent.path().links().iterator(); ConnectPoint prev = links.next().dst(); - List rules = Lists.newLinkedList(); + Set rules = Sets.newHashSet(); // TODO Generate multiple batches while (links.hasNext()) { builder.matchInPort(prev.port()); @@ -104,23 +105,21 @@ public class PathIntentInstaller implements IntentInstaller { appId, new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)), 0, true); - rules.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, rule, - intent.id().fingerprint())); + rules.add(new FlowRuleOperation(rule, FlowRuleOperation.Type.ADD)); 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 - public List uninstall(PathIntent intent) { + public List> uninstall(PathIntent intent) { deallocateResources(intent); - TrafficSelector.Builder builder = DefaultTrafficSelector.builder(intent.selector()); Iterator links = intent.path().links().iterator(); ConnectPoint prev = links.next().dst(); - List rules = Lists.newLinkedList(); + Set rules = Sets.newHashSet(); // TODO Generate multiple batches while (links.hasNext()) { builder.matchInPort(prev.port()); @@ -133,18 +132,17 @@ public class PathIntentInstaller implements IntentInstaller { builder.build(), treatment, 123, appId, new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)), 0, true); - rules.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, rule, - intent.id().fingerprint())); + rules.add(new FlowRuleOperation(rule, FlowRuleOperation.Type.REMOVE)); 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 - public List replace(PathIntent oldIntent, PathIntent newIntent) { + public List> replace(PathIntent oldIntent, PathIntent newIntent) { // FIXME: implement this - List batches = Lists.newArrayList(); + List> batches = Lists.newArrayList(); batches.addAll(uninstall(oldIntent)); batches.addAll(install(newIntent)); return batches; diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java index c60c874090..f55b575c5b 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java @@ -16,6 +16,7 @@ package org.onosproject.net.intent.impl; import com.google.common.collect.HashMultimap; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Maps; 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.net.NetworkResource; import org.onosproject.net.flow.FlowRule; -import org.onosproject.net.flow.FlowRuleBatchEntry; -import org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation; -import org.onosproject.net.flow.FlowRuleBatchOperation; +import org.onosproject.net.flow.FlowRuleOperation; import org.onosproject.net.intent.Intent; import org.onosproject.net.intent.IntentCompiler; import org.onosproject.net.intent.IntentEvent; @@ -195,45 +194,45 @@ public class IntentManagerTest { private static class TestIntentInstaller implements IntentInstaller { @Override - public List install(MockInstallableIntent intent) { + public List> install(MockInstallableIntent intent) { FlowRule fr = new IntentTestsMocks.MockFlowRule(intent.number().intValue()); - List rules = Lists.newLinkedList(); - rules.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, fr)); - return Lists.newArrayList(new FlowRuleBatchOperation(rules, fr.deviceId(), 0)); + Set rules = ImmutableSet.of( + new FlowRuleOperation(fr, FlowRuleOperation.Type.ADD)); + return Lists.newArrayList(ImmutableSet.of(rules)); } @Override - public List uninstall(MockInstallableIntent intent) { + public List> uninstall(MockInstallableIntent intent) { FlowRule fr = new IntentTestsMocks.MockFlowRule(intent.number().intValue()); - List rules = Lists.newLinkedList(); - rules.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, fr)); - return Lists.newArrayList(new FlowRuleBatchOperation(rules, fr.deviceId(), 0)); + Set rules = ImmutableSet.of( + new FlowRuleOperation(fr, FlowRuleOperation.Type.REMOVE)); + return Lists.newArrayList(ImmutableSet.of(rules)); } @Override - public List replace(MockInstallableIntent oldIntent, MockInstallableIntent newIntent) { + public List> replace(MockInstallableIntent oldIntent, MockInstallableIntent newIntent) { FlowRule fr = new IntentTestsMocks.MockFlowRule(oldIntent.number().intValue()); FlowRule fr2 = new IntentTestsMocks.MockFlowRule(newIntent.number().intValue()); - List rules = Lists.newLinkedList(); - rules.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, fr)); - rules.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, fr2)); - return Lists.newArrayList(new FlowRuleBatchOperation(rules, fr.deviceId(), 0)); + Set rules = ImmutableSet.of( + new FlowRuleOperation(fr, FlowRuleOperation.Type.REMOVE), + new FlowRuleOperation(fr2, FlowRuleOperation.Type.ADD)); + return Lists.newArrayList(ImmutableSet.of(rules)); } } private static class TestIntentErrorInstaller implements IntentInstaller { @Override - public List install(MockInstallableIntent intent) { + public List> install(MockInstallableIntent intent) { throw new IntentInstallationException("install() always fails"); } @Override - public List uninstall(MockInstallableIntent intent) { + public List> uninstall(MockInstallableIntent intent) { throw new IntentRemovalException("uninstall() always fails"); } @Override - public List replace(MockInstallableIntent oldIntent, MockInstallableIntent newIntent) { + public List> replace(MockInstallableIntent oldIntent, MockInstallableIntent newIntent) { throw new IntentInstallationException("replace() always fails"); } } diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/PathConstraintCalculationTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/PathConstraintCalculationTest.java index 9f69e65510..5a5611bb8b 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/PathConstraintCalculationTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/PathConstraintCalculationTest.java @@ -17,9 +17,10 @@ package org.onosproject.net.intent.impl; import java.util.LinkedList; import java.util.List; +import java.util.Set; 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.TrafficTreatment; import org.onosproject.net.intent.AbstractIntentTest; @@ -96,9 +97,9 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { * * @param compiledIntents list of compiled intents * @param resourceService service to use for resource allocation requests - * @return + * @return fow rule entries */ - private List installIntents(List compiledIntents, + private List> installIntents(List compiledIntents, LinkResourceService resourceService) { final PathIntent path = (PathIntent) compiledIntents.get(0); @@ -192,7 +193,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { assertThat(compiledIntents, notNullValue()); assertThat(compiledIntents, hasSize(1)); - final List flowOperations = + final List> flowOperations = installIntents(compiledIntents, resourceService); assertThat(flowOperations, notNullValue()); @@ -241,7 +242,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { assertThat(compiledIntents, notNullValue()); assertThat(compiledIntents, hasSize(1)); - final List flowOperations = + final List> flowOperations = installIntents(compiledIntents, resourceService); assertThat(flowOperations, notNullValue());