blob: 0ef08090d2cee9b4b8beb849a26ed0148867e6a1 [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;
27import org.onosproject.net.flow.TrafficSelector;
28import org.onosproject.net.flow.TrafficTreatment;
29
30import com.google.common.annotations.Beta;
31import com.google.common.base.MoreObjects;
32import com.google.common.collect.ImmutableList;
33
34/**
35 * Intent to create a protected linear path.
36 */
37@Immutable
38@Beta
39public final class ProtectedTransportIntent extends ConnectivityIntent {
40
41 private final DeviceId one;
42 private final DeviceId two;
43 // Do we want to be able to explicitly specify VLANs?
44 //private final Optional<VlanId> oneVid;
45 //private final Optional<VlanId> twoVid;
46
47 // TODO consider removing selector and treatment from signature
48 /**
49 * Creates {@link ProtectedTransportIntent}.
50 *
51 * @param one transport endpoint device
52 * @param two transport endpoint device
53 * @param appId application identifier
54 * @param key key of the intent
55 * @param resources resources
56 * @param selector traffic selector
57 * @param treatment treatment
58 * @param constraints optional list of constraints
59 * @param priority priority to use for flows generated by this intent
60 */
61 private ProtectedTransportIntent(DeviceId one,
62 DeviceId two,
63 ApplicationId appId, Key key,
64 Collection<NetworkResource> resources,
65 TrafficSelector selector,
66 TrafficTreatment treatment,
67 List<Constraint> constraints,
68 int priority) {
69 super(appId, key, resources, selector, treatment, constraints,
70 priority);
71
72 this.one = checkNotNull(one, "one cannot be null");
73 this.two = checkNotNull(two, "two cannot be null");
74 }
75
76 /**
77 * Returns the transport endpoint device one.
78 *
79 * @return transport endpoint device id
80 */
81 public DeviceId one() {
82 return one;
83 }
84
85 /**
86 * Returns the transport endpoint device two.
87 *
88 * @return transport endpoint device id
89 */
90 public DeviceId two() {
91 return two;
92 }
93
94 /**
95 * Returns a new {@link ProtectedTransportIntent} builder.
96 *
97 * @return the builder
98 */
99 public static Builder builder() {
100 return new Builder();
101 }
102
103 /**
104 * Builder for {@link ProtectedTransportIntent}.
105 */
106 public static final class Builder extends ConnectivityIntent.Builder {
107 private DeviceId one;
108 private DeviceId two;
109
110 private Builder() {
111 // Hide constructor
112 resources = ImmutableList.of();
113 }
114
115 // TODO remove these overrides after Builder refactoring
116 @Override
117 public Builder appId(ApplicationId appId) {
118 return (Builder) super.appId(appId);
119 }
120
121 @Override
122 public Builder key(Key key) {
123 return (Builder) super.key(key);
124 }
125
126 @Override
127 public Builder selector(TrafficSelector selector) {
128 return (Builder) super.selector(selector);
129 }
130
131 @Override
132 public Builder treatment(TrafficTreatment treatment) {
133 return (Builder) super.treatment(treatment);
134 }
135
136 @Override
137 public Builder constraints(List<Constraint> constraints) {
138 return (Builder) super.constraints(constraints);
139 }
140
141 @Override
142 public Builder priority(int priority) {
143 return (Builder) super.priority(priority);
144 }
145
146 /**
147 * Sets the transport endpoint device one.
148 *
149 * @param one transport endpoint device
150 * @return this builder
151 */
152 public Builder one(DeviceId one) {
153 this.one = checkNotNull(one);
154 return this;
155 }
156
157 /**
158 * Sets the transport endpoint device two.
159 *
160 * @param two transport endpoint device
161 * @return this builder
162 */
163 public Builder two(DeviceId two) {
164 this.two = checkNotNull(two);
165 return this;
166 }
167
168
169 /**
170 * Builds a point to point intent from the accumulated parameters.
171 *
172 * @return point to point intent
173 */
174 public ProtectedTransportIntent build() {
175
176 return new ProtectedTransportIntent(one,
177 two,
178 appId,
179 key,
180 resources,
181 selector,
182 treatment,
183 constraints,
184 priority
185 );
186 }
187
188 }
189 @Override
190 public String toString() {
191 return MoreObjects.toStringHelper(getClass())
192 .add("id", id())
193 .add("key", key())
194 .add("appId", appId())
195 .add("priority", priority())
196 .add("resources", resources())
197 .add("selector", selector())
198 .add("treatment", treatment())
199 .add("one", one())
200 .add("two", two())
201 .add("constraints", constraints())
202 .toString();
203 }
204
205
206 // For serializer
207 private ProtectedTransportIntent() {
208 this.one = null;
209 this.two = null;
210 }
211}