Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.host; |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 17 | |
Yuta HIGUCHI | 0c47d53 | 2017-08-18 23:16:35 -0700 | [diff] [blame] | 18 | import org.onlab.util.Tools; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.event.AbstractEvent; |
| 20 | import org.onosproject.net.Host; |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 21 | |
| 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Describes end-station host event. |
| 26 | */ |
| 27 | public class HostEvent extends AbstractEvent<HostEvent.Type, Host> { |
| 28 | |
| 29 | /** |
| 30 | * Type of host events. |
| 31 | */ |
| 32 | public enum Type { |
| 33 | /** |
| 34 | * Signifies that a new host has been detected. |
| 35 | */ |
| 36 | HOST_ADDED, |
| 37 | |
| 38 | /** |
| 39 | * Signifies that a host has been removed. |
| 40 | */ |
| 41 | HOST_REMOVED, |
| 42 | |
| 43 | /** |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 44 | * Signifies that host data changed, e.g. IP address |
| 45 | */ |
| 46 | HOST_UPDATED, |
| 47 | |
| 48 | /** |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 49 | * Signifies that a host location has changed. |
| 50 | */ |
| 51 | HOST_MOVED |
| 52 | } |
| 53 | |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 54 | private Host prevSubject; |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 55 | |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 56 | /** |
| 57 | * Creates an event of a given type and for the specified host and the |
| 58 | * current time. |
| 59 | * |
| 60 | * @param type host event type |
| 61 | * @param host event host subject |
| 62 | */ |
| 63 | public HostEvent(Type type, Host host) { |
| 64 | super(type, host); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Creates an event of a given type and for the specified host and time. |
| 69 | * |
| 70 | * @param type host event type |
| 71 | * @param host event host subject |
| 72 | * @param time occurrence time |
| 73 | */ |
| 74 | public HostEvent(Type type, Host host, long time) { |
| 75 | super(type, host, time); |
| 76 | } |
| 77 | |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 78 | /** |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 79 | * Creates an event with previous subject. |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 80 | * |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 81 | * The previous subject is ignored if the type is not moved or updated |
| 82 | * |
| 83 | * @param type host event type |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 84 | * @param host event host subject |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 85 | * @param prevSubject previous host subject |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 86 | */ |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 87 | public HostEvent(Type type, Host host, Host prevSubject) { |
| 88 | super(type, host); |
| 89 | if (type == Type.HOST_MOVED || type == Type.HOST_UPDATED) { |
| 90 | this.prevSubject = prevSubject; |
| 91 | } |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /** |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 95 | * Gets the previous subject in this host event. |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 96 | * |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 97 | * @return the previous subject, or null if previous subject is not |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 98 | * specified. |
| 99 | */ |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 100 | public Host prevSubject() { |
| 101 | return this.prevSubject; |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public String toString() { |
| 106 | return toStringHelper(this) |
Yuta HIGUCHI | 0c47d53 | 2017-08-18 23:16:35 -0700 | [diff] [blame] | 107 | .add("time", Tools.defaultOffsetDataTime(time())) |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 108 | .add("type", type()) |
| 109 | .add("subject", subject()) |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 110 | .add("prevSubject", prevSubject()) |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 111 | .toString(); |
| 112 | } |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 113 | } |