From 9d575939fe52f6f6cbb49dd37a5347f0f5f055d2 Mon Sep 17 00:00:00 2001 From: Sam Robertson Date: Mon, 23 Jan 2012 13:28:39 -0800 Subject: [PATCH] Bug 11860: combining 32 bit signed values into a 64 bit value had errors. This should correct that --- .../network/resource/F5BigIpResource.java | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/core/src/com/cloud/network/resource/F5BigIpResource.java b/core/src/com/cloud/network/resource/F5BigIpResource.java index 0671e6089b4..c74a918e5fb 100644 --- a/core/src/com/cloud/network/resource/F5BigIpResource.java +++ b/core/src/com/cloud/network/resource/F5BigIpResource.java @@ -936,22 +936,10 @@ public class F5BigIpResource implements ServerResource { } long high = stat.getValue().getHigh(); - long low = stat.getValue().getLow(); - long full; - long rollOver = 0x7fffffff + 1; - - if (high >= 0) { - full = (high << 32) & 0xffff0000; - } else { - full = ((high & 0x7fffffff) << 32) + (0x80000000 << 32); - } - - if (low >= 0) { - full += low; - } else { - full += (low & 0x7fffffff) + rollOver; - } + long low = stat.getValue().getLow(); + long full = getFullUsage(high, low); + bytesSentAndReceived[index] += full; } @@ -967,6 +955,31 @@ public class F5BigIpResource implements ServerResource { return answer; } + private long getFullUsage(long high, long low) { + Double full; + Double rollOver = new Double((double) 0x7fffffff); + rollOver = new Double(rollOver.doubleValue() + 1.0); + + if (high >= 0) { + // shift left 32 bits and mask off new bits to 0's + full = new Double((high << 32 & 0xffff0000)); + } else { + // mask off sign bits + shift left by 32 bits then add the sign bit back + full = new Double(((high & 0x7fffffff) << 32) + (0x80000000 << 32)); + } + + if (low >= 0) { + // add low to full and we're good + full = new Double(full.doubleValue() + (double) low); + } else { + // add full to low after masking off sign bits and adding 1 to the masked off low order value + full = new Double(full.doubleValue() + (double) ((low & 0x7fffffff)) + rollOver.doubleValue()); + } + + return full.longValue(); + } + + // Misc methods private String tagAddressWithRouteDomain(String address, long vlanTag) {