alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
alshabib | 2ce0c73 | 2015-10-02 11:20:39 +0200 | [diff] [blame] | 16 | package org.onosproject.net.mcast; |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 17 | |
alshabib | 2ce0c73 | 2015-10-02 11:20:39 +0200 | [diff] [blame] | 18 | import com.google.common.annotations.Beta; |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 19 | import org.onosproject.event.AbstractEvent; |
| 20 | import org.onosproject.net.ConnectPoint; |
| 21 | |
| 22 | import java.util.Optional; |
| 23 | |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 26 | /** |
| 27 | * An entity representing a multicast event. Event either add or remove |
| 28 | * sinks or sources. |
| 29 | */ |
alshabib | 2ce0c73 | 2015-10-02 11:20:39 +0200 | [diff] [blame] | 30 | @Beta |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 31 | public 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 | /** |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 53 | * 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 | |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 75 | public McastEvent(McastEvent.Type type, McastRoute subject, |
| 76 | ConnectPoint sink, |
| 77 | ConnectPoint source) { |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 78 | super(type, subject); |
| 79 | this.sink = Optional.ofNullable(sink); |
| 80 | this.source = Optional.ofNullable(source); |
| 81 | } |
| 82 | |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 83 | public McastEvent(McastEvent.Type type, McastRoute subject, long time, |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 84 | 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 | /** |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 102 | * The source which has been removed or added. |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 103 | |
| 104 | * @return an optional connect point |
| 105 | */ |
| 106 | public Optional<ConnectPoint> source() { |
| 107 | return source; |
| 108 | } |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 109 | |
| 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 | } |
alshabib | a9b2b5d | 2015-09-23 15:01:47 -0700 | [diff] [blame] | 118 | } |