def __init__(self, passive_nodes, run_which_nodes, interactive, telnet_port_file, multicast_loopback, log_level, config): log_file_name = "rift.log" if "RIFT_TEST_RESULTS_DIR" in os.environ: log_file_name = os.environ[ "RIFT_TEST_RESULTS_DIR"] + "/" + log_file_name logging.basicConfig( filename=log_file_name, format='%(asctime)s:%(levelname)s:%(name)s:%(message)s', level=log_level) self._run_which_nodes = run_which_nodes self._interactive = interactive self._telnet_port_file = telnet_port_file self._multicast_loopback = multicast_loopback self._config = config self._tx_src_address = self.read_global_configuration( config, 'tx_src_address', '') self._nodes = sortedcontainers.SortedDict() self.create_configuration(passive_nodes) cli_log = logging.getLogger('cli') if self._nodes: first_node = self._nodes.peekitem(0)[1] else: first_node = None if self._interactive: self._cli_listen_handler = None self._interactive_cli_session_handler = cli_session_handler.CliSessionHandler( sock=None, rx_fd=sys.stdin.fileno(), tx_fd=sys.stdout.fileno(), parse_tree=self.parse_tree, command_handler=self, log=cli_log, node=first_node) else: self._cli_listen_handler = cli_listen_handler.CliListenHandler( command_tree=self.parse_tree, command_handler=self, log=cli_log, default_node=first_node) self._interactive_cli_session_handler = None if self._telnet_port_file is None: print( "Command Line Interface (CLI) available on port {}".format( self._cli_listen_handler.port)) else: try: with open(self._telnet_port_file, 'w') as file: print(self._cli_listen_handler.port, file=file) except IOError: pass # TODO: Log an error
def __init__(self, passive_nodes, run_which_nodes, interactive, telnet_port_file, ipv4_multicast_loopback, ipv6_multicast_loopback, log_level, config): log_file_name = "rift.log" # TODO: Make this configurable if "RIFT_TEST_RESULTS_DIR" in os.environ: log_file_name = os.environ[ "RIFT_TEST_RESULTS_DIR"] + "/" + log_file_name logging.basicConfig( filename=log_file_name, format='%(asctime)s:%(levelname)s:%(name)s:%(message)s', level=log_level) self._run_which_nodes = run_which_nodes self._interactive = interactive self._telnet_port_file = telnet_port_file self.ipv4_multicast_loopback = ipv4_multicast_loopback self.ipv6_multicast_loopback = ipv6_multicast_loopback self._config = config if self.nr_nodes() > 1: self._stand_alone = False self.simulated_interfaces = True self.physical_interface_name = self.default_physical_interface() else: self._stand_alone = True self.simulated_interfaces = False self.physical_interface_name = None self.tx_src_address = self.read_global_configuration( config, 'tx_src_address', '') self.floodred_enabled = self.read_global_configuration( config, 'flooding_reduction', True) self.floodred_redundancy = self.read_global_configuration( config, 'flooding_reduction_redundancy', constants.DEFAULT_FLOODING_REDUCTION_REDUNDANCY) self.floodred_similarity = self.read_global_configuration( config, 'flooding_reduction_similarity', constants.DEFAULT_FLOODING_REDUCTION_SIMILARITY) self.floodred_system_random = random.randint(0, 0xffffffffffffffff) self.intf_traffic_stats_group = stats.Group() self.intf_lie_fsm_stats_group = stats.Group() self.node_ztp_fsm_stats_group = stats.Group() self._nodes = sortedcontainers.SortedDict() self.create_configuration(passive_nodes) cli_log = logging.getLogger('cli') if self._nodes: first_node = self._nodes.peekitem(0)[1] else: first_node = None if self._interactive: make_terminal_unbuffered() self._cli_listen_handler = None self._interactive_cli_session_handler = cli_session_handler.CliSessionHandler( sock=None, rx_fd=sys.stdin.fileno(), tx_fd=sys.stdout.fileno(), parse_tree=self.parse_tree, command_handler=self, log=cli_log, node=first_node) else: self._cli_listen_handler = cli_listen_handler.CliListenHandler( command_tree=self.parse_tree, command_handler=self, log=cli_log, default_node=first_node) self._interactive_cli_session_handler = None if self._telnet_port_file is None: print( "Command Line Interface (CLI) available on port {}".format( self._cli_listen_handler.port)) else: try: with open(self._telnet_port_file, 'w') as file: print(self._cli_listen_handler.port, file=file) except IOError: pass # TODO: Log an error