Search in sources :

Example 11 with TablesKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.

the class GracefulCapabilityHandler method serializeCapability.

private ByteBuf serializeCapability(final GracefulRestartCapability grace) {
    final Map<TablesKey, Tables> tables = grace.getTables();
    final int tablesSize = tables != null ? tables.size() : 0;
    final ByteBuf bytes = Unpooled.buffer(HEADER_SIZE + PER_AFI_SAFI_SIZE * tablesSize);
    Uint16 time = grace.getRestartTime();
    if (time == null) {
        time = Uint16.ZERO;
    }
    final int timeval = time.toJava();
    Preconditions.checkArgument(timeval >= 0 && timeval <= MAX_RESTART_TIME, "Restart time is " + time);
    final GracefulRestartCapability.RestartFlags flags = grace.getRestartFlags();
    if (flags != null && flags.getRestartState()) {
        bytes.writeShort(RESTART_FLAG_STATE | timeval);
    } else {
        bytes.writeShort(timeval);
    }
    serializeTables(tables, bytes);
    return bytes;
}
Also used : RestartFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.GracefulRestartCapability.RestartFlags) TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.graceful.restart.capability.TablesKey) Uint16(org.opendaylight.yangtools.yang.common.Uint16) Tables(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.graceful.restart.capability.Tables) GracefulRestartCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.GracefulRestartCapability) ByteBuf(io.netty.buffer.ByteBuf)

Example 12 with TablesKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.

the class LlGracefulCapabilityHandler method serializeCapability.

private ByteBuf serializeCapability(final LlGracefulRestartCapability cap) {
    final Map<TablesKey, Tables> tables = cap.getTables();
    if (tables == null || tables.isEmpty()) {
        return Unpooled.EMPTY_BUFFER;
    }
    final ByteBuf buffer = Unpooled.buffer(PER_TABLE_SIZE * tables.size());
    for (Tables table : tables.values()) {
        final Class<? extends AddressFamily> afi = table.getAfi();
        final Class<? extends SubsequentAddressFamily> safi = table.getSafi();
        final Integer afival = this.afiReg.numberForClass(afi);
        checkArgument(afival != null, "Unhandled address family %s", afi);
        buffer.writeShort(afival);
        final Integer safival = this.safiReg.numberForClass(safi);
        checkArgument(safival != null, "Unhandled subsequent address family %s", safi);
        buffer.writeByte(safival);
        if (table.getAfiFlags() != null && table.getAfiFlags().getForwardingState()) {
            buffer.writeByte(AFI_FLAG_FORWARDING_STATE);
        } else {
            buffer.writeByte(0);
        }
        final Uint24 staleTime = table.getLongLivedStaleTime();
        final int timeval = staleTime != null ? staleTime.getValue().intValue() : 0;
        checkArgument(timeval >= 0 && timeval <= MAX_STALE_TIME, "Restart time is %s", staleTime);
        buffer.writeMedium(timeval);
    }
    return buffer;
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey) Tables(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.Tables) Uint24(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Uint24) ByteBuf(io.netty.buffer.ByteBuf)

Example 13 with TablesKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.

the class AdjRibInWriter method updateRoutes.

void updateRoutes(final MpReachNlri nlri, final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes attributes) {
    final TablesKey key = new TablesKey(nlri.getAfi(), nlri.getSafi());
    final TableContext ctx = this.tables.get(key);
    if (ctx == null) {
        LOG.debug("No table for {}, not accepting NLRI {}", key, nlri);
        return;
    }
    final DOMDataTreeWriteTransaction tx = this.chain.getDomChain().newWriteOnlyTransaction();
    final Collection<NodeIdentifierWithPredicates> routeKeys = ctx.writeRoutes(tx, nlri, attributes);
    final Collection<NodeIdentifierWithPredicates> staleRoutes = this.staleRoutesRegistry.get(key);
    if (staleRoutes != null) {
        staleRoutes.removeAll(routeKeys);
    }
    LOG.trace("Write routes {}", nlri);
    final FluentFuture<? extends CommitInfo> future = tx.commit();
    this.submitted = future;
    future.addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.trace("Write routes {}, succeed", nlri);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Write routes failed", throwable);
        }
    }, MoreExecutors.directExecutor());
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)

Example 14 with TablesKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.

the class AdjRibInWriter method storeStaleRoutes.

