Search in sources :

Example 1 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 RIBSupportContextRegistry registry, final Set<TablesKey> tableTypes, final Map<TablesKey, SendReceive> addPathTablesType, @Nullable final RegisterAppPeerListener registerAppPeerListener) {
    final DOMDataWriteTransaction tx = this.chain.newWriteOnlyTransaction();
    final YangInstanceIdentifier newPeerPath;
    newPeerPath = createEmptyPeerStructure(newPeerId, tx);
    final ImmutableMap<TablesKey, TableContext> tb = createNewTableInstances(newPeerPath, registry, tableTypes, addPathTablesType, tx);
    Futures.addCallback(tx.submit(), new FutureCallback<Void>() {

        @Override
        public void onSuccess(final Void 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, newPeerPath, tb);
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 2 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 AddPathAbstractRouteEntry method fillAdjRibsOut.

@SuppressWarnings("unchecked")
private void fillAdjRibsOut(final boolean isFirstBestPath, final Attributes attributes, final Route routeNonAddPath, final Route routeAddPath, final Identifier routeKeyAddNonPath, final Identifier routeKeyAddPath, final PeerId fromPeerId, final TablesKey localTK, 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 RIBSupport ribSupport = routeEntryDep.getRibSupport();
    for (final Peer toPeer : this.peerTracker.getPeers()) {
        if (!filterRoutes(fromPeerId, toPeer, localTK)) {
            continue;
        }
        final boolean destPeerSupAddPath = toPeer.supportsAddPathSupported(localTK);
        if (toPeer.getPeerId().getValue().equals("bgp://127.0.0.5")) {
            LOG.debug("Write route {} to peer AdjRibsOut {}", toPeer.getPeerId());
        }
        if (peersSupportsAddPathOrIsFirstBestPath(destPeerSupAddPath, isFirstBestPath)) {
            Optional<Attributes> effAttrib = Optional.empty();
            final Peer fromPeer = this.peerTracker.getPeer(fromPeerId);
            if (fromPeer != null && attributes != null) {
                final BGPRouteEntryExportParameters baseExp = new BGPRouteEntryExportParametersImpl(fromPeer, toPeer);
                effAttrib = routeEntryDep.getRoutingPolicies().applyExportPolicies(baseExp, attributes);
            }
            Route newRoute = null;
            InstanceIdentifier ribOutRoute = null;
            if (destPeerSupAddPath) {
                newRoute = routeAddPath;
                ribOutRoute = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), routeKeyAddPath);
            } else if (!this.oldNonAddPathBestPathTheSame) {
                ribOutRoute = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), routeKeyAddNonPath);
                newRoute = routeNonAddPath;
            }
            if (effAttrib.isPresent() && newRoute != null) {
                LOG.debug("Write route {} to peer AdjRibsOut {}", newRoute, toPeer.getPeerId());
                tx.put(LogicalDatastoreType.OPERATIONAL, ribOutRoute, newRoute);
                tx.put(LogicalDatastoreType.OPERATIONAL, ribOutRoute.child(Attributes.class), effAttrib.get());
            } else if (ribOutRoute != null) {
                LOG.trace("Removing {} from transaction for peer {}", ribOutRoute, toPeer.getPeerId());
                tx.delete(LogicalDatastoreType.OPERATIONAL, ribOutRoute);
            }
        }
    }
}
Also used : 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) Route(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route)

Example 3 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 MatchBgpNeighborSetTest method testMatchFromBgpNeighborInvert.

@Test
public void testMatchFromBgpNeighborInvert() {
    Statement statement = this.basicStatements.stream().filter(st -> st.getName().equals("reject-from-neighbor-invert-test")).findFirst().get();
    RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().build());
    doReturn(new PeerId("bgp://42.42.42.42")).when(this.exportParameters).getFromPeerId();
    RouteAttributeContainer result = this.statementRegistry.applyExportStatement(this.baseAttributes, IPV4UNICAST.class, this.exportParameters, attributeContainer, statement);
    assertNull(result.getAttributes());
    doReturn(new PeerId("bgp://127.0.0.1")).when(this.exportParameters).getFromPeerId();
    result = this.statementRegistry.applyExportStatement(this.baseAttributes, IPV4UNICAST.class, this.exportParameters, attributeContainer, statement);
    assertNotNull(result.getAttributes());
}
Also used : Statement(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement) RouteAttributeContainer(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder) IPV4UNICAST(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST) PeerId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId) Test(org.junit.Test)

Example 4 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 MatchBgpNeighborSetTest method testMatchToBgpNeighborInvert.

@Test
public void testMatchToBgpNeighborInvert() {
    Statement statement = this.basicStatements.stream().filter(st -> st.getName().equals("reject-to-neighbor-invert-test")).findFirst().get();
    RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().build());
    doReturn(new PeerId("bgp://127.0.0.2")).when(this.exportParameters).getFromPeerId();
    doReturn(new PeerId("bgp://42.42.42.42")).when(this.exportParameters).getToPeerId();
    RouteAttributeContainer result = this.statementRegistry.applyExportStatement(this.baseAttributes, IPV4UNICAST.class, this.exportParameters, attributeContainer, statement);
    assertNull(result.getAttributes());
    doReturn(new PeerId("bgp://127.0.0.1")).when(this.exportParameters).getToPeerId();
    result = this.statementRegistry.applyExportStatement(this.baseAttributes, IPV4UNICAST.class, this.exportParameters, attributeContainer, statement);
    assertNotNull(result.getAttributes());
}
Also used : Statement(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement) RouteAttributeContainer(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder) IPV4UNICAST(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST) PeerId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId) Test(org.junit.Test)

Example 5 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 matchBgpNeighborSetCondition.

private boolean matchBgpNeighborSetCondition(final PeerId fromPeerId, final PeerId toPeerId, final MatchBgpNeighborSet matchBgpNeighborSet) {
    final BgpNeighbor from = matchBgpNeighborSet.getFromNeighbor();
    Boolean match = null;
    if (from != null) {
        match = checkMatch(from.getNeighborSet(), fromPeerId, from.getMatchSetOptions());
    }
    if (match != null && !match) {
        return false;
    }
    final BgpNeighbor to = matchBgpNeighborSet.getToNeighbor();
    if (to != null) {
        match = checkMatch(to.getNeighborSet(), toPeerId, to.getMatchSetOptions());
    }
    return match;
}
Also used : BgpNeighbor(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev200120.BgpNeighbor)

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