use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.
the class GracefulCapabilityHandler method serializeCapability.
private ByteBuf serializeCapability(final GracefulRestartCapability grace) {
final Map<TablesKey, Tables> tables = grace.getTables();
final int tablesSize = tables != null ? tables.size() : 0;
final ByteBuf bytes = Unpooled.buffer(HEADER_SIZE + PER_AFI_SAFI_SIZE * tablesSize);
Uint16 time = grace.getRestartTime();
if (time == null) {
time = Uint16.ZERO;
}
final int timeval = time.toJava();
Preconditions.checkArgument(timeval >= 0 && timeval <= MAX_RESTART_TIME, "Restart time is " + time);
final GracefulRestartCapability.RestartFlags flags = grace.getRestartFlags();
if (flags != null && flags.getRestartState()) {
bytes.writeShort(RESTART_FLAG_STATE | timeval);
} else {
bytes.writeShort(timeval);
}
serializeTables(tables, bytes);
return bytes;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.
the class LlGracefulCapabilityHandler method serializeCapability.
private ByteBuf serializeCapability(final LlGracefulRestartCapability cap) {
final Map<TablesKey, Tables> tables = cap.getTables();
if (tables == null || tables.isEmpty()) {
return Unpooled.EMPTY_BUFFER;
}
final ByteBuf buffer = Unpooled.buffer(PER_TABLE_SIZE * tables.size());
for (Tables table : tables.values()) {
final Class<? extends AddressFamily> afi = table.getAfi();
final Class<? extends SubsequentAddressFamily> safi = table.getSafi();
final Integer afival = this.afiReg.numberForClass(afi);
checkArgument(afival != null, "Unhandled address family %s", afi);
buffer.writeShort(afival);
final Integer safival = this.safiReg.numberForClass(safi);
checkArgument(safival != null, "Unhandled subsequent address family %s", safi);
buffer.writeByte(safival);
if (table.getAfiFlags() != null && table.getAfiFlags().getForwardingState()) {
buffer.writeByte(AFI_FLAG_FORWARDING_STATE);
} else {
buffer.writeByte(0);
}
final Uint24 staleTime = table.getLongLivedStaleTime();
final int timeval = staleTime != null ? staleTime.getValue().intValue() : 0;
checkArgument(timeval >= 0 && timeval <= MAX_STALE_TIME, "Restart time is %s", staleTime);
buffer.writeMedium(timeval);
}
return buffer;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.
the class AdjRibInWriter method updateRoutes.
void updateRoutes(final MpReachNlri nlri, final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes attributes) {
final TablesKey key = new TablesKey(nlri.getAfi(), nlri.getSafi());
final TableContext ctx = this.tables.get(key);
if (ctx == null) {
LOG.debug("No table for {}, not accepting NLRI {}", key, nlri);
return;
}
final DOMDataTreeWriteTransaction tx = this.chain.getDomChain().newWriteOnlyTransaction();
final Collection<NodeIdentifierWithPredicates> routeKeys = ctx.writeRoutes(tx, nlri, attributes);
final Collection<NodeIdentifierWithPredicates> staleRoutes = this.staleRoutesRegistry.get(key);
if (staleRoutes != null) {
staleRoutes.removeAll(routeKeys);
}
LOG.trace("Write routes {}", nlri);
final FluentFuture<? extends CommitInfo> future = tx.commit();
this.submitted = future;
future.addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.trace("Write routes {}, succeed", nlri);
}
@Override
public void onFailure(final Throwable throwable) {
LOG.error("Write routes failed", throwable);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.
the class AdjRibInWriter method storeStaleRoutes.
void storeStaleRoutes(final Set<TablesKey> gracefulTables) {
final CountDownLatch latch = new CountDownLatch(gracefulTables.size());
try (DOMDataTreeReadTransaction tx = this.chain.getDomChain().newReadOnlyTransaction()) {
for (TablesKey tablesKey : gracefulTables) {
final TableContext ctx = this.tables.get(tablesKey);
if (ctx == null) {
LOG.warn("Missing table for address family {}", tablesKey);
latch.countDown();
continue;
}
tx.read(LogicalDatastoreType.OPERATIONAL, ctx.routesPath()).addCallback(new FutureCallback<Optional<NormalizedNode>>() {
@Override
public void onSuccess(final Optional<NormalizedNode> routesOptional) {
try {
if (routesOptional.isPresent()) {
synchronized (AdjRibInWriter.this.staleRoutesRegistry) {
final MapNode routesNode = (MapNode) routesOptional.get();
final List<NodeIdentifierWithPredicates> routes = routesNode.body().stream().map(MapEntryNode::getIdentifier).collect(Collectors.toList());
if (!routes.isEmpty()) {
AdjRibInWriter.this.staleRoutesRegistry.put(tablesKey, routes);
}
}
}
} finally {
latch.countDown();
}
}
@Override
public void onFailure(final Throwable throwable) {
LOG.warn("Failed to store stale routes for table {}", tablesKey, throwable);
latch.countDown();
}
}, MoreExecutors.directExecutor());
}
}
try {
latch.await();
} catch (InterruptedException e) {
LOG.warn("Interrupted while waiting to store stale routes with {} tasks of {} to finish", latch.getCount(), gracefulTables, e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.
the class ApplicationPeer method instantiateServiceInstance.
public synchronized void instantiateServiceInstance(final DOMDataTreeChangeService dataTreeChangeService, final DOMDataTreeIdentifier appPeerDOMId) {
setActive(true);
final Set<TablesKey> localTables = this.rib.getLocalTablesKeys();
localTables.forEach(tablesKey -> this.supportedTables.add(RibSupportUtils.toYangTablesKey(tablesKey)));
setAdvertizedGracefulRestartTableTypes(Collections.emptyList());
createDomChain();
this.adjRibInWriter = AdjRibInWriter.create(this.rib.getYangRibId(), PeerRole.Internal, this);
final RIBSupportContextRegistry context = this.rib.getRibSupportContext();
final RegisterAppPeerListener registerAppPeerListener = () -> {
synchronized (this) {
if (getDomChain() != null) {
this.registration = dataTreeChangeService.registerDataTreeChangeListener(appPeerDOMId, this);
}
}
};
this.peerPath = createPeerPath(this.peerId);
this.adjRibInWriter = this.adjRibInWriter.transform(this.peerId, this.peerPath, context, localTables, Collections.emptyMap(), registerAppPeerListener);
this.effectiveRibInWriter = new EffectiveRibInWriter(this, this.rib, this.rib.createPeerDOMChain(this), this.peerPath, localTables, this.tableTypeRegistry, new ArrayList<>(), this.rtCache);
this.effectiveRibInWriter.init();
this.bgpSessionState.registerMessagesCounter(this);
this.trackerRegistration = this.rib.getPeerTracker().registerPeer(this);
}
Aggregations