[or-cvs] r21411: {torflow} Add code to dump stats on ratios for guard, middle, and exit (torflow/trunk/NetworkScanners)

Mike Perry mikeperry-svn at fscked.org
Thu Jan 14 01:40:58 UTC 2010


Author: mikeperry
Date: 2010-01-14 01:40:57 +0000 (Thu, 14 Jan 2010)
New Revision: 21411

Modified:
   torflow/trunk/NetworkScanners/statsplitter.py
Log:

Add code to dump stats on ratios for guard, middle, and exit
nodes.



Modified: torflow/trunk/NetworkScanners/statsplitter.py
===================================================================
--- torflow/trunk/NetworkScanners/statsplitter.py	2010-01-13 21:42:38 UTC (rev 21410)
+++ torflow/trunk/NetworkScanners/statsplitter.py	2010-01-14 01:40:57 UTC (rev 21411)
@@ -11,8 +11,11 @@
 from TorCtl.PathSupport import *
 import atexit
 
-TorUtil.loglevel = "INFO"
+TorUtil.loglevel = "WARN"
 
+# TODO:
+#  Print ratios of All, Guard, Mid, Exit and Guard+Exit nodes
+#    - Print Num < 1, Num >= 1, avg < 1, avg >= 1, and avg for each
 
 def cleanup(c, f):
   print "Resetting FetchUselessDescriptors to "+f
@@ -69,12 +72,19 @@
 # >= 0.2.2.2-alpha and >= 0.2.1.20
 cwind_yes = NodeRestrictionList([VersionRangeRestriction("0.2.1.20"),
              NotNodeRestriction(VersionRangeRestriction("0.2.2.0", "0.2.2.1"))])
-       
 cwind_no = NotNodeRestriction(cwind_yes)
 
+nsbw_yes = VersionRangeRestriction("0.2.1.17")
+nsbw_no = NotNodeRestriction(nsbw_yes)
+
+
 fast_rst = FlagsRestriction(["Fast"], [])
 #exit_rst = NodeRestrictionList([cwind_yes, FlagsRestriction(["Exit"], [])])
 exit_rst = FlagsRestriction(["Exit"], [])
+exitonly_rst = FlagsRestriction(["Exit"], ["Guard"])
+guardonly_rst = FlagsRestriction(["Guard"], ["Exit"])
+guardexit_rst = FlagsRestriction(["Guard", "Exit"], [])
+mid_rst = FlagsRestriction([], ["Guard", "Exit"])
 dir_rst = FlagsRestriction(["V2Dir"], [])
 heavy_exits = OrNodeRestriction(
       [ExitPolicyRestriction("255.255.255.255", 6881),
@@ -82,7 +92,6 @@
       ExitPolicyRestriction("255.255.255.255", 6346),
       ExitPolicyRestriction("255.255.255.255", 25)])
 
-
 def check(start, stop):
   pct_rst = PercentileRestriction(start, stop, sorted_rlist)
   bw = 0
@@ -93,11 +102,14 @@
   dirs = 0
   nodes_up = 0.0000000005 # shhh. dirty hack for div 0 
   up = 0
-  
+  pct_list = []
+
   for r in sorted_rlist:
     if pct_rst.r_is_ok(r) and fast_rst.r_is_ok(r):
       nodes += 1
       bw += r.bw
+      pct_list.append(r)
+
       if r.uptime > 0:
         nodes_up += 1.0
         up += r.uptime
@@ -109,11 +121,12 @@
       if dir_rst.r_is_ok(r):
         dirs += 1
 
+
   print str(start)+"-"+str(stop)+": N: "+str(nodes)+", Bw: "+str(round(bw/(1024*1024.0), 2))+", X: "+str(exits)+", XBw: "+str(round(exit_bw/(1024*1024.0),2))+", BT: "+str(heavy)+", Dirs:"+str(dirs)+", Up: "+str(round(up/nodes_up/60/60/24, 2))
 
-for i in xrange(0,100,10):
-  check(i,i+10)
+  #check_ratios(pct_list)
 
+
 def check_entropy(rlist, clipping_point):
   clipped = 0
   clipped_bw = 0.0
@@ -184,7 +197,8 @@
     else:
       rbw = r.desc_bw
     clipped_entropy += (rbw/clipped_bw)*math.log(rbw/clipped_bw, 2)
-  
+
+  print ""
   print "Uniform entropy: " + str(-uniform_entropy)
   print "Consensus entropy: " + str(-pure_entropy)
   print "Raw Descriptor entropy: " + str(-desc_entropy)
@@ -196,6 +210,172 @@
 
   print "Nodes: "+str(nodes)+", Exits: "+str(exits)+" Total bw: "+str(round(bw/(1024.0*1024),2))+", Exit Bw: "+str(round(exit_bw/(1024.0*1024),2))
   print "Clipped: "+str(clipped)+", bw: "+str(round(clipped_bw/(1024.0*1024),2))
