diff options
Diffstat (limited to 'framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler')
14 files changed, 0 insertions, 2236 deletions
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/ConnectivityIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/ConnectivityIntentCompiler.java deleted file mode 100644 index 6de4cfdc..00000000 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/ConnectivityIntentCompiler.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.net.intent.impl.compiler; - -import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableList; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.onosproject.net.ElementId; -import org.onosproject.net.Path; -import org.onosproject.net.intent.ConnectivityIntent; -import org.onosproject.net.intent.Constraint; -import org.onosproject.net.intent.IntentCompiler; -import org.onosproject.net.intent.IntentExtensionService; -import org.onosproject.net.intent.impl.PathNotFoundException; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.net.resource.link.LinkResourceService; -import org.onosproject.net.topology.LinkWeight; -import org.onosproject.net.topology.PathService; -import org.onosproject.net.topology.TopologyEdge; - -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -/** - * Base class for compilers of various - * {@link org.onosproject.net.intent.ConnectivityIntent connectivity intents}. - */ -@Component(immediate = true) -public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent> - implements IntentCompiler<T> { - - private static final ProviderId PID = new ProviderId("core", "org.onosproject.core", true); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected IntentExtensionService intentManager; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected PathService pathService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected LinkResourceService resourceService; - - /** - * Returns an edge-weight capable of evaluating links on the basis of the - * specified constraints. - * - * @param constraints path constraints - * @return edge-weight function - */ - protected LinkWeight weight(List<Constraint> constraints) { - return new ConstraintBasedLinkWeight(constraints); - } - - /** - * Validates the specified path against the given constraints. - * - * @param path path to be checked - * @param constraints path constraints - * @return true if the path passes all constraints - */ - protected boolean checkPath(Path path, List<Constraint> constraints) { - for (Constraint constraint : constraints) { - if (!constraint.validate(path, resourceService)) { - return false; - } - } - return true; - } - - /** - * Computes a path between two ConnectPoints. - * - * @param intent intent on which behalf path is being computed - * @param one start of the path - * @param two end of the path - * @return Path between the two - * @throws PathNotFoundException if a path cannot be found - */ - protected Path getPath(ConnectivityIntent intent, - ElementId one, ElementId two) { - Set<Path> paths = pathService.getPaths(one, two, weight(intent.constraints())); - final List<Constraint> constraints = intent.constraints(); - ImmutableList<Path> filtered = FluentIterable.from(paths) - .filter(path -> checkPath(path, constraints)) - .toList(); - if (filtered.isEmpty()) { - throw new PathNotFoundException(one, two); - } - // TODO: let's be more intelligent about this eventually - return filtered.iterator().next(); - } - - /** - * Edge-weight capable of evaluating link cost using a set of constraints. - */ - protected class ConstraintBasedLinkWeight implements LinkWeight { - - private final List<Constraint> constraints; - - /** - * Creates a new edge-weight function capable of evaluating links - * on the basis of the specified constraints. - * - * @param constraints path constraints - */ - ConstraintBasedLinkWeight(List<Constraint> constraints) { - if (constraints == null) { - this.constraints = Collections.emptyList(); - } else { - this.constraints = ImmutableList.copyOf(constraints); - } - } - - @Override - public double weight(TopologyEdge edge) { - if (!constraints.iterator().hasNext()) { - return 1.0; - } - - // iterate over all constraints in order and return the weight of - // the first one with fast fail over the first failure - Iterator<Constraint> it = constraints.iterator(); - - double cost = it.next().cost(edge.link(), resourceService); - while (it.hasNext() && cost > 0) { - if (it.next().cost(edge.link(), resourceService) < 0) { - return -1; - } - } - return cost; - - } - } - -} diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java deleted file mode 100644 index 41168258..00000000 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.net.intent.impl.compiler; - -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.onosproject.net.DefaultLink; -import org.onosproject.net.DefaultPath; -import org.onosproject.net.Host; -import org.onosproject.net.Link; -import org.onosproject.net.Path; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.host.HostService; -import org.onosproject.net.intent.HostToHostIntent; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.PathIntent; -import org.onosproject.net.intent.constraint.AsymmetricPathConstraint; -import org.onosproject.net.resource.link.LinkResourceAllocations; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; - -import static org.onosproject.net.flow.DefaultTrafficSelector.builder; - -/** - * A intent compiler for {@link HostToHostIntent}. - */ -@Component(immediate = true) -public class HostToHostIntentCompiler - extends ConnectivityIntentCompiler<HostToHostIntent> { - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected HostService hostService; - - @Activate - public void activate() { - intentManager.registerCompiler(HostToHostIntent.class, this); - } - - @Deactivate - public void deactivate() { - intentManager.unregisterCompiler(HostToHostIntent.class); - } - - @Override - public List<Intent> compile(HostToHostIntent intent, List<Intent> installable, - Set<LinkResourceAllocations> resources) { - boolean isAsymmetric = intent.constraints().contains(new AsymmetricPathConstraint()); - Path pathOne = getPath(intent, intent.one(), intent.two()); - Path pathTwo = isAsymmetric ? - getPath(intent, intent.two(), intent.one()) : invertPath(pathOne); - - Host one = hostService.getHost(intent.one()); - Host two = hostService.getHost(intent.two()); - - return Arrays.asList(createPathIntent(pathOne, one, two, intent), - createPathIntent(pathTwo, two, one, intent)); - } - - // Inverts the specified path. This makes an assumption that each link in - // the path has a reverse link available. Under most circumstances, this - // assumption will hold. - private Path invertPath(Path path) { - List<Link> reverseLinks = new ArrayList<>(path.links().size()); - for (Link link : path.links()) { - reverseLinks.add(0, reverseLink(link)); - } - return new DefaultPath(path.providerId(), reverseLinks, path.cost()); - } - - // Produces a reverse variant of the specified link. - private Link reverseLink(Link link) { - return new DefaultLink(link.providerId(), link.dst(), link.src(), - link.type(), link.state(), link.isDurable()); - } - - // Creates a path intent from the specified path and original connectivity intent. - private Intent createPathIntent(Path path, Host src, Host dst, - HostToHostIntent intent) { - TrafficSelector selector = builder(intent.selector()) - .matchEthSrc(src.mac()).matchEthDst(dst.mac()).build(); - return PathIntent.builder() - .appId(intent.appId()) - .selector(selector) - .treatment(intent.treatment()) - .path(path) - .constraints(intent.constraints()) - .priority(intent.priority()) - .build(); - } - -} diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java deleted file mode 100644 index 76c5736d..00000000 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.net.intent.impl.compiler; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.SetMultimap; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Link; -import org.onosproject.net.PortNumber; -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.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.intent.FlowRuleIntent; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.IntentCompiler; -import org.onosproject.net.intent.IntentExtensionService; -import org.onosproject.net.intent.LinkCollectionIntent; -import org.onosproject.net.resource.link.LinkResourceAllocations; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -@Component(immediate = true) -public class LinkCollectionIntentCompiler implements IntentCompiler<LinkCollectionIntent> { - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected IntentExtensionService intentManager; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - - private ApplicationId appId; - - @Activate - public void activate() { - appId = coreService.registerApplication("org.onosproject.net.intent"); - intentManager.registerCompiler(LinkCollectionIntent.class, this); - } - - @Deactivate - public void deactivate() { - intentManager.unregisterCompiler(LinkCollectionIntent.class); - } - - @Override - public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable, - Set<LinkResourceAllocations> resources) { - SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create(); - SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create(); - - for (Link link : intent.links()) { - inputPorts.put(link.dst().deviceId(), link.dst().port()); - outputPorts.put(link.src().deviceId(), link.src().port()); - } - - for (ConnectPoint ingressPoint : intent.ingressPoints()) { - inputPorts.put(ingressPoint.deviceId(), ingressPoint.port()); - } - - for (ConnectPoint egressPoint : intent.egressPoints()) { - outputPorts.put(egressPoint.deviceId(), egressPoint.port()); - } - - List<FlowRule> rules = new ArrayList<>(); - for (DeviceId deviceId: outputPorts.keys()) { - rules.addAll(createRules(intent, deviceId, inputPorts.get(deviceId), outputPorts.get(deviceId))); - } - return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources())); - } - - private List<FlowRule> createRules(LinkCollectionIntent intent, DeviceId deviceId, - Set<PortNumber> inPorts, Set<PortNumber> outPorts) { - Set<PortNumber> ingressPorts = intent.ingressPoints().stream() - .filter(point -> point.deviceId().equals(deviceId)) - .map(ConnectPoint::port) - .collect(Collectors.toSet()); - - TrafficTreatment.Builder defaultTreatmentBuilder = DefaultTrafficTreatment.builder(); - outPorts.stream() - .forEach(defaultTreatmentBuilder::setOutput); - TrafficTreatment defaultTreatment = defaultTreatmentBuilder.build(); - - TrafficTreatment.Builder ingressTreatmentBuilder = DefaultTrafficTreatment.builder(intent.treatment()); - outPorts.stream() - .forEach(ingressTreatmentBuilder::setOutput); - TrafficTreatment ingressTreatment = ingressTreatmentBuilder.build(); - - List<FlowRule> rules = new ArrayList<>(inPorts.size()); - for (PortNumber inPort: inPorts) { - TrafficSelector selector = DefaultTrafficSelector.builder(intent.selector()).matchInPort(inPort).build(); - TrafficTreatment treatment; - if (ingressPorts.contains(inPort)) { - treatment = ingressTreatment; - } else { - treatment = defaultTreatment; - } - - FlowRule rule = DefaultFlowRule.builder() - .forDevice(deviceId) - .withSelector(selector) - .withTreatment(treatment) - .withPriority(intent.priority()) - .fromApp(appId) - .makePermanent() - .build(); - rules.add(rule); - } - - return rules; - } -} diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java deleted file mode 100644 index 52621e2f..00000000 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.net.intent.impl.compiler; - -import static java.util.Arrays.asList; -import static org.onosproject.net.DefaultEdgeLink.createEdgeLink; - -import java.util.ArrayList; -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; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DefaultPath; -import org.onosproject.net.Link; -import org.onosproject.net.Path; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.MplsIntent; -import org.onosproject.net.intent.MplsPathIntent; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.net.resource.link.LinkResourceAllocations; - - -@Component(immediate = true) -public class MplsIntentCompiler extends ConnectivityIntentCompiler<MplsIntent> { - - // TODO: use off-the-shell core provider ID - private static final ProviderId PID = - new ProviderId("core", "org.onosproject.core", true); - // TODO: consider whether the default cost is appropriate or not - public static final int DEFAULT_COST = 1; - - - @Activate - public void activate() { - intentManager.registerCompiler(MplsIntent.class, this); - } - - @Deactivate - public void deactivate() { - intentManager.unregisterCompiler(MplsIntent.class); - } - - @Override - public List<Intent> compile(MplsIntent intent, List<Intent> installable, - Set<LinkResourceAllocations> resources) { - ConnectPoint ingressPoint = intent.ingressPoint(); - ConnectPoint egressPoint = intent.egressPoint(); - - if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { - List<Link> links = asList(createEdgeLink(ingressPoint, true), createEdgeLink(egressPoint, false)); - return asList(createPathIntent(new DefaultPath(PID, links, DEFAULT_COST), intent)); - } - - List<Link> links = new ArrayList<>(); - Path path = getPath(intent, ingressPoint.deviceId(), - egressPoint.deviceId()); - - links.add(createEdgeLink(ingressPoint, true)); - links.addAll(path.links()); - - links.add(createEdgeLink(egressPoint, false)); - - return asList(createPathIntent(new DefaultPath(PID, links, path.cost(), - path.annotations()), intent)); - } - - /** - * Creates a path intent from the specified path and original - * connectivity intent. - * - * @param path path to create an intent for - * @param intent original intent - */ - private Intent createPathIntent(Path path, - MplsIntent intent) { - return MplsPathIntent.builder() - .appId(intent.appId()) - .selector(intent.selector()) - .treatment(intent.treatment()) - .path(path) - .ingressLabel(intent.ingressLabel()) - .egressLabel(intent.egressLabel()) - .constraints(intent.constraints()) - .priority(intent.priority()) - .build(); - } - - -} diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java deleted file mode 100644 index 5549918c..00000000 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java +++ /dev/null @@ -1,320 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.net.intent.impl.compiler; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Sets; - -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.onlab.packet.EthType; -import org.onlab.packet.Ethernet; -import org.onlab.packet.MplsLabel; -import org.onlab.packet.VlanId; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Link; -import org.onosproject.net.LinkKey; -import org.onosproject.net.PortNumber; -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.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.flow.criteria.Criterion; -import org.onosproject.net.flow.criteria.EthTypeCriterion; -import org.onosproject.net.flow.instructions.Instruction; -import org.onosproject.net.flow.instructions.L2ModificationInstruction; -import org.onosproject.net.intent.FlowRuleIntent; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.IntentCompiler; -import org.onosproject.net.intent.IntentExtensionService; -import org.onosproject.net.intent.MplsPathIntent; -import org.onosproject.net.newresource.ResourcePath; -import org.onosproject.net.newresource.ResourceService; -import org.onosproject.net.resource.link.LinkResourceAllocations; -import org.slf4j.Logger; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.onosproject.net.LinkKey.linkKey; -import static org.slf4j.LoggerFactory.getLogger; - -@Component(immediate = true) -public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { - - private final Logger log = getLogger(getClass()); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected IntentExtensionService intentExtensionService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected ResourceService resourceService; - - protected ApplicationId appId; - - @Override - public List<Intent> compile(MplsPathIntent intent, List<Intent> installable, - Set<LinkResourceAllocations> resources) { - Map<LinkKey, MplsLabel> labels = assignMplsLabel(intent); - List<FlowRule> rules = generateRules(intent, labels); - - return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources())); - } - - @Activate - public void activate() { - appId = coreService.registerApplication("org.onosproject.net.intent"); - intentExtensionService.registerCompiler(MplsPathIntent.class, this); - } - - @Deactivate - public void deactivate() { - intentExtensionService.unregisterCompiler(MplsPathIntent.class); - } - - private Map<LinkKey, MplsLabel> assignMplsLabel(MplsPathIntent intent) { - // TODO: do it better... Suggestions? - Set<LinkKey> linkRequest = Sets.newHashSetWithExpectedSize(intent.path() - .links().size() - 2); - for (int i = 1; i <= intent.path().links().size() - 2; i++) { - LinkKey link = linkKey(intent.path().links().get(i)); - linkRequest.add(link); - // add the inverse link. I want that the label is reserved both for - // the direct and inverse link - linkRequest.add(linkKey(link.dst(), link.src())); - } - - Map<LinkKey, MplsLabel> labels = findMplsLabels(linkRequest); - if (labels.isEmpty()) { - return Collections.emptyMap(); - } - - // for short term solution: same label is used for both directions - // TODO: introduce the concept of Tx and Rx resources of a port - Set<ResourcePath> resources = labels.entrySet().stream() - .flatMap(x -> Stream.of( - ResourcePath.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue()), - ResourcePath.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue()) - )) - .collect(Collectors.toSet()); - List<org.onosproject.net.newresource.ResourceAllocation> allocations = - resourceService.allocate(intent.id(), ImmutableList.copyOf(resources)); - if (allocations.isEmpty()) { - Collections.emptyMap(); - } - - return labels; - } - - private Map<LinkKey, MplsLabel> findMplsLabels(Set<LinkKey> links) { - Map<LinkKey, MplsLabel> labels = new HashMap<>(); - for (LinkKey link : links) { - Set<MplsLabel> forward = findMplsLabel(link.src()); - Set<MplsLabel> backward = findMplsLabel(link.dst()); - Set<MplsLabel> common = Sets.intersection(forward, backward); - if (common.isEmpty()) { - continue; - } - labels.put(link, common.iterator().next()); - } - - return labels; - } - - private Set<MplsLabel> findMplsLabel(ConnectPoint cp) { - return resourceService.getAvailableResources(ResourcePath.discrete(cp.deviceId(), cp.port())).stream() - .filter(x -> x.last() instanceof MplsLabel) - .map(x -> (MplsLabel) x.last()) - .collect(Collectors.toSet()); - } - - private MplsLabel getMplsLabel(Map<LinkKey, MplsLabel> labels, LinkKey link) { - return labels.get(link); - } - - private List<FlowRule> generateRules(MplsPathIntent intent, - Map<LinkKey, MplsLabel> labels) { - - Iterator<Link> links = intent.path().links().iterator(); - Link srcLink = links.next(); - ConnectPoint prev = srcLink.dst(); - - Link link = links.next(); - // List of flow rules to be installed - List<FlowRule> rules = new LinkedList<>(); - - // Ingress traffic - // Get the new MPLS label - MplsLabel mpls = getMplsLabel(labels, linkKey(link)); - checkNotNull(mpls); - MplsLabel prevLabel = mpls; - rules.add(ingressFlow(prev.port(), link, intent, mpls)); - - prev = link.dst(); - - while (links.hasNext()) { - - link = links.next(); - - if (links.hasNext()) { - // Transit traffic - // Get the new MPLS label - mpls = getMplsLabel(labels, linkKey(link)); - checkNotNull(mpls); - rules.add(transitFlow(prev.port(), link, intent, - prevLabel, mpls)); - prevLabel = mpls; - - } else { - // Egress traffic - rules.add(egressFlow(prev.port(), link, intent, - prevLabel)); - } - - prev = link.dst(); - } - return rules; - } - - private FlowRule ingressFlow(PortNumber inPort, Link link, - MplsPathIntent intent, - MplsLabel label) { - - TrafficSelector.Builder ingressSelector = DefaultTrafficSelector - .builder(intent.selector()); - TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder(); - ingressSelector.matchInPort(inPort); - - if (intent.ingressLabel().isPresent()) { - ingressSelector.matchEthType(Ethernet.MPLS_UNICAST) - .matchMplsLabel(intent.ingressLabel().get()); - - // Swap the MPLS label - treat.setMpls(label); - } else { - // Push and set the MPLS label - treat.pushMpls().setMpls(label); - } - // Add the output action - treat.setOutput(link.src().port()); - - return createFlowRule(intent, link.src().deviceId(), ingressSelector.build(), treat.build()); - } - - private FlowRule transitFlow(PortNumber inPort, Link link, - MplsPathIntent intent, - MplsLabel prevLabel, - MplsLabel outLabel) { - - // Ignore the ingress Traffic Selector and use only the MPLS label - // assigned in the previous link - TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); - selector.matchInPort(inPort).matchEthType(Ethernet.MPLS_UNICAST) - .matchMplsLabel(prevLabel); - TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder(); - - // Set the new label only if the label on the packet is - // different - if (!prevLabel.equals(outLabel)) { - treat.setMpls(outLabel); - } - - treat.setOutput(link.src().port()); - return createFlowRule(intent, link.src().deviceId(), selector.build(), treat.build()); - } - - private FlowRule egressFlow(PortNumber inPort, Link link, - MplsPathIntent intent, - MplsLabel prevLabel) { - // egress point: either set the egress MPLS label or pop the - // MPLS label based on the intent annotations - - TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); - selector.matchInPort(inPort).matchEthType(Ethernet.MPLS_UNICAST) - .matchMplsLabel(prevLabel); - - // apply the intent's treatments - TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder(intent - .treatment()); - - // check if the treatement is popVlan or setVlan (rewrite), - // than selector needs to match any VlanId - for (Instruction instruct : intent.treatment().allInstructions()) { - if (instruct instanceof L2ModificationInstruction) { - L2ModificationInstruction l2Mod = (L2ModificationInstruction) instruct; - if (l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_PUSH) { - break; - } - if (l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_POP || - l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) { - selector.matchVlanId(VlanId.ANY); - } - } - } - - if (intent.egressLabel().isPresent()) { - treat.setMpls(intent.egressLabel().get()); - } else { - treat.popMpls(outputEthType(intent.selector())); - } - treat.setOutput(link.src().port()); - return createFlowRule(intent, link.src().deviceId(), - selector.build(), treat.build()); - } - - protected FlowRule createFlowRule(MplsPathIntent intent, DeviceId deviceId, - TrafficSelector selector, TrafficTreatment treat) { - return DefaultFlowRule.builder() - .forDevice(deviceId) - .withSelector(selector) - .withTreatment(treat) - .withPriority(intent.priority()) - .fromApp(appId) - .makePermanent() - .build(); - } - - // if the ingress ethertype is defined, the egress traffic - // will be use that value, otherwise the IPv4 ethertype is used. - private EthType outputEthType(TrafficSelector selector) { - Criterion c = selector.getCriterion(Criterion.Type.ETH_TYPE); - if (c != null && c instanceof EthTypeCriterion) { - EthTypeCriterion ethertype = (EthTypeCriterion) c; - return ethertype.ethType(); - } else { - return EthType.EtherType.IPV4.ethType(); - } - } -} diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java deleted file mode 100644 index 06d0e9a2..00000000 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.net.intent.impl.compiler; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Link; -import org.onosproject.net.Path; -import org.onosproject.net.device.DeviceService; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.IntentCompiler; -import org.onosproject.net.intent.IntentException; -import org.onosproject.net.intent.IntentExtensionService; -import org.onosproject.net.intent.LinkCollectionIntent; -import org.onosproject.net.intent.MultiPointToSinglePointIntent; -import org.onosproject.net.intent.PointToPointIntent; -import org.onosproject.net.resource.link.LinkResourceAllocations; -import org.onosproject.net.topology.PathService; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static org.onosproject.net.intent.constraint.PartialFailureConstraint.intentAllowsPartialFailure; - - -/** - * An intent compiler for - * {@link org.onosproject.net.intent.MultiPointToSinglePointIntent}. - */ -@Component(immediate = true) -public class MultiPointToSinglePointIntentCompiler - implements IntentCompiler<MultiPointToSinglePointIntent> { - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected IntentExtensionService intentManager; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected PathService pathService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceService deviceService; - - @Activate - public void activate() { - intentManager.registerCompiler(MultiPointToSinglePointIntent.class, this); - } - - @Deactivate - public void deactivate() { - intentManager.unregisterCompiler(PointToPointIntent.class); - } - - @Override - public List<Intent> compile(MultiPointToSinglePointIntent intent, List<Intent> installable, - Set<LinkResourceAllocations> resources) { - Map<DeviceId, Link> links = new HashMap<>(); - ConnectPoint egressPoint = intent.egressPoint(); - - final boolean allowMissingPaths = intentAllowsPartialFailure(intent); - boolean partialTree = false; - boolean anyMissingPaths = false; - for (ConnectPoint ingressPoint : intent.ingressPoints()) { - if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { - if (deviceService.isAvailable(ingressPoint.deviceId())) { - partialTree = true; - } else { - anyMissingPaths = true; - } - - continue; - } - - Path path = getPath(ingressPoint, intent.egressPoint()); - if (path != null) { - partialTree = true; - - for (Link link : path.links()) { - if (links.containsKey(link.dst().deviceId())) { - // We've already reached the existing tree with the first - // part of this path. Add the merging point with different - // incoming port, but don't add the remainder of the path - // in case it differs from the path we already have. - links.put(link.src().deviceId(), link); - break; - } - links.put(link.src().deviceId(), link); - } - } else { - anyMissingPaths = true; - } - } - - if (!partialTree) { - throw new IntentException("Could not find any paths between ingress and egress points."); - } else if (!allowMissingPaths && anyMissingPaths) { - throw new IntentException("Missing some paths between ingress and egress ports."); - } - - Intent result = LinkCollectionIntent.builder() - .appId(intent.appId()) - .selector(intent.selector()) - .treatment(intent.treatment()) - .links(Sets.newHashSet(links.values())) - .ingressPoints(intent.ingressPoints()) - .egressPoints(ImmutableSet.of(intent.egressPoint())) - .priority(intent.priority()) - .constraints(intent.constraints()) - .build(); - - return Collections.singletonList(result); - } - - /** - * Computes a path between two ConnectPoints. - * - * @param one start of the path - * @param two end of the path - * @return Path between the two - */ - private Path getPath(ConnectPoint one, ConnectPoint two) { - Set<Path> paths = pathService.getPaths(one.deviceId(), two.deviceId()); - if (paths.isEmpty()) { - return null; - } - // TODO: let's be more intelligent about this eventually - return paths.iterator().next(); - } -} diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java deleted file mode 100644 index ee04aab5..00000000 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java +++ /dev/null @@ -1,390 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.net.intent.impl.compiler; - -import org.apache.commons.lang3.tuple.Pair; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Modified; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.onlab.util.Tools; -import org.onosproject.cfg.ComponentConfigService; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.net.AnnotationKeys; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.OchPort; -import org.onosproject.net.OduCltPort; -import org.onosproject.net.OduSignalType; -import org.onosproject.net.Port; -import org.onosproject.net.device.DeviceService; -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.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.intent.FlowRuleIntent; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.IntentCompiler; -import org.onosproject.net.intent.IntentExtensionService; -import org.onosproject.net.intent.IntentId; -import org.onosproject.net.intent.IntentService; -import org.onosproject.net.intent.OpticalCircuitIntent; -import org.onosproject.net.intent.OpticalConnectivityIntent; -import org.onosproject.net.intent.impl.IntentCompilationException; -import org.onosproject.net.newresource.ResourceAllocation; -import org.onosproject.net.newresource.ResourcePath; -import org.onosproject.net.newresource.ResourceService; -import org.onosproject.net.resource.device.IntentSetMultimap; -import org.onosproject.net.resource.link.LinkResourceAllocations; -import org.osgi.service.component.ComponentContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collections; -import java.util.Dictionary; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.Set; - -import static com.google.common.base.Preconditions.checkArgument; - -/** - * An intent compiler for {@link org.onosproject.net.intent.OpticalCircuitIntent}. - */ -// For now, remove component designation until dependency on the new resource manager is available. -@Component(immediate = true) -public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircuitIntent> { - - private static final Logger log = LoggerFactory.getLogger(OpticalCircuitIntentCompiler.class); - - private static final int DEFAULT_MAX_CAPACITY = 10; - - @Property(name = "maxCapacity", intValue = DEFAULT_MAX_CAPACITY, - label = "Maximum utilization of an optical connection.") - - private int maxCapacity = DEFAULT_MAX_CAPACITY; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected ComponentConfigService cfgService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected IntentExtensionService intentManager; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceService deviceService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected ResourceService resourceService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected IntentSetMultimap intentSetMultimap; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected IntentService intentService; - - private ApplicationId appId; - - @Modified - public void modified(ComponentContext context) { - Dictionary properties = context.getProperties(); - - //TODO for reduction check if the new capacity is smaller than the size of the current mapping - String propertyString = Tools.get(properties, "maxCapacity"); - - //Ignore if propertyString is empty - if (!propertyString.isEmpty()) { - try { - int temp = Integer.parseInt(propertyString); - //Ensure value is non-negative but allow zero as a way to shutdown the link - if (temp >= 0) { - maxCapacity = temp; - } - } catch (NumberFormatException e) { - //Malformed arguments lead to no change of value (user should be notified of error) - log.error("The value '{}' for maxCapacity was not parsable as an integer.", propertyString, e); - } - } else { - //Notify of empty value but do not return (other properties will also go in this function) - log.error("The value for maxCapacity was set to an empty value."); - } - - } - - @Activate - public void activate(ComponentContext context) { - appId = coreService.registerApplication("org.onosproject.net.intent"); - intentManager.registerCompiler(OpticalCircuitIntent.class, this); - cfgService.registerProperties(getClass()); - modified(context); - } - - @Deactivate - public void deactivate() { - intentManager.unregisterCompiler(OpticalCircuitIntent.class); - cfgService.unregisterProperties(getClass(), false); - } - - @Override - public List<Intent> compile(OpticalCircuitIntent intent, List<Intent> installable, - Set<LinkResourceAllocations> resources) { - // Check if ports are OduClt ports - ConnectPoint src = intent.getSrc(); - ConnectPoint dst = intent.getDst(); - Port srcPort = deviceService.getPort(src.deviceId(), src.port()); - Port dstPort = deviceService.getPort(dst.deviceId(), dst.port()); - checkArgument(srcPort instanceof OduCltPort); - checkArgument(dstPort instanceof OduCltPort); - - log.debug("Compiling optical circuit intent between {} and {}", src, dst); - - // Reserve OduClt ports - ResourcePath srcPortPath = ResourcePath.discrete(src.deviceId(), src.port()); - ResourcePath dstPortPath = ResourcePath.discrete(dst.deviceId(), dst.port()); - List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortPath, dstPortPath); - if (allocation.isEmpty()) { - throw new IntentCompilationException("Unable to reserve ports for intent " + intent); - } - - LinkedList<Intent> intents = new LinkedList<>(); - - FlowRuleIntent circuitIntent; - OpticalConnectivityIntent connIntent = findOpticalConnectivityIntent(intent); - - // Create optical connectivity intent if needed - if (connIntent == null) { - // Find OCh ports with available resources - Pair<OchPort, OchPort> ochPorts = findPorts(intent); - - if (ochPorts == null) { - return Collections.emptyList(); - } - - // Create optical connectivity intent - ConnectPoint srcCP = new ConnectPoint(src.elementId(), ochPorts.getLeft().number()); - ConnectPoint dstCP = new ConnectPoint(dst.elementId(), ochPorts.getRight().number()); - // FIXME: hardcoded ODU signal type - connIntent = OpticalConnectivityIntent.builder() - .appId(appId) - .src(srcCP) - .dst(dstCP) - .signalType(OduSignalType.ODU4) - .bidirectional(intent.isBidirectional()) - .build(); - intentService.submit(connIntent); - } - - // Create optical circuit intent - List<FlowRule> rules = new LinkedList<>(); - rules.add(connectPorts(src, connIntent.getSrc(), intent.priority())); - rules.add(connectPorts(connIntent.getDst(), dst, intent.priority())); - - // Create flow rules for reverse path - if (intent.isBidirectional()) { - rules.add(connectPorts(connIntent.getSrc(), src, intent.priority())); - rules.add(connectPorts(dst, connIntent.getDst(), intent.priority())); - } - - circuitIntent = new FlowRuleIntent(appId, rules, intent.resources()); - - // Save circuit to connectivity intent mapping - intentSetMultimap.allocateMapping(connIntent.id(), intent.id()); - intents.add(circuitIntent); - - return intents; - } - - /** - * Checks if current allocations on given resource can satisfy request. - * If the resource is null, return true. - * - * @param resource the resource on which to map the intent - * @return true if the resource can accept the request, false otherwise - */ - private boolean isAvailable(IntentId resource) { - if (resource == null) { - return true; - } - - Set<IntentId> mapping = intentSetMultimap.getMapping(resource); - - if (mapping == null) { - return true; - } - - return mapping.size() < maxCapacity; - } - - private boolean isAllowed(OpticalCircuitIntent circuitIntent, OpticalConnectivityIntent connIntent) { - ConnectPoint srcStaticPort = staticPort(circuitIntent.getSrc()); - if (srcStaticPort != null) { - if (!srcStaticPort.equals(connIntent.getSrc())) { - return false; - } - } - - ConnectPoint dstStaticPort = staticPort(circuitIntent.getDst()); - if (dstStaticPort != null) { - if (!dstStaticPort.equals(connIntent.getDst())) { - return false; - } - } - - return true; - } - - /** - * Returns existing and available optical connectivity intent that matches the given circuit intent. - * - * @param circuitIntent optical circuit intent - * @return existing optical connectivity intent, null otherwise. - */ - private OpticalConnectivityIntent findOpticalConnectivityIntent(OpticalCircuitIntent circuitIntent) { - for (Intent intent : intentService.getIntents()) { - if (!(intent instanceof OpticalConnectivityIntent)) { - continue; - } - - OpticalConnectivityIntent connIntent = (OpticalConnectivityIntent) intent; - - ConnectPoint src = circuitIntent.getSrc(); - ConnectPoint dst = circuitIntent.getDst(); - // Ignore if the intents don't have identical src and dst devices - if (!src.deviceId().equals(connIntent.getSrc().deviceId()) && - !dst.deviceId().equals(connIntent.getDst().deviceId())) { - continue; - } - - if (!isAllowed(circuitIntent, connIntent)) { - continue; - } - - if (isAvailable(connIntent.id())) { - return connIntent; - } - } - - return null; - } - - private ConnectPoint staticPort(ConnectPoint connectPoint) { - Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port()); - - String staticPort = port.annotations().value(AnnotationKeys.STATIC_PORT); - - // FIXME: need a better way to match the port - if (staticPort != null) { - for (Port p : deviceService.getPorts(connectPoint.deviceId())) { - if (staticPort.equals(p.number().name())) { - return new ConnectPoint(p.element().id(), p.number()); - } - } - } - - return null; - } - - private OchPort findAvailableOchPort(ConnectPoint oduPort) { - // First see if the port mappings are constrained - ConnectPoint ochCP = staticPort(oduPort); - - if (ochCP != null) { - OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port()); - Optional<IntentId> intentId = - resourceService.getResourceAllocation(ResourcePath.discrete(ochCP.deviceId(), ochCP.port())) - .map(ResourceAllocation::consumer) - .filter(x -> x instanceof IntentId) - .map(x -> (IntentId) x); - - if (isAvailable(intentId.orElse(null))) { - return ochPort; - } - } - - // No port constraints, so find any port that works - List<Port> ports = deviceService.getPorts(oduPort.deviceId()); - - for (Port port : ports) { - if (!(port instanceof OchPort)) { - continue; - } - - Optional<IntentId> intentId = - resourceService.getResourceAllocation(ResourcePath.discrete(oduPort.deviceId(), port.number())) - .map(ResourceAllocation::consumer) - .filter(x -> x instanceof IntentId) - .map(x -> (IntentId) x); - if (isAvailable(intentId.orElse(null))) { - return (OchPort) port; - } - } - - return null; - } - - private Pair<OchPort, OchPort> findPorts(OpticalCircuitIntent intent) { - - OchPort srcPort = findAvailableOchPort(intent.getSrc()); - if (srcPort == null) { - return null; - } - - OchPort dstPort = findAvailableOchPort(intent.getDst()); - if (dstPort == null) { - return null; - } - - return Pair.of(srcPort, dstPort); - } - - /** - * Builds flow rule for mapping between two ports. - * - * @param src source port - * @param dst destination port - * @return flow rules - */ - private FlowRule connectPorts(ConnectPoint src, ConnectPoint dst, int priority) { - checkArgument(src.deviceId().equals(dst.deviceId())); - - TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); - TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); - - selectorBuilder.matchInPort(src.port()); - //selectorBuilder.add(Criteria.matchCltSignalType) - treatmentBuilder.setOutput(dst.port()); - //treatmentBuilder.add(Instructions.modL1OduSignalType) - - FlowRule flowRule = DefaultFlowRule.builder() - .forDevice(src.deviceId()) - .withSelector(selectorBuilder.build()) - .withTreatment(treatmentBuilder.build()) - .withPriority(priority) - .fromApp(appId) - .makePermanent() - .build(); - - return flowRule; - } -} diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java deleted file mode 100644 index e017ac58..00000000 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java +++ /dev/null @@ -1,281 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.net.intent.impl.compiler; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.onlab.util.Frequency; -import org.onosproject.net.AnnotationKeys; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DeviceId; -import org.onosproject.net.IndexedLambda; -import org.onosproject.net.Link; -import org.onosproject.net.OchPort; -import org.onosproject.net.OchSignal; -import org.onosproject.net.OchSignalType; -import org.onosproject.net.OmsPort; -import org.onosproject.net.Path; -import org.onosproject.net.Port; -import org.onosproject.net.device.DeviceService; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.IntentCompiler; -import org.onosproject.net.intent.IntentExtensionService; -import org.onosproject.net.intent.OpticalConnectivityIntent; -import org.onosproject.net.intent.OpticalPathIntent; -import org.onosproject.net.intent.impl.IntentCompilationException; -import org.onosproject.net.newresource.ResourceAllocation; -import org.onosproject.net.newresource.ResourcePath; -import org.onosproject.net.newresource.ResourceService; -import org.onosproject.net.resource.link.LinkResourceAllocations; -import org.onosproject.net.topology.LinkWeight; -import org.onosproject.net.topology.Topology; -import org.onosproject.net.topology.TopologyService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static com.google.common.base.Preconditions.checkArgument; - -/** - * An intent compiler for {@link org.onosproject.net.intent.OpticalConnectivityIntent}. - */ -// For now, remove component designation until dependency on the new resource manager is available. -@Component(immediate = true) -public class OpticalConnectivityIntentCompiler implements IntentCompiler<OpticalConnectivityIntent> { - - protected static final Logger log = LoggerFactory.getLogger(OpticalConnectivityIntentCompiler.class); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected IntentExtensionService intentManager; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected TopologyService topologyService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceService deviceService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected ResourceService resourceService; - - @Activate - public void activate() { - intentManager.registerCompiler(OpticalConnectivityIntent.class, this); - } - - @Deactivate - public void deactivate() { - intentManager.unregisterCompiler(OpticalConnectivityIntent.class); - } - - @Override - public List<Intent> compile(OpticalConnectivityIntent intent, - List<Intent> installable, - Set<LinkResourceAllocations> resources) { - // Check if source and destination are optical OCh ports - ConnectPoint src = intent.getSrc(); - ConnectPoint dst = intent.getDst(); - Port srcPort = deviceService.getPort(src.deviceId(), src.port()); - Port dstPort = deviceService.getPort(dst.deviceId(), dst.port()); - checkArgument(srcPort instanceof OchPort); - checkArgument(dstPort instanceof OchPort); - - log.debug("Compiling optical connectivity intent between {} and {}", src, dst); - - // Reserve OCh ports - ResourcePath srcPortPath = ResourcePath.discrete(src.deviceId(), src.port()); - ResourcePath dstPortPath = ResourcePath.discrete(dst.deviceId(), dst.port()); - List<org.onosproject.net.newresource.ResourceAllocation> allocation = - resourceService.allocate(intent.id(), srcPortPath, dstPortPath); - if (allocation.isEmpty()) { - throw new IntentCompilationException("Unable to reserve ports for intent " + intent); - } - - // Calculate available light paths - Set<Path> paths = getOpticalPaths(intent); - - // Use first path that can be successfully reserved - for (Path path : paths) { - - // Static or dynamic lambda allocation - String staticLambda = srcPort.annotations().value(AnnotationKeys.STATIC_LAMBDA); - OchPort srcOchPort = (OchPort) srcPort; - OchPort dstOchPort = (OchPort) dstPort; - OchSignal ochSignal; - - // FIXME: need to actually reserve the lambda for static lambda's - if (staticLambda != null) { - ochSignal = new OchSignal(Frequency.ofHz(Long.parseLong(staticLambda)), - srcOchPort.lambda().channelSpacing(), - srcOchPort.lambda().slotGranularity()); - } else if (!srcOchPort.isTunable() || !dstOchPort.isTunable()) { - // FIXME: also check OCh port - ochSignal = srcOchPort.lambda(); - } else { - // Request and reserve lambda on path - IndexedLambda lambda = assignWavelength(intent, path); - if (lambda == null) { - continue; - } - OmsPort omsPort = (OmsPort) deviceService.getPort(path.src().deviceId(), path.src().port()); - ochSignal = new OchSignal((int) lambda.index(), omsPort.maxFrequency(), omsPort.grid()); - } - - // Create installable optical path intent - // Only support fixed grid for now - OchSignalType signalType = OchSignalType.FIXED_GRID; - - Intent newIntent = OpticalPathIntent.builder() - .appId(intent.appId()) - .src(intent.getSrc()) - .dst(intent.getDst()) - .path(path) - .lambda(ochSignal) - .signalType(signalType) - .bidirectional(intent.isBidirectional()) - .build(); - - return ImmutableList.of(newIntent); - } - - // Release port allocations if unsuccessful - resourceService.release(intent.id()); - - throw new IntentCompilationException("Unable to find suitable lightpath for intent " + intent); - } - - /** - * Request and reserve first available wavelength across path. - * - * @param path path in WDM topology - * @return first available lambda allocated - */ - private IndexedLambda assignWavelength(Intent intent, Path path) { - Set<IndexedLambda> lambdas = findCommonLambdasOverLinks(path.links()); - if (lambdas.isEmpty()) { - return null; - } - - IndexedLambda minLambda = findFirstLambda(lambdas); - List<ResourcePath> lambdaResources = path.links().stream() - .flatMap(x -> Stream.of( - ResourcePath.discrete(x.src().deviceId(), x.src().port()), - ResourcePath.discrete(x.dst().deviceId(), x.dst().port()) - )) - .map(x -> x.child(minLambda)) - .collect(Collectors.toList()); - - List<ResourceAllocation> allocations = resourceService.allocate(intent.id(), lambdaResources); - if (allocations.isEmpty()) { - log.info("Resource allocation for {} failed (resource request: {})", intent, lambdaResources); - return null; - } - - return minLambda; - } - - private Set<IndexedLambda> findCommonLambdasOverLinks(List<Link> links) { - return links.stream() - .flatMap(x -> Stream.of( - ResourcePath.discrete(x.src().deviceId(), x.src().port()), - ResourcePath.discrete(x.dst().deviceId(), x.dst().port()) - )) - .map(resourceService::getAvailableResources) - .map(x -> Iterables.filter(x, r -> r.last() instanceof IndexedLambda)) - .map(x -> Iterables.transform(x, r -> (IndexedLambda) r.last())) - .map(x -> (Set<IndexedLambda>) ImmutableSet.copyOf(x)) - .reduce(Sets::intersection) - .orElse(Collections.emptySet()); - } - - private IndexedLambda findFirstLambda(Set<IndexedLambda> lambdas) { - return lambdas.stream() - .findFirst() - .get(); - } - - private ConnectPoint staticPort(ConnectPoint connectPoint) { - Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port()); - - String staticPort = port.annotations().value(AnnotationKeys.STATIC_PORT); - - // FIXME: need a better way to match the port - if (staticPort != null) { - for (Port p : deviceService.getPorts(connectPoint.deviceId())) { - if (staticPort.equals(p.number().name())) { - return new ConnectPoint(p.element().id(), p.number()); - } - } - } - - return null; - } - - /** - * Calculates optical paths in WDM topology. - * - * @param intent optical connectivity intent - * @return set of paths in WDM topology - */ - private Set<Path> getOpticalPaths(OpticalConnectivityIntent intent) { - // Route in WDM topology - Topology topology = topologyService.currentTopology(); - LinkWeight weight = edge -> { - // Disregard inactive or non-optical links - if (edge.link().state() == Link.State.INACTIVE) { - return -1; - } - if (edge.link().type() != Link.Type.OPTICAL) { - return -1; - } - // Adhere to static port mappings - DeviceId srcDeviceId = edge.link().src().deviceId(); - if (srcDeviceId.equals(intent.getSrc().deviceId())) { - ConnectPoint srcStaticPort = staticPort(intent.getSrc()); - if (srcStaticPort != null) { - return srcStaticPort.equals(edge.link().src()) ? 1 : -1; - } - } - DeviceId dstDeviceId = edge.link().dst().deviceId(); - if (dstDeviceId.equals(intent.getDst().deviceId())) { - ConnectPoint dstStaticPort = staticPort(intent.getDst()); - if (dstStaticPort != null) { - return dstStaticPort.equals(edge.link().dst()) ? 1 : -1; - } - } - - return 1; - }; - - ConnectPoint start = intent.getSrc(); - ConnectPoint end = intent.getDst(); - Set<Path> paths = topologyService.getPaths(topology, start.deviceId(), - end.deviceId(), weight); - - return paths; - } -} diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompiler.java deleted file mode 100644 index 2cc45e79..00000000 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompiler.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.net.intent.impl.compiler; - -import com.google.common.collect.Lists; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.Link; -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.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.flow.criteria.Criteria; -import org.onosproject.net.flow.instructions.Instructions; -import org.onosproject.net.intent.FlowRuleIntent; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.IntentCompiler; -import org.onosproject.net.intent.IntentExtensionService; -import org.onosproject.net.intent.OpticalPathIntent; -import org.onosproject.net.resource.link.LinkResourceAllocations; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -@Component(immediate = true) -public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathIntent> { - - private static final Logger log = LoggerFactory.getLogger(OpticalPathIntentCompiler.class); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected IntentExtensionService intentManager; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - - private ApplicationId appId; - - @Activate - public void activate() { - appId = coreService.registerApplication("org.onosproject.net.intent"); - intentManager.registerCompiler(OpticalPathIntent.class, this); - } - - @Deactivate - public void deactivate() { - intentManager.unregisterCompiler(OpticalPathIntent.class); - } - - @Override - public List<Intent> compile(OpticalPathIntent intent, List<Intent> installable, - Set<LinkResourceAllocations> resources) { - log.debug("Compiling optical path intent between {} and {}", intent.src(), intent.dst()); - - // Create rules for forward and reverse path - List<FlowRule> rules = createRules(intent); - if (intent.isBidirectional()) { - rules.addAll(createReverseRules(intent)); - } - - return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources())); - } - - /** - * Create rules for the forward path of the intent. - * - * @param intent the intent - * @return list of flow rules - */ - private List<FlowRule> createRules(OpticalPathIntent intent) { - TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); - selectorBuilder.matchInPort(intent.src().port()); - - List<FlowRule> rules = new LinkedList<>(); - ConnectPoint current = intent.src(); - - for (Link link : intent.path().links()) { - TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); - treatmentBuilder.add(Instructions.modL0Lambda(intent.lambda())); - treatmentBuilder.setOutput(link.src().port()); - - FlowRule rule = DefaultFlowRule.builder() - .forDevice(current.deviceId()) - .withSelector(selectorBuilder.build()) - .withTreatment(treatmentBuilder.build()) - .withPriority(intent.priority()) - .fromApp(appId) - .makePermanent() - .build(); - - rules.add(rule); - - current = link.dst(); - selectorBuilder.matchInPort(link.dst().port()); - selectorBuilder.add(Criteria.matchLambda(intent.lambda())); - selectorBuilder.add(Criteria.matchOchSignalType(intent.signalType())); - } - - // Build the egress ROADM rule - TrafficTreatment.Builder treatmentLast = DefaultTrafficTreatment.builder(); - treatmentLast.setOutput(intent.dst().port()); - - FlowRule rule = new DefaultFlowRule.Builder() - .forDevice(intent.dst().deviceId()) - .withSelector(selectorBuilder.build()) - .withTreatment(treatmentLast.build()) - .withPriority(intent.priority()) - .fromApp(appId) - .makePermanent() - .build(); - rules.add(rule); - - return rules; - } - - /** - * Create rules for the reverse path of the intent. - * - * @param intent the intent - * @return list of flow rules - */ - private List<FlowRule> createReverseRules(OpticalPathIntent intent) { - TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); - selectorBuilder.matchInPort(intent.dst().port()); - - List<FlowRule> rules = new LinkedList<>(); - ConnectPoint current = intent.dst(); - - for (Link link : Lists.reverse(intent.path().links())) { - TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); - treatmentBuilder.add(Instructions.modL0Lambda(intent.lambda())); - treatmentBuilder.setOutput(link.dst().port()); - - FlowRule rule = DefaultFlowRule.builder() - .forDevice(current.deviceId()) - .withSelector(selectorBuilder.build()) - .withTreatment(treatmentBuilder.build()) - .withPriority(intent.priority()) - .fromApp(appId) - .makePermanent() - .build(); - - rules.add(rule); - - current = link.src(); - selectorBuilder.matchInPort(link.src().port()); - selectorBuilder.add(Criteria.matchLambda(intent.lambda())); - selectorBuilder.add(Criteria.matchOchSignalType(intent.signalType())); - } - - // Build the egress ROADM rule - TrafficTreatment.Builder treatmentLast = DefaultTrafficTreatment.builder(); - treatmentLast.setOutput(intent.src().port()); - - FlowRule rule = new DefaultFlowRule.Builder() - .forDevice(intent.src().deviceId()) - .withSelector(selectorBuilder.build()) - .withTreatment(treatmentLast.build()) - .withPriority(intent.priority()) - .fromApp(appId) - .makePermanent() - .build(); - rules.add(rule); - - return rules; - } -} diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java deleted file mode 100644 index 7add2173..00000000 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.net.intent.impl.compiler; - -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.Link; -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.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.intent.FlowRuleIntent; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.IntentCompiler; -import org.onosproject.net.intent.IntentExtensionService; -import org.onosproject.net.intent.PathIntent; -import org.onosproject.net.resource.link.LinkResourceAllocations; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -@Component(immediate = true) -public class PathIntentCompiler implements IntentCompiler<PathIntent> { - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected IntentExtensionService intentManager; - - private ApplicationId appId; - - @Activate - public void activate() { - appId = coreService.registerApplication("org.onosproject.net.intent"); - intentManager.registerCompiler(PathIntent.class, this); - } - - @Deactivate - public void deactivate() { - intentManager.unregisterCompiler(PathIntent.class); - } - - @Override - public List<Intent> compile(PathIntent intent, List<Intent> installable, - Set<LinkResourceAllocations> resources) { - // Note: right now recompile is not considered - // TODO: implement recompile behavior - - List<Link> links = intent.path().links(); - List<FlowRule> rules = new ArrayList<>(links.size() - 1); - - for (int i = 0; i < links.size() - 1; i++) { - ConnectPoint ingress = links.get(i).dst(); - ConnectPoint egress = links.get(i + 1).src(); - FlowRule rule = createFlowRule(intent.selector(), intent.treatment(), - ingress, egress, intent.priority(), - isLast(links, i)); - rules.add(rule); - } - - return Collections.singletonList(new FlowRuleIntent(appId, null, rules, intent.resources())); - } - - private FlowRule createFlowRule(TrafficSelector originalSelector, TrafficTreatment originalTreatment, - ConnectPoint ingress, ConnectPoint egress, - int priority, boolean last) { - TrafficSelector selector = DefaultTrafficSelector.builder(originalSelector) - .matchInPort(ingress.port()) - .build(); - - TrafficTreatment.Builder treatmentBuilder; - if (last) { - treatmentBuilder = DefaultTrafficTreatment.builder(originalTreatment); - } else { - treatmentBuilder = DefaultTrafficTreatment.builder(); - } - TrafficTreatment treatment = treatmentBuilder.setOutput(egress.port()).build(); - - return DefaultFlowRule.builder() - .forDevice(ingress.deviceId()) - .withSelector(selector) - .withTreatment(treatment) - .withPriority(priority) - .fromApp(appId) - .makePermanent() - .build(); - } - - private boolean isLast(List<Link> links, int i) { - return i == links.size() - 2; - } -} diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java deleted file mode 100644 index 5644ee22..00000000 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.net.intent.impl.compiler; - -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DefaultPath; -import org.onosproject.net.Link; -import org.onosproject.net.Path; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.PathIntent; -import org.onosproject.net.intent.PointToPointIntent; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.net.resource.link.LinkResourceAllocations; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import static java.util.Arrays.asList; -import static org.onosproject.net.DefaultEdgeLink.createEdgeLink; - -/** - * An intent compiler for {@link org.onosproject.net.intent.PointToPointIntent}. - */ -@Component(immediate = true) -public class PointToPointIntentCompiler - extends ConnectivityIntentCompiler<PointToPointIntent> { - - // TODO: use off-the-shell core provider ID - private static final ProviderId PID = - new ProviderId("core", "org.onosproject.core", true); - // TODO: consider whether the default cost is appropriate or not - public static final int DEFAULT_COST = 1; - - @Activate - public void activate() { - intentManager.registerCompiler(PointToPointIntent.class, this); - } - - @Deactivate - public void deactivate() { - intentManager.unregisterCompiler(PointToPointIntent.class); - } - - @Override - public List<Intent> compile(PointToPointIntent intent, List<Intent> installable, - Set<LinkResourceAllocations> resources) { - - ConnectPoint ingressPoint = intent.ingressPoint(); - ConnectPoint egressPoint = intent.egressPoint(); - - if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { - List<Link> links = asList(createEdgeLink(ingressPoint, true), createEdgeLink(egressPoint, false)); - return asList(createPathIntent(new DefaultPath(PID, links, DEFAULT_COST), intent)); - } - - List<Link> links = new ArrayList<>(); - Path path = getPath(intent, ingressPoint.deviceId(), - egressPoint.deviceId()); - - links.add(createEdgeLink(ingressPoint, true)); - links.addAll(path.links()); - links.add(createEdgeLink(egressPoint, false)); - - return asList(createPathIntent(new DefaultPath(PID, links, path.cost(), - path.annotations()), intent)); - } - - /** - * Creates a path intent from the specified path and original - * connectivity intent. - * - * @param path path to create an intent for - * @param intent original intent - */ - private Intent createPathIntent(Path path, - PointToPointIntent intent) { - return PathIntent.builder() - .appId(intent.appId()) - .selector(intent.selector()) - .treatment(intent.treatment()) - .path(path) - .constraints(intent.constraints()) - .priority(intent.priority()) - .build(); - } - -} diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java deleted file mode 100644 index 56565908..00000000 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.net.intent.impl.compiler; - -import com.google.common.collect.ImmutableSet; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.Link; -import org.onosproject.net.Path; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.LinkCollectionIntent; -import org.onosproject.net.intent.SinglePointToMultiPointIntent; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.net.resource.link.LinkResourceAllocations; - -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -@Component(immediate = true) -public class SinglePointToMultiPointIntentCompiler - extends ConnectivityIntentCompiler<SinglePointToMultiPointIntent> { - - // TODO: use off-the-shell core provider ID - private static final ProviderId PID = - new ProviderId("core", "org.onosproject.core", true); - - @Activate - public void activate() { - intentManager.registerCompiler(SinglePointToMultiPointIntent.class, - this); - } - - @Deactivate - public void deactivate() { - intentManager.unregisterCompiler(SinglePointToMultiPointIntent.class); - } - - - @Override - public List<Intent> compile(SinglePointToMultiPointIntent intent, - List<Intent> installable, - Set<LinkResourceAllocations> resources) { - Set<Link> links = new HashSet<>(); - - for (ConnectPoint egressPoint : intent.egressPoints()) { - if (egressPoint.deviceId().equals(intent.ingressPoint().deviceId())) { - continue; - } - - Path path = getPath(intent, intent.ingressPoint().deviceId(), egressPoint.deviceId()); - links.addAll(path.links()); - } - - Intent result = LinkCollectionIntent.builder() - .appId(intent.appId()) - .key(intent.key()) - .selector(intent.selector()) - .treatment(intent.treatment()) - .links(links) - .ingressPoints(ImmutableSet.of(intent.ingressPoint())) - .egressPoints(intent.egressPoints()) - .priority(intent.priority()) - .constraints(intent.constraints()) - .build(); - - return Collections.singletonList(result); - } -} diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/TwoWayP2PIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/TwoWayP2PIntentCompiler.java deleted file mode 100644 index 50a67546..00000000 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/TwoWayP2PIntentCompiler.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.net.intent.impl.compiler; - -import com.google.common.collect.Lists; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.PointToPointIntent; -import org.onosproject.net.intent.TwoWayP2PIntent; -import org.onosproject.net.resource.link.LinkResourceAllocations; - -import java.util.List; -import java.util.Set; - -/** - * A intent compiler for {@link org.onosproject.net.intent.TwoWayP2PIntent}. - */ -@Component(immediate = true) -public class TwoWayP2PIntentCompiler - extends ConnectivityIntentCompiler<TwoWayP2PIntent> { - - @Activate - public void activate() { - intentManager.registerCompiler(TwoWayP2PIntent.class, this); - } - - @Deactivate - public void deactivate() { - intentManager.unregisterCompiler(TwoWayP2PIntent.class); - } - - @Override - public List<Intent> compile(TwoWayP2PIntent intent, List<Intent> installable, - Set<LinkResourceAllocations> resources) { - return Lists.newArrayList( - PointToPointIntent.builder() - .appId(intent.appId()) - .key(intent.key()) - .selector(intent.selector()) - .treatment(intent.treatment()) - .ingressPoint(intent.one()) - .egressPoint(intent.two()) - .constraints(intent.constraints()) - .priority(intent.priority()) - .build(), - PointToPointIntent.builder() - .appId(intent.appId()) - .key(intent.key()) - .selector(intent.selector()) - .treatment(intent.treatment()) - .ingressPoint(intent.two()) - .egressPoint(intent.one()) - .constraints(intent.constraints()) - .priority(intent.priority()) - .build()); - } -} diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/package-info.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/package-info.java deleted file mode 100644 index beaf5ed0..00000000 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Implementations of builtin intent compilers. - */ -package org.onosproject.net.intent.impl.compiler;
\ No newline at end of file |