Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.openstacknetworking.api; |
| 17 | |
Yuta HIGUCHI | 0c47d53 | 2017-08-18 23:16:35 -0700 | [diff] [blame] | 18 | import org.onlab.util.Tools; |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 19 | import org.onosproject.event.AbstractEvent; |
| 20 | import org.openstack4j.model.network.Network; |
| 21 | import org.openstack4j.model.network.Port; |
| 22 | import org.openstack4j.model.network.Subnet; |
| 23 | |
| 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | |
| 26 | /** |
| 27 | * Describes OpenStack network service event. |
| 28 | */ |
| 29 | public class OpenstackNetworkEvent extends AbstractEvent<OpenstackNetworkEvent.Type, Network> { |
| 30 | |
| 31 | private final Port port; |
| 32 | private final Subnet subnet; |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 33 | private final String securityGroupId; |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 34 | |
| 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 Li | 8f64feb | 2018-07-24 13:20:16 +0900 | [diff] [blame^] | 72 | * Signifies that the OpenStack port will be updated. |
| 73 | */ |
| 74 | OPENSTACK_PORT_PRE_UPDATE, |
| 75 | |
| 76 | /** |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 77 | * Signifies that the OpenStack port is updated. |
| 78 | */ |
| 79 | OPENSTACK_PORT_UPDATED, |
| 80 | |
| 81 | /** |
Jian Li | 8f64feb | 2018-07-24 13:20:16 +0900 | [diff] [blame^] | 82 | * Signifies that the OpenStack port will be removed. |
| 83 | */ |
| 84 | OPENSTACK_PORT_PRE_REMOVE, |
| 85 | |
| 86 | /** |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 87 | * Signifies that the OpenStack port is removed. |
| 88 | */ |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 89 | OPENSTACK_PORT_REMOVED, |
| 90 | |
| 91 | /** |
| 92 | * Signifies that the OpenStack security group rule is added to a specific port. |
| 93 | */ |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 94 | OPENSTACK_PORT_SECURITY_GROUP_ADDED, |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * Signifies that the OpenStack security group rule is removed from a specific port. |
| 98 | */ |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 99 | OPENSTACK_PORT_SECURITY_GROUP_REMOVED |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 100 | } |
| 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 Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 111 | this.securityGroupId = null; |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 112 | } |
| 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 Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 126 | this.securityGroupId = null; |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 127 | } |
| 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 Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 141 | this.securityGroupId = null; |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 142 | } |
| 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 |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 148 | * @param port openstack port |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 149 | * @param securityGroupId openstack security group |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 150 | */ |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 151 | public OpenstackNetworkEvent(Type type, Port port, String securityGroupId) { |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 152 | super(type, null); |
| 153 | this.port = port; |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 154 | this.subnet = null; |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 155 | this.securityGroupId = securityGroupId; |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 156 | } |
| 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 | |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 176 | /** |
| 177 | * Returns the security group rule IDs updated. |
| 178 | * |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 179 | * @return openstack security group |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 180 | */ |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 181 | public String securityGroupId() { |
| 182 | return securityGroupId; |
sangho | 6a9ff0d | 2017-03-27 11:23:37 +0900 | [diff] [blame] | 183 | } |
| 184 | |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 185 | @Override |
| 186 | public String toString() { |
| 187 | if (port == null && subnet == null) { |
| 188 | return super.toString(); |
| 189 | } |
| 190 | return toStringHelper(this) |
Yuta HIGUCHI | 0c47d53 | 2017-08-18 23:16:35 -0700 | [diff] [blame] | 191 | .add("time", Tools.defaultOffsetDataTime(time())) |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 192 | .add("type", type()) |
| 193 | .add("network", subject()) |
| 194 | .add("port", port) |
| 195 | .add("subnet", subnet) |
Hyunsun Moon | ae51e73 | 2017-04-25 17:46:21 +0900 | [diff] [blame] | 196 | .add("security group", securityGroupId()) |
Hyunsun Moon | 44aac66 | 2017-02-18 02:07:01 +0900 | [diff] [blame] | 197 | .toString(); |
| 198 | } |
| 199 | } |