blob: 6af8e1d86cd4aec8b35883b54281fe4325b52ec2 [file] [log] [blame]
Hyunsun Moon44aac662017-02-18 02:07:01 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Hyunsun Moon44aac662017-02-18 02:07:01 +09003 *
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 */
16package org.onosproject.openstacknetworking.api;
17
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -070018import org.onlab.util.Tools;
Hyunsun Moon44aac662017-02-18 02:07:01 +090019import org.onosproject.event.AbstractEvent;
20import org.openstack4j.model.network.Network;
21import org.openstack4j.model.network.Port;
22import org.openstack4j.model.network.Subnet;
23
24import static com.google.common.base.MoreObjects.toStringHelper;
25
26/**
27 * Describes OpenStack network service event.
28 */
Jian Li5ecfd1a2018-12-10 11:41:03 +090029public class OpenstackNetworkEvent
30 extends AbstractEvent<OpenstackNetworkEvent.Type, Network> {
Hyunsun Moon44aac662017-02-18 02:07:01 +090031
32 private final Port port;
33 private final Subnet subnet;
Hyunsun Moonae51e732017-04-25 17:46:21 +090034 private final String securityGroupId;
Jian Lie6e609f2019-05-14 17:45:54 +090035 private final ExternalPeerRouter peerRouter;
Hyunsun Moon44aac662017-02-18 02:07:01 +090036
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 Li00105802020-02-25 03:30:20 +090049 * Signifies that the OpenStack network is pre-removed.
50 */
51 OPENSTACK_NETWORK_PRE_REMOVED,
52
53 /**
Hyunsun Moon44aac662017-02-18 02:07:01 +090054 * 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 Li8f64feb2018-07-24 13:20:16 +090079 * Signifies that the OpenStack port will be updated.
80 */
81 OPENSTACK_PORT_PRE_UPDATE,
82
83 /**
Hyunsun Moon44aac662017-02-18 02:07:01 +090084 * Signifies that the OpenStack port is updated.
85 */
86 OPENSTACK_PORT_UPDATED,
87
88 /**
Jian Li8f64feb2018-07-24 13:20:16 +090089 * Signifies that the OpenStack port will be removed.
90 */
91 OPENSTACK_PORT_PRE_REMOVE,
92
93 /**
Hyunsun Moon44aac662017-02-18 02:07:01 +090094 * Signifies that the OpenStack port is removed.
95 */
sangho6a9ff0d2017-03-27 11:23:37 +090096 OPENSTACK_PORT_REMOVED,
97
98 /**
99 * Signifies that the OpenStack security group rule is added to a specific port.
100 */
Hyunsun Moonae51e732017-04-25 17:46:21 +0900101 OPENSTACK_PORT_SECURITY_GROUP_ADDED,
sangho6a9ff0d2017-03-27 11:23:37 +0900102
103 /**
104 * Signifies that the OpenStack security group rule is removed from a specific port.
105 */
Jian Lie6e609f2019-05-14 17:45:54 +0900106 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 Moon44aac662017-02-18 02:07:01 +0900127 }
128
129 /**
130 * Creates an event of a given type for the specified network and the current time.
Jian Lie6e609f2019-05-14 17:45:54 +0900131 *
Hyunsun Moon44aac662017-02-18 02:07:01 +0900132 * @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 Moonae51e732017-04-25 17:46:21 +0900139 this.securityGroupId = null;
Jian Lie6e609f2019-05-14 17:45:54 +0900140 this.peerRouter = null;
Hyunsun Moon44aac662017-02-18 02:07:01 +0900141 }
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 Moonae51e732017-04-25 17:46:21 +0900155 this.securityGroupId = null;
Jian Lie6e609f2019-05-14 17:45:54 +0900156 this.peerRouter = null;
Hyunsun Moon44aac662017-02-18 02:07:01 +0900157 }
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 Moonae51e732017-04-25 17:46:21 +0900171 this.securityGroupId = null;
Jian Lie6e609f2019-05-14 17:45:54 +0900172 this.peerRouter = null;
sangho6a9ff0d2017-03-27 11:23:37 +0900173 }
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
sangho6a9ff0d2017-03-27 11:23:37 +0900179 * @param port openstack port
Hyunsun Moonae51e732017-04-25 17:46:21 +0900180 * @param securityGroupId openstack security group
sangho6a9ff0d2017-03-27 11:23:37 +0900181 */
Hyunsun Moonae51e732017-04-25 17:46:21 +0900182 public OpenstackNetworkEvent(Type type, Port port, String securityGroupId) {
sangho6a9ff0d2017-03-27 11:23:37 +0900183 super(type, null);
184 this.port = port;
sangho6a9ff0d2017-03-27 11:23:37 +0900185 this.subnet = null;
Hyunsun Moonae51e732017-04-25 17:46:21 +0900186 this.securityGroupId = securityGroupId;
Jian Lie6e609f2019-05-14 17:45:54 +0900187 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 Moon44aac662017-02-18 02:07:01 +0900202 }
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
sangho6a9ff0d2017-03-27 11:23:37 +0900222 /**
Jian Lie6e609f2019-05-14 17:45:54 +0900223 * 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 /**
sangho6a9ff0d2017-03-27 11:23:37 +0900232 * Returns the security group rule IDs updated.
233 *
Hyunsun Moonae51e732017-04-25 17:46:21 +0900234 * @return openstack security group
sangho6a9ff0d2017-03-27 11:23:37 +0900235 */
Hyunsun Moonae51e732017-04-25 17:46:21 +0900236 public String securityGroupId() {
237 return securityGroupId;
sangho6a9ff0d2017-03-27 11:23:37 +0900238 }
239
Hyunsun Moon44aac662017-02-18 02:07:01 +0900240 @Override
241 public String toString() {
242 if (port == null && subnet == null) {
243 return super.toString();
244 }
245 return toStringHelper(this)
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -0700246 .add("time", Tools.defaultOffsetDataTime(time()))
Hyunsun Moon44aac662017-02-18 02:07:01 +0900247 .add("type", type())
248 .add("network", subject())
249 .add("port", port)
250 .add("subnet", subnet)
Hyunsun Moonae51e732017-04-25 17:46:21 +0900251 .add("security group", securityGroupId())
Jian Lie6e609f2019-05-14 17:45:54 +0900252 .add("external peer router", peerRouter)
Hyunsun Moon44aac662017-02-18 02:07:01 +0900253 .toString();
254 }
255}