def __init__(self, getopt=False, **keywords):

        # all of the variables above become attributes of AliceConfig;
        # we pick the value passed to this function (if there was one)
        # or the default value otherwise

        self.private_ip = None

        for variable in alice_options.keys():
            if variable in keywords:
                self.__dict__[variable] = keywords[variable]
            else:
                self.__dict__[variable] = alice_options[variable][0]

        if getopt:
            self.get_options()

        # Defaults remaining if getopt hasn't set things:
        if self.interface == None and getopt:
            self.interface = local_ip.get_interface()
            log.info("interface is now %s", self.interface)

        if self.force_private_ip and self.private_ip == None: # could have been set by getopt?
            self.private_ip = force_private_ip
        if self.private_ip == None:
            self.private_ip = local_ip.get_local_ip(self.interface)
Exemple #2
0
    def __init__(self, getopt=False, **keywords):

        # all of the variables above become attributes of AliceConfig;
        # we pick the value passed to this function (if there was one)
        # or the default value otherwise

        self.private_ip = None

        for variable in alice_options.keys():
            if variable in keywords:
                self.__dict__[variable] = keywords[variable]
            else:
                self.__dict__[variable] = alice_options[variable][0]

        if getopt:
            self.get_options()

        # Defaults remaining if getopt hasn't set things:
        if self.interface == None and getopt:
            self.interface = local_ip.get_interface()
            log.info("interface is now %s", self.interface)

        if self.force_private_ip and self.private_ip == None:  # could have been set by getopt?
            self.private_ip = force_private_ip
        if self.private_ip == None:
            self.private_ip = local_ip.get_local_ip(self.interface)
Exemple #3
0
    def pcap_playback(self,
                      filename1,
                      ip_in_pcap1,
                      filename2,
                      ip_in_pcap2,
                      skew_pcap2,
                      playback_offset=0,
                      keep_archives=False,
                      force_public_ip1=False,
                      force_public_ip2=False):
        ip = local_ip.get_local_ip()
        localhost = "127.0.0.1"
        if ip == localhost:
            print "Can't run system tests without a non-localhost interface!!"
            return 0

        # We turn the packet filter off, because it would require extra waiting
        # mechanisms for the new-members messages to arrive in time for the
        # filtering mechanism.  NTP is off because we don't need it.  Cleaning has
        # to be off because the timestamps in the pcaps are antique.
        if not force_public_ip1:
            public_ip1 = ip_in_pcap1
        else:
            public_ip1 = force_public_ip1

        client1= Alice.Alice(linkobj=LocalAliceLink,\
            config=AliceConfig(host="localhost", port=self.port, use_ntp=False,\
                do_cleaning=False, seriousness=seriousness_threshold,\
                filter_packets=False, keep_archives=keep_archives,\
                force_public_ip=public_ip1, pcap_playback=filename1,\
                force_private_ip=ip_in_pcap1, logfile=None, pcap_logdir=None))

        if not force_public_ip2:
            public_ip2 = ip_in_pcap2
        else:
            public_ip2 = force_public_ip2

        client2= Alice.Alice(\
            config=AliceConfig(host=ip, port=self.port, use_ntp=False,\
                       do_cleaning=False, seriousness=seriousness_threshold, skew=skew_pcap2,\
                       filter_packets=False, keep_archives=keep_archives,\
                       force_public_ip=public_ip2, pcap_playback=filename2,\
                       force_private_ip=ip_in_pcap2, logfile=None, \
                       pcap_logdir=None))
        time.sleep(2)
        # if we have a negative playback_offset, switch the order of events
        if playback_offset < 0.0:
            playback_offset *= -1
            client1, client2 = client2, client1
        client2.listener.start()
        client2.start()
        time.sleep(playback_offset)
        client1.listener.start()
        client1.start()
        client1.listener.done.wait()
        client2.listener.done.wait()
 def setUp(self):
   self.ip = local_ip.get_local_ip()
   self.localhost = "127.0.0.1"
   if self.ip == self.localhost:
     print "Can't run testFlowManagement without a non-localhost interface"
     return 0  
   self.port = random.randint(17000,18000)
   self.server = Switzerland.SwitzerlandMasterServer(SwitzerlandConfig(port=self.port, keep_threads=True, logging=False, allow_fake_ips=True))
   util.ThreadLauncher(self.server.accept_connections).start()
   self.lh_config = AliceConfig(host="localhost", port=self.port)
   self.net_config = AliceConfig(host=self.ip, port=self.port)