+  print ""
 
 
+class RatioStats:
+  def __init__(self):
+    self.avg = 0
+    self.avg_lt1 = 0
+    self.avg_gt1 = 0
+    self.cnt = 0
+    self.cnt_lt1 = 0
+    self.cnt_gt1 = 0
+    self.pct_lt1 = 0
+    self.pct_gt1 = 0
+
+def check_ratios(sorted_rlist):
+  # ratio stats
+  all_ratio = RatioStats()
+  guard_ratio = RatioStats()
+  mid_ratio = RatioStats()
+  exit_ratio = RatioStats()
+  guardexit_ratio = RatioStats()
+
+  for r in sorted_rlist:
+    if r.down or r.desc_bw <= 0: continue
+    ratio = float(r.bw)/r.desc_bw
+    if ratio >= 1:
+      rc_gt1 = 1
+      rc_lt1 = 0
+      r_gt1 = ratio
+      r_lt1 = 0
+    else:
+      rc_gt1 = 0
+      rc_lt1 = 1
+      r_gt1 = 0
+      r_lt1 = ratio
+
+    all_ratio.cnt += 1
+    all_ratio.cnt_lt1 += rc_lt1
+    all_ratio.cnt_gt1 += rc_gt1
+    all_ratio.avg += ratio
+    all_ratio.avg_lt1 += r_lt1
+    all_ratio.avg_gt1 += r_gt1
+
+    if guardonly_rst.r_is_ok(r):
+      guard_ratio.avg += ratio
+      guard_ratio.avg_lt1 += r_lt1
+      guard_ratio.avg_gt1 += r_gt1
+      guard_ratio.cnt += 1
+      guard_ratio.cnt_lt1 += rc_lt1
+      guard_ratio.cnt_gt1 += rc_gt1
+    if guardexit_rst.r_is_ok(r):
+      guardexit_ratio.avg += ratio
+      guardexit_ratio.avg_lt1 += r_lt1
+      guardexit_ratio.avg_gt1 += r_gt1
+      guardexit_ratio.cnt += 1
+      guardexit_ratio.cnt_lt1 += rc_lt1
+      guardexit_ratio.cnt_gt1 += rc_gt1
+    if exitonly_rst.r_is_ok(r):
+      exit_ratio.avg += ratio
+      exit_ratio.avg_lt1 += r_lt1
+      exit_ratio.avg_gt1 += r_gt1
+      exit_ratio.cnt += 1
+      exit_ratio.cnt_lt1 += rc_lt1
+      exit_ratio.cnt_gt1 += rc_gt1
+    if mid_rst.r_is_ok(r):
+      mid_ratio.avg += ratio
+      mid_ratio.avg_lt1 += r_lt1
+      mid_ratio.avg_gt1 += r_gt1
+      mid_ratio.cnt += 1
+      mid_ratio.cnt_lt1 += rc_lt1
+      mid_ratio.cnt_gt1 += rc_gt1
+
+  if not all_ratio.cnt:     all_ratio.cnt = -1
+  if not all_ratio.cnt_lt1: all_ratio.cnt_lt1 = -1
+  if not all_ratio.cnt_gt1: all_ratio.cnt_gt1 = -1
+
+  all_ratio.avg     /= all_ratio.cnt
+  all_ratio.avg_lt1 /= all_ratio.cnt_lt1
+  all_ratio.avg_gt1 /= all_ratio.cnt_gt1
+  all_ratio.pct_lt1 = round((100.0*all_ratio.cnt_lt1)/all_ratio.cnt,1)
+  all_ratio.pct_gt1 = round((100.0*all_ratio.cnt_gt1)/all_ratio.cnt,1)
+
+  if not guard_ratio.cnt:     guard_ratio.cnt = -1
+  if not guard_ratio.cnt_lt1: guard_ratio.cnt_lt1 = -1
+  if not guard_ratio.cnt_gt1: guard_ratio.cnt_gt1 = -1
+
+  guard_ratio.avg     /= guard_ratio.cnt
+  guard_ratio.avg_lt1 /= guard_ratio.cnt_lt1
+  guard_ratio.avg_gt1 /= guard_ratio.cnt_gt1
+  guard_ratio.pct_lt1 = round((100.0*guard_ratio.cnt_lt1)/guard_ratio.cnt,1)
+  guard_ratio.pct_gt1 = round((100.0*guard_ratio.cnt_gt1)/guard_ratio.cnt,1)
+
+  if not mid_ratio.cnt:     mid_ratio.cnt = -1
+  if not mid_ratio.cnt_lt1: mid_ratio.cnt_lt1 = -1
+  if not mid_ratio.cnt_gt1: mid_ratio.cnt_gt1 = -1
+
+  mid_ratio.avg     /= mid_ratio.cnt
+  mid_ratio.avg_lt1 /= mid_ratio.cnt_lt1
+  mid_ratio.avg_gt1 /= mid_ratio.cnt_gt1
+  mid_ratio.pct_lt1 = round((100.0*mid_ratio.cnt_lt1)/mid_ratio.cnt,1)
+  mid_ratio.pct_gt1 = round((100.0*mid_ratio.cnt_gt1)/mid_ratio.cnt,1)
+
+  if not exit_ratio.cnt:     exit_ratio.cnt = -1
+  if not exit_ratio.cnt_lt1: exit_ratio.cnt_lt1 = -1
+  if not exit_ratio.cnt_gt1: exit_ratio.cnt_gt1 = -1
+
+  exit_ratio.avg     /= exit_ratio.cnt
+  exit_ratio.avg_lt1 /= exit_ratio.cnt_lt1
+  exit_ratio.avg_gt1 /= exit_ratio.cnt_gt1
+  exit_ratio.pct_lt1 = round((100.0*exit_ratio.cnt_lt1)/exit_ratio.cnt,1)
+  exit_ratio.pct_gt1 = round((100.0*exit_ratio.cnt_gt1)/exit_ratio.cnt,1)
+
+  if not guardexit_ratio.cnt:     guardexit_ratio.cnt = -1
+  if not guardexit_ratio.cnt_lt1: guardexit_ratio.cnt_lt1 = -1
+  if not guardexit_ratio.cnt_gt1: guardexit_ratio.cnt_gt1 = -1
+
+  guardexit_ratio.avg     /= guardexit_ratio.cnt
+  guardexit_ratio.avg_lt1 /= guardexit_ratio.cnt_lt1
+  guardexit_ratio.avg_gt1 /= guardexit_ratio.cnt_gt1
+  guardexit_ratio.pct_lt1 = \
+       round((100.0*guardexit_ratio.cnt_lt1)/guardexit_ratio.cnt,1)
+  guardexit_ratio.pct_gt1 = \
+       round((100.0*guardexit_ratio.cnt_gt1)/guardexit_ratio.cnt,1)
+
+  #  Print ratios of All, Guard, Mid, Exit and Guard+Exit nodes
+  #    - Print Num < 1, Num >= 1, avg < 1, avg >= 1, and avg for each
+  print "Overall Cnt: "       +str(all_ratio.cnt)
+  print "Overall Avg Ratio: "     +str(all_ratio.avg)
+  print "Overall Ratios < 1 Pct: "+str(all_ratio.pct_lt1)
+  print "Overall Ratios < 1 Avg: "+str(all_ratio.avg_lt1)
+  print "Overall Ratios > 1 Pct: "+str(all_ratio.pct_gt1)
+  print "Overall Ratios > 1 Avg: "+str(all_ratio.avg_gt1)
+  print ""
+  print "Guard Cnt: "       +str(guard_ratio.cnt)
+  print "Guard Avg Ratio: "     +str(guard_ratio.avg)
+  print "Guard Ratios < 1 Pct: "+str(guard_ratio.pct_lt1)
+  print "Guard Ratios < 1 Avg: "+str(guard_ratio.avg_lt1)
+  print "Guard Ratios > 1 Pct: "+str(guard_ratio.pct_gt1)
+  print "Guard Ratios > 1 Avg: "+str(guard_ratio.avg_gt1)
+  print ""
+  print "Mid Cnt: "       +str(mid_ratio.cnt)
+  print "Mid Avg Ratio: "     +str(mid_ratio.avg)
+  print "Mid Ratios < 1 Pct: "+str(mid_ratio.pct_lt1)
+  print "Mid Ratios < 1 Avg: "+str(mid_ratio.avg_lt1)
+  print "Mid Ratios > 1 Pct: "+str(mid_ratio.pct_gt1)
+  print "Mid Ratios > 1 Avg: "+str(mid_ratio.avg_gt1)
+  print ""
+  print "Exit Cnt: "       +str(exit_ratio.cnt)
+  print "Exit Avg Ratio: "     +str(exit_ratio.avg)
+  print "Exit Ratios < 1 Pct: "+str(exit_ratio.pct_lt1)
+  print "Exit Ratios < 1 Avg: "+str(exit_ratio.avg_lt1)
+  print "Exit Ratios > 1 Pct: "+str(exit_ratio.pct_gt1)
+  print "Exit Ratios > 1 Avg: "+str(exit_ratio.avg_gt1)
+  print ""
+  print "Guard+Exit Cnt: "       +str(guardexit_ratio.cnt)
+  print "Guard+Exit Avg Ratio: "     +str(guardexit_ratio.avg)
+  print "Guard+Exit Ratios < 1 Pct: "+str(guardexit_ratio.pct_lt1)
+  print "Guard+Exit Ratios < 1 Avg: "+str(guardexit_ratio.avg_lt1)
+  print "Guard+Exit Ratios > 1 Pct: "+str(guardexit_ratio.pct_gt1)
+  print "Guard+Exit Ratios > 1 Avg: "+str(guardexit_ratio.avg_gt1)
+  print ""
+
+
+for i in xrange(0,100,10):
+  check(i,i+10)
+
 check_entropy(sorted_rlist, 1500000)
+
+check_ratios(sorted_rlist)



More information about the tor-commits mailing list