blob: e78e89329bf012f6a82e022d8433bb32147d4689 [file] [log] [blame]
Yuta HIGUCHIa255bb42016-11-03 16:04:08 -07001/*
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;
19import java.util.Collection;
20
21import javax.annotation.concurrent.Immutable;
22
23import org.onosproject.core.ApplicationId;
24import org.onosproject.net.DeviceId;
25import org.onosproject.net.NetworkResource;
Luca Prete670ac5d2017-02-03 15:55:43 -080026import org.onosproject.net.ResourceGroup;
Yuta HIGUCHIa255bb42016-11-03 16:04:08 -070027import org.onosproject.net.behaviour.protection.ProtectedTransportEndpointDescription;
28
29import com.google.common.annotations.Beta;
30import com.google.common.base.MoreObjects;
31import com.google.common.collect.ImmutableList;
32
33/**
34 * Installable Intent for the ProtectionEndpoint (head/tail).
35 */
36@Immutable
37@Beta
38public class ProtectionEndpointIntent extends Intent {
39
40 private final DeviceId deviceId;
41 private final ProtectedTransportEndpointDescription description;
42
Luca Prete670ac5d2017-02-03 15:55:43 -080043 /**
44 * Creates a ProtectionEndpointIntent by specific resource and description.
45 *
46 * @param appId application identification
47 * @param key intent key
48 * @param resources network resource to be set
49 * @param priority priority to use for flows from this intent
50 * @param deviceId target device id
51 * @param description protected transport endpoint description of the intent
52 * @deprecated 1.9.1
53 */
54 @Deprecated
Yuta HIGUCHIa255bb42016-11-03 16:04:08 -070055 protected ProtectionEndpointIntent(ApplicationId appId, Key key,
Luca Prete670ac5d2017-02-03 15:55:43 -080056 Collection<NetworkResource> resources,
57 int priority,
58 DeviceId deviceId,
59 ProtectedTransportEndpointDescription description) {
60 super(appId, key, resources, priority, null);
61
62 this.deviceId = checkNotNull(deviceId);
63 this.description = checkNotNull(description);
64 }
65
66 /**
67 * Creates a ProtectionEndpointIntent by specific resource and description.
68 *
69 * @param appId application identification
70 * @param key intent key
71 * @param resources network resource to be set
72 * @param priority priority to use for flows from this intent
73 * @param deviceId target device id
74 * @param description protected transport endpoint description of the intent
75 * @param resourceGroup resource group for this intent
76 */
77 protected ProtectionEndpointIntent(ApplicationId appId, Key key,
78 Collection<NetworkResource> resources,
79 int priority,
80 DeviceId deviceId,
81 ProtectedTransportEndpointDescription description,
82 ResourceGroup resourceGroup) {
83 super(appId, key, resources, priority, resourceGroup);
Yuta HIGUCHIa255bb42016-11-03 16:04:08 -070084
85 this.deviceId = checkNotNull(deviceId);
86 this.description = checkNotNull(description);
87 }
88
89 /**
90 * Returns the identifier of the device to be configured.
91 *
92 * @return the deviceId
93 */
94 public DeviceId deviceId() {
95 return deviceId;
96 }
97
98 /**
99 * Returns the description of this protection endpoint.
100 *
101 * @return the description
102 */
103 public ProtectedTransportEndpointDescription description() {
104 return description;
105 }
106
107 @Override
108 public boolean isInstallable() {
109 return true;
110 }
111
112 @Override
113 public String toString() {
114 return MoreObjects.toStringHelper(getClass())
115 .add("id", id())
116 .add("key", key())
117 .add("appId", appId())
118 .add("priority", priority())
119 .add("resources", resources())
120 .add("deviceId", deviceId)
121 .add("description", description)
122 .toString();
123 }
124
125 /**
126 * Returns a new {@link ProtectionEndpointIntent} builder.
127 *
128 * @return the builder
129 */
130 public static Builder builder() {
131 return new Builder();
132 }
133
134 /**
135 * Builder for {@link ProtectionEndpointIntent}.
136 */
137 public static class Builder extends Intent.Builder {
138
139 private DeviceId deviceId;
140 private ProtectedTransportEndpointDescription description;
141
142 /**
143 * Creates a new empty builder.
144 */
145 protected Builder() {
146 resources = ImmutableList.of();
147 }
148
149 /**
150 * Creates a new builder pre-populated with the information in the given
151 * intent.
152 *
153 * @param intent initial intent
154 */
155 protected Builder(ProtectionEndpointIntent intent) {
156 super(intent);
157 }
158
159 // TODO remove these overrides
160 @Override
161 public Builder key(Key key) {
162 super.key(key);
163 return this;
164 }
165
166 @Override
167 public Builder appId(ApplicationId appId) {
168 super.appId(appId);
169 return this;
170 }
171
172 @Override
173 public Builder resources(Collection<NetworkResource> resources) {
174 super.resources(resources);
175 return this;
176 }
177
178 @Override
179 public Builder priority(int priority) {
180 super.priority(priority);
181 return this;
182 }
183
Luca Prete670ac5d2017-02-03 15:55:43 -0800184 @Override
185 public Builder resourceGroup(ResourceGroup resourceGroup) {
186 return (Builder) super.resourceGroup(resourceGroup);
187 }
188
Yuta HIGUCHIa255bb42016-11-03 16:04:08 -0700189 public Builder deviceId(DeviceId deviceId) {
190 this.deviceId = deviceId;
191 return this;
192 }
193
194 public Builder description(ProtectedTransportEndpointDescription description) {
195 this.description = description;
196 return this;
197 }
198
199 public ProtectionEndpointIntent build() {
200 checkNotNull(key, "Key inherited from origin Intent expected.");
201 return new ProtectionEndpointIntent(appId,
202 key,
203 resources,
204 priority,
205 deviceId,
Luca Prete670ac5d2017-02-03 15:55:43 -0800206 description,
207 resourceGroup);
Yuta HIGUCHIa255bb42016-11-03 16:04:08 -0700208 }
209
210 }
211
212
213
214 /*
215 * For serialization.
216 */
217 @SuppressWarnings("unused")
218 private ProtectionEndpointIntent() {
219 this.deviceId = null;
220 this.description = null;
221 }
222}