blob: 5c9a8e90dd29b9ab5b91599cc897f164cb6729c6 [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.base.MoreObjects;
21import com.google.common.collect.ImmutableList;
22import com.google.common.collect.ImmutableSet;
23import org.onosproject.core.ApplicationId;
24import org.onosproject.net.FilteredConnectPoint;
25import org.onosproject.net.Link;
26import org.onosproject.net.NetworkResource;
27import org.onosproject.net.flow.TrafficTreatment;
28import org.onosproject.net.intent.Constraint;
29import org.onosproject.net.intent.Key;
30
31import java.util.Collection;
32import java.util.List;
33
34import static com.google.common.base.Preconditions.checkNotNull;
35
36/**
37 * Representation of a point to point intent targeting a domain. It consists
38 * into an ingress and an egress filtered connection points and
39 * a set of links to represent the path.
40 */
41@Beta
42public class DomainPointToPointIntent extends DomainIntent {
43
44 private final List<Link> links;
45
46
47 /**
48 * Creates a new point-to-point domain intent with the supplied ingress/egress
49 * ports and domainId.
50 *
51 * @param appId application identifier
52 * @param key explicit key to use for intent
53 * @param priority intent priority
54 * @param filteredIngressPoint filtered ingress point
55 * @param filteredEgressPoint filtered egress point
56 * @throws NullPointerException if {@code filteredIngressPoint} or
57 * {@code filteredEgressPoint} or {@code appId}
58 * or {@code links} or {@code constraints}
59 * is null.
60 */
61 private DomainPointToPointIntent(ApplicationId appId, Key key,
62 int priority,
63 FilteredConnectPoint filteredIngressPoint,
64 FilteredConnectPoint filteredEgressPoint,
65 TrafficTreatment treatment,
66 List<Constraint> constraints,
67 List<Link> links) {
68
69 super(appId, key, resources(links),
70 priority, ImmutableSet.of(filteredIngressPoint),
71 ImmutableSet.of(filteredEgressPoint), treatment, constraints);
72 this.links = links;
73
74 }
75
76 /**
77 * Constructor for serializer.
78 */
79 protected DomainPointToPointIntent() {
80 super();
81 this.links = null;
82 }
83
84 /**
85 * Returns a new point to point domain intent builder. The application id,
86 * ingress point, egress point and domainId are required fields.
87 * If they are not set by calls to the appropriate methods,
88 * an exception will be thrown.
89 *
90 * @return point to point builder
91 */
92 public static DomainPointToPointIntent.Builder builder() {
93 return new Builder();
94 }
95
96 /**
97 * Builder of a point to point domain intent.
98 */
99 public static final class Builder extends DomainIntent.Builder {
100 private FilteredConnectPoint filteredIngressPoint;
101 private FilteredConnectPoint filteredEgressPoint;
102 private List<Link> links;
103
104 private Builder() {
105 // Hide constructor
106 }
107
108 @Override
109 public Builder appId(ApplicationId appId) {
110 super.appId = appId;
111 return this;
112 }
113
114 @Override
115 public Builder key(Key key) {
116 super.key = key;
117 return this;
118 }
119
120 @Override
121 public Builder priority(int priority) {
122 super.priority = priority;
123 return this;
124 }
125
126 @Override
127 public Builder treatment(TrafficTreatment treatment) {
128 super.treatment = treatment;
129 return this;
130 }
131
132 @Override
133 public Builder constraints(List<Constraint> constraints) {
134 super.constraints = ImmutableList.copyOf(constraints);
135 return this;
136 }
137
138 /**
139 * Sets the filtered ingress point of the domain point to point intent
140 * that will be built.
141 *
142 * @param ingressPoint single ingress connect point
143 * @return this builder
144 */
145 public Builder filteredIngressPoint(FilteredConnectPoint ingressPoint) {
146 this.filteredIngressPoint = ingressPoint;
147 return this;
148 }
149
150 /**
151 * Sets the filtered egress point of the domain point to point intent
152 * that will be built.
153 *
154 * @param egressPoint single egress connect point
155 * @return this builder
156 */
157 public Builder filteredEgressPoint(FilteredConnectPoint egressPoint) {
158 this.filteredEgressPoint = egressPoint;
159 return this;
160 }
161
162 /**
163 * Sets the links of the point to domain point intent that will be built.
164 *
165 * @param links links for the intent
166 * @return this builder
167 */
168 public Builder links(List<Link> links) {
169 this.links = ImmutableList.copyOf(links);
170 return this;
171 }
172
173 /**
174 * Builds a point to point domain intent from the accumulated parameters.
175 *
176 * @return point to point domain intent
177 */
178 public DomainPointToPointIntent build() {
179
180 return new DomainPointToPointIntent(
181 appId,
182 key,
183 priority,
184 filteredIngressPoint,
185 filteredEgressPoint,
186 treatment,
187 constraints,
188 links
189 );
190 }
191 }
192
193 public List<Link> links() {
194 return links;
195 }
196
197 /**
198 * Produces a collection of network resources from the given links.
199 *
200 * @param links collection of links
201 * @return collection of link resources
202 */
203 protected static Collection<NetworkResource> resources(Collection<Link> links) {
204 checkNotNull(links, "links cannot be null");
205 return ImmutableSet.copyOf(links);
206 }
207
208 @Override
209 public String toString() {
210 return MoreObjects.toStringHelper(getClass())
211 .add("id", id())
212 .add("key", key())
213 .add("appId", appId())
214 .add("priority", priority())
215 .add("resources", resources())
216 .add("filtered ingress", filteredIngressPoints())
217 .add("filtered egress", filteredEgressPoints())
218 .toString();
219 }
220
221}
222