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 | */ |
jobin | d19b714 | 2019-05-17 09:46:52 -0400 | [diff] [blame] | 51 | HOST_MOVED, |
| 52 | /** |
| 53 | * Signifies that a host is in offending state, eg: frequent host movement. |
| 54 | */ |
| 55 | HOST_SUSPENDED, |
| 56 | /** |
| 57 | * Signifies that host state in non offending state. |
| 58 | */ |
Charles Chan | f42939d | 2019-12-06 19:19:30 -0800 | [diff] [blame] | 59 | HOST_UNSUSPENDED, |
| 60 | /** |
| 61 | * Signifies that host auxiliary location has changed. |
| 62 | */ |
| 63 | HOST_AUX_MOVED |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 66 | private Host prevSubject; |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 67 | |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 68 | /** |
| 69 | * Creates an event of a given type and for the specified host and the |
| 70 | * current time. |
| 71 | * |
| 72 | * @param type host event type |
| 73 | * @param host event host subject |
| 74 | */ |
| 75 | public HostEvent(Type type, Host host) { |
| 76 | super(type, host); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Creates an event of a given type and for the specified host and time. |
| 81 | * |
| 82 | * @param type host event type |
| 83 | * @param host event host subject |
| 84 | * @param time occurrence time |
| 85 | */ |
| 86 | public HostEvent(Type type, Host host, long time) { |
| 87 | super(type, host, time); |
| 88 | } |
| 89 | |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 90 | /** |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 91 | * Creates an event with previous subject. |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 92 | * |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 93 | * The previous subject is ignored if the type is not moved or updated |
| 94 | * |
| 95 | * @param type host event type |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 96 | * @param host event host subject |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 97 | * @param prevSubject previous host subject |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 98 | */ |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 99 | public HostEvent(Type type, Host host, Host prevSubject) { |
| 100 | super(type, host); |
Charles Chan | f42939d | 2019-12-06 19:19:30 -0800 | [diff] [blame] | 101 | if (type == Type.HOST_MOVED || type == Type.HOST_UPDATED || type == Type.HOST_AUX_MOVED) { |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 102 | this.prevSubject = prevSubject; |
| 103 | } |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /** |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 107 | * Gets the previous subject in this host event. |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 108 | * |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 109 | * @return the previous subject, or null if previous subject is not |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 110 | * specified. |
| 111 | */ |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 112 | public Host prevSubject() { |
| 113 | return this.prevSubject; |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public String toString() { |
| 118 | return toStringHelper(this) |
Yuta HIGUCHI | 0c47d53 | 2017-08-18 23:16:35 -0700 | [diff] [blame] | 119 | .add("time", Tools.defaultOffsetDataTime(time())) |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 120 | .add("type", type()) |
| 121 | .add("subject", subject()) |
Charles Chan | 33f28a9 | 2015-11-13 13:12:38 -0800 | [diff] [blame] | 122 | .add("prevSubject", prevSubject()) |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 123 | .toString(); |
| 124 | } |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 125 | } |