Brian O'Connor | 7cbbbb7 | 2016-04-09 02:13:23 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Brian O'Connor | 7cbbbb7 | 2016-04-09 02:13:23 -0700 | [diff] [blame] | 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 | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 16 | package org.onosproject.net.mcast; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableSet; |
| 19 | import org.onosproject.net.ConnectPoint; |
| 20 | |
| 21 | import java.util.Collections; |
| 22 | import java.util.Optional; |
| 23 | import java.util.Set; |
| 24 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 26 | import static com.google.common.base.Preconditions.checkNotNull; |
| 27 | |
| 28 | /** |
| 29 | * Multicast information as stored in the store. |
Ray Milkey | 50b1458 | 2017-08-23 09:55:02 -0700 | [diff] [blame] | 30 | * |
| 31 | * @deprecated in 1.11 ("Loon") release. To be moved into an app. |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 32 | */ |
Ray Milkey | 50b1458 | 2017-08-23 09:55:02 -0700 | [diff] [blame] | 33 | |
| 34 | @Deprecated |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 35 | public final class McastRouteInfo { |
| 36 | |
| 37 | private static final String ROUTE_NOT_NULL = "Route cannot be null"; |
| 38 | |
| 39 | private final McastRoute route; |
| 40 | private final Optional<ConnectPoint> sink; |
| 41 | private final Optional<ConnectPoint> source; |
| 42 | private final Set<ConnectPoint> sinks; |
| 43 | |
| 44 | private McastRouteInfo(McastRoute route, ConnectPoint sink, |
| 45 | ConnectPoint source, Set<ConnectPoint> sinks) { |
| 46 | this.route = checkNotNull(route, ROUTE_NOT_NULL); |
| 47 | this.sink = Optional.ofNullable(sink); |
| 48 | this.source = Optional.ofNullable(source); |
| 49 | this.sinks = sinks; |
| 50 | } |
| 51 | |
| 52 | public static McastRouteInfo mcastRouteInfo(McastRoute route) { |
| 53 | return new McastRouteInfo(route, null, null, Collections.EMPTY_SET); |
| 54 | } |
| 55 | |
| 56 | public static McastRouteInfo mcastRouteInfo(McastRoute route, |
| 57 | ConnectPoint sink, |
| 58 | ConnectPoint source) { |
| 59 | return new McastRouteInfo(route, sink, source, Collections.EMPTY_SET); |
| 60 | } |
| 61 | |
| 62 | public static McastRouteInfo mcastRouteInfo(McastRoute route, |
| 63 | Set<ConnectPoint> sinks, |
| 64 | ConnectPoint source) { |
| 65 | return new McastRouteInfo(route, null, source, ImmutableSet.copyOf(sinks)); |
| 66 | } |
| 67 | |
| 68 | public boolean isComplete() { |
Jon Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 69 | return ((sink.isPresent() || !sinks.isEmpty()) && source.isPresent()); |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /** |
| 73 | * The route associated with this multicast information. |
| 74 | * |
| 75 | * @return a mulicast route |
| 76 | */ |
| 77 | public McastRoute route() { |
| 78 | return route; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * The source which has been removed or added. |
| 83 | |
| 84 | * @return an optional connect point |
| 85 | */ |
| 86 | public Optional<ConnectPoint> source() { |
| 87 | return source; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * The sink which has been removed or added. The field may not be set |
| 92 | * if the sink has not been detected yet or has been removed. |
| 93 | * |
| 94 | * @return an optional connect point |
| 95 | */ |
| 96 | public Optional<ConnectPoint> sink() { |
| 97 | return sink; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Returns the set of sinks associated with this route. Only valid with |
| 102 | * SOURCE_ADDED events. |
| 103 | * |
| 104 | * @return a set of connect points |
| 105 | */ |
| 106 | public Set<ConnectPoint> sinks() { |
| 107 | return sinks; |
| 108 | } |
| 109 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 110 | @Override |
| 111 | public String toString() { |
| 112 | return toStringHelper(this) |
| 113 | .add("route", route()) |
| 114 | .add("sink", sink()) |
| 115 | .add("source", source()) |
| 116 | .add("sinks", sinks()) |
| 117 | .toString(); |
| 118 | } |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 119 | } |