blob: 132ac111b4402712b169edd35ed4bb6bd14524a6 [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 */
Charles Chanf42939d2019-12-06 19:19:30 -080059 HOST_UNSUSPENDED,
60 /**
61 * Signifies that host auxiliary location has changed.
62 */
63 HOST_AUX_MOVED
tom64b7aac2014-08-26 00:18:21 -070064 }
65
Charles Chan33f28a92015-11-13 13:12:38 -080066 private Host prevSubject;
Charles Chanec0425c2015-11-11 12:09:38 -080067
tom64b7aac2014-08-26 00:18:21 -070068 /**
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 Chanec0425c2015-11-11 12:09:38 -080090 /**
Charles Chan33f28a92015-11-13 13:12:38 -080091 * Creates an event with previous subject.
Charles Chanec0425c2015-11-11 12:09:38 -080092 *
Charles Chan33f28a92015-11-13 13:12:38 -080093 * The previous subject is ignored if the type is not moved or updated
94 *
95 * @param type host event type
Charles Chanec0425c2015-11-11 12:09:38 -080096 * @param host event host subject
Charles Chan33f28a92015-11-13 13:12:38 -080097 * @param prevSubject previous host subject
Charles Chanec0425c2015-11-11 12:09:38 -080098 */
Charles Chan33f28a92015-11-13 13:12:38 -080099 public HostEvent(Type type, Host host, Host prevSubject) {
100 super(type, host);
Charles Chanf42939d2019-12-06 19:19:30 -0800101 if (type == Type.HOST_MOVED || type == Type.HOST_UPDATED || type == Type.HOST_AUX_MOVED) {
Charles Chan33f28a92015-11-13 13:12:38 -0800102 this.prevSubject = prevSubject;
103 }
Charles Chanec0425c2015-11-11 12:09:38 -0800104 }
105
106 /**
Charles Chan33f28a92015-11-13 13:12:38 -0800107 * Gets the previous subject in this host event.
Charles Chanec0425c2015-11-11 12:09:38 -0800108 *
Charles Chan33f28a92015-11-13 13:12:38 -0800109 * @return the previous subject, or null if previous subject is not
Charles Chanec0425c2015-11-11 12:09:38 -0800110 * specified.
111 */
Charles Chan33f28a92015-11-13 13:12:38 -0800112 public Host prevSubject() {
113 return this.prevSubject;
Charles Chanec0425c2015-11-11 12:09:38 -0800114 }
115
116 @Override
117 public String toString() {
118 return toStringHelper(this)
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -0700119 .add("time", Tools.defaultOffsetDataTime(time()))
Charles Chanec0425c2015-11-11 12:09:38 -0800120 .add("type", type())
121 .add("subject", subject())
Charles Chan33f28a92015-11-13 13:12:38 -0800122 .add("prevSubject", prevSubject())
Charles Chanec0425c2015-11-11 12:09:38 -0800123 .toString();
124 }
tom64b7aac2014-08-26 00:18:21 -0700125}