def launch(): h1 = NoPacketHost.create("h1") h2 = GetPacketHost.create("h2") s1 = sim.config.default_switch_type.create('s1') s2 = sim.config.default_switch_type.create('s2') h1.linkTo(s1) h2.linkTo(s2) def test_tasklet(): yield 5 api.userlog.debug('Linking s1 and s2') s1.linkTo(s2) yield 0.1 api.userlog.debug('Sending ping from h1 to h2') h1.ping(h2) yield 5 if h2.pings != 1: api.userlog.error("h2 got %s pings instead of 1", h2.pings) good = False else: api.userlog.debug('h2 successfully received the ping') good = True import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch(): host_count = 4 topo_rand.launch(host_type=GetPacketHost, hosts=host_count) def test_tasklet(): yield 20 # when i drop this number to '15' i seldomly start getting test failures # let me know if you have the same problem h1.ping(h2) h1.ping(h3) h1.ping(h4) h2.ping(h1) h2.ping(h3) h2.ping(h4) h3.ping(h1) h3.ping(h2) h3.ping(h4) h4.ping(h1) h4.ping(h2) h4.ping(h3) yield 10 if h1.pings != 3 or h2.pings != 3 or h3.pings != 3 or h4.pings != 3: api.userlog.error("The pings didn't get through") sys.exit(1) api.userlog.debug("Pings got through") sys.exit(0) api.run_tasklet(test_tasklet)
def launch(): h1 = TestHost.create("h1") h2 = TestHost.create("h2") h3 = TestHost.create("h3") h4 = TestHost.create("h4") hosts = [h1, h2, h3, h4] r = sim.config.default_switch_type.create("r") r.linkTo(h1) r.linkTo(h2) r.linkTo(h3) r.linkTo(h4) def test_tasklet(): yield 1 api.userlog.debug("Sending test pings") h2.ping(h1) yield 3 + 3 # for h in hosts: # print(h.name + ": " + str(h.pings) + ", " + str(h.pongs)) r.unlinkTo(h4) h2.ping(h4) yield 3 + 3 # for h in hosts: # print(h.name + ": " + str(h.pings) + ", " + str(h.pongs)) pings = sum([h.pings for h in hosts]) pongs = sum([h.pongs for h in hosts]) good = True if pings != 5: api.userlog.error("Got %s pings", pings) good = False if pongs != 1: api.userlog.error("Got %s pongs", pongs) good = False if good: api.userlog.debug("Test passed successfully!") # End the simulation and (if not running in interactive mode) exit. import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch(): h1 = NoPacketHost.create('h1') h2 = GetPacketHost.create('h2') s1 = sim.config.default_switch_type.create('s1') s2 = sim.config.default_switch_type.create('s2') s3 = sim.config.default_switch_type.create('s3') c1 = CountingHub.create('c1') h1.linkTo(s1, latency=1) s1.linkTo(s2, latency=1) s2.linkTo(s3, latency=5) s3.linkTo(c1, latency=1) c1.linkTo(h2, latency=1) def test_tasklet(): yield 20 api.userlog.debug('Sending ping from h1 to h2') h1.ping(h2) yield 10 if c1.pings == 1: api.userlog.debug('The ping took the right path') good = True else: api.userlog.error( 'idk what happened to ping lol theres no other way') good = False s4 = sim.config.default_switch_type.create('s4') c2 = CountingHub.create('c2') s1.linkTo(s4, latency=1) s4.linkTo(c2, latency=1) c2.linkTo(h2, latency=1) yield 20 h1.ping(h2) yield 5 if c1.pings == 1 and c2.pings == 1: api.userlog.debug('The ping took the right path') good2 = True elif c2.pings == 0 and c1.pings == 2: api.userlog.error('The ping took the wrong path') good2 = False else: api.userlog.error('Something strange happened to the ping') good2 = False import sys sys.exit(0 if good and good2 else 1) api.run_tasklet(test_tasklet)
def launch(): h1 = GetPacketHost.create("h1") h2 = GetPacketHost.create("h2") s1 = sim.config.default_switch_type.create("s1") s2 = sim.config.default_switch_type.create("s2") s3 = sim.config.default_switch_type.create("s3") s4 = sim.config.default_switch_type.create("s4") s5 = sim.config.default_switch_type.create("s5") h1.linkTo(s1) h2.linkTo(s2) s1.linkTo(s2) s1.linkTo(s3) s3.linkTo(s4) s4.linkTo(s5) s5.linkTo(s2) def test_tasklet(): yield 5 # Wait five seconds for routing to converge api.userlog.debug("Sending test ping 1") h1.ping(h2) yield 5 api.userlog.debug("Failing and slowing s1-s2 link ") # pdb.set_trace() s1.unlinkTo(s2) # s1.linkTo(s2 ) yield 10 api.userlog.debug("Sending test ping 2") h1.ping(h2) # pdb.set_trace() yield 10 s1.linkTo(s2, latency=2) if h2.pings != 2: api.userlog.error("h2 got %s packets instead of 2", h2.pings) else: api.userlog.debug("Test passed successfully!") # End the simulation and (if not running in interactive mode) exit. import sys sys.exit(0) api.run_tasklet(test_tasklet)
def launch(): h1 = TestHost.create("h1") h2 = TestHost.create("h2") h3 = TestHost.create("h3") h4 = TestHost.create("h4") hosts = [h1, h2, h3, h4] r = sim.config.default_switch_type.create("r") r.linkTo(h1) r.linkTo(h2) r.linkTo(h3) r.linkTo(h4) def test_tasklet(): yield 1 api.userlog.debug("Sending test pings") h2.ping(h1) yield 3 h2.ping(h4) yield 3 h1.ping(h2) api.userlog.debug("Waiting for deliveries") yield 5 # Wait five seconds for deliveries pings = sum([h.pings for h in hosts]) pongs = sum([h.pongs for h in hosts]) good = True if pings != 7: api.userlog.error("Got %s pings", pings) good = False if pongs != 3: api.userlog.error("Got %s pongs", pongs) good = False if good: api.userlog.debug("Test passed successfully!") # End the simulation and (if not running in interactive mode) exit. import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch(): h1 = NoPacketHost.create('h1') h2 = GetPacketHost.create('h2') s1 = sim.config.default_switch_type.create('s1') s2 = sim.config.default_switch_type.create('s2') c1 = CountingHub.create('c1') h1.linkTo(s1) s1.linkTo(c1) c1.linkTo(s2) h2.linkTo(s1, latency=5) h2.linkTo(s2) def test_tasklet(): yield 15 api.userlog.debug('Sending ping from h1 to h2 - it should get through') h1.ping(h2) yield 5 if c1.pings != 1: api.userlog.error("The first ping didn't go through s2") sys.exit(1) if h2.pings != 1: api.userlog.error("The first ping didn't get through") sys.exit(1) api.userlog.debug('Disconnecting s2 and h2') s2.unlinkTo(h2) api.userlog.debug('Waiting for routes to expire') yield 20 api.userlog.debug( 'Sending ping from h1 to h2 - should still get through and not' + 'try to go through c1') h1.ping(h2) yield 7 if c1.pings != 1: api.userlog.error( 's1 forwarded the ping through c1 instead of directly to h2') sys.exit(1) elif h2.pings != 2: api.userlog.error( 'h2 did not receive the second ping') sys.exit(1) else: api.userlog.debug('yay') sys.exit(0) api.run_tasklet(test_tasklet)
def launch(): h1 = NoPacketHost.create('h1') h2 = GetPacketHost.create('h2') s1 = sim.config.default_switch_type.create('s1') s2 = sim.config.default_switch_type.create('s2') c1 = CountingHub.create('c1') c2 = CountingHub.create('c2') h1.linkTo(s1, latency=1) s1.linkTo(c1, latency=1) c1.linkTo(s2, latency=1) s2.linkTo(h2, latency=1) s1.linkTo(c2, latency=3) # should not take c2.linkTo(h2, latency=1) def test_tasklet(): yield 10 # need to wait for routing tables api.userlog.debug('Sending ping from h1 to h2') h1.ping(h2) yield 5 # need to wait for packet to get past c1 if c1.pings == 1 and c2.pings == 0: api.userlog.debug('The ping took the right path') good = True else: api.userlog.error('Wrong initial path!') good = False api.userlog.debug('Increasing s2-h2 latency') s2.unlinkTo(h2) s2.linkTo(h2, latency=4) yield 5 # wait for update to propagate back to routers api.userlog.debug('Sending ping from h1 to h2') h1.ping(h2) yield 5 # wait for packet to pass c2 and get to h2 if c1.pings == 1 and c2.pings == 1: api.userlog.debug('Good path!') good = True and good else: api.userlog.error('You wrong') good = False import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch(): h1 = NoPacketHost.create('h1') h2 = GetPacketHost.create('h2') s1 = sim.config.default_switch_type.create('s1') s2 = sim.config.default_switch_type.create('s2') c1 = SwitchableCountingHub.create('c1') s1.linkTo(h1, latency=1) s1.linkTo(h2, latency=5) s1.linkTo(c1, latency=1) s2.linkTo(c1, latency=1) s2.linkTo(h2, latency=1) def test_tasklet(): yield 15 # wait for path convergence api.userlog.debug('Sending ping from h1 to h2') h1.ping(h2) yield 10 # wait for ping to go through if c1.pings != 1: api.userlog.error("Ping should have gone through c1") sys.exit(1) # unlink s2 s2.unlinkTo(c1) s2.unlinkTo(h2) s1.unlinkTo(c1) api.userlog.debug("bye bye s2") yield 25 # wait for new route convergence api.userlog.debug('Sending ping from h1 to h2') h1.ping(h2) yield 10 # wait for ping to reach h2 again if c1.pings != 1: api.userlog.error("c1 shouldn't have seen another ping") sys.exit(1) if h2.pings != 2: api.userlog.error("h2 should have seen the ping by now") sys.exit(1) sys.exit(0) api.run_tasklet(test_tasklet)
def launch(): h1 = NoPacketHost.create('h1') h2 = GetPacketHost.create('h2') s1 = sim.config.default_switch_type.create('s1') s2 = sim.config.default_switch_type.create('s2') s3 = sim.config.default_switch_type.create('s3') c1 = CountingHub.create('c1') h1.linkTo(s1) s1.linkTo(c1) c1.linkTo(s2) s2.linkTo(s3) s3.linkTo(h2) def test_tasklet(): yield 15 api.userlog.debug('Sending ping from h1 to h2 - it should get through') h1.ping(h2) yield 5 if c1.pings != 1: api.userlog.error("The first ping didn't get through") sys.exit(1) api.userlog.debug('Disconnecting s2 and s3') s2.unlinkTo(s3) api.userlog.debug( 'Waiting for poison to propagate, but not long enough ' + 'for routes to time out') yield 10 api.userlog.debug( 'Sending ping from h1 to h2 - it should be dropped at s2, not s1') h1.ping(h2) yield 5 if c1.pings != 2: api.userlog.error( 's1 dropped the ping when it should have forwarded it') sys.exit(1) else: api.userlog.debug('s1 forwarded the ping as expected') if h2.pings != 1: api.userlog.error('h2 received pings after the link removed!') sys.exit(1) sys.exit(0) api.run_tasklet(test_tasklet)
def launch(): h1 = GetPacketHost.create("h1") h2 = GetPacketHost.create("h2") s1 = sim.config.default_switch_type.create('s1') s2 = sim.config.default_switch_type.create('s2') s3 = sim.config.default_switch_type.create('s3') s4 = sim.config.default_switch_type.create('s4') s5 = sim.config.default_switch_type.create('s5') h1.linkTo(s1) h2.linkTo(s2) s1.linkTo(s2) s1.linkTo(s3) s3.linkTo(s4) s4.linkTo(s5) s5.linkTo(s2) def test_tasklet(): t = 25.5 yield t # Wait for routing to converge api.userlog.debug("Sending test ping 1") h1.ping(h2) yield t api.userlog.debug("Failing s1-s2 link") s1.unlinkTo(s2) yield t api.userlog.debug("Sending test ping 2") h1.ping(h2) yield t if h2.pings != 2: api.userlog.error("h2 got %s packets instead of 2", h2.pings) good = False else: api.userlog.debug("Test passed successfully!") good = True # End the simulation and (if not running in interactive mode) exit. import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch (): h1 = GetPacketHost.create("h1") h2 = GetPacketHost.create("h2") s1 = sim.config.default_switch_type.create("s1") s2 = sim.config.default_switch_type.create("s2") #s3 = sim.config.default_switch_type.create("s3") h1.linkTo(s1) h2.linkTo(s2) # s2.linkTo(s3) # s1.linkTo(s3) def test_tasklet (): s1.linkTo(s2) yield 5 # Wait five seconds for routing to converge api.userlog.debug("Sending test ping 1") h1.ping(h2) yield 5 # Wait five seconds to receive ping s1.unlinkTo(s2) api.userlog.debug("Sending test ping 2") h1.ping(h2) yield 5 # Wait a bit before sending last ping print "s1 = ", s1.vector, "s2 = ", s2.vector s1.linkTo(s2) yield 5 api.userlog.debug("Sending test ping 3") h1.ping(h2) yield 5 # Wait five seconds for pings to be delivered print "s1 = ", s1.vector, "s2 = ", s2.vector api.userlog.debug("Pings received: " + str(h2.pings)) if h2.pings != 2: api.userlog.debug("FAILED") else: api.userlog.debug("Tests passed") # End the simulation and (if not running in interactive mode) exit. import sys sys.exit(0) api.run_tasklet(test_tasklet)
def launch(): h2 = NoPacketHost.create('h2') h1 = GetPacketHost.create('h1') s1 = sim.config.default_switch_type.create('s1') s3 = sim.config.default_switch_type.create('s3') c1 = CountingHub.create('c1') h1.linkTo(s1, latency=10) s1.linkTo(s3, latency=1) s1.linkTo(h2, latency=1) h1.linkTo(c1, latency=1) c1.linkTo(s3, latency=1) # s1.linkTo(s3, latency=1) # s3.linkTo(s4, latency=1) # s4.linkTo(h2, latency=1) def test_tasklet(): yield 20 api.userlog.debug('Sending ping from h2 to h1') h2.ping(h1) yield 20 if c1.pings == 1: api.userlog.debug('The ping took the right path') good = True else: api.userlog.error('Wrong initial path!') good = False s1.unlinkTo(s3) yield 20 api.userlog.debug('Sending ping from h2 to h1') h2.ping(h1) yield 20 if c1.pings == 1 and h1.pings == 2: api.userlog.debug('Good path!') good = True and good else: api.userlog.debug('Wrong!') good = False import sys if not good: sys.exit(1) sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch(): candy.launch(host_type=GetPacketHost) def test_tasklet(): yield 12 api.userlog.debug('Sending multiple pings - all should get through') h1a.ping(h2b) h1a.ping(h1b) h1b.ping(h2a) h1b.ping(h1a) h2a.ping(h1b) h2a.ping(h2b) h2b.ping(h1a) h2b.ping(h2a) yield 5 if h1a.pings != 2 or h1b.pings != 2 or h2a.pings != 2 or h2b.pings != 2: api.userlog.error("The pings didn't get through") sys.exit(1) api.userlog.debug("First round of pings got through") api.userlog.debug('Disconnecting s1 and s3') s1.unlinkTo(s3) yield 12 api.userlog.debug( 'Sending same set of pings again - all should get through') h1a.ping(h2b) h1a.ping(h1b) h1b.ping(h2a) h1b.ping(h1a) h2a.ping(h1b) h2a.ping(h2b) h2b.ping(h1a) h2b.ping(h2a) yield 7 if h1a.pings != 4 or h1b.pings != 4 or h2a.pings != 4 or h2b.pings != 4: api.userlog.error("The pings didn't get through") sys.exit(1) api.userlog.debug("Second round of pings got through") sys.exit(0) api.run_tasklet(test_tasklet)
def launch(): h1 = GetPacketHost.create('h1') h2 = GetPacketHost.create('h2') s1 = sim.config.default_switch_type.create('s1') s2 = sim.config.default_switch_type.create('s2') s3 = sim.config.default_switch_type.create('s3') c1 = CountingHub.create('c1') c2 = CountingHub.create('c2') c3 = CountingHub.create('c3') h1.linkTo(s1) s1.linkTo(c1) c1.linkTo(s3) h1.linkTo(s2) s2.linkTo(c2) c2.linkTo(s3) h1.linkTo(c3) c3.linkTo(s3) s3.linkTo(h2) def test_tasklet(): yield 15 api.userlog.debug( 'Sending ping from h1 to h2 - it should hit 3 routers') h1.ping(h2) yield 5 if h1.pings != 0 or h2.pings != 3 or c1.pings != 1 or c2.pings != 1 or c3.pings != 1: api.userlog.error("The ping did not propagate through all routers") sys.exit(1) api.userlog.debug( 'Sending ping from h2 to h1 - it should hit 1 router') h2.ping(h1) yield 5 if h1.pings != 1 or h2.pings != 3 or c1.pings != 1 or c2.pings != 1 or c3.pings != 2: api.userlog.error("The ping hit more than 1 router") sys.exit(1) api.userlog.debug("Pings sent correctly") sys.exit(0) api.run_tasklet(test_tasklet)
def launch(): h1 = GetPacketHost.create("h1") h2 = GetPacketHost.create("h2") s1 = sim.config.default_switch_type.create('s1') s2 = sim.config.default_switch_type.create('s2') c1 = CountingHub.create('c1') h1.linkTo(s1, latency=4) h2.linkTo(s1) s1.linkTo(s2) s2.linkTo(c1, latency=1) c1.linkTo(h1, latency=1) def test_tasklet(): t = 25.5 yield t # Wait for routing to converge api.userlog.debug("Sending test ping 1") h2.ping(h1) yield t api.userlog.debug("Failing s1-s2 link") s1.unlinkTo(s2) yield t api.userlog.debug("Sending test ping 2") h2.ping(h1) yield t if h1.pings != 2: api.userlog.error("h1 got %s packets instead of 2", h1.pings) good = False elif c1.pings != 1: api.userlog.error("c1 got %s pings instead of 1", c1.pings) good = False else: api.userlog.debug("Test passed successfully!") good = True # End the simulation and (if not running in interactive mode) exit. import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch(): h1 = GetPacketHost.create("h1") h2 = NoPacketHost.create("h2") h3 = NoPacketHost.create("h3") h4 = GetPacketHost.create("h4") r = sim.config.default_switch_type.create("r") s = sim.config.default_switch_type.create("s") r.linkTo(h1) r.linkTo(h2) s.linkTo(h3) s.linkTo(h4) r.linkTo(s) def test_tasklet(): yield 5 # Wait five seconds for routing to converge api.userlog.debug("Sending test pings") h2.ping(h1) h2.ping(h4) yield 1 # Wait a bit before sending last ping h3.ping(h1) yield 5 # Wait five seconds for pings to be delivered good = True if h1.pings != 2: api.userlog.error("h1 got %s packets instead of 2", h1.pings) good = False if h4.pings != 1: api.userlog.error("h4 got %s packets instead of 1", h4.pings) good = False if NoPacketHost.bad_pings != 0: api.userlog.error("Got %s unexpected packets", NoPacketHost.bad_pings) good = False if good: api.userlog.debug("Test passed successfully!") # End the simulation and (if not running in interactive mode) exit. import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch(): h1 = NoPacketHost.create('h1') h2 = GetPacketHost.create('h2') s1 = sim.config.default_switch_type.create('s1') s2 = sim.config.default_switch_type.create('s2') s3 = sim.config.default_switch_type.create('s3') c1 = CountingHub.create('c1') h1.linkTo(s1) s1.linkTo(c1) c1.linkTo(s2) s2.linkTo(s3) s3.linkTo(h2) def test_tasklet(): yield 15 api.userlog.debug('Sending ping from h1 to h2 - it should get through') h1.ping(h2) yield 5 if c1.pings != 1: api.userlog.error("The first ping didn't get through") sys.exit(1) api.userlog.debug('Disconnecting s2 and s3') s2.unlinkTo(s3) api.userlog.debug( 'Waiting for poison to propagate, but not long enough ' + 'for routes to time out') yield 10 api.userlog.debug( 'Sending ping from h1 to h2 - it should be dropped at s1') h1.ping(h2) yield 5 if c1.pings != 1: api.userlog.error( 's1 forwarded the ping when it should have dropped it') sys.exit(1) else: api.userlog.debug('s1 dropped the ping as expected') sys.exit(0) api.run_tasklet(test_tasklet)
def launch(): h1 = GetPacketHost.create("h1") h2 = NoPacketHost.create("h2") h3 = NoPacketHost.create("h3") h4 = GetPacketHost.create("h4") r = sim.config.default_switch_type.create("r") r.linkTo(h1) r.linkTo(h2) r.linkTo(h3) r.linkTo(h4) def test_tasklet(): yield 5 # Wait five seconds for routing to converge api.userlog.debug("Sending test pings") h2.ping(h1) h2.ping(h4) yield 1 # Wait a bit before sending last ping h3.ping(h1) yield 5 # Wait five seconds for pings to be delivered good = True if h1.pings != 2: api.userlog.error("h1 got %s packets instead of 2", h1.pings) good = False if h4.pings != 1: api.userlog.error("h4 got %s packets instead of 1", h4.pings) good = False if NoPacketHost.bad_pings != 0: api.userlog.error("Got %s unexpected packets", NoPacketHost.bad_pings) good = False if good: api.userlog.debug("Test passed successfully!") # End the simulation and (if not running in interactive mode) exit. import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch (): h1 = GetPacketHost.create("h1") h2 = GetPacketHost.create("h2") h3 = GetPacketHost.create("h3") s1 = sim.config.default_switch_type.create("s1") s2 = sim.config.default_switch_type.create("s2") s3 = sim.config.default_switch_type.create("s3") h1.linkTo(s1) h2.linkTo(s2) h3.linkTo(s3) s2.linkTo(s1) s2.linkTo(s3) def test_tasklet (): yield 5 # Wait five seconds for routing to converge api.userlog.debug("Sending test pings") h2.ping(h1) yield 5 # Wait a bit before sending last ping if h1.pings == 1: api.userlog.debug("Recieved first ping from h2") api.userlog.debug(s2.table) api.userlog.debug(s1.table) api.userlog.debug(s3.table) api.userlog.debug("Removing link from s1 to s2") s2.unlinkTo(s1) yield 5 api.userlog.debug(s2.table) api.userlog.debug(s1.table) yield 5 # Wait five seconds for pings to be delivered # End the simulation and (if not running in interactive mode) exit. import sys sys.exit(0) api.run_tasklet(test_tasklet)
def launch(): h2 = NoPacketHost.create('h2') h1 = GetPacketHost.create('h1') s1 = sim.config.default_switch_type.create('s1') s2 = sim.config.default_switch_type.create('s2') s3 = sim.config.default_switch_type.create('s3') s4 = sim.config.default_switch_type.create('s4') c1 = CountingHub.create('c1') c2 = CountingHub.create('c2') h1.linkTo(c1, latency=1) h1.linkTo(c2, latency=1) c2.linkTo(s2, latency=4) c1.linkTo(s1, latency=1) s1.linkTo(s3, latency=1) s2.linkTo(s3, latency=1) s3.linkTo(s4, latency=1) s4.linkTo(h2, latency=1) def test_tasklet(): yield 20 api.userlog.debug('Sending ping from h1 to h2') h2.ping(h1) yield 5 good = True if c1.pings != 1 or c2.pings != 0: api.userlog.debug('The ping took the wrong path') good = False api.userlog.debug('C1 received %i pings, C2 received %i pings' % (c1.pings, c2.pings)) import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch(): h1 = NoPacketHost.create('h1') h2 = GetPacketHost.create('h2') s1 = sim.config.default_switch_type.create('s1') s2 = sim.config.default_switch_type.create('s2') s3 = sim.config.default_switch_type.create('s3') s4 = sim.config.default_switch_type.create('s4') c1 = CountingHub.create('c1') c2 = CountingHub.create('c2') h1.linkTo(s1, latency=1) s1.linkTo(s2, latency=1) s2.linkTo(s3, latency=1) s3.linkTo(c1, latency=1) c1.linkTo(h2, latency=1) s1.linkTo(s4, latency=3) s4.linkTo(c2, latency=1) c2.linkTo(h2, latency=1) def test_tasklet(): yield 20 api.userlog.debug('Sending ping from h1 to h2') h1.ping(h2) yield 5 if c1.pings == 1 and c2.pings == 0: api.userlog.debug('The ping took the right path') good = True elif c2.pings == 1 and c1.pings == 0: api.userlog.error('The ping took the wrong path') good = False else: api.userlog.error('Something strange happened to the ping') good = False import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch(): h1 = NoPacketHost.create('h1') s1 = sim.config.default_switch_type.create('s1') h1.linkTo(s1) def test_tasklet(): yield 5 api.userlog.debug('Sending ping from h1 to itself') h1.ping(h1) yield 5 if h1.bad_pings > 0: api.userlog.error('h1 got a hairpinned packet') good = False else: api.userlog.debug('As expected, h1 did not get a ping') good = True import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch(): h1 = NoPacketHost.create("h1") h2 = GetPacketHost.create("h2") s1 = sim.config.default_switch_type.create('s1') s2 = sim.config.default_switch_type.create('s2') h1.linkTo(s1) h2.linkTo(s2) def test_tasklet(): yield 5 api.userlog.debug('Linking s1 and s2') def test_cable(): c = cable.BasicCable() c.tx_time = 0 return c s1.linkTo(s2, cable=(test_cable(), test_cable())) yield 0.1 api.userlog.debug('Sending ping from h1 to h2') h1.ping(h2) yield 5 if h2.pings != 1: api.userlog.error("h2 got %s pings instead of 1", h2.pings) good = False else: api.userlog.debug('h2 successfully received the ping') good = True import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch(): h1 = GetPacketHost.create('h1') h2 = NoPacketHost.create('h2') h3 = NoPacketHost.create('h3') h4 = NoPacketHost.create('h4') h5 = NoPacketHost.create('h5') r1 = sim.config.default_switch_type.create('r1') r2 = sim.config.default_switch_type.create('r2') r3 = sim.config.default_switch_type.create('r3') r4 = sim.config.default_switch_type.create('r4') c1 = CountingHub.create('c1') c2 = CountingHub.create('c2') c3 = CountingHub.create('c3') c4 = CountingHub.create('c4') h1.linkTo(r1, latency=5) h1.linkTo(r2, latency=1) h1.linkTo(r3, latency=4) h1.linkTo(r4, latency=8) h2.linkTo(r4, latency=0) h3.linkTo(r3, latency=.5) h4.linkTo(r2, latency=0) h5.linkTo(r1, latency=0) r4.linkTo(c1, latency=2) c1.linkTo(r1, latency=2) r1.linkTo(c2, latency=2) c2.linkTo(r3, latency=2) r3.linkTo(c3, latency=1) c3.linkTo(r2, latency=1) r2.linkTo(c4, latency=7) c4.linkTo(r4, latency=7) def test_tasklet(): yield 20 api.userlog.debug('Sending pings') h2.ping(h1) h3.ping(h1) h4.ping(h1) h5.ping(h1) yield 15 good = True if c1.pings == 1 and c2.pings == 2 and c3.pings == 3 and c4.pings == 0 and h1.pings == 4: api.userlog.debug('The ping took the right path') else: api.userlog.error('Something strange happened to the ping') good = False api.userlog.debug('Disconnecting R2') r2.unlinkTo(h1) r2.unlinkTo(c4) r2.unlinkTo(c3) yield 20 api.userlog.debug('Sending pings') h2.ping(h1) h3.ping(h1) h5.ping(h1) yield 15 if c1.pings == 2 and c2.pings == 2 and c3.pings == 3 and c4.pings == 0 and h1.pings == 7: api.userlog.debug('The ping took the right path') else: api.userlog.error('Something strange happened to the ping') good = False import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch(): h1 = TestHost.create("h1") h2 = TestHost.create("h2") h3 = TestHost.create("h3") h4 = TestHost.create("h4") h5 = TestHost.create("h5") hosts = [h1, h2, h3, h4, h5] s1 = sim.config.default_switch_type.create("s1") s2 = sim.config.default_switch_type.create("s2") s3 = sim.config.default_switch_type.create("s3") s1.linkTo(h1) s1.linkTo(h3) s2.linkTo(s1) s2.linkTo(s3) s2.linkTo(h4) s3.linkTo(h5) s3.linkTo(h2) def test_tasklet(): yield 1 api.userlog.debug("Sending test pings") h2.ping(h1) yield 3 h2.ping(h4) yield 3 h1.ping(h2) yield 3 h1.ping(h3) yield 3 h5.ping(h4) yield 3 h3.ping(h5) yield 3 api.userlog.debug("Waiting for deliveries") yield 15 # Wait five seconds for deliveries api.userlog.debug("Counting Pings and Pongs") pings = sum([h.pings for h in hosts]) pongs = sum([h.pongs for h in hosts]) good = True if pings != 16: api.userlog.error("Got %s pings", pings) good = False if h2.pongs != 2 or h1.pongs != 2 or h5.pongs != 1 or h3.pongs != 1: api.userlog.error("A node didn't receive the proper amount of pongs") good = False if pongs != 6: api.userlog.error("Got %s pongs", pongs) good = False if good: api.userlog.debug("Test passed successfully!") # End the simulation and (if not running in interactive mode) exit. import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch(): h1 = basics.BasicHost.create("h1") h2 = basics.BasicHost.create("h2") h3 = basics.BasicHost.create("h3") c12 = CountingHub.create('c12') c13 = CountingHub.create('c13') c23 = CountingHub.create('c23') r1 = sim.config.default_switch_type.create("r1") r2 = sim.config.default_switch_type.create('r2') r3 = sim.config.default_switch_type.create('r3') r1.linkTo(h1, latency=1) r1.linkTo(c12, latency=1) c12.linkTo(r2, latency=2) r1.linkTo(c13, latency=5) c13.linkTo(r3, latency=5) r2.linkTo(c23, latency=2) c23.linkTo(r3, latency=2) r2.linkTo(h2, latency=2) r3.linkTo(h3, latency=1) def test_tasklet(): yield 20 api.userlog.debug('Sending ping from h1 to h3') h1.ping(h3) yield 10 if c13.pings == 0 and c12.pings == 1 and c23.pings == 1: api.userlog.debug('The ping took the right path') good = True else: api.userlog.error('The ping took the wrong path') good = False api.userlog.debug('Sending ping from h2 to h3') h2.ping(h3) yield 10 if c13.pings == 0 and c12.pings == 1 and c23.pings == 2: api.userlog.debug('The ping took the right path') good = good and True else: api.userlog.error('The ping took the wrong path') good = False api.userlog.debug('Link R1 - R2 goes down') r1.unlinkTo(c12) c12.unlinkTo(r2) yield 20 api.userlog.debug('Sending ping from h1 to h2') h1.ping(h2) yield 15 if c13.pings == 1 and c12.pings == 1 and c23.pings == 3: api.userlog.debug('The ping took the right path') good = good and True else: api.userlog.error('The ping took the wrong path') good = False import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch(): h_a = GetPacketHost.create('h_a') h_c = NoPacketHost.create('h_c') h_d = NoPacketHost.create('h_d') backup_interval = sim.config.default_switch_type.DEFAULT_TIMER_INTERVAL sim.config.default_switch_type.DEFAULT_TIMER_INTERVAL = 1 a = sim.config.default_switch_type.create('a') b = sim.config.default_switch_type.create('b') c = sim.config.default_switch_type.create('c') d = sim.config.default_switch_type.create('d') c_cb = CountingHub.create('c_cb') c_db = CountingHub.create('c_db') c_cd = CountingHub.create('c_cd') h_a.linkTo(a) h_c.linkTo(c) h_d.linkTo(d) a.linkTo(b) b.linkTo(c_cb) b.linkTo(c_db, latency = 1.5) c_cb.linkTo(c, latency = 0) c_db.linkTo(d, latency = 0) c.linkTo(c_cd) c_cd.linkTo(d, latency = 0) def test_tasklet(): yield 15 api.userlog.debug('Sending ping from h_c to h_a - it should get through') h_c.ping(h_a) yield 6 if h_a.pings != 1 or c_cb.pings != 1 or c_cd.pings != 0: api.userlog.error("The first ping didn't get through or followed wrong path") sys.exit(1) api.userlog.debug('Sending ping from h_d to h_a - it should get through') h_d.ping(h_a) yield 6 if h_a.pings != 2 or c_db.pings != 1 or c_cd.pings != 0: api.userlog.error("The second ping didn't get through or followed wrong path") sys.exit(1) api.userlog.debug('Disconnecting a and b') a.unlinkTo(b) api.userlog.debug('Waiting for routers to count to infinity') yield 75 api.userlog.debug( 'Sending ping from h_c to h_a - it should be dropped at c') h_c.ping(h_a) yield 5 if c_cb.pings != 1 or c_cd.pings != 0: api.userlog.error( 'c forwarded the ping when it should have dropped it') sys.exit(1) else: api.userlog.debug('c dropped the ping as expected') sys.exit(0) api.run_tasklet(test_tasklet) sim.config.default_switch_type.DEFAULT_TIMER_INTERVAL = backup_interval
def launch(): h1 = Host.create("h1") h2 = Host.create("h2") s1 = Router.create("s1") s2 = Router.create("s2") s3 = Router.create("s3") h1.linkTo(s1) h1.linkTo(s2) h2.linkTo(s1) h2.linkTo(s3) s2.linkTo(s3) def test_tasklet_1(): good = True yield 20 api.userlog.debug("Sending test pings") h1.ping(h2) h2.ping(h1) yield 10 if h1.pongs != 2 or h1.pings != 2: api.userlog.error("h1 got %s pings instead of 2", h1.pings) api.userlog.error("h1 got %s pongs instead of 2", h1.pongs) good = False if h2.pongs != 2 or h2.pings != 2: api.userlog.error("h2 got %s pings instead of 2", h2.pings) api.userlog.error("h2 got %s pongs instead of 2", h2.pongs) good = False good &= check_router(s1, h1, 1) good &= check_router(s1, h1, 1, False) good &= check_router(s1, h2, 1) good &= check_router(s1, h2, 1, False) good &= check_router(s2, h1, 1) good &= check_router(s2, h1, 1, False) good &= check_router(s2, h2, 1) good &= check_router(s2, h2, 1, False) good &= check_router(s3, h1, 1) good &= check_router(s3, h1, 1, False) good &= check_router(s3, h2, 1) good &= check_router(s3, h2, 1, False) s2.linkTo(s1) s2.unlinkTo(s3) s1.clean() s2.clean() yield 20 h1.ping(h2) h2.ping(h1) yield 10 if h1.pongs != 4 or h1.pings != 3: api.userlog.error("h1 got %s pings instead of 3", h1.pings) api.userlog.error("h1 got %s pongs instead of 3", h1.pongs) good = False if h2.pongs != 3 or h2.pings != 4: api.userlog.error("h2 got %s pings instead of 4", h2.pings) api.userlog.error("h2 got %s pongs instead of 3", h2.pongs) good = False good &= check_router(s1, h1, 2) good &= check_router(s1, h1, 1, False) good &= check_router(s1, h2, 1) good &= check_router(s1, h2, 2, False) good &= check_router(s2, h1, 1) good &= check_router(s2, h1, 0, False) good &= check_router(s2, h2, 0) good &= check_router(s2, h2, 0, False) import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet_1)
def launch(): h1 = NoPacketHost.create('h1') h2 = GetPacketHost.create('h2') h3 = GetPacketHost.create('h3') r1 = sim.config.default_switch_type.create('r1') r2 = sim.config.default_switch_type.create('r2') r3 = sim.config.default_switch_type.create('r3') r4 = sim.config.default_switch_type.create('r4') c1 = CountingHub.create('c1') c2 = CountingHub.create('c2') c3 = CountingHub.create('c3') c4 = CountingHub.create('c4') c5 = CountingHub.create('c5') c6 = CountingHub.create('c6') h1.linkTo(r1, latency=1) h1.linkTo(r2, latency=1) h1.linkTo(c6, latency=3) c6.linkTo(r3, latency=3) r1.linkTo(c1, latency=2) c1.linkTo(h2, latency=2) r2.linkTo(h2, latency=1) r2.linkTo(c2, latency=2) c2.linkTo(h3, latency=2) r2.linkTo(c4, latency=1) c4.linkTo(r3, latency=1) r3.linkTo(c3, latency=4) c3.linkTo(h3, latency=4) h2.linkTo(c5, latency=3) c5.linkTo(r4, latency=3) r4.linkTo(h3, latency=2) def test_tasklet(): yield 100 api.userlog.debug('Sending pings') h1.ping(h2) h1.ping(h3) h2.ping(h3) yield 50 if c1.pings == 2 and c2.pings == 3 and c3.pings == 0 and c4.pings == 2 and c5.pings == 1 and c6.pings == 2: api.userlog.debug('The ping took the right path') good = True else: api.userlog.error('Something strange happened to the ping') good = False api.userlog.debug('Disconnecting R2 to h2') r2.unlinkTo(h2) api.userlog.debug('Disconnecting R2 to h3') r2.unlinkTo(c2) c2.unlinkTo(h3) yield 25 print(r3.routing_table) api.userlog.debug('Sending pings') h1.ping(h2) h1.ping(h3) h2.ping(h3) yield 20 if c1.pings == 4 and c2.pings == 3 and c3.pings == 2 and c4.pings == 3 and c5.pings == 2 and c6.pings == 4: api.userlog.debug('The ping took the right path') good = True else: api.userlog.error('Something strange happened to the ping') good = False api.userlog.debug('Disconnecting h1 to R3') h1.unlinkTo(c6) c6.unlinkTo(r3) yield 20 api.userlog.debug('Sending pings') h1.ping(h3) yield 30 if c1.pings == 4 and c2.pings == 3 and c3.pings == 3 and c4.pings == 4 and c5.pings == 2 and c6.pings == 4: api.userlog.debug('The ping took the right path') good = True else: api.userlog.error('Something strange happened to the ping') good = False import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch(): h1 = GetPacketHost.create('h1') h2 = NoPacketHost.create('h2') rx = sim.config.default_switch_type.create('rx') ry = sim.config.default_switch_type.create('ry') r1 = sim.config.default_switch_type.create('r1') r2 = sim.config.default_switch_type.create('r2') r3 = sim.config.default_switch_type.create('r3') r4 = sim.config.default_switch_type.create('r4') c1 = SwitchableCountingHub.create('c1') r1.linkTo(c1, latency=1) r2.linkTo(c1, latency=1) c2 = SwitchableCountingHub.create('c2') r3.linkTo(c2, latency=1) r4.linkTo(c2, latency=1) h1.linkTo(rx, latency=0) h2.linkTo(ry, latency=0) rx.linkTo(r1, latency=2) rx.linkTo(r3, latency=1) ry.linkTo(r2, latency=4) c3 = SwitchableCountingHub.create('c3') r1.linkTo(c3, latency=16) r3.linkTo(c3, latency=16) c4 = SwitchableCountingHub.create('c4') r2.linkTo(c4, latency=16) r4.linkTo(c4, latency=16) hosts = [h1, h2] routers = [r1, r2, r3, r4] counting_hubs = [c1, c2, c3, c4] def test_tasklet(): yield 30 api.userlog.debug('Sending ping from h1 to h2 - it should get through') h1.ping(h2) yield 5 if c1.pings != 1: api.userlog.error("The first ping didn't get through") sys.exit(1) api.userlog.debug('Sending ping from h2 to h1 - it should get through') h2.ping(h1) yield 10 if c1.pings != 2: api.userlog.error("The second ping didn't get through") sys.exit(1) yield 10 api.userlog.debug('Silently connecting r2 and h2') ry.linkTo(r4, latency=2) yield 20 api.userlog.debug('Sending ping from h1 to h2 - it should get through') h1.ping(h2) yield 5 if c2.pings != 1: api.userlog.error("The first ping didn't get through") sys.exit(1) yield 10 api.userlog.debug('Sending ping from h2 to h1 - it should get through') h2.ping(h1) yield 5 if c2.pings != 2: api.userlog.error("The second ping didn't get through") sys.exit(1) yield 10 api.userlog.debug('Silently disconnecting r2') c2.unlinkTo(r4) c2.unlinkTo(r3) api.userlog.debug('Waiting for routes to time out') yield 22 api.userlog.debug( 'Sending ping from h1 to h2 - it should be sent through r1') h1.ping(h2) yield 5 if c1.pings != 3: api.userlog.error('r1 never received ping') sys.exit(1) else: api.userlog.debug('r1 rerouted the ping as expected') sys.exit(0) api.run_tasklet(test_tasklet)
def launch(): h1 = Host.create("h1") h2 = Host.create("h2") h3 = Host.create("h3") h4 = Host.create("h4") h5 = Host.create("h5") s1 = Router.create("s1") s2 = Router.create("s2") s3 = Router.create("s3") s4 = Router.create("s4") s5 = Router.create("s5") h1.linkTo(s5) s5.linkTo(s1) s5.linkTo(s2) s5.linkTo(s3) s5.linkTo(s4) h2.linkTo(s1) h3.linkTo(s2) h4.linkTo(s3) h5.linkTo(s4) s1.linkTo(s2) s2.linkTo(s3) s3.linkTo(s4) def check_ping_pong(host, pings, pongs): good = True if host.pings != pings: api.userlog.error("%s got %d pings instead of %d", str(host), host.pings, pings) good = False if host.pongs != pongs: api.userlog.error("%s got %d pongs instead of %d", str(host), host.pongs, pongs) good = False return good def check_router(router, host, num): if host not in router.packets: if num > 0: api.userlog.error("%s got %d packets from %s instead of %d", str(router), 0, str(host), num) return False else: return True if router.packets[host] != num: api.userlog.error("%s got %d packets from %s instead of %d", str(router), router.packets[host], str(host), num) return False return True def refresh(): for router in [s1, s2, s3, s4, s5]: router.packets = {} for host in [h1, h2, h3, h4, h5]: host.pings = 0 host.pongs = 0 def test_tasklet_1(): good = True yield 10 api.userlog.debug("Sending test pings") h2.ping(h1) h3.ping(h1) h4.ping(h1) h5.ping(h1) yield 10 good &= check_ping_pong(h2, 0, 1) good &= check_ping_pong(h3, 0, 1) good &= check_ping_pong(h4, 0, 1) good &= check_ping_pong(h5, 0, 1) good &= check_router(s4, h5, 1) good &= all([check_router(s4, host, 0) for host in [h4, h3, h2, h1]]) good &= check_router(s3, h4, 1) good &= all([check_router(s3, host, 0) for host in [h5, h3, h2, h1]]) good &= check_router(s2, h3, 1) good &= all([check_router(s2, host, 0) for host in [h5, h4, h2, h1]]) good &= check_router(s1, h2, 1) good &= all([check_router(s1, host, 0) for host in [h5, h3, h4, h1]]) good &= all([check_router(s5, host, 1) for host in [h5, h4, h3, h2]]) good &= check_router(s5, h1, 0) s1.unlinkTo(s5) yield 5 refresh() h2.ping(h1) h3.ping(h1) h4.ping(h1) h5.ping(h1) yield 10 good &= check_ping_pong(h2, 0, 1) good &= check_ping_pong(h3, 0, 1) good &= check_ping_pong(h4, 0, 1) good &= check_ping_pong(h5, 0, 1) good &= check_router(s4, h5, 1) good &= all([check_router(s4, host, 0) for host in [h4, h3, h2, h1]]) good &= check_router(s3, h4, 1) good &= all([check_router(s3, host, 0) for host in [h5, h3, h2, h1]]) good &= check_router(s2, h3, 1) good &= check_router(s2, h2, 1) good &= all([check_router(s2, host, 0) for host in [h5, h4, h1]]) good &= check_router(s1, h2, 1) good &= all([check_router(s1, host, 0) for host in [h5, h3, h4, h1]]) good &= all([check_router(s5, host, 1) for host in [h5, h4, h3, h2]]) good &= check_router(s5, h1, 0) s2.unlinkTo(s5) yield 10 refresh() h2.ping(h1) h3.ping(h1) h4.ping(h1) h5.ping(h1) yield 15 good &= check_ping_pong(h2, 0, 1) good &= check_ping_pong(h3, 0, 1) good &= check_ping_pong(h4, 0, 1) good &= check_ping_pong(h5, 0, 1) good &= check_router(s4, h5, 1) good &= all([check_router(s4, host, 0) for host in [h4, h3, h2, h1]]) good &= check_router(s3, h4, 1) good &= check_router(s3, h3, 1) good &= check_router(s3, h2, 1) good &= all([check_router(s3, host, 0) for host in [h5, h1]]) good &= check_router(s2, h3, 1) good &= check_router(s2, h2, 1) good &= all([check_router(s2, host, 0) for host in [h5, h4, h1]]) good &= check_router(s1, h2, 1) good &= all([check_router(s1, host, 0) for host in [h5, h3, h4, h1]]) good &= all([check_router(s5, host, 1) for host in [h5, h4, h3, h2]]) good &= check_router(s5, h1, 0) s3.unlinkTo(s5) yield 15 refresh() h2.ping(h1) h3.ping(h1) h4.ping(h1) h5.ping(h1) yield 15 good &= check_ping_pong(h2, 0, 1) good &= check_ping_pong(h3, 0, 1) good &= check_ping_pong(h4, 0, 1) good &= check_ping_pong(h5, 0, 1) good &= all([check_router(s4, host, 1) for host in [h4, h3, h2, h5]]) good &= check_router(s4, h1, 0) good &= all([check_router(s3, host, 1) for host in [h2, h3, h4]]) good &= check_router(s3, h5, 0) good &= check_router(s3, h1, 0) good &= check_router(s2, h3, 1) good &= check_router(s2, h2, 1) good &= all([check_router(s2, host, 0) for host in [h5, h4, h1]]) good &= check_router(s1, h2, 1) good &= all([check_router(s1, host, 0) for host in [h5, h3, h4, h1]]) good &= all([check_router(s5, host, 1) for host in [h5, h4, h3, h2]]) good &= check_router(s5, h1, 0) import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet_1)
def launch(seed=None): # Seed the RNG. rand = Random() if seed is not None: rand.seed(float(seed)) sim.config.default_switch_type.POISON_MODE = True # Make sure that each cable has a transmission time of zero. for c in all_cables: assert c.tx_time == 0, "BUG: cable {} has non-zero transmission time {}".format(c, c.tx_time) def comprehensive_test_tasklet(): """Comprehensive test.""" successes = 0 try: yield 0 g = nx.Graph() # Construct a graph for the current topology. for c in sorted(all_cables, key=lambda x: (x.src.entity.name, x.dst.entity.name)): assert c.src, "cable {} has no source".format(c) assert c.dst, "cable {} has no destination".format(c) g.add_node(c.src.entity.name, entity=c.src.entity) g.add_node(c.dst.entity.name, entity=c.dst.entity) g.add_edge(c.src.entity.name, c.dst.entity.name, latency=c.latency) initial_wait = 5 + nx.diameter(g) api.simlog.info("Waiting for at least %d seconds for initial routes to converge...", initial_wait) yield initial_wait * 1.1 for round in itertools.count(): api.simlog.info("=== Round %d ===", round+1) num_actions = rand.randint(1, 3) for i in range(num_actions): yield rand.random() * 2 # Wait 0 to 2 seconds. action, u, v = pick_action(g, rand) if action == "del": api.simlog.info("\tAction %d/%d: remove link %s -- %s" % (i+1, num_actions, u, v)) g.remove_edge(u, v) g.nodes[u]["entity"].unlinkTo(g.nodes[v]["entity"]) elif action == "add": api.simlog.info("\tAction %d/%d: add link %s -- %s" % (i+1, num_actions, u, v)) g.add_edge(u, v) g.nodes[u]["entity"].linkTo(g.nodes[v]["entity"]) else: assert False, "unknown action {}".format(action) # Wait for convergence. max_latency = nx.diameter(g) * 1.01 yield max_latency # Send pair-wise pings. assert nx.is_connected(g), "BUG: network partition" expected = defaultdict(dict) # dst -> src -> time deadline = defaultdict(dict) # dst -> src -> time lengths = dict(nx.shortest_path_length(g)) for s in sorted(all_hosts, key=lambda h: h.name): for d in sorted(all_hosts, key=lambda h: h.name): if s is d: continue s.ping(d, data=round) latency = lengths[s.name][d.name] deadline[d][s] = api.current_time() + latency expected[d][s] = api.current_time() + latency * 1.01 # Wait for ping to propagate. yield max_latency for dst in expected: rxed = dst.rxed_pings for src in set(expected[dst].keys()) | set(rxed.keys()): if src not in rxed: api.simlog.error("\tFAILED: Missing ping: %s -> %s", src, dst) return assert rxed[src] rx_packets = [packet for packet, _ in rxed[src]] if src not in expected[dst]: api.simlog.error("\tFAILED: Extraneous ping(s): %s -> %s %s", src, dst, rx_packets) return if len(rx_packets) > 1: api.simlog.error("\tFAILED: Duplicate ping(s): %s -> %s %s", src, dst, rx_packets) return rx_packet = rx_packets[0] assert isinstance(rx_packet, Ping) if rx_packet.data != round: api.simlog.error("\tFAILED: Ping NOT from current round %d: %s -> %s %s", round, src, dst, rx_packet) return _, actual_time = rxed[src][0] late = actual_time - expected[dst][src] if late > 0: api.simlog.error("\tFAILED: Ping late by %g sec: %s -> %s %s", actual_time - deadline[dst][src], src, dst, rx_packet) return dst.reset() api.simlog.info("\tSUCCESS!") successes += 1 except Exception as e: api.simlog.error("Exception occurred: %s" % e) traceback.print_exc() finally: sys.exit() api.run_tasklet(comprehensive_test_tasklet)
def launch(): h1 = NoPacketHost.create('h1') h2 = GetPacketHost.create('h2') h3 = GetPacketHost.create('h3') s1 = sim.config.default_switch_type.create('s1') s2 = sim.config.default_switch_type.create('s2') s3 = sim.config.default_switch_type.create('s3') s4 = sim.config.default_switch_type.create('s4') s5 = sim.config.default_switch_type.create('s5') s6 = sim.config.default_switch_type.create('s6') c1 = CountingHub.create('c1') c2 = CountingHub.create('c2') c3 = CountingHub.create('c3') c4 = CountingHub.create('c4') c5 = CountingHub.create('c5') h1.linkTo(s4, latency=1) h2.linkTo(s5, latency=1) h3.linkTo(s6, latency=1) s4.linkTo(c1, latency=1) s4.linkTo(c3, latency=1) c1.linkTo(s1, latency=1) c3.linkTo(s3, latency=10) s1.linkTo(s3, latency=8) s1.linkTo(c5, latency=1) c5.linkTo(s5, latency=1) s1.linkTo(c2, latency=1) s5.linkTo(s2, latency=1) c2.linkTo(s2, latency=1) s3.linkTo(s2, latency=8) s3.linkTo(c4, latency=10) c4.linkTo(s6, latency=10) s2.linkTo(s6, latency=1) def test_tasklet(): yield 20 api.userlog.debug('Sending ping from h1 to h2') h1.ping(h2) yield 5 if c1.pings == 1 and c2.pings == 0 and c3.pings == 0 and c4.pings == 0 and c5.pings == 1: api.userlog.debug('The ping took the right path') good = True elif not c1.pings == 1 or not c2.pings == 0 or not c3.pings == 0 or not c4.pings == 0 or not c5.pings == 1: api.userlog.error('The ping took the wrong path') good = False else: api.userlog.error('Something strange happened to the ping') good = False api.userlog.debug('Sending ping from h1 to h3') h1.ping(h3) yield 5 if c1.pings == 2 and c2.pings == 1 and c3.pings == 0 and c4.pings == 0 and c5.pings == 1: api.userlog.debug('The ping took the right path') good2 = True elif not c1.pings == 2 or not c2.pings == 1 or not c3.pings == 0 or not c4.pings == 0 or not c5.pings == 1: api.userlog.error('The ping took the wrong path') good2 = False else: api.userlog.error('Something strange happened to the ping') good2 = False import sys sys.exit(0 if good and good2 else 1) api.run_tasklet(test_tasklet)
def launch(): h1 = TestHost.create("h1") h2 = TestHost.create("h2") h3 = TestHost.create("h3") h4 = TestHost.create("h4") c1 = CountingHub.create('c1') c2 = CountingHub.create('c2') c3 = CountingHub.create('c3') c4 = CountingHub.create('c4') c1.linkTo(h1) c2.linkTo(h2) c3.linkTo(h3) c4.linkTo(h4) s1 = sim.config.default_switch_type.create("s1") s2 = sim.config.default_switch_type.create("s2") s3 = sim.config.default_switch_type.create("s3") s4 = sim.config.default_switch_type.create("s4") s5 = sim.config.default_switch_type.create("s5") s1.linkTo(c1) s2.linkTo(c2) s3.linkTo(c3) s4.linkTo(c4) s1.linkTo(s5) s2.linkTo(s5) s3.linkTo(s5) s4.linkTo(s5) def test_tasklet(): yield 1 api.userlog.debug("Sending test pings") h1.ping(h2) yield 10 h2.ping(h3) yield 10 h3.ping(h4) yield 10 h4.ping(h1) api.userlog.debug("Waiting for deliveries") yield 10 h2.ping(h3) yield 10 # Wait five seconds for deliveries h2.ping(h3) yield 10 h2.ping(h3) yield 10 good = True if c1.pings != 4 or c2.pings != 6 or c3.pings != 6 or c4.pings != 4: good = False # End the simulation and (if not running in interactive mode) exit. import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch(): h1 = NoPacketHost.create('h1') h2 = GetPacketHost.create('h2') s1 = sim.config.default_switch_type.create('s1') s2 = sim.config.default_switch_type.create('s2') s3 = sim.config.default_switch_type.create('s3') c2 = BlockingHub.create('c2') c3 = BlockingHub.create('c3') h1.linkTo(s1) s1.linkTo(c2) c2.linkTo(s2) s2.linkTo(h2) s1.linkTo(c3) c3.linkTo(s3) s3.linkTo(h2) def test_tasklet(): yield 15 api.userlog.debug('Sending ping from h1 to h2 - it should get through') h1.ping(h2) yield 5 if h2.pings != 1: api.userlog.error("The ping did not get through to h2") sys.exit(1) if c2.pings == 1: api.userlog.debug( 'Ping was sent through s2, dropping routing packets between s1-s2' ) c2.block_route_packets = True elif c3.pings == 1: api.userlog.debug( 'Ping was sent through s3, dropping routing packets between s1-s3' ) c3.block_route_packets = True else: api.userlog.error('Something wierd happened') yield sim.config.default_switch_type.ROUTE_TIMEOUT - 1 # '-1' since the link h1-s1 has latency 1 # if the test fails for you, try removing this '-1', not sure if it is nitpicking api.userlog.debug( 'Sending another ping from h1 to h2 - it should take the other path' ) h1.ping(h2) yield 5 if h2.pings != 2 or c2.pings != 1 or c3.pings != 1: api.userlog.error("The second ping did not take the correct path") sys.exit(1) api.userlog.debug("Paths expired and replaced correctly") sys.exit(0) api.run_tasklet(test_tasklet)
def launch (): h1 = GetPacketHost.create("h1") h2 = NoPacketHost.create("h2") h3 = NoPacketHost.create("h3") h4 = GetPacketHost.create("h4") h5 = GetPacketHost.create("h5") r0 = sim.config.default_switch_type.create("r0") r1 = sim.config.default_switch_type.create("r1") r2 = sim.config.default_switch_type.create("r2") r3 = sim.config.default_switch_type.create("r3") r4 = sim.config.default_switch_type.create("r4") r5 = sim.config.default_switch_type.create("r5") r0.linkTo(r1) r1.linkTo(r2) r2.linkTo(r3) r3.linkTo(r4) r4.linkTo(r5) r5.linkTo(r1) r1.linkTo(h1) r2.linkTo(h2) r3.linkTo(h3) r4.linkTo(h4) r5.linkTo(h5) def test_tasklet (): yield 5 # Wait five seconds for routing to converge api.userlog.debug("Sending test pings") yield 1 #r1.unlinkTo(r2) h2.ping(h4) h2.ping(h1) yield 1 # Wait a bit before sending last ping h3.ping(h1) yield 1 h4.ping(h5) yield 1 h1.ping(h4) yield 1 h2.ping(h4) yield 1 h3.ping(h4) yield 1 h4.ping(h4) yield 1 h5.ping(h4) yield 1 h1.ping(h4) yield 1 h2.ping(h4) yield 1 h3.ping(h4) yield 1 h4.ping(h4) yield 1 h5.ping(h4) yield 8 # Wait five seconds for pings to be delivered good = True if h1.pings != 2: api.userlog.error("h1 got %s packets instead of 2", h1.pings) good = False if h4.pings != 9: api.userlog.error("h4 got %s packets instead of 9", h4.pings) good = False if h5.pings != 1: api.userlog.error("h5 got %s packets instead of 1", h5.pings) good = False if NoPacketHost.bad_pings != 0: api.userlog.error("Got %s unexpected packets", NoPacketHost.bad_pings) good = False if good: api.userlog.debug("Test passed successfully!") # End the simulation and (if not running in interactive mode) exit. import sys sys.exit(0) api.run_tasklet(test_tasklet)
def launch(): h1 = GetPacketHost.create("h1") h2 = GetPacketHost.create("h2") h3 = GetPacketHost.create("h3") s1 = sim.config.default_switch_type.create('s1') s2 = sim.config.default_switch_type.create('s2') s3 = sim.config.default_switch_type.create('s3') s4 = sim.config.default_switch_type.create('s4') s5 = sim.config.default_switch_type.create('s5') s6 = sim.config.default_switch_type.create('s6') s7 = sim.config.default_switch_type.create('s7') s8 = sim.config.default_switch_type.create('s8') s1.linkTo(h1, latency=1) s1.linkTo(h2, latency=1) s2.linkTo(h3, latency=1) s1.linkTo(s4, latency=1) s1.linkTo(s3, latency=3) s4.linkTo(s5, latency=2) s5.linkTo(s6, latency=3) s6.linkTo(s2, latency=1) s3.linkTo(s7, latency=6) s7.linkTo(s8, latency=1) s8.linkTo(s2, latency=1) s5.linkTo(s7, latency=7) def test_tasklet(): t = 30 yield t # Wait for routing to converge api.userlog.debug("Sending test ping 1 (h1-h2)") h1.ping(h2) yield t api.userlog.debug("Sending test ping 2 (h1-h3)") h1.ping(h3) yield t api.userlog.debug("Failing s5-s6 link") s5.unlinkTo(s6) yield t api.userlog.debug("Sending test ping 3 (h1-h3)") h1.ping(h3) yield t api.userlog.debug("Failing s1-s3 link") s1.unlinkTo(s3) yield t api.userlog.debug("Sending test ping 4 (h1-h3)") h1.ping(h3) yield t if h3.pings != 3: api.userlog.error("h3 got %s packets instead of 3", h3.pings) good = False elif h2.pings != 1: api.userlog.error("h2 got %s packets instead of 1", h2.pings) good = False else: api.userlog.debug("Test passed successfully!") good = True # End the simulation and (if not running in interactive mode) exit. import sys sys.exit(0 if good else 1) api.run_tasklet(test_tasklet)
def launch (): h1 = GetPacketHost.create("h1") h2 = GetPacketHost.create("h2") h3 = GetPacketHost.create("h3") h4 = GetPacketHost.create("h4") s1 = sim.config.default_switch_type.create('s1') s2 = sim.config.default_switch_type.create('s2') s3 = sim.config.default_switch_type.create('s3') s4 = sim.config.default_switch_type.create('s4') s5 = sim.config.default_switch_type.create('s5') h1.linkTo(s1) h2.linkTo(s4) h3.linkTo(s3) h4.linkTo(s5) s1.linkTo(s2, latency =4) s1.linkTo(s3) s1.linkTo(s5) s4.linkTo(s3) s4.linkTo(s2) s4.linkTo(s5) s5.linkTo(s2) s3.linkTo(s2) def test_tasklet (): yield 5 # Wait five seconds for routing to converge api.userlog.debug("Sending test ping 1") h1.ping(h2) yield 5 h3.ping(h4) api.userlog.debug("Adding fast s1-s2 link ") #pdb.set_trace() #s1.unlinkTo(s2) s1.linkTo(s2) yield 10 h1.ping(h3) api.userlog.debug("Sending test ping 2") #t = TestPacket(dst=h2) #h1.send(t, flood=True) #pdb.set_trace() h1.ping(h2) yield 10 if h2.pings != 2: api.userlog.error("h2 got " + str(h2.basic_pings) + " basic pings") api.userlog.error("h2 got " + str(h2.test_packets) + " test packets") api.userlog.error("h2 got %s packets instead of 2", h2.pings) else: api.userlog.debug("Test passed successfully!") # End the simulation and (if not running in interactive mode) exit. import sys sys.exit(0) api.run_tasklet(test_tasklet)