blob: a117cc41a6d21e85059407d8ad45a5e70fc5d3c7 [file] [log] [blame]
Andrea Campanella545edb42018-03-20 16:37:29 -07001/*
2 * Copyright 2018-present Open Networking Foundation
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 */
16package org.onosproject.mcast.api;
17
18import com.google.common.annotations.Beta;
19import org.onosproject.net.ConnectPoint;
20import org.onosproject.net.HostId;
21
22import java.util.Map;
23import java.util.Objects;
24import java.util.Set;
25
26import static com.google.common.base.MoreObjects.toStringHelper;
27import static com.google.common.base.Preconditions.checkNotNull;
28
29/**
30 * Utility class to propagate updates to multicast route information stored in the store.
31 */
32@Beta
33public final class McastRouteUpdate {
34
35 private static final String ROUTE_NOT_NULL = "Route cannot be null";
36 private static final String SOURCE_NOT_NULL = "Source cannot be null";
37 private static final String SINK_NOT_NULL = "Sink cannot be null";
38
39 private final McastRoute route;
Andrea Campanella0ddf9b82018-04-27 15:54:42 +020040 private final Map<HostId, Set<ConnectPoint>> sources;
Andrea Campanella545edb42018-03-20 16:37:29 -070041 private final Map<HostId, Set<ConnectPoint>> sinks;
42
Andrea Campanella0ddf9b82018-04-27 15:54:42 +020043 private McastRouteUpdate(McastRoute route,
44 Map<HostId, Set<ConnectPoint>> sources,
45 Map<HostId, Set<ConnectPoint>> sinks) {
Andrea Campanella545edb42018-03-20 16:37:29 -070046 this.route = checkNotNull(route, ROUTE_NOT_NULL);
Andrea Campanella0ddf9b82018-04-27 15:54:42 +020047 this.sources = checkNotNull(sources, SOURCE_NOT_NULL);
Andrea Campanella545edb42018-03-20 16:37:29 -070048 this.sinks = checkNotNull(sinks, SINK_NOT_NULL);
49 }
50
51 /**
52 * Static method to create an McastRoutUpdate object.
53 *
54 * @param route the route updated
55 * @param sources the different sources
56 * @param sinks the different sinks
57 * @return the McastRouteUpdate object.
58 */
59 public static McastRouteUpdate mcastRouteUpdate(McastRoute route,
Andrea Campanella0ddf9b82018-04-27 15:54:42 +020060 Map<HostId, Set<ConnectPoint>> sources,
Andrea Campanella545edb42018-03-20 16:37:29 -070061 Map<HostId, Set<ConnectPoint>> sinks) {
62 return new McastRouteUpdate(route, sources, sinks);
63 }
64
65 /**
66 * The route associated with this multicast information.
67 *
68 * @return a mulicast route
69 */
70 public McastRoute route() {
71 return route;
72 }
73
74 /**
75 * The sources.
76 *
Andrea Campanella0ddf9b82018-04-27 15:54:42 +020077 * @return a set of connect points
Andrea Campanella545edb42018-03-20 16:37:29 -070078 */
Andrea Campanella0ddf9b82018-04-27 15:54:42 +020079 public Map<HostId, Set<ConnectPoint>> sources() {
Andrea Campanella545edb42018-03-20 16:37:29 -070080 return sources;
81 }
82
83 /**
84 * The sinks.
85 *
86 * @return a set of connect points
87 */
88 public Map<HostId, Set<ConnectPoint>> sinks() {
89 return sinks;
90 }
91
92 @Override
93 public boolean equals(Object o) {
94 if (this == o) {
95 return true;
96 }
97 if (o == null || getClass() != o.getClass()) {
98 return false;
99 }
100 McastRouteUpdate that = (McastRouteUpdate) o;
101 return Objects.equals(route, that.route) &&
102 Objects.equals(sources, that.sources) &&
103 Objects.equals(sinks, that.sinks);
104 }
105
106 @Override
107 public int hashCode() {
108 return Objects.hash(route, sources, sinks);
109 }
110
111 @Override
112 public String toString() {
113 return toStringHelper(this)
114 .add("route", route())
115 .add("sources", sources)
116 .add("sinks", sinks)
117 .toString();
118 }
119}