Skip to content

Commit

Permalink
Fix NeighborUtil saturated conversion
Browse files Browse the repository at this point in the history
Use Uint32.saturatedOf() instead of our home-grown, buggy
implementation.

Change-Id: I4be14a570f3160d59cea0d7dc937a94b5774dc8c
Signed-off-by: Robert Varga <[email protected]>
  • Loading branch information
rovarga committed Mar 6, 2024
1 parent 1e8483d commit 2b143cb
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ private static Sent buildMessagesSent(final @NonNull BGPPeerMessagesState neighb
public static @NonNull NeighborErrorHandlingStateAugmentation buildErrorHandlingState(
final long erroneousUpdateCount) {
return new NeighborErrorHandlingStateAugmentationBuilder()
.setErroneousUpdateMessages(saturatedUint32(erroneousUpdateCount)).build();
.setErroneousUpdateMessages(Uint32.saturatedOf(erroneousUpdateCount))
.build();
}

/**
Expand Down Expand Up @@ -347,19 +348,14 @@ private static Sent buildMessagesSent(final @NonNull BGPPeerMessagesState neighb
builder.setActive(afiSafiSupported);
if (afiSafiSupported) {
builder.setPrefixes(new PrefixesBuilder()
.setInstalled(saturatedUint32(neighbor.getPrefixesInstalledCount(tablesKey)))
.setReceived(saturatedUint32(neighbor.getPrefixesReceivedCount(tablesKey)))
.setSent(saturatedUint32(neighbor.getPrefixesSentCount(tablesKey))).build());
.setInstalled(Uint32.saturatedOf(neighbor.getPrefixesInstalledCount(tablesKey)))
.setReceived(Uint32.saturatedOf(neighbor.getPrefixesReceivedCount(tablesKey)))
.setSent(Uint32.saturatedOf(neighbor.getPrefixesSentCount(tablesKey))).build());
}
return new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi
.safi.list.afi.safi.StateBuilder().addAugmentation(builder.build()).build();
}

// FIXME: remove this with YANGTOOLS-5.0.7+
private static Uint32 saturatedUint32(final long value) {
return value < 4294967295L ? Uint32.valueOf(value) : Uint32.MAX_VALUE;
}

private static org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi
.safi.list.afi.safi.GracefulRestart buildAfiSafiGracefulRestartState(
final @NonNull BGPLlGracelfulRestartState neighbor, final @NonNull TablesKey tablesKey) {
Expand Down

0 comments on commit 2b143cb

Please sign in to comment.