blob: 4f4892fdd624b7632921d1f7f0bf2cb1ef81445a [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 /**
72 * Signifies that the OpenStack port is updated.
73 */
74 OPENSTACK_PORT_UPDATED,
75
76 /**
77 * Signifies that the OpenStack port is removed.
78 */
sangho6a9ff0d2017-03-27 11:23:37 +090079 OPENSTACK_PORT_REMOVED,
80
81 /**
82 * Signifies that the OpenStack security group rule is added to a specific port.
83 */
Hyunsun Moonae51e732017-04-25 17:46:21 +090084 OPENSTACK_PORT_SECURITY_GROUP_ADDED,
sangho6a9ff0d2017-03-27 11:23:37 +090085
86 /**
87 * Signifies that the OpenStack security group rule is removed from a specific port.
88 */
Hyunsun Moonae51e732017-04-25 17:46:21 +090089 OPENSTACK_PORT_SECURITY_GROUP_REMOVED
Hyunsun Moon44aac662017-02-18 02:07:01 +090090 }
91
92 /**
93 * Creates an event of a given type for the specified network and the current time.
94 * @param type openstack network event type
95 * @param network openstack network
96 */
97 public OpenstackNetworkEvent(Type type, Network network) {
98 super(type, network);
99 this.port = null;
100 this.subnet = null;
Hyunsun Moonae51e732017-04-25 17:46:21 +0900101 this.securityGroupId = null;
Hyunsun Moon44aac662017-02-18 02:07:01 +0900102 }
103
104 /**
105 * Creates an event of a given type for the specified network, port and the
106 * current time.
107 *
108 * @param type openstack network event type
109 * @param network openstack network
110 * @param port openstack port
111 */
112 public OpenstackNetworkEvent(Type type, Network network, Port port) {
113 super(type, network);
114 this.port = port;
115 this.subnet = null;
Hyunsun Moonae51e732017-04-25 17:46:21 +0900116 this.securityGroupId = null;
Hyunsun Moon44aac662017-02-18 02:07:01 +0900117 }
118
119 /**
120 * Creates an event of a given type for the specified network, subnet and the
121 * current time.
122 *
123 * @param type openstack network event type
124 * @param network openstack network
125 * @param subnet openstack subnet
126 */
127 public OpenstackNetworkEvent(Type type, Network network, Subnet subnet) {
128 super(type, network);
129 this.port = null;
130 this.subnet = subnet;
Hyunsun Moonae51e732017-04-25 17:46:21 +0900131 this.securityGroupId = null;
sangho6a9ff0d2017-03-27 11:23:37 +0900132 }
133
134 /**
135 * Creates an event of a given type for the specified port and security groups.
136 *
137 * @param type openstack network event type
sangho6a9ff0d2017-03-27 11:23:37 +0900138 * @param port openstack port
Hyunsun Moonae51e732017-04-25 17:46:21 +0900139 * @param securityGroupId openstack security group
sangho6a9ff0d2017-03-27 11:23:37 +0900140 */
Hyunsun Moonae51e732017-04-25 17:46:21 +0900141 public OpenstackNetworkEvent(Type type, Port port, String securityGroupId) {
sangho6a9ff0d2017-03-27 11:23:37 +0900142 super(type, null);
143 this.port = port;
sangho6a9ff0d2017-03-27 11:23:37 +0900144 this.subnet = null;
Hyunsun Moonae51e732017-04-25 17:46:21 +0900145 this.securityGroupId = securityGroupId;
Hyunsun Moon44aac662017-02-18 02:07:01 +0900146 }
147
148 /**
149 * Returns the port of the network event.
150 *
151 * @return openstack port; null if the event is not port specific
152 */
153 public Port port() {
154 return port;
155 }
156
157 /**
158 * Returns the subnet of the network event.
159 *
160 * @return openstack subnet; null if the event is not subnet specific
161 */
162 public Subnet subnet() {
163 return subnet;
164 }
165
sangho6a9ff0d2017-03-27 11:23:37 +0900166 /**
167 * Returns the security group rule IDs updated.
168 *
Hyunsun Moonae51e732017-04-25 17:46:21 +0900169 * @return openstack security group
sangho6a9ff0d2017-03-27 11:23:37 +0900170 */
Hyunsun Moonae51e732017-04-25 17:46:21 +0900171 public String securityGroupId() {
172 return securityGroupId;
sangho6a9ff0d2017-03-27 11:23:37 +0900173 }
174
Hyunsun Moon44aac662017-02-18 02:07:01 +0900175 @Override
176 public String toString() {
177 if (port == null && subnet == null) {
178 return super.toString();
179 }
180 return toStringHelper(this)
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -0700181 .add("time", Tools.defaultOffsetDataTime(time()))
Hyunsun Moon44aac662017-02-18 02:07:01 +0900182 .add("type", type())
183 .add("network", subject())
184 .add("port", port)
185 .add("subnet", subnet)
Hyunsun Moonae51e732017-04-25 17:46:21 +0900186 .add("security group", securityGroupId())
Hyunsun Moon44aac662017-02-18 02:07:01 +0900187 .toString();
188 }
189}