* Fixed floating point arith error. tc likes whole numbers.
authorFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Fri, 1 Dec 2006 22:02:01 +0000 (22:02 +0000)
committerFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Fri, 1 Dec 2006 22:02:01 +0000 (22:02 +0000)
* Added extra debug statements.

bwmon.py

index b31e893..09bea99 100755 (executable)
--- a/bwmon.py
+++ b/bwmon.py
@@ -100,12 +100,6 @@ class Slice:
        ByteThresh - After thresh, cap node to (maxbyte - bytes)/(time left in period)
        ExemptByteMax - Same as above, but for i2.
        ExemptByteThresh - i2 ByteThresh
        ByteThresh - After thresh, cap node to (maxbyte - bytes)/(time left in period)
        ExemptByteMax - Same as above, but for i2.
        ExemptByteThresh - i2 ByteThresh
-       #last_maxexemptrate - last recorded maxexemptrate from NM.  Slice attribute.
-       #last_maxrate - last recorded maxrate from NM.  Slice attribute.
-       #last_ByteMax - Last recorded from NM. total volume of data allowed.
-       #last_ByteThresh - Last recorded from NM.  After thresh, cap node to (maxbyte - bytes)/(period - t)
-       #last_ExemptByteMax - Last recorded from NM.  Same as above, but for i2.
-       #last_ExemptByteThresh - Last recorded from NM.  i2 ByteThresh
 
     """
 
 
     """
 
@@ -121,12 +115,6 @@ class Slice:
                self.ExemptByteThresh = default_ExemptByteThresh
                self.maxrate = default_maxrate
                self.maxexemptrate = default_maxexemptrate
                self.ExemptByteThresh = default_ExemptByteThresh
                self.maxrate = default_maxrate
                self.maxexemptrate = default_maxexemptrate
-               #self.last_maxrate = default_maxrate
-               #self.last_maxexemptrate = default_maxexemptrate        
-               #self.last_ByteMax = default_ByteMax
-               #self.last_ByteThresh = default_ByteThresh
-               #self.last_ExemptByteMax = default_ExemptByteMax
-               #self.last_ExemptByteThresh = default_ExemptByteThresh
 
                # Get real values where applicable
                self.reset(maxrate, maxexemptrate, bytes, exemptbytes)
 
                # Get real values where applicable
                self.reset(maxrate, maxexemptrate, bytes, exemptbytes)
@@ -170,13 +158,8 @@ class Slice:
 
        def update(self, maxrate, maxexemptrate, bytes, exemptbytes):
                """
 
        def update(self, maxrate, maxexemptrate, bytes, exemptbytes):
                """
-               Update byte counts and check if average rates have been
-               exceeded. In the worst case (instantaneous usage of the entire
-               average daily byte limit at the beginning of the recording
-               period), the slice will be immediately capped and will get to
-               send twice the average daily byte limit. In the common case,
-               it will get to send slightly more than the average daily byte
-               limit.
+               Update byte counts and check if byte limits have been
+               exceeded. 
                """
        
                # Query Node Manager for max rate overrides
                """
        
                # Query Node Manager for max rate overrides
@@ -190,8 +173,9 @@ class Slice:
                                  'date': time.asctime(time.gmtime()) + " GMT",
                                  'period': format_period(period)} 
 
                                  'date': time.asctime(time.gmtime()) + " GMT",
                                  'period': format_period(period)} 
 
+               print("byts %s self.bytes %s ByteThresh %s" %(bytes, self.bytes, self.ByteThresh))
                if bytes >= (self.bytes + self.ByteThresh):
                if bytes >= (self.bytes + self.ByteThresh):
-                       new_maxrate = (self.ByteMax - self.ByteThresh)/(period - (time.time() - self.time))
+                       new_maxrate = int(self.ByteMax - self.ByteThresh)/(period - (time.time() - self.time))
                else:
                        new_maxrate = maxrate
 
                else:
                        new_maxrate = maxrate
 
@@ -204,7 +188,7 @@ class Slice:
 
                if verbose:
                        print "%(slice)s %(class)s " \
 
                if verbose:
                        print "%(slice)s %(class)s " \
-                                 "%(bytes)s, %(limit)s (%(new_maxrate)s avg)" % \
+                                 "%(bytes)s, %(limit)s (%(new_maxrate)s maxrate)" % \
                                  params
 
                # Cap low bandwidth burst rate
                                  params
 
                # Cap low bandwidth burst rate
@@ -214,7 +198,7 @@ class Slice:
        
                if exemptbytes >= (self.exemptbytes + self.ExemptByteThresh):
                        new_maxexemptrate = \
        
                if exemptbytes >= (self.exemptbytes + self.ExemptByteThresh):
                        new_maxexemptrate = \
-                       (self.ExemptByteMax - self.ExemptByteThresh)/(period - (time.time() - self.time))
+                       int((self.ExemptByteMax - self.ExemptByteThresh)/(period - (time.time() - self.time)))
                else:
                        new_maxexemptrate = maxexemptrate
 
                else:
                        new_maxexemptrate = maxexemptrate
 
@@ -247,6 +231,8 @@ class Slice:
                        else:
                                slicemail(self.name, subject, message + (footer % params))
 
                        else:
                                slicemail(self.name, subject, message + (footer % params))
 
+
+
 def usage():
        print """
 Usage: %s [OPTIONS]...
 def usage():
        print """
 Usage: %s [OPTIONS]...
@@ -328,8 +314,16 @@ def main():
                 bytes, exemptbytes) = params
                live.append(xid)
                
                 bytes, exemptbytes) = params
                live.append(xid)
                
-               # Delete Me
-               print("name %s , minrate %s, maxrate %s, minexemptrate %s, maxexemptrate %s, bytes %s, exemptbytes %s" % (bwlimit.get_slice(xid), minrate, maxrate, minexemptrate, maxexemptrate, bytes, exemptbytes))
+               if verbose:
+                       print("\n%s, minrate %s, maxrate %s, minexemptrate %s,"\
+                               " maxexemptrate %s, bytes %s, exemptbytes %s" % \
+                               (bwlimit.get_slice(xid), 
+                               bwlimit.format_tc_rate(minrate),
+                               bwlimit.format_tc_rate(maxrate), 
+                               bwlimit.format_tc_rate(minexemptrate),
+                               bwlimit.format_tc_rate(maxexemptrate), 
+                               bytes, 
+                               exemptbytes))
 
                # Ignore root and default buckets
                if xid == root_xid or xid == default_xid:
 
                # Ignore root and default buckets
                if xid == root_xid or xid == default_xid: