blob: 20a0fb232f0d1844e28d5c60d387bf5430ed12ab [file] [log] [blame]
Brian O'Connor7cbbbb72016-04-09 02:13:23 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Brian O'Connor7cbbbb72016-04-09 02:13:23 -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 */
alshabib79e52872015-12-07 16:01:01 -080016package org.onosproject.net.mcast;
17
18import com.google.common.collect.ImmutableSet;
19import org.onosproject.net.ConnectPoint;
20
21import java.util.Collections;
22import java.util.Optional;
23import java.util.Set;
24
Charles Chand55e84d2016-03-30 17:54:24 -070025import static com.google.common.base.MoreObjects.toStringHelper;
alshabib79e52872015-12-07 16:01:01 -080026import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * Multicast information as stored in the store.
Ray Milkey50b14582017-08-23 09:55:02 -070030 *
31 * @deprecated in 1.11 ("Loon") release. To be moved into an app.
alshabib79e52872015-12-07 16:01:01 -080032 */
Ray Milkey50b14582017-08-23 09:55:02 -070033
34@Deprecated
alshabib79e52872015-12-07 16:01:01 -080035public 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 Hallcbd1b392017-01-18 20:15:44 -080069 return ((sink.isPresent() || !sinks.isEmpty()) && source.isPresent());
alshabib79e52872015-12-07 16:01:01 -080070 }
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 Chand55e84d2016-03-30 17:54:24 -0700110 @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 }
alshabib79e52872015-12-07 16:01:01 -0800119}