Yuta HIGUCHI | 4d0f89a | 2016-09-14 15:40:39 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Yuta HIGUCHI | 4d0f89a | 2016-09-14 15:40:39 -0700 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.net.behaviour.protection; |
| 17 | |
| 18 | import java.util.Map; |
| 19 | import java.util.Set; |
| 20 | import java.util.concurrent.CompletableFuture; |
| 21 | |
| 22 | import org.onosproject.net.ConnectPoint; |
| 23 | import org.onosproject.net.driver.HandlerBehaviour; |
| 24 | |
| 25 | import 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 |
| 49 | public 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 | /** |
MaoLu | bbf6e8b | 2017-05-04 15:44:45 -0700 | [diff] [blame] | 156 | * Attempts to forcibly switch to the one specified path by {@code index}. |
| 157 | * |
| 158 | * @param identifier {@link ConnectPoint} for the virtual Port representing |
| 159 | * protected path endpoint |
| 160 | * @param index 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 | */ |
| 164 | default CompletableFuture<Void> switchToForce(ConnectPoint identifier, int index) { |
| 165 | return CompletableFuture.completedFuture(null); |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Attempts to manually switch to the one specified path by {@code index}. |
| 170 | * This operation would be rejected if the specified path is a fault path. |
| 171 | * |
| 172 | * @param identifier {@link ConnectPoint} for the virtual Port representing |
| 173 | * protected path endpoint |
| 174 | * @param index path index to switch to |
| 175 | * @return Completes if request was accepted, fails exceptionally on error. |
| 176 | * Note: completion does not always assure working path has switched. |
| 177 | */ |
Ray Milkey | 4f7e363 | 2019-02-19 15:35:20 -0800 | [diff] [blame] | 178 | CompletableFuture<Void> switchToManual(ConnectPoint identifier, int index); |
MaoLu | bbf6e8b | 2017-05-04 15:44:45 -0700 | [diff] [blame] | 179 | |
| 180 | /** |
| 181 | * Attempts to set the device to automatic protection mode. |
| 182 | * |
| 183 | * @param identifier {@link ConnectPoint} for the virtual Port representing |
| 184 | * protected path endpoint |
| 185 | * @return Completes if request was accepted, fails exceptionally on error. |
| 186 | */ |
| 187 | default CompletableFuture<Void> switchToAutomatic(ConnectPoint identifier) { |
| 188 | CompletableFuture<Void> future = new CompletableFuture<>(); |
| 189 | future.completeExceptionally(new UnsupportedOperationException()); |
| 190 | return future; |
| 191 | } |
| 192 | |
Yuta HIGUCHI | 4d0f89a | 2016-09-14 15:40:39 -0700 | [diff] [blame] | 193 | // TODO How to let one listen to async events? e.g., working path changed event |
| 194 | } |