def create_network(network): """Creates a new network. Keyword arguments: @param name: The network name or dictionary configuration. @return: A new network instance. """ if isinstance(network, dict): return NetworkConfig( org.vertx.java.core.json.JsonObject( _vertigo.createNetwork(map_to_java(network)))) return NetworkConfig(_vertigo.createNetwork(network))
class testFattree(unittest.TestCase): config = NetworkConfig( paths=[('h25', 'h34', ['h25', 's14', 's6', 's0', 's10', 's19', 'h34'])]) def testSameCore(self): # different cores, different aggregates spec = "not match(ip_src=a.b.c.d); s14: .* s0 .* => (N-s0)* s1 (N-s0)* od" expected = [('s6', 's1'), ('s1', 's10')] runSynthesis(FattreeTopo(), testFattree.config, spec, expected) def testDifferentCore(self): # different cores, different aggregates spec = "not match(ip_src=a.b.c.d); s14: .* s0 .* => (N-s0)* s3 (N-s0)* od" expected = [('s14', 's7'), ('s7', 's3'), ('s11', 's19'), ('s3', 's11')] runSynthesis(FattreeTopo(), testFattree.config, spec, expected) def testImmutable(self): # different aggregate, but make core immutable # note: difference is core s2 and s3 between two tests spec = "not match(ip_src=a.b.c.d); s14: .* s10 .* => (N-s10)* s11 (N-s10)* od NM:{s2}" expected = [('s7', 's3'), ('s14', 's7'), ('s3', 's11'), ('s11', 's19')] runSynthesis(FattreeTopo(), testFattree.config, spec, expected) spec = "not match(ip_src=a.b.c.d); s14: .* s10 .* => (N-s10)* s11 (N-s10)* od NM:{s3}" expected = [('s7', 's2'), ('s14', 's7'), ('s11', 's19'), ('s2', 's11')] runSynthesis(FattreeTopo(), testFattree.config, spec, expected)
def testCluster(self): config = NetworkConfig(egresses=['Dst'], paths=[('Src', 'Dst', ['Src', 's14', 'Core', 's15', 'Dst'])]) spec = "not match(ip_src=a.b.c.d); Src: .* Core .* => N* Fw1 N* od" expected = [('Fw1', 's18'), ('Core', 'Fw1'), ('s18', 's15')] runSynthesis(DiamondClusterTopo(), config, spec, expected)
def testThinTree(self): config = NetworkConfig(egresses=['s10', 's11', 's1'], paths=[('s1', 's10', ['s1', 's2', 's4', 's8', 's10'])]) spec = "not match(ip_src=a.b.c.d); s1: .* s4 .* => (N-s4)(N-s4)* s5 (N-s4)(N-s4)*" expected = [('s2', 's5'), ('s5', 's8')] runSynthesis(ThintreeTopo(), config, spec, expected)
def testLineTopo(): #line topo topo = LineTopo() config = NetworkConfig(paths=[('s1', 's5', ['s1', 's2', 's3', 's4', 's5'])]) specstr = "not match(ip_src=a.b.c.d); s1: .* s3 .* => (N-s3)* s6 (N-s3)* od" print topo, config, specstr run("linetopo", topo, config, specstr)
def testSosrFigure3(self): config = NetworkConfig(egresses=['Z'], flowtable=[('A', '10.0.1.1', 'Z', 'F1'), ('B', '10.0.1.1', 'Z', 'F1'), ('C', '10.0.1.1', 'Z', 'F1'), ('F1', '10.0.1.1', 'Z', 'X'), ('X', '10.0.1.1', 'Z', 'Z'), ('F2', '10.0.1.1', 'Z', 'Y')]) spec = "match(tcp_src_port=80); A,B,C: .* F1 .* => (N-F1)* F2 (N-F1)* od NM:{F1,F2}" expected = [('Y', 'Z'), ('B', 'F2'), ('C', 'F2'), ('A', 'F2')] runSynthesis(SosrTopo(), config, spec, expected)
def fattree_test(): config = NetworkConfig(paths=[('h25', 'h34', ['h25', 's14', 's6', 's0', 's10', 's19', 'h34'])]) topo = FattreeTopo() topo.apply_config(config) specstr = "not match(ip_src=a.b.c.d); s14: .* s0 .* => (N-s0)* s1 (N-s0)* od" s = Specification.parseString(topo, specstr) net = synthesis.AbstractNetwork(topo, s) abs_net = conv_abstract_network(net) slvr = CPPSolver(abs_net) t = time.time() result = slvr.solve() t = time.time() - t expected = [('s6', 's1'), ('s1', 's10')] expected = [(net.node_intrep[s], net.node_intrep[d]) for (s,d) in expected] print "Result:", result print "Expect:", expected print "Solver time: {0}ms".format(round(t * 1000, 3))
def diamond_test(): config = NetworkConfig(paths=[('s1', 's4', ['s1', 's2', 's4'])], egresses=['s4']) topo = DiamondTopo() topo.apply_config(config) specstr = "not match(ip_src=a.b.c.d); s1: .* s2 .* => (N-s2) s3 (N-s2)" s = Specification.parseString(topo, specstr) net = synthesis.AbstractNetwork(topo, s) abs_net = conv_abstract_network(net) slvr = CPPSolver(abs_net) t = time.time() result = slvr.solve() t = time.time() - t expected = [('s3', 's4'), ('s1', 's3')] expected = [(net.node_intrep[s], net.node_intrep[d]) for (s,d) in expected] print "Result:", result print "Expect:", expected print "Solver time: {0}ms".format(round(t * 1000, 3))
def testForwardPath(self): config = NetworkConfig(paths=[('s1', 's4', ['s1', 's2', 's4'])], egresses=['s4']) spec = "not match(ip_src=a.b.c.d); s1: .* s2 .* => (N-s2) s3 (N-s2)" expected = [('s3', 's4'), ('s1', 's3')] runSynthesis(DiamondTopo(), config, spec, expected)
TOPOS = { "stanford": StanfordTopo, "internet2": Internet2Topo, "fattree": FattreeTopo, "diamond": DiamondTopo, "line": LineTopo, "diamondext": DiamondExtendedTopo, "thintree": ThintreeTopo, "sosr": SosrTopo, "as1755": As1755Topo, "cluster": DiamondClusterTopo } CONFIGS = { "diamond": NetworkConfig(egresses=['s4'], paths=[('s1', 's4', ['s1', 's2', 's4'])]), "diamondext": NetworkConfig(egresses=['s6'], paths=[('s1', 's6', ['s1', 's2', 's3', 's5', 's6'])]), "thintree": NetworkConfig(egresses=['s10', 's11', 's1'], paths=[('s1', 's10', ['s1', 's2', 's4', 's8', 's10'])]), "fattree": NetworkConfig(paths=[('h25', 'h34', ['h25', 's14', 's6', 's0', 's10', 's19', 'h34'])]), "sosr": NetworkConfig(egresses=['Z'], flowtable=[('A', '10.0.1.1', 'Z', 'F1'), ('B', '10.0.1.1', 'Z', 'F1'), ('C', '10.0.1.1', 'Z', 'F1'), ('F1', '10.0.1.1', 'Z', 'X'),
def test_fattree_perf(): logger.setLogLevel("info") # fattree 4 ------------------------------------------------------ topo = FattreeTopo(k=4) config = NetworkConfig(paths=[('h25', 'h34', None), ('h24', 'h34', None)]) specstr = "not match(ip_src=a.b.c.d); s14: .* s3 .* => (N-s3)* s2 (N-s3)* od" run("fattree4,2", topo, config, specstr) # topo = FattreeTopo(k=4) config = NetworkConfig(paths=[('h25', 'h34', None), ('h24', 'h34', None)]) specstr = "not match(ip_src=a.b.c.d); s14: .* s3 .* => (N-s3)* s0 (N-s3)* od" run("fattree4,4", topo, config, specstr) # fattree 6 ------------------------------------------------------ topo = FattreeTopo(k=6) config = NetworkConfig(paths=[('h78', 'h98', None)]) specstr = "not match(ip_src=a.b.c.d); s38: .* s2 .* => (N-s2)* s0 (N-s2)* od" run("fattree6,2", topo, config, specstr) topo = FattreeTopo(k=6) config = NetworkConfig(paths=[('h78', 'h98', None)]) specstr = "not match(ip_src=a.b.c.d); s38: .* s2 .* => (N-s2)* s4 (N-s2)* od" run("fattree6,4", topo, config, specstr) # fattree 8 ------------------------------------------------------ topo = FattreeTopo(k=8) config = NetworkConfig(paths=[('h138', 'h151', None)]) specstr = "not match(ip_src=a.b.c.d); s62: .* s13 .* => (N-s13)* s12 (N-s13)* od" run("fattree8,2", topo, config, specstr) topo = FattreeTopo(k=8) config = NetworkConfig(paths=[('h138', 'h151', None)]) specstr = "not match(ip_src=a.b.c.d); s62: .* s13 .* => (N-s13)* s0 (N-s13)* od" run("fattree8,4", topo, config, specstr) # fattree 10 ----------------------------------------------------- topo = FattreeTopo(k=10) config = NetworkConfig(paths=[('h329', 'h250', None)]) specstr = "not match(ip_src=a.b.c.d); s115: .* s22 .* => (N-s22)* s21 (N-s22)* od" run("fattree10,2", topo, config, specstr) topo = FattreeTopo(k=10) config = NetworkConfig(paths=[('h329', 'h250', None)]) specstr = "not match(ip_src=a.b.c.d); s115: .* s22 .* => (N-s22)* s0 (N-s22)* od" run("fattree10,4", topo, config, specstr) # fattree 12 ----------------------------------------------------- topo = FattreeTopo(k=12) config = NetworkConfig(paths=[('h334', 'h539', None)]) specstr = "not match(ip_src=a.b.c.d); s133: .* s19 .* => (N-s19)* s20 (N-s19)* od" run("fattree12,2", topo, config, specstr) topo = FattreeTopo(k=12) config = NetworkConfig(paths=[('h334', 'h539', None)]) specstr = "not match(ip_src=a.b.c.d); s133: .* s19 .* => (N-s19)* s0 (N-s19)* od" run("fattree12,4", topo, config, specstr) # fattree 14 ----------------------------------------------------- topo = FattreeTopo(k=14) config = NetworkConfig(paths=[('h690', 'h587', None)]) specstr = "not match(ip_src=a.b.c.d); s210: .* s19 .* => (N-s19)* s19 (N-s19)* od" run("fattree14,2", topo, config, specstr) topo = FattreeTopo(k=14) config = NetworkConfig(paths=[('h690', 'h587', None)]) specstr = "not match(ip_src=a.b.c.d); s210: .* s19 .* => (N-s19)* s0 (N-s19)* od" run("fattree14,4", topo, config, specstr) # fattree 16 ----------------------------------------------------- topo = FattreeTopo(k=16) config = NetworkConfig(paths=[('h920', 'h1270', None)]) specstr = "not match(ip_src=a.b.c.d); s267: .* s31 .* => (N-s31)* s30 (N-s31)* od" run("fattree16,2", topo, config, specstr) topo = FattreeTopo(k=16) config = NetworkConfig(paths=[('h920', 'h1270', None)]) specstr = "not match(ip_src=a.b.c.d); s267: .* s31 .* => (N-s31)* s0 (N-s31)* od" run("fattree16,4", topo, config, specstr)