We are receiving a splat when the sum ends up being negative. While the
underlying cause needs to be investigated, we also should be properly
defensive. Uint32.saturatedOf() catches negative values and squashes
them to 0.
JIRA: BGPCEP-1021
Change-Id: Ia376305aa677ebd05a41629c5083f8829891615f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit
cc71ea45a8e373d50b063a61966245c5e90d4aa8)
public static @NonNull PeerGroup buildPeerGroupState(final @NonNull String groupId,
final @NonNull List<BGPPeerState> groups) {
final PeerGroupStateAugmentation groupState = new PeerGroupStateAugmentationBuilder()
public static @NonNull PeerGroup buildPeerGroupState(final @NonNull String groupId,
final @NonNull List<BGPPeerState> groups) {
final PeerGroupStateAugmentation groupState = new PeerGroupStateAugmentationBuilder()
- .setTotalPrefixes(saturatedUint32(groups.stream().mapToLong(BGPPeerState::getTotalPrefixes).sum()))
- .setTotalPaths(saturatedUint32(groups.stream().mapToLong(BGPPeerState::getTotalPathsCount).sum()))
+ .setTotalPrefixes(Uint32.saturatedOf(groups.stream().mapToLong(BGPPeerState::getTotalPrefixes).sum()))
+ .setTotalPaths(Uint32.saturatedOf(groups.stream().mapToLong(BGPPeerState::getTotalPathsCount).sum()))
.build();
return new PeerGroupBuilder()
.build();
return new PeerGroupBuilder()
.setState(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group
.StateBuilder().addAugmentation(groupState).build()).build();
}
.setState(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group
.StateBuilder().addAugmentation(groupState).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;
- }
-