blob: 6f1f71e60d2dffc28d4c4f363a796b884c7ea756 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska83e090e2014-10-22 14:25:35 -070015 */
Brian O'Connorb876bf12014-10-02 14:59:37 -070016package org.onlab.onos.net.intent;
17
Thomas Vachuskac96058a2014-10-20 23:00:16 -070018import com.google.common.collect.ImmutableSet;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070019import org.onlab.onos.core.ApplicationId;
Thomas Vachuskac96058a2014-10-20 23:00:16 -070020import org.onlab.onos.net.Link;
21import org.onlab.onos.net.NetworkResource;
Brian O'Connorb876bf12014-10-02 14:59:37 -070022import org.onlab.onos.net.flow.TrafficSelector;
23import org.onlab.onos.net.flow.TrafficTreatment;
24
Thomas Vachuskac96058a2014-10-20 23:00:16 -070025import java.util.Collection;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080026import java.util.List;
Thomas Vachuskac96058a2014-10-20 23:00:16 -070027
toma1d16b62014-10-02 23:45:11 -070028import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070029
30/**
31 * Abstraction of connectivity intent for traffic matching some criteria.
32 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070033public abstract class ConnectivityIntent extends Intent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070034
35 // TODO: other forms of intents should be considered for this family:
36 // point-to-point with constraints (waypoints/obstacles)
37 // multi-to-single point with constraints (waypoints/obstacles)
38 // single-to-multi point with constraints (waypoints/obstacles)
39 // concrete path (with alternate)
40 // ...
41
42 private final TrafficSelector selector;
Brian O'Connorb876bf12014-10-02 14:59:37 -070043 private final TrafficTreatment treatment;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080044 private final List<Constraint> constraints;
Brian O'Connorb876bf12014-10-02 14:59:37 -070045
46 /**
Thomas Vachuskac96058a2014-10-20 23:00:16 -070047 * Creates a connectivity intent that matches on the specified selector
48 * and applies the specified treatment.
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080049 * <p>
50 * Path will be chosen without any constraints.
51 * </p>
Brian O'Connorb876bf12014-10-02 14:59:37 -070052 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070053 * @param id intent identifier
54 * @param appId application identifier
55 * @param resources required network resources (optional)
56 * @param selector traffic selector
57 * @param treatment treatment
toma1d16b62014-10-02 23:45:11 -070058 * @throws NullPointerException if the selector or treatement is null
Brian O'Connorb876bf12014-10-02 14:59:37 -070059 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070060 protected ConnectivityIntent(IntentId id, ApplicationId appId,
61 Collection<NetworkResource> resources,
62 TrafficSelector selector,
63 TrafficTreatment treatment) {
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080064 this(id, appId, resources, selector, treatment, null);
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 *
74 * @param id intent identifier
75 * @param appId application identifier
76 * @param resources required network resources (optional)
77 * @param selector traffic selector
78 * @param treatment treatment
79 * @param constraints optional prioritized list of constraints
80 * @throws NullPointerException if the selector or treatement is null
81 */
82 protected ConnectivityIntent(IntentId id, ApplicationId appId,
83 Collection<NetworkResource> resources,
84 TrafficSelector selector,
85 TrafficTreatment treatment,
86 List<Constraint> constraints) {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070087 super(id, appId, resources);
toma1d16b62014-10-02 23:45:11 -070088 this.selector = checkNotNull(selector);
Thomas Vachuskac96058a2014-10-20 23:00:16 -070089 this.treatment = checkNotNull(treatment);
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080090 this.constraints = constraints;
Brian O'Connorb876bf12014-10-02 14:59:37 -070091 }
92
93 /**
94 * Constructor for serializer.
95 */
96 protected ConnectivityIntent() {
97 super();
98 this.selector = null;
99 this.treatment = null;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800100 this.constraints = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700101 }
102
103 /**
104 * Returns the match specifying the type of traffic.
105 *
106 * @return traffic match
107 */
tom85258ee2014-10-07 00:10:02 -0700108 public TrafficSelector selector() {
Brian O'Connorb876bf12014-10-02 14:59:37 -0700109 return selector;
110 }
111
112 /**
113 * Returns the action applied to the traffic.
114 *
115 * @return applied action
116 */
tom85258ee2014-10-07 00:10:02 -0700117 public TrafficTreatment treatment() {
Brian O'Connorb876bf12014-10-02 14:59:37 -0700118 return treatment;
119 }
120
Thomas Vachuskae291c842014-10-21 02:52:38 -0700121 /**
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800122 * Returns the set of connectivity constraints.
123 *
124 * @return list of intent constraints
125 */
126 public List<Constraint> constraints() {
127 return constraints;
128 }
129
130 /**
Thomas Vachuskae291c842014-10-21 02:52:38 -0700131 * Produces a collection of network resources from the given links.
132 *
133 * @param links collection of links
134 * @return collection of link resources
135 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -0700136 protected static Collection<NetworkResource> resources(Collection<Link> links) {
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800137 return ImmutableSet.<NetworkResource>copyOf((Iterable<? extends NetworkResource>) links);
Brian O'Connorb876bf12014-10-02 14:59:37 -0700138 }
139
140}