*/
package org.opendaylight.protocol.bgp.flowspec;
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableCollection;
-import com.google.common.collect.ImmutableSet;
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.annotations.Beta;
import com.google.common.collect.Iterables;
import java.util.Collection;
-import javax.annotation.Nonnull;
+import java.util.Optional;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
-import org.opendaylight.protocol.bgp.rib.spi.MultiPathAbstractRIBSupport;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.FlowspecSubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.DestinationType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
+import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupport;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.SubsequentAddressFamily;
+import org.opendaylight.yangtools.yang.binding.ChildOf;
import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.Identifier;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-public abstract class AbstractFlowspecRIBSupport extends MultiPathAbstractRIBSupport {
- protected AbstractFlowspecRIBSupport(final Class<? extends Routes> cazeClass, final Class<? extends DataObject> containerClass,
- final Class<? extends Route> listClass, final Class<? extends AddressFamily> afiClass, final QName destinationQname) {
- super(cazeClass, containerClass, listClass, afiClass, FlowspecSubsequentAddressFamily.class, "route-key", destinationQname);
- }
-
- protected abstract AbstractFlowspecNlriParser getParser();
+@Beta
+public abstract class AbstractFlowspecRIBSupport<
+ T extends AbstractFlowspecNlriParser,
+ C extends Routes & DataObject,
+ S extends ChildOf<? super C>,
+ R extends Route & ChildOf<? super S> & Identifiable<I>,
+ I extends Identifier<R>> extends AbstractRIBSupport<C, S, R, I> {
+ protected final T nlriParser;
- @Override
- public final ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects() {
- return ImmutableSet.of();
- }
+ protected AbstractFlowspecRIBSupport(
+ final BindingNormalizedNodeSerializer mappingService,
+ final Class<C> cazeClass,
+ final Class<S> containerClass,
+ final Class<R> listClass,
+ final Class<? extends AddressFamily> afiClass,
+ final Class<? extends SubsequentAddressFamily> safiClass,
+ final QName dstContainerClassQName,
+ final T nlriParser
+ ) {
+ super(mappingService, cazeClass, containerClass, listClass, afiClass, safiClass, dstContainerClassQName);
- @Override
- public final ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects() {
- return ImmutableSet.of();
- }
-
- @Override
- public final boolean isComplexRoute() {
- return true;
+ this.nlriParser = requireNonNull(nlriParser);
}
- @Nonnull
@Override
- protected DestinationType buildDestination(@Nonnull final Collection<MapEntryNode> routes) {
+ protected DestinationType buildDestination(final Collection<MapEntryNode> routes) {
final MapEntryNode routesCont = Iterables.getOnlyElement(routes);
final PathId pathId = PathIdUtil.buildPathId(routesCont, routePathIdNid());
- return getParser().createAdvertizedRoutesDestinationType(new Object[] {getParser().extractFlowspec(routesCont)}, pathId);
+ return this.nlriParser.createAdvertizedRoutesDestinationType(
+ new Object[] {this.nlriParser.extractFlowspec(routesCont)},
+ pathId
+ );
}
- @Nonnull
@Override
- protected DestinationType buildWithdrawnDestination(@Nonnull final Collection<MapEntryNode> routes) {
+ protected DestinationType buildWithdrawnDestination(final Collection<MapEntryNode> routes) {
final MapEntryNode routesCont = Iterables.getOnlyElement(routes);
final PathId pathId = PathIdUtil.buildPathId(routesCont, routePathIdNid());
- return getParser().createWithdrawnDestinationType(new Object[] {getParser().extractFlowspec(Iterables.getOnlyElement(routes))}, pathId);
+ return this.nlriParser.createWithdrawnDestinationType(
+ new Object[] {this.nlriParser.extractFlowspec(Iterables.getOnlyElement(routes))},
+ pathId
+ );
}
@Override
- protected final void processDestination(final DOMDataWriteTransaction tx, final YangInstanceIdentifier routesPath,
- final ContainerNode destination, final ContainerNode attributes, final ApplyRoute function) {
+ protected final void processDestination(
+ final DOMDataWriteTransaction tx,
+ final YangInstanceIdentifier routesPath,
+ final ContainerNode destination,
+ final ContainerNode attributes,
+ final ApplyRoute function
+ ) {
if (destination != null) {
final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeQName());
- final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf = destination.getChild(routePathIdNid());
- final String routeKeyValue = getParser().stringNlri(destination);
- final NodeIdentifierWithPredicates routeKey = PathIdUtil.createNidKey(routeQName(), routeKeyQName(), pathIdQName(), routeKeyValue, maybePathIdLeaf);
+ final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf
+ = destination.getChild(routePathIdNid());
+ final String routeKeyValue = this.nlriParser.stringNlri(destination);
+ final NodeIdentifierWithPredicates routeKey = PathIdUtil.createNidKey(routeQName(), routeKeyQName(),
+ pathIdQName(), routeKeyValue, maybePathIdLeaf);
function.apply(tx, base, routeKey, destination, attributes);
}
}