blob: 5815b7aa3dc52fb8b4183640d93125863e038e07 [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;
Hyunsun Moon44aac662017-02-18 02:07:01 +090035
36 public enum Type {
37 /**
38 * Signifies that a new OpenStack network is created.
39 */
40 OPENSTACK_NETWORK_CREATED,
41
42 /**
43 * Signifies that the OpenStack network is updated.
44 */
45 OPENSTACK_NETWORK_UPDATED,
46
47 /**
48 * Signifies that the OpenStack network is removed.
49 */
50 OPENSTACK_NETWORK_REMOVED,
51
52 /**
53 * Signifies that a new OpenStack subnet is created.
54 */
55 OPENSTACK_SUBNET_CREATED,
56
57 /**
58 * Signifies that the OpenStack subnet is updated.
59 */
60 OPENSTACK_SUBNET_UPDATED,
61
62 /**
63 * Signifies that the OpenStack subnet is removed.
64 */
65 OPENSTACK_SUBNET_REMOVED,
66
67 /**
68 * Signifies that a new OpenStack port is created.
69 */
70 OPENSTACK_PORT_CREATED,
71
72 /**
Jian Li8f64feb2018-07-24 13:20:16 +090073 * Signifies that the OpenStack port will be updated.
74 */
75 OPENSTACK_PORT_PRE_UPDATE,
76
77 /**
Hyunsun Moon44aac662017-02-18 02:07:01 +090078 * Signifies that the OpenStack port is updated.
79 */
80 OPENSTACK_PORT_UPDATED,
81
82 /**
Jian Li8f64feb2018-07-24 13:20:16 +090083 * Signifies that the OpenStack port will be removed.
84 */
85 OPENSTACK_PORT_PRE_REMOVE,
86
87 /**
Hyunsun Moon44aac662017-02-18 02:07:01 +090088 * Signifies that the OpenStack port is removed.
89 */
sangho6a9ff0d2017-03-27 11:23:37 +090090 OPENSTACK_PORT_REMOVED,
91
92 /**
93 * Signifies that the OpenStack security group rule is added to a specific port.
94 */
Hyunsun Moonae51e732017-04-25 17:46:21 +090095 OPENSTACK_PORT_SECURITY_GROUP_ADDED,
sangho6a9ff0d2017-03-27 11:23:37 +090096
97 /**
98 * Signifies that the OpenStack security group rule is removed from a specific port.
99 */
Hyunsun Moonae51e732017-04-25 17:46:21 +0900100 OPENSTACK_PORT_SECURITY_GROUP_REMOVED
Hyunsun Moon44aac662017-02-18 02:07:01 +0900101 }
102
103 /**
104 * Creates an event of a given type for the specified network and the current time.
105 * @param type openstack network event type
106 * @param network openstack network
107 */
108 public OpenstackNetworkEvent(Type type, Network network) {
109 super(type, network);
110 this.port = null;
111 this.subnet = null;
Hyunsun Moonae51e732017-04-25 17:46:21 +0900112 this.securityGroupId = null;
Hyunsun Moon44aac662017-02-18 02:07:01 +0900113 }
114
115 /**
116 * Creates an event of a given type for the specified network, port and the
117 * current time.
118 *
119 * @param type openstack network event type
120 * @param network openstack network
121 * @param port openstack port
122 */
123 public OpenstackNetworkEvent(Type type, Network network, Port port) {
124 super(type, network);
125 this.port = port;
126 this.subnet = null;
Hyunsun Moonae51e732017-04-25 17:46:21 +0900127 this.securityGroupId = null;
Hyunsun Moon44aac662017-02-18 02:07:01 +0900128 }
129
130 /**
131 * Creates an event of a given type for the specified network, subnet and the
132 * current time.
133 *
134 * @param type openstack network event type
135 * @param network openstack network
136 * @param subnet openstack subnet
137 */
138 public OpenstackNetworkEvent(Type type, Network network, Subnet subnet) {
139 super(type, network);
140 this.port = null;
141 this.subnet = subnet;
Hyunsun Moonae51e732017-04-25 17:46:21 +0900142 this.securityGroupId = null;
sangho6a9ff0d2017-03-27 11:23:37 +0900143 }
144
145 /**
146 * Creates an event of a given type for the specified port and security groups.
147 *
148 * @param type openstack network event type
sangho6a9ff0d2017-03-27 11:23:37 +0900149 * @param port openstack port
Hyunsun Moonae51e732017-04-25 17:46:21 +0900150 * @param securityGroupId openstack security group
sangho6a9ff0d2017-03-27 11:23:37 +0900151 */
Hyunsun Moonae51e732017-04-25 17:46:21 +0900152 public OpenstackNetworkEvent(Type type, Port port, String securityGroupId) {
sangho6a9ff0d2017-03-27 11:23:37 +0900153 super(type, null);
154 this.port = port;
sangho6a9ff0d2017-03-27 11:23:37 +0900155 this.subnet = null;
Hyunsun Moonae51e732017-04-25 17:46:21 +0900156 this.securityGroupId = securityGroupId;
Hyunsun Moon44aac662017-02-18 02:07:01 +0900157 }
158
159 /**
160 * Returns the port of the network event.
161 *
162 * @return openstack port; null if the event is not port specific
163 */
164 public Port port() {
165 return port;
166 }
167
168 /**
169 * Returns the subnet of the network event.
170 *
171 * @return openstack subnet; null if the event is not subnet specific
172 */
173 public Subnet subnet() {
174 return subnet;
175 }
176
sangho6a9ff0d2017-03-27 11:23:37 +0900177 /**
178 * Returns the security group rule IDs updated.
179 *
Hyunsun Moonae51e732017-04-25 17:46:21 +0900180 * @return openstack security group
sangho6a9ff0d2017-03-27 11:23:37 +0900181 */
Hyunsun Moonae51e732017-04-25 17:46:21 +0900182 public String securityGroupId() {
183 return securityGroupId;
sangho6a9ff0d2017-03-27 11:23:37 +0900184 }
185
Hyunsun Moon44aac662017-02-18 02:07:01 +0900186 @Override
187 public String toString() {
188 if (port == null && subnet == null) {
189 return super.toString();
190 }
191 return toStringHelper(this)
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -0700192 .add("time", Tools.defaultOffsetDataTime(time()))
Hyunsun Moon44aac662017-02-18 02:07:01 +0900193 .add("type", type())
194 .add("network", subject())
195 .add("port", port)
196 .add("subnet", subnet)
Hyunsun Moonae51e732017-04-25 17:46:21 +0900197 .add("security group", securityGroupId())
Hyunsun Moon44aac662017-02-18 02:07:01 +0900198 .toString();
199 }
200}