blob: d15a15a98604a000f92307cb73786ad6d05e7bd5 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
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'Connorb876bf12014-10-02 14:59:37 -070019package org.onlab.onos.net.intent;
20
Thomas Vachuskac96058a2014-10-20 23:00:16 -070021import com.google.common.collect.ImmutableSet;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070022import org.onlab.onos.core.ApplicationId;
Thomas Vachuskac96058a2014-10-20 23:00:16 -070023import org.onlab.onos.net.Link;
24import org.onlab.onos.net.NetworkResource;
Brian O'Connorb876bf12014-10-02 14:59:37 -070025import org.onlab.onos.net.flow.TrafficSelector;
26import org.onlab.onos.net.flow.TrafficTreatment;
27
Thomas Vachuskac96058a2014-10-20 23:00:16 -070028import java.util.Collection;
29
toma1d16b62014-10-02 23:45:11 -070030import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070031
32/**
33 * Abstraction of connectivity intent for traffic matching some criteria.
34 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070035public abstract class ConnectivityIntent extends Intent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070036
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'Connorb876bf12014-10-02 14:59:37 -070045 private final TrafficTreatment treatment;
46
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.
Brian O'Connorb876bf12014-10-02 14:59:37 -070050 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070051 * @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
toma1d16b62014-10-02 23:45:11 -070056 * @throws NullPointerException if the selector or treatement is null
Brian O'Connorb876bf12014-10-02 14:59:37 -070057 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070058 protected ConnectivityIntent(IntentId id, ApplicationId appId,
59 Collection<NetworkResource> resources,
60 TrafficSelector selector,
61 TrafficTreatment treatment) {
62 super(id, appId, resources);
toma1d16b62014-10-02 23:45:11 -070063 this.selector = checkNotNull(selector);
Thomas Vachuskac96058a2014-10-20 23:00:16 -070064 this.treatment = checkNotNull(treatment);
Brian O'Connorb876bf12014-10-02 14:59:37 -070065 }
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 */
tom85258ee2014-10-07 00:10:02 -070081 public TrafficSelector selector() {
Brian O'Connorb876bf12014-10-02 14:59:37 -070082 return selector;
83 }
84
85 /**
86 * Returns the action applied to the traffic.
87 *
88 * @return applied action
89 */
tom85258ee2014-10-07 00:10:02 -070090 public TrafficTreatment treatment() {
Brian O'Connorb876bf12014-10-02 14:59:37 -070091 return treatment;
92 }
93
Thomas Vachuskae291c842014-10-21 02:52:38 -070094 /**
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 Vachuskac96058a2014-10-20 23:00:16 -0700100 protected static Collection<NetworkResource> resources(Collection<Link> links) {
101 return ImmutableSet.<NetworkResource>copyOf(links);
Brian O'Connorb876bf12014-10-02 14:59:37 -0700102 }
103
104}