blob: 9a47817ac0c9ac7caea4edf68a3913a338314250 [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
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.
30 */
31public final class McastRouteInfo {
32
33 private static final String ROUTE_NOT_NULL = "Route cannot be null";
34
35 private final McastRoute route;
36 private final Optional<ConnectPoint> sink;
37 private final Optional<ConnectPoint> source;
38 private final Set<ConnectPoint> sinks;
39
40 private McastRouteInfo(McastRoute route, ConnectPoint sink,
41 ConnectPoint source, Set<ConnectPoint> sinks) {
42 this.route = checkNotNull(route, ROUTE_NOT_NULL);
43 this.sink = Optional.ofNullable(sink);
44 this.source = Optional.ofNullable(source);
45 this.sinks = sinks;
46 }
47
48 public static McastRouteInfo mcastRouteInfo(McastRoute route) {
49 return new McastRouteInfo(route, null, null, Collections.EMPTY_SET);
50 }
51
52 public static McastRouteInfo mcastRouteInfo(McastRoute route,
53 ConnectPoint sink,
54 ConnectPoint source) {
55 return new McastRouteInfo(route, sink, source, Collections.EMPTY_SET);
56 }
57
58 public static McastRouteInfo mcastRouteInfo(McastRoute route,
59 Set<ConnectPoint> sinks,
60 ConnectPoint source) {
61 return new McastRouteInfo(route, null, source, ImmutableSet.copyOf(sinks));
62 }
63
64 public boolean isComplete() {
Jon Hallcbd1b392017-01-18 20:15:44 -080065 return ((sink.isPresent() || !sinks.isEmpty()) && source.isPresent());
alshabib79e52872015-12-07 16:01:01 -080066 }
67
68 /**
69 * The route associated with this multicast information.
70 *
71 * @return a mulicast route
72 */
73 public McastRoute route() {
74 return route;
75 }
76
77 /**
78 * The source which has been removed or added.
79
80 * @return an optional connect point
81 */
82 public Optional<ConnectPoint> source() {
83 return source;
84 }
85
86 /**
87 * The sink which has been removed or added. The field may not be set
88 * if the sink has not been detected yet or has been removed.
89 *
90 * @return an optional connect point
91 */
92 public Optional<ConnectPoint> sink() {
93 return sink;
94 }
95
96 /**
97 * Returns the set of sinks associated with this route. Only valid with
98 * SOURCE_ADDED events.
99 *
100 * @return a set of connect points
101 */
102 public Set<ConnectPoint> sinks() {
103 return sinks;
104 }
105
Charles Chand55e84d2016-03-30 17:54:24 -0700106 @Override
107 public String toString() {
108 return toStringHelper(this)
109 .add("route", route())
110 .add("sink", sink())
111 .add("source", source())
112 .add("sinks", sinks())
113 .toString();
114 }
alshabib79e52872015-12-07 16:01:01 -0800115}