blob: 28d7ea51e4b3e011b07ad2b4845b67e7667cf08c [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present 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;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080029
30import java.util.ArrayList;
31import java.util.List;
Ray Milkeya058c732014-10-08 13:52:34 -070032
Thomas Vachuska425a2d72014-10-29 11:28:28 -070033import static java.util.Arrays.asList;
Brian O'Connorabafb502014-12-02 22:26:20 -080034import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
Thomas Vachuska425a2d72014-10-29 11:28:28 -070035
Ray Milkeya058c732014-10-08 13:52:34 -070036/**
Brian O'Connorabafb502014-12-02 22:26:20 -080037 * An intent compiler for {@link org.onosproject.net.intent.PointToPointIntent}.
Ray Milkeya058c732014-10-08 13:52:34 -070038 */
39@Component(immediate = true)
40public class PointToPointIntentCompiler
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080041 extends ConnectivityIntentCompiler<PointToPointIntent> {
Ray Milkeya058c732014-10-08 13:52:34 -070042
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080043 // TODO: use off-the-shell core provider ID
44 private static final ProviderId PID =
Brian O'Connorabafb502014-12-02 22:26:20 -080045 new ProviderId("core", "org.onosproject.core", true);
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080046 // TODO: consider whether the default cost is appropriate or not
47 public static final int DEFAULT_COST = 1;
weibit50eb95b2014-10-25 21:47:54 -070048
Ray Milkeya058c732014-10-08 13:52:34 -070049 @Activate
50 public void activate() {
Ray Milkeya058c732014-10-08 13:52:34 -070051 intentManager.registerCompiler(PointToPointIntent.class, this);
52 }
53
54 @Deactivate
55 public void deactivate() {
56 intentManager.unregisterCompiler(PointToPointIntent.class);
57 }
58
59 @Override
Sho SHIMIZUec07ffd2016-02-22 20:45:21 -080060 public List<Intent> compile(PointToPointIntent intent, List<Intent> installable) {
Brian O'Connorfa81eae2014-10-30 13:20:05 -070061
Sho SHIMIZUde8e6b52014-11-13 11:23:17 -080062 ConnectPoint ingressPoint = intent.ingressPoint();
63 ConnectPoint egressPoint = intent.egressPoint();
64
65 if (ingressPoint.deviceId().equals(egressPoint.deviceId())) {
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080066 List<Link> links = asList(createEdgeLink(ingressPoint, true), createEdgeLink(egressPoint, false));
67 return asList(createPathIntent(new DefaultPath(PID, links, DEFAULT_COST), intent));
Sho SHIMIZUde8e6b52014-11-13 11:23:17 -080068 }
Ray Milkeya058c732014-10-08 13:52:34 -070069
70 List<Link> links = new ArrayList<>();
Sho SHIMIZUde8e6b52014-11-13 11:23:17 -080071 Path path = getPath(intent, ingressPoint.deviceId(),
72 egressPoint.deviceId());
73
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080074 links.add(createEdgeLink(ingressPoint, true));
Ray Milkeya058c732014-10-08 13:52:34 -070075 links.addAll(path.links());
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080076 links.add(createEdgeLink(egressPoint, false));
Ray Milkeya058c732014-10-08 13:52:34 -070077
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080078 return asList(createPathIntent(new DefaultPath(PID, links, path.cost(),
79 path.annotations()), intent));
Ray Milkeya058c732014-10-08 13:52:34 -070080 }
81
82 /**
83 * Creates a path intent from the specified path and original
84 * connectivity intent.
85 *
Thomas Vachuskab97cf282014-10-20 23:31:12 -070086 * @param path path to create an intent for
Ray Milkeya058c732014-10-08 13:52:34 -070087 * @param intent original intent
88 */
89 private Intent createPathIntent(Path path,
90 PointToPointIntent intent) {
Ray Milkeyebc5d222015-03-18 15:45:36 -070091 return PathIntent.builder()
92 .appId(intent.appId())
93 .selector(intent.selector())
94 .treatment(intent.treatment())
95 .path(path)
96 .constraints(intent.constraints())
97 .priority(intent.priority())
98 .build();
Ray Milkeya058c732014-10-08 13:52:34 -070099 }
100
Ray Milkeya058c732014-10-08 13:52:34 -0700101}