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