2 * Copyright (c) 2015 Cisco Systems, Inc. and others. 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
8 package org.opendaylight.protocol.bgp.rib.spi;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.cache.CacheBuilder;
14 import com.google.common.cache.CacheLoader;
15 import com.google.common.cache.LoadingCache;
16 import java.util.Collection;
17 import java.util.Collections;
18 import java.util.Optional;
19 import javax.annotation.Nonnull;
20 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
21 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
22 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
23 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.UpdateBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1Builder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2Builder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlri;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlriBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlri;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlriBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutes;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutes;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.BgpRib;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.Rib;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.LocRib;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.AddressFamily;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.RouteDistinguisher;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.RouteDistinguisherBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.SubsequentAddressFamily;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.CNextHop;
54 import org.opendaylight.yangtools.yang.binding.ChildOf;
55 import org.opendaylight.yangtools.yang.binding.ChoiceIn;
56 import org.opendaylight.yangtools.yang.binding.DataObject;
57 import org.opendaylight.yangtools.yang.binding.Identifiable;
58 import org.opendaylight.yangtools.yang.binding.Identifier;
59 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
60 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
61 import org.opendaylight.yangtools.yang.common.QName;
62 import org.opendaylight.yangtools.yang.common.QNameModule;
63 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
64 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
65 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
66 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
67 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
68 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
69 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
70 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
71 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
72 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
73 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
74 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
75 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
76 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
77 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
78 import org.slf4j.Logger;
79 import org.slf4j.LoggerFactory;
82 public abstract class AbstractRIBSupport<
83 C extends Routes & DataObject & ChoiceIn<Tables>,
84 S extends ChildOf<? super C>,
85 R extends Route & ChildOf<? super S> & Identifiable<I>,
86 I extends Identifier<R>>
87 implements RIBSupport<C, S, R, I> {
88 public static final String ROUTE_KEY = "route-key";
89 private static final Logger LOG = LoggerFactory.getLogger(AbstractRIBSupport.class);
90 private static final NodeIdentifier ADVERTISED_ROUTES = new NodeIdentifier(AdvertizedRoutes.QNAME);
91 private static final NodeIdentifier WITHDRAWN_ROUTES = new NodeIdentifier(WithdrawnRoutes.QNAME);
92 private static final NodeIdentifier DESTINATION_TYPE = new NodeIdentifier(DestinationType.QNAME);
93 private static final InstanceIdentifier<Tables> TABLES_II = InstanceIdentifier.create(BgpRib.class)
94 .child(Rib.class).child(LocRib.class).child(Tables.class);
95 private static final NodeIdentifier ROUTES = new NodeIdentifier(Routes.QNAME);
96 private static final ApplyRoute DELETE_ROUTE = new DeleteRoute();
97 // Instance identifier to table/(choice routes)/(map of route)
98 private final LoadingCache<YangInstanceIdentifier, YangInstanceIdentifier> routesPath = CacheBuilder.newBuilder()
99 .weakValues().build(new CacheLoader<YangInstanceIdentifier, YangInstanceIdentifier>() {
101 public YangInstanceIdentifier load(@Nonnull final YangInstanceIdentifier routesTablePaths) {
102 return routesTablePaths.node(routesContainerIdentifier()).node(routeQName());
105 private final NodeIdentifier routesContainerIdentifier;
106 private final NodeIdentifier routesListIdentifier;
107 private final NodeIdentifier routeAttributesIdentifier;
108 private final Class<C> cazeClass;
109 private final Class<S> containerClass;
110 private final Class<R> listClass;
111 private final ApplyRoute putRoute = new PutRoute();
112 private final MapEntryNode emptyTable;
113 private final QName routeQname;
114 private final Class<? extends AddressFamily> afiClass;
115 private final Class<? extends SubsequentAddressFamily> safiClass;
116 private final NodeIdentifier destinationNid;
117 private final QName pathIdQname;
118 private final NodeIdentifier pathIdNid;
119 private final QName routeKeyQname;
120 private final NodeIdentifier prefixTypeNid;
121 private final NodeIdentifier rdNid;
122 protected final BindingNormalizedNodeSerializer mappingService;
123 protected final YangInstanceIdentifier routeDefaultYii;
124 private final TablesKey tk;
127 * Default constructor. Requires the QName of the container augmented under the routes choice
128 * node in instantiations of the rib grouping. It is assumed that this container is defined by
129 * the same model which populates it with route grouping instantiation, and by extension with
130 * the route attributes container.
132 * @param mappingService Serialization service
133 * @param cazeClass Binding class of the AFI/SAFI-specific case statement, must not be null
134 * @param containerClass Binding class of the container in routes choice, must not be null.
135 * @param listClass Binding class of the route list, nust not be null;
136 * @param afiClass address Family Class
137 * @param safiClass SubsequentAddressFamily
138 * @param destContainerQname destination Container Qname
140 protected AbstractRIBSupport(
141 final BindingNormalizedNodeSerializer mappingService,
142 final Class<C> cazeClass,
143 final Class<S> containerClass,
144 final Class<R> listClass,
145 final Class<? extends AddressFamily> afiClass,
146 final Class<? extends SubsequentAddressFamily> safiClass,
147 final QName destContainerQname) {
148 final QNameModule module = BindingReflections.getQNameModule(cazeClass);
149 this.routesContainerIdentifier
150 = new NodeIdentifier(BindingReflections.findQName(containerClass).withModule(module));
151 this.routeAttributesIdentifier = new NodeIdentifier(Attributes.QNAME.withModule(module));
152 this.cazeClass = requireNonNull(cazeClass);
153 this.mappingService = requireNonNull(mappingService);
154 this.containerClass = requireNonNull(containerClass);
155 this.listClass = requireNonNull(listClass);
156 this.routeQname = BindingReflections.findQName(listClass).withModule(module);
157 this.routesListIdentifier = new NodeIdentifier(this.routeQname);
158 this.tk = new TablesKey(afiClass, safiClass);
159 this.emptyTable = (MapEntryNode) this.mappingService
160 .toNormalizedNode(TABLES_II, new TablesBuilder().withKey(tk)
161 .setAttributes(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib
162 .rev180329.rib.tables.AttributesBuilder().build()).build()).getValue();
163 this.afiClass = afiClass;
164 this.safiClass = safiClass;
165 this.destinationNid = new NodeIdentifier(destContainerQname);
166 this.pathIdQname = QName.create(routeQName(), "path-id").intern();
167 this.pathIdNid = new NodeIdentifier(this.pathIdQname);
168 this.routeKeyQname = QName.create(routeQName(), ROUTE_KEY).intern();
169 this.prefixTypeNid = NodeIdentifier.create(QName.create(destContainerQname, "prefix").intern());
170 this.rdNid = NodeIdentifier.create(QName.create(destContainerQname, "route-distinguisher").intern());
171 this.routeDefaultYii =
172 YangInstanceIdentifier.builder()
180 .node(BindingReflections.findQName(containerClass).withModule(module))
181 .node(this.routeQname)
182 .node(this.routeQname).build();
186 public final TablesKey getTablesKey() {
191 public final Class<C> routesCaseClass() {
192 return this.cazeClass;
196 public final Class<S> routesContainerClass() {
197 return this.containerClass;
201 public final Class<R> routesListClass() {
202 return this.listClass;
206 public final MapEntryNode emptyTable() {
207 return this.emptyTable;
210 public final QName routeQName() {
211 return this.routeQname;
214 protected final NodeIdentifier prefixNid() {
215 return this.prefixTypeNid;
218 protected final NodeIdentifier routeNid() {
219 return this.routesListIdentifier;
223 public final Class<? extends AddressFamily> getAfi() {
224 return this.afiClass;
228 public final Class<? extends SubsequentAddressFamily> getSafi() {
229 return this.safiClass;
233 * Build MpReachNlri object from DOM representation.
235 * @param routes Collection of MapEntryNode DOM representation of routes
236 * @param hop CNextHop as it was parsed from Attributes, to be included in MpReach object
237 * @return MpReachNlri
239 private MpReachNlri buildReach(final Collection<MapEntryNode> routes, final CNextHop hop) {
240 final MpReachNlriBuilder mb = new MpReachNlriBuilder();
241 mb.setAfi(this.getAfi());
242 mb.setSafi(this.getSafi());
244 mb.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(buildDestination(routes)).build());
249 * Build MpUnReachNlri object from DOM representation.
251 * @param routes Collection of MapEntryNode DOM representation of routes
252 * @return MpUnreachNlri
254 private MpUnreachNlri buildUnreach(final Collection<MapEntryNode> routes) {
255 final MpUnreachNlriBuilder mb = new MpUnreachNlriBuilder();
256 mb.setAfi(this.getAfi());
257 mb.setSafi(this.getSafi());
258 mb.setWithdrawnRoutes(new WithdrawnRoutesBuilder()
259 .setDestinationType(buildWithdrawnDestination(routes)).build());
263 protected abstract DestinationType buildDestination(Collection<MapEntryNode> routes);
265 protected abstract DestinationType buildWithdrawnDestination(Collection<MapEntryNode> routes);
268 * Return the {@link NodeIdentifier} of the AFI/SAFI-specific container under
271 * @return Container identifier, may not be null.
273 protected final NodeIdentifier routesContainerIdentifier() {
274 return this.routesContainerIdentifier;
278 * Return the {@link NodeIdentifier} of the AFI/SAFI-specific container under
279 * the NLRI destination.
281 * @return Container identifier, may not be null.
283 private NodeIdentifier destinationContainerIdentifier() {
284 return this.destinationNid;
288 * Given the destination as ContainerNode, implementation needs to parse the DOM model
289 * from this point onward:
291 * {@code /bgp-mp:mp-unreach-nlri/bgp-mp:withdrawn-routes/bgp-mp:destination-type}
292 * and delete the routes from its RIBs.
294 * @param tx DOMDataWriteTransaction to be passed into implementation
295 * @param tablePath YangInstanceIdentifier to be passed into implementation
296 * @param destination ContainerNode DOM representation of NLRI in Update message
297 * @param routesNodeId NodeIdentifier
299 private void deleteDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
300 final ContainerNode destination, final NodeIdentifier routesNodeId) {
301 processDestination(tx, tablePath.node(routesNodeId), destination, null, DELETE_ROUTE);
305 * Given the destination as ContainerNode, implementation needs to parse the DOM model
306 * from this point onward:
308 * {@code /bgp-mp:mp-reach-nlri/bgp-mp:advertized-routes/bgp-mp:destination-type}
309 * and put the routes to its RIBs.
311 * @param tx DOMDataWriteTransaction to be passed into implementation
312 * @param tablePath YangInstanceIdentifier to be passed into implementation
313 * @param destination ContainerNode DOM representation of NLRI in Update message
314 * @param attributes ContainerNode to be passed into implementation
315 * @param routesNodeId NodeIdentifier
316 * @return List of processed route identifiers
318 private Collection<NodeIdentifierWithPredicates> putDestinationRoutes(final DOMDataWriteTransaction tx,
319 final YangInstanceIdentifier tablePath, final ContainerNode destination, final ContainerNode attributes,
320 final NodeIdentifier routesNodeId) {
321 return processDestination(tx, tablePath.node(routesNodeId), destination, attributes, this.putRoute);
324 protected abstract Collection<NodeIdentifierWithPredicates> processDestination(DOMDataWriteTransaction tx,
325 YangInstanceIdentifier routesPath, ContainerNode destination, ContainerNode attributes,
326 ApplyRoute applyFunction);
328 private static ContainerNode getDestination(final DataContainerChild<? extends PathArgument, ?> routes,
329 final NodeIdentifier destinationId) {
330 if (routes instanceof ContainerNode) {
331 final java.util.Optional<DataContainerChild<? extends PathArgument, ?>> maybeDestination =
332 ((ContainerNode) routes).getChild(DESTINATION_TYPE);
333 if (maybeDestination.isPresent()) {
334 final DataContainerChild<? extends PathArgument, ?> destination = maybeDestination.get();
335 if (destination instanceof ChoiceNode) {
336 final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRet =
337 ((ChoiceNode) destination).getChild(destinationId);
338 if (maybeRet.isPresent()) {
339 final DataContainerChild<? extends PathArgument, ?> ret = maybeRet.get();
340 if (ret instanceof ContainerNode) {
341 return (ContainerNode) ret;
344 LOG.debug("Specified node {} is not a container, ignoring it", ret);
346 LOG.debug("Specified container {} is not present in destination {}",
347 destinationId, destination);
350 LOG.warn("Destination {} is not a choice, ignoring it", destination);
353 LOG.debug("Destination is not present in routes {}", routes);
356 LOG.warn("Advertized routes {} are not a container, ignoring it", routes);
363 public final NodeIdentifier routeAttributesIdentifier() {
364 return this.routeAttributesIdentifier;
368 public final Collection<DataTreeCandidateNode> changedRoutes(final DataTreeCandidateNode routes) {
369 final DataTreeCandidateNode myRoutes = routes.getModifiedChild(this.routesContainerIdentifier);
370 if (myRoutes == null) {
371 return Collections.emptySet();
373 final DataTreeCandidateNode routesMap = myRoutes.getModifiedChild(routeNid());
374 if (routesMap == null) {
375 return Collections.emptySet();
377 // Well, given the remote possibility of augmentation, we should perform a filter here,
378 // to make sure the type matches what routeType() reports.
379 return routesMap.getChildNodes();
383 public final YangInstanceIdentifier routesPath(final YangInstanceIdentifier routesTablePaths) {
384 return routesYangInstanceIdentifier(routesTablePaths.node(Routes.QNAME));
388 public final InstanceIdentifier<R> createRouteIdentifier(
389 final KeyedInstanceIdentifier<Tables, TablesKey> tableIId, final I key) {
391 return tableIId.child(routesCaseClass(), routesContainerClass()).child(routesListClass(), key);
395 public final void deleteRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
396 final ContainerNode nlri) {
397 deleteRoutes(tx, tablePath, nlri, ROUTES);
401 public final Collection<NodeIdentifierWithPredicates> putRoutes(final DOMDataWriteTransaction tx,
402 final YangInstanceIdentifier tablePath,
403 final ContainerNode nlri,
404 final ContainerNode attributes) {
405 return putRoutes(tx, tablePath, nlri, attributes, ROUTES);
409 public final Update buildUpdate(final Collection<MapEntryNode> advertised, final Collection<MapEntryNode> withdrawn,
410 final Attributes attr) {
411 final UpdateBuilder ub = new UpdateBuilder();
412 final AttributesBuilder ab = new AttributesBuilder(attr);
413 final CNextHop hop = ab.getCNextHop();
415 LOG.debug("cnextHop before={}", hop);
416 // do not preserve next hop in attributes if we are using MpReach
417 ab.setCNextHop(null);
419 if (!advertised.isEmpty()) {
420 final MpReachNlri mb = buildReach(advertised, hop);
421 ab.addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mb).build());
422 LOG.debug("mpreach nexthop={}", mb);
424 if (!withdrawn.isEmpty()) {
425 final MpUnreachNlri mb = buildUnreach(withdrawn);
426 ab.addAugmentation(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(mb).build());
427 LOG.debug("mpunrach mb={}", mb);
430 ub.setAttributes(ab.build());
431 LOG.debug("update {}", ub.build());
436 @SuppressWarnings("checkstyle:OverloadMethodsDeclarationOrder")
437 public final void deleteRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
438 final ContainerNode nlri, final NodeIdentifier routesNodeId) {
439 final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = nlri.getChild(WITHDRAWN_ROUTES);
440 if (maybeRoutes.isPresent()) {
441 final ContainerNode destination = getDestination(maybeRoutes.get(), destinationContainerIdentifier());
442 if (destination != null) {
443 deleteDestinationRoutes(tx, tablePath, destination, routesNodeId);
446 LOG.debug("Withdrawn routes are not present in NLRI {}", nlri);
451 public final Collection<NodeIdentifierWithPredicates> putRoutes(final DOMDataWriteTransaction tx,
452 final YangInstanceIdentifier tablePath,
453 final ContainerNode nlri,
454 final ContainerNode attributes,
455 final NodeIdentifier routesNodeId) {
456 final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = nlri.getChild(ADVERTISED_ROUTES);
457 if (maybeRoutes.isPresent()) {
458 final ContainerNode destination = getDestination(maybeRoutes.get(), destinationContainerIdentifier());
459 if (destination != null) {
460 return putDestinationRoutes(tx, tablePath, destination, attributes, routesNodeId);
463 LOG.debug("Advertized routes are not present in NLRI {}", nlri);
465 return Collections.emptyList();
468 private static final class DeleteRoute implements ApplyRoute {
470 public void apply(final DOMDataWriteTransaction tx, final YangInstanceIdentifier base,
471 final NodeIdentifierWithPredicates routeKey, final DataContainerNode<?> route,
472 final ContainerNode attributes) {
473 tx.delete(LogicalDatastoreType.OPERATIONAL, base.node(routeKey));
477 private final class PutRoute implements ApplyRoute {
479 public void apply(final DOMDataWriteTransaction tx, final YangInstanceIdentifier base,
480 final NodeIdentifierWithPredicates routeKey, final DataContainerNode<?> route,
481 final ContainerNode attributes) {
482 // Build the DataContainer data
483 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> b =
484 ImmutableNodes.mapEntryBuilder();
485 b.withNodeIdentifier(routeKey);
487 route.getValue().forEach(b::withChild);
489 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> cb =
490 Builders.containerBuilder(attributes);
491 cb.withNodeIdentifier(routeAttributesIdentifier());
492 b.withChild(cb.build());
493 tx.put(LogicalDatastoreType.OPERATIONAL, base.node(routeKey), b.build());
497 protected final NodeIdentifier routePathIdNid() {
498 return this.pathIdNid;
501 protected final QName pathIdQName() {
502 return this.pathIdQname;
505 protected final QName routeKeyQName() {
506 return this.routeKeyQname;
509 protected final String extractPrefix(final DataContainerNode<? extends PathArgument> route) {
510 return (String) route.getChild(prefixTypeNid).get().getValue();
513 protected final RouteDistinguisher extractRouteDistinguisher(
514 final DataContainerNode<? extends PathArgument> route) {
515 if (route.getChild(this.rdNid).isPresent()) {
516 return RouteDistinguisherBuilder.getDefaultInstance((String) route.getChild(this.rdNid).get().getValue());
521 protected final YangInstanceIdentifier routesYangInstanceIdentifier(final YangInstanceIdentifier routesTablePaths) {
522 return this.routesPath.getUnchecked(routesTablePaths);
526 public R fromNormalizedNode(final YangInstanceIdentifier routePath, final NormalizedNode<?, ?> normalizedNode) {
527 return (R) this.mappingService.fromNormalizedNode(routePath, normalizedNode).getValue();
531 public Attributes attributeFromContainerNode(final ContainerNode advertisedAttrs) {
532 final YangInstanceIdentifier path = this.routeDefaultYii.node(routeAttributesIdentifier());
533 return (Attributes) this.mappingService.fromNormalizedNode(path, advertisedAttrs).getValue();
537 public ContainerNode attributeToContainerNode(final YangInstanceIdentifier attPath, final Attributes attributes) {
538 final InstanceIdentifier<DataObject> iid = this.mappingService.fromYangInstanceIdentifier(attPath);
539 return (ContainerNode) this.mappingService.toNormalizedNode(iid, attributes).getValue();