blob: b1246025cfce9428dbd54cb52385da0253e00597 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 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 */
Ray Milkeya058c732014-10-08 13:52:34 -070016package org.onlab.onos.net.intent.impl;
17
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;
Sho SHIMIZUde8e6b52014-11-13 11:23:17 -080021import org.onlab.onos.net.ConnectPoint;
Ray Milkeya058c732014-10-08 13:52:34 -070022import org.onlab.onos.net.DefaultPath;
23import org.onlab.onos.net.Link;
24import org.onlab.onos.net.Path;
Ray Milkeya058c732014-10-08 13:52:34 -070025import org.onlab.onos.net.intent.Intent;
Ray Milkeya058c732014-10-08 13:52:34 -070026import org.onlab.onos.net.intent.PathIntent;
27import org.onlab.onos.net.intent.PointToPointIntent;
28import org.onlab.onos.net.provider.ProviderId;
Brian O'Connorfa81eae2014-10-30 13:20:05 -070029import org.onlab.onos.net.resource.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;
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080036import static org.onlab.onos.net.DefaultEdgeLink.createEdgeLink;
Thomas Vachuska425a2d72014-10-29 11:28:28 -070037
Ray Milkeya058c732014-10-08 13:52:34 -070038/**
Thomas Vachuska425a2d72014-10-29 11:28:28 -070039 * An intent compiler for {@link org.onlab.onos.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 =
47 new ProviderId("core", "org.onlab.onos.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) {
Thomas Vachuskab97cf282014-10-20 23:31:12 -070094 return new PathIntent(intent.appId(),
Ray Milkey460f4022014-11-05 15:41:43 -080095 intent.selector(), intent.treatment(), path,
96 intent.constraints());
Ray Milkeya058c732014-10-08 13:52:34 -070097 }
98
Ray Milkeya058c732014-10-08 13:52:34 -070099}