Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 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 Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.intent.impl; |
| 17 | |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 18 | import org.apache.felix.scr.annotations.Activate; |
| 19 | import org.apache.felix.scr.annotations.Component; |
| 20 | import org.apache.felix.scr.annotations.Deactivate; |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 21 | import org.onlab.onos.net.DefaultEdgeLink; |
| 22 | import org.onlab.onos.net.DefaultPath; |
| 23 | import org.onlab.onos.net.Link; |
| 24 | import org.onlab.onos.net.Path; |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 25 | import org.onlab.onos.net.intent.Intent; |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 26 | import org.onlab.onos.net.intent.PathIntent; |
| 27 | import org.onlab.onos.net.intent.PointToPointIntent; |
| 28 | import org.onlab.onos.net.provider.ProviderId; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 29 | |
| 30 | import java.util.ArrayList; |
| 31 | import java.util.List; |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 32 | |
Thomas Vachuska | 425a2d7 | 2014-10-29 11:28:28 -0700 | [diff] [blame] | 33 | import static java.util.Arrays.asList; |
| 34 | |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 35 | /** |
Thomas Vachuska | 425a2d7 | 2014-10-29 11:28:28 -0700 | [diff] [blame] | 36 | * An intent compiler for {@link org.onlab.onos.net.intent.PointToPointIntent}. |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 37 | */ |
| 38 | @Component(immediate = true) |
| 39 | public class PointToPointIntentCompiler |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 40 | extends ConnectivityIntentCompiler<PointToPointIntent> { |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 41 | |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 42 | // TODO: use off-the-shell core provider ID |
| 43 | private static final ProviderId PID = |
| 44 | new ProviderId("core", "org.onlab.onos.core", true); |
weibit | 50eb95b | 2014-10-25 21:47:54 -0700 | [diff] [blame] | 45 | |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 46 | @Activate |
| 47 | public void activate() { |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 48 | 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 Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 58 | Path path = getPath(intent, intent.ingressPoint().deviceId(), |
| 59 | intent.egressPoint().deviceId()); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 60 | |
| 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 Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 66 | return asList(createPathIntent(new DefaultPath(PID, links, path.cost(), |
| 67 | path.annotations()), intent)); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Creates a path intent from the specified path and original |
| 72 | * connectivity intent. |
| 73 | * |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 74 | * @param path path to create an intent for |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 75 | * @param intent original intent |
| 76 | */ |
| 77 | private Intent createPathIntent(Path path, |
| 78 | PointToPointIntent intent) { |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 79 | return new PathIntent(intent.appId(), |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 80 | intent.selector(), intent.treatment(), path, |
| 81 | intent.constraints()); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 84 | } |