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 | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.intent; |
| 17 | |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 19 | import org.onlab.onos.core.ApplicationId; |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 20 | import org.onlab.onos.net.Link; |
| 21 | import org.onlab.onos.net.NetworkResource; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 22 | import org.onlab.onos.net.flow.TrafficSelector; |
| 23 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 24 | |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 25 | import java.util.Collection; |
| 26 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 27 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Abstraction of connectivity intent for traffic matching some criteria. |
| 31 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 32 | public abstract class ConnectivityIntent extends Intent { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 33 | |
| 34 | // TODO: other forms of intents should be considered for this family: |
| 35 | // point-to-point with constraints (waypoints/obstacles) |
| 36 | // multi-to-single point with constraints (waypoints/obstacles) |
| 37 | // single-to-multi point with constraints (waypoints/obstacles) |
| 38 | // concrete path (with alternate) |
| 39 | // ... |
| 40 | |
| 41 | private final TrafficSelector selector; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 42 | private final TrafficTreatment treatment; |
| 43 | |
| 44 | /** |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 45 | * Creates a connectivity intent that matches on the specified selector |
| 46 | * and applies the specified treatment. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 47 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 48 | * @param id intent identifier |
| 49 | * @param appId application identifier |
| 50 | * @param resources required network resources (optional) |
| 51 | * @param selector traffic selector |
| 52 | * @param treatment treatment |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 53 | * @throws NullPointerException if the selector or treatement is null |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 54 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 55 | protected ConnectivityIntent(IntentId id, ApplicationId appId, |
| 56 | Collection<NetworkResource> resources, |
| 57 | TrafficSelector selector, |
| 58 | TrafficTreatment treatment) { |
| 59 | super(id, appId, resources); |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 60 | this.selector = checkNotNull(selector); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 61 | this.treatment = checkNotNull(treatment); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Constructor for serializer. |
| 66 | */ |
| 67 | protected ConnectivityIntent() { |
| 68 | super(); |
| 69 | this.selector = null; |
| 70 | this.treatment = null; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Returns the match specifying the type of traffic. |
| 75 | * |
| 76 | * @return traffic match |
| 77 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 78 | public TrafficSelector selector() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 79 | return selector; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Returns the action applied to the traffic. |
| 84 | * |
| 85 | * @return applied action |
| 86 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 87 | public TrafficTreatment treatment() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 88 | return treatment; |
| 89 | } |
| 90 | |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 91 | /** |
| 92 | * Produces a collection of network resources from the given links. |
| 93 | * |
| 94 | * @param links collection of links |
| 95 | * @return collection of link resources |
| 96 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 97 | protected static Collection<NetworkResource> resources(Collection<Link> links) { |
| 98 | return ImmutableSet.<NetworkResource>copyOf(links); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | } |