Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [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.openstacknetworking.api; |
| 17 | |
Yuta HIGUCHI | 0c47d53 | 2017-08-18 23:16:35 -0700 | [diff] [blame] | 18 | import org.onlab.util.Tools; |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 19 | import org.onosproject.event.AbstractEvent; |
| 20 | import org.openstack4j.model.network.ExternalGateway; |
| 21 | import org.openstack4j.model.network.NetFloatingIP; |
| 22 | import org.openstack4j.model.network.Router; |
| 23 | import org.openstack4j.model.network.RouterInterface; |
| 24 | |
| 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 26 | |
| 27 | /** |
| 28 | * Describes OpenStack router service events. |
| 29 | */ |
Jian Li | 5ecfd1a | 2018-12-10 11:41:03 +0900 | [diff] [blame] | 30 | public class OpenstackRouterEvent |
| 31 | extends AbstractEvent<OpenstackRouterEvent.Type, Router> { |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 32 | |
| 33 | private final ExternalGateway exGateway; |
| 34 | private final RouterInterface routerIface; |
| 35 | private final NetFloatingIP floatingIP; |
| 36 | private final String portId; |
| 37 | |
| 38 | public enum Type { |
| 39 | |
| 40 | /** |
| 41 | * Signifies that a new OpenStack router is created. |
| 42 | */ |
| 43 | OPENSTACK_ROUTER_CREATED, |
| 44 | |
| 45 | /** |
| 46 | * Signifies that the OpenStack router is updated. |
| 47 | */ |
| 48 | OPENSTACK_ROUTER_UPDATED, |
| 49 | |
| 50 | /** |
| 51 | * Signifies that the OpenStack router is removed. |
| 52 | */ |
| 53 | OPENSTACK_ROUTER_REMOVED, |
| 54 | |
| 55 | /** |
| 56 | * Signifies that the external gateway is added to the router. |
| 57 | */ |
| 58 | OPENSTACK_ROUTER_GATEWAY_ADDED, |
| 59 | |
| 60 | /** |
| 61 | * Signifies that the external gateway is removed from the router. |
| 62 | */ |
| 63 | OPENSTACK_ROUTER_GATEWAY_REMOVED, |
| 64 | |
| 65 | /** |
| 66 | * Signifies that the OpenStack router interface is added. |
| 67 | */ |
| 68 | OPENSTACK_ROUTER_INTERFACE_ADDED, |
| 69 | |
| 70 | /** |
| 71 | * Signifies that the OpenStack router interface is updated. |
| 72 | */ |
| 73 | OPENSTACK_ROUTER_INTERFACE_UPDATED, |
| 74 | |
| 75 | /** |
| 76 | * Signifies that the OpenStack router interface is removed. |
| 77 | */ |
| 78 | OPENSTACK_ROUTER_INTERFACE_REMOVED, |
| 79 | |
| 80 | /** |
| 81 | * Signifies that a new floating IP is created. |
| 82 | */ |
| 83 | OPENSTACK_FLOATING_IP_CREATED, |
| 84 | |
| 85 | /** |
| 86 | * Signifies that the floating IP is updated. |
| 87 | */ |
| 88 | OPENSTACK_FLOATING_IP_UPDATED, |
| 89 | |
| 90 | /** |
| 91 | * Signifies that the floating IP is removed. |
| 92 | */ |
| 93 | OPENSTACK_FLOATING_IP_REMOVED, |
| 94 | |
| 95 | /** |
| 96 | * Signifies that the floating IP is associated to a fixed IP. |
| 97 | */ |
| 98 | OPENSTACK_FLOATING_IP_ASSOCIATED, |
| 99 | |
| 100 | /** |
| 101 | * Signifies that the floating IP disassociated from the fixed IP. |
| 102 | */ |
| 103 | OPENSTACK_FLOATING_IP_DISASSOCIATED |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Creates an event of a given type for the specified router and the current time. |
| 108 | * |
| 109 | * @param type openstack router event type |
| 110 | * @param osRouter openstack router |
| 111 | */ |
| 112 | public OpenstackRouterEvent(Type type, Router osRouter) { |
| 113 | super(type, osRouter); |
| 114 | this.exGateway = null; |
| 115 | this.routerIface = null; |
| 116 | this.floatingIP = null; |
| 117 | this.portId = null; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Creates an event of a given type for the specified router, external gateway and |
| 122 | * the current time. |
| 123 | * |
| 124 | * @param type openstack router event type |
| 125 | * @param osRouter openstack router |
| 126 | * @param exGateway openstack router external gateway |
| 127 | */ |
| 128 | public OpenstackRouterEvent(Type type, Router osRouter, ExternalGateway exGateway) { |
| 129 | super(type, osRouter); |
| 130 | this.exGateway = exGateway; |
| 131 | this.routerIface = null; |
| 132 | this.floatingIP = null; |
| 133 | this.portId = null; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Creates an event of a given type for the specified router, floating IP and |
| 138 | * the current time. |
| 139 | * |
| 140 | * @param type openstack router event type |
| 141 | * @param osRouter openstack router |
| 142 | * @param osRouterIface openstack router interface |
| 143 | */ |
| 144 | public OpenstackRouterEvent(Type type, Router osRouter, RouterInterface osRouterIface) { |
| 145 | super(type, osRouter); |
| 146 | this.exGateway = null; |
| 147 | this.routerIface = osRouterIface; |
| 148 | this.floatingIP = null; |
| 149 | this.portId = null; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Creates an event of a given type for the specified router, floating IP and |
| 154 | * the current time. |
| 155 | * |
| 156 | * @param type openstack router event type |
| 157 | * @param router openstack router |
| 158 | * @param floatingIP openstack floating ip |
| 159 | */ |
| 160 | public OpenstackRouterEvent(Type type, Router router, NetFloatingIP floatingIP) { |
| 161 | super(type, router); |
| 162 | this.exGateway = null; |
| 163 | this.routerIface = null; |
| 164 | this.floatingIP = floatingIP; |
| 165 | this.portId = null; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Creates an event of a given type for the specified router, floating IP, |
| 170 | * associated OpenStack port ID and the current time. |
| 171 | * |
| 172 | * @param type openstack router event type |
| 173 | * @param router openstack router |
| 174 | * @param floatingIP openstack floating ip |
| 175 | * @param portId associated openstack port id |
| 176 | */ |
| 177 | public OpenstackRouterEvent(Type type, Router router, NetFloatingIP floatingIP, |
| 178 | String portId) { |
| 179 | super(type, router); |
| 180 | this.exGateway = null; |
| 181 | this.routerIface = null; |
| 182 | this.floatingIP = floatingIP; |
| 183 | this.portId = portId; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Returns the router external gateway object of the router event. |
| 188 | * |
| 189 | * @return openstack router external gateway; null if the event is not |
| 190 | * relevant to the router external gateway |
| 191 | */ |
| 192 | public ExternalGateway externalGateway() { |
| 193 | return exGateway; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Returns the router interface object of the router event. |
| 198 | * |
| 199 | * @return openstack router interface; null if the event is not relevant to |
| 200 | * the router interface |
| 201 | */ |
| 202 | public RouterInterface routerIface() { |
| 203 | return routerIface; |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * Returns the floating IP of the router event. |
| 208 | * |
| 209 | * @return openstack floating ip; null if the event is not relevant to |
| 210 | * the floating ip |
| 211 | */ |
| 212 | public NetFloatingIP floatingIp() { |
| 213 | return floatingIP; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Returns the associated port ID of the floating IP. |
| 218 | * |
| 219 | * @return openstack port id; null if the event is not relevant to the |
| 220 | * floating ip |
| 221 | */ |
| 222 | public String portId() { |
| 223 | return portId; |
| 224 | } |
| 225 | |
| 226 | @Override |
| 227 | public String toString() { |
| 228 | if (floatingIP == null) { |
| 229 | return super.toString(); |
| 230 | } |
| 231 | return toStringHelper(this) |
Yuta HIGUCHI | 0c47d53 | 2017-08-18 23:16:35 -0700 | [diff] [blame] | 232 | .add("time", Tools.defaultOffsetDataTime(time())) |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 233 | .add("type", type()) |
| 234 | .add("router", subject()) |
| 235 | .add("externalGateway", exGateway) |
| 236 | .add("routerIface", routerIface) |
| 237 | .add("floatingIp", floatingIP) |
| 238 | .add("portId", portId) |
| 239 | .toString(); |
| 240 | } |
| 241 | } |