Esempio n. 1
0
    def testFlowManagement(self):
        print 80 * "-"
        print "  testFlowManagement"
        print 80 * "-"
        client1 = LocalAliceLink(threading.Event(), None, self.lh_config)
        client1.start()
        client1.ready.wait()
        client1.send_message("ping")
        flow1 = self.random_flow(self.localhost, self.ip)
        flow2 = Switzerland.flow_mirror(flow1)
        #self.assertEqual(flow2, (ip,port2_s,localhost, port_s, prot_s))
        client1.send_message("active_flows", [[(0, "hash00", flow1)], []])
        # This trick should get us two useable Alice IPs
        client2 = AliceLink(threading.Event(), None, self.net_config)
        client2.start()
        client2.ready.wait()
        client2.send_message("ping")
        client2.send_message("active_flows", [[(0, "hash00", flow1)], []])

        mm1 = (flow1[0], flow1[2], "hash00")
        mm2 = (flow2[0], flow2[2], "hash00")
        time.sleep(3)
        mm = self.server.mm
        mm.global_flow_lock.acquire()
        try:
            print "Global flow table", mm.flow_matchmaker
            # XXX fix these
            #self.assert_(mm.global_flow_table.has_key(flow1))
            print "Hunting for", mm1, "\nand", mm2
            self.assert_(mm.flow_matchmaker.has_key(mm1))
            #self.assert_(not mm.global_flow_table.has_key(flow2))
            self.assert_(not mm.flow_matchmaker.has_key(mm2))

        finally:
            mm.global_flow_lock.release()

        # Now tear things down
        client2.send_message("active_flows", [[], [0]])
        client1.send_message("active_flows", [[], [0]])

        time.sleep(2)
        mm.global_flow_lock.acquire()
        try:
            print "Global flow table", mm.flow_matchmaker
            #self.assertEqual(mm.global_flow_table, {})
            self.assertEqual(mm.flow_matchmaker, {})
        finally:
            mm.global_flow_lock.release()

        nmf = lambda m: m[0] == "new-members"
        new_member_counts = [
            len(filter(nmf, c.in_log)) for c in [client1, client2]
        ]
        print "nmc:", new_member_counts
        self.assert_(1 in new_member_counts)
        self.assert_(2 in new_member_counts)
Esempio n. 2
0
  def testFlowManagement(self):
    print 80 * "-"
    print "  testFlowManagement"
    print 80 * "-"
    client1 = LocalAliceLink(threading.Event(), None, self.lh_config)
    client1.start()
    client1.ready.wait()
    client1.send_message("ping")
    flow1 = self.random_flow(self.localhost, self.ip)
    flow2 = Switzerland.flow_mirror(flow1)
    #self.assertEqual(flow2, (ip,port2_s,localhost, port_s, prot_s))
    client1.send_message("active_flows", [[(0, "hash00", flow1)], []])
    # This trick should get us two useable Alice IPs
    client2 = AliceLink(threading.Event(), None, self.net_config)
    client2.start()
    client2.ready.wait()
    client2.send_message("ping")
    client2.send_message("active_flows", [[(0, "hash00", flow1)], []])
    
    mm1 = (flow1[0], flow1[2], "hash00")
    mm2 = (flow2[0], flow2[2], "hash00")
    time.sleep(3)
    mm = self.server.mm
    mm.global_flow_lock.acquire()
    try:
      print "Global flow table", mm.flow_matchmaker
      # XXX fix these
      #self.assert_(mm.global_flow_table.has_key(flow1))
      print "Hunting for", mm1, "\nand",  mm2
      self.assert_(mm.flow_matchmaker.has_key(mm1))
      #self.assert_(not mm.global_flow_table.has_key(flow2))
      self.assert_(not mm.flow_matchmaker.has_key(mm2))

    finally:
      mm.global_flow_lock.release()

    # Now tear things down
    client2.send_message("active_flows", [[], [0]])
    client1.send_message("active_flows", [[], [0]])

    time.sleep(2)
    mm.global_flow_lock.acquire()
    try:
      print "Global flow table", mm.flow_matchmaker
      #self.assertEqual(mm.global_flow_table, {})
      self.assertEqual(mm.flow_matchmaker, {})
    finally:
      mm.global_flow_lock.release()

    nmf = lambda m : m[0] == "new-members"
    new_member_counts = [len(filter(nmf, c.in_log)) for c in [client1, client2]]
    print "nmc:", new_member_counts
    self.assert_(1 in new_member_counts)
    self.assert_(2 in new_member_counts)
Esempio n. 3
0
 def testFirewallDetection(self):
     print 80 * "-"
     print "  testFirewallDetection"
     print 80 * "-"
     client1 = LocalAliceLink(threading.Event(), None, self.lh_config)
     client1.start()
     client1.ready.wait()
     client1.send_message("ping")
     server_thread1 = self.server.threads[-1]  # XXX not safe!!!
     client2 = LocalAliceLink(threading.Event(), None, self.lh_config)
     client2.start()
     client1.send_message("ping")
     client2.ready.wait()
     time.sleep(1)
     client1.send_message("ping")
     time.sleep(1)
     client1.send_message("ping")
     server_thread2 = self.server.threads[-1]
     self.assertNotEqual(server_thread1, server_thread2)
     self.assert_(['public-ip', 0, '127.0.0.1'] in server_thread1.out_log)
     self.assert_(['public-ip', 0, '127.0.0.1'] in client1.in_log)
     self.assert_(['public-ip', 0, '127.0.0.1'] in server_thread2.out_log)
     self.assert_(['public-ip', 0, '127.0.0.1'] in client2.in_log)
     self.assert_([
         'error-bye',
         'We already have a connection from your IP.  Multiple connections from a single IP are currently disallowed!'
     ] in server_thread2.out_log)
     self.assert_([
         'error-bye',
         'We already have a connection from your IP.  Multiple connections from a single IP are currently disallowed!'
     ] in client2.in_log)
Esempio n. 4
0
 def testFirewallDetection(self):
   print 80 * "-"
   print "  testFirewallDetection"
   print 80 * "-"
   client1 = LocalAliceLink(threading.Event(), None, self.lh_config)
   client1.start()
   client1.ready.wait()
   client1.send_message("ping")
   server_thread1 = self.server.threads[-1]  # XXX not safe!!!
   client2 = LocalAliceLink(threading.Event(), None, self.lh_config)
   client2.start()
   client1.send_message("ping")
   client2.ready.wait()
   time.sleep(1)
   client1.send_message("ping")
   time.sleep(1)
   client1.send_message("ping")
   server_thread2 = self.server.threads[-1]
   self.assertNotEqual(server_thread1,server_thread2)
   self.assert_(['public-ip', 0, '127.0.0.1'] in server_thread1.out_log)
   self.assert_(['public-ip', 0, '127.0.0.1' ] in client1.in_log)
   self.assert_(['public-ip', 0, '127.0.0.1'] in server_thread2.out_log)
   self.assert_(['public-ip', 0, '127.0.0.1'] in client2.in_log)
   self.assert_(['error-bye', 'We already have a connection from your IP.  Multiple connections from a single IP are currently disallowed!'] in server_thread2.out_log)
   self.assert_(['error-bye', 'We already have a connection from your IP.  Multiple connections from a single IP are currently disallowed!'] in client2.in_log)