def run(args): topo = GridTopo(args.rows, args.cols) net = Mininet(topo, host=NdnHost, link=TCLink, controller=None) topo.assignIps(net) net.start() ndndumps = [] if not args.no_ndndump: print 'Start ndndump tracers.' ndndumps = [ NdnDump(link) for link in net.links ] for ndndump in ndndumps: ndndump.start() print 'Start forwarding.' fws = [ host.getFw() for host in net.hosts ] for fw in fws: fw.start() time.sleep(5) print 'Start routing.' routs = [ host.getRout() for host in net.hosts ] for rout in routs: rout.advertise('/%s' % rout.host.name) rout.start() convergeTime = Routing.waitForConverge(net) if convergeTime is False: print 'Routing is not converged.' net.stop() exit(1) print 'Routing is converged in %d seconds at %d.' % (convergeTime, time.time()) pingServers = [] pingClients = [] if not args.no_ping: print 'Start ping servers and clients.' for host in net.hosts: pingServer = NdnPingServer(host, '/%s' % host.name) pingServer.start() pingServers.append(pingServer) for otherHost in net.hosts: pingClient = NdnPing(host, '/%s' % otherHost.name) pingClient.start('/var/log/ndn/ndnping_%s.log' % otherHost.name) pingClients.append(pingClient) sched = scheduler(time.time, time.sleep) schedLinkFails(sched, net, args.linkFails) sched.enter(args.duration, 0, lambda:0, ()) sched.run() if not args.no_ping: print 'Stop ping clients.' for pingClient in pingClients: pingClient.stop() time.sleep(1) net.stop()
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))