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 org.onosproject.net.Link; |
Pier Ventre | f34966c | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 20 | import org.onosproject.net.config.NetworkConfigEvent; |
Pier Ventre | f34966c | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 21 | |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 22 | import java.util.List; |
| 23 | import java.util.Set; |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 24 | |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 25 | public interface L2TunnelHandler { |
| 26 | void init(); |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 27 | |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 28 | /** |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 29 | * Returns a copy of the l2 policies that exist in the store. |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 30 | * |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 31 | * @return The l2 policies |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 32 | */ |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 33 | List<L2TunnelPolicy> getL2Policies(); |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 36 | * Returns a copy of the l2 tunnels that exist in the store. |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 37 | * |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 38 | * @return The l2 tunnels. |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 39 | */ |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 40 | List<L2Tunnel> getL2Tunnels(); |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Processes a link removal. Finds affected pseudowires and rewires them. |
| 44 | * TODO: Make it also take into account failures of links that are used for pw |
| 45 | * traffic in the spine. |
| 46 | * @param link The link that failed |
| 47 | */ |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 48 | void processLinkDown(Link link); |
Pier Ventre | f34966c | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * Processes Pwaas Config added event. |
| 52 | * |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 53 | * @param event network config add event |
Pier Ventre | f34966c | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 54 | */ |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 55 | void processPwaasConfigAdded(NetworkConfigEvent event); |
Pier Ventre | f34966c | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 56 | |
| 57 | /** |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 58 | * Processes PWaaS Config updated event. |
Pier Ventre | f34966c | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 59 | * |
| 60 | * @param event network config updated event |
| 61 | */ |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 62 | void processPwaasConfigUpdated(NetworkConfigEvent event); |
Pier Ventre | f34966c | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 63 | |
| 64 | /** |
| 65 | * Processes Pwaas Config removed event. |
| 66 | * |
| 67 | * @param event network config removed event |
| 68 | */ |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 69 | void processPwaasConfigRemoved(NetworkConfigEvent event); |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 70 | |
| 71 | /** |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 72 | * Helper function to handle the pw removal. |
| 73 | * <p> |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 74 | * This method should for the mastership of the device because it is |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 75 | * used only from network configuration updates, thus we only want |
| 76 | * one instance only to program each pseudowire. |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 77 | * |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 78 | * @param pwToRemove the pseudo wires to remove |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 79 | */ |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 80 | void tearDown(Set<L2TunnelDescription> pwToRemove); |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 81 | |
| 82 | /** |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 83 | * Pwaas pipelines. |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 84 | */ |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 85 | enum Pipeline { |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 86 | /** |
| 87 | * The initiation pipeline. |
| 88 | */ |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 89 | INITIATION, /** |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 90 | * The termination pipeline. |
| 91 | */ |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 92 | TERMINATION |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /** |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 96 | * Enum helper to carry results of various operations. |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 97 | */ |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 98 | enum Result { |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 99 | /** |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 100 | * Happy ending scenario. |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 101 | */ |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 102 | SUCCESS(0, "No error occurred"), |
| 103 | |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 104 | /** |
| 105 | * We have problems with the supplied parameters. |
| 106 | */ |
| 107 | WRONG_PARAMETERS(1, "Wrong parameters"), |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 108 | |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 109 | /** |
| 110 | * We have an internal error during the deployment |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 111 | * or removal phase. |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 112 | */ |
| 113 | INTERNAL_ERROR(3, "Internal error"), |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 114 | |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 115 | /** |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 116 | * |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 117 | */ |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 118 | REMOVAL_ERROR(5, "Can not remove pseudowire from network configuration"), |
| 119 | |
| 120 | /** |
| 121 | * |
| 122 | */ |
| 123 | ADDITION_ERROR(6, "Can not add pseudowire in network configuration"), |
| 124 | |
| 125 | /** |
| 126 | * |
| 127 | */ |
| 128 | CONFIG_NOT_FOUND(7, "Can not find configuration class for pseudowires"); |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 129 | |
| 130 | private final int code; |
| 131 | private final String description; |
Ray Milkey | 067c44b | 2018-02-26 12:48:23 -0800 | [diff] [blame] | 132 | protected int nextId; |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 133 | |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 134 | Result(int code, String description) { |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 135 | this.code = code; |
| 136 | this.description = description; |
| 137 | } |
| 138 | |
| 139 | public String getDescription() { |
| 140 | return description; |
| 141 | } |
| 142 | |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 143 | @Override |
| 144 | public String toString() { |
| 145 | return code + ": " + description; |
| 146 | } |
| 147 | } |
| 148 | |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 149 | /** |
| 150 | * Enum helper for handling the direction of the pw. |
| 151 | */ |
Andreas Pantelopoulos | b21547d | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 152 | enum Direction { |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 153 | /** |
| 154 | * The forward direction of the pseudo wire. |
| 155 | */ |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 156 | FWD, /** |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 157 | * The reverse direction of the pseudo wire. |
| 158 | */ |
Jon Hall | 8c7b06a | 2017-02-22 13:37:33 -0800 | [diff] [blame] | 159 | REV |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 160 | } |
Pier Ventre | f34966c | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 161 | } |