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 = 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 = 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') 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 = 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') 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) def test_tasklet(): yield 15 api.userlog.debug('Sending ping from h2 to h1') h2.ping(h1) yield 5 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 0.1 api.userlog.debug('Sending ping from h2 to h1') h2.ping(h1) yield 15 if c1.pings == 1 and h1.pings == 2: api.userlog.debug('Good path!') good = True and good else: api.userlog.error('Wrong, fallback direct path not used!') 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 = 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 = 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(): h1 = GetPacketHost.create('h1') h2 = GetPacketHost.create('h2') c1 = CountingHub.create('c1') c2 = CountingHub.create('c2') 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, latency=1) s1.linkTo(c1, latency=6) c1.linkTo(s2, latency=6) s2.linkTo(h2, latency=5) s2.linkTo(c2, latency=1) c2.linkTo(s3, latency=1) s3.linkTo(h2, latency=1) h2.linkTo(s1, latency=10) def test_tasklet(): yield 40 api.userlog.debug('Sending ping from h1 to h2') h1.ping(h2) yield 20 if c1.pings == 1 and c2.pings == 1 and h2.pings == 1: api.userlog.debug('The ping took the right path') good = True else: api.userlog.error('Wrong initial path!') good = False s2.unlinkTo(c2) s3.unlinkTo(c2) yield 0.1 api.userlog.debug('Sending ping from h1 to h2') h1.ping(h2) yield 20 if c1.pings == 2 and c2.pings == 1 and h2.pings == 2: api.userlog.debug('The ping took the right path') good = True and good else: api.userlog.error('Wrong, fallback direct path not used!') good = False yield 60 api.userlog.debug('Sending ping from h1 to h2') h1.ping(h2) yield 20 if c1.pings == 2 and h2.pings == 3: api.userlog.debug('Good path!') good = True and good else: api.userlog.error('%s, %s, %s', str(c1.pings), str(c2.pings), str(h2.pings)) api.userlog.error('Paths not updated after fallback.') 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') 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)