Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 19 | package org.onlab.onos.net.intent; |
| 20 | |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableSet; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame^] | 22 | import org.onlab.onos.core.ApplicationId; |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 23 | import org.onlab.onos.net.Link; |
| 24 | import org.onlab.onos.net.NetworkResource; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 25 | import org.onlab.onos.net.flow.TrafficSelector; |
| 26 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 27 | |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 28 | import java.util.Collection; |
| 29 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 30 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Abstraction of connectivity intent for traffic matching some criteria. |
| 34 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 35 | public abstract class ConnectivityIntent extends Intent { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 36 | |
| 37 | // TODO: other forms of intents should be considered for this family: |
| 38 | // point-to-point with constraints (waypoints/obstacles) |
| 39 | // multi-to-single point with constraints (waypoints/obstacles) |
| 40 | // single-to-multi point with constraints (waypoints/obstacles) |
| 41 | // concrete path (with alternate) |
| 42 | // ... |
| 43 | |
| 44 | private final TrafficSelector selector; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 45 | private final TrafficTreatment treatment; |
| 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. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 50 | * |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 51 | * @param id intent identifier |
| 52 | * @param appId application identifier |
| 53 | * @param resources required network resources (optional) |
| 54 | * @param selector traffic selector |
| 55 | * @param treatment treatment |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 56 | * @throws NullPointerException if the selector or treatement is null |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 57 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 58 | protected ConnectivityIntent(IntentId id, ApplicationId appId, |
| 59 | Collection<NetworkResource> resources, |
| 60 | TrafficSelector selector, |
| 61 | TrafficTreatment treatment) { |
| 62 | super(id, appId, resources); |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 63 | this.selector = checkNotNull(selector); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 64 | this.treatment = checkNotNull(treatment); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Constructor for serializer. |
| 69 | */ |
| 70 | protected ConnectivityIntent() { |
| 71 | super(); |
| 72 | this.selector = null; |
| 73 | this.treatment = null; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns the match specifying the type of traffic. |
| 78 | * |
| 79 | * @return traffic match |
| 80 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 81 | public TrafficSelector selector() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 82 | return selector; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Returns the action applied to the traffic. |
| 87 | * |
| 88 | * @return applied action |
| 89 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 90 | public TrafficTreatment treatment() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 91 | return treatment; |
| 92 | } |
| 93 | |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 94 | /** |
| 95 | * Produces a collection of network resources from the given links. |
| 96 | * |
| 97 | * @param links collection of links |
| 98 | * @return collection of link resources |
| 99 | */ |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 100 | protected static Collection<NetworkResource> resources(Collection<Link> links) { |
| 101 | return ImmutableSet.<NetworkResource>copyOf(links); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | } |