alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 1 | package org.onosproject.net.mcast; |
| 2 | |
| 3 | import com.google.common.collect.ImmutableSet; |
| 4 | import org.onosproject.net.ConnectPoint; |
| 5 | |
| 6 | import java.util.Collections; |
| 7 | import java.util.Optional; |
| 8 | import java.util.Set; |
| 9 | |
| 10 | import static com.google.common.base.Preconditions.checkNotNull; |
| 11 | |
| 12 | /** |
| 13 | * Multicast information as stored in the store. |
| 14 | */ |
| 15 | public final class McastRouteInfo { |
| 16 | |
| 17 | private static final String ROUTE_NOT_NULL = "Route cannot be null"; |
| 18 | |
| 19 | private final McastRoute route; |
| 20 | private final Optional<ConnectPoint> sink; |
| 21 | private final Optional<ConnectPoint> source; |
| 22 | private final Set<ConnectPoint> sinks; |
| 23 | |
| 24 | private McastRouteInfo(McastRoute route, ConnectPoint sink, |
| 25 | ConnectPoint source, Set<ConnectPoint> sinks) { |
| 26 | this.route = checkNotNull(route, ROUTE_NOT_NULL); |
| 27 | this.sink = Optional.ofNullable(sink); |
| 28 | this.source = Optional.ofNullable(source); |
| 29 | this.sinks = sinks; |
| 30 | } |
| 31 | |
| 32 | public static McastRouteInfo mcastRouteInfo(McastRoute route) { |
| 33 | return new McastRouteInfo(route, null, null, Collections.EMPTY_SET); |
| 34 | } |
| 35 | |
| 36 | public static McastRouteInfo mcastRouteInfo(McastRoute route, |
| 37 | ConnectPoint sink, |
| 38 | ConnectPoint source) { |
| 39 | return new McastRouteInfo(route, sink, source, Collections.EMPTY_SET); |
| 40 | } |
| 41 | |
| 42 | public static McastRouteInfo mcastRouteInfo(McastRoute route, |
| 43 | Set<ConnectPoint> sinks, |
| 44 | ConnectPoint source) { |
| 45 | return new McastRouteInfo(route, null, source, ImmutableSet.copyOf(sinks)); |
| 46 | } |
| 47 | |
| 48 | public boolean isComplete() { |
| 49 | return ((sink.isPresent() || sinks.size() > 0) && source.isPresent()); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * The route associated with this multicast information. |
| 54 | * |
| 55 | * @return a mulicast route |
| 56 | */ |
| 57 | public McastRoute route() { |
| 58 | return route; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * The source which has been removed or added. |
| 63 | |
| 64 | * @return an optional connect point |
| 65 | */ |
| 66 | public Optional<ConnectPoint> source() { |
| 67 | return source; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * The sink which has been removed or added. The field may not be set |
| 72 | * if the sink has not been detected yet or has been removed. |
| 73 | * |
| 74 | * @return an optional connect point |
| 75 | */ |
| 76 | public Optional<ConnectPoint> sink() { |
| 77 | return sink; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns the set of sinks associated with this route. Only valid with |
| 82 | * SOURCE_ADDED events. |
| 83 | * |
| 84 | * @return a set of connect points |
| 85 | */ |
| 86 | public Set<ConnectPoint> sinks() { |
| 87 | return sinks; |
| 88 | } |
| 89 | |
| 90 | } |