Пример #1
0
def run_analysis(options):

    # Get our FTP IP
    try:
        ftp_ip = NET.get_ip_address(options.ftp_interface)
    except:
        logger.error("Could not find ip for the given interface. (%s)"%
                     options.ftp_interface)
            
    # Add a sensors to physical machines if needed
    if options.machine_type == G.MACHINE_TYPES.PHYSICAL:
        has_memory = has_disk = False
        
        if options.machine_config is None:
            logger.error("No machine config file given.")
            return
        
        # This isn't the class we use in practice, but fake it here for simplicity
        machines = CONF.import_from_config(options.machine_config, "machine")
    
        if options.machine not in machines:
            logger.error("%s is not a valid machine from the config file."%options.machine)
            logger.error("Valid targets are: %s"%machines.keys())
            return

        # Get our machine object
        machine = machines[options.machine]
            
        # Ensure that a sensor config is defined
        if options.sensor_config is None:
            logger.error("A sensor config file must be defined for physical analysis")
            return
        # Get the list of sensors
        sensors = CONF.import_from_config(options.sensor_config, "sensor")
        
        # Add sensors to our machine
        print "* Trying to find physical sensors for %s..."%options.machine
        added_sensors = machine.add_sensors(sensors)
        
    else:
        machine = VirtualMachine(options.machine,
                                 vm_type=options.machine_type,
                                 volatility_profile=options.profile)
        
        
    
    ftp_info = {'user':G.FTP_USER,
                 'pass':G.FTP_PASSWORD,
                 'ip':ftp_ip,
                 'port':G.FTP_PORT,
                 'dir':None
                 }
    
    print "* Machine is: %s"%machine.power_status()
    
    ra = RemoteAnalysis(options.profile, machine.control, ftp_info)
        

        
    parameters = {
#                   1:'INTmark (write)',
#                   2:'INTmark (Read)',
                  3:'INTmem',
#                   4:'FLOATmark (write)',
#                   5:'FLOATmark (Read)',
                  6:'FLOATmem',
#                   7:'MMXmark (write)',
#                   8:'MMXmark (Read)',
                  9:'MMXmem',
#                   10:'SSEmark (write)',
#                   11:'SSEmark (Read)',
                  12:'SSEmem'
                  }
    # Create a run for all of our parameters (Only *mem will run in batches)
    for b_param in parameters:
        # Should we be reading memory?
        if options.enable_sensor:
            memory_thread = MemoryThread(machine)
            memory_thread.daemon = True
            memory_thread.start()
        
        param_name = parameters[b_param]
        
        print "* Running %s test, %d times..."%(param_name, 
                                                options.run_count)
        
        response = ra.run_analysis("ramspeed-win32.exe -b %d -l %d"%(
                                                        b_param,
                                                        options.run_count),
                                    "artifacts-memory",
                                    init_commands=[],
                                    bind_ip=ftp_ip)
        
        # Now store our results
        results_file = os.path.join(options.output_dir,
                                    "trial_b%d_l%d.txt"%(b_param,
                                                         options.run_count))
        sensor_file = os.path.join(options.output_dir,
                                    "trial_b%d_l%d_sensor.txt"%(b_param,
                                                         options.run_count))
        print "* Storing results (%d bytes) in %s."%(len(response),results_file)
        f = open(results_file, "w+")
        f.write(response)
        f.close()
    
        if options.enable_sensor:
            (time_elapsed, bytes_read) = memory_thread.join()
            f = open(sensor_file, "w+")
            f.write(str(time_elapsed)+"\t"+str(bytes_read))
            f.close()
