Search in sources :

Example 11 with PeerId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId in project bgpcep by opendaylight.

the class BmpRouterImpl method onPeerUp.

private synchronized void onPeerUp(final PeerUpNotification peerUp) {
    final PeerId peerId = getPeerIdFromOpen(peerUp.getReceivedOpen());
    if (!getPeer(peerId).isPresent()) {
        final BmpRouterPeer peer = BmpRouterPeerImpl.createRouterPeer(this.domTxChain, this.peersYangIId, peerUp, this.extensions, this.tree, peerId);
        this.peers.put(peerId, peer);
        LOG.debug("Router {}: Peer {} goes up.", this.routerIp, peerId.getValue());
    } else {
        LOG.debug("Peer: {} for Router: {} already exists.", peerId.getValue(), this.routerIp);
    }
}
Also used : BmpRouterPeer(org.opendaylight.protocol.bmp.impl.spi.BmpRouterPeer) PeerId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId)

Example 12 with PeerId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId in project bgpcep by opendaylight.

the class MatchBgpNeighborSetHandler method loadRoleSets.

private List<PeerId> loadRoleSets(final String key) throws ExecutionException, InterruptedException {
    final ReadOnlyTransaction tr = this.dataBroker.newReadOnlyTransaction();
    final Optional<NeighborSet> result = tr.read(LogicalDatastoreType.CONFIGURATION, NEIGHBOR_SET_IID.child(NeighborSet.class, new NeighborSetKey(key))).get();
    if (!result.isPresent()) {
        return Collections.emptyList();
    }
    return result.get().getNeighbor().stream().map(nei -> RouterIds.createPeerId(nei.getAddress())).collect(Collectors.toList());
}
Also used : LoadingCache(com.google.common.cache.LoadingCache) PeerId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId) RouterIds(org.opendaylight.protocol.bgp.rib.spi.RouterIds) NeighborSet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.neighbor.set.NeighborSet) StringUtils(org.apache.commons.lang3.StringUtils) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) MatchSetOptionsRestrictedType(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.MatchSetOptionsRestrictedType) BGPRouteEntryImportParameters(org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryImportParameters) Optional(com.google.common.base.Optional) Objects.requireNonNull(java.util.Objects.requireNonNull) RouteEntryBaseAttributes(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.RouteEntryBaseAttributes) Nonnull(javax.annotation.Nonnull) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) Nullable(javax.annotation.Nullable) DefinedSets(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.DefinedSets) BGPRouteEntryExportParameters(org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters) BgpConditionsAugmentationPolicy(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.condition.BgpConditionsAugmentationPolicy) MatchBgpNeighborSet(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.match.bgp.neighbor.grouping.MatchBgpNeighborSet) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) RoutingPolicy(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.RoutingPolicy) Collectors(java.util.stream.Collectors) NeighborSetKey(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.neighbor.set.NeighborSetKey) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) NeighborSets(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.generic.defined.sets.NeighborSets) CacheLoader(com.google.common.cache.CacheLoader) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) BgpNeighbor(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.BgpNeighbor) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) MatchBgpNeighborCondition(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.MatchBgpNeighborCondition) CacheBuilder(com.google.common.cache.CacheBuilder) Collections(java.util.Collections) NeighborSetKey(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.neighbor.set.NeighborSetKey) NeighborSet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.neighbor.set.NeighborSet) MatchBgpNeighborSet(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.match.bgp.neighbor.grouping.MatchBgpNeighborSet) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)

Example 13 with PeerId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId in project bgpcep by opendaylight.

the class BaseAbstractRouteEntry method fillAdjRibsOut.

