# default=0.0, help="link packet loss probability") (opt, args) = parser.parse_args() if opt.rand == True: rg = RandomGraph(opt.numnodes) (NODES, LINKS) = rg.genGraph() else: # build the deterministic test network # A---B C---D # | | / | / | # E F---G---H # format: (name of node, x coord, y coord) NODES = (('A', 0, 0), ('B', 1, 0), ('C', 2, 0), ('D', 3, 0), ('E', 0, 1), ('F', 1, 1), ('G', 2, 1), ('H', 3, 1)) # format: (link start, link end) LINKS = (('A', 'B'), ('A', 'E'), ('B', 'F'), ('E', 'F'), ('C', 'D'), ('C', 'F'), ('C', 'G'), ('D', 'G'), ('D', 'H'), ('F', 'G'), ('G', 'H')) # setup graphical simulation interface if opt.gui == True: net = LSRouterNetwork(opt.simtime, NODES, LINKS, 0) sim = NetSim() sim.SetNetwork(net) sim.MainLoop() else: PS8_tests.verify_routes(LSRouterNetwork)
return PS8_ls.LSRouter(loc, address=address) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("-n", "--numnodes", type=int, default=12, help="number of nodes") parser.add_argument("-t", "--simtime", type=int, default=2000, help="simulation time") parser.add_argument("-r", "--rand", action="store_true", default=False, help="use randomly generated topology") parser.add_argument("-p", "--protocol", type=str, default="dv", choices=["dv", "ls"], help="routing protocol (dv or ls)") parser.add_argument("-s", "--tests", action="store_true", default=False, help="run tests") args = parser.parse_args() if args.tests: if args.protocol == "dv": PS8_tests.verify_routes(DVRouterNetwork) elif args.protocol == "ls": PS8_tests.verify_routes(LSRouterNetwork) else: if args.rand == True: print "Generating random graph" rg = RandomGraph(args.numnodes) (NODES, LINKS) = rg.genGraph() else: print "Using default graph" NODES =(('A',0,0), ('B',1,0), ('C',2,0), ('D',3,0), ('E',0,1), ('F',1,1), ('G',2,1), ('H',3,1)) LINKS = (('A','B'),('A','E'),('B','F'), ('C','D'),('C','F'),('C','G'), ('D','G'),('D','H'),('F','G'),('G','H'))
# add one really high cost link for l in net.links: if (l.end1.address == 'B' and l.end2.address == 'C'): l.cost = infinity - 2 print 'Testing a network path with very high cost' print 'A-----B--------------------------C-----D' print ' 1 self.INFINITY-2 1 ' net.reset() net.step(count=1000) routing_table = {} routing_table['A'] = {'B': ('B',), 'C': ('B',), 'D': (None,)} routing_table['B'] = {'A': ('A',), 'C': ('C',), 'D': ('C',)} routing_table['C'] = {'A': ('B',), 'B': ('B',), 'D': ('D',)} routing_table['D'] = {'A': (None,), 'B': ('C',), 'C': ('C',)} result = PS8_tests.verify_routing_table(net, routing_table) if result: print "Routing Tables: (format: src, (dst1, link1), (dst2, link2), ...)" print "\tA, (B,B), (C,B), (D,None)" print "\tB, (A,A), (C,C), (D,C)" print "\tC, (A,B), (B,B), (D,D)" print "\tD, (A,None), (B,C), (C,C)" print 'Route from A<-->D exists in topology but your protocol says it doesn\'t!' print 'Why did this happen? Give your answer in the pset.' else: print "Your code did not give the correct result on this test"
default=False, help="use randomly generated topology") parser.add_argument("-p", "--protocol", type=str, default="dv", choices=["dv", "ls"], help="routing protocol (dv or ls)") parser.add_argument("-s", "--tests", action="store_true", default=False, help="run tests") parser.add_argument("-v", "--verbose", action="store_true", default=False, help="verbose output") args = parser.parse_args() if args.tests: if args.protocol == "dv": PS8_tests.verify_routes(DVRouterNetwork, args.verbose) elif args.protocol == "ls": PS8_tests.verify_routes(LSRouterNetwork, args.verbose) else: print( "Without wx, GUI testing is unavailable. You can use the staff tests (with the -s option) or write your own in PS8.py." )