Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test():
automated = True # whether to open ksdiff, log to file...
if __name__ == "__main__":
automated = False
dirname, filename = os.path.split(os.path.abspath(__file__))
parent_dir = os.path.abspath(os.path.join(dirname, os.pardir))
anm = autonetkit.NetworkModel()
input_file = os.path.join(parent_dir, "small_internet.graphml")
input_graph = graphml.load_graphml(input_file)
import autonetkit.build_network as build_network
anm = build_network.initialise(input_graph)
anm = build_network.apply_design_rules(anm)
try:
from websocket import create_connection
except ImportError:
print "websocket-client package not installed"
else:
autonetkit.update_http(anm)
ws = create_connection("ws://localhost:8000/ws")
ws.send("overlay_list")
automated = True # whether to open ksdiff, log to file...
enabled = False
if __name__ == "__main__":
# not called by test
automated = False
enabled = True
remote_server = "54.252.205.75"
if enabled:
dirname, filename = os.path.split(os.path.abspath(__file__))
input_file = os.path.join(dirname, "../big.graphml")
input_graph = graphml.load_graphml(input_file)
import autonetkit.build_network as build_network
anm = build_network.initialise(input_graph)
anm = build_network.apply_design_rules(anm)
render_hostname = "localhost"
nidb = console_script.create_nidb(anm)
import autonetkit.compilers.platform.netkit as pl_netkit
nk_compiler = pl_netkit.NetkitCompiler(nidb, anm, render_hostname)
nk_compiler.compile()
import autonetkit.render
autonetkit.render.render(nidb)
import autonetkit.deploy.netkit as nk_deploy
def build_anm(topology_name):
print "Building anm for %s" % topology_name
dirname, filename = os.path.split(os.path.abspath(__file__))
input_filename = os.path.join(dirname, "%s.graphml" % topology_name)
anm = autonetkit.NetworkModel()
input_graph = graphml.load_graphml(input_filename)
import autonetkit.build_network as build_network
anm = build_network.initialise(input_graph)
anm = build_network.apply_design_rules(anm)
return anm
automated = True # whether to open ksdiff, log to file...
if __name__ == "__main__":
automated = False
dirname, filename = os.path.split(os.path.abspath(__file__))
anm = autonetkit.NetworkModel()
input_file = os.path.join(dirname, "small_internet.graphml")
input_graph = graphml.load_graphml(input_file)
import autonetkit.build_network as build_network
anm = build_network.initialise(input_graph)
anm = build_network.apply_design_rules(anm)
anm.save()
anm_restored = autonetkit.NetworkModel()
anm_restored.restore_latest()
g_phy_original = anm['phy']
g_phy_restored = anm_restored['phy']
assert(all(n in g_phy_restored for n in g_phy_original))
#TODO: do more extensive deep check of parameters
import autonetkit.workflow as workflow
render_hostname = "localhost"
nidb = workflow.create_nidb(anm)
import autonetkit.compilers.platform.netkit as pl_netkit
nk_compiler = pl_netkit.NetkitCompiler(nidb, anm, render_hostname)
nk_compiler.compile()
nidb.save()
def build_anm(topology_name):
print "Building anm for %s" % topology_name
dirname, filename = os.path.split(os.path.abspath(__file__))
input_filename = os.path.join(dirname, "%s.graphml" % topology_name)
anm = autonetkit.NetworkModel()
input_graph = graphml.load_graphml(input_filename)
import autonetkit.build_network as build_network
anm = build_network.initialise(input_graph)
anm = build_network.apply_design_rules(anm)
return anm
def test():
log.info("Testing ANM")
anm = autonetkit.NetworkModel()
g_in = anm.add_overlay("input")
router_ids = ["r1", "r2", "r3", "r4", "r5"]
g_in.add_nodes_from(router_ids)
g_in.update(device_type = "router")
g_in.update(asn = 1)
positions = {'r3': (107, 250), 'r5': (380, 290), 'r1': (22, 50), 'r2': (377, 9), 'r4': (571, 229)}
for node in g_in:
node.x = positions[node][0]
node.y = positions[node][1]
eth0 = node.add_interface("eth0")
eth0.speed = 100
def test():
automated = True # whether to open ksdiff, log to file...
if __name__ == "__main__":
automated = False
dirname, filename = os.path.split(os.path.abspath(__file__))
anm = autonetkit.NetworkModel()
input_file = os.path.join(dirname, "small_internet.graphml")
input_graph = graphml.load_graphml(input_file)
import autonetkit.build_network as build_network
anm = build_network.initialise(input_graph)
anm = build_network.apply_design_rules(anm)
import autonetkit.console_script as console_script
render_hostname = "localhost"
nidb = console_script.create_nidb(anm)
import autonetkit.compilers.platform.netkit as pl_netkit
nk_compiler = pl_netkit.NetkitCompiler(nidb, anm, render_hostname)
nk_compiler.compile()
import autonetkit.render
def test():
automated = True # whether to open ksdiff, log to file...
if __name__ == "__main__":
automated = False
dirname, filename = os.path.split(os.path.abspath(__file__))
parent_dir = os.path.abspath(os.path.join(dirname, os.pardir))
anm = autonetkit.NetworkModel()
input_file = os.path.join(parent_dir, "small_internet.graphml")
input_graph = graphml.load_graphml(input_file)
import autonetkit.build_network as build_network
anm = build_network.initialise(input_graph)
anm = build_network.apply_design_rules(anm)
try:
from websocket import create_connection
except ImportError:
print "websocket-client package not installed"
else:
autonetkit.update_http(anm)
def test_split(self):
anm = autonetkit.topos.house()
g_phy = anm['phy']
edge = g_phy.edge("r1", "r2")
new_nodes = ank_utils.split_edge(g_phy, edge)
r1 = g_phy.node('r1')
r2 = g_phy.node('r2')
r1_r2 = g_phy.node('r1_r2')
self.assertListEqual(new_nodes, [r1_r2])
result = [n.neighbors() for n in new_nodes]
self.assertListEqual([[r1, r2]], result)
# For multiple edges and specifying a prepend for the new nodes
anm = autonetkit.topos.house()
g_phy = anm['phy']
edges = g_phy.node("r2").edges()
new_nodes = ank_utils.split_edges(g_phy, edges, id_prepend="split_")
split_r2_r4 = g_phy.node('split_r2_r4')
split_r1_r2 = g_phy.node('split_r1_r2')
split_r2_r3 = g_phy.node('split_r2_r3')
expected_result = [split_r2_r4, split_r1_r2, split_r2_r3]
self.assertListEqual(expected_result, new_nodes)
result = [n.neighbors() for n in new_nodes]
r3 = g_phy.node('r3')
r4 = g_phy.node('r4')
expected_result = [[r4, r2], [r1, r2], [r2, r3]]
self.assertListEqual(expected_result, result)
# Can specify a default value if unset
nodes = ["r1", "r2", "r3"]
r1 = g_in.node('r1')
r2 = g_in.node('r2')
r3 = g_in.node('r3')
r4 = g_in.node('r4')
r5 = g_in.node('r5')
ank_utils.set_node_default(g_in, nodes, role="core")
ank_utils.copy_attr_from(g_in, g_phy, "role", default="edge")
result = [(n, n.get("role")) for n in g_phy]
expected_result = [(r4, 'edge'), (r5, 'edge'), (r1, 'core'),
(r2, 'core'), (r3, 'core')]
self.assertListEqual(expected_result, result)
# Can specify the remote attribute to set
ank_utils.copy_attr_from(g_in, g_phy, "role",
"device_role", default="edge")
result = [(n, n.get('device_role')) for n in g_phy]
expected_result = [(n, n.get('role') if n.get('role') else 'edge')
for n in g_in]
self.assertListEqual(expected_result, result)
# Can specify the type to cast to
g_in.update(memory = "32")
ank_utils.copy_attr_from(g_in, g_phy, "memory", type=int)
result = [n.get("memory") for n in g_phy]
expected_result = [32, 32, 32, 32, 32]
self.assertEqual(expected_result, result)