Search in sources :

Example 16 with MpReachNlri

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri in project bgpcep by opendaylight.

the class AbstractRIBSupport method buildReach.

/**
 * Build MpReachNlri object from DOM representation.
 *
 * @param routes Collection of MapEntryNode DOM representation of routes
 * @param hop    CNextHop as it was parsed from Attributes, to be included in MpReach object
 * @return MpReachNlri
 */
private MpReachNlri buildReach(final Collection<MapEntryNode> routes, final CNextHop hop) {
    final MpReachNlriBuilder mb = new MpReachNlriBuilder();
    mb.setAfi(this.getAfi());
    mb.setSafi(this.getSafi());
    mb.setCNextHop(hop);
    mb.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(buildDestination(routes)).build());
    return mb.build();
}
Also used : MpReachNlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlriBuilder) AdvertizedRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder)

Example 17 with MpReachNlri

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri in project bgpcep by opendaylight.

the class BGPPeer method prefixesToMpReach.

/**
 * Creates MPReach for the prefixes to be handled in the same way as linkstate routes.
 *
 * @param message Update message containing prefixes in NLRI
 * @return MpReachNlri with prefixes from the nlri field
 */
private static MpReachNlri prefixesToMpReach(final Update message) {
    final List<Ipv4Prefixes> prefixes = message.getNlri().stream().map(n -> new Ipv4PrefixesBuilder().setPrefix(n.getPrefix()).setPathId(n.getPathId()).build()).collect(Collectors.toList());
    final MpReachNlriBuilder b = new MpReachNlriBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder().setIpv4Prefixes(prefixes).build()).build()).build());
    if (message.getAttributes() != null) {
        b.setCNextHop(message.getAttributes().getCNextHop());
    }
    return b.build();
}
Also used : Arrays(java.util.Arrays) LoadingCache(com.google.common.cache.LoadingCache) SubsequentAddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily) BgpAddPathTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpAddPathTableType) AsyncTransaction(org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction) RpcProviderRegistry(org.opendaylight.controller.sal.binding.api.RpcProviderRegistry) PeerId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId) LoggerFactory(org.slf4j.LoggerFactory) MpReachNlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlriBuilder) BgpPeerRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev171207.BgpPeerRpcService) Tables(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.Tables) LocalPreferenceAttributeParser(org.opendaylight.protocol.bgp.parser.impl.message.update.LocalPreferenceAttributeParser) Notification(org.opendaylight.yangtools.yang.binding.Notification) DestinationIpv4CaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4CaseBuilder) BGPRouteEntryImportParameters(org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryImportParameters) TransactionChainListener(org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener) AbstractRegistration(org.opendaylight.protocol.concepts.AbstractRegistration) Map(java.util.Map) UnicastSubsequentAddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily) Peer(org.opendaylight.protocol.bgp.rib.spi.Peer) Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update) Objects(com.google.common.base.Objects) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) DOMTransactionChain(org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey) Set(java.util.Set) RoutedRpcRegistration(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) GuardedBy(javax.annotation.concurrent.GuardedBy) Collectors(java.util.stream.Collectors) Ipv4Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.prefixes.destination.ipv4.Ipv4Prefixes) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) MpReachNlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri) BGPSessionStateProvider(org.opendaylight.protocol.bgp.rib.impl.state.BGPSessionStateProvider) BGPTerminationReason(org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) RouteRefresh(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.RouteRefresh) AdvertizedRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder) RIB(org.opendaylight.protocol.bgp.rib.impl.spi.RIB) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) WithdrawnRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder) BGPAfiSafiState(org.opendaylight.protocol.bgp.rib.spi.state.BGPAfiSafiState) RouterIds(org.opendaylight.protocol.bgp.rib.spi.RouterIds) HashMap(java.util.HashMap) AddressFamilies(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.add.path.capability.AddressFamilies) BGPError(org.opendaylight.protocol.bgp.parser.BGPError) MpUnreachNlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpUnreachNlriBuilder) ArrayList(java.util.ArrayList) ToStringHelper(com.google.common.base.MoreObjects.ToStringHelper) HashSet(java.util.HashSet) PeerRole(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole) BGPSessionState(org.opendaylight.protocol.bgp.rib.spi.state.BGPSessionState) DestinationIpv4Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.prefixes.DestinationIpv4Builder) AdjRibOut(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.peer.AdjRibOut) MessageUtil(org.opendaylight.protocol.bgp.parser.spi.MessageUtil) Objects.requireNonNull(java.util.Objects.requireNonNull) BGPSessionListener(org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener) TransactionChain(org.opendaylight.controller.md.sal.common.api.data.TransactionChain) Nullable(javax.annotation.Nullable) BGPTransportState(org.opendaylight.protocol.bgp.rib.spi.state.BGPTransportState) Logger(org.slf4j.Logger) RIBSupport(org.opendaylight.protocol.bgp.rib.spi.RIBSupport) BGPErrorHandlingState(org.opendaylight.protocol.bgp.rib.spi.state.BGPErrorHandlingState) MoreObjects(com.google.common.base.MoreObjects) PeerContext(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev171207.PeerContext) Ipv4PrefixesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.prefixes.destination.ipv4.Ipv4PrefixesBuilder) MpUnreachNlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpUnreachNlri) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder) Ipv4Util(org.opendaylight.protocol.util.Ipv4Util) Ipv4AddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily) Nlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.update.message.Nlri) Futures(com.google.common.util.concurrent.Futures) PeerKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.PeerKey) BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) ClusterIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier) InetAddresses(com.google.common.net.InetAddresses) BGPTimersState(org.opendaylight.protocol.bgp.rib.spi.state.BGPTimersState) Collections(java.util.Collections) AddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily) BGPPeerStateImpl(org.opendaylight.protocol.bgp.rib.impl.state.BGPPeerStateImpl) BGPSession(org.opendaylight.protocol.bgp.rib.spi.BGPSession) SendReceive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.SendReceive) MpReachNlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlriBuilder) AdvertizedRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder) Ipv4PrefixesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.prefixes.destination.ipv4.Ipv4PrefixesBuilder) DestinationIpv4CaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4CaseBuilder) Ipv4Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.prefixes.destination.ipv4.Ipv4Prefixes) DestinationIpv4Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.prefixes.DestinationIpv4Builder) UnicastSubsequentAddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily)