Пример #2
0
    def __init__(self, options, positionals):
        """
            Initialize our controller.  This includes initializing all of the 
            configurations and opening all of the appropriate logfiles.
        """

        # Set our port to bind to
        self._sock = None
        self.PORT_NUM = options.port

        # AMQP Host (Only used to hand off to analysis
        self.services_host = options.services_host

        # What config file are we loading?
        sensor_config_file = options.sensor_config_file

        # What config file are we loading?
        machine_config_file = options.machine_config_file

        # Disk images config file
        images_config_file = options.images_config_file

        # Import our available sensors
        logger.debug("Importing sensor config file (%s)" % sensor_config_file)
        self.sensor_list = Configs.import_from_config(sensor_config_file,
                                                      "sensor")

        # Import our available machines
        logger.debug("Importing machine config file (%s)" %
                     machine_config_file)
        self.machine_list = Configs.import_from_config(machine_config_file,
                                                       "machine")

        # Import our image mappings
        logger.debug("Importing images config file (%s)" % images_config_file)
        self.images_map = Configs.import_from_config(images_config_file,
                                                     "images")

        # Provision the number of requested VMs
        print "* Initializing %d virtual machines..." % options.vm_count
        for x in range(0, options.vm_count):
            tmp_name = "lophi-%d" % x
            self.machine_list[tmp_name] = VirtualMachine(tmp_name,
                                                         force_new=True)

        # Build our dictionary of queues
        # This queues are handed to analysis for scheduling
        self.MACHINE_QUEUES = {}

        self.ANALYSIS_SCHEDULER = {}

        print "* Assigning sensors to machines, and configure machines"
        for m in self.machine_list:

            # Setup their image maps
            self.machine_list[m].add_image_map( \
                 self.images_map[self.machine_list[m].type])

            # Add sensors and PXE server to physical machines
            if self.machine_list[m].type == G.MACHINE_TYPES.PHYSICAL:
                # Add sensors
                self.machine_list[m].add_sensors(self.sensor_list)
                # Add pxe_server
                from lophinet.pxeserver import PXEServer
                pxe_server = PXEServer(options.pxe_server)
                self.machine_list[m].add_pxe_server(pxe_server)

        manager = multiprocessing.Manager()
        for m in self.machine_list:
            # Get our indices
            t = self.machine_list[m].type
            # New queue?
            if t not in self.MACHINE_QUEUES:
                machine_queue = manager.Queue()
                self.MACHINE_QUEUES[t] = machine_queue
                self.ANALYSIS_SCHEDULER[t] = LophiScheduler(
                    self.machine_list, machine_queue)
                self.ANALYSIS_SCHEDULER[t].start()
            # Add to queue
            self.MACHINE_QUEUES[t].put(m)

        # Ensure that we can share this list with our analysis threads
#         self.machine_list = multiprocessing.Manager().dict(self.machine_list)

