Search in sources :

Example 1 with RouteEntry

use of org.opendaylight.protocol.bgp.mode.api.RouteEntry 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 RouteEntry

use of org.opendaylight.protocol.bgp.mode.api.RouteEntry in project bgpcep by opendaylight.

the class LocRibWriter method walkThrough.

private void walkThrough(final WriteTransaction tx, final Set<Map.Entry<RouteUpdateKey, RouteEntry>> toUpdate) {
    for (final Map.Entry<RouteUpdateKey, RouteEntry> e : toUpdate) {
        LOG.trace("Walking through {}", e);
        final RouteEntry entry = e.getValue();
        if (!entry.selectBest(this.ourAs)) {
            LOG.trace("Best path has not changed, continuing");
            continue;
        }
        entry.updateBestPaths(entryDep, e.getKey().getRouteId(), tx);
    }
}
Also used : RouteEntry(org.opendaylight.protocol.bgp.mode.api.RouteEntry) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with RouteEntry

use of org.opendaylight.protocol.bgp.mode.api.RouteEntry in project bgpcep by opendaylight.

the class LocRibWriter method createEntry.

@Nonnull
private RouteEntry createEntry(final Identifier routeId) {
    final RouteEntry ret = this.pathSelectionMode.createRouteEntry(this.ribSupport.isComplexRoute());
    this.routeEntries.put(routeId, ret);
    this.totalPrefixesCounter.increment();
    LOG.trace("Created new entry for {}", routeId);
    return ret;
}
Also used : RouteEntry(org.opendaylight.protocol.bgp.mode.api.RouteEntry) Nonnull(javax.annotation.Nonnull)

Example 4 with RouteEntry

use of org.opendaylight.protocol.bgp.mode.api.RouteEntry in project bgpcep by opendaylight.

the class LocRibWriter method onDataTreeChanged.

/**
 * We use two-stage processing here in hopes that we avoid duplicate
 * calculations when multiple peers have changed a particular entry.
 *
 * @param changes on supported table
 */
@Override
public void onDataTreeChanged(final Collection<DataTreeModification<Tables>> changes) {
    LOG.trace("Received data change {} to LocRib {}", changes, this);
    final WriteTransaction tx = this.chain.newWriteOnlyTransaction();
    try {
        final Map<RouteUpdateKey, RouteEntry> toUpdate = update(tx, changes);
        if (!toUpdate.isEmpty()) {
            walkThrough(tx, toUpdate.entrySet());
        }
    } catch (final Exception e) {
        LOG.error("Failed to completely propagate updates {}, state is undefined", changes, e);
    } finally {
        tx.submit();
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) RouteEntry(org.opendaylight.protocol.bgp.mode.api.RouteEntry)

Example 5 with RouteEntry

use of org.opendaylight.protocol.bgp.mode.api.RouteEntry in project bgpcep by opendaylight.

the class LocRibWriter method updateRoutesEntries.

@SuppressWarnings("unchecked")
private void updateRoutesEntries(final Collection<DataObjectModification<? extends DataObject>> routeChanges, final UnsignedInteger routerId, final Map<RouteUpdateKey, RouteEntry> routes) {
    for (final DataObjectModification<? extends DataObject> route : routeChanges) {
        final Identifier routeKey = ((InstanceIdentifier.IdentifiableItem) route.getIdentifier()).getKey();
        RouteEntry entry = this.routeEntries.get(routeKey);
        final Route newRoute = (Route) route.getDataAfter();
        final Route oldRoute = (Route) route.getDataBefore();
        if (newRoute != null) {
            if (entry == null) {
                entry = createEntry(routeKey);
            }
            final long pathId = this.ribSupport.extractPathId(newRoute);
            entry.addRoute(routerId, pathId, newRoute);
            this.totalPathsCounter.increment();
        } else if (oldRoute != null && entry != null) {
            this.totalPathsCounter.decrement();
            final long pathId = this.ribSupport.extractPathId(oldRoute);
            if (entry.removeRoute(routerId, pathId)) {
                this.routeEntries.remove(routeKey);
                this.totalPrefixesCounter.decrement();
                LOG.trace("Removed route from {}", routerId);
            }
        }
        final RouteUpdateKey routeUpdateKey = new RouteUpdateKey(routerId, routeKey);
        LOG.debug("Updated route {} entry {}", routeKey, entry);
        routes.put(routeUpdateKey, entry);
    }
}
Also used : RouteEntry(org.opendaylight.protocol.bgp.mode.api.RouteEntry) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) Identifier(org.opendaylight.yangtools.yang.binding.Identifier) DataTreeIdentifier(org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier) Route(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route)

Aggregations

RouteEntry (org.opendaylight.protocol.bgp.mode.api.RouteEntry)5 HashMap (java.util.HashMap)2 KeyedInstanceIdentifier (org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier)2 UnsignedInteger (com.google.common.primitives.UnsignedInteger)1 Map (java.util.Map)1 Nonnull (javax.annotation.Nonnull)1 DataTreeIdentifier (org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier)1 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)1 Route (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route)1 Peer (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.Peer)1 PeerKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.PeerKey)1 Tables (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.Tables)1 Identifier (org.opendaylight.yangtools.yang.binding.Identifier)1 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)1