Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Sho SHIMIZU | 6c28f83 | 2015-02-20 16:12:19 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent.impl.compiler; |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 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; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.net.ConnectPoint; |
| 22 | import org.onosproject.net.DefaultPath; |
| 23 | import org.onosproject.net.Link; |
| 24 | import org.onosproject.net.Path; |
| 25 | import org.onosproject.net.intent.Intent; |
| 26 | import org.onosproject.net.intent.PathIntent; |
| 27 | import org.onosproject.net.intent.PointToPointIntent; |
| 28 | import org.onosproject.net.provider.ProviderId; |
Brian O'Connor | 6de2e20 | 2015-05-21 14:30:41 -0700 | [diff] [blame] | 29 | import org.onosproject.net.resource.link.LinkResourceAllocations; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 30 | |
| 31 | import java.util.ArrayList; |
| 32 | import java.util.List; |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 33 | import java.util.Set; |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 34 | |
Thomas Vachuska | 425a2d7 | 2014-10-29 11:28:28 -0700 | [diff] [blame] | 35 | import static java.util.Arrays.asList; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 36 | import static org.onosproject.net.DefaultEdgeLink.createEdgeLink; |
Thomas Vachuska | 425a2d7 | 2014-10-29 11:28:28 -0700 | [diff] [blame] | 37 | |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 38 | /** |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 39 | * An intent compiler for {@link org.onosproject.net.intent.PointToPointIntent}. |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 40 | */ |
| 41 | @Component(immediate = true) |
| 42 | public class PointToPointIntentCompiler |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 43 | extends ConnectivityIntentCompiler<PointToPointIntent> { |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 44 | |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 45 | // TODO: use off-the-shell core provider ID |
| 46 | private static final ProviderId PID = |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 47 | new ProviderId("core", "org.onosproject.core", true); |
Sho SHIMIZU | 3908fde | 2014-11-19 16:30:22 -0800 | [diff] [blame] | 48 | // TODO: consider whether the default cost is appropriate or not |
| 49 | public static final int DEFAULT_COST = 1; |
weibit | 50eb95b | 2014-10-25 21:47:54 -0700 | [diff] [blame] | 50 | |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 51 | @Activate |
| 52 | public void activate() { |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 53 | intentManager.registerCompiler(PointToPointIntent.class, this); |
| 54 | } |
| 55 | |
| 56 | @Deactivate |
| 57 | public void deactivate() { |
| 58 | intentManager.unregisterCompiler(PointToPointIntent.class); |
| 59 | } |
| 60 | |
| 61 | @Override |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 62 | public List<Intent> compile(PointToPointIntent intent, List<Intent> installable, |
| 63 | Set<LinkResourceAllocations> resources) { |
| 64 | |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 65 | ConnectPoint ingressPoint = intent.ingressPoint(); |
| 66 | ConnectPoint egressPoint = intent.egressPoint(); |
| 67 | |
| 68 | if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { |
Sho SHIMIZU | 3908fde | 2014-11-19 16:30:22 -0800 | [diff] [blame] | 69 | List<Link> links = asList(createEdgeLink(ingressPoint, true), createEdgeLink(egressPoint, false)); |
| 70 | return asList(createPathIntent(new DefaultPath(PID, links, DEFAULT_COST), intent)); |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 71 | } |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 72 | |
| 73 | List<Link> links = new ArrayList<>(); |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 74 | Path path = getPath(intent, ingressPoint.deviceId(), |
| 75 | egressPoint.deviceId()); |
| 76 | |
Sho SHIMIZU | 3908fde | 2014-11-19 16:30:22 -0800 | [diff] [blame] | 77 | links.add(createEdgeLink(ingressPoint, true)); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 78 | links.addAll(path.links()); |
Sho SHIMIZU | 3908fde | 2014-11-19 16:30:22 -0800 | [diff] [blame] | 79 | links.add(createEdgeLink(egressPoint, false)); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 80 | |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 81 | return asList(createPathIntent(new DefaultPath(PID, links, path.cost(), |
| 82 | path.annotations()), intent)); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Creates a path intent from the specified path and original |
| 87 | * connectivity intent. |
| 88 | * |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 89 | * @param path path to create an intent for |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 90 | * @param intent original intent |
| 91 | */ |
| 92 | private Intent createPathIntent(Path path, |
| 93 | PointToPointIntent intent) { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 94 | return PathIntent.builder() |
| 95 | .appId(intent.appId()) |
| 96 | .selector(intent.selector()) |
| 97 | .treatment(intent.treatment()) |
| 98 | .path(path) |
| 99 | .constraints(intent.constraints()) |
| 100 | .priority(intent.priority()) |
| 101 | .build(); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 104 | } |