autonetkit.anm package

Submodules

autonetkit.anm.base module

class autonetkit.anm.base.OverlayBase(anm, overlay_id)

Bases: autonetkit.anm.ank_element.AnkElement

Base class for overlays - overlay graphs, subgraphs, projections, etc

data

Returns data stored on this overlay graph

device(key)

To access programatically

edge(edge_to_find, dst_to_find=None, key=0)

returns edge in this graph with same src and dst and key for parallel edges (default is to return first edge) #TODO: explain parameter overloading: strings, edges, nodes...

Example:

>>> anm = autonetkit.topos.house()
>>> g_phy = anm['phy']
>>> e_r1_r2 = g_phy.edge("r1", "r2")

Can also find from an edge

>>> e_r1_r2_input = anm['input'].edge(e_r1_r2)

And for multi-edge graphs can specify key

>>> anm = autonetkit.topos.multi_edge()
>>> e1 = anm['phy'].edge("r1", "r2", 0)
>>> e2 = anm['phy'].edge("r1", "r2", 1)
>>> e1 == e2
False
>>> autonetkit.update_http(anm)
>>> eth0_r1 = anm["phy"].node("r1").interface("eth0")
>>> eth3_r1 = anm["phy"].node("r1").interface("eth3")
>>> eth0_r2 = anm["phy"].node("r2").interface("eth0")
>>> anm["phy"].has_edge(eth0_r1, eth0_r2)
True
>>> anm["phy"].has_edge(eth3_r1, eth0_r2)
False
edges(src_nbunch=None, dst_nbunch=None, *args, **kwargs)
>>> anm = autonetkit.topos.house()
>>> g_phy = anm['phy']
>>> g_phy.edges()
[(r4, r5), (r4, r2), (r5, r3), (r1, r2), (r1, r3), (r2, r3)]
>>> g_phy.edge("r1", "r2").color = "red"
>>> g_phy.edges(color = "red")
[(r1, r2)]
filter(nbunch=None, *args, **kwargs)
groupby(attribute, nodes=None)

Returns a dictionary sorted by attribute

>>> anm = autonetkit.topos.house()
>>> g_phy = anm['phy']
>>> g_phy.groupby("asn")
{1: [r1, r2, r3], 2: [r4, r5]}

Can also specify a subset to work from

>>> nodes = [n for n in g_phy if n.degree() > 2]
>>> g_phy.groupby("asn", nodes=nodes)
{1: [r2, r3]}
has_edge(edge_to_find, dst_to_find=None)

Tests if edge in graph

>>> anm = autonetkit.topos.house()
>>> g_phy = anm['phy']
>>> r1 = g_phy.node("r1")
>>> r2 = g_phy.node("r2")
>>> r5 = g_phy.node("r5")
>>> g_phy.has_edge(r1, r2)
True
>>> g_phy.has_edge(r1, r5)
False
>>> e_r1_r2 = anm['input'].edge(r1, r2)
>>> g_phy.has_edge(e_r1_r2)
True
interface(interface)
is_multigraph()

Example:

>>> anm = autonetkit.topos.house()
>>> anm['phy'].is_multigraph()
False
>>> anm = autonetkit.topos.multi_edge()
>>> anm['phy'].is_multigraph()
True
l3devices(*args, **kwargs)

Shortcut for nodes(), tests if device is_l3device

>>> anm = autonetkit.topos.mixed()
>>> anm['phy'].l3devices()
[s1, r1, r2, r3]
name
node(key)

Returns node based on name This is currently O(N). Could use a lookup table

Example:

>>> anm = autonetkit.topos.house()
>>> g_phy = anm['phy']
>>> r1 = g_phy.node("r1")

Can also find across layers >>> r1_input = anm[‘input’].node(r1)

