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.Network; |
| 21 | import org.openstack4j.model.network.Port; |
| 22 | import org.openstack4j.model.network.Subnet; |
| 23 | |
| 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | |
| 26 | /** |
| 27 | * Describes OpenStack network service event. |
| 28 | */ |
Jian Li | 5ecfd1a | 2018-12-10 11:41:03 +0900 | [diff] [blame] | 29 | public class OpenstackNetworkEvent |
| 30 | extends AbstractEvent<OpenstackNetworkEvent.Type, Network> { |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 31 | |
| 32 | private final Port port; |
| 33 | private final Subnet subnet; |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 34 | private final String securityGroupId; |
Jian Li | e6e609f | 2019-05-14 17:45:54 +0900 | [diff] [blame] | 35 | private final ExternalPeerRouter peerRouter; |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 36 | |
| 37 | public enum Type { |
| 38 | /** |
| 39 | * Signifies that a new OpenStack network is created. |
| 40 | */ |
| 41 | OPENSTACK_NETWORK_CREATED, |
| 42 | |
| 43 | /** |
| 44 | * Signifies that the OpenStack network is updated. |
| 45 | */ |
| 46 | OPENSTACK_NETWORK_UPDATED, |
| 47 | |
| 48 | /** |
Jian Li | 0010580 | 2020-02-25 03:30:20 +0900 | [diff] [blame] | 49 | * Signifies that the OpenStack network is pre-removed. |
| 50 | */ |
| 51 | OPENSTACK_NETWORK_PRE_REMOVED, |
| 52 | |
| 53 | /** |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 54 | * Signifies that the OpenStack network is removed. |
| 55 | */ |
| 56 | OPENSTACK_NETWORK_REMOVED, |
| 57 | |
| 58 | /** |
| 59 | * Signifies that a new OpenStack subnet is created. |
| 60 | */ |
| 61 | OPENSTACK_SUBNET_CREATED, |
| 62 | |
| 63 | /** |
| 64 | * Signifies that the OpenStack subnet is updated. |
| 65 | */ |
| 66 | OPENSTACK_SUBNET_UPDATED, |
| 67 | |
| 68 | /** |
| 69 | * Signifies that the OpenStack subnet is removed. |
| 70 | */ |
| 71 | OPENSTACK_SUBNET_REMOVED, |
| 72 | |
| 73 | /** |
| 74 | * Signifies that a new OpenStack port is created. |
| 75 | */ |
| 76 | OPENSTACK_PORT_CREATED, |
| 77 | |
| 78 | /** |
Jian Li | 8f64feb | 2018-07-24 13:20:16 +0900 | [diff] [blame] | 79 | * Signifies that the OpenStack port will be updated. |
| 80 | */ |
| 81 | OPENSTACK_PORT_PRE_UPDATE, |
| 82 | |
| 83 | /** |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 84 | * Signifies that the OpenStack port is updated. |
| 85 | */ |
| 86 | OPENSTACK_PORT_UPDATED, |
| 87 | |
| 88 | /** |
Jian Li | 8f64feb | 2018-07-24 13:20:16 +0900 | [diff] [blame] | 89 | * Signifies that the OpenStack port will be removed. |
| 90 | */ |
| 91 | OPENSTACK_PORT_PRE_REMOVE, |
| 92 | |
| 93 | /** |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 94 | * Signifies that the OpenStack port is removed. |
| 95 | */ |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 96 | OPENSTACK_PORT_REMOVED, |
| 97 | |
| 98 | /** |
| 99 | * Signifies that the OpenStack security group rule is added to a specific port. |
| 100 | */ |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 101 | OPENSTACK_PORT_SECURITY_GROUP_ADDED, |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * Signifies that the OpenStack security group rule is removed from a specific port. |
| 105 | */ |
Jian Li | e6e609f | 2019-05-14 17:45:54 +0900 | [diff] [blame] | 106 | OPENSTACK_PORT_SECURITY_GROUP_REMOVED, |
| 107 | |
| 108 | /** |
| 109 | * Signifies that the external peer router is created. |
| 110 | */ |
| 111 | EXTERNAL_PEER_ROUTER_CREATED, |
| 112 | |
| 113 | /** |
| 114 | * Signifies that the external peer router is updated. |
| 115 | */ |
| 116 | EXTERNAL_PEER_ROUTER_UPDATED, |
| 117 | |
| 118 | /** |
| 119 | * Signifies that the external peer router MAC is updated. |
| 120 | */ |
| 121 | EXTERNAL_PEER_ROUTER_MAC_UPDATED, |
| 122 | |
| 123 | /** |
| 124 | * Signifies that the external peer router is removed. |
| 125 | */ |
| 126 | EXTERNAL_PEER_ROUTER_REMOVED, |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Creates an event of a given type for the specified network and the current time. |
Jian Li | e6e609f | 2019-05-14 17:45:54 +0900 | [diff] [blame] | 131 | * |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 132 | * @param type openstack network event type |
| 133 | * @param network openstack network |
| 134 | */ |
| 135 | public OpenstackNetworkEvent(Type type, Network network) { |
| 136 | super(type, network); |
| 137 | this.port = null; |
| 138 | this.subnet = null; |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 139 | this.securityGroupId = null; |
Jian Li | e6e609f | 2019-05-14 17:45:54 +0900 | [diff] [blame] | 140 | this.peerRouter = null; |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Creates an event of a given type for the specified network, port and the |
| 145 | * current time. |
| 146 | * |
| 147 | * @param type openstack network event type |
| 148 | * @param network openstack network |
| 149 | * @param port openstack port |
| 150 | */ |
| 151 | public OpenstackNetworkEvent(Type type, Network network, Port port) { |
| 152 | super(type, network); |
| 153 | this.port = port; |
| 154 | this.subnet = null; |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 155 | this.securityGroupId = null; |
Jian Li | e6e609f | 2019-05-14 17:45:54 +0900 | [diff] [blame] | 156 | this.peerRouter = null; |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Creates an event of a given type for the specified network, subnet and the |
| 161 | * current time. |
| 162 | * |
| 163 | * @param type openstack network event type |
| 164 | * @param network openstack network |
| 165 | * @param subnet openstack subnet |
| 166 | */ |
| 167 | public OpenstackNetworkEvent(Type type, Network network, Subnet subnet) { |
| 168 | super(type, network); |
| 169 | this.port = null; |
| 170 | this.subnet = subnet; |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 171 | this.securityGroupId = null; |
Jian Li | e6e609f | 2019-05-14 17:45:54 +0900 | [diff] [blame] | 172 | this.peerRouter = null; |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Creates an event of a given type for the specified port and security groups. |
| 177 | * |
| 178 | * @param type openstack network event type |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 179 | * @param port openstack port |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 180 | * @param securityGroupId openstack security group |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 181 | */ |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 182 | public OpenstackNetworkEvent(Type type, Port port, String securityGroupId) { |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 183 | super(type, null); |
| 184 | this.port = port; |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 185 | this.subnet = null; |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 186 | this.securityGroupId = securityGroupId; |
Jian Li | e6e609f | 2019-05-14 17:45:54 +0900 | [diff] [blame] | 187 | this.peerRouter = null; |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Creates an event of a given type for the specified external peer router. |
| 192 | * |
| 193 | * @param type openstack network event type |
| 194 | * @param peerRouter external peer router |
| 195 | */ |
| 196 | public OpenstackNetworkEvent(Type type, ExternalPeerRouter peerRouter) { |
| 197 | super(type, null); |
| 198 | this.port = null; |
| 199 | this.subnet = null; |
| 200 | this.securityGroupId = null; |
| 201 | this.peerRouter = peerRouter; |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Returns the port of the network event. |
| 206 | * |
| 207 | * @return openstack port; null if the event is not port specific |
| 208 | */ |
| 209 | public Port port() { |
| 210 | return port; |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Returns the subnet of the network event. |
| 215 | * |
| 216 | * @return openstack subnet; null if the event is not subnet specific |
| 217 | */ |
| 218 | public Subnet subnet() { |
| 219 | return subnet; |
| 220 | } |
| 221 | |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 222 | /** |
Jian Li | e6e609f | 2019-05-14 17:45:54 +0900 | [diff] [blame] | 223 | * Returns the external peer router. |
| 224 | * |
| 225 | * @return external peer router; null if the event is not peer router specific |
| 226 | */ |
| 227 | public ExternalPeerRouter peerRouter() { |
| 228 | return peerRouter; |
| 229 | } |
| 230 | |
| 231 | /** |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 232 | * Returns the security group rule IDs updated. |
| 233 | * |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 234 | * @return openstack security group |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 235 | */ |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 236 | public String securityGroupId() { |
| 237 | return securityGroupId; |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 238 | } |
| 239 | |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 240 | @Override |
| 241 | public String toString() { |
| 242 | if (port == null && subnet == null) { |
| 243 | return super.toString(); |
| 244 | } |
| 245 | return toStringHelper(this) |
Yuta HIGUCHI | 0c47d53 | 2017-08-18 23:16:35 -0700 | [diff] [blame] | 246 | .add("time", Tools.defaultOffsetDataTime(time())) |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 247 | .add("type", type()) |
| 248 | .add("network", subject()) |
| 249 | .add("port", port) |
| 250 | .add("subnet", subnet) |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 251 | .add("security group", securityGroupId()) |
Jian Li | e6e609f | 2019-05-14 17:45:54 +0900 | [diff] [blame] | 252 | .add("external peer router", peerRouter) |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 253 | .toString(); |
| 254 | } |
| 255 | } |