Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021-present Open Networking Foundation |
| 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.kubevirtnetworking.api; |
| 17 | |
Daniel Park | 5a3e939 | 2021-03-23 08:00:00 +0900 | [diff] [blame] | 18 | import org.onlab.packet.MacAddress; |
Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 19 | import org.onosproject.event.AbstractEvent; |
| 20 | |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 21 | import java.util.Set; |
| 22 | |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 23 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 24 | |
Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 25 | /** |
| 26 | * Kubevirt router event class. |
| 27 | */ |
| 28 | public class KubevirtRouterEvent extends AbstractEvent<KubevirtRouterEvent.Type, KubevirtRouter> { |
| 29 | |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 30 | private final KubevirtFloatingIp floatingIp; |
| 31 | private final String podName; |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 32 | private final Set<String> internal; |
| 33 | private final String externalIp; |
| 34 | private final String externalNet; |
| 35 | private final String peerRouterIp; |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame] | 36 | private final String gateway; |
Daniel Park | 5a3e939 | 2021-03-23 08:00:00 +0900 | [diff] [blame] | 37 | private final MacAddress peerRouterMac; |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 38 | |
Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 39 | /** |
| 40 | * Creates an event of a given type for the specified kubevirt router. |
| 41 | * |
| 42 | * @param type kubevirt router event type |
| 43 | * @param subject kubevirt router |
| 44 | */ |
Jian Li | 810f58c | 2021-02-27 01:10:50 +0900 | [diff] [blame] | 45 | public KubevirtRouterEvent(Type type, KubevirtRouter subject) { |
Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 46 | super(type, subject); |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 47 | this.floatingIp = null; |
| 48 | this.podName = null; |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 49 | this.internal = null; |
| 50 | this.externalIp = null; |
| 51 | this.externalNet = null; |
| 52 | this.peerRouterIp = null; |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame] | 53 | this.gateway = null; |
Daniel Park | 5a3e939 | 2021-03-23 08:00:00 +0900 | [diff] [blame] | 54 | this.peerRouterMac = null; |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Creates an event of a given type for the specified kubevirt router. |
| 59 | * |
| 60 | * @param type kubevirt router event type |
| 61 | * @param subject kubevirt router |
| 62 | * @param floatingIp kubevirt floating IP |
| 63 | */ |
| 64 | public KubevirtRouterEvent(Type type, KubevirtRouter subject, KubevirtFloatingIp floatingIp) { |
| 65 | super(type, subject); |
| 66 | this.floatingIp = floatingIp; |
| 67 | this.podName = null; |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 68 | this.internal = null; |
| 69 | this.externalIp = null; |
| 70 | this.externalNet = null; |
| 71 | this.peerRouterIp = null; |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame] | 72 | this.gateway = null; |
Daniel Park | 5a3e939 | 2021-03-23 08:00:00 +0900 | [diff] [blame] | 73 | this.peerRouterMac = null; |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Creates an event of a given type for the specified kubevirt router. |
| 78 | * |
| 79 | * @param type kubevirt router event type |
| 80 | * @param subject kubevirt router |
| 81 | * @param floatingIp kubevirt floating IP |
| 82 | * @param podName kubevirt POD name |
| 83 | */ |
| 84 | public KubevirtRouterEvent(Type type, KubevirtRouter subject, KubevirtFloatingIp floatingIp, String podName) { |
| 85 | super(type, subject); |
| 86 | this.floatingIp = floatingIp; |
| 87 | this.podName = podName; |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 88 | this.internal = null; |
| 89 | this.externalIp = null; |
| 90 | this.externalNet = null; |
| 91 | this.peerRouterIp = null; |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame] | 92 | this.gateway = null; |
Daniel Park | 5a3e939 | 2021-03-23 08:00:00 +0900 | [diff] [blame] | 93 | this.peerRouterMac = null; |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Creates an event of a given type for the specified kubevirt router. |
| 98 | * |
| 99 | * @param type kubevirt router event type |
| 100 | * @param subject kubevirt router |
| 101 | * @param internal internal networks attached to the router |
| 102 | */ |
| 103 | public KubevirtRouterEvent(Type type, KubevirtRouter subject, Set<String> internal) { |
| 104 | super(type, subject); |
| 105 | this.internal = internal; |
| 106 | this.podName = null; |
| 107 | this.floatingIp = null; |
| 108 | this.externalIp = null; |
| 109 | this.externalNet = null; |
| 110 | this.peerRouterIp = null; |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame] | 111 | this.gateway = null; |
Daniel Park | 5a3e939 | 2021-03-23 08:00:00 +0900 | [diff] [blame] | 112 | this.peerRouterMac = null; |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Creates an event of a given type for the specified kubevirt router. |
| 117 | * |
| 118 | * @param type kubevirt router event type |
| 119 | * @param subject kubevirt router |
| 120 | * @param externalIp virtual router's IP address included in external network |
| 121 | * @param externalNet external network name |
| 122 | * @param peerRouterIp external peer router IP address |
Daniel Park | 5a3e939 | 2021-03-23 08:00:00 +0900 | [diff] [blame] | 123 | * @param peerRouterMac external peer router MAC address |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 124 | */ |
| 125 | public KubevirtRouterEvent(Type type, KubevirtRouter subject, |
| 126 | String externalIp, String externalNet, |
Daniel Park | 5a3e939 | 2021-03-23 08:00:00 +0900 | [diff] [blame] | 127 | String peerRouterIp, MacAddress peerRouterMac) { |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 128 | super(type, subject); |
| 129 | this.internal = null; |
| 130 | this.podName = null; |
| 131 | this.floatingIp = null; |
| 132 | this.externalIp = externalIp; |
| 133 | this.externalNet = externalNet; |
| 134 | this.peerRouterIp = peerRouterIp; |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame] | 135 | this.gateway = null; |
Daniel Park | 5a3e939 | 2021-03-23 08:00:00 +0900 | [diff] [blame] | 136 | this.peerRouterMac = peerRouterMac; |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | public KubevirtRouterEvent(Type type, KubevirtRouter subject, |
| 140 | String gateway) { |
| 141 | super(type, subject); |
| 142 | this.gateway = gateway; |
| 143 | this.floatingIp = null; |
| 144 | this.podName = null; |
| 145 | this.internal = null; |
| 146 | this.externalIp = null; |
| 147 | this.externalNet = null; |
| 148 | this.peerRouterIp = null; |
Daniel Park | 5a3e939 | 2021-03-23 08:00:00 +0900 | [diff] [blame] | 149 | this.peerRouterMac = null; |
Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | public enum Type { |
| 153 | /** |
| 154 | * Signifies that a new kubevirt router is created. |
| 155 | */ |
| 156 | KUBEVIRT_ROUTER_CREATED, |
| 157 | |
| 158 | /** |
| 159 | * Signifies that the kubevirt router is updated. |
| 160 | */ |
| 161 | KUBEVIRT_ROUTER_UPDATED, |
| 162 | |
| 163 | /** |
| 164 | * Signifies that the kubevirt router is removed. |
| 165 | */ |
| 166 | KUBEVIRT_ROUTER_REMOVED, |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 167 | |
| 168 | /** |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 169 | * Signifies that a new external network is added to the router. |
| 170 | */ |
| 171 | KUBEVIRT_ROUTER_EXTERNAL_NETWORK_ATTACHED, |
| 172 | |
| 173 | /** |
| 174 | * Signifies that the existing external network is removed from the router. |
| 175 | */ |
| 176 | KUBEVIRT_ROUTER_EXTERNAL_NETWORK_DETACHED, |
| 177 | |
| 178 | /** |
| 179 | * Signifies that a new internal network is added to the router. |
| 180 | */ |
| 181 | KUBEVIRT_ROUTER_INTERNAL_NETWORKS_ATTACHED, |
| 182 | |
| 183 | /** |
| 184 | * Signifies that the existing internal network is removed from the router. |
| 185 | */ |
| 186 | KUBEVIRT_ROUTER_INTERNAL_NETWORKS_DETACHED, |
| 187 | |
| 188 | /** |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 189 | * Signifies that a new kubevirt floating IP is created. |
| 190 | */ |
| 191 | KUBEVIRT_FLOATING_IP_CREATED, |
| 192 | |
| 193 | /** |
| 194 | * Signifies that the kubevirt floating IP is updated. |
| 195 | */ |
| 196 | KUBEVIRT_FLOATING_IP_UPDATED, |
| 197 | |
| 198 | /** |
| 199 | * Signifies that the kubevirt floating IP is removed. |
| 200 | */ |
| 201 | KUBEVIRT_FLOATING_IP_REMOVED, |
| 202 | |
| 203 | /** |
| 204 | * Signifies that the floating IP is associated to a fixed IP. |
| 205 | */ |
| 206 | KUBEVIRT_FLOATING_IP_ASSOCIATED, |
| 207 | |
| 208 | /** |
| 209 | * Signifies that the floating IP disassociated from the fixed IP. |
| 210 | */ |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame] | 211 | KUBEVIRT_FLOATING_IP_DISASSOCIATED, |
| 212 | |
| 213 | /** |
| 214 | * Signified that the gateway node associated for this router. |
| 215 | */ |
| 216 | KUBEVIRT_GATEWAY_NODE_ATTACHED, |
| 217 | /** |
| 218 | * Signified that the gateway node disassociated for this router. |
| 219 | */ |
| 220 | KUBEVIRT_GATEWAY_NODE_DETACHED, |
| 221 | /** |
| 222 | * Signified that the gateway node changed for this router. |
| 223 | */ |
Daniel Park | 8ad7c3b | 2021-04-09 15:45:59 +0900 | [diff] [blame] | 224 | KUBEVIRT_GATEWAY_NODE_CHANGED, |
| 225 | /** |
| 226 | * Signified that the snat status disabled for this router. |
| 227 | */ |
Daniel Park | 05a9458 | 2021-05-12 10:57:02 +0900 | [diff] [blame] | 228 | KUBEVIRT_SNAT_STATUS_DISABLED, |
| 229 | /** |
| 230 | * Signifies that the floating IP is associated to a lb VIP. |
| 231 | */ |
| 232 | KUBEVIRT_FLOATING_IP_LB_ASSOCIATED, |
| 233 | /** |
| 234 | * Signifies that the floating IP is disassociated to a lb VIP. |
| 235 | */ |
| 236 | KUBEVIRT_FLOATING_IP_LB_DISASSOCIATED, |
| 237 | /** |
| 238 | * Signifies the that peer router mac address is retrieved for this router. |
| 239 | */ |
| 240 | KUBEVIRT_PEER_ROUTER_MAC_RETRIEVED, |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Returns the floating IP of the router event. |
| 245 | * |
| 246 | * @return kubevirt floating IP; null if the event is not relevant to the floating IP |
| 247 | */ |
| 248 | public KubevirtFloatingIp floatingIp() { |
| 249 | return floatingIp; |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * Returns the pod name of the router event. |
| 254 | * |
| 255 | * @return kubevirt pod name; null if the event is not relevant to the pod name |
| 256 | */ |
| 257 | public String podName() { |
| 258 | return podName; |
| 259 | } |
| 260 | |
Jian Li | da7ec15 | 2021-03-05 12:21:50 +0900 | [diff] [blame] | 261 | /** |
| 262 | * Returns the internal of the router event. |
| 263 | * |
| 264 | * @return kubevirt internal network set, null if the event is not relevant to the internal |
| 265 | */ |
| 266 | public Set<String> internal() { |
| 267 | return internal; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Returns the external IP address of the router event. |
| 272 | * |
| 273 | * @return external IP address, null if the event is not relevant to the external |
| 274 | */ |
| 275 | public String externalIp() { |
| 276 | return externalIp; |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * Returns the external network of the router event. |
| 281 | * |
| 282 | * @return external network, null if the event is not relevant ot the external |
| 283 | */ |
| 284 | public String externalNet() { |
| 285 | return externalNet; |
| 286 | } |
| 287 | |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame] | 288 | /** |
| 289 | * Returns the gateway of the router event. |
| 290 | * |
| 291 | * @return gateway if exists, null otherwise |
| 292 | */ |
| 293 | public String gateway() { |
| 294 | return gateway; |
| 295 | } |
| 296 | |
Daniel Park | 5a3e939 | 2021-03-23 08:00:00 +0900 | [diff] [blame] | 297 | /** |
| 298 | * Returns the external peer router IP address. |
| 299 | * |
| 300 | * @return external peer router IP if exists, null otherwise |
| 301 | */ |
| 302 | public String externalPeerRouterIp() { |
| 303 | return peerRouterIp; |
| 304 | } |
| 305 | /** |
| 306 | * Returns the external peer router MAC address. |
| 307 | * |
| 308 | * @return external peer router MAC if exists, null otherwise |
| 309 | */ |
| 310 | public MacAddress peerRouterMac() { |
| 311 | return peerRouterMac; |
| 312 | } |
| 313 | |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 314 | @Override |
| 315 | public String toString() { |
| 316 | if (floatingIp == null) { |
| 317 | return super.toString(); |
| 318 | } |
| 319 | return toStringHelper(this) |
| 320 | .add("type", type()) |
| 321 | .add("router", subject()) |
| 322 | .add("floatingIp", floatingIp) |
| 323 | .add("podName", podName) |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 324 | .add("internal", internal) |
| 325 | .add("externalIp", externalIp) |
| 326 | .add("externalNet", externalNet) |
| 327 | .add("peerRouterIp", peerRouterIp) |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame] | 328 | .add("gatewayNodeHostName", gateway) |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 329 | .toString(); |
Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 330 | } |
| 331 | } |