Example 18 with MpReachNlri

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri in project bgpcep by opendaylight.

the class BGPPeer method onUpdateMessage.

/**
 * Process Update message received.
 * Calls {@link #checkMandatoryAttributesPresence(Update)} to check for presence of mandatory attributes.
 *
 * @param message Update message
 */
private synchronized void onUpdateMessage(final Update message) throws BGPDocumentedException {
    checkMandatoryAttributesPresence(message);
    // update AdjRibs
    final Attributes attrs = message.getAttributes();
    MpReachNlri mpReach;
    final boolean isAnyNlriAnnounced = message.getNlri() != null;
    if (isAnyNlriAnnounced) {
        mpReach = prefixesToMpReach(message);
    } else {
        mpReach = MessageUtil.getMpReachNlri(attrs);
    }
    if (mpReach != null) {
        this.ribWriter.updateRoutes(mpReach, nextHopToAttribute(attrs, mpReach));
    }
    MpUnreachNlri mpUnreach;
    if (message.getWithdrawnRoutes() != null) {
        mpUnreach = prefixesToMpUnreach(message, isAnyNlriAnnounced);
    } else {
        mpUnreach = MessageUtil.getMpUnreachNlri(attrs);
    }
    if (mpUnreach != null) {
        this.ribWriter.removeRoutes(mpUnreach);
    }
}
Also used : MpUnreachNlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpUnreachNlri) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) MpReachNlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri)

Example 19 with MpReachNlri

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri in project bgpcep by opendaylight.

the class SimpleNlriRegistry method serializeMpReach.

