test module¶
- class test.Case¶
Bases: enum.Enum
An enumeration defining different test cases.
- one = None¶
Test case 1.
- two = None¶
Test case 2.
- zero = None¶
Test case 0.
- class test.Graph(adjacent, tcp='FAST', until=None)¶
Bases: builtins.object
Graphing class for generating simulation results.
This class uses the Network class to create and run a network simulation with the specified parameters, then groups the values monitored during that simulation by category (window title), assuming that all monitored identifiers have the form “window title,tags”, where tags may itself be a comma-delimited string of integer values, such as an index, address, etc. The instantiated object then provides various methods to graph/save the data sets using matplotlib. The only obvious caveat when using the Graph class to run a simulation is that monitored data must be restricted to numerical values (anything that can be cast as a float) in order to actually produce graphical output.
Parameters: - static graph(title, datasets, legend='', y_label='', scale=1.0, save=False)¶
Graph a set of data sets.
Parameters: - title (str) – graph title
- datasets ([(tuple, numpy.ndarray, numpy.ndarray)]) – a list of tagged data sets given as (tags, x, y)
- legend (str) – legend label for each data set (e.g. “flow”)
- y_label (str) – label for the plot’s y axis
- scale (float) – y is multiplied by scale before graphing
- save (bool) – flag indicating whether to save or display figures
- graph_all(tags=None, save=False)¶
Graph all data sets.
If the tags parameter is given, graphical output for data sets whose title is a key in tags will be restricted to data sets with the specified tags.
Parameters: - tags (dict) – dictionary mapping titles to data set tags
- save (bool) – flag indicating whether to save or display figures
Returns: None
- graph_titles(titles, tags=None, save=False)¶
Graph sets of data sets by category title.
If the tags parameter is given, graphical output for data sets whose title is a key in tags will be restricted to data sets with the specified tags.
Parameters: - titles (list) – titles of data categories to graph
- tags (dict) – dictionary mapping titles to data set tags
- save (bool) – flag indicating whether to save or display figures
Returns: None
- title_kwargs = {'Dropped packets': {'legend': 'link', 'y_label': 'packets'}, 'Round trip times': {'scale': 1e-06, 'legend': 'flow', 'y_label': 'ms'}, 'Link rate': {'scale': 1000, 'legend': 'link', 'y_label': 'Mbps'}, 'Flow received': {'scale': 1000, 'legend': 'flow', 'y_label': 'Mbps'}, 'Host received': {'scale': 1000, 'legend': 'host', 'y_label': 'Mbps'}, 'Link fill': {'legend': 'link', 'y_label': 'packets'}, 'Host rate': {'scale': 1000, 'legend': 'host', 'y_label': 'Mbps'}, 'Window size': {'legend': 'flow', 'y_label': 'packets'}, 'Flow rate': {'scale': 1000, 'legend': 'flow', 'y_label': 'Mbps'}}¶
Maps graph title to graph() keyword parameters.
- titles¶
Data categories.
Returns: list of data categories Return type: [str]
- class test.Network(adjacent=None, tcp='FAST')¶
Bases: builtins.object
This class encapsulates a network simulation.
If adjacent is None, then a GUI for drawing a network appears. The adjacency list should be formatted as [((src, dest), (capacity, buffer size, delay))], where src & dest are formatted as a string with a leading “h” or “r”, specifying a host or router, followed by an integer id. Flows should be given as [((src, dest), ((data, delay), (tcp, tcp_param)))], where src & dest are formatted as previously, but only host tags are allowed. Link arguments are all in bits/bps, as is the data parameter for flows. Delay is given in ns. The tcp parameter is a string which determines which TCP algorithm to use; see process.Flow.allowed_tcp for accepted TCP specifiers. The tcp_param parameter is a list containing the arguments for initializing the TCP object, and will change depending on the TCP algorithm specified. See process for details of the currently implemented TCP algorithms. Alternatively, adjacent may be a test case, as defined by the enumerated type Case. If so the tcp parameter may be a (valid) TCP specifier, used for all flows in the given test case.
Parameters: - simulate(until=None)¶
Run the initialized simulation.
Parameters: until (int or simpy.events.Event) – time or event to run the simulation until Returns: all monitored values Return type: {str: [(int, object)]}
- test.ONE = <Case.one: 1>¶
Convenience alias for test case 1 (type).
- test.TWO = <Case.two: 2>¶
Convenience alias for test case 2 (type).
- class test.TestCase¶
Bases: builtins.object
Factory class for producing test case adjacency lists.
See adjacent() for details.
- adjacencies = {<Case.two: 2>: ([(('r0', 'r1'), (10000000, 1024000, 10000000)), (('r1', 'r2'), (10000000, 1024000, 10000000)), (('r2', 'r3'), (10000000, 1024000, 10000000)), (('h0', 'r0'), (12500000, 1024000, 10000000)), (('h1', 'r0'), (12500000, 1024000, 10000000)), (('h2', 'r2'), (12500000, 1024000, 10000000)), (('h3', 'r3'), (12500000, 1024000, 10000000)), (('h4', 'r1'), (12500000, 1024000, 10000000)), (('h5', 'r3'), (12500000, 1024000, 10000000))], [(('h0', 'h3'), (280000000, 500000000)), (('h1', 'h4'), (120000000, 10000000000)), (('h2', 'h5'), (240000000, 20000000000))]), <Case.zero: 0>: ([(('h0', 'h1'), (10000000, 512000, 10000000))], [(('h0', 'h1'), (160000000, 1000000000))]), <Case.one: 1>: ([(('h0', 'r0'), (12500000, 512000, 10000000)), (('r0', 'r1'), (10000000, 512000, 10000000)), (('r0', 'r2'), (10000000, 512000, 10000000)), (('r1', 'r3'), (10000000, 512000, 10000000)), (('r2', 'r3'), (10000000, 512000, 10000000)), (('r3', 'h1'), (12500000, 512000, 10000000))], [(('h0', 'h1'), (160000000, 500000000))])}¶
Edge & flow adjacency lists for each test case.
- classmethod adjacent(case, tcp='FAST')¶
Generate an adjanceny list for a given test case.
For the given test case & TCP specifier, an adjacency list of the type taken by network.Network is constructed from the adjacency lists in adjacencies and the TCP parameters in tcp_parameters.
Parameters: - case (Case) – test case to build adjacency lists for
- tcp (str) – TCP specifier (see process.Flow.allowed_tcp)
Returns: Adjacency lists defining edges & flows
Return type: ([((str, str), (int, int, int))], [((str, str), ((int, int), (str, list)))])
- tcp_parameters = {<Case.two: 2>: {'Reno': [[1, 1500000000], [1, 90000000], [1, 90000000]], 'FAST': [[1, 150000000, 6], [1, 90000000, 6], [1, 90000000, 6]]}, <Case.zero: 0>: {'Reno': [[1, 30000000]], 'FAST': [[1, 30000000, 45]]}, <Case.one: 1>: {'Reno': [[1, 120000000]], 'FAST': [[1, 120000000, 20]]}}¶
TCP parameters for each test case.
- test.ZERO = <Case.zero: 0>¶
Convenience alias for test case 0 (type).