# Setup our FTP info
        self.ftp_ip_physical = self.ftp_ip_virtual = None
        try:
            self.ftp_ip_physical = NET.get_ip_address(options.ftp_physical)
        except:
            logger.error("Could not find ip for physical FTP interface. (%s)" %
                         options.ftp_physical)
        try:
            self.ftp_ip_virtual = NET.get_ip_address(options.ftp_virtual)
        except:
            logger.error("Could not find ip for virtual FTP interface. (%s)" %
                         options.ftp_virtual)

        # Server stuff
        self.RUNNING = True

        # Init our multiprocess
        multiprocessing.Process.__init__(self)
        """ 
Пример #3
0
    def __init__(self, options, positionals):
        """
            Initialize our controller.  This includes initializing all of the 
            configurations and opening all of the appropriate logfiles.
        """

        # Set our port to bind to
        self._sock = None
        self.PORT_NUM = options.port

        # AMQP Host (Only used to hand off to analysis
        self.services_host = options.services_host

        # What config file are we loading?
        sensor_config_file = options.sensor_config_file

        # What config file are we loading?
        machine_config_file = options.machine_config_file
        
        # Disk images config file
        images_config_file = options.images_config_file

        # Import our available sensors
        logger.debug("Importing sensor config file (%s)"%sensor_config_file)
        self.sensor_list = Configs.import_from_config(sensor_config_file, "sensor")
        
        # Import our available machines
        logger.debug("Importing machine config file (%s)"%machine_config_file)
        self.machine_list = Configs.import_from_config(machine_config_file, "machine")

        # Import our image mappings
        logger.debug("Importing images config file (%s)"%images_config_file)
        self.images_map = Configs.import_from_config(images_config_file, "images")


        # Provision the number of requested VMs
        print "* Initializing %d virtual machines..."%options.vm_count
        for x in range(0,options.vm_count):
            tmp_name = "lophi-%d"%x
            self.machine_list[tmp_name] = VirtualMachine(tmp_name,force_new=True)


        # Build our dictionary of queues
        # This queues are handed to analysis for scheduling
        self.MACHINE_QUEUES = {}
        
        self.ANALYSIS_SCHEDULER = {}

        print "* Assigning sensors to machines, and configure machines"
        for m in self.machine_list:
            
            # Setup their image maps
            self.machine_list[m].add_image_map( \
                 self.images_map[self.machine_list[m].type])
            
            
            # Add sensors and PXE server to physical machines    
            if self.machine_list[m].type == G.MACHINE_TYPES.PHYSICAL:
                # Add sensors
                self.machine_list[m].add_sensors(self.sensor_list)
                # Add pxe_server
                from lophinet.pxeserver import PXEServer
                pxe_server = PXEServer(options.pxe_server)
                self.machine_list[m].add_pxe_server(pxe_server)
                
        manager = multiprocessing.Manager()
        for m in self.machine_list:
            # Get our indices
            t = self.machine_list[m].type
            # New queue?
            if t not in self.MACHINE_QUEUES:
                machine_queue = manager.Queue()
                self.MACHINE_QUEUES[t] = machine_queue 
                self.ANALYSIS_SCHEDULER[t] = LophiScheduler(self.machine_list,
                                                            machine_queue)
                self.ANALYSIS_SCHEDULER[t].start()
            # Add to queue
            self.MACHINE_QUEUES[t].put(m)

        

        
        # Ensure that we can share this list with our analysis threads        
#         self.machine_list = multiprocessing.Manager().dict(self.machine_list)
            
        # Setup our FTP info
        self.ftp_ip_physical = self.ftp_ip_virtual = None
        try:
            self.ftp_ip_physical = NET.get_ip_address(options.ftp_physical)
        except:
            logger.error("Could not find ip for physical FTP interface. (%s)"%
                         options.ftp_physical)
        try:
            self.ftp_ip_virtual = NET.get_ip_address(options.ftp_virtual)
        except:
            logger.error("Could not find ip for virtual FTP interface. (%s)"%
                         options.ftp_virtual)
            
        # Server stuff
        self.RUNNING = True
        
        # Init our multiprocess
        multiprocessing.Process.__init__(self)
        
        """ 
