blob: afc82e55e02849f88a1b8f0aa923ada2f3d659ba [file] [log] [blame]
Yuta HIGUCHIb360bb02016-12-08 16:40:48 -08001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
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 */
16package org.onosproject.net.intent;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19
20import java.util.Collection;
21import java.util.List;
22import javax.annotation.concurrent.Immutable;
23
24import org.onosproject.core.ApplicationId;
25import org.onosproject.net.DeviceId;
26import org.onosproject.net.NetworkResource;
Luca Prete670ac5d2017-02-03 15:55:43 -080027import org.onosproject.net.ResourceGroup;
Yuta HIGUCHIb360bb02016-12-08 16:40:48 -080028import org.onosproject.net.flow.TrafficSelector;
29import org.onosproject.net.flow.TrafficTreatment;
30
31import com.google.common.annotations.Beta;
32import com.google.common.base.MoreObjects;
33import com.google.common.collect.ImmutableList;
34
35/**
36 * Intent to create a protected linear path.
37 */
38@Immutable
39@Beta
40public final class ProtectedTransportIntent extends ConnectivityIntent {
41
42 private final DeviceId one;
43 private final DeviceId two;
44 // Do we want to be able to explicitly specify VLANs?
45 //private final Optional<VlanId> oneVid;
46 //private final Optional<VlanId> twoVid;
47
48 // TODO consider removing selector and treatment from signature
49 /**
50 * Creates {@link ProtectedTransportIntent}.
51 *
52 * @param one transport endpoint device
53 * @param two transport endpoint device
54 * @param appId application identifier
55 * @param key key of the intent
56 * @param resources resources
57 * @param selector traffic selector
58 * @param treatment treatment
59 * @param constraints optional list of constraints
60 * @param priority priority to use for flows generated by this intent
61 */
62 private ProtectedTransportIntent(DeviceId one,
63 DeviceId two,
64 ApplicationId appId, Key key,
65 Collection<NetworkResource> resources,
66 TrafficSelector selector,
67 TrafficTreatment treatment,
68 List<Constraint> constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -080069 int priority,
70 ResourceGroup resourceGroup) {
Yuta HIGUCHIb360bb02016-12-08 16:40:48 -080071 super(appId, key, resources, selector, treatment, constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -080072 priority, resourceGroup);
Yuta HIGUCHIb360bb02016-12-08 16:40:48 -080073
74 this.one = checkNotNull(one, "one cannot be null");
75 this.two = checkNotNull(two, "two cannot be null");
76 }
77
78 /**
79 * Returns the transport endpoint device one.
80 *
81 * @return transport endpoint device id
82 */
83 public DeviceId one() {
84 return one;
85 }
86
87 /**
88 * Returns the transport endpoint device two.
89 *
90 * @return transport endpoint device id
91 */
92 public DeviceId two() {
93 return two;
94 }
95
96 /**
97 * Returns a new {@link ProtectedTransportIntent} builder.
98 *
99 * @return the builder
100 */
101 public static Builder builder() {
102 return new Builder();
103 }
104
105 /**
106 * Builder for {@link ProtectedTransportIntent}.
107 */
108 public static final class Builder extends ConnectivityIntent.Builder {
109 private DeviceId one;
110 private DeviceId two;
111
112 private Builder() {
113 // Hide constructor
114 resources = ImmutableList.of();
115 }
116
117 // TODO remove these overrides after Builder refactoring
118 @Override
119 public Builder appId(ApplicationId appId) {
120 return (Builder) super.appId(appId);
121 }
122
123 @Override
124 public Builder key(Key key) {
125 return (Builder) super.key(key);
126 }
127
128 @Override
129 public Builder selector(TrafficSelector selector) {
130 return (Builder) super.selector(selector);
131 }
132
133 @Override
134 public Builder treatment(TrafficTreatment treatment) {
135 return (Builder) super.treatment(treatment);
136 }
137
138 @Override
139 public Builder constraints(List<Constraint> constraints) {
140 return (Builder) super.constraints(constraints);
141 }
142
143 @Override
144 public Builder priority(int priority) {
145 return (Builder) super.priority(priority);
146 }
147
Luca Prete670ac5d2017-02-03 15:55:43 -0800148 @Override
149 public Builder resourceGroup(ResourceGroup resourceGroup) {
150 return (Builder) super.resourceGroup(resourceGroup);
151 }
152
Yuta HIGUCHIb360bb02016-12-08 16:40:48 -0800153 /**
154 * Sets the transport endpoint device one.
155 *
156 * @param one transport endpoint device
157 * @return this builder
158 */
159 public Builder one(DeviceId one) {
160 this.one = checkNotNull(one);
161 return this;
162 }
163
164 /**
165 * Sets the transport endpoint device two.
166 *
167 * @param two transport endpoint device
168 * @return this builder
169 */
170 public Builder two(DeviceId two) {
171 this.two = checkNotNull(two);
172 return this;
173 }
174
175
176 /**
177 * Builds a point to point intent from the accumulated parameters.
178 *
179 * @return point to point intent
180 */
181 public ProtectedTransportIntent build() {
182
183 return new ProtectedTransportIntent(one,
184 two,
185 appId,
186 key,
187 resources,
188 selector,
189 treatment,
190 constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -0800191 priority,
192 resourceGroup
Yuta HIGUCHIb360bb02016-12-08 16:40:48 -0800193 );
194 }
195
196 }
197 @Override
198 public String toString() {
199 return MoreObjects.toStringHelper(getClass())
200 .add("id", id())
201 .add("key", key())
202 .add("appId", appId())
203 .add("priority", priority())
204 .add("resources", resources())
205 .add("selector", selector())
206 .add("treatment", treatment())
207 .add("one", one())
208 .add("two", two())
209 .add("constraints", constraints())
Luca Prete670ac5d2017-02-03 15:55:43 -0800210 .add("resourceGroup", resourceGroup())
Yuta HIGUCHIb360bb02016-12-08 16:40:48 -0800211 .toString();
212 }
213
214
215 // For serializer
216 private ProtectedTransportIntent() {
217 this.one = null;
218 this.two = null;
219 }
220}