Search in sources :

Example 1 with Rib

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

the class LocRibWriter method update.

@SuppressWarnings("unchecked")
private Map<RouteUpdateKey, RouteEntry> update(final WriteTransaction tx, final Collection<DataTreeModification<Tables>> changes) {
    final Map<RouteUpdateKey, RouteEntry> ret = new HashMap<>();
    for (final DataTreeModification<Tables> tc : changes) {
        final DataObjectModification<Tables> table = tc.getRootNode();
        final DataTreeIdentifier<Tables> rootPath = tc.getRootPath();
        final KeyedInstanceIdentifier<Peer, PeerKey> peerKIid = (KeyedInstanceIdentifier<Peer, PeerKey>) rootPath.getRootIdentifier().firstIdentifierOf(Peer.class);
        final UnsignedInteger peerUuid = RouterIds.routerIdForPeerId(peerKIid.getKey().getPeerId());
        /*
            Initialize Peer with routes under loc rib
             */
        if (!this.routeEntries.isEmpty() && table.getDataBefore() == null) {
            final org.opendaylight.protocol.bgp.rib.spi.Peer peer = this.peerTracker.getPeer(peerKIid.getKey().getPeerId());
            if (peer != null && peer.supportsTable(this.entryDep.getLocalTablesKey())) {
                LOG.debug("Peer {} table has been created, inserting existent routes", peer.getPeerId());
                this.routeEntries.forEach((key, value) -> value.initializeBestPaths(this.entryDep, new RouteEntryInfoImpl(peer, key), tx));
            }
        }
        /*
            Process new routes from Peer
             */
        updateNodes(table, peerUuid, tx, ret);
    }
    return ret;
}
Also used : RouteEntry(org.opendaylight.protocol.bgp.mode.api.RouteEntry) HashMap(java.util.HashMap) Peer(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.Peer) PeerKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.PeerKey) Tables(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.Tables) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) UnsignedInteger(com.google.common.primitives.UnsignedInteger)

Example 2 with Rib

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.Rib 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 Rib

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

the class BGPOperationalStateUtils method readGlobalFromDataStore.

private static Bgp readGlobalFromDataStore(final DataBroker dataBroker, final String ribId) {
    final InstanceIdentifier<Bgp> bgpIID = PROTOCOLS_IID.child(Protocol.class, new ProtocolKey(BGP.class, ribId)).augmentation(NetworkInstanceProtocol.class).child(Bgp.class);
    final ReadTransaction rot = dataBroker.newReadOnlyTransaction();
    try {
        return rot.read(LogicalDatastoreType.OPERATIONAL, bgpIID).get().orElse(null);
    } catch (final InterruptedException | ExecutionException e) {
        LOG.warn("Failed to read rib {}", ribId, e);
    }
    return null;
}
Also used : ProtocolKey(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.ProtocolKey) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) Bgp(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp) BGP(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP) NetworkInstanceProtocol(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.NetworkInstanceProtocol) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with Rib

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

the class ParserTest method testEORLS.

/*
     * End of Rib for LS consists of empty MP_UNREACH_NLRI, with AFI 16388 and SAFI 71
     *
     * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
     * 00 1d <- length (29) - including header
     * 02 <- message type
     * 00 00 <- withdrawn routes length
     * 00 06 <- total path attribute length
     * 80 <- attribute flags
     * 0f <- attribute type (15 - MP_UNREACH_NLRI)
     * 03 <- attribute length
     * 40 04 <- value (AFI 16388: LS)
     * 47 <- value (SAFI 71)
     */
@Test
public void testEORLS() throws Exception {
    final byte[] body = ByteArray.cutBytes(INPUT_BYTES.get(0), MessageUtil.COMMON_HEADER_LENGTH);
    final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(INPUT_BYTES.get(0), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
    final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, null);
    final Class<? extends AddressFamily> afi = message.getAttributes().augmentation(AttributesUnreach.class).getMpUnreachNlri().getAfi();
    final Class<? extends SubsequentAddressFamily> safi = message.getAttributes().augmentation(AttributesUnreach.class).getMpUnreachNlri().getSafi();
    assertEquals(LinkstateAddressFamily.class, afi);
    assertEquals(LinkstateSubsequentAddressFamily.class, safi);
    final ByteBuf buffer = Unpooled.buffer();
    ParserTest.updateParser.serializeMessage(message, buffer);
    assertArrayEquals(INPUT_BYTES.get(0), ByteArray.readAllBytes(buffer));
}
Also used : Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 5 with Rib

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

the class StateProviderImplTest method setUp.

