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 MvpnRouteKey key, final Attributes attributes) {
92 final MvpnRouteBuilder builder;
94 builder = new MvpnRouteBuilder(route);
96 builder = new MvpnRouteBuilder();
98 return builder.withKey(key).setAttributes(attributes).build();
102 public final MvpnRouteKey createRouteListKey(final PathId pathId, final String routeKey) {
103 return new MvpnRouteKey(pathId, routeKey);
107 public final List<MvpnRoute> routesFromContainer(final S container) {
108 return container.getMvpnRoute();
111 final MvpnChoice extractMvpnChoice(final DataContainerNode<? extends PathArgument> route) {
112 final DataObject nn = this.mappingService.fromNormalizedNode(this.routeDefaultYii, route).getValue();
113 return ((MvpnRoute) nn).getMvpnChoice();
117 protected final Collection<NodeIdentifierWithPredicates> processDestination(
118 final DOMDataWriteTransaction tx,
119 final YangInstanceIdentifier routesPath,
120 final ContainerNode destination,
121 final ContainerNode attributes,
122 final ApplyRoute function) {
123 if (destination != null) {
124 final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = destination
125 .getChild(this.nlriRoutesList);
126 if (maybeRoutes.isPresent()) {
127 final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
128 if (routes instanceof UnkeyedListNode) {
129 final YangInstanceIdentifier base = routesYangInstanceIdentifier(routesPath);
130 final Collection<UnkeyedListEntryNode> routesList = ((UnkeyedListNode) routes).getValue();
131 final List<NodeIdentifierWithPredicates> keys = new ArrayList<>(routesList.size());
132 for (final UnkeyedListEntryNode mvpnDest : routesList) {
133 final NodeIdentifierWithPredicates routeKey = createRouteKey(mvpnDest);
134 function.apply(tx, base, routeKey, mvpnDest, attributes);
139 LOG.warn("Routes {} are not a map", routes);
143 return Collections.emptyList();
148 public final PathId extractPathId(final MvpnRouteKey routeListKey) {
149 return routeListKey.getPathId();
153 public final String extractRouteKey(final MvpnRouteKey routeListKey) {
154 return routeListKey.getRouteKey();
157 abstract NodeIdentifierWithPredicates createRouteKey(UnkeyedListEntryNode mvpn);