void storeStaleRoutes(final Set<TablesKey> gracefulTables) {
    final CountDownLatch latch = new CountDownLatch(gracefulTables.size());
    try (DOMDataTreeReadTransaction tx = this.chain.getDomChain().newReadOnlyTransaction()) {
        for (TablesKey tablesKey : gracefulTables) {
            final TableContext ctx = this.tables.get(tablesKey);
            if (ctx == null) {
                LOG.warn("Missing table for address family {}", tablesKey);
                latch.countDown();
                continue;
            }
            tx.read(LogicalDatastoreType.OPERATIONAL, ctx.routesPath()).addCallback(new FutureCallback<Optional<NormalizedNode>>() {

                @Override
                public void onSuccess(final Optional<NormalizedNode> routesOptional) {
                    try {
                        if (routesOptional.isPresent()) {
                            synchronized (AdjRibInWriter.this.staleRoutesRegistry) {
                                final MapNode routesNode = (MapNode) routesOptional.get();
                                final List<NodeIdentifierWithPredicates> routes = routesNode.body().stream().map(MapEntryNode::getIdentifier).collect(Collectors.toList());
                                if (!routes.isEmpty()) {
                                    AdjRibInWriter.this.staleRoutesRegistry.put(tablesKey, routes);
                                }
                            }
                        }
                    } finally {
                        latch.countDown();
                    }
                }

                @Override
                public void onFailure(final Throwable throwable) {
                    LOG.warn("Failed to store stale routes for table {}", tablesKey, throwable);
                    latch.countDown();
                }
            }, MoreExecutors.directExecutor());
        }
    }
    try {
        latch.await();
    } catch (InterruptedException e) {
        LOG.warn("Interrupted while waiting to store stale routes with {} tasks of {} to finish", latch.getCount(), gracefulTables, e);
    }
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey) Optional(java.util.Optional) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) CountDownLatch(java.util.concurrent.CountDownLatch) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) List(java.util.List) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMDataTreeReadTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction)

Example 15 with TablesKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.

the class ApplicationPeer method instantiateServiceInstance.

public synchronized void instantiateServiceInstance(final DOMDataTreeChangeService dataTreeChangeService, final DOMDataTreeIdentifier appPeerDOMId) {
    setActive(true);
    final Set<TablesKey> localTables = this.rib.getLocalTablesKeys();
    localTables.forEach(tablesKey -> this.supportedTables.add(RibSupportUtils.toYangTablesKey(tablesKey)));
    setAdvertizedGracefulRestartTableTypes(Collections.emptyList());
    createDomChain();
    this.adjRibInWriter = AdjRibInWriter.create(this.rib.getYangRibId(), PeerRole.Internal, this);
    final RIBSupportContextRegistry context = this.rib.getRibSupportContext();
    final RegisterAppPeerListener registerAppPeerListener = () -> {
        synchronized (this) {
            if (getDomChain() != null) {
                this.registration = dataTreeChangeService.registerDataTreeChangeListener(appPeerDOMId, this);
            }
        }
    };
    this.peerPath = createPeerPath(this.peerId);
    this.adjRibInWriter = this.adjRibInWriter.transform(this.peerId, this.peerPath, context, localTables, Collections.emptyMap(), registerAppPeerListener);
    this.effectiveRibInWriter = new EffectiveRibInWriter(this, this.rib, this.rib.createPeerDOMChain(this), this.peerPath, localTables, this.tableTypeRegistry, new ArrayList<>(), this.rtCache);
    this.effectiveRibInWriter.init();
    this.bgpSessionState.registerMessagesCounter(this);
    this.trackerRegistration = this.rib.getPeerTracker().registerPeer(this);
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey) ArrayList(java.util.ArrayList) RIBSupportContextRegistry(org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry)

Aggregations

TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey)40 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey)15 RIBSupport (org.opendaylight.protocol.bgp.rib.spi.RIBSupport)11 KeyedInstanceIdentifier (org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier)11 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)9 Before (org.junit.Before)8 Test (org.junit.Test)8 PathSelectionMode (org.opendaylight.protocol.bgp.mode.api.PathSelectionMode)8 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)8 ArrayList (java.util.ArrayList)7 CommitInfo (org.opendaylight.mdsal.common.api.CommitInfo)7 Peer (org.opendaylight.protocol.bgp.rib.spi.Peer)6 Identifier (org.opendaylight.yangtools.yang.binding.Identifier)6 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)5 RibId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId)5 ChannelFuture (io.netty.channel.ChannelFuture)4 InetSocketAddress (java.net.InetSocketAddress)4 HashMap (java.util.HashMap)4 BGPRouteEntryExportParametersImpl (org.opendaylight.protocol.bgp.mode.impl.BGPRouteEntryExportParametersImpl)4 BGPRouteEntryExportParameters (org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters)4