blob: c32c8ee009afd37c550c52fe3defa27ef9d51b8f [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;
Ray Milkeya058c732014-10-08 13:52:34 -070021import org.onlab.onos.net.DefaultEdgeLink;
22import 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;
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;
34
Ray Milkeya058c732014-10-08 13:52:34 -070035/**
Thomas Vachuska425a2d72014-10-29 11:28:28 -070036 * An intent compiler for {@link org.onlab.onos.net.intent.PointToPointIntent}.
Ray Milkeya058c732014-10-08 13:52:34 -070037 */
38@Component(immediate = true)
39public class PointToPointIntentCompiler
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080040 extends ConnectivityIntentCompiler<PointToPointIntent> {
Ray Milkeya058c732014-10-08 13:52:34 -070041
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080042 // TODO: use off-the-shell core provider ID
43 private static final ProviderId PID =
44 new ProviderId("core", "org.onlab.onos.core", true);
weibit50eb95b2014-10-25 21:47:54 -070045
Ray Milkeya058c732014-10-08 13:52:34 -070046 @Activate
47 public void activate() {
Ray Milkeya058c732014-10-08 13:52:34 -070048 intentManager.registerCompiler(PointToPointIntent.class, this);
49 }
50
51 @Deactivate
52 public void deactivate() {
53 intentManager.unregisterCompiler(PointToPointIntent.class);
54 }
55
56 @Override
57 public List<Intent> compile(PointToPointIntent intent) {
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080058 Path path = getPath(intent, intent.ingressPoint().deviceId(),
59 intent.egressPoint().deviceId());
Ray Milkeya058c732014-10-08 13:52:34 -070060
61 List<Link> links = new ArrayList<>();
62 links.add(DefaultEdgeLink.createEdgeLink(intent.ingressPoint(), true));
63 links.addAll(path.links());
64 links.add(DefaultEdgeLink.createEdgeLink(intent.egressPoint(), false));
65
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080066 return asList(createPathIntent(new DefaultPath(PID, links, path.cost(),
67 path.annotations()), intent));
Ray Milkeya058c732014-10-08 13:52:34 -070068 }
69
70 /**
71 * Creates a path intent from the specified path and original
72 * connectivity intent.
73 *
Thomas Vachuskab97cf282014-10-20 23:31:12 -070074 * @param path path to create an intent for
Ray Milkeya058c732014-10-08 13:52:34 -070075 * @param intent original intent
76 */
77 private Intent createPathIntent(Path path,
78 PointToPointIntent intent) {
Thomas Vachuskab97cf282014-10-20 23:31:12 -070079 return new PathIntent(intent.appId(),
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080080 intent.selector(), intent.treatment(), path);
Ray Milkeya058c732014-10-08 13:52:34 -070081 }
82
Ray Milkeya058c732014-10-08 13:52:34 -070083}