Skip to content

Simulation Grapher

jfuruness edited this page Mar 3, 2021 · 4 revisions

Table of Contents

Short Description

This module graphs various attack/defend scenarios at various adoption percentages.

Long Description

This grapher is a little bit too dynamic, and thus, can be complex to understand. This section is moreso meant as a developers guide on how this was built so that you can edit it in the future if need be. Reach out to me if you have any questions and I'd be more than happy to walk you through it.

In short, the grapher works as follows. The user specifies what points to plot on the x axis (default is all available). The user specifies what values they want on the X axis. The user specifies what policies to graph on the plot. Along with a few other optional parameters. Graphs for the simulations are generated.

  1. The graph dir of /tmp/graphs is overwritten/created from scratch
  2. The graphs are generated using the graph generator class
  3. Using multiprocessing, the graphs are written to files (mp is used because it can be very slow if there are lots of graphs)
  4. The graphs are tared up

Let's go more in depth into how the graph generator class generates the graphs.

  1. Aggregate tables are generated. This is because each trial is saved separately in the database. So all these trials are aggregated together depending on the test information. Afterwards, they are averaged together with a 95% confidence interval.
  2. We get all the possible variations of test scenarios that exist in the database, which takes place in the get_graph_attrs function.
  3. For each variation of test scenarios, we extract that information from the database and make a graph class a. For each graph class, we first create a bunch of line classes b. Each line class consists of the test information and then a single policy c. Note that this will change depending on what is chosen for the x axis (the default being the adoption percentages)

Note that if you are running a simulation and you really need a custom graph, beyond the standard change of the x axis, then you can merely inherit either the graph class or the line class and overwrite the methods that you need to whilst maintaining the functionality. That being said, this has been fairly versatile thus far so hopefully you will not need to.

Note also that each line on the graphs is formatted with the Line_Formatter class. This class will automatically assign unique markers, styles, and colors to the lines. This is used when writing the graphs and are passed into matplotlib functions.

Also note that by default we write the plots as both pngs and tikz. If you want faster plots, simply change the num in the fmts argument, as shown in the usage below.

NOTE: Currently the Y axis is one of three things: Percent hijacked, percent disconnected, percent successful connection.

Usage

NOTE: You must make sure that the simulator has been run and that results are stored in the database.

From the Command Line

Best way:

lib_bgp_data --simulation_grapher

For debugging:

lib_bgp_data --simulation_grapher --debug

This example must be run over the package, so cd into one directory above that package

python3 -m lib_bgp_data --simulation_grapher

From a Script:

To initialize Simulation Grapher with default values:

from lib_bgp_data import Simulation_Grapher
grapher = Simulation_Grapher()

To initialize Simulation_Grapher with logging level and database section:

from logging import DEBUG
from lib_bgp_data import Simulation_Grapher
grapher = Simulation_Grapher(stream_level=DEBUG.
                             section="mydatabasesection")

Running the Simulation_Grapher for ROV++ Sims with defaults:

from lib_bgp_data import Simulation_Grapher

grapher = Simulation_Grapher()
grapher.run()

Running the Simulation_Grapher with non default arguments:

from lib_bgp_data import Simulation_Grapher
from lib_bgp_data.simulations.simulation_grapher.enums import Graph_Formats, Policy_Combos

grapher = Simulation_Grapher()
# First arg is x axis pts. Default None for all points
grapher.run(x_axis_pts=[2,3,4],
            # column to place on x axis. Default percent for percent adoption
            # Something like ezbgpsec may want rounds on the x axis
            x_axis_column="rounds",
            # Policy combos to graph on a single graph
            # Defaults include all ROV++ policies, all ROV++ LITE policies, and EZ_BGP policies
            # Feel free to override this as well and create your own for your case
            Policy_Combos.__members__.values(),
            # If you want to display titles on the graphs. By default profs want this off
            titles=False,
            # fmts of the graphs. This is just .png and .tikz. It's faster if you exclude one.
            fmts=Graph_Formats.__members__.values())
            
)

Design Choices

  • Table of contents
  • See long-description
  • Also, everything was made as dynamic as possible so that all parts could be overwritten.
  • This way, regardless of the simulation, the grapher could stay (mostly) the same
  • Multiprocessing was used to write the graphs because with so many graphs it may take a long time
  • titles default to False because apparently titles aren't good in LaTeX
  • Policy combinations are used rather than plotting the powerset of policies to save time
  • Line formats are automatically specified so that the user does not have to worry about selecting a specific line format when plotting and it can be taken care of behind the scenes when new enums are added

Table Schema

There are a lot of columns of info, so see here. Note that the test info is located there as well, which is used to group the rows. At the time of this writing (check the file to be sure), it is as follows:

test_info = ["adopt_pol",
             "attack_type",
             "number_of_attackers",
             "subtable_name",
             "percent",
             "round_num",
             "extra_bash_arg_1",
             "extra_bash_arg_2",
             "extra_bash_arg_3",
             "extra_bash_arg_4",
             "extra_bash_arg_5"]