blob: 84c9b218b665cbb452b35d274ab9a4a6ca84ea27 [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 /**
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 Li8f64feb2018-07-24 13:20:16 +090074 * Signifies that the OpenStack port will be updated.
75 */
76 OPENSTACK_PORT_PRE_UPDATE,
77
78 /**
Hyunsun Moon44aac662017-02-18 02:07:01 +090079 * Signifies that the OpenStack port is updated.
80 */
81 OPENSTACK_PORT_UPDATED,
82
83 /**
Jian Li8f64feb2018-07-24 13:20:16 +090084 * Signifies that the OpenStack port will be removed.
85 */
86 OPENSTACK_PORT_PRE_REMOVE,
87
88 /**
Hyunsun Moon44aac662017-02-18 02:07:01 +090089 * Signifies that the OpenStack port is removed.
90 */
sangho6a9ff0d2017-03-27 11:23:37 +090091 OPENSTACK_PORT_REMOVED,
92
93 /**
94 * Signifies that the OpenStack security group rule is added to a specific port.
95 */
Hyunsun Moonae51e732017-04-25 17:46:21 +090096 OPENSTACK_PORT_SECURITY_GROUP_ADDED,
sangho6a9ff0d2017-03-27 11:23:37 +090097
98 /**
99 * Signifies that the OpenStack security group rule is removed from a specific port.
100 */
Jian Lie6e609f2019-05-14 17:45:54 +0900101 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 Moon44aac662017-02-18 02:07:01 +0900122 }
123
124 /**
125 * Creates an event of a given type for the specified network and the current time.
Jian Lie6e609f2019-05-14 17:45:54 +0900126 *
Hyunsun Moon44aac662017-02-18 02:07:01 +0900127 * @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 Moonae51e732017-04-25 17:46:21 +0900134 this.securityGroupId = null;
Jian Lie6e609f2019-05-14 17:45:54 +0900135 this.peerRouter = null;
Hyunsun Moon44aac662017-02-18 02:07:01 +0900136 }
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 Moonae51e732017-04-25 17:46:21 +0900150 this.securityGroupId = null;
Jian Lie6e609f2019-05-14 17:45:54 +0900151 this.peerRouter = null;
Hyunsun Moon44aac662017-02-18 02:07:01 +0900152 }
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 Moonae51e732017-04-25 17:46:21 +0900166 this.securityGroupId = null;
Jian Lie6e609f2019-05-14 17:45:54 +0900167 this.peerRouter = null;
sangho6a9ff0d2017-03-27 11:23:37 +0900168 }
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
sangho6a9ff0d2017-03-27 11:23:37 +0900174 * @param port openstack port
Hyunsun Moonae51e732017-04-25 17:46:21 +0900175 * @param securityGroupId openstack security group
sangho6a9ff0d2017-03-27 11:23:37 +0900176 */
Hyunsun Moonae51e732017-04-25 17:46:21 +0900177 public OpenstackNetworkEvent(Type type, Port port, String securityGroupId) {
sangho6a9ff0d2017-03-27 11:23:37 +0900178 super(type, null);
179 this.port = port;
sangho6a9ff0d2017-03-27 11:23:37 +0900180 this.subnet = null;
Hyunsun Moonae51e732017-04-25 17:46:21 +0900181 this.securityGroupId = securityGroupId;
Jian Lie6e609f2019-05-14 17:45:54 +0900182 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 Moon44aac662017-02-18 02:07:01 +0900197 }
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
sangho6a9ff0d2017-03-27 11:23:37 +0900217 /**
Jian Lie6e609f2019-05-14 17:45:54 +0900218 * 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 /**
sangho6a9ff0d2017-03-27 11:23:37 +0900227 * Returns the security group rule IDs updated.
228 *
Hyunsun Moonae51e732017-04-25 17:46:21 +0900229 * @return openstack security group
sangho6a9ff0d2017-03-27 11:23:37 +0900230 */
Hyunsun Moonae51e732017-04-25 17:46:21 +0900231 public String securityGroupId() {
232 return securityGroupId;
sangho6a9ff0d2017-03-27 11:23:37 +0900233 }
234
Hyunsun Moon44aac662017-02-18 02:07:01 +0900235 @Override
236 public String toString() {
237 if (port == null && subnet == null) {
238 return super.toString();
239 }
240 return toStringHelper(this)
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -0700241 .add("time", Tools.defaultOffsetDataTime(time()))
Hyunsun Moon44aac662017-02-18 02:07:01 +0900242 .add("type", type())
243 .add("network", subject())
244 .add("port", port)
245 .add("subnet", subnet)
Hyunsun Moonae51e732017-04-25 17:46:21 +0900246 .add("security group", securityGroupId())
Jian Lie6e609f2019-05-14 17:45:54 +0900247 .add("external peer router", peerRouter)
Hyunsun Moon44aac662017-02-18 02:07:01 +0900248 .toString();
249 }
250}