blob: 979194c376c5d6260830e0c2f9a4f49019e6b7a5 [file] [log] [blame]
alshabiba9b2b5d2015-09-23 15:01:47 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
alshabib2ce0c732015-10-02 11:20:39 +020016package org.onosproject.net.mcast;
alshabiba9b2b5d2015-09-23 15:01:47 -070017
alshabib2ce0c732015-10-02 11:20:39 +020018import com.google.common.annotations.Beta;
alshabiba9b2b5d2015-09-23 15:01:47 -070019import org.onosproject.event.AbstractEvent;
20import org.onosproject.net.ConnectPoint;
21
22import java.util.Optional;
23
alshabibed0951f2015-10-02 21:39:27 +020024import static com.google.common.base.MoreObjects.toStringHelper;
25
alshabiba9b2b5d2015-09-23 15:01:47 -070026/**
27 * An entity representing a multicast event. Event either add or remove
28 * sinks or sources.
29 */
alshabib2ce0c732015-10-02 11:20:39 +020030@Beta
alshabiba9b2b5d2015-09-23 15:01:47 -070031public class McastEvent extends AbstractEvent<McastEvent.Type, McastRoute> {
32
33 private final Optional<ConnectPoint> sink;
34 private final Optional<ConnectPoint> source;
35
36 public enum Type {
37 /**
38 * A new mcast route has been added.
39 */
40 ROUTE_ADDED,
41
42 /**
43 * A mcast route has been removed.
44 */
45 ROUTE_REMOVED,
46
47 /**
48 * A source for a mcast route (ie. the subject) has been added.
49 */
50 SOURCE_ADDED,
51
52 /**
alshabiba9b2b5d2015-09-23 15:01:47 -070053 * A sink for a mcast route (ie. the subject) has been added.
54 */
55 SINK_ADDED,
56
57 /**
58 * A source for a mcast route (ie. the subject) has been removed.
59 */
60 SINK_REMOVED
61 }
62
63 private McastEvent(McastEvent.Type type, McastRoute subject) {
64 super(type, subject);
65 sink = Optional.empty();
66 source = Optional.empty();
67 }
68
69 private McastEvent(McastEvent.Type type, McastRoute subject, long time) {
70 super(type, subject, time);
71 sink = Optional.empty();
72 source = Optional.empty();
73 }
74
alshabibed0951f2015-10-02 21:39:27 +020075 public McastEvent(McastEvent.Type type, McastRoute subject,
76 ConnectPoint sink,
77 ConnectPoint source) {
alshabiba9b2b5d2015-09-23 15:01:47 -070078 super(type, subject);
79 this.sink = Optional.ofNullable(sink);
80 this.source = Optional.ofNullable(source);
81 }
82
alshabibed0951f2015-10-02 21:39:27 +020083 public McastEvent(McastEvent.Type type, McastRoute subject, long time,
alshabiba9b2b5d2015-09-23 15:01:47 -070084 ConnectPoint sink,
85 ConnectPoint source) {
86 super(type, subject, time);
87 this.sink = Optional.ofNullable(sink);
88 this.source = Optional.ofNullable(source);
89 }
90
91 /**
92 * The sink which has been removed or added. The field may not be set
93 * if the sink has not been detected yet or has been removed.
94 *
95 * @return an optional connect point
96 */
97 public Optional<ConnectPoint> sink() {
98 return sink;
99 }
100
101 /**
alshabibed0951f2015-10-02 21:39:27 +0200102 * The source which has been removed or added.
alshabiba9b2b5d2015-09-23 15:01:47 -0700103
104 * @return an optional connect point
105 */
106 public Optional<ConnectPoint> source() {
107 return source;
108 }
alshabibed0951f2015-10-02 21:39:27 +0200109
110 @Override
111 public String toString() {
112 return toStringHelper(this)
113 .add("type", type())
114 .add("route", subject())
115 .add("source", source)
116 .add("sinks", sink).toString();
117 }
alshabiba9b2b5d2015-09-23 15:01:47 -0700118}