@Before
public void setUp() {
    doReturn(IPV4UNICAST.class).when(this.tableTypeRegistry).getAfiSafiType(eq(TABLES_KEY));
    doReturn(this.bgpRibStates).when(this.stateProvider).getRibStats();
    doReturn(this.bgpPeerStates).when(this.stateProvider).getPeerStats();
    final KeyedInstanceIdentifier<Rib, RibKey> iid = InstanceIdentifier.create(BgpRib.class).child(Rib.class, new RibKey(new RibId(this.ribId)));
    doReturn(iid).when(this.bgpRibState).getInstanceIdentifier();
    doReturn(this.as).when(this.bgpRibState).getAs();
    doReturn(this.bgpId).when(this.bgpRibState).getRouteId();
    doAnswer(invocation -> this.totalPathsCounter.longValue()).when(this.bgpRibState).getTotalPathsCount();
    doAnswer(invocation -> this.totalPrefixesCounter.longValue()).when(this.bgpRibState).getTotalPrefixesCount();
    doAnswer(invocation -> this.totalPathsCounter.longValue()).when(this.bgpRibState).getPathCount(eq(TABLES_KEY));
    doAnswer(invocation -> this.totalPrefixesCounter.longValue()).when(this.bgpRibState).getPrefixesCount(eq(TABLES_KEY));
    doAnswer(invocation -> Map.of(TABLES_KEY, this.totalPathsCounter.longValue())).when(this.bgpRibState).getPathsCount();
    // Mock Peer
    doReturn("test-group").when(this.bgpPeerState).getGroupId();
    doReturn(iid).when(this.bgpPeerState).getInstanceIdentifier();
    doAnswer(invocation -> this.totalPrefixesCounter.longValue()).when(this.bgpPeerState).getTotalPrefixes();
    doAnswer(invocation -> this.totalPathsCounter.longValue()).when(this.bgpPeerState).getTotalPathsCount();
    doReturn(this.neighborAddress).when(this.bgpPeerState).getNeighborAddress();
    doReturn(this.bgpSessionState).when(this.bgpPeerState).getBGPSessionState();
    doReturn(this.bgpPeerMessagesState).when(this.bgpPeerState).getBGPPeerMessagesState();
    doReturn(1L).when(this.bgpPeerMessagesState).getNotificationMessagesReceivedCount();
    doReturn(1L).when(this.bgpPeerMessagesState).getNotificationMessagesSentCount();
    doReturn(1L).when(this.bgpPeerMessagesState).getUpdateMessagesReceivedCount();
    doReturn(1L).when(this.bgpPeerMessagesState).getUpdateMessagesSentCount();
    doReturn(State.UP).when(this.bgpSessionState).getSessionState();
    doReturn(true).when(this.bgpSessionState).isAddPathCapabilitySupported();
    doReturn(true).when(this.bgpSessionState).isAsn32CapabilitySupported();
    doReturn(true).when(this.bgpSessionState).isGracefulRestartCapabilitySupported();
    doReturn(true).when(this.bgpSessionState).isMultiProtocolCapabilitySupported();
    doReturn(true).when(this.bgpSessionState).isRouterRefreshCapabilitySupported();
    doReturn(this.timersState).when(this.bgpPeerState).getBGPTimersState();
    doReturn(10L).when(this.timersState).getNegotiatedHoldTime();
    doReturn(10L).when(this.timersState).getUpTime();
    doReturn(this.bgpTransportState).when(this.bgpPeerState).getBGPTransportState();
    doReturn(this.localPort).when(this.bgpTransportState).getLocalPort();
    doReturn(this.neighborAddress).when(this.bgpTransportState).getRemoteAddress();
    doReturn(this.remotePort).when(this.bgpTransportState).getRemotePort();
    doReturn(this.bgpErrorHandlingState).when(this.bgpPeerState).getBGPErrorHandlingState();
    doReturn(1L).when(this.bgpErrorHandlingState).getErroneousUpdateReceivedCount();
    doReturn(this.bgpGracelfulRestartState).when(this.bgpPeerState).getBGPGracelfulRestart();
    doReturn(true).when(this.bgpGracelfulRestartState).isLocalRestarting();
    doReturn(true).when(this.bgpGracelfulRestartState).isPeerRestarting();
    doReturn(this.restartTime.toJava()).when(this.bgpGracelfulRestartState).getPeerRestartTime();
    doReturn(BgpAfiSafiGracefulRestartState.Mode.BILATERAL).when(this.bgpGracelfulRestartState).getMode();
    doReturn(this.bgpAfiSafiState).when(this.bgpPeerState).getBGPAfiSafiState();
    doReturn(Set.of(TABLES_KEY)).when(this.bgpAfiSafiState).getAfiSafisAdvertized();
    doReturn(Set.of(TABLES_KEY)).when(this.bgpAfiSafiState).getAfiSafisReceived();
    doReturn(1L).when(this.bgpAfiSafiState).getPrefixesInstalledCount(any());
    doReturn(2L).when(this.bgpAfiSafiState).getPrefixesReceivedCount(any());
    doReturn(1L).when(this.bgpAfiSafiState).getPrefixesSentCount(any());
    doReturn(true).when(this.bgpAfiSafiState).isAfiSafiSupported(any());
    doReturn(true).when(this.bgpAfiSafiState).isGracefulRestartAdvertized(any());
    doReturn(true).when(this.bgpAfiSafiState).isGracefulRestartReceived(any());
    doReturn(true).when(this.bgpAfiSafiState).isLlGracefulRestartAdvertised(any());
    doReturn(true).when(this.bgpAfiSafiState).isLlGracefulRestartReceived(any());
    doReturn(60).when(this.bgpAfiSafiState).getLlGracefulRestartTimer(any());
}
Also used : RibId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId) RibKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.RibKey) BgpRib(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.BgpRib) Rib(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.Rib) BgpRib(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.BgpRib) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)16 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)7 InetSocketAddress (java.net.InetSocketAddress)5 Before (org.junit.Before)5 Ipv6Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)5 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update)5 RibId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId)5 ByteBuf (io.netty.buffer.ByteBuf)4 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey)4 ChannelFuture (io.netty.channel.ChannelFuture)3 ExecutionException (java.util.concurrent.ExecutionException)3 PathSelectionMode (org.opendaylight.protocol.bgp.mode.api.PathSelectionMode)3 BgpTableTypeImpl (org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl)3 PeerSpecificParserConstraint (org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)3 BgpTableType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType)3 ArrayList (java.util.ArrayList)2 BGPRouteEntryExportParametersImpl (org.opendaylight.protocol.bgp.mode.impl.BGPRouteEntryExportParametersImpl)2 NeighborBuilder (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)2