@Nonnull @Override public final PathArgument getRouteIdAddPath(final long pathId, final PathArgument routeId) { return PathIdUtil.createNidKey(pathId, routeId, routeQName(), pathIdQName(), routeKeyQName()); }
@Nonnull @Override protected DestinationType buildWithdrawnDestination(@Nonnull final Collection<MapEntryNode> routes) { final MapEntryNode routesCont = Iterables.getOnlyElement(routes); final PathId pathId = PathIdUtil.buildPathId(routesCont, routePathIdNid()); return this.nlriParser.createWithdrawnDestinationType( new Object[] {this.nlriParser.extractFlowspec(Iterables.getOnlyElement(routes))}, pathId ); }
@Nullable protected final PathId readPathId(@Nonnull final ByteBuf nlri, final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi, final PeerSpecificParserConstraint constraint) { if (MultiPathSupportUtil.isTableTypeSupported(constraint, new BgpTableTypeImpl(afi, safi))) { return PathIdUtil.readPathId(nlri); } return null; }
/** * Serializes Flowspec NLRI to ByteBuf. * * @param nlriFields NLRI fields to be serialized * @param pathId * @param buffer where flowspec NLRI will be serialized */ protected final void serializeNlri(@Nonnull final Object[] nlriFields, @Nullable final PathId pathId, @Nonnull final ByteBuf buffer) { final ByteBuf nlriByteBuf = Unpooled.buffer(); PathIdUtil.writePathId(pathId, buffer); serializeNlri(nlriFields, nlriByteBuf); Preconditions.checkState(nlriByteBuf.readableBytes() <= MAX_NLRI_LENGTH, "Maximum length of Flowspec NLRI reached."); if (nlriByteBuf.readableBytes() <= MAX_NLRI_LENGTH_ONE_BYTE) { buffer.writeByte(nlriByteBuf.readableBytes()); } else { buffer.writeShort(nlriByteBuf.readableBytes() + LENGTH_MAGIC); } buffer.writeBytes(nlriByteBuf); }
@Override public final Long extractPathId(final NormalizedNode<?, ?> data) { final Long pathId = PathIdUtil.extractPathId(data, this.routePathIdNid()); if(pathId == null) { return PathIdUtil.NON_PATH_ID; } return pathId; }
@Override public final PathArgument createRouteKeyPathArgument(final PathArgument routeKey) { final ImmutableMap<QName, Object> keyValues = ImmutableMap.of(routeKeyQName(), PathIdUtil.getObjectKey(routeKey, routeKeyQName())); return new NodeIdentifierWithPredicates(routeQName(), keyValues); }
@Override public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); final Attributes pathAttributes = (Attributes) attribute; final Attributes1 pathAttributes1 = pathAttributes.getAugmentation(Attributes1.class); final Attributes2 pathAttributes2 = pathAttributes.getAugmentation(Attributes2.class); if (pathAttributes1 != null) { final AdvertizedRoutes advertizedRoutes = pathAttributes1.getMpReachNlri().getAdvertizedRoutes(); if (advertizedRoutes != null && advertizedRoutes.getDestinationType() instanceof DestinationIpv4Case) { final DestinationIpv4Case destinationIpv4Case = (DestinationIpv4Case) advertizedRoutes.getDestinationType(); for (final Ipv4Prefixes ipv4Prefix : destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes()) { PathIdUtil.writePathId(ipv4Prefix.getPathId(), byteAggregator); ByteBufWriteUtil.writeMinimalPrefix(ipv4Prefix.getPrefix(), byteAggregator); } } } else if (pathAttributes2 != null) { final WithdrawnRoutes withdrawnRoutes = pathAttributes2.getMpUnreachNlri().getWithdrawnRoutes(); if (withdrawnRoutes != null && withdrawnRoutes.getDestinationType() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4Case) { final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4Case destinationIpv4Case = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4Case) withdrawnRoutes.getDestinationType(); for (final Ipv4Prefixes ipv4Prefix : destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes()) { PathIdUtil.writePathId(ipv4Prefix.getPathId(), byteAggregator); ByteBufWriteUtil.writeMinimalPrefix(ipv4Prefix.getPrefix(), byteAggregator); } } } } }
/** * Prefix and Path Id are the route key * * @param prefixes UnkeyedListEntryNode containing route * @return Nid with Route Key */ private NodeIdentifierWithPredicates createRouteKey(final UnkeyedListEntryNode prefixes) { final Optional<DataContainerChild<? extends PathArgument, ?>> maybePrefixLeaf = prefixes.getChild(routePrefixIdentifier()); final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf = prefixes.getChild(routePathIdNid()); Preconditions.checkState(maybePrefixLeaf.isPresent()); final Object prefixValue = (maybePrefixLeaf.get()).getValue(); return PathIdUtil.createNidKey(routeQName(), routeKeyQName(), pathIdQName(), prefixValue, maybePathIdLeaf); } }
@Nonnull @Override protected DestinationType buildDestination(@Nonnull final Collection<MapEntryNode> routes) { final MapEntryNode routesCont = Iterables.getOnlyElement(routes); final PathId pathId = PathIdUtil.buildPathId(routesCont, routePathIdNid()); return this.nlriParser.createAdvertizedRoutesDestinationType( new Object[] {this.nlriParser.extractFlowspec(routesCont)}, pathId ); }
private static DestinationIpv4 prefixes(final ByteBuf nlri, final PeerSpecificParserConstraint constraints, final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) { final List<Ipv4Prefixes> prefixes = new ArrayList<>(); while (nlri.isReadable()) { final Ipv4PrefixesBuilder prefixesBuilder = new Ipv4PrefixesBuilder(); if (MultiPathSupportUtil.isTableTypeSupported(constraints, new BgpTableTypeImpl(afi, safi))) { prefixesBuilder.setPathId(PathIdUtil.readPathId(nlri)); } prefixesBuilder.setPrefix(Ipv4Util.prefixForByteBuf(nlri)); prefixes.add(prefixesBuilder.build()); } return new DestinationIpv4Builder().setIpv4Prefixes(prefixes).build(); }
@Override public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object."); final Attributes pathAttributes = (Attributes) attribute; final Attributes1 pathAttributes1 = pathAttributes.getAugmentation(Attributes1.class); final Attributes2 pathAttributes2 = pathAttributes.getAugmentation(Attributes2.class); if (pathAttributes1 != null) { final AdvertizedRoutes advertizedRoutes = pathAttributes1.getMpReachNlri().getAdvertizedRoutes(); if (advertizedRoutes != null && advertizedRoutes.getDestinationType() instanceof DestinationIpv6Case) { final DestinationIpv6Case destinationIpv6Case = (DestinationIpv6Case) advertizedRoutes.getDestinationType(); for (final Ipv6Prefixes ipv6Prefix : destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes()) { PathIdUtil.writePathId(ipv6Prefix.getPathId(), byteAggregator); ByteBufWriteUtil.writeMinimalPrefix(ipv6Prefix.getPrefix(), byteAggregator); } } } else if (pathAttributes2 != null) { final WithdrawnRoutes withdrawnRoutes = pathAttributes2.getMpUnreachNlri().getWithdrawnRoutes(); if (withdrawnRoutes != null && withdrawnRoutes.getDestinationType() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6Case) { final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6Case destinationIpv6Case = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6Case) withdrawnRoutes.getDestinationType(); for (final Ipv6Prefixes ipv6Prefix : destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes()) { PathIdUtil.writePathId(ipv6Prefix.getPathId(), byteAggregator); ByteBufWriteUtil.writeMinimalPrefix(ipv6Prefix.getPrefix(), byteAggregator); } } } } }
@Override 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 = this.nlriParser.stringNlri(destination); final NodeIdentifierWithPredicates routeKey = PathIdUtil.createNidKey(routeQName(), routeKeyQName(), pathIdQName(), routeKeyValue, maybePathIdLeaf); function.apply(tx, base, routeKey, destination, attributes); } } }
@Nonnull @Override protected DestinationType buildWithdrawnDestination(@Nonnull final Collection<MapEntryNode> routes) { final MapEntryNode routesCont = Iterables.getOnlyElement(routes); final PathId pathId = PathIdUtil.buildPathId(routesCont, routePathIdNid()); final RouteDistinguisher rd = extractRouteDistinguisher(routesCont, this.routeDistinguisherNID); return this.nlriParser.createWithdrawnDestinationType( new Object[] {rd, nlriParser.extractFlowspec(Iterables.getOnlyElement(routes))}, pathId ); } }
private static DestinationIpv6 prefixes(final ByteBuf nlri, final PeerSpecificParserConstraint constraint, final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) { final List<Ipv6Prefixes> prefixes = new ArrayList<>(); final boolean supported = MultiPathSupportUtil.isTableTypeSupported(constraint, new BgpTableTypeImpl(afi, safi)); while (nlri.isReadable()) { final Ipv6PrefixesBuilder prefixesBuilder = new Ipv6PrefixesBuilder(); if (supported) { prefixesBuilder.setPathId(PathIdUtil.readPathId(nlri)); } prefixesBuilder.setPrefix(Ipv6Util.prefixForByteBuf(nlri)); prefixes.add(prefixesBuilder.build()); } return new DestinationIpv6Builder().setIpv6Prefixes(prefixes).build(); }
@Nonnull @Override protected DestinationType buildDestination(@Nonnull final Collection<MapEntryNode> routes) { final MapEntryNode routesCont = Iterables.getOnlyElement(routes); final PathId pathId = PathIdUtil.buildPathId(routesCont, routePathIdNid()); final RouteDistinguisher rd = extractRouteDistinguisher(routesCont, this.routeDistinguisherNID); return this.nlriParser.createAdvertizedRoutesDestinationType( new Object[] {rd, this.nlriParser.extractFlowspec(routesCont)}, pathId ); }
private List<Ipv6Prefixes> extractPrefixes(final Collection<MapEntryNode> routes) { final List<Ipv6Prefixes> prefs = new ArrayList<>(routes.size()); for (final MapEntryNode route : routes) { final String prefix = (String) NormalizedNodes.findNode(route, routePrefixIdentifier()).get().getValue(); prefs.add(new Ipv6PrefixesBuilder().setPathId(PathIdUtil.buildPathId(route, routePathIdNid())).setPrefix(new Ipv6Prefix(prefix)).build()); } return prefs; } }
private List<Ipv4Prefixes> extractPrefixes(final Collection<MapEntryNode> routes) { final List<Ipv4Prefixes> prefs = new ArrayList<>(routes.size()); for (final MapEntryNode route : routes) { final String prefix = (String) NormalizedNodes.findNode(route, routePrefixIdentifier()).get().getValue(); final Ipv4PrefixesBuilder prefixBuilder = new Ipv4PrefixesBuilder().setPrefix(new Ipv4Prefix(prefix)); prefixBuilder.setPathId(PathIdUtil.buildPathId(route, routePathIdNid())); prefs.add(prefixBuilder.build()); } return prefs; }