2 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.protocol.bgp.mvpn.impl;
11 import com.google.common.collect.ImmutableCollection;
12 import com.google.common.collect.ImmutableSet;
13 import java.util.ArrayList;
14 import java.util.Collection;
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.Optional;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
19 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
20 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupport;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.McastVpnSubsequentAddressFamily;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.MvpnRoutes;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.mvpn.MvpnChoice;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.mvpn.routes.MvpnRoute;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.mvpn.routes.MvpnRouteBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.mvpn.routes.MvpnRouteKey;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.AddressFamily;
32 import org.opendaylight.yangtools.yang.binding.ChildOf;
33 import org.opendaylight.yangtools.yang.binding.ChoiceIn;
34 import org.opendaylight.yangtools.yang.binding.DataObject;
35 import org.opendaylight.yangtools.yang.common.QName;
36 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
37 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
38 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
39 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
40 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
41 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
42 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
43 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
44 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
49 * Abstract Mvpn RIBSupport.
51 * @author Claudio D. Gasparini
53 abstract class AbstractMvpnRIBSupport<C extends Routes & DataObject & ChoiceIn<Tables>,
54 S extends ChildOf<? super C> & MvpnRoutes> extends AbstractRIBSupport<C, S, MvpnRoute, MvpnRouteKey> {
55 private static final Logger LOG = LoggerFactory.getLogger(AbstractMvpnRIBSupport.class);
56 private final NodeIdentifier nlriRoutesList;
57 private final ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects;
60 * Default constructor. Requires the QName of the container augmented under the routes choice
61 * node in instantiations of the rib grouping. It is assumed that this container is defined by
62 * the same model which populates it with route grouping instantiation, and by extension with
63 * the route attributes container.
65 * @param mappingService Serialization service
66 * @param cazeClass Binding class of the AFI/SAFI-specific case statement, must not be null
67 * @param afiClass address Family Class
68 * @param destContainerQname destination container Qname
69 * @param destListQname destinations list Qname
71 AbstractMvpnRIBSupport(
72 final BindingNormalizedNodeSerializer mappingService,
73 final Class<C> cazeClass,
74 final Class<S> containerClass,
75 final Class<? extends AddressFamily> afiClass,
76 final QName destContainerQname,
77 final QName destListQname) {
78 super(mappingService, cazeClass, containerClass, MvpnRoute.class, afiClass,
79 McastVpnSubsequentAddressFamily.class, destContainerQname);
80 this.nlriRoutesList = NodeIdentifier.create(destListQname);
81 this.cacheableNlriObjects = ImmutableSet.of(cazeClass);
86 public final ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects() {
87 return this.cacheableNlriObjects;
91 public final MvpnRoute createRoute(final MvpnRoute route, final String routeKey, final long pathId,
92 final Attributes attributes) {
93 final MvpnRouteBuilder builder;
95 builder = new MvpnRouteBuilder(route);
97 builder = new MvpnRouteBuilder();
99 return builder.withKey(createRouteListKey(pathId, routeKey)).setAttributes(attributes).build();
103 public final MvpnRouteKey createRouteListKey(final long pathId, final String routeKey) {
104 return new MvpnRouteKey(new PathId(pathId), routeKey);
108 public final List<MvpnRoute> routesFromContainer(final S container) {
109 return container.getMvpnRoute();
112 final MvpnChoice extractMvpnChoice(final DataContainerNode<? extends PathArgument> route) {
113 final DataObject nn = this.mappingService.fromNormalizedNode(this.routeDefaultYii, route).getValue();
114 return ((MvpnRoute) nn).getMvpnChoice();
118 protected final Collection<NodeIdentifierWithPredicates> processDestination(
119 final DOMDataWriteTransaction tx,
120 final YangInstanceIdentifier routesPath,
121 final ContainerNode destination,
122 final ContainerNode attributes,
123 final ApplyRoute function) {
124 if (destination != null) {
125 final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = destination
126 .getChild(this.nlriRoutesList);
127 if (maybeRoutes.isPresent()) {
128 final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
129 if (routes instanceof UnkeyedListNode) {
130 final YangInstanceIdentifier base = routesYangInstanceIdentifier(routesPath);
131 final Collection<UnkeyedListEntryNode> routesList = ((UnkeyedListNode) routes).getValue();
132 final List<NodeIdentifierWithPredicates> keys = new ArrayList<>(routesList.size());
133 for (final UnkeyedListEntryNode mvpnDest : routesList) {
134 final NodeIdentifierWithPredicates routeKey = createRouteKey(mvpnDest);
135 function.apply(tx, base, routeKey, mvpnDest, attributes);
140 LOG.warn("Routes {} are not a map", routes);
144 return Collections.emptyList();
147 abstract NodeIdentifierWithPredicates createRouteKey(UnkeyedListEntryNode mvpn);