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;
}
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);
}
}
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;
}
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();
}
}
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);
}
}
Aggregations