Пример #4
0
def run_analysis(options):

    # Get our FTP IP
    try:
        ftp_ip = NET.get_ip_address(options.ftp_interface)
    except:
        logger.error("Could not find ip for the given interface. (%s)" %
                     options.ftp_interface)

    # Add a sensors to physical machines if needed
    if options.machine_type == G.MACHINE_TYPES.PHYSICAL:
        has_memory = has_disk = False

        if options.machine_config is None:
            logger.error("No machine config file given.")
            return

        # This isn't the class we use in practice, but fake it here for simplicity
        machines = CONF.import_from_config(options.machine_config, "machine")

        if options.machine not in machines:
            logger.error("%s is not a valid machine from the config file." %
                         options.machine)
            logger.error("Valid targets are: %s" % machines.keys())
            return

        # Get our machine object
        machine = machines[options.machine]

        # Ensure that a sensor config is defined
        if options.sensor_config is None:
            logger.error(
                "A sensor config file must be defined for physical analysis")
            return
        # Get the list of sensors
        sensors = CONF.import_from_config(options.sensor_config, "sensor")

        # Add sensors to our machine
        print "Trying to find physical sensors for %s..." % options.machine
        added_sensors = machine.add_sensors(sensors)

        if options.enable_sensor:
            machine.disk.sata_enable_all()

    else:
        machine = VirtualMachine(options.machine,
                                 vm_type=options.machine_type,
                                 volatility_profile=options.profile)

    ftp_info = {
        'user': G.FTP_USER,
        'pass': G.FTP_PASSWORD,
        'ip': ftp_ip,
        'port': G.FTP_PORT,
        'dir': None
    }

    print machine.power_status()

    ra = RemoteAnalysis(options.profile, machine.control, ftp_info)

    for trial in range(44, options.run_count):

        print "Running trial #%d..." % trial

        # Should we fire up our disk sensor?
        #         if options.enable_sensor:
        #             log_dcap_filename = os.path.join(options.output_dir,"trial_%d.dcap"%trial)
        #             log_dcap_queue = multiprocessing.Queue()
        #             log_dcap_writer = CaptureWriter(log_dcap_filename,
        #                                             log_dcap_queue)
        #             log_dcap_writer.start()
        #
        #             dcap_engine = DiskCaptureEngine(machine, log_dcap_queue)
        #             dcap_engine.start()

        iozone_cmd = "iozone.exe -a -g 2G -i 0 -i 1"
        response = ra.run_analysis(
            iozone_cmd,
            None,
            init_commands=["cd C:\Program Files\Benchmarks\Iozone3_414"],
            bind_ip=ftp_ip)

        f = open(os.path.join(options.output_dir, "trial_%d.txt" % trial),
                 "w+")
        f.write(response)
        f.close()

        #         if options.enable_sensor:
        #             dcap_engine.stop()
        #             log_dcap_writer.stop()

        print response
Пример #5
0
def run_analysis(options):

    # Get our FTP IP
    try:
        ftp_ip = NET.get_ip_address(options.ftp_interface)
    except:
        logger.error("Could not find ip for the given interface. (%s)" %
                     options.ftp_interface)

    # Add a sensors to physical machines if needed
    if options.machine_type == G.MACHINE_TYPES.PHYSICAL:
        has_memory = has_disk = False

        if options.machine_config is None:
            logger.error("No machine config file given.")
            return

        # This isn't the class we use in practice, but fake it here for simplicity
        machines = CONF.import_from_config(options.machine_config, "machine")

        if options.machine not in machines:
            logger.error("%s is not a valid machine from the config file." %
                         options.machine)
            logger.error("Valid targets are: %s" % machines.keys())
            return

        # Get our machine object
        machine = machines[options.machine]

        # Ensure that a sensor config is defined
        if options.sensor_config is None:
            logger.error(
                "A sensor config file must be defined for physical analysis")
            return
        # Get the list of sensors
        sensors = CONF.import_from_config(options.sensor_config, "sensor")

        # Add sensors to our machine
        print "* Trying to find physical sensors for %s..." % options.machine
        added_sensors = machine.add_sensors(sensors)

    else:
        machine = VirtualMachine(options.machine,
                                 vm_type=options.machine_type,
                                 volatility_profile=options.profile)

    ftp_info = {
        'user': G.FTP_USER,
        'pass': G.FTP_PASSWORD,
        'ip': ftp_ip,
        'port': G.FTP_PORT,
        'dir': None
    }

    print "* Machine is: %s" % machine.power_status()

    ra = RemoteAnalysis(options.profile, machine.control, ftp_info)

    parameters = {
        #                   1:'INTmark (write)',
        #                   2:'INTmark (Read)',
        3: 'INTmem',
        #                   4:'FLOATmark (write)',
        #                   5:'FLOATmark (Read)',
        6: 'FLOATmem',
        #                   7:'MMXmark (write)',
        #                   8:'MMXmark (Read)',
        9: 'MMXmem',
        #                   10:'SSEmark (write)',
        #                   11:'SSEmark (Read)',
        12: 'SSEmem'
    }
    # Create a run for all of our parameters (Only *mem will run in batches)
    for b_param in parameters:
        # Should we be reading memory?
        if options.enable_sensor:
            memory_thread = MemoryThread(machine)
            memory_thread.daemon = True
            memory_thread.start()

        param_name = parameters[b_param]

        print "* Running %s test, %d times..." % (param_name,
                                                  options.run_count)

        response = ra.run_analysis("ramspeed-win32.exe -b %d -l %d" %
                                   (b_param, options.run_count),
                                   "artifacts-memory",
                                   init_commands=[],
                                   bind_ip=ftp_ip)

        # Now store our results
        results_file = os.path.join(
            options.output_dir,
            "trial_b%d_l%d.txt" % (b_param, options.run_count))
        sensor_file = os.path.join(
            options.output_dir,
            "trial_b%d_l%d_sensor.txt" % (b_param, options.run_count))
        print "* Storing results (%d bytes) in %s." % (len(response),
                                                       results_file)
        f = open(results_file, "w+")
        f.write(response)
        f.close()

        if options.enable_sensor:
            (time_elapsed, bytes_read) = memory_thread.join()
            f = open(sensor_file, "w+")
            f.write(str(time_elapsed) + "\t" + str(bytes_read))
            f.close()
