blob: 7a230968be3117ad3d1ee24f13dee72728a6e407 [file] [log] [blame]
Yuta HIGUCHIa255bb42016-11-03 16:04:08 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Yuta HIGUCHIa255bb42016-11-03 16:04:08 -07003 *
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
Luca Prete670ac5d2017-02-03 15:55:43 -080052 * @param resourceGroup resource group for this intent
53 */
54 protected ProtectionEndpointIntent(ApplicationId appId, Key key,
55 Collection<NetworkResource> resources,
56 int priority,
57 DeviceId deviceId,
58 ProtectedTransportEndpointDescription description,
59 ResourceGroup resourceGroup) {
60 super(appId, key, resources, priority, resourceGroup);
Yuta HIGUCHIa255bb42016-11-03 16:04:08 -070061
62 this.deviceId = checkNotNull(deviceId);
63 this.description = checkNotNull(description);
64 }
65
66 /**
67 * Returns the identifier of the device to be configured.
68 *
69 * @return the deviceId
70 */
71 public DeviceId deviceId() {
72 return deviceId;
73 }
74
75 /**
76 * Returns the description of this protection endpoint.
77 *
78 * @return the description
79 */
80 public ProtectedTransportEndpointDescription description() {
81 return description;
82 }
83
84 @Override
85 public boolean isInstallable() {
86 return true;
87 }
88
89 @Override
90 public String toString() {
91 return MoreObjects.toStringHelper(getClass())
92 .add("id", id())
93 .add("key", key())
94 .add("appId", appId())
95 .add("priority", priority())
96 .add("resources", resources())
97 .add("deviceId", deviceId)
98 .add("description", description)
99 .toString();
100 }
101
102 /**
103 * Returns a new {@link ProtectionEndpointIntent} builder.
104 *
105 * @return the builder
106 */
107 public static Builder builder() {
108 return new Builder();
109 }
110
111 /**
112 * Builder for {@link ProtectionEndpointIntent}.
113 */
114 public static class Builder extends Intent.Builder {
115
116 private DeviceId deviceId;
117 private ProtectedTransportEndpointDescription description;
118
119 /**
120 * Creates a new empty builder.
121 */
122 protected Builder() {
123 resources = ImmutableList.of();
124 }
125
126 /**
127 * Creates a new builder pre-populated with the information in the given
128 * intent.
129 *
130 * @param intent initial intent
131 */
132 protected Builder(ProtectionEndpointIntent intent) {
133 super(intent);
134 }
135
136 // TODO remove these overrides
137 @Override
138 public Builder key(Key key) {
139 super.key(key);
140 return this;
141 }
142
143 @Override
144 public Builder appId(ApplicationId appId) {
145 super.appId(appId);
146 return this;
147 }
148
149 @Override
150 public Builder resources(Collection<NetworkResource> resources) {
151 super.resources(resources);
152 return this;
153 }
154
155 @Override
156 public Builder priority(int priority) {
157 super.priority(priority);
158 return this;
159 }
160
Luca Prete670ac5d2017-02-03 15:55:43 -0800161 @Override
162 public Builder resourceGroup(ResourceGroup resourceGroup) {
163 return (Builder) super.resourceGroup(resourceGroup);
164 }
165
Yuta HIGUCHIa255bb42016-11-03 16:04:08 -0700166 public Builder deviceId(DeviceId deviceId) {
167 this.deviceId = deviceId;
168 return this;
169 }
170
171 public Builder description(ProtectedTransportEndpointDescription description) {
172 this.description = description;
173 return this;
174 }
175
176 public ProtectionEndpointIntent build() {
177 checkNotNull(key, "Key inherited from origin Intent expected.");
178 return new ProtectionEndpointIntent(appId,
179 key,
180 resources,
181 priority,
182 deviceId,
Luca Prete670ac5d2017-02-03 15:55:43 -0800183 description,
184 resourceGroup);
Yuta HIGUCHIa255bb42016-11-03 16:04:08 -0700185 }
186
187 }
188
189
190
191 /*
192 * For serialization.
193 */
194 @SuppressWarnings("unused")
195 private ProtectionEndpointIntent() {
196 this.deviceId = null;
197 this.description = null;
198 }
199}