blob: c8ccf6801a8d637d7ad8e92208e5f00a91532338 [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuska58de4162015-09-10 16:15:33 -07003 *
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;
Michele Santuari4b6019e2014-12-19 11:31:45 +010023
24
25import org.apache.felix.scr.annotations.Activate;
26import org.apache.felix.scr.annotations.Component;
27import org.apache.felix.scr.annotations.Deactivate;
28import org.onosproject.net.ConnectPoint;
29import org.onosproject.net.DefaultPath;
30import org.onosproject.net.Link;
31import org.onosproject.net.Path;
32import org.onosproject.net.intent.Intent;
33import org.onosproject.net.intent.MplsIntent;
34import org.onosproject.net.intent.MplsPathIntent;
35import org.onosproject.net.provider.ProviderId;
Michele Santuari4b6019e2014-12-19 11:31:45 +010036
Michele Santuari6096acd2016-02-09 17:00:37 +010037/**
38 * @deprecated in Goldeneye Release, in favour of encapsulation
39 * constraint {@link org.onosproject.net.intent.constraint.EncapsulationConstraint}
40 */
41@Deprecated
Michele Santuari4b6019e2014-12-19 11:31:45 +010042@Component(immediate = true)
43public 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 SHIMIZUec07ffd2016-02-22 20:45:21 -080063 public List<Intent> compile(MplsIntent intent, List<Intent> installable) {
Michele Santuari4b6019e2014-12-19 11:31:45 +010064 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<>();
73 Path path = getPath(intent, ingressPoint.deviceId(),
74 egressPoint.deviceId());
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 Milkeyebc5d222015-03-18 15:45:36 -070094 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 Santuari4b6019e2014-12-19 11:31:45 +0100104 }
105
106
107}