Пример #6
0
def run_analysis(options):

    # Get our FTP IP
    try:
        ftp_ip = NET.get_ip_address(options.ftp_interface)
    except:
        logger.error("Could not find ip for the given interface. (%s)"%
                     options.ftp_interface)
            
    # Add a sensors to physical machines if needed
    if options.machine_type == G.MACHINE_TYPES.PHYSICAL:
        has_memory = has_disk = False
        
        if options.machine_config is None:
            logger.error("No machine config file given.")
            return
        
        # This isn't the class we use in practice, but fake it here for simplicity
        machines = CONF.import_from_config(options.machine_config, "machine")
    
        if options.machine not in machines:
            logger.error("%s is not a valid machine from the config file."%options.machine)
            logger.error("Valid targets are: %s"%machines.keys())
            return

        # Get our machine object
        machine = machines[options.machine]
            
        # Ensure that a sensor config is defined
        if options.sensor_config is None:
            logger.error("A sensor config file must be defined for physical analysis")
            return
        # Get the list of sensors
        sensors = CONF.import_from_config(options.sensor_config, "sensor")
        
        # Add sensors to our machine
        print "Trying to find physical sensors for %s..."%options.machine
        added_sensors = machine.add_sensors(sensors)
        
        if options.enable_sensor:
            machine.disk.sata_enable_all()
        
    else:
        machine = VirtualMachine(options.machine,
                                 vm_type=options.machine_type,
                                 volatility_profile=options.profile)
        
        
    
    ftp_info = {'user':G.FTP_USER,
                 'pass':G.FTP_PASSWORD,
                 'ip':ftp_ip,
                 'port':G.FTP_PORT,
                 'dir':None
                 }
    
    print machine.power_status()
    
    ra = RemoteAnalysis(options.profile, machine.control, ftp_info)
    
    for trial in range(44,options.run_count):
        
        print "Running trial #%d..."%trial
        
        # Should we fire up our disk sensor?
#         if options.enable_sensor:
#             log_dcap_filename = os.path.join(options.output_dir,"trial_%d.dcap"%trial)
#             log_dcap_queue = multiprocessing.Queue()
#             log_dcap_writer = CaptureWriter(log_dcap_filename,
#                                             log_dcap_queue)
#             log_dcap_writer.start()
#             
#             dcap_engine = DiskCaptureEngine(machine, log_dcap_queue)
#             dcap_engine.start()
            
        iozone_cmd = "iozone.exe -a -g 2G -i 0 -i 1"
        response = ra.run_analysis(iozone_cmd,
                                     None,
                                     init_commands=["cd C:\Program Files\Benchmarks\Iozone3_414"],
                                     bind_ip=ftp_ip)

        f = open(os.path.join(options.output_dir,"trial_%d.txt"%trial), "w+")
        f.write(response)
        f.close()
        
#         if options.enable_sensor:
#             dcap_engine.stop()
#             log_dcap_writer.stop()
            
        print response