blob: 946d8c6efaf9997ceeeddae4cd101a3c35c02cbf [file] [log] [blame]
alshabibed0951f2015-10-02 21:39:27 +02001/*
2 * Copyright 2015 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 */
16package org.onosproject.incubator.net.mcast.impl;
17
18import com.google.common.collect.ImmutableList;
19import com.google.common.collect.Lists;
20import org.onosproject.net.ConnectPoint;
21
22import java.util.Collections;
23import java.util.List;
24
alshabibc6b60802015-10-06 11:42:50 +020025import static com.google.common.base.Preconditions.checkNotNull;
26
alshabibed0951f2015-10-02 21:39:27 +020027/**
28 * Simple entity maintaining a mapping between a source and a collection of sink
29 * connect points.
30 */
31public final class MulticastData {
32
33 private final ConnectPoint source;
34 private final List<ConnectPoint> sinks;
alshabibc6b60802015-10-06 11:42:50 +020035 private final boolean isEmpty;
alshabibed0951f2015-10-02 21:39:27 +020036
37 private MulticastData() {
38 this.source = null;
39 this.sinks = Collections.EMPTY_LIST;
alshabibc6b60802015-10-06 11:42:50 +020040 isEmpty = true;
alshabibed0951f2015-10-02 21:39:27 +020041 }
42
43 public MulticastData(ConnectPoint source, List<ConnectPoint> sinks) {
alshabibc6b60802015-10-06 11:42:50 +020044 this.source = checkNotNull(source, "Multicast source cannot be null.");
45 this.sinks = checkNotNull(sinks, "List of sinks cannot be null.");
46 isEmpty = false;
alshabibed0951f2015-10-02 21:39:27 +020047 }
48
49 public MulticastData(ConnectPoint source, ConnectPoint sink) {
alshabibc6b60802015-10-06 11:42:50 +020050 this.source = checkNotNull(source, "Multicast source cannot be null.");
51 this.sinks = Lists.newArrayList(checkNotNull(sink, "Sink cannot be null."));
52 isEmpty = false;
alshabibed0951f2015-10-02 21:39:27 +020053 }
54
55 public MulticastData(ConnectPoint source) {
alshabibc6b60802015-10-06 11:42:50 +020056 this.source = checkNotNull(source, "Multicast source cannot be null.");
alshabibed0951f2015-10-02 21:39:27 +020057 this.sinks = Lists.newArrayList();
alshabibc6b60802015-10-06 11:42:50 +020058 isEmpty = false;
alshabibed0951f2015-10-02 21:39:27 +020059 }
60
61 public ConnectPoint source() {
62 return source;
63 }
64
65 public List<ConnectPoint> sinks() {
66 return ImmutableList.copyOf(sinks);
67 }
68
69 public void appendSink(ConnectPoint sink) {
70 sinks.add(sink);
71 }
72
73 public boolean removeSink(ConnectPoint sink) {
74 return sinks.remove(sink);
75 }
76
77 public boolean isEmpty() {
alshabibc6b60802015-10-06 11:42:50 +020078 return isEmpty;
alshabibed0951f2015-10-02 21:39:27 +020079 }
80
81 public static MulticastData empty() {
82 return new MulticastData();
83 }
84
85}