blob: 0fecf2b232a84bfa006fde23716961b8bd85ef53 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.host;
tom64b7aac2014-08-26 00:18:21 -070017
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -070018import org.onlab.util.Tools;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.event.AbstractEvent;
20import org.onosproject.net.Host;
Charles Chanec0425c2015-11-11 12:09:38 -080021
22import static com.google.common.base.MoreObjects.toStringHelper;
tom64b7aac2014-08-26 00:18:21 -070023
24/**
25 * Describes end-station host event.
26 */
27public 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 /**
tom7869ad92014-09-09 14:32:08 -070044 * Signifies that host data changed, e.g. IP address
45 */
46 HOST_UPDATED,
47
48 /**
tom64b7aac2014-08-26 00:18:21 -070049 * Signifies that a host location has changed.
50 */
jobind19b7142019-05-17 09:46:52 -040051 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 */
59 HOST_UNSUSPENDED
tom64b7aac2014-08-26 00:18:21 -070060 }
61
Charles Chan33f28a92015-11-13 13:12:38 -080062 private Host prevSubject;
Charles Chanec0425c2015-11-11 12:09:38 -080063
tom64b7aac2014-08-26 00:18:21 -070064 /**
65 * Creates an event of a given type and for the specified host and the
66 * current time.
67 *
68 * @param type host event type
69 * @param host event host subject
70 */
71 public HostEvent(Type type, Host host) {
72 super(type, host);
73 }
74
75 /**
76 * Creates an event of a given type and for the specified host and time.
77 *
78 * @param type host event type
79 * @param host event host subject
80 * @param time occurrence time
81 */
82 public HostEvent(Type type, Host host, long time) {
83 super(type, host, time);
84 }
85
Charles Chanec0425c2015-11-11 12:09:38 -080086 /**
Charles Chan33f28a92015-11-13 13:12:38 -080087 * Creates an event with previous subject.
Charles Chanec0425c2015-11-11 12:09:38 -080088 *
Charles Chan33f28a92015-11-13 13:12:38 -080089 * The previous subject is ignored if the type is not moved or updated
90 *
91 * @param type host event type
Charles Chanec0425c2015-11-11 12:09:38 -080092 * @param host event host subject
Charles Chan33f28a92015-11-13 13:12:38 -080093 * @param prevSubject previous host subject
Charles Chanec0425c2015-11-11 12:09:38 -080094 */
Charles Chan33f28a92015-11-13 13:12:38 -080095 public HostEvent(Type type, Host host, Host prevSubject) {
96 super(type, host);
97 if (type == Type.HOST_MOVED || type == Type.HOST_UPDATED) {
98 this.prevSubject = prevSubject;
99 }
Charles Chanec0425c2015-11-11 12:09:38 -0800100 }
101
102 /**
Charles Chan33f28a92015-11-13 13:12:38 -0800103 * Gets the previous subject in this host event.
Charles Chanec0425c2015-11-11 12:09:38 -0800104 *
Charles Chan33f28a92015-11-13 13:12:38 -0800105 * @return the previous subject, or null if previous subject is not
Charles Chanec0425c2015-11-11 12:09:38 -0800106 * specified.
107 */
Charles Chan33f28a92015-11-13 13:12:38 -0800108 public Host prevSubject() {
109 return this.prevSubject;
Charles Chanec0425c2015-11-11 12:09:38 -0800110 }
111
112 @Override
113 public String toString() {
114 return toStringHelper(this)
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -0700115 .add("time", Tools.defaultOffsetDataTime(time()))
Charles Chanec0425c2015-11-11 12:09:38 -0800116 .add("type", type())
117 .add("subject", subject())
Charles Chan33f28a92015-11-13 13:12:38 -0800118 .add("prevSubject", prevSubject())
Charles Chanec0425c2015-11-11 12:09:38 -0800119 .toString();
120 }
tom64b7aac2014-08-26 00:18:21 -0700121}