node_label(node)
nodes(*args, **kwargs)
>>> anm = autonetkit.topos.multi_as()
>>> g_phy = anm["phy"]
>>> g_phy.nodes()
[r4, r5, r6, r7, r1, r2, r3, r8, r9, r10]
>>> g_phy.nodes(asn=1)
[r4, r5, r1, r2, r3]
>>> g_phy.nodes(asn=3)
[r7, r8, r9, r10]
>>> g_phy.nodes(asn=1, ibgp_role="RR")
[r4, r5]
>>> g_phy.nodes(asn=1, ibgp_role="RRC")
[r1, r2, r3]
overlay(key)

Get to other overlay graphs in functions

routers(*args, **kwargs)

Shortcut for nodes(), sets device_type to be router

>>> anm = autonetkit.topos.mixed()
>>> anm['phy'].routers()
[r1, r2, r3]
servers(*args, **kwargs)

Shortcut for nodes(), sets device_type to be server

>>> anm = autonetkit.topos.mixed()
>>> anm['phy'].servers()
[s1]
switches(*args, **kwargs)

Shortcut for nodes(), sets device_type to be switch

>>> anm = autonetkit.topos.mixed()
>>> anm['phy'].switches()
[sw1]

autonetkit.anm.edge module

class autonetkit.anm.edge.NmEdge(anm, overlay_id, src_id, dst_id, ekey=0)

Bases: autonetkit.anm.ank_element.AnkElement

API to access link in network

apply_to_interfaces(attribute)

>>> anm = autonetkit.topos.house()
>>> edge = anm['phy'].edge("r1", "r2")
>>> edge.src_int.color = edge.dst_int.color = "blue"
>>> (edge.src_int.color, edge.dst_int.color)
('blue', 'blue')
>>> edge.color = "red"
>>> edge.apply_to_interfaces("color")
>>> (edge.src_int.color, edge.dst_int.color)
('red', 'red')
bind_interface(node, interface)

Bind this edge to specified index

dst

Destination node of edge

>>> anm = autonetkit.topos.house()
>>> edge = anm['phy'].edge("r1", "r2")
>>> edge.dst
r2
dst_int

Interface bound to destination node of edge

>>> anm = autonetkit.topos.house()
>>> edge = anm['phy'].edge("r1", "r2")
>>> edge.dst_int
eth0.r2
dump()
get(key)

For consistency, edge.get(key) is neater than getattr(edge, key)

>>> anm = autonetkit.topos.house()
>>> edge = anm['phy'].edge("r1", "r2")
>>> edge.color = "red"
>>> edge.get("color")
'red'
interfaces()
>>> anm = autonetkit.topos.house()
>>> edge = anm['phy'].edge("r1", "r2")
>>> list(edge.interfaces())
[eth0.r1, eth0.r2]
is_multigraph()
is_parallel()

If there is more than one edge between the src, dst of this edge

>>> anm = autonetkit.topos.multi_edge()
>>> edge = anm['phy'].edge("r1", "r2")
>>> edge.is_parallel()
True
>>> edge = anm['phy'].edge("r2", "r3")
>>> edge.is_parallel()
False
raw_interfaces

Direct access to the interfaces dictionary, used by ANK modules

set(key, val)

For consistency, edge.set(key, value) is neater than setattr(edge, key, value)

>>> anm = autonetkit.topos.house()
>>> edge = anm['phy'].edge("r1", "r2")
>>> edge.color = "blue"
>>> edge.color
'blue'
>>> edge.set("color", "red")
>>> edge.color
'red'
src

Source node of edge

>>> anm = autonetkit.topos.house()
>>> edge = anm['phy'].edge("r1", "r2")
>>> edge.src
r1
src_int

Interface bound to source node of edge

>>> anm = autonetkit.topos.house()
>>> edge = anm['phy'].edge("r1", "r2")
>>> edge.src_int
eth0.r1

autonetkit.anm.graph module

class autonetkit.anm.graph.NmGraph(anm, overlay_id)

Bases: autonetkit.anm.base.OverlayBase

API to interact with an overlay graph in ANM

