Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Sho SHIMIZU | 6c28f83 | 2015-02-20 16:12:19 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent.impl.compiler; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 17 | |
| 18 | import static java.util.Arrays.asList; |
| 19 | import static org.onosproject.net.DefaultEdgeLink.createEdgeLink; |
| 20 | |
| 21 | import java.util.ArrayList; |
| 22 | import java.util.List; |
| 23 | import java.util.Set; |
| 24 | |
| 25 | |
| 26 | import org.apache.felix.scr.annotations.Activate; |
| 27 | import org.apache.felix.scr.annotations.Component; |
| 28 | import org.apache.felix.scr.annotations.Deactivate; |
| 29 | import org.onosproject.net.ConnectPoint; |
| 30 | import org.onosproject.net.DefaultPath; |
| 31 | import org.onosproject.net.Link; |
| 32 | import org.onosproject.net.Path; |
| 33 | import org.onosproject.net.intent.Intent; |
| 34 | import org.onosproject.net.intent.MplsIntent; |
| 35 | import org.onosproject.net.intent.MplsPathIntent; |
| 36 | import org.onosproject.net.provider.ProviderId; |
Brian O'Connor | 6de2e20 | 2015-05-21 14:30:41 -0700 | [diff] [blame] | 37 | import org.onosproject.net.resource.link.LinkResourceAllocations; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 38 | |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame^] | 39 | /** |
| 40 | * @deprecated in Goldeneye Release, in favour of encapsulation |
| 41 | * constraint {@link org.onosproject.net.intent.constraint.EncapsulationConstraint} |
| 42 | */ |
| 43 | @Deprecated |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 44 | @Component(immediate = true) |
| 45 | public class MplsIntentCompiler extends ConnectivityIntentCompiler<MplsIntent> { |
| 46 | |
| 47 | // TODO: use off-the-shell core provider ID |
| 48 | private static final ProviderId PID = |
| 49 | new ProviderId("core", "org.onosproject.core", true); |
| 50 | // TODO: consider whether the default cost is appropriate or not |
| 51 | public static final int DEFAULT_COST = 1; |
| 52 | |
| 53 | |
| 54 | @Activate |
| 55 | public void activate() { |
| 56 | intentManager.registerCompiler(MplsIntent.class, this); |
| 57 | } |
| 58 | |
| 59 | @Deactivate |
| 60 | public void deactivate() { |
| 61 | intentManager.unregisterCompiler(MplsIntent.class); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public List<Intent> compile(MplsIntent intent, List<Intent> installable, |
| 66 | Set<LinkResourceAllocations> resources) { |
| 67 | ConnectPoint ingressPoint = intent.ingressPoint(); |
| 68 | ConnectPoint egressPoint = intent.egressPoint(); |
| 69 | |
| 70 | if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { |
| 71 | List<Link> links = asList(createEdgeLink(ingressPoint, true), createEdgeLink(egressPoint, false)); |
| 72 | return asList(createPathIntent(new DefaultPath(PID, links, DEFAULT_COST), intent)); |
| 73 | } |
| 74 | |
| 75 | List<Link> links = new ArrayList<>(); |
| 76 | Path path = getPath(intent, ingressPoint.deviceId(), |
| 77 | egressPoint.deviceId()); |
| 78 | |
| 79 | links.add(createEdgeLink(ingressPoint, true)); |
| 80 | links.addAll(path.links()); |
| 81 | |
| 82 | links.add(createEdgeLink(egressPoint, false)); |
| 83 | |
| 84 | return asList(createPathIntent(new DefaultPath(PID, links, path.cost(), |
| 85 | path.annotations()), intent)); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Creates a path intent from the specified path and original |
| 90 | * connectivity intent. |
| 91 | * |
| 92 | * @param path path to create an intent for |
| 93 | * @param intent original intent |
| 94 | */ |
| 95 | private Intent createPathIntent(Path path, |
| 96 | MplsIntent intent) { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 97 | return MplsPathIntent.builder() |
| 98 | .appId(intent.appId()) |
| 99 | .selector(intent.selector()) |
| 100 | .treatment(intent.treatment()) |
| 101 | .path(path) |
| 102 | .ingressLabel(intent.ingressLabel()) |
| 103 | .egressLabel(intent.egressLabel()) |
| 104 | .constraints(intent.constraints()) |
| 105 | .priority(intent.priority()) |
| 106 | .build(); |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | |
| 110 | } |