blob: a2261ed55924b245ae713b44693631705424715a [file] [log] [blame]
Yuta HIGUCHI4d0f89a2016-09-14 15:40:39 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Yuta HIGUCHI4d0f89a2016-09-14 15:40:39 -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.behaviour.protection;
17
18import java.util.Map;
19import java.util.Set;
20import java.util.concurrent.CompletableFuture;
21
22import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.driver.HandlerBehaviour;
24
25import com.google.common.annotations.Beta;
26
27
28/**
29 * Behaviour for configuring Device triggered protection mechanism.
30 * <p>
31 * <b>Protected transport entity model</b><br>
32 * <pre>
33 * {@literal
34 * - ProtectedTransportEndpoint
35 * +- TransportEndpoint - working transport entity/path
36 * |
37 * +- TransportEndpoint - standby transport entity/path
38 * ⋮
39 * }
40 * </pre>
41 * ProtectedTransportEndpoint is the entity representing the transport entity endpoint.
42 * Traffic flowing into the protected transport endpoint will flow
43 * through one of it's underlying TransportEndpoint, (=active transport entity).
44 *
45 * After successful creation of ProtectedPathEndpoint, implementation is expected
46 * to advertise virtual Port corresponding to the ProtectedPathEndpoint created.
47 */
48@Beta
49public interface ProtectionConfigBehaviour extends HandlerBehaviour {
50
51 /**
52 * Annotation key for virtual Port.
53 */
54 static String FINGERPRINT = "protection:fingerprint";
55
56 // Implementation is expected to
57 // - Create logical entity representing protection group
58 // - Expose (virtual) Port via Device Subsystem
59 // - implementation of FlowRuleProvider and similar should translate
60 // request forwarding from/to virtual port to corresponding configuration
61 // stitching protection group.
62 /**
63 * Creates protected path endpoint.
64 *
65 * @param configuration {@link ProtectedTransportEndpointDescription}
66 * @return {@link ConnectPoint} for the virtual Port added on success,
67 * or exceptionally return {@link ProtectionException} as cause on error.
68 */
69 CompletableFuture<ConnectPoint>
70 createProtectionEndpoint(ProtectedTransportEndpointDescription configuration);
71
72 /**
73 * Updates protected path endpoint configuration.
74 *
75 * @param identifier {@link ConnectPoint} for the virtual Port representing
76 * protected path endpoint
77 * @param configuration {@link ProtectedTransportEndpointDescription}
78 * @return {@code identifier} on success,
79 * or exceptionally return {@link ProtectionException} as cause on error.
80 */
81 CompletableFuture<ConnectPoint>
82 updateProtectionEndpoint(ConnectPoint identifier,
83 ProtectedTransportEndpointDescription configuration);
84
85 /**
86 * Deletes protected path endpoint.
87 *
88 * @param identifier {@link ConnectPoint} for the virtual Port representing
89 * protected path endpoint
90 * @return true if successfully removed, false otherwise.
91 */
92 // TODO Should we return Boolean or instead return Void and fail exceptionally?
93 CompletableFuture<Boolean>
94 deleteProtectionEndpoint(ConnectPoint identifier);
95
96 /**
97 * Retrieves {@link ProtectedTransportEndpointDescription}s on the Device.
98 *
99 * @return {@link ProtectedTransportEndpointDescription}s on the Device
100 */
101 CompletableFuture<Map<ConnectPoint, ProtectedTransportEndpointDescription>>
102 getProtectionEndpointConfigs();
103
104 /**
105 * Retrieves {@link ProtectedTransportEndpointDescription} with specified ID.
106 *
107 * @param identifier {@link ConnectPoint} for the virtual Port representing
108 * protected path endpoint to retrieve
109 * @return {@link ProtectedTransportEndpointDescription} found or null
110 */
111 default CompletableFuture<ProtectedTransportEndpointDescription>
112 getProtectionEndpointConfig(ConnectPoint identifier) {
113 return getProtectionEndpointConfigs().thenApply(m -> m.get(identifier));
114 }
115
116 /**
117 * Retrieves {@link ProtectedTransportEndpointState}s on the Device.
118 *
119 * @return {@link ProtectedTransportEndpointState}s on the Device
120 */
121 CompletableFuture<Map<ConnectPoint, ProtectedTransportEndpointState>>
122 getProtectionEndpointStates();
123
124 /**
125 * Retrieves {@link ProtectedTransportEndpointState} on the Device.
126 *
127 * @param identifier {@link ConnectPoint} for the virtual Port representing
128 * protected path endpoint to retrieve
129 * @return {@link ProtectedTransportEndpointState} found or null
130 */
131 default CompletableFuture<ProtectedTransportEndpointState>
132 getProtectionEndpointState(ConnectPoint identifier) {
133 return getProtectionEndpointStates().thenApply(m -> m.get(identifier));
134 }
135
136 /**
137 * Retrieves ProtectedTansportEndpoint information
138 * (=virtual Port {@link ConnectPoint} and {@link ProtectedTransportEndpointState} pair)
139 * on the Device.
140 *
141 * @param fingerprint of the protected path endpoint to retrieve
142 * @return ProtectedTansportEndpoint information found or null
143 */
144 default CompletableFuture<Map.Entry<ConnectPoint, ProtectedTransportEndpointState>>
145 getProtectionEndpoint(String fingerprint) {
146 return getProtectionEndpointStates()
147 .thenApply(Map::entrySet)
148 .thenApply(Set::stream)
149 .thenApply(s ->
150 s.filter(e -> fingerprint.equals(e.getValue().description().fingerprint()))
151 .findFirst().orElse(null)
152 );
153 }
154
155 /**
156 * Attempts to manually switch working path to the one specified by {@code index}.
157 *
158 * @param identifier {@link ConnectPoint} for the virtual Port representing
159 * protected path endpoint
160 * @param index working path index to switch to
161 * @return Completes if request was accepted, fails exceptionally on error.
162 * Note: completion does not always assure working path has switched.
163 */
MaoLubbf6e8b2017-05-04 15:44:45 -0700164 @Deprecated
Yuta HIGUCHI4d0f89a2016-09-14 15:40:39 -0700165 CompletableFuture<Void> switchWorkingPath(ConnectPoint identifier, int index);
166
MaoLubbf6e8b2017-05-04 15:44:45 -0700167 /**
168 * Attempts to forcibly switch to the one specified path by {@code index}.
169 *
170 * @param identifier {@link ConnectPoint} for the virtual Port representing
171 * protected path endpoint
172 * @param index path index to switch to
173 * @return Completes if request was accepted, fails exceptionally on error.
174 * Note: completion does not always assure working path has switched.
175 */
176 default CompletableFuture<Void> switchToForce(ConnectPoint identifier, int index) {
177 return CompletableFuture.completedFuture(null);
178 }
179
180 /**
181 * Attempts to manually switch to the one specified path by {@code index}.
182 * This operation would be rejected if the specified path is a fault path.
183 *
184 * @param identifier {@link ConnectPoint} for the virtual Port representing
185 * protected path endpoint
186 * @param index path index to switch to
187 * @return Completes if request was accepted, fails exceptionally on error.
188 * Note: completion does not always assure working path has switched.
189 */
190 default CompletableFuture<Void> switchToManual(ConnectPoint identifier, int index) {
191 return switchWorkingPath(identifier, index);
192 }
193
194 /**
195 * Attempts to set the device to automatic protection mode.
196 *
197 * @param identifier {@link ConnectPoint} for the virtual Port representing
198 * protected path endpoint
199 * @return Completes if request was accepted, fails exceptionally on error.
200 */
201 default CompletableFuture<Void> switchToAutomatic(ConnectPoint identifier) {
202 CompletableFuture<Void> future = new CompletableFuture<>();
203 future.completeExceptionally(new UnsupportedOperationException());
204 return future;
205 }
206
Yuta HIGUCHI4d0f89a2016-09-14 15:40:39 -0700207 // TODO How to let one listen to async events? e.g., working path changed event
208}