Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 17 | |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.core.ApplicationId; |
| 20 | import org.onosproject.net.Link; |
| 21 | import org.onosproject.net.NetworkResource; |
| 22 | import org.onosproject.net.flow.TrafficSelector; |
| 23 | import org.onosproject.net.flow.TrafficTreatment; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 24 | |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 25 | import java.util.Collection; |
Sho SHIMIZU | c3df36b | 2014-11-11 18:19:29 -0800 | [diff] [blame] | 26 | import java.util.Collections; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 27 | import java.util.List; |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 28 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 29 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Abstraction of connectivity intent for traffic matching some criteria. |
| 33 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 34 | public abstract class ConnectivityIntent extends Intent { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 35 | |
| 36 | // TODO: other forms of intents should be considered for this family: |
| 37 | // point-to-point with constraints (waypoints/obstacles) |
| 38 | // multi-to-single point with constraints (waypoints/obstacles) |
| 39 | // single-to-multi point with constraints (waypoints/obstacles) |
| 40 | // concrete path (with alternate) |
| 41 | // ... |
| 42 | |
| 43 | private final TrafficSelector selector; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 44 | private final TrafficTreatment treatment; |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 45 | private final List<Constraint> constraints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 46 | |
| 47 | /** |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 48 | * Creates a connectivity intent that matches on the specified selector |
| 49 | * and applies the specified treatment. |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 50 | * <p> |
| 51 | * Path will be chosen without any constraints. |
| 52 | * </p> |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 53 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 54 | * @param appId application identifier |
| 55 | * @param resources required network resources (optional) |
| 56 | * @param selector traffic selector |
| 57 | * @param treatment treatment |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 58 | * @throws NullPointerException if the selector or treatement is null |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 59 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 60 | protected ConnectivityIntent(ApplicationId appId, |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 61 | Collection<NetworkResource> resources, |
| 62 | TrafficSelector selector, |
| 63 | TrafficTreatment treatment) { |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 64 | this(appId, resources, selector, treatment, Collections.emptyList()); |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Creates a connectivity intent that matches on the specified selector |
| 69 | * and applies the specified treatment. |
| 70 | * <p> |
| 71 | * Path will be optimized based on the first constraint if one is given. |
| 72 | * </p> |
| 73 | * |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 74 | * @param appId application identifier |
| 75 | * @param resources required network resources (optional) |
| 76 | * @param selector traffic selector |
| 77 | * @param treatment treatment |
| 78 | * @param constraints optional prioritized list of constraints |
| 79 | * @throws NullPointerException if the selector or treatement is null |
| 80 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 81 | protected ConnectivityIntent(ApplicationId appId, |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 82 | Collection<NetworkResource> resources, |
| 83 | TrafficSelector selector, |
| 84 | TrafficTreatment treatment, |
| 85 | List<Constraint> constraints) { |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 86 | super(appId, resources); |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 87 | this.selector = checkNotNull(selector); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 88 | this.treatment = checkNotNull(treatment); |
Sho SHIMIZU | c3df36b | 2014-11-11 18:19:29 -0800 | [diff] [blame] | 89 | this.constraints = checkNotNull(constraints); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Constructor for serializer. |
| 94 | */ |
| 95 | protected ConnectivityIntent() { |
| 96 | super(); |
| 97 | this.selector = null; |
| 98 | this.treatment = null; |
Sho SHIMIZU | c3df36b | 2014-11-11 18:19:29 -0800 | [diff] [blame] | 99 | this.constraints = Collections.emptyList(); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Returns the match specifying the type of traffic. |
| 104 | * |
| 105 | * @return traffic match |
| 106 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 107 | public TrafficSelector selector() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 108 | return selector; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Returns the action applied to the traffic. |
| 113 | * |
| 114 | * @return applied action |
| 115 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 116 | public TrafficTreatment treatment() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 117 | return treatment; |
| 118 | } |
| 119 | |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 120 | /** |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 121 | * Returns the set of connectivity constraints. |
| 122 | * |
| 123 | * @return list of intent constraints |
| 124 | */ |
| 125 | public List<Constraint> constraints() { |
| 126 | return constraints; |
| 127 | } |
| 128 | |
| 129 | /** |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 130 | * Produces a collection of network resources from the given links. |
| 131 | * |
| 132 | * @param links collection of links |
| 133 | * @return collection of link resources |
| 134 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 135 | protected static Collection<NetworkResource> resources(Collection<Link> links) { |
Sho SHIMIZU | f4dbc726 | 2014-11-04 18:49:02 -0800 | [diff] [blame] | 136 | return ImmutableSet.copyOf(links); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | } |