Example #1
0
def schedLinkFails(sched, net, linkFails):
    def fail(intf):
        intf.config(loss=100)
    def recover(intf):
        # loss=0 alone would be ignored, so we add bw=1000
        intf.config(bw=1000, loss=0)
    def do(t, h1, h2, act):
        print '%d %s %s-%s' % (t, act.func_name, h1.name, h2.name)
        connections = h1.connectionsTo(h2)
        for (intf1, intf2) in connections:
            act(intf1)
            act(intf2)

    for (x1, y1, x2, y2, t1, t2) in linkFails:
        h1 = net.get(GridTopo.makeHostName(x1, y1))
        h2 = net.get(GridTopo.makeHostName(x2, y2))
        sched.enter(t1, 0, do, (t1, h1, h2, fail))
        sched.enter(t2, 0, do, (t2, h1, h2, recover))