#NEWLINE# def bootstrap( self , sync_callback = None , boot_controllers = default_boot_controllers ) : #NEWLINE# #INDENT# 'Return a simulation object encapsulating the state of\n       the system in its initial starting point:\n       - boots controllers\n       - connects switches to controllers\n\n       May be invoked multiple times!\n    ' #NEWLINE# if ( sync_callback is None ) : #NEWLINE# #INDENT# sync_callback = ReplaySyncCallback ( None ) #NEWLINE# #UNINDENT# def initialize_io_loop( ) : #NEWLINE# #INDENT# ' boot the IOLoop (needed for the controllers) ' #NEWLINE# _io_master = IOMaster ( ) #NEWLINE# _io_master . monkey_time_sleep ( ) #NEWLINE# msg . set_io_master ( _io_master ) #NEWLINE# return _io_master #NEWLINE# #UNINDENT# def wire_controller_patch_panel( controller_manager , create_io_worker ) : #NEWLINE# #INDENT# patch_panel = None #NEWLINE# if ( not self . interpose_on_controllers ) : #NEWLINE# #INDENT# return patch_panel #NEWLINE# #UNINDENT# remote_controllers = controller_manager . remote_controllers #NEWLINE# if ( len ( remote_controllers ) != 0 ) : #NEWLINE# #INDENT# patch_panel = self . controller_patch_panel_class ( create_io_worker ) #NEWLINE# for c in remote_controllers : #NEWLINE# #INDENT# patch_panel . register_controller ( c . cid , c . guest_eth_addr , c . host_device ) #NEWLINE# #UNINDENT# #UNINDENT# return patch_panel #NEWLINE# #UNINDENT# def instantiate_topology( create_io_worker ) : #NEWLINE# #INDENT# 'construct a clean topology object from topology_class and\n      topology_params' #NEWLINE# log . info ( 'Creating topology...' ) #NEWLINE# comma = ( '' if ( self . _topology_params == '' ) else ',' ) #NEWLINE# topology = eval ( ( '%s(%s%screate_io_worker=create_io_worker)' % ( self . _topology_class . __name__ , self . _topology_params , comma ) ) ) #NEWLINE# return topology #NEWLINE# #UNINDENT# def monkeypatch_select( multiplex_sockets , controller_manager ) : #NEWLINE# #INDENT# mux_select = None #NEWLINE# demuxers = [ ] #NEWLINE# if multiplex_sockets : #NEWLINE# #INDENT# log . debug ( 'Monkeypatching STS select' ) #NEWLINE# revert_select_monkeypatch ( ) #NEWLINE# mux_select = MultiplexedSelect ( ) #NEWLINE# for c in controller_manager . controller_configs : #NEWLINE# #INDENT# true_socket = connect_socket_with_backoff ( address = c . address , port = c . port ) #NEWLINE# true_socket . setblocking ( 0 ) #NEWLINE# io_worker = mux_select . create_worker_for_socket ( true_socket ) #NEWLINE# demux = STSSocketDemultiplexer ( io_worker , c . server_info ) #NEWLINE# demuxers . append ( demux ) #NEWLINE# #UNINDENT# select . _old_select = select . select #NEWLINE# select . select = mux_select . select #NEWLINE# #UNINDENT# return ( mux_select , demuxers ) #NEWLINE# #UNINDENT# revert_select_monkeypatch ( ) #NEWLINE# io_master = initialize_io_loop ( ) #NEWLINE# sync_connection_manager = STSSyncConnectionManager ( io_master , sync_callback ) #NEWLINE# controller_manager = boot_controllers ( self . controller_configs , self . snapshot_service , sync_connection_manager , multiplex_sockets = self . multiplex_sockets ) #NEWLINE# controller_patch_panel = wire_controller_patch_panel ( controller_manager , io_master . create_worker_for_socket ) #NEWLINE# topology = instantiate_topology ( io_master . create_worker_for_socket ) #NEWLINE# patch_panel = self . _patch_panel_class ( topology . switches , topology . hosts , topology . get_connected_port ) #NEWLINE# openflow_buffer = OpenFlowBuffer ( ) #NEWLINE# dataplane_trace = None #NEWLINE# if ( self . _dataplane_trace_path is not None ) : #NEWLINE# #INDENT# dataplane_trace = Trace ( self . _dataplane_trace_path , topology ) #NEWLINE# #UNINDENT# if ( self . _violation_persistence_threshold is not None ) : #NEWLINE# #INDENT# violation_tracker = ViolationTracker ( self . _violation_persistence_threshold ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# violation_tracker = ViolationTracker ( ) #NEWLINE# #UNINDENT# ( mux_select , demuxers ) = monkeypatch_select ( self . multiplex_sockets , self ) #NEWLINE# simulation = Simulation ( topology , controller_manager , dataplane_trace , openflow_buffer , io_master , controller_patch_panel , patch_panel , sync_callback , mux_select , demuxers , violation_tracker , self . _kill_controllers_on_exit ) #NEWLINE# if self . ignore_interposition : #NEWLINE# #INDENT# simulation . set_pass_through ( ) #NEWLINE# #UNINDENT# self . current_simulation = simulation #NEWLINE# return simulation