Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 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; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 23 | |
| 24 | |
| 25 | import org.apache.felix.scr.annotations.Activate; |
| 26 | import org.apache.felix.scr.annotations.Component; |
| 27 | import org.apache.felix.scr.annotations.Deactivate; |
| 28 | import org.onosproject.net.ConnectPoint; |
| 29 | import org.onosproject.net.DefaultPath; |
| 30 | import org.onosproject.net.Link; |
| 31 | import org.onosproject.net.Path; |
| 32 | import org.onosproject.net.intent.Intent; |
| 33 | import org.onosproject.net.intent.MplsIntent; |
| 34 | import org.onosproject.net.intent.MplsPathIntent; |
| 35 | import org.onosproject.net.provider.ProviderId; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 36 | |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 37 | /** |
| 38 | * @deprecated in Goldeneye Release, in favour of encapsulation |
| 39 | * constraint {@link org.onosproject.net.intent.constraint.EncapsulationConstraint} |
| 40 | */ |
| 41 | @Deprecated |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 42 | @Component(immediate = true) |
| 43 | public class MplsIntentCompiler extends ConnectivityIntentCompiler<MplsIntent> { |
| 44 | |
| 45 | // TODO: use off-the-shell core provider ID |
| 46 | private static final ProviderId PID = |
| 47 | new ProviderId("core", "org.onosproject.core", true); |
| 48 | // TODO: consider whether the default cost is appropriate or not |
| 49 | public static final int DEFAULT_COST = 1; |
| 50 | |
| 51 | |
| 52 | @Activate |
| 53 | public void activate() { |
| 54 | intentManager.registerCompiler(MplsIntent.class, this); |
| 55 | } |
| 56 | |
| 57 | @Deactivate |
| 58 | public void deactivate() { |
| 59 | intentManager.unregisterCompiler(MplsIntent.class); |
| 60 | } |
| 61 | |
| 62 | @Override |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 63 | public List<Intent> compile(MplsIntent intent, List<Intent> installable) { |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 64 | ConnectPoint ingressPoint = intent.ingressPoint(); |
| 65 | ConnectPoint egressPoint = intent.egressPoint(); |
| 66 | |
| 67 | if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { |
| 68 | List<Link> links = asList(createEdgeLink(ingressPoint, true), createEdgeLink(egressPoint, false)); |
| 69 | return asList(createPathIntent(new DefaultPath(PID, links, DEFAULT_COST), intent)); |
| 70 | } |
| 71 | |
| 72 | List<Link> links = new ArrayList<>(); |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 73 | Path path = getPathOrException(intent, ingressPoint.deviceId(), |
| 74 | egressPoint.deviceId()); |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 75 | |
| 76 | links.add(createEdgeLink(ingressPoint, true)); |
| 77 | links.addAll(path.links()); |
| 78 | |
| 79 | links.add(createEdgeLink(egressPoint, false)); |
| 80 | |
| 81 | return asList(createPathIntent(new DefaultPath(PID, links, path.cost(), |
| 82 | path.annotations()), intent)); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Creates a path intent from the specified path and original |
| 87 | * connectivity intent. |
| 88 | * |
| 89 | * @param path path to create an intent for |
| 90 | * @param intent original intent |
| 91 | */ |
| 92 | private Intent createPathIntent(Path path, |
| 93 | MplsIntent intent) { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 94 | return MplsPathIntent.builder() |
| 95 | .appId(intent.appId()) |
| 96 | .selector(intent.selector()) |
| 97 | .treatment(intent.treatment()) |
| 98 | .path(path) |
| 99 | .ingressLabel(intent.ingressLabel()) |
| 100 | .egressLabel(intent.egressLabel()) |
| 101 | .constraints(intent.constraints()) |
| 102 | .priority(intent.priority()) |
| 103 | .build(); |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | |
| 107 | } |