add_edge(src, dst, retain=None, **kwargs)

Adds an edge to the overlay

add_edges(*args, **kwargs)

Adds a set of edges. Alias for add_edges_from

add_edges_from(ebunch, bidirectional=False, retain=None, warn=True, **kwargs)

Add edges. Unlike NetworkX, can only add an edge if both src and dst in graph already. If they are not, then they will not be added (silently ignored)

Retains interface mappings if they are present (this is why ANK
stores the interface reference on the edges, as it simplifies cross-layer access, as well as split, aggregate, etc retaining the interface bindings)_

Bidirectional will add edge in both directions. Useful if going from an undirected graph to a directed, eg G_in to G_bgp #TODO: explain “retain” and [“retain”] logic

if user wants to add from another overlay, first go g_x.edges() then add from the result

allow (src, dst, ekey), (src, dst, ekey, data) for the ank utils

add_node(node, retain=None, **kwargs)

Adds node to overlay

add_nodes_from(nbunch, retain=None, update=False, **kwargs)

Update won’t append data (which could clobber) if node exists

allocate_input_interfaces()

allocates edges to interfaces

anm

Returns anm for this overlay

>>> anm = autonetkit.topos.house()
number_of_edges(node_a, node_b)
remove_edges_from(ebunch)

Removes set of edges from ebunch

remove_node(node_id)

Removes a node from the overlay

remove_nodes_from(nbunch)

Removes set of nodes from nbunch

subgraph(nbunch, name=None)
update(nbunch=None, **kwargs)

Sets property defined in kwargs to all nodes in nbunch

autonetkit.anm.graph_data module

class autonetkit.anm.graph_data.NmGraphData(anm, overlay_id)

Bases: object

API to access link in network

dump()

autonetkit.anm.interface module

class autonetkit.anm.interface.NmPort(anm, overlay_id, node_id, interface_id)

Bases: autonetkit.anm.ank_element.AnkElement

category
description
dump()
edges()

Returns all edges from node that have this interface ID This is the convention for binding an edge to an interface

get(key)

For consistency, node.get(key) is neater than getattr(interface, key)

id

Returns id of node, falls-through to phy if not set on this overlay

is_bound

Returns if this interface is bound to an edge on this layer

is_loopback
is_loopback_zero
is_physical
neighbors()

Returns interfaces on nodes that are linked to this interface Can get nodes using [i.node for i in interface.neighbors()]

node

Returns parent node of this interface

phy
set(key, val)

For consistency, node.set(key, value) is neater than setattr(interface, key, value)

autonetkit.anm.network_model module

class autonetkit.anm.network_model.NetworkModel(all_multigraph=False)

Bases: autonetkit.anm.ank_element.AnkElement

add_overlay(name, nodes=None, graph=None, directed=False, multi_edge=False, retain=None)

Adds overlay graph of name name

devices(*args, **kwargs)
dump()
has_overlay(overlay_id)
initialise_graph(graph)

Sets input graph. Converts to undirected. Initialises graphics overlay.

initialise_input(graph)

Initialises input graph

node_label(node)

Returns node label from physical graph

overlay(key)
overlay_nx_graphs
overlays()
restore(pickle_file)
restore_from_json(in_data)
restore_latest(directory=None)

Restores latest saved ANM

save()
set_node_label(seperator, label_attrs)

autonetkit.anm.node module

class autonetkit.anm.node.NmNode(anm, overlay_id, node_id)

Bases: autonetkit.anm.ank_element.AnkElement

add_interface(*args, **kwargs)

Public function to add interface

add_loopback(*args, **kwargs)

Public function to add a loopback interface

asn

Returns ASN of this node

>>> anm = autonetkit.topos.house()
>>> r1 = anm['phy'].node("r1")
>>> r1.asn
1
>>> r5 = anm['phy'].node("r5")
>>> r5.asn
2
degree()

Returns degree of node