Exemple #5
0
 def setUp(self):
     self.ip = local_ip.get_local_ip()
     self.localhost = "127.0.0.1"
     if self.ip == self.localhost:
         print "Can't run testFlowManagement without a non-localhost interface"
         return 0
     self.port = random.randint(17000, 18000)
     self.server = Switzerland.SwitzerlandMasterServer(
         SwitzerlandConfig(port=self.port,
                           keep_threads=True,
                           logging=False,
                           allow_fake_ips=True))
     util.ThreadLauncher(self.server.accept_connections).start()
     self.lh_config = AliceConfig(host="localhost", port=self.port)
     self.net_config = AliceConfig(host=self.ip, port=self.port)
  def pcap_playback(self, filename1, ip_in_pcap1, filename2, ip_in_pcap2, skew_pcap2, playback_offset=0, keep_archives=False, force_public_ip1=False, force_public_ip2=False):
    ip = local_ip.get_local_ip()
    localhost = "127.0.0.1"
    if ip == localhost:
      print "Can't run system tests without a non-localhost interface!!"
      return 0  

    # We turn the packet filter off, because it would require extra waiting
    # mechanisms for the new-members messages to arrive in time for the
    # filtering mechanism.  NTP is off because we don't need it.  Cleaning has
    # to be off because the timestamps in the pcaps are antique.
    if not force_public_ip1:
      public_ip1 = ip_in_pcap1
    else:
      public_ip1 = force_public_ip1

    client1= Alice.Alice(linkobj=LocalAliceLink,\
        config=AliceConfig(host="localhost", port=self.port, use_ntp=False,\
            do_cleaning=False, seriousness=seriousness_threshold,\
            filter_packets=False, keep_archives=keep_archives,\
            force_public_ip=public_ip1, pcap_playback=filename1,\
            force_private_ip=ip_in_pcap1, logfile=None, pcap_logdir=None))

    if not force_public_ip2:
      public_ip2 = ip_in_pcap2
    else:
      public_ip2 = force_public_ip2

    client2= Alice.Alice(\
        config=AliceConfig(host=ip, port=self.port, use_ntp=False,\
                   do_cleaning=False, seriousness=seriousness_threshold, skew=skew_pcap2,\
                   filter_packets=False, keep_archives=keep_archives,\
                   force_public_ip=public_ip2, pcap_playback=filename2,\
                   force_private_ip=ip_in_pcap2, logfile=None, \
                   pcap_logdir=None))
    time.sleep(2)
    # if we have a negative playback_offset, switch the order of events
    if playback_offset < 0.0:
      playback_offset *= -1
      client1, client2 = client2, client1
    client2.listener.start()
    client2.start()
    time.sleep(playback_offset)
    client1.listener.start()
    client1.start()
    client1.listener.done.wait()
    client2.listener.done.wait()
Exemple #7
0
    def __init__(self, log, seriousness=0, accounting=True, private_ip=False):
        """Alice will connect to a server here, Switzerland will get a socket from
    a listening SwitzerlandMasterServer"""

        self.seriousness_threshold = seriousness
        self.accounting = accounting
        self.log = log
        if private_ip:
            log.debug("Setting private IP to %s" % private_ip)
            self.private_ip = private_ip
        else:
            self.private_ip = local_ip.get_local_ip()

        self.ready = threading.Event(
        )  # ready for the sender thread, currently set
        # after we know if we're firewalled or not

        self.sequence_no = 0  # sequence number for sent messages

        # this is a lock for data that's shared between read and write threads
        self.status_lock = threading.RLock()
        self.bailing_out = False
        self.bailout_waiting = None  # if we get a bailout during handshake
        self.closed = False
        self.messages_in = 0
        self.messages_out = 0
        self.in_log = []
        self.out_log = []
        self.faking = False

        self.hash_length = hash_length

        # For handling acknowledgement messages and replies (which basically
        # count as acks for most purposes)
        self.ack_lock = threading.RLock()
        self.timeout_period = 25  # the time we'll wait for an ack/reply
        self.ack_timeouts = [
        ]  # ordered list of (deadline, sequence_no, msg_type)
        self.expected_acknowledgments = {}  # callbacks for failed acks
        self.last_deadline = 0  # the last ack deadline around
        self.last_sent = time.time()

        # this dict passes state from an outbound message that expects a reply
        # to the handler for the inbound reply:
        self.reply_data_table = {}

        threading.Thread.__init__(self)
  def __init__(self, log, seriousness=0, accounting=True, private_ip=False):
    """Alice will connect to a server here, Switzerland will get a socket from
    a listening SwitzerlandMasterServer"""

    self.seriousness_threshold=seriousness
    self.accounting = accounting
    self.log = log
    if private_ip:
      log.debug("Setting private IP to %s" % private_ip)
      self.private_ip = private_ip
    else:
      self.private_ip = local_ip.get_local_ip()

    self.ready=threading.Event() # ready for the sender thread, currently set
                                 # after we know if we're firewalled or not 

    self.sequence_no = 0  # sequence number for sent messages

    # this is a lock for data that's shared between read and write threads
    self.status_lock = threading.RLock()
    self.bailing_out = False
    self.bailout_waiting = None     # if we get a bailout during handshake
    self.closed = False
    self.messages_in = 0
    self.messages_out = 0
    self.in_log = []
    self.out_log = []
    self.faking = False

    self.hash_length = hash_length
    
    # For handling acknowledgement messages and replies (which basically
    # count as acks for most purposes)
    self.ack_lock= threading.RLock()
    self.timeout_period = 25   # the time we'll wait for an ack/reply
    self.ack_timeouts = []     # ordered list of (deadline, sequence_no, msg_type)
    self.expected_acknowledgments = {}   # callbacks for failed acks
    self.last_deadline = 0               # the last ack deadline around
    self.last_sent = time.time()

    # this dict passes state from an outbound message that expects a reply
    # to the handler for the inbound reply:
    self.reply_data_table = {}

    threading.Thread.__init__(self)
