All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.onosproject.net.mcast.McastRouteInfo Maven / Gradle / Ivy

There is a newer version: 2.7.0
Show newest version
package org.onosproject.net.mcast;

import com.google.common.collect.ImmutableSet;
import org.onosproject.net.ConnectPoint;

import java.util.Collections;
import java.util.Optional;
import java.util.Set;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Multicast information as stored in the store.
 */
public final class McastRouteInfo {

    private static final String ROUTE_NOT_NULL = "Route cannot be null";

    private final McastRoute route;
    private final Optional sink;
    private final Optional source;
    private final Set sinks;

    private McastRouteInfo(McastRoute route, ConnectPoint sink,
                           ConnectPoint source, Set sinks) {
        this.route = checkNotNull(route, ROUTE_NOT_NULL);
        this.sink = Optional.ofNullable(sink);
        this.source = Optional.ofNullable(source);
        this.sinks = sinks;
    }

    public static McastRouteInfo mcastRouteInfo(McastRoute route) {
        return new McastRouteInfo(route, null, null, Collections.EMPTY_SET);
    }

    public static McastRouteInfo mcastRouteInfo(McastRoute route,
                                                ConnectPoint sink,
                                                ConnectPoint source) {
        return new McastRouteInfo(route, sink, source, Collections.EMPTY_SET);
    }

    public static McastRouteInfo mcastRouteInfo(McastRoute route,
                                                Set sinks,
                                                ConnectPoint source) {
        return new McastRouteInfo(route, null, source, ImmutableSet.copyOf(sinks));
    }

    public boolean isComplete() {
        return ((sink.isPresent() || sinks.size() > 0) && source.isPresent());
    }

    /**
     * The route associated with this multicast information.
     *
     * @return a mulicast route
     */
    public McastRoute route() {
        return route;
    }

    /**
     * The source which has been removed or added.

     * @return an optional connect point
     */
    public Optional source() {
        return source;
    }

    /**
     * The sink which has been removed or added. The field may not be set
     * if the sink has not been detected yet or has been removed.
     *
     * @return an optional connect point
     */
    public Optional sink() {
        return sink;
    }

    /**
     * Returns the set of sinks associated with this route. Only valid with
     * SOURCE_ADDED events.
     *
     * @return a set of connect points
     */
    public Set sinks() {
        return sinks;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy