blob: 88b61be1cdb18174b0c943212f2b19b5b27725a3 [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 */
29public class OpenstackNetworkEvent extends AbstractEvent<OpenstackNetworkEvent.Type, Network> {
30
31 private final Port port;
32 private final Subnet subnet;
Hyunsun Moonae51e732017-04-25 17:46:21 +090033 private final String securityGroupId;
Hyunsun Moon44aac662017-02-18 02:07:01 +090034
35 public enum Type {
36 /**
37 * Signifies that a new OpenStack network is created.
38 */
39 OPENSTACK_NETWORK_CREATED,
40
41 /**
42 * Signifies that the OpenStack network is updated.
43 */
44 OPENSTACK_NETWORK_UPDATED,
45
46 /**
47 * Signifies that the OpenStack network is removed.
48 */
49 OPENSTACK_NETWORK_REMOVED,
50
51 /**
52 * Signifies that a new OpenStack subnet is created.
53 */
54 OPENSTACK_SUBNET_CREATED,
55
56 /**
57 * Signifies that the OpenStack subnet is updated.
58 */
59 OPENSTACK_SUBNET_UPDATED,
60
61 /**
62 * Signifies that the OpenStack subnet is removed.
63 */
64 OPENSTACK_SUBNET_REMOVED,
65
66 /**
67 * Signifies that a new OpenStack port is created.
68 */
69 OPENSTACK_PORT_CREATED,
70
71 /**
Jian Li8f64feb2018-07-24 13:20:16 +090072 * Signifies that the OpenStack port will be updated.
73 */
74 OPENSTACK_PORT_PRE_UPDATE,
75
76 /**
Hyunsun Moon44aac662017-02-18 02:07:01 +090077 * Signifies that the OpenStack port is updated.
78 */
79 OPENSTACK_PORT_UPDATED,
80
81 /**
Jian Li8f64feb2018-07-24 13:20:16 +090082 * Signifies that the OpenStack port will be removed.
83 */
84 OPENSTACK_PORT_PRE_REMOVE,
85
86 /**
Hyunsun Moon44aac662017-02-18 02:07:01 +090087 * Signifies that the OpenStack port is removed.
88 */
sangho6a9ff0d2017-03-27 11:23:37 +090089 OPENSTACK_PORT_REMOVED,
90
91 /**
92 * Signifies that the OpenStack security group rule is added to a specific port.
93 */
Hyunsun Moonae51e732017-04-25 17:46:21 +090094 OPENSTACK_PORT_SECURITY_GROUP_ADDED,
sangho6a9ff0d2017-03-27 11:23:37 +090095
96 /**
97 * Signifies that the OpenStack security group rule is removed from a specific port.
98 */
Hyunsun Moonae51e732017-04-25 17:46:21 +090099 OPENSTACK_PORT_SECURITY_GROUP_REMOVED
Hyunsun Moon44aac662017-02-18 02:07:01 +0900100 }
101
102 /**
103 * Creates an event of a given type for the specified network and the current time.
104 * @param type openstack network event type
105 * @param network openstack network
106 */
107 public OpenstackNetworkEvent(Type type, Network network) {
108 super(type, network);
109 this.port = null;
110 this.subnet = null;
Hyunsun Moonae51e732017-04-25 17:46:21 +0900111 this.securityGroupId = null;
Hyunsun Moon44aac662017-02-18 02:07:01 +0900112 }
113
114 /**
115 * Creates an event of a given type for the specified network, port and the
116 * current time.
117 *
118 * @param type openstack network event type
119 * @param network openstack network
120 * @param port openstack port
121 */
122 public OpenstackNetworkEvent(Type type, Network network, Port port) {
123 super(type, network);
124 this.port = port;
125 this.subnet = null;
Hyunsun Moonae51e732017-04-25 17:46:21 +0900126 this.securityGroupId = null;
Hyunsun Moon44aac662017-02-18 02:07:01 +0900127 }
128
129 /**
130 * Creates an event of a given type for the specified network, subnet and the
131 * current time.
132 *
133 * @param type openstack network event type
134 * @param network openstack network
135 * @param subnet openstack subnet
136 */
137 public OpenstackNetworkEvent(Type type, Network network, Subnet subnet) {
138 super(type, network);
139 this.port = null;
140 this.subnet = subnet;
Hyunsun Moonae51e732017-04-25 17:46:21 +0900141 this.securityGroupId = null;
sangho6a9ff0d2017-03-27 11:23:37 +0900142 }
143
144 /**
145 * Creates an event of a given type for the specified port and security groups.
146 *
147 * @param type openstack network event type
sangho6a9ff0d2017-03-27 11:23:37 +0900148 * @param port openstack port
Hyunsun Moonae51e732017-04-25 17:46:21 +0900149 * @param securityGroupId openstack security group
sangho6a9ff0d2017-03-27 11:23:37 +0900150 */
Hyunsun Moonae51e732017-04-25 17:46:21 +0900151 public OpenstackNetworkEvent(Type type, Port port, String securityGroupId) {
sangho6a9ff0d2017-03-27 11:23:37 +0900152 super(type, null);
153 this.port = port;
sangho6a9ff0d2017-03-27 11:23:37 +0900154 this.subnet = null;
Hyunsun Moonae51e732017-04-25 17:46:21 +0900155 this.securityGroupId = securityGroupId;
Hyunsun Moon44aac662017-02-18 02:07:01 +0900156 }
157
158 /**
159 * Returns the port of the network event.
160 *
161 * @return openstack port; null if the event is not port specific
162 */
163 public Port port() {
164 return port;
165 }
166
167 /**
168 * Returns the subnet of the network event.
169 *
170 * @return openstack subnet; null if the event is not subnet specific
171 */
172 public Subnet subnet() {
173 return subnet;
174 }
175
sangho6a9ff0d2017-03-27 11:23:37 +0900176 /**
177 * Returns the security group rule IDs updated.
178 *
Hyunsun Moonae51e732017-04-25 17:46:21 +0900179 * @return openstack security group
sangho6a9ff0d2017-03-27 11:23:37 +0900180 */
Hyunsun Moonae51e732017-04-25 17:46:21 +0900181 public String securityGroupId() {
182 return securityGroupId;
sangho6a9ff0d2017-03-27 11:23:37 +0900183 }
184
Hyunsun Moon44aac662017-02-18 02:07:01 +0900185 @Override
186 public String toString() {
187 if (port == null && subnet == null) {
188 return super.toString();
189 }
190 return toStringHelper(this)
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -0700191 .add("time", Tools.defaultOffsetDataTime(time()))
Hyunsun Moon44aac662017-02-18 02:07:01 +0900192 .add("type", type())
193 .add("network", subject())
194 .add("port", port)
195 .add("subnet", subnet)
Hyunsun Moonae51e732017-04-25 17:46:21 +0900196 .add("security group", securityGroupId())
Hyunsun Moon44aac662017-02-18 02:07:01 +0900197 .toString();
198 }
199}