Exemple #9
0
    def testProtocolBasics(self):
        print 80 * "-"
        print "  testProtocolBasics"
        print 80 * "-"
        client = AliceLink(threading.Event(), None, self.lh_config)
        client.start()
        client.ready.wait()

        server_thread = self.server.threads[-1]  # XXX not safe!!!
        client.send_message("ping")
        client.send_message("test", [1, 0, [1, 2, 4]])
        client.send_message("test", [2, 0, [1, 2, 5]])
        client.send_message("test", [3, 0, [1, 2, 6]])
        client.send_message("ping")
        client.send_message("ping")
        client.send_message("ping")
        time.sleep(1)
        client.send_message("signoff")
        time.sleep(1)

        #print "Server in:"
        #print "\n".join(map(repr, server_thread.in_log))
        server_thread.status_lock.acquire()
        # adding one for the firewall mss now in Protocol.setup(), and one more
        # for the default new-members message in Switzerland.new_link() and its
        # ack

        self.assertEqual(server_thread.messages_in, 8 + 2)
        self.assertEqual(server_thread.messages_out,
                         4 + 2)  # just for the pings
        self.assert_(server_thread.closed)
        self.assertEqual(client.messages_out, 8 + 2)
        self.assertEqual(client.messages_in, 4 + 2)
        self.assert_(["test", 3, 0, [1, 2, 6]] in client.out_log)
        self.assert_(["test", 3, 0, [1, 2, 6]] in server_thread.in_log)
        if local_ip.get_local_ip() != "127.0.0.1":
            #self.assert_(['you-are-firewalled', 0, '127.0.0.1'] in server_thread.out_log)
            #self.assert_(['you-are-firewalled', 0, '127.0.0.1'] in client.in_log)
            self.assert_(
                ['public-ip', 0, '127.0.0.1'] in server_thread.out_log)
            self.assert_(['public-ip', 0, '127.0.0.1'] in client.in_log)
        server_thread.status_lock.release()
  def testProtocolBasics(self):
    print 80 * "-"
    print "  testProtocolBasics"
    print 80 * "-"
    client = AliceLink(threading.Event(), None, self.lh_config)
    client.start()
    client.ready.wait()

    server_thread = self.server.threads[-1]  # XXX not safe!!!
    client.send_message("ping")
    client.send_message("test", [1,0,[1,2,4]])
    client.send_message("test", [2,0,[1,2,5]])
    client.send_message("test", [3,0,[1,2,6]])
    client.send_message("ping")
    client.send_message("ping")
    client.send_message("ping")
    time.sleep(1)
    client.send_message("signoff")
    time.sleep(1)

    #print "Server in:"
    #print "\n".join(map(repr, server_thread.in_log))
    server_thread.status_lock.acquire()
    # adding one for the firewall mss now in Protocol.setup(), and one more
    # for the default new-members message in Switzerland.new_link() and its
    # ack
    
    self.assertEqual(server_thread.messages_in, 8+2)
    self.assertEqual(server_thread.messages_out, 4+2)  # just for the pings
    self.assert_(server_thread.closed)
    self.assertEqual(client.messages_out,8+2)
    self.assertEqual(client.messages_in,4+2)
    self.assert_(["test", 3, 0, [1,2,6]] in client.out_log)
    self.assert_(["test", 3, 0, [1,2,6]] in server_thread.in_log)
    if local_ip.get_local_ip() != "127.0.0.1":
      #self.assert_(['you-are-firewalled', 0, '127.0.0.1'] in server_thread.out_log)
      #self.assert_(['you-are-firewalled', 0, '127.0.0.1'] in client.in_log)
      self.assert_(['public-ip', 0, '127.0.0.1'] in server_thread.out_log)
      self.assert_(['public-ip', 0, '127.0.0.1'] in client.in_log)
    server_thread.status_lock.release()