blob: 038e96a7fbf6916c130b89f18cda80b622945f0a [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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
Brian O'Connorb876bf12014-10-02 14:59:37 -070017
Thomas Vachuskac96058a2014-10-20 23:00:16 -070018import com.google.common.collect.ImmutableSet;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.core.ApplicationId;
20import org.onosproject.net.Link;
21import org.onosproject.net.NetworkResource;
22import org.onosproject.net.flow.TrafficSelector;
23import org.onosproject.net.flow.TrafficTreatment;
Brian O'Connorb876bf12014-10-02 14:59:37 -070024
Thomas Vachuskac96058a2014-10-20 23:00:16 -070025import java.util.Collection;
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -080026import java.util.Collections;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080027import java.util.List;
Thomas Vachuskac96058a2014-10-20 23:00:16 -070028
toma1d16b62014-10-02 23:45:11 -070029import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070030
31/**
32 * Abstraction of connectivity intent for traffic matching some criteria.
33 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070034public abstract class ConnectivityIntent extends Intent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070035
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'Connorb876bf12014-10-02 14:59:37 -070044 private final TrafficTreatment treatment;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080045 private final List<Constraint> constraints;
Brian O'Connorb876bf12014-10-02 14:59:37 -070046
47 /**
Thomas Vachuskac96058a2014-10-20 23:00:16 -070048 * Creates a connectivity intent that matches on the specified selector
49 * and applies the specified treatment.
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080050 * <p>
Ray Milkey5b3717e2015-02-05 11:44:08 -080051 * Path will be optimized based on the first constraint if one is given.
52 * </p>
53 *
54 * @param appId application identifier
55 * @param key explicit key to use for intent
56 * @param resources required network resources (optional)
57 * @param selector traffic selector
58 * @param treatment treatment
59 * @param constraints optional prioritized list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -070060 * @param priority priority to use for flows generated by this intent
Ray Milkey5b3717e2015-02-05 11:44:08 -080061 * @throws NullPointerException if the selector or treatment is null
62 */
Ray Milkey5b3717e2015-02-05 11:44:08 -080063 protected ConnectivityIntent(ApplicationId appId,
64 Key key,
65 Collection<NetworkResource> resources,
66 TrafficSelector selector,
67 TrafficTreatment treatment,
Ray Milkeyc24cde32015-03-10 18:20:18 -070068 List<Constraint> constraints,
69 int priority) {
70 super(appId, key, resources, priority);
Ray Milkey5b3717e2015-02-05 11:44:08 -080071 this.selector = checkNotNull(selector);
72 this.treatment = checkNotNull(treatment);
73 this.constraints = checkNotNull(constraints);
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080074 }
75
76 /**
77 * Creates a connectivity intent that matches on the specified selector
78 * and applies the specified treatment.
79 * <p>
80 * Path will be optimized based on the first constraint if one is given.
81 * </p>
82 *
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080083 * @param appId application identifier
84 * @param resources required network resources (optional)
85 * @param selector traffic selector
86 * @param treatment treatment
87 * @param constraints optional prioritized list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -070088 * @param priority priority to use for flows generated by this intent
Ray Milkeye1dfb502015-01-13 16:35:46 -080089 * @throws NullPointerException if the selector or treatment is null
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080090 */
Ray Milkey5b3717e2015-02-05 11:44:08 -080091
Brian O'Connor520c0522014-11-23 23:50:47 -080092 protected ConnectivityIntent(ApplicationId appId,
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080093 Collection<NetworkResource> resources,
94 TrafficSelector selector,
95 TrafficTreatment treatment,
Ray Milkeyc24cde32015-03-10 18:20:18 -070096 List<Constraint> constraints,
97 int priority) {
98 super(appId, null, resources, priority);
toma1d16b62014-10-02 23:45:11 -070099 this.selector = checkNotNull(selector);
Thomas Vachuskac96058a2014-10-20 23:00:16 -0700100 this.treatment = checkNotNull(treatment);
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -0800101 this.constraints = checkNotNull(constraints);
Brian O'Connorb876bf12014-10-02 14:59:37 -0700102 }
103
104 /**
105 * Constructor for serializer.
106 */
107 protected ConnectivityIntent() {
108 super();
109 this.selector = null;
110 this.treatment = null;
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -0800111 this.constraints = Collections.emptyList();
Brian O'Connorb876bf12014-10-02 14:59:37 -0700112 }
113
114 /**
115 * Returns the match specifying the type of traffic.
116 *
117 * @return traffic match
118 */
tom85258ee2014-10-07 00:10:02 -0700119 public TrafficSelector selector() {
Brian O'Connorb876bf12014-10-02 14:59:37 -0700120 return selector;
121 }
122
123 /**
124 * Returns the action applied to the traffic.
125 *
126 * @return applied action
127 */
tom85258ee2014-10-07 00:10:02 -0700128 public TrafficTreatment treatment() {
Brian O'Connorb876bf12014-10-02 14:59:37 -0700129 return treatment;
130 }
131
Thomas Vachuskae291c842014-10-21 02:52:38 -0700132 /**
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800133 * Returns the set of connectivity constraints.
134 *
135 * @return list of intent constraints
136 */
137 public List<Constraint> constraints() {
138 return constraints;
139 }
140
141 /**
Thomas Vachuskae291c842014-10-21 02:52:38 -0700142 * Produces a collection of network resources from the given links.
143 *
144 * @param links collection of links
145 * @return collection of link resources
146 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -0700147 protected static Collection<NetworkResource> resources(Collection<Link> links) {
Sho SHIMIZUf4dbc7262014-11-04 18:49:02 -0800148 return ImmutableSet.copyOf(links);
Brian O'Connorb876bf12014-10-02 14:59:37 -0700149 }
150
151}