[or-cvs] r18137: {torflow} Integrate verification routines into the buildtimes script i (torflow/trunk/CircuitAnalysis/BuildTimes)

mikeperry at seul.org mikeperry at seul.org
Sat Jan 17 00:15:57 UTC 2009


Author: mikeperry
Date: 2009-01-16 19:15:57 -0500 (Fri, 16 Jan 2009)
New Revision: 18137

Modified:
   torflow/trunk/CircuitAnalysis/BuildTimes/buildtimes.py
   torflow/trunk/CircuitAnalysis/BuildTimes/dist_check.py
   torflow/trunk/CircuitAnalysis/BuildTimes/full_run.sh
Log:

Integrate verification routines into the buildtimes script
itself, so we can better leverage information collected in
its routers, and run the checks more frequently. They can
still be run standalone, but some verication info will be
missing.



Modified: torflow/trunk/CircuitAnalysis/BuildTimes/buildtimes.py
===================================================================
--- torflow/trunk/CircuitAnalysis/BuildTimes/buildtimes.py	2009-01-16 19:23:26 UTC (rev 18136)
+++ torflow/trunk/CircuitAnalysis/BuildTimes/buildtimes.py	2009-01-17 00:15:57 UTC (rev 18137)
@@ -15,11 +15,15 @@
 sys.path.append("../../")
 import TorCtl
 from TorCtl.TorUtil import meta_port,meta_host,control_port,control_host,control_pass
+from TorCtl import StatsSupport
 from TorCtl.StatsSupport import StatsHandler
 from TorCtl import PathSupport, TorCtl
 from TorCtl.PathSupport import ExitPolicyRestriction,OrNodeRestriction
 from TorCtl.TorUtil import plog
 
+# For testing:
+from dist_check import run_check
+
 # Note: It is not recommended to set order_exits to True, because
 # of the lifetime differences between this __selmgr and the 
 # StatsGatherer when slicing the network into segments.
@@ -42,9 +46,22 @@
 # Original value of FetchUselessDescriptors
 FUDValue = None
 
+# XXX: This router is in both buildtimes and dist_check
+# Probably should be in its own file..
+class BTRouter(StatsSupport.StatsRouter):
+  def __init__(self, router):
+    StatsSupport.StatsRouter.__init__(self, router)
+ 
+  def reset(self):
+    StatsSupport.StatsRouter.reset(self)
+    self.rank_history = []
+    self.bw_history = []
+    self.chosen = [0,0,0]
+    self.uptime = 0
+ 
 class StatsGatherer(StatsHandler):
   def __init__(self,c, selmgr,basefile_name,nstats):
-    StatsHandler.__init__(self,c, selmgr)
+    StatsHandler.__init__(self,c, selmgr, BTRouter)
     self.nodesfile = open(basefile_name + '.nodes','w')
     self.failfile = open(basefile_name + '.failed','w')
     self.extendtimesfile = open(basefile_name + '.extendtimes','w')
@@ -94,6 +111,27 @@
         self.failfile.flush()
     StatsHandler.circ_status_event(self,circ_event)
 
+  def new_desc_event(self, d):
+    for idhex in d.idlist: 
+      if not idhex in self.routers:
+        continue
+      r = self.routers[idhex]
+      r.bw_history.append(r.bw)
+    for r in self.sorted_r:
+      r.rank_history.append(r.list_rank)
+    StatsHandler.new_desc_event(self, d)
+
+  def ns_event(self, n):
+    for ns in n.nslist:
+      if not ns.idhex in self.routers:
+        continue
+      r = self.routers[ns.idhex]
+      r.bw_history.append(r.bw)
+    for r in self.sorted_r:
+      r.rank_history.append(r.list_rank)
+    StatsHandler.ns_event(self, n)
+
+
 def cleanup():
   s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
   s.connect((control_host,control_port))
@@ -130,7 +168,6 @@
 def getargs():
   ncircuits = ""
   dirname = ""
-  filename = ""
   if len(sys.argv[1:]) < 3:
     usage()
     sys.exit(2)
@@ -252,6 +289,14 @@
   c._handler.schedule_low_prio(notlambda)
   cond.wait()
   cond.release()
+
+  # Run self-checks
+  checkfile = open(basefile_name+".check", "w")
+  def logger(msg):
+    checkfile.write(msg+"\n")
+
+  run_check(c._handler.sorted_r, basefile_name, logger)
+  checkfile.close()
   c.close()
   c._thread.join()
   print "Done in main."

