blob: 5644ee2226999dbe707fddfa301d582f5f6c75cb [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -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;
Ray Milkeya058c732014-10-08 13:52:34 -070017
Ray Milkeya058c732014-10-08 13:52:34 -070018import org.apache.felix.scr.annotations.Activate;
19import org.apache.felix.scr.annotations.Component;
20import org.apache.felix.scr.annotations.Deactivate;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.ConnectPoint;
22import org.onosproject.net.DefaultPath;
23import org.onosproject.net.Link;
24import org.onosproject.net.Path;
25import org.onosproject.net.intent.Intent;
26import org.onosproject.net.intent.PathIntent;
27import org.onosproject.net.intent.PointToPointIntent;
28import org.onosproject.net.provider.ProviderId;
Brian O'Connor6de2e202015-05-21 14:30:41 -070029import org.onosproject.net.resource.link.LinkResourceAllocations;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080030
31import java.util.ArrayList;
32import java.util.List;
Brian O'Connorfa81eae2014-10-30 13:20:05 -070033import java.util.Set;
Ray Milkeya058c732014-10-08 13:52:34 -070034
Thomas Vachuska425a2d72014-10-29 11:28:28 -070035import static java.util.Arrays.asList;
Brian O'Connorabafb502014-12-02 22:26:20 -080036import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
Thomas Vachuska425a2d72014-10-29 11:28:28 -070037
Ray Milkeya058c732014-10-08 13:52:34 -070038/**
Brian O'Connorabafb502014-12-02 22:26:20 -080039 * An intent compiler for {@link org.onosproject.net.intent.PointToPointIntent}.
Ray Milkeya058c732014-10-08 13:52:34 -070040 */
41@Component(immediate = true)
42public class PointToPointIntentCompiler
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080043 extends ConnectivityIntentCompiler<PointToPointIntent> {
Ray Milkeya058c732014-10-08 13:52:34 -070044
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080045 // TODO: use off-the-shell core provider ID
46 private static final ProviderId PID =
Brian O'Connorabafb502014-12-02 22:26:20 -080047 new ProviderId("core", "org.onosproject.core", true);
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080048 // TODO: consider whether the default cost is appropriate or not
49 public static final int DEFAULT_COST = 1;
weibit50eb95b2014-10-25 21:47:54 -070050
Ray Milkeya058c732014-10-08 13:52:34 -070051 @Activate
52 public void activate() {
Ray Milkeya058c732014-10-08 13:52:34 -070053 intentManager.registerCompiler(PointToPointIntent.class, this);
54 }
55
56 @Deactivate
57 public void deactivate() {
58 intentManager.unregisterCompiler(PointToPointIntent.class);
59 }
60
61 @Override
Brian O'Connorfa81eae2014-10-30 13:20:05 -070062 public List<Intent> compile(PointToPointIntent intent, List<Intent> installable,
63 Set<LinkResourceAllocations> resources) {
64
Sho SHIMIZUde8e6b52014-11-13 11:23:17 -080065 ConnectPoint ingressPoint = intent.ingressPoint();
66 ConnectPoint egressPoint = intent.egressPoint();
67
68 if (ingressPoint.deviceId().equals(egressPoint.deviceId())) {
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080069 List<Link> links = asList(createEdgeLink(ingressPoint, true), createEdgeLink(egressPoint, false));
70 return asList(createPathIntent(new DefaultPath(PID, links, DEFAULT_COST), intent));
Sho SHIMIZUde8e6b52014-11-13 11:23:17 -080071 }
Ray Milkeya058c732014-10-08 13:52:34 -070072
73 List<Link> links = new ArrayList<>();
Sho SHIMIZUde8e6b52014-11-13 11:23:17 -080074 Path path = getPath(intent, ingressPoint.deviceId(),
75 egressPoint.deviceId());
76
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080077 links.add(createEdgeLink(ingressPoint, true));
Ray Milkeya058c732014-10-08 13:52:34 -070078 links.addAll(path.links());
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080079 links.add(createEdgeLink(egressPoint, false));
Ray Milkeya058c732014-10-08 13:52:34 -070080
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080081 return asList(createPathIntent(new DefaultPath(PID, links, path.cost(),
82 path.annotations()), intent));
Ray Milkeya058c732014-10-08 13:52:34 -070083 }
84
85 /**
86 * Creates a path intent from the specified path and original
87 * connectivity intent.
88 *
Thomas Vachuskab97cf282014-10-20 23:31:12 -070089 * @param path path to create an intent for
Ray Milkeya058c732014-10-08 13:52:34 -070090 * @param intent original intent
91 */
92 private Intent createPathIntent(Path path,
93 PointToPointIntent intent) {
Ray Milkeyebc5d222015-03-18 15:45:36 -070094 return PathIntent.builder()
95 .appId(intent.appId())
96 .selector(intent.selector())
97 .treatment(intent.treatment())
98 .path(path)
99 .constraints(intent.constraints())
100 .priority(intent.priority())
101 .build();
Ray Milkeya058c732014-10-08 13:52:34 -0700102 }
103
Ray Milkeya058c732014-10-08 13:52:34 -0700104}