blob: 31e51a0d1e8f46539b758723e23f12c67c50a8b7 [file] [log] [blame]
Brian O'Connor7cbbbb72016-04-09 02:13:23 -07001/*
2 * Copyright 2015-present 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 */
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
25import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * Multicast information as stored in the store.
29 */
30public final class McastRouteInfo {
31
32 private static final String ROUTE_NOT_NULL = "Route cannot be null";
33
34 private final McastRoute route;
35 private final Optional<ConnectPoint> sink;
36 private final Optional<ConnectPoint> source;
37 private final Set<ConnectPoint> sinks;
38
39 private McastRouteInfo(McastRoute route, ConnectPoint sink,
40 ConnectPoint source, Set<ConnectPoint> sinks) {
41 this.route = checkNotNull(route, ROUTE_NOT_NULL);
42 this.sink = Optional.ofNullable(sink);
43 this.source = Optional.ofNullable(source);
44 this.sinks = sinks;
45 }
46
47 public static McastRouteInfo mcastRouteInfo(McastRoute route) {
48 return new McastRouteInfo(route, null, null, Collections.EMPTY_SET);
49 }
50
51 public static McastRouteInfo mcastRouteInfo(McastRoute route,
52 ConnectPoint sink,
53 ConnectPoint source) {
54 return new McastRouteInfo(route, sink, source, Collections.EMPTY_SET);
55 }
56
57 public static McastRouteInfo mcastRouteInfo(McastRoute route,
58 Set<ConnectPoint> sinks,
59 ConnectPoint source) {
60 return new McastRouteInfo(route, null, source, ImmutableSet.copyOf(sinks));
61 }
62
63 public boolean isComplete() {
64 return ((sink.isPresent() || sinks.size() > 0) && source.isPresent());
65 }
66
67 /**
68 * The route associated with this multicast information.
69 *
70 * @return a mulicast route
71 */
72 public McastRoute route() {
73 return route;
74 }
75
76 /**
77 * The source which has been removed or added.
78
79 * @return an optional connect point
80 */
81 public Optional<ConnectPoint> source() {
82 return source;
83 }
84
85 /**
86 * The sink which has been removed or added. The field may not be set
87 * if the sink has not been detected yet or has been removed.
88 *
89 * @return an optional connect point
90 */
91 public Optional<ConnectPoint> sink() {
92 return sink;
93 }
94
95 /**
96 * Returns the set of sinks associated with this route. Only valid with
97 * SOURCE_ADDED events.
98 *
99 * @return a set of connect points
100 */
101 public Set<ConnectPoint> sinks() {
102 return sinks;
103 }
104
105}