>>> anm = autonetkit.topos.house()
>>> r1 = anm['phy'].node("r1")
>>> r1.degree()
2
>>> r2 = anm['phy'].node("r2")
>>> r2.degree()
3
dump()

Dump attributes of this node

edges(*args, **kwargs)

Edges to/from this node

>>> anm = autonetkit.topos.house()
>>> r1 = anm['phy'].node("r1")
>>> r1.edges()
[(r1, r2), (r1, r3)]
>>> r2 = anm['phy'].node("r2")
>>> r2.edges()
[(r2, r4), (r2, r1), (r2, r3)]
get(key)

For consistency, node.get(key) is neater than getattr(node, key)

id

Returns node id

interface(key)

Returns interface based on interface id

interfaces(*args, **kwargs)

Public function to view interfaces

is_device_type(device_type)

Generic user-defined cross-overlay search for device_type either from this graph or the physical graph

is_hub()

Either from this graph or the physical graph

is_l3device()

Layer 3 devices: router, server, cloud, host ie not switch

>>> anm = autonetkit.topos.mixed()
>>> r1 = anm['phy'].node("r1")
>>> r1.is_l3device()
True
>>> s1 = anm['phy'].node("s1")
>>> s1.is_l3device()
True
>>> sw1 = anm['phy'].node("sw1")
>>> sw1.is_l3device()
False
is_multigraph()
is_router()

Either from this graph or the physical graph

>>> anm = autonetkit.topos.mixed()
>>> r1 = anm['phy'].node("r1")
>>> r1.is_router()
True
>>> s1 = anm['phy'].node("s1")
>>> s1.is_router()
False
>>> sw1 = anm['phy'].node("sw1")
>>> sw1.is_router()
False
is_server()

Returns if device is a server

>>> anm = autonetkit.topos.mixed()
>>> r1 = anm['phy'].node("r1")
>>> r1.is_server()
False
>>> s1 = anm['phy'].node("s1")
>>> s1.is_server()
True
>>> sw1 = anm['phy'].node("sw1")
>>> sw1.is_server()
False
is_switch()

Returns if device is a switch

>>> anm = autonetkit.topos.mixed()
>>> r1 = anm['phy'].node("r1")
>>> r1.is_switch()
False
>>> s1 = anm['phy'].node("s1")
>>> s1.is_switch()
False
>>> sw1 = anm['phy'].node("sw1")
>>> sw1.is_switch()
True
label

Returns node label (mapped from ANM)

loopback_interfaces(*args, **kwargs)
loopback_zero
>>> anm = autonetkit.topos.house()
>>> r1 = anm['phy'].node("r1")
>>> lo_zero = r1.loopback_zero
neighbor_interfaces(*args, **kwargs)
>>> anm = autonetkit.topos.house()
>>> r1 = anm['phy'].node("r1")
>>> r1.neighbor_interfaces()
[eth0.r2, eth0.r3]
>>> r2 = anm['phy'].node("r2")
>>> r2.neighbor_interfaces()
[eth0.r4, eth0.r1, eth1.r3]
neighbors(*args, **kwargs)

Returns neighbors of node

>>> anm = autonetkit.topos.house()
>>> r1 = anm['phy'].node("r1")
>>> r1.neighbors()
[r2, r3]
>>> r2 = anm['phy'].node("r2")
>>> r2.neighbors()
[r4, r1, r3]

Can also filter

>>> r2.neighbors(asn=1)
[r1, r3]
>>> r2.neighbors(asn=2)
[r4]
physical_interfaces(*args, **kwargs)
raw_interfaces

Direct access to the interfaces dictionary, used by ANK modules

set(key, val)

For consistency, node.set(key, value) is neater than setattr(node, key, value)

autonetkit.anm.subgraph module

class autonetkit.anm.subgraph.OverlaySubgraph(anm, overlay_id, graph, name=None)

Bases: autonetkit.anm.base.OverlayBase

Module contents