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