blob: f3c5aa9a4bb3d3112db8d0a23a9fc29657133e95 [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
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 SHIMIZU6c28f832015-02-20 16:12:19 -080016package org.onosproject.net.intent.impl.compiler;
Michele Santuari4b6019e2014-12-19 11:31:45 +010017
18import static java.util.Arrays.asList;
19import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
20
21import java.util.ArrayList;
22import java.util.List;
23import java.util.Set;
24
25
26import org.apache.felix.scr.annotations.Activate;
27import org.apache.felix.scr.annotations.Component;
28import org.apache.felix.scr.annotations.Deactivate;
29import org.onosproject.net.ConnectPoint;
30import org.onosproject.net.DefaultPath;
31import org.onosproject.net.Link;
32import org.onosproject.net.Path;
33import org.onosproject.net.intent.Intent;
34import org.onosproject.net.intent.MplsIntent;
35import org.onosproject.net.intent.MplsPathIntent;
36import org.onosproject.net.provider.ProviderId;
Brian O'Connor6de2e202015-05-21 14:30:41 -070037import org.onosproject.net.resource.link.LinkResourceAllocations;
Michele Santuari4b6019e2014-12-19 11:31:45 +010038
Michele Santuari6096acd2016-02-09 17:00:37 +010039/**
40 * @deprecated in Goldeneye Release, in favour of encapsulation
41 * constraint {@link org.onosproject.net.intent.constraint.EncapsulationConstraint}
42 */
43@Deprecated
Michele Santuari4b6019e2014-12-19 11:31:45 +010044@Component(immediate = true)
45public 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 Milkeyebc5d222015-03-18 15:45:36 -070097 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 Santuari4b6019e2014-12-19 11:31:45 +0100107 }
108
109
110}