Search in sources :

Example 1 with Rib

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.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.rev171207.bgp.rib.Rib in project bgpcep by opendaylight.

the class BGPClusterSingletonService method onGlobalChanged.

synchronized void onGlobalChanged(final DataObjectModification<Global> dataObjectModification) {
    switch(dataObjectModification.getModificationType()) {
        case DELETE:
            LOG.debug("Removing RIB instance: {}", this.bgpIid);
            if (this.ribImpl != null) {
                LOG.debug("RIB instance removed {}", this.ribImpl);
                closeAllBindedPeers();
                closeRibService();
            }
            break;
        case SUBTREE_MODIFIED:
        case WRITE:
            final Global global = dataObjectModification.getDataAfter();
            if (this.ribImpl == null) {
                onGlobalCreated(global);
            } else if (!this.ribImpl.isGlobalEqual(global)) {
                onGlobalUpdated(global);
            }
            break;
        default:
            break;
    }
}
Also used : Global(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global)

Example 3 with Rib

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.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(inputBytes.get(0), MessageUtil.COMMON_HEADER_LENGTH);
    final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
    final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
    final Class<? extends AddressFamily> afi = message.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getAfi();
    final Class<? extends SubsequentAddressFamily> safi = message.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getSafi();
    assertEquals(LinkstateAddressFamily.class, afi);
    assertEquals(LinkstateSubsequentAddressFamily.class, safi);
    final ByteBuf buffer = Unpooled.buffer();
    ParserTest.updateParser.serializeMessage(message, buffer);
    assertArrayEquals(inputBytes.get(0), ByteArray.readAllBytes(buffer));
}
Also used : Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 4 with Rib

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.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 ReadOnlyTransaction rot = dataBroker.newReadOnlyTransaction();
    try {
        return rot.read(LogicalDatastoreType.OPERATIONAL, bgpIID).get().orNull();
    } 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) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) 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.rev180321.NetworkInstanceProtocol) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with Rib

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

the class BGPParserTest method testEORIpv6.

/*
     * End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
     *
     * 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
     * 00 02 <- value (AFI 2: IPv6)
     * 01 <- value (SAFI 1)
     */
@Test
public void testEORIpv6() throws Exception {
    final byte[] body = ByteArray.cutBytes(inputBytes.get(6), MessageUtil.COMMON_HEADER_LENGTH);
    final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
    final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
    final Class<? extends AddressFamily> afi = message.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getAfi();
    final Class<? extends SubsequentAddressFamily> safi = message.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getSafi();
    assertEquals(Ipv6AddressFamily.class, afi);
    assertEquals(UnicastSubsequentAddressFamily.class, safi);
    final ByteBuf buffer = Unpooled.buffer();
    BGPParserTest.updateParser.serializeMessage(message, buffer);
    assertArrayEquals(inputBytes.get(6), ByteArray.readAllBytes(buffer));
}
Also used : Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update) ByteBuf(io.netty.buffer.ByteBuf) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 RibId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.RibId)6 ByteBuf (io.netty.buffer.ByteBuf)4 Before (org.junit.Before)4 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey)4 ChannelFuture (io.netty.channel.ChannelFuture)3 InetSocketAddress (java.net.InetSocketAddress)3 PathSelectionMode (org.opendaylight.protocol.bgp.mode.api.PathSelectionMode)3 PeerSpecificParserConstraint (org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)3 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update)3 BgpTableType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType)3 ExecutionException (java.util.concurrent.ExecutionException)2 BGPRouteEntryExportParametersImpl (org.opendaylight.protocol.bgp.mode.impl.BGPRouteEntryExportParametersImpl)2 BgpTableTypeImpl (org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl)2 Peer (org.opendaylight.protocol.bgp.rib.spi.Peer)2 RIBSupport (org.opendaylight.protocol.bgp.rib.spi.RIBSupport)2 BGPRouteEntryExportParameters (org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters)2 BgpId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId)2 KeyedInstanceIdentifier (org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1