Modified: torflow/trunk/CircuitAnalysis/BuildTimes/dist_check.py
===================================================================
--- torflow/trunk/CircuitAnalysis/BuildTimes/dist_check.py	2009-01-16 19:23:26 UTC (rev 18136)
+++ torflow/trunk/CircuitAnalysis/BuildTimes/dist_check.py	2009-01-17 00:15:57 UTC (rev 18137)
@@ -10,15 +10,29 @@
 
 #import profile
 
-import socket,sys,time,getopt,os,threading
+import socket,sys,time,getopt
 sys.path.append("../../")
 import TorCtl
 from TorCtl.TorUtil import meta_port,meta_host,control_port,control_host,control_pass
+from TorCtl import StatsSupport
 from TorCtl.StatsSupport import StatsHandler
 from TorCtl import PathSupport, TorCtl
 from TorCtl.PathSupport import ExitPolicyRestriction,OrNodeRestriction
 from TorCtl.TorUtil import plog
 
+# XXX: This router is in both buildtimes and dist_check
+# Probably should be in its own file..
+class BTRouter(StatsSupport.StatsRouter):
+  def __init__(self, router):
+    StatsSupport.StatsRouter.__init__(self, router)
+ 
+  def reset(self):
+    StatsSupport.StatsRouter.reset(self)
+    self.rank_history = []
+    self.bw_history = []
+    self.chosen = [0,0,0]
+    self.uptime = 0
+
 def usage():
   print "Option fail."
 
@@ -40,37 +54,36 @@
       assert False, "Bad option"
   return pathfile
 
+def check_ranks(r):
+  if not r.rank_history:
+    return (r.list_rank, r.list_rank, r.list_rank)
+  minr = 100
+  maxr = 0
+  avgr = 0.0
+  for rank in r.rank_history:
+    avgr += rank
+    if rank < minr: minr = rank
+    if rank > maxr: maxr = rank
+  avgr /= len(r.rank_history)
+  return (avgr,minr,maxr)
+
 def open_controller():
   """ starts stat gathering thread """
-
   s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
   s.connect((control_host,control_port))
   c = PathSupport.Connection(s)
   c.authenticate(control_pass)  # also launches thread...
-
-
   return c
 
+def run_check(routers, pathfile, log):
+  for i in xrange(len(routers)):
+    if routers[i].list_rank != i:
+      log("WARN: List unsorted at position "+str(i)+", "+routers[i].idhex)
 
-class ChosenRouter(TorCtl.Router):
-  def __init__(self, router):
-    self.__dict__ = router.__dict__
-    self.chosen = [0,0,0]
-    self.uptime = 0
-
-
-def main():
-  pathfile = getargs()
-  c=open_controller()  
-
-  routers = map(ChosenRouter, c.read_routers(c.get_network_status())) 
   router_map = {}
   for r in routers:
     router_map[r.idhex] = r
 
-  routers.sort(lambda x, y: cmp(y.bw, x.bw))
-  for i in xrange(len(routers)): routers[i].list_rank = i
-
   f = open(pathfile+".nodes", "r")
   ok_circs = f.readlines()
   f.close()
@@ -80,10 +93,15 @@
   f.close()
 
   uptimes = open(pathfile+".uptime", "r")
+  total_absent = 0
+  total_present = 0
   for line in uptimes:
     nodes = map(lambda n: n.strip(), line.split("\t"))
     if nodes[0] in router_map:
+      total_present += 1
       router_map[nodes[0]].uptime = float(nodes[1])/60.0
+    else:
+      total_absent += 1
 
   pct_mins = [100, 100, 100]
   pct_maxes = [0, 0, 0]
@@ -98,11 +116,11 @@
   
   for line in ok_circs+failed_circs:
     nodes = map(lambda n: n.strip(), line.split("\t"))
-    id,nodes = (nodes[0],nodes[1:])
+    cid,nodes = (nodes[0],nodes[1:])
     circuits+=1
     for i in xrange(0, len(nodes)):
       if nodes[i] not in router_map:
-        #print nodes[i] + " no longer present in map"
+        #log(nodes[i] + " no longer present in map")
         absent[nodes[i]] = 1
         continue
       present[nodes[i]] = 1
@@ -119,43 +137,56 @@
 
     if nodes[2] in router_map:
       if not exit_check.r_is_ok(router_map[nodes[2]]):
-        print "WARN: Exit policy fail for circ "+str(id)+" on "+nodes[2]
-        print "Exit policy:"
+        log("WARN: Exit policy fail for circ "+str(cid)+" on "+nodes[2])
+        log("Exit policy:")
         for e in router_map[nodes[2]].exitpolicy:
