blob: d4d6b23e8fcb393152868792cd48b9f319d35023 [file] [log] [blame]
Jian Li70c32de2021-02-26 18:15:20 +09001/*
2 * Copyright 2021-present Open Networking Foundation
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 */
16package org.onosproject.kubevirtnetworking.api;
17
18import org.onosproject.event.AbstractEvent;
19
Jian Li4acd4542021-03-03 14:46:50 +090020import java.util.Set;
21
Jian Lie48a6172021-02-28 03:50:15 +090022import static com.google.common.base.MoreObjects.toStringHelper;
23
Jian Li70c32de2021-02-26 18:15:20 +090024/**
25 * Kubevirt router event class.
26 */
27public class KubevirtRouterEvent extends AbstractEvent<KubevirtRouterEvent.Type, KubevirtRouter> {
28
Jian Lie48a6172021-02-28 03:50:15 +090029 private final KubevirtFloatingIp floatingIp;
30 private final String podName;
Jian Li4acd4542021-03-03 14:46:50 +090031 private final Set<String> internal;
32 private final String externalIp;
33 private final String externalNet;
34 private final String peerRouterIp;
Jian Lie48a6172021-02-28 03:50:15 +090035
Jian Li70c32de2021-02-26 18:15:20 +090036 /**
37 * Creates an event of a given type for the specified kubevirt router.
38 *
39 * @param type kubevirt router event type
40 * @param subject kubevirt router
41 */
Jian Li7eb20782021-02-27 01:10:50 +090042 public KubevirtRouterEvent(Type type, KubevirtRouter subject) {
Jian Li70c32de2021-02-26 18:15:20 +090043 super(type, subject);
Jian Lie48a6172021-02-28 03:50:15 +090044 this.floatingIp = null;
45 this.podName = null;
Jian Li4acd4542021-03-03 14:46:50 +090046 this.internal = null;
47 this.externalIp = null;
48 this.externalNet = null;
49 this.peerRouterIp = null;
Jian Lie48a6172021-02-28 03:50:15 +090050 }
51
52 /**
53 * Creates an event of a given type for the specified kubevirt router.
54 *
55 * @param type kubevirt router event type
56 * @param subject kubevirt router
57 * @param floatingIp kubevirt floating IP
58 */
59 public KubevirtRouterEvent(Type type, KubevirtRouter subject, KubevirtFloatingIp floatingIp) {
60 super(type, subject);
61 this.floatingIp = floatingIp;
62 this.podName = null;
Jian Li4acd4542021-03-03 14:46:50 +090063 this.internal = null;
64 this.externalIp = null;
65 this.externalNet = null;
66 this.peerRouterIp = null;
Jian Lie48a6172021-02-28 03:50:15 +090067 }
68
69 /**
70 * Creates an event of a given type for the specified kubevirt router.
71 *
72 * @param type kubevirt router event type
73 * @param subject kubevirt router
74 * @param floatingIp kubevirt floating IP
75 * @param podName kubevirt POD name
76 */
77 public KubevirtRouterEvent(Type type, KubevirtRouter subject, KubevirtFloatingIp floatingIp, String podName) {
78 super(type, subject);
79 this.floatingIp = floatingIp;
80 this.podName = podName;
Jian Li4acd4542021-03-03 14:46:50 +090081 this.internal = null;
82 this.externalIp = null;
83 this.externalNet = null;
84 this.peerRouterIp = null;
85 }
86
87 /**
88 * Creates an event of a given type for the specified kubevirt router.
89 *
90 * @param type kubevirt router event type
91 * @param subject kubevirt router
92 * @param internal internal networks attached to the router
93 */
94 public KubevirtRouterEvent(Type type, KubevirtRouter subject, Set<String> internal) {
95 super(type, subject);
96 this.internal = internal;
97 this.podName = null;
98 this.floatingIp = null;
99 this.externalIp = null;
100 this.externalNet = null;
101 this.peerRouterIp = null;
102 }
103
104 /**
105 * Creates an event of a given type for the specified kubevirt router.
106 *
107 * @param type kubevirt router event type
108 * @param subject kubevirt router
109 * @param externalIp virtual router's IP address included in external network
110 * @param externalNet external network name
111 * @param peerRouterIp external peer router IP address
112 */
113 public KubevirtRouterEvent(Type type, KubevirtRouter subject,
114 String externalIp, String externalNet,
115 String peerRouterIp) {
116 super(type, subject);
117 this.internal = null;
118 this.podName = null;
119 this.floatingIp = null;
120 this.externalIp = externalIp;
121 this.externalNet = externalNet;
122 this.peerRouterIp = peerRouterIp;
Jian Li70c32de2021-02-26 18:15:20 +0900123 }
124
125 public enum Type {
126 /**
127 * Signifies that a new kubevirt router is created.
128 */
129 KUBEVIRT_ROUTER_CREATED,
130
131 /**
132 * Signifies that the kubevirt router is updated.
133 */
134 KUBEVIRT_ROUTER_UPDATED,
135
136 /**
137 * Signifies that the kubevirt router is removed.
138 */
139 KUBEVIRT_ROUTER_REMOVED,
Jian Lie48a6172021-02-28 03:50:15 +0900140
141 /**
Jian Li4acd4542021-03-03 14:46:50 +0900142 * Signifies that a new external network is added to the router.
143 */
144 KUBEVIRT_ROUTER_EXTERNAL_NETWORK_ATTACHED,
145
146 /**
147 * Signifies that the existing external network is removed from the router.
148 */
149 KUBEVIRT_ROUTER_EXTERNAL_NETWORK_DETACHED,
150
151 /**
152 * Signifies that a new internal network is added to the router.
153 */
154 KUBEVIRT_ROUTER_INTERNAL_NETWORKS_ATTACHED,
155
156 /**
157 * Signifies that the existing internal network is removed from the router.
158 */
159 KUBEVIRT_ROUTER_INTERNAL_NETWORKS_DETACHED,
160
161 /**
Jian Lie48a6172021-02-28 03:50:15 +0900162 * Signifies that a new kubevirt floating IP is created.
163 */
164 KUBEVIRT_FLOATING_IP_CREATED,
165
166 /**
167 * Signifies that the kubevirt floating IP is updated.
168 */
169 KUBEVIRT_FLOATING_IP_UPDATED,
170
171 /**
172 * Signifies that the kubevirt floating IP is removed.
173 */
174 KUBEVIRT_FLOATING_IP_REMOVED,
175
176 /**
177 * Signifies that the floating IP is associated to a fixed IP.
178 */
179 KUBEVIRT_FLOATING_IP_ASSOCIATED,
180
181 /**
182 * Signifies that the floating IP disassociated from the fixed IP.
183 */
184 KUBEVIRT_FLOATING_IP_DISASSOCIATED
185 }
186
187 /**
188 * Returns the floating IP of the router event.
189 *
190 * @return kubevirt floating IP; null if the event is not relevant to the floating IP
191 */
192 public KubevirtFloatingIp floatingIp() {
193 return floatingIp;
194 }
195
196 /**
197 * Returns the pod name of the router event.
198 *
199 * @return kubevirt pod name; null if the event is not relevant to the pod name
200 */
201 public String podName() {
202 return podName;
203 }
204
Jian Li29572ba2021-03-05 12:21:50 +0900205 /**
206 * Returns the internal of the router event.
207 *
208 * @return kubevirt internal network set, null if the event is not relevant to the internal
209 */
210 public Set<String> internal() {
211 return internal;
212 }
213
214 /**
215 * Returns the external IP address of the router event.
216 *
217 * @return external IP address, null if the event is not relevant to the external
218 */
219 public String externalIp() {
220 return externalIp;
221 }
222
223 /**
224 * Returns the external network of the router event.
225 *
226 * @return external network, null if the event is not relevant ot the external
227 */
228 public String externalNet() {
229 return externalNet;
230 }
231
Jian Lie48a6172021-02-28 03:50:15 +0900232 @Override
233 public String toString() {
234 if (floatingIp == null) {
235 return super.toString();
236 }
237 return toStringHelper(this)
238 .add("type", type())
239 .add("router", subject())
240 .add("floatingIp", floatingIp)
241 .add("podName", podName)
Jian Li4acd4542021-03-03 14:46:50 +0900242 .add("internal", internal)
243 .add("externalIp", externalIp)
244 .add("externalNet", externalNet)
245 .add("peerRouterIp", peerRouterIp)
Jian Lie48a6172021-02-28 03:50:15 +0900246 .toString();
Jian Li70c32de2021-02-26 18:15:20 +0900247 }
248}