@Override
public void serializeMpReach(final MpReachNlri mpReachNlri, final ByteBuf byteAggregator) {
    final Class<? extends AddressFamily> afi = mpReachNlri.getAfi();
    final Class<? extends SubsequentAddressFamily> safi = mpReachNlri.getSafi();
    byteAggregator.writeShort(this.afiReg.numberForClass(afi));
    byteAggregator.writeByte(this.safiReg.numberForClass(safi));
    final CNextHop cNextHop = mpReachNlri.getCNextHop();
    if (cNextHop != null) {
        final Entry<Class<? extends CNextHop>, BgpTableType> key = new SimpleEntry(cNextHop.getImplementedInterface(), new BgpTableTypeImpl(afi, safi));
        final NextHopParserSerializer nextHopSerializer = this.nextHopSerializers.get(key);
        final ByteBuf nextHopBuffer = Unpooled.buffer();
        nextHopSerializer.serializeNextHop(cNextHop, nextHopBuffer);
        byteAggregator.writeByte(nextHopBuffer.writerIndex());
        byteAggregator.writeBytes(nextHopBuffer);
    } else {
        byteAggregator.writeZero(NEXT_HOP_LENGHT);
    }
    byteAggregator.writeZero(RESERVED);
}
Also used : BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType) SimpleEntry(java.util.AbstractMap.SimpleEntry) BgpTableTypeImpl(org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl) CNextHop(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop) ByteBuf(io.netty.buffer.ByteBuf) NextHopParserSerializer(org.opendaylight.protocol.bgp.parser.spi.NextHopParserSerializer)

Example 20 with MpReachNlri

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri in project bgpcep by opendaylight.

the class SimpleNlriRegistry method parseMpReach.

@Override
public MpReachNlri parseMpReach(final ByteBuf buffer, final PeerSpecificParserConstraint constraint) throws BGPParsingException {
    final MpReachNlriBuilder builder = new MpReachNlriBuilder();
    final Class<? extends AddressFamily> afi = getAfi(buffer);
    final Class<? extends SubsequentAddressFamily> safi = getSafi(buffer);
    builder.setAfi(afi);
    builder.setSafi(safi);
    final BgpTableType key = createKey(builder.getAfi(), builder.getSafi());
    final int nextHopLength = buffer.readUnsignedByte();
    if (nextHopLength != 0) {
        final NextHopParserSerializer nextHopParser = this.nextHopParsers.get(key);
        if (nextHopParser != null) {
            builder.setCNextHop(nextHopParser.parseNextHop(buffer.readSlice(nextHopLength)));
        } else {
            builder.setCNextHop(NextHopUtil.parseNextHop(buffer.readSlice(nextHopLength)));
            LOG.warn("NexHop Parser/Serializer for AFI/SAFI ({},{}) not bound", afi, safi);
        }
    }
    buffer.skipBytes(RESERVED);
    final ByteBuf nlri = buffer.slice();
    final NlriParser parser = this.handlers.get(key);
    if (parser == null) {
        LOG.warn(PARSER_NOT_FOUND, key);
    } else {
        parser.parseNlri(nlri, builder, constraint);
    }
    return builder.build();
}
Also used : BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType) MpReachNlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlriBuilder) NlriParser(org.opendaylight.protocol.bgp.parser.spi.NlriParser) ByteBuf(io.netty.buffer.ByteBuf) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint) NextHopParserSerializer(org.opendaylight.protocol.bgp.parser.spi.NextHopParserSerializer)

Aggregations

MpReachNlri (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri)22 MpReachNlriBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlriBuilder)20 ByteBuf (io.netty.buffer.ByteBuf)15 AdvertizedRoutesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder)15 Test (org.junit.Test)14 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder)13 Attributes1Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1Builder)12 Attributes1 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1)8 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes)7 MpUnreachNlri (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpUnreachNlri)6 Ipv4AddressFamily (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily)5 UnicastSubsequentAddressFamily (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily)5 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)4 CLabeledUnicastDestination (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.labeled.unicast.destination.CLabeledUnicastDestination)4 CLabeledUnicastDestinationBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.labeled.unicast.destination.CLabeledUnicastDestinationBuilder)4 UpdateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.UpdateBuilder)4 Map (java.util.Map)3 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)3 NlriRegistry (org.opendaylight.protocol.bgp.parser.spi.NlriRegistry)3 DestinationIpv4Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.prefixes.DestinationIpv4Builder)3