blob: caa0284f8f96918d1b7b8faf6b3e3040e85ad1ac [file] [log] [blame]
alshabiba9b2b5d2015-09-23 15:01:47 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
alshabiba9b2b5d2015-09-23 15:01:47 -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 */
alshabib2ce0c732015-10-02 11:20:39 +020016package org.onosproject.net.mcast;
alshabiba9b2b5d2015-09-23 15:01:47 -070017
18import org.onosproject.event.AbstractEvent;
alshabiba9b2b5d2015-09-23 15:01:47 -070019
Pier Luigi57d41792018-02-26 12:31:38 +010020import java.util.Objects;
21
alshabibed0951f2015-10-02 21:39:27 +020022import static com.google.common.base.MoreObjects.toStringHelper;
23
alshabiba9b2b5d2015-09-23 15:01:47 -070024/**
25 * An entity representing a multicast event. Event either add or remove
26 * sinks or sources.
Ray Milkey50b14582017-08-23 09:55:02 -070027 *
28 * @deprecated in 1.11 ("Loon") release. To be moved into an app.
alshabiba9b2b5d2015-09-23 15:01:47 -070029 */
Ray Milkey50b14582017-08-23 09:55:02 -070030@Deprecated
alshabib79e52872015-12-07 16:01:01 -080031public class McastEvent extends AbstractEvent<McastEvent.Type, McastRouteInfo> {
alshabiba9b2b5d2015-09-23 15:01:47 -070032
alshabiba9b2b5d2015-09-23 15:01:47 -070033
34 public enum Type {
35 /**
36 * A new mcast route has been added.
37 */
38 ROUTE_ADDED,
39
40 /**
41 * A mcast route has been removed.
42 */
43 ROUTE_REMOVED,
44
45 /**
46 * A source for a mcast route (ie. the subject) has been added.
47 */
48 SOURCE_ADDED,
49
50 /**
Pier Luigi57d41792018-02-26 12:31:38 +010051 * A source for a mcast route has been updated.
52 */
53 SOURCE_UPDATED,
54
55 /**
alshabiba9b2b5d2015-09-23 15:01:47 -070056 * A sink for a mcast route (ie. the subject) has been added.
57 */
58 SINK_ADDED,
59
60 /**
61 * A source for a mcast route (ie. the subject) has been removed.
62 */
63 SINK_REMOVED
64 }
65
Pier Luigi57d41792018-02-26 12:31:38 +010066 // Used when an update event happens
67 private McastRouteInfo prevSubject;
68
69 /**
70 * Creates a McastEvent of a given type using the subject.
71 *
72 * @param type the event type
73 * @param subject the subject of the event type
74 */
alshabib79e52872015-12-07 16:01:01 -080075 public McastEvent(McastEvent.Type type, McastRouteInfo subject) {
alshabiba9b2b5d2015-09-23 15:01:47 -070076 super(type, subject);
alshabiba9b2b5d2015-09-23 15:01:47 -070077 }
78
Pier Luigi57d41792018-02-26 12:31:38 +010079 /**
80 * Creates a McastEvent of a given type using the subject and
81 * the previous subject.
82 *
83 * @param type the event type
84 * @param subject the subject of the event
85 * @param prevSubject the previous subject of the event
86 */
87 public McastEvent(McastEvent.Type type, McastRouteInfo subject,
88 McastRouteInfo prevSubject) {
89 super(type, subject);
90 // For now we have just this kind of updates
91 if (type == Type.SOURCE_UPDATED) {
92 this.prevSubject = prevSubject;
93 }
94 }
95
96 /**
97 * Gets the previous subject in this mcast event.
98 *
99 * @return the previous subject, or null if previous subject is not
100 * specified.
101 */
102 public McastRouteInfo prevSubject() {
103 return this.prevSubject;
104 }
105
106 @Override
107 public int hashCode() {
108 return Objects.hash(type(), subject(), prevSubject);
109 }
110
111 @Override
112 public boolean equals(Object other) {
113 if (this == other) {
114 return true;
115 }
116
117 if (!(other instanceof McastEvent)) {
118 return false;
119 }
120
121 McastEvent that = (McastEvent) other;
122
123 return Objects.equals(this.subject(), that.subject()) &&
124 Objects.equals(this.type(), that.type()) &&
125 Objects.equals(this.prevSubject, that.prevSubject);
126 }
alshabibed0951f2015-10-02 21:39:27 +0200127
128 @Override
129 public String toString() {
130 return toStringHelper(this)
131 .add("type", type())
Pier Luigi57d41792018-02-26 12:31:38 +0100132 .add("info", subject())
133 .add("prevInfo", prevSubject())
134 .toString();
alshabibed0951f2015-10-02 21:39:27 +0200135 }
alshabiba9b2b5d2015-09-23 15:01:47 -0700136}