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