blob: da212a5f60ba5a9a7ec93b4c5354f0f3f47d70f6 [file] [log] [blame]
Michele Santuari38dd82e2017-01-04 09:23:49 +01001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Michele Santuari38dd82e2017-01-04 09:23:49 +01003 *
4 * 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
7 *
8 * 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.
15 */
16
17package org.onosproject.net.domain;
18
19import com.google.common.annotations.Beta;
20import com.google.common.collect.ImmutableList;
21import org.onosproject.core.ApplicationId;
22import org.onosproject.net.FilteredConnectPoint;
23import org.onosproject.net.NetworkResource;
24import org.onosproject.net.flow.TrafficTreatment;
25import org.onosproject.net.intent.Constraint;
26import org.onosproject.net.intent.Intent;
27import org.onosproject.net.intent.Key;
28
29import java.util.Collection;
30import java.util.List;
31import java.util.Set;
32
33import static com.google.common.base.Preconditions.checkArgument;
34import static com.google.common.base.Preconditions.checkNotNull;
35
36/**
37 * Intents targeting a domain network.
38 */
39@Beta
40public abstract class DomainIntent extends Intent {
41
42 private final Set<FilteredConnectPoint> filteredIngressPoints;
43 private final Set<FilteredConnectPoint> filteredEgressPoints;
44 private final TrafficTreatment treatment;
45 private final List<Constraint> constraints;
46
47
48 /**
49 * @param appId application identifier
50 * @param key explicit key to use for intent
51 * @param resources required network resources (optional)
52 * @param priority intent priority
53 * @param filteredIngressPoints filtered ingress points
54 * @param filteredEgressPoints filtered egress points
55 * @param treatment action to be applied at the egress
56 * @param constraints constraints of the intent
57 * @throws NullPointerException if {@code filteredIngressPoints} or
58 * {@code filteredEgressPoints} or {@code appId}
59 * or {@code constraints} is null.
60 * @throws IllegalArgumentException if {@code filteredIngressPoints} or {@code filteredEgressPoints} is empty.
61 */
62 public DomainIntent(ApplicationId appId, Key key,
63 Collection<NetworkResource> resources,
64 int priority,
65 Set<FilteredConnectPoint> filteredIngressPoints,
66 Set<FilteredConnectPoint> filteredEgressPoints,
67 TrafficTreatment treatment,
68 List<Constraint> constraints) {
Ray Milkey39f78b62018-01-05 15:17:37 -080069 super(appId, key, resources, priority, null);
Michele Santuari38dd82e2017-01-04 09:23:49 +010070
71 checkNotNull(filteredIngressPoints, "Ingress points cannot be null");
72 checkArgument(!filteredIngressPoints.isEmpty(), "Ingress point cannot be empty");
73 checkNotNull(filteredEgressPoints, "Egress points cannot be null");
74 checkArgument(!filteredEgressPoints.isEmpty(), "Egress point cannot be empty");
75 this.filteredIngressPoints = filteredIngressPoints;
76 this.filteredEgressPoints = filteredEgressPoints;
77 this.treatment = treatment;
78 this.constraints = checkNotNull(constraints, "Constraints cannot be null");
79 }
80
81 /**
82 * Constructor for serializer.
83 */
84 protected DomainIntent() {
85 super();
86 filteredIngressPoints = null;
87 filteredEgressPoints = null;
88 treatment = null;
89 constraints = null;
90 }
91
92 /**
93 * Abstract builder for connectivity intents.
94 */
95 public abstract static class Builder extends Intent.Builder {
96 protected List<Constraint> constraints = ImmutableList.of();
97 protected TrafficTreatment treatment;
98
99 /**
100 * Creates a new empty builder.
101 */
102 protected Builder() {
103 }
104
105 @Override
106 public Builder appId(ApplicationId appId) {
107 return (Builder) super.appId(appId);
108 }
109
110 @Override
111 public Builder key(Key key) {
112 return (Builder) super.key(key);
113 }
114
115 @Override
116 public Builder priority(int priority) {
117 return (Builder) super.priority(priority);
118 }
119
120 /**
121 * Sets the traffic treatment for the intent that will be built.
122 *
123 * @param treatment treatment to use for built intent
124 * @return this builder
125 */
126 public Builder treatment(TrafficTreatment treatment) {
127 this.treatment = treatment;
128 return this;
129 }
130
131 /**
132 * Sets the constraints for the intent that will be built.
133 *
134 * @param constraints constraints to use for built intent
135 * @return this builder
136 */
137 public Builder constraints(List<Constraint> constraints) {
138 this.constraints = ImmutableList.copyOf(constraints);
139 return this;
140 }
141 }
142
143 @Override
144 public boolean isInstallable() {
145 return true;
146 }
147
148 /**
149 * Returns the filtered connected points on which the ingress traffic
150 * should be connected to the egress.
151 *
152 * @return filtered ingress connect points
153 */
154 public Set<FilteredConnectPoint> filteredIngressPoints() {
155 return filteredIngressPoints;
156 }
157
158 /**
159 * Returns the filtered connected points on which the traffic should egress.
160 *
161 * @return filtered egress connect points
162 */
163 public Set<FilteredConnectPoint> filteredEgressPoints() {
164 return filteredEgressPoints;
165 }
166
167 /**
168 * Returns the action applied to the traffic at the egress.
169 *
170 * @return applied action
171 */
172 public TrafficTreatment treatment() {
173 return treatment;
174 }
175
176 /**
177 * Returns the set of connectivity constraints.
178 *
179 * @return list of intent constraints
180 */
181 public List<Constraint> constraints() {
182 return constraints;
183 }
184
185}