@VisibleForTesting
@SuppressWarnings("unchecked")
private void fillAdjRibsOut(@Nullable final Attributes attributes, @Nullable final Route route, final Identifier routeKey, final PeerId fromPeerId, final RouteEntryDependenciesContainer routeEntryDep, final WriteTransaction tx) {
    /*
         * We need to keep track of routers and populate adj-ribs-out, too. If we do not, we need to
         * expose from which client a particular route was learned from in the local RIB, and have
         * the listener perform filtering.
         *
         * We walk the policy set in order to minimize the amount of work we do for multiple peers:
         * if we have two eBGP peers, for example, there is no reason why we should perform the translation
         * multiple times.
         */
    final TablesKey localTK = routeEntryDep.getLocalTablesKey();
    final BGPRibRoutingPolicy routingPolicies = routeEntryDep.getRoutingPolicies();
    final RIBSupport ribSupport = routeEntryDep.getRibSupport();
    for (final Peer toPeer : this.peerTracker.getPeers()) {
        if (!filterRoutes(fromPeerId, toPeer, localTK)) {
            continue;
        }
        Optional<Attributes> effAttr = Optional.empty();
        final Peer fromPeer = this.peerTracker.getPeer(fromPeerId);
        if (fromPeer != null && attributes != null) {
            final BGPRouteEntryExportParameters routeEntry = new BGPRouteEntryExportParametersImpl(fromPeer, toPeer);
            effAttr = routingPolicies.applyExportPolicies(routeEntry, attributes);
        }
        final InstanceIdentifier ribOutTarget = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), routeKey);
        if (effAttr.isPresent() && route != null) {
            LOG.debug("Write route {} to peer AdjRibsOut {}", route, toPeer.getPeerId());
            tx.put(LogicalDatastoreType.OPERATIONAL, ribOutTarget, route);
            tx.put(LogicalDatastoreType.OPERATIONAL, ribOutTarget.child(Attributes.class), effAttr.get());
        } else {
            LOG.trace("Removing {} from transaction for peer {}", ribOutTarget, toPeer.getPeerId());
            tx.delete(LogicalDatastoreType.OPERATIONAL, ribOutTarget);
        }
    }
}
Also used : BGPRibRoutingPolicy(org.opendaylight.protocol.bgp.rib.spi.policy.BGPRibRoutingPolicy) TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey) RIBSupport(org.opendaylight.protocol.bgp.rib.spi.RIBSupport) Peer(org.opendaylight.protocol.bgp.rib.spi.Peer) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) BGPRouteEntryExportParametersImpl(org.opendaylight.protocol.bgp.mode.impl.BGPRouteEntryExportParametersImpl) BGPRouteEntryExportParameters(org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 14 with PeerId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId in project bgpcep by opendaylight.

the class AdjRibInWriter method transform.

AdjRibInWriter transform(final PeerId newPeerId, final YangInstanceIdentifier peerPath, final RIBSupportContextRegistry registry, final Set<TablesKey> tableTypes, final Map<TablesKey, SendReceive> addPathTablesType, @Nullable final RegisterAppPeerListener registerAppPeerListener) {
    final DOMDataTreeWriteTransaction tx = this.chain.getDomChain().newWriteOnlyTransaction();
    createEmptyPeerStructure(newPeerId, peerPath, tx);
    final ImmutableMap<TablesKey, TableContext> tb = createNewTableInstances(peerPath, registry, tableTypes, addPathTablesType, tx);
    tx.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            if (registerAppPeerListener != null) {
                LOG.trace("Application Peer Listener registered");
                registerAppPeerListener.register();
            }
        }

        @Override
        public void onFailure(final Throwable throwable) {
            if (registerAppPeerListener != null) {
                LOG.error("Failed to create Empty Structure, Application Peer Listener won't be registered", throwable);
            } else {
                LOG.error("Failed to create Empty Structure", throwable);
            }
        }
    }, MoreExecutors.directExecutor());
    return new AdjRibInWriter(this.ribPath, this.chain, this.role, tb);
}
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)

Example 15 with PeerId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId in project bgpcep by opendaylight.

the class AbstractPeer method initializeRibOut.

@Override
public final synchronized <C extends Routes & DataObject & ChoiceIn<Tables>, S extends ChildOf<? super C>> void initializeRibOut(final RouteEntryDependenciesContainer entryDep, final List<ActualBestPathRoutes<C, S>> routesToStore) {
    if (ribOutChain == null) {
        LOG.debug("Session closed, skip changes to peer AdjRibsOut {}", getPeerId());
        return;
    }
    final RIBSupport<C, S> ribSupport = entryDep.getRIBSupport();
    final YangInstanceIdentifier tableRibout = getRibOutIId(ribSupport.tablesKey());
    final boolean addPathSupported = supportsAddPathSupported(ribSupport.getTablesKey());
    final DOMDataTreeWriteTransaction tx = ribOutChain.newWriteOnlyTransaction();
    for (final ActualBestPathRoutes<C, S> initRoute : routesToStore) {
        if (!supportsLLGR() && initRoute.isDepreferenced()) {
            // Stale Long-lived Graceful Restart routes should not be propagated
            continue;
        }
        final PeerId fromPeerId = initRoute.getFromPeerId();
        if (!filterRoutes(fromPeerId, ribSupport.getTablesKey())) {
            continue;
        }
        final MapEntryNode route = initRoute.getRoute();
        final Peer fromPeer = entryDep.getPeerTracker().getPeer(fromPeerId);
        if (fromPeer == null) {
            LOG.debug("Failed to acquire peer structure for {}, ignoring route {}", fromPeerId, initRoute);
            continue;
        }
        final YangInstanceIdentifier routePath = createRoutePath(ribSupport, tableRibout, initRoute, addPathSupported);
        applyExportPolicy(entryDep, fromPeerId, route, routePath, initRoute.getAttributes()).ifPresent(attributes -> storeRoute(ribSupport, initRoute, route, routePath, attributes, tx));
    }
    final FluentFuture<? extends CommitInfo> future = tx.commit();
    submitted = future;
    future.addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.trace("Successful update commit");
        }

        @Override
        public void onFailure(final Throwable trw) {
            LOG.error("Failed update commit", trw);
        }
    }, MoreExecutors.directExecutor());
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) Peer(org.opendaylight.protocol.bgp.rib.spi.Peer) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) PeerId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId)

Aggregations

PeerId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId)13 Test (org.junit.Test)7 Peer (org.opendaylight.protocol.bgp.rib.spi.Peer)5 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)5 RouteAttributeContainer (org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer)4 BGPRouteEntryExportParameters (org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters)4 IPV4UNICAST (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST)4 Statement (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement)4 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder)4 CommitInfo (org.opendaylight.mdsal.common.api.CommitInfo)3 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)3 BGPRouteEntryExportParametersImpl (org.opendaylight.protocol.bgp.mode.impl.BGPRouteEntryExportParametersImpl)3 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes)3 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)3 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)3 RIBSupport (org.opendaylight.protocol.bgp.rib.spi.RIBSupport)2 BmpRouterPeer (org.opendaylight.protocol.bmp.impl.spi.BmpRouterPeer)2 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey)2 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1