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)
Ejemplo n.º 2
0
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 10  # Wait five seconds for routing to converge

        api.userlog.debug("Sending test ping 1")
        h1.ping(h2)

        yield 10

        api.userlog.debug("Failing s1-s2 link")
        s1.unlinkTo(s2)

        yield 10

        api.userlog.debug("Sending test ping 2")
        h1.ping(h2)

        yield 10

        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 = 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)