*/
package org.opendaylight.protocol.bgp.route.targetcontrain.impl;
-import static com.google.common.base.Verify.verify;
-
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableSet;
import io.netty.buffer.ByteBuf;
import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupport;
-import org.opendaylight.protocol.bgp.route.targetcontrain.impl.nlri.SimpleRouteTargetConstrainNlriRegistry;
+import org.opendaylight.protocol.bgp.route.targetcontrain.impl.nlri.ImmutableRouteTargetConstrainNlriRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
-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.message.rev180329.path.attributes.Attributes;
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.rib.tables.Routes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.RouteTargetConstrainSubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.bgp.rib.rib.loc.rib.tables.routes.RouteTargetConstrainRoutesCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.RouteTargetConstrainChoice;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.destination.RouteTargetConstrainDestination;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.destination.RouteTargetConstrainDestinationBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.routes.RouteTargetConstrainRoutes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.routes.RouteTargetConstrainRoutesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.routes.route.target.constrain.routes.RouteTargetConstrainRoute;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.routes.route.target.constrain.routes.RouteTargetConstrainRouteBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.routes.route.target.constrain.routes.RouteTargetConstrainRouteKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationRouteTargetConstrainAdvertizedCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.route.target.constrain.advertized._case.DestinationRouteTargetConstrain;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.route.target.constrain.advertized._case.DestinationRouteTargetConstrainBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationRouteTargetConstrainWithdrawnCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily;
import org.opendaylight.yangtools.yang.binding.BindingObject;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
*/
public final class RouteTargetConstrainRIBSupport
extends AbstractRIBSupport<RouteTargetConstrainRoutesCase, RouteTargetConstrainRoutes,
- RouteTargetConstrainRoute, RouteTargetConstrainRouteKey> {
+ RouteTargetConstrainRoute> {
private static final Logger LOG = LoggerFactory.getLogger(RouteTargetConstrainRIBSupport.class);
private static final NodeIdentifier NLRI_ROUTES_LIST = NodeIdentifier.create(RouteTargetConstrainDestination.QNAME);
- private static final RouteTargetConstrainRoutes EMPTY_CONTAINER
- = new RouteTargetConstrainRoutesBuilder().setRouteTargetConstrainRoute(Collections.emptyList()).build();
private static final String ORIGIN_AS = "origin-as";
- private static RouteTargetConstrainRIBSupport SINGLETON;
private final ImmutableCollection<Class<? extends BindingObject>> cacheableNlriObjects
= ImmutableSet.of(RouteTargetConstrainRoutesCase.class);
private final NodeIdentifier originAsNid;
*
* @param mappingService Serialization service
*/
- private RouteTargetConstrainRIBSupport(final BindingNormalizedNodeSerializer mappingService) {
+ public RouteTargetConstrainRIBSupport(final BindingNormalizedNodeSerializer mappingService) {
super(mappingService,
- RouteTargetConstrainRoutesCase.class,
- RouteTargetConstrainRoutes.class,
- RouteTargetConstrainRoute.class,
- Ipv4AddressFamily.class,
- RouteTargetConstrainSubsequentAddressFamily.class,
- DestinationRouteTargetConstrain.QNAME);
- this.originAsNid = new NodeIdentifier(QName.create(routeQName(), ORIGIN_AS).intern());
- }
-
- public static synchronized RouteTargetConstrainRIBSupport getInstance(
- final BindingNormalizedNodeSerializer mappingService) {
- if (SINGLETON == null) {
- SINGLETON = new RouteTargetConstrainRIBSupport(mappingService);
- }
- return SINGLETON;
+ RouteTargetConstrainRoutesCase.class, RouteTargetConstrainRoutesCase.QNAME,
+ RouteTargetConstrainRoutes.class, RouteTargetConstrainRoutes.QNAME,
+ RouteTargetConstrainRoute.class, RouteTargetConstrainRoute.QNAME,
+ Ipv4AddressFamily.VALUE, Ipv4AddressFamily.QNAME,
+ RouteTargetConstrainSubsequentAddressFamily.VALUE, RouteTargetConstrainSubsequentAddressFamily.QNAME,
+ DestinationRouteTargetConstrain.QNAME);
+ originAsNid = new NodeIdentifier(QName.create(routeQName(), ORIGIN_AS).intern());
}
@Override
public ImmutableCollection<Class<? extends BindingObject>> cacheableNlriObjects() {
- return this.cacheableNlriObjects;
+ return cacheableNlriObjects;
}
@Override
return routes.stream().map(this::extractDestination).collect(Collectors.toList());
}
- private RouteTargetConstrainDestination extractDestination(final DataContainerNode<? extends PathArgument> rtDest) {
+ private RouteTargetConstrainDestination extractDestination(final DataContainerNode rtDest) {
final RouteTargetConstrainDestinationBuilder builder = new RouteTargetConstrainDestinationBuilder()
.setPathId(PathIdUtil.buildPathId(rtDest, routePathIdNid()))
.setRouteTargetConstrainChoice(extractRouteTargetChoice(rtDest));
final Optional<Object> originAs = NormalizedNodes
- .findNode(rtDest, this.originAsNid).map(NormalizedNode::getValue);
- originAs.ifPresent(o -> builder.setOriginAs(new AsNumber((Long) o)));
+ .findNode(rtDest, originAsNid).map(NormalizedNode::body);
+ originAs.ifPresent(o -> builder.setOriginAs(new AsNumber((Uint32) o)));
return builder.build();
}
- private RouteTargetConstrainChoice extractRouteTargetChoice(final DataContainerNode<? extends PathArgument> route) {
- final DataObject nn = this.mappingService.fromNormalizedNode(this.routeDefaultYii, route).getValue();
+ private RouteTargetConstrainChoice extractRouteTargetChoice(final DataContainerNode route) {
+ final DataObject nn = mappingService.fromNormalizedNode(routeDefaultYii, route).getValue();
return ((RouteTargetConstrainRoute) nn).getRouteTargetConstrainChoice();
}
final ContainerNode attributes,
final ApplyRoute function) {
if (destination != null) {
- final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = destination
- .getChild(NLRI_ROUTES_LIST);
- if (maybeRoutes.isPresent()) {
- final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
+ final DataContainerChild routes = destination.childByArg(NLRI_ROUTES_LIST);
+ if (routes != null) {
if (routes instanceof UnkeyedListNode) {
final YangInstanceIdentifier base = routesYangInstanceIdentifier(routesPath);
- final Collection<UnkeyedListEntryNode> routesList = ((UnkeyedListNode) routes).getValue();
+ final Collection<UnkeyedListEntryNode> routesList = ((UnkeyedListNode) routes).body();
final List<NodeIdentifierWithPredicates> keys = new ArrayList<>(routesList.size());
for (final UnkeyedListEntryNode rtDest : routesList) {
final NodeIdentifierWithPredicates routeKey = createRouteKey(rtDest);
keys.add(routeKey);
}
return keys;
- } else {
- LOG.warn("Routes {} are not a map", routes);
}
+ LOG.warn("Routes {} are not a map", routes);
}
}
return Collections.emptyList();
private NodeIdentifierWithPredicates createRouteKey(final UnkeyedListEntryNode routeTarget) {
final ByteBuf buffer = Unpooled.buffer();
final RouteTargetConstrainDestination dest = extractDestination(routeTarget);
- buffer.writeBytes(SimpleRouteTargetConstrainNlriRegistry.getInstance()
+ buffer.writeBytes(ImmutableRouteTargetConstrainNlriRegistry.getInstance()
.serializeRouteTargetConstrain(dest.getRouteTargetConstrainChoice()));
- final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf =
- routeTarget.getChild(routePathIdNid());
return PathIdUtil.createNidKey(routeQName(), routeKeyTemplate(),
- ByteArray.encodeBase64(buffer), maybePathIdLeaf);
- }
-
- @Override
- public RouteTargetConstrainRoute createRoute(final RouteTargetConstrainRoute route,
- final RouteTargetConstrainRouteKey key, final Attributes attributes) {
- final RouteTargetConstrainRouteBuilder builder;
- if (route != null) {
- builder = new RouteTargetConstrainRouteBuilder(route);
- } else {
- builder = new RouteTargetConstrainRouteBuilder();
- }
- return builder.withKey(key).setAttributes(attributes).build();
- }
-
- @Override
- public RouteTargetConstrainRoutes emptyRoutesContainer() {
- return EMPTY_CONTAINER;
- }
-
- @Override
- public RouteTargetConstrainRouteKey createRouteListKey(final PathId pathId, final String routeKey) {
- return new RouteTargetConstrainRouteKey(pathId, routeKey);
- }
-
- @Override
- public PathId extractPathId(final RouteTargetConstrainRouteKey routeListKey) {
- return routeListKey.getPathId();
- }
-
- @Override
- public String extractRouteKey(final RouteTargetConstrainRouteKey routeListKey) {
- return routeListKey.getRouteKey();
- }
-
- @Override
- public List<RouteTargetConstrainRoute> extractAdjRibInRoutes(final Routes routes) {
- verify(routes instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target
- .constrain.rev180618.bgp.rib.rib.peer.adj.rib.in.tables.routes.RouteTargetConstrainRoutesCase,
- "Unrecognized routes %s", routes);
- return ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618
- .bgp.rib.rib.peer.adj.rib.in.tables.routes.RouteTargetConstrainRoutesCase) routes)
- .getRouteTargetConstrainRoutes().nonnullRouteTargetConstrainRoute();
+ ByteArray.encodeBase64(buffer), routeTarget.findChildByArg(routePathIdNid()));
}
}