blob: 65d48d568e2881fc9df6971fd0daaa9ad27279e6 [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;
26
toma1d16b62014-10-02 23:45:11 -070027import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070028
29/**
30 * Abstraction of connectivity intent for traffic matching some criteria.
31 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070032public abstract class ConnectivityIntent extends Intent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070033
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'Connorb876bf12014-10-02 14:59:37 -070042 private final TrafficTreatment treatment;
43
44 /**
Thomas Vachuskac96058a2014-10-20 23:00:16 -070045 * Creates a connectivity intent that matches on the specified selector
46 * and applies the specified treatment.
Brian O'Connorb876bf12014-10-02 14:59:37 -070047 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070048 * @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
toma1d16b62014-10-02 23:45:11 -070053 * @throws NullPointerException if the selector or treatement is null
Brian O'Connorb876bf12014-10-02 14:59:37 -070054 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070055 protected ConnectivityIntent(IntentId id, ApplicationId appId,
56 Collection<NetworkResource> resources,
57 TrafficSelector selector,
58 TrafficTreatment treatment) {
59 super(id, appId, resources);
toma1d16b62014-10-02 23:45:11 -070060 this.selector = checkNotNull(selector);
Thomas Vachuskac96058a2014-10-20 23:00:16 -070061 this.treatment = checkNotNull(treatment);
Brian O'Connorb876bf12014-10-02 14:59:37 -070062 }
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 */
tom85258ee2014-10-07 00:10:02 -070078 public TrafficSelector selector() {
Brian O'Connorb876bf12014-10-02 14:59:37 -070079 return selector;
80 }
81
82 /**
83 * Returns the action applied to the traffic.
84 *
85 * @return applied action
86 */
tom85258ee2014-10-07 00:10:02 -070087 public TrafficTreatment treatment() {
Brian O'Connorb876bf12014-10-02 14:59:37 -070088 return treatment;
89 }
90
Thomas Vachuskae291c842014-10-21 02:52:38 -070091 /**
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 Vachuskac96058a2014-10-20 23:00:16 -070097 protected static Collection<NetworkResource> resources(Collection<Link> links) {
98 return ImmutableSet.<NetworkResource>copyOf(links);
Brian O'Connorb876bf12014-10-02 14:59:37 -070099 }
100
101}