Pier Ventre | f34966c | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Pier Ventre | f34966c | 2016-11-07 16:21:04 -0800 | [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 | |
| 17 | package org.onosproject.segmentrouting.pwaas; |
| 18 | |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 19 | import java.util.List; |
| 20 | import java.util.Set; |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 21 | |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 22 | public interface L2TunnelHandler { |
| 23 | void init(); |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 24 | |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 25 | /** |
Andreas Pantelopoulos | ff691b7 | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 26 | * Combines policies and tunnels to create descriptions. |
| 27 | * |
Andreas Pantelopoulos | 811bbae | 2018-03-15 16:56:09 -0700 | [diff] [blame] | 28 | * @param pending if it is true return pending to be installed pseudowires |
| 29 | * from the appropriate store, else return installed pseudowires |
Andreas Pantelopoulos | ff691b7 | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 30 | * @return Set of l2 tunnel descriptions. |
| 31 | */ |
Andreas Pantelopoulos | 811bbae | 2018-03-15 16:56:09 -0700 | [diff] [blame] | 32 | Set<L2TunnelDescription> getL2Descriptions(boolean pending); |
Andreas Pantelopoulos | ff691b7 | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 35 | * Returns a copy of the l2 policies that exist in the store. |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 36 | * |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 37 | * @return The l2 policies |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 38 | */ |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 39 | List<L2TunnelPolicy> getL2Policies(); |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 42 | * Returns a copy of the l2 tunnels that exist in the store. |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 43 | * |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 44 | * @return The l2 tunnels. |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 45 | */ |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 46 | List<L2Tunnel> getL2Tunnels(); |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 47 | |
| 48 | /** |
Andreas Pantelopoulos | 811bbae | 2018-03-15 16:56:09 -0700 | [diff] [blame] | 49 | * Returns a copy of the pending l2 policies that exist in the store. |
| 50 | * |
| 51 | * @return The l2 policies |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 52 | */ |
Andreas Pantelopoulos | 811bbae | 2018-03-15 16:56:09 -0700 | [diff] [blame] | 53 | List<L2TunnelPolicy> getL2PendingPolicies(); |
| 54 | |
| 55 | /** |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 56 | * Helper function to handle the pw removal. |
| 57 | * <p> |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 58 | * This method should for the mastership of the device because it is |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 59 | * used only from network configuration updates, thus we only want |
| 60 | * one instance only to program each pseudowire. |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 61 | * |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 62 | * @param pwToRemove the pseudo wires to remove |
Andreas Pantelopoulos | ffe6974 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 63 | * @deprecated onos-1.12 Do not use this method. |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 64 | */ |
Andreas Pantelopoulos | ffe6974 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 65 | @Deprecated |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 66 | void tearDown(Set<L2TunnelDescription> pwToRemove); |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 67 | |
| 68 | /** |
Andreas Pantelopoulos | ffe6974 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 69 | * Returns a copy of the pending l2 tunnels that exist in the store. |
| 70 | * |
| 71 | * @return The l2 tunnels. |
| 72 | */ |
| 73 | List<L2Tunnel> getL2PendingTunnels(); |
| 74 | |
| 75 | /** |
Andreas Pantelopoulos | 935d59d | 2018-03-21 16:44:18 -0700 | [diff] [blame] | 76 | * Verifies global validity for existing pseudowires, both ones in |
| 77 | * the pending store and the ones installed. |
| 78 | * |
| 79 | * @param pwToAdd the new pseudowire to add |
| 80 | * @return a Result describing the outcome |
| 81 | */ |
| 82 | Result verifyGlobalValidity(L2TunnelDescription pwToAdd); |
| 83 | |
| 84 | /** |
| 85 | * Check if pseudowire exists in the store. |
| 86 | * |
| 87 | * @param tunnelId The tunnel id to check for. |
| 88 | * @param pending Check in pending store for pseudowires. |
| 89 | * @return The result of the operation. |
| 90 | */ |
| 91 | Result checkIfPwExists(long tunnelId, boolean pending); |
| 92 | |
| 93 | /** |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 94 | * Pwaas pipelines. |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 95 | */ |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 96 | enum Pipeline { |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 97 | /** |
| 98 | * The initiation pipeline. |
| 99 | */ |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 100 | INITIATION, /** |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 101 | * The termination pipeline. |
| 102 | */ |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 103 | TERMINATION |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /** |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 107 | * Enum helper to carry results of various operations. |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 108 | */ |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 109 | enum Result { |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 110 | /** |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 111 | * Happy ending scenario. |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 112 | */ |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 113 | SUCCESS(0, "No error occurred"), |
| 114 | |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 115 | /** |
| 116 | * We have problems with the supplied parameters. |
| 117 | */ |
| 118 | WRONG_PARAMETERS(1, "Wrong parameters"), |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 119 | |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 120 | /** |
| 121 | * We have an internal error during the deployment |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 122 | * or removal phase. |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 123 | */ |
| 124 | INTERNAL_ERROR(3, "Internal error"), |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 125 | |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 126 | /** |
Andreas Pantelopoulos | 935d59d | 2018-03-21 16:44:18 -0700 | [diff] [blame] | 127 | * No path found between the connection points. |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 128 | */ |
Andreas Pantelopoulos | ffe6974 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 129 | PATH_NOT_FOUND(7, "Could not find valid path between connection points!"), |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 130 | |
| 131 | /** |
Andreas Pantelopoulos | 935d59d | 2018-03-21 16:44:18 -0700 | [diff] [blame] | 132 | * Error in global pseudowires configuration. |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 133 | */ |
Andreas Pantelopoulos | ffe6974 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 134 | CONFIGURATION_ERROR(8, "Conflicting pseudowire configurations!"); |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 135 | |
| 136 | private final int code; |
| 137 | private final String description; |
Andreas Pantelopoulos | ffe6974 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 138 | |
| 139 | private String specificError; |
Andreas Pantelopoulos | daf02c8 | 2018-04-04 11:16:56 -0700 | [diff] [blame] | 140 | private int nextId; |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 141 | |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 142 | Result(int code, String description) { |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 143 | this.code = code; |
| 144 | this.description = description; |
| 145 | } |
| 146 | |
Andreas Pantelopoulos | ffe6974 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 147 | public Result appendError(String error) { |
| 148 | this.specificError = error; |
| 149 | return this; |
| 150 | } |
| 151 | |
| 152 | public String getSpecificError() { |
| 153 | return specificError; |
| 154 | } |
| 155 | |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 156 | public String getDescription() { |
| 157 | return description; |
| 158 | } |
| 159 | |
Andreas Pantelopoulos | daf02c8 | 2018-04-04 11:16:56 -0700 | [diff] [blame] | 160 | public int getNextId() { |
| 161 | return nextId; |
| 162 | } |
| 163 | |
Ray Milkey | 6fc64c1 | 2018-04-12 09:35:33 -0700 | [diff] [blame] | 164 | protected void setNextId(int nextId) { |
Andreas Pantelopoulos | daf02c8 | 2018-04-04 11:16:56 -0700 | [diff] [blame] | 165 | this.nextId = nextId; |
| 166 | } |
| 167 | |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 168 | @Override |
| 169 | public String toString() { |
| 170 | return code + ": " + description; |
| 171 | } |
| 172 | } |
| 173 | |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 174 | /** |
| 175 | * Enum helper for handling the direction of the pw. |
| 176 | */ |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 177 | enum Direction { |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 178 | /** |
| 179 | * The forward direction of the pseudo wire. |
| 180 | */ |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 181 | FWD, /** |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 182 | * The reverse direction of the pseudo wire. |
| 183 | */ |
Jon Hall | 8c7b06a | 2017-02-22 13:37:33 -0800 | [diff] [blame] | 184 | REV |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 185 | } |
Pier Ventre | f34966c | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 186 | } |