blob: 9d26208167b50ba19679cd387b2001b747b792cc [file] [log] [blame]
Jonathan Hart4b5c6dc2015-10-13 14:27:48 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Jonathan Hart4b5c6dc2015-10-13 14:27:48 -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 */
16
Ray Milkeyfacf2862017-08-03 11:58:29 -070017package org.onosproject.net.intf;
Jonathan Hart4b5c6dc2015-10-13 14:27:48 -070018
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -070019import org.onlab.util.Tools;
Ray Milkeyfacf2862017-08-03 11:58:29 -070020import org.onosproject.event.AbstractEvent;
21
gaurav2c626cc2016-04-26 04:18:33 +053022import static com.google.common.base.MoreObjects.toStringHelper;
Jonathan Hart4b5c6dc2015-10-13 14:27:48 -070023
24/**
25 * Describes an interface event.
26 */
27public class InterfaceEvent extends AbstractEvent<InterfaceEvent.Type, Interface> {
28
gaurav2c626cc2016-04-26 04:18:33 +053029 private final Interface prevSubject;
30
Jonathan Hart4b5c6dc2015-10-13 14:27:48 -070031 public enum Type {
32 /**
33 * Indicates a new interface has been added.
34 */
35 INTERFACE_ADDED,
36
37 /**
38 * Indicates an interface has been updated.
39 */
40 INTERFACE_UPDATED,
41
42 /**
43 * Indicates an interface has been removed.
44 */
45 INTERFACE_REMOVED
46 }
47
48 /**
49 * Creates an interface event with type and subject.
50 *
51 * @param type event type
52 * @param subject subject interface
53 */
54 public InterfaceEvent(Type type, Interface subject) {
gaurav2c626cc2016-04-26 04:18:33 +053055 this(type, subject, null);
Jonathan Hart4b5c6dc2015-10-13 14:27:48 -070056 }
57
58 /**
gaurav2c626cc2016-04-26 04:18:33 +053059 * Creates an interface event with type, subject and time of event.
Jonathan Hart4b5c6dc2015-10-13 14:27:48 -070060 *
61 * @param type event type
62 * @param subject subject interface
63 * @param time time of event
64 */
65 public InterfaceEvent(Type type, Interface subject, long time) {
gaurav2c626cc2016-04-26 04:18:33 +053066 this(type, subject, null, time);
Jonathan Hart4b5c6dc2015-10-13 14:27:48 -070067 }
68
gaurav2c626cc2016-04-26 04:18:33 +053069 /**
70 * Creates an interface event with type, subject and previous subject.
71 *
72 * @param type event type
73 * @param subject subject interface
Charles Chanab69c2c2016-06-13 12:06:31 -070074 * @param prevSubject previous interface subject
gaurav2c626cc2016-04-26 04:18:33 +053075 */
76 public InterfaceEvent(Type type, Interface subject, Interface prevSubject) {
77 super(type, subject);
78 this.prevSubject = prevSubject;
79 }
80
81 /**
82 * Creates an interface event with type, subject, previous subject and time.
83 *
84 * @param type event type
85 * @param subject subject interface
Charles Chanab69c2c2016-06-13 12:06:31 -070086 * @param prevSubject previous interface subject
gaurav2c626cc2016-04-26 04:18:33 +053087 * @param time time of event
88 */
89 public InterfaceEvent(Type type, Interface subject, Interface prevSubject, long time) {
90 super(type, subject, time);
91 this.prevSubject = prevSubject;
92 }
93
94 /**
95 * Returns the previous interface subject.
96 *
97 * @return previous subject of interface or null if the event is not interface specific.
98 */
99 public Interface prevSubject() {
100 return prevSubject;
101 }
102
103 @Override
104 public String toString() {
105 if (prevSubject == null) {
106 return super.toString();
107 }
108 return toStringHelper(this)
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -0700109 .add("time", Tools.defaultOffsetDataTime(time()))
gaurav2c626cc2016-04-26 04:18:33 +0530110 .add("type", type())
111 .add("subject", subject())
112 .add("prevSubject", prevSubject)
113 .toString();
114 }
Jonathan Hart4b5c6dc2015-10-13 14:27:48 -0700115}