예제 #1
0
    def create_network(self, settings=None, f=None):
        """Initializes the network and bw variables.

        Parameters
        ----------
        settings : dict, optional
            A dictionary of settings (the default is None). See `Blackwidow`
            for valid values.
        f : string, optional
            The filename containing the network (the default is None).
        """

        # If settings are not provided, initialize bw and network without any
        # settings.
        if settings is None:
            self.bw = BlackWidow()
            self.network = Network(self.bw)

        # Initialize bw and network with settings
        else:
            self.bw = BlackWidow(settings)
            self.network = parser.config_network(f, self.bw)

        # Reset visual parameters
        self.do_reset_v("")

        # Clear the plot
        self.do_clear("")

        # Create a new figure to show the network
        f = plt.figure(2)
        self.do_show("")
예제 #2
0
    def do_load(self, line):
        """Loads a file.

        Parameters
        ----------
        line : string
            A string containing command line arguments.
            See help_load.
        """

        # Get the args
        args = line.split()

        # Make sure only 1 argument is provided
        if not check_args(args, 1):
            return
        try:
            # Initialize bw with the log file
            base = os.path.basename(args[0])
            self.bw = BlackWidow({'log_file': os.path.splitext(base)[0]})

            # Initialie network from the file
            self.network = parser.config_network(args[0], self.bw)

            # Create a new figure
            f = plt.figure(2)

            # Show the network if show_network is True
            if self.show_network:
                self.do_show("")
        except Exception as e:
            print e
예제 #3
0
    def do_reset(self, line):
        """Resets network

        Parameters
        ----------
        line : string
            A string containing command line arguments. Ignored.
        """

        # Initialize bw and network without settings
        self.bw = BlackWidow()
        self.network = Network(self.bw)

        # Clear the figure
        f = plt.figure(2)

        # Reset visual parameters
        self.do_reset_v("")

        # Show the network
        self.do_show("")
예제 #4
0
def main():
    """Runs the simulator."""

    # Configure argument parser
    parser = argparse.ArgumentParser(description='Run a TCP network'
                                     'simulation')

    # Files containing network configurations. Multiple files can be provided.
    parser.add_argument('files',
                        metavar='config_file',
                        type=str,
                        nargs='*',
                        help='name of file to process. e.g. case0.json')
    # Flag to show verbose output
    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        help='whether to print verbose statements')
    # Flag to graph in real time
    parser.add_argument('-r',
                        '--real-time',
                        action='store_true',
                        help='whether to graph in real time')
    # Flag to use static routing instead of dynamic routing
    parser.add_argument('-s',
                        '--static-routing',
                        action='store_true',
                        help='uses static routing instead of dynamic routing.')
    # Flag to set the routing packet size
    parser.add_argument('-rp',
                        '--routing-packet-size',
                        type=int,
                        help='Sets the size of the routing packet')
    # Flag to set the TCP algorithm. Valid arguments are: Reno, Tahoe, Fast
    parser.add_argument('-t',
                        '--tcp-alg',
                        type=str,
                        help='Sets the TCP algorithm for the simulation.')
    # Flag to use non-interactive mode
    parser.add_argument('-n',
                        '--no-interactive',
                        action='store_true',
                        help='Sets interactive mode off')

    # Dictionary of alternative settings.
    # Default settings should be set in the BlackWidow class.
    settings = vars(parser.parse_args())

    # Iterate through config files specified.

    if len(settings['files']) != 0:
        for f in settings['files']:
            # Make default log_file name the input name without ext.
            # Set the log file if not running in real time since data will be
            # written to file.
            if not settings['real_time']:
                base = os.path.basename(f)
                settings['log_file'] = os.path.splitext(base)[0]

            # Run non-interactive mode if no_interactive flag is set.
            if settings["no_interactive"]:
                bw = BlackWidow(settings)
                bw.run(f)
            # Otherwise, run interactive mode and load file
            else:
                create_bw(settings, f)
    # Run interactive mode without loading any files
    else:
        create_bw()