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(): 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 = 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 = 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') 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') 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(): 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(): 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(): 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") 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 = 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 = 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(): 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 = GetPacketHost.create('h1') h2 = NoPacketHost.create('h2') r1 = sim.config.default_switch_type.create('r1') r2 = sim.config.default_switch_type.create('r2') r3 = sim.config.default_switch_type.create('r3') c1 = SwitchableCountingHub.create('c1') r1.linkTo(c1, latency=10) r3.linkTo(c1, latency=10) c2 = SwitchableCountingHub.create('c2') r2.linkTo(c2, latency=1) r3.linkTo(c2, latency=1) h1.linkTo(r1, latency=1) r1.linkTo(r2, latency=1) h2.linkTo(r3, latency=1) hosts = [h1, h2] routers = [r1, r2, r3] counting_hubs = [c1, c2] def test_tasklet(): yield 20 api.userlog.debug('Sending ping from h1 to h2 - it should get through') h1.ping(h2) yield 5 if c1.pings != 0: api.userlog.error("The first ping should not pass through c1") sys.exit(1) if c2.pings != 1: api.userlog.error("The first ping didn't get through") sys.exit(1) yield 10 api.userlog.debug('Silently disconnecting r2 and h2') c2.unlinkTo(r2) c2.unlinkTo(r3) yield 25 api.userlog.debug('Sending ping from h1 to h2 - it should get through') h1.ping(h2) yield 15 if c1.pings != 1: api.userlog.error("The second ping didn't get through") sys.exit(1) if c2.pings > 1: api.userlog.error("The second ping should not pass through c2") 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') s4 = sim.config.default_switch_type.create('s4') c1 = CountingHub.create('c1') c2 = CountingHub.create('c2') c3 = CountingHub.create('c3') h1.linkTo(s1, latency=1) h2.linkTo(s2, latency=1) s1.linkTo(c1, latency=1) c1.linkTo(s2, latency=1) s1.linkTo(c2, latency=2) c2.linkTo(s3, latency=1) s1.linkTo(c3, latency=1) c3.linkTo(s4, latency=1) s2.linkTo(s3, latency=5) s4.linkTo(s3, latency=15) 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: 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: 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('Disconnecting s1 and c1') s1.unlinkTo(c1) yield 20 api.userlog.debug('Sending ping from h1 to h2') h1.ping(h2) yield 5 if c1.pings == 1 and c2.pings == 1 and c3.pings == 0 : api.userlog.debug('The ping took the right path') good2 = True elif not c1.pings == 1 or not c2.pings == 1 or not c3.pings == 0 : api.userlog.error('The ping took the wrong path') good2 = False else: api.userlog.error('Something strange happened to the ping') good2 = False api.userlog.debug('Connecting s2 to s4') s2.linkTo(s4, latency=2) yield 20 api.userlog.debug('Sending ping from h1 to h2') h1.ping(h2) yield 5 if c1.pings == 1 and c2.pings == 1 and c3.pings == 1 : api.userlog.debug('The ping took the right path') good3 = True elif not c1.pings == 1 or not c2.pings == 1 or not c3.pings == 1 : api.userlog.error('The ping took the wrong path') good3 = False else: api.userlog.error('Something strange happened to the ping') good3 = False import sys sys.exit(0 if good and good2 and good3 else 1) api.run_tasklet(test_tasklet)
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 = NoPacketHost.create('h1') h2 = GetPacketHost.create('h2') h3 = NoPacketHost.create('h3') h4 = GetPacketHost.create('h4') h10 = GetPacketHost.create('h10') 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') s9 = sim.config.default_switch_type.create('s9') s10 = sim.config.default_switch_type.create('s10') s11 = sim.config.default_switch_type.create('s11') s12 = sim.config.default_switch_type.create('s12') c13 = CountingHub.create('c1') h1.linkTo(s1) h3.linkTo(s3) h4.linkTo(s4) s1.linkTo(c1) c1.linkTo(s2) s2.linkTo(s3) s3.linkTo(h2) s2.linkTo(s4) s5.linkTo(s8) s6.linkTo(s8) s1.linkTo(s3) s4.linkTo(s9) s8.linkTo(s7) s5.linkTo(s7) s6.linkTo(s10) s1.linkTo(s11) s4.linkTo(s12) s8.linkTo(s10) s4.linkTo(s10) s10.linkTo(h10) 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 first ping didn't get through") sys.exit(1) api.userlog.debug('Disconnecting s2 and s3') s4.unlinkTo(h4) api.userlog.debug( 'Waiting for poison to propagate, but not long enough ' + 'for routes to time out') yield 15 api.userlog.debug( 'Sending ping from h1 to h2 - it should be dropped at s1') h1.ping(h4) yield 5 if c1.pings != 0: 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 = 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 = 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)