blob: efdc4bdf498c1945719a91fc4dca27be64f3d7b3 [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.DefaultEdgeLink;
Sho SHIMIZUde8e6b52014-11-13 11:23:17 -080023import org.onlab.onos.net.DefaultLink;
Ray Milkeya058c732014-10-08 13:52:34 -070024import org.onlab.onos.net.DefaultPath;
25import org.onlab.onos.net.Link;
26import org.onlab.onos.net.Path;
Ray Milkeya058c732014-10-08 13:52:34 -070027import org.onlab.onos.net.intent.Intent;
Ray Milkeya058c732014-10-08 13:52:34 -070028import org.onlab.onos.net.intent.PathIntent;
29import org.onlab.onos.net.intent.PointToPointIntent;
30import org.onlab.onos.net.provider.ProviderId;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080031
32import java.util.ArrayList;
33import java.util.List;
Ray Milkeya058c732014-10-08 13:52:34 -070034
Thomas Vachuska425a2d72014-10-29 11:28:28 -070035import static java.util.Arrays.asList;
Sho SHIMIZUde8e6b52014-11-13 11:23:17 -080036import static org.onlab.onos.net.Link.Type.DIRECT;
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);
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
60 public List<Intent> compile(PointToPointIntent intent) {
Sho SHIMIZUde8e6b52014-11-13 11:23:17 -080061 ConnectPoint ingressPoint = intent.ingressPoint();
62 ConnectPoint egressPoint = intent.egressPoint();
63
64 if (ingressPoint.deviceId().equals(egressPoint.deviceId())) {
65 List<Link> links = asList(new DefaultLink(PID, ingressPoint, egressPoint, DIRECT));
66 return asList(createPathIntent(new DefaultPath(PID, links, 1), intent));
67 }
Ray Milkeya058c732014-10-08 13:52:34 -070068
69 List<Link> links = new ArrayList<>();
Sho SHIMIZUde8e6b52014-11-13 11:23:17 -080070 Path path = getPath(intent, ingressPoint.deviceId(),
71 egressPoint.deviceId());
72
73 links.add(DefaultEdgeLink.createEdgeLink(ingressPoint, true));
Ray Milkeya058c732014-10-08 13:52:34 -070074 links.addAll(path.links());
Sho SHIMIZUde8e6b52014-11-13 11:23:17 -080075 links.add(DefaultEdgeLink.createEdgeLink(egressPoint, false));
Ray Milkeya058c732014-10-08 13:52:34 -070076
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080077 return asList(createPathIntent(new DefaultPath(PID, links, path.cost(),
78 path.annotations()), intent));
Ray Milkeya058c732014-10-08 13:52:34 -070079 }
80
81 /**
82 * Creates a path intent from the specified path and original
83 * connectivity intent.
84 *
Thomas Vachuskab97cf282014-10-20 23:31:12 -070085 * @param path path to create an intent for
Ray Milkeya058c732014-10-08 13:52:34 -070086 * @param intent original intent
87 */
88 private Intent createPathIntent(Path path,
89 PointToPointIntent intent) {
Thomas Vachuskab97cf282014-10-20 23:31:12 -070090 return new PathIntent(intent.appId(),
Ray Milkey460f4022014-11-05 15:41:43 -080091 intent.selector(), intent.treatment(), path,
92 intent.constraints());
Ray Milkeya058c732014-10-08 13:52:34 -070093 }
94
Ray Milkeya058c732014-10-08 13:52:34 -070095}