-          print " "+str(e)
-        print " 80: "+str(router_map[nodes[2]].will_exit_to("255.255.255.255",
-80))
-        print " 443: "+str(router_map[nodes[2]].will_exit_to("255.255.255.255", 443))
+          log(" "+str(e))
+        log(" 80: "+str(router_map[nodes[2]].will_exit_to("255.255.255.255", 80)))
+        log(" 443: "+str(router_map[nodes[2]].will_exit_to("255.255.255.255", 443)))
 
 
   # FIXME: Compare circuits/chosen to %bw. Multiply by pct_min+max
   # FIXME: Verify by guard+exit weighting?
   for i in xrange(0, 3):
     routers.sort(lambda x, y: cmp(y.chosen[i], x.chosen[i]))
-    print "\nHop "+str(i)+": "
+    log("\nHop "+str(i)+": ")
     unchosen = 0
     for r in routers:
       if r.chosen[i] == 0: unchosen+=1
-      else: print r.idhex+" "+str(round((100.0*r.list_rank)/len(routers),2))+"%, chosen: "+str(r.chosen[i])+", up: "+str(round(r.uptime,2))
+      else:
+        ranks = check_ranks(r) 
+        log(r.idhex+" "+"/".join(map(lambda f: str(round(f, 2)), ranks))+"%, chosen: "+str(r.chosen[i])+", up: "+str(round(r.uptime,2)))
+        #log(r.idhex+" "+str(round((100.0*r.list_rank)/len(routers),2))+"%, chosen: "+str(r.chosen[i])+", up: "+str(round(r.uptime,2)))
 
-    print "Nodes not chosen for this hop: "+str(unchosen)+"/"+str(len(routers))
+    log("Nodes not chosen for this hop: "+str(unchosen)+"/"+str(len(routers)))
 
     flgs = flags[i].keys()
     flgs.sort(lambda x, y: cmp(y,x))
     for f in flgs:
       if flags[i][f] == circuits:
-        print f+": "+str(flags[i][f])+" (all)"
+        log(f+": "+str(flags[i][f])+" (all)")
       else:
-        print f+": "+str(flags[i][f])
+        log(f+": "+str(flags[i][f]))
 
   # FIXME: Print out summaries for failure information for some routers
   
+  log("Routers used that are still present: "+str(len(present.keys())))
+  log("Routers used that are now absent: "+str(len(absent.keys())))
+  log("Routers considered that are still present: "+str(total_present))
+  log("Routers considered that are now absent: "+str(total_absent))
+  log("Min percentiles per hop: "+str(pct_mins))
+  log("Max percentiles per hop: "+str(pct_maxes))
 
+def logger(msg):
+  print msg
 
-  print "Routers used that are still present: "+str(len(present.keys()))
-  print "Routers used that are now absent: "+str(len(absent.keys()))
-  print "Min percentiles per hop: "+str(pct_mins)
-  print "Max percentiles per hop: "+str(pct_maxes)
+def main():
+  pathfile = getargs()
+  c=open_controller()  
+  routers = map(BTRouter, c.read_routers(c.get_network_status())) 
+  routers.sort(lambda x, y: cmp(y.bw, x.bw))
+  for i in xrange(len(routers)): routers[i].list_rank = i
+  run_check(routers, pathfile, logger)
 
 if __name__ == '__main__':
   main()

Modified: torflow/trunk/CircuitAnalysis/BuildTimes/full_run.sh
===================================================================
--- torflow/trunk/CircuitAnalysis/BuildTimes/full_run.sh	2009-01-16 19:23:26 UTC (rev 18136)
+++ torflow/trunk/CircuitAnalysis/BuildTimes/full_run.sh	2009-01-17 00:15:57 UTC (rev 18137)
@@ -3,33 +3,7 @@
 mkdir slices
 
 ./buildtimes.py -n 10000 -s 3 -e 80 -d ./slices >& ./slices/bt-slices.log
-
-# Check all slices
-for f in ./slices/*.nodes
-do
-  base = `basename ${f} .nodes`
-  ./dist_check.py -f ${base} >& ${base}.check
-  mv ${f} ${f}.checked
-done
-
 ./buildtimes.py -n 10000 -s 3 -g -e 50 -d ./slices >& ./slices/bt-guards.log
-
-# Check all slices
-for f in ./slices/*.nodes
-do
-  base = `basename ${f} .nodes`
-  ./dist_check.py -f $base >& ${base}.check
-  mv ${f} ${f}.checked
-done
-
 ./buildtimes.py -n 20000 -d slices/ -s 80 >& ./slices/bt-all.log
 
-# Check all slices
-for f in ./slices/*.nodes
-do
-  base = `basename ${f} .nodes`
-  ./dist_check.py -f ${base} >& ${base}.check
-  mv ${f} ${f}.checked
-done
-
 mv slices slices-`date +%Y-%m-%d-%H:%M`



More information about the tor-commits mailing list