Hyunsun Moon | eaf75e6 | 2016-09-27 16:40:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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 | */ |
Hyunsun Moon | fd5a24e | 2016-10-19 19:15:48 -0700 | [diff] [blame^] | 16 | package org.opencord.cordvtn.api.net; |
Hyunsun Moon | eaf75e6 | 2016-09-27 16:40:23 -0700 | [diff] [blame] | 17 | |
| 18 | import org.joda.time.LocalDateTime; |
| 19 | import org.onosproject.event.AbstractEvent; |
| 20 | |
| 21 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 22 | |
| 23 | /** |
| 24 | * Describes vtn network event. |
| 25 | */ |
| 26 | public class VtnNetworkEvent extends AbstractEvent<VtnNetworkEvent.Type, VtnNetwork> { |
| 27 | |
| 28 | private final VtnPort vtnPort; |
| 29 | |
| 30 | /** |
| 31 | * Type of vtn network event. |
| 32 | */ |
| 33 | public enum Type { |
| 34 | /** |
| 35 | * Signifies that a new vtn network has been created. |
| 36 | */ |
| 37 | VTN_NETWORK_CREATED, |
| 38 | |
| 39 | /** |
| 40 | * Signifies that some vtn network attributes have changed. |
| 41 | */ |
| 42 | VTN_NETWORK_UPDATED, |
| 43 | |
| 44 | /** |
| 45 | * Signifies that a vtn network has been removed. |
| 46 | */ |
| 47 | VTN_NETWORK_REMOVED, |
| 48 | |
| 49 | /** |
| 50 | * Signifies that a new vtn port has been created. |
| 51 | */ |
| 52 | VTN_PORT_CREATED, |
| 53 | |
| 54 | /** |
| 55 | * Signifies that some vtn port attributes have changed. |
| 56 | */ |
| 57 | VTN_PORT_UPDATED, |
| 58 | |
| 59 | /** |
| 60 | * Signifies that a vtn port has been removed. |
| 61 | */ |
| 62 | VTN_PORT_REMOVED |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Creates an event of a given type and for the specified vtn network and |
| 67 | * the current time. |
| 68 | * |
| 69 | * @param type vtn network event type |
| 70 | * @param vtnNet vtn network subject |
| 71 | */ |
| 72 | public VtnNetworkEvent(Type type, VtnNetwork vtnNet) { |
| 73 | super(type, vtnNet); |
| 74 | this.vtnPort = null; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Creates an event of a given type and for the specified vtn network, |
| 79 | * port and the current time. |
| 80 | * |
| 81 | * @param type vtn network event type |
| 82 | * @param vtnNet vtn network subject |
| 83 | * @param vtnPort optional vtn port subject |
| 84 | */ |
| 85 | public VtnNetworkEvent(Type type, VtnNetwork vtnNet, VtnPort vtnPort) { |
| 86 | super(type, vtnNet); |
| 87 | this.vtnPort = vtnPort; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Returns the vtn port subject. |
| 92 | * It returns valid value only with the vtn port events. |
| 93 | * |
| 94 | * @return vtn port or null if the event is not vtn port specific |
| 95 | */ |
| 96 | public VtnPort vtnPort() { |
| 97 | return vtnPort; |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public String toString() { |
| 102 | if (vtnPort == null) { |
| 103 | return super.toString(); |
| 104 | } |
| 105 | return toStringHelper(this) |
| 106 | .add("time", new LocalDateTime(time())) |
| 107 | .add("type", type()) |
| 108 | .add("vtnNet", subject()) |
| 109 | .add("vtnPort", vtnPort) |
| 110 | .toString(); |
| 111 | } |
| 112 | } |