client = network.Host(1) object_L.append(client) server = network.Host(2) object_L.append(server) router_a = network.Router(name='A', intf_count=1, max_queue_size=router_queue_size) object_L.append(router_a) # create a Link Layer to keep track of links between network nodes link_layer = link.LinkLayer() object_L.append(link_layer) # add all the links # link parameters: from_node, from_intf_num, to_node, to_intf_num, mtu link_layer.add_link(link.Link(client, 0, router_a, 0, 50)) link_layer.add_link(link.Link(router_a, 0, server, 0, 50)) # start all the objects thread_L = [ threading.Thread(name=object.__str__(), target=object.run) for object in object_L ] for t in thread_L: t.start() try: #client.udt_send(2, "DATA") #sleep(0.1) #client.udt_send(2, "We the People of the United States, in Order to form a more perfect...") client.udt_send(
cost_D=cost_D, max_queue_size=router_queue_size) object_L.append(router_a) cost_D = {'H2': {1: 3}, 'RA': {0: 1}} # {neighbor: {interface: cost}} router_b = network.Router(name='RB', cost_D=cost_D, max_queue_size=router_queue_size) object_L.append(router_b) # create a Link Layer to keep track of links between network nodes link_layer = link.LinkLayer() object_L.append(link_layer) # add all the links - need to reflect the connectivity in cost_D tables above link_layer.add_link(link.Link(host_1, 0, router_a, 0)) link_layer.add_link(link.Link(router_a, 1, router_b, 0)) link_layer.add_link(link.Link(router_b, 1, host_2, 0)) # start all the objects thread_L = [] for obj in object_L: thread_L.append(threading.Thread(name=obj.__str__(), target=obj.run)) for t in thread_L: t.start() # compute routing tables router_a.send_routes(1) # one update starts the routing process sleep(simulation_time) # let the tables converge print("Converged routing tables")
client = network_1.Host(1) #client has address 1 object_L.append(client) server = network_1.Host(2) #server has address 2 object_L.append(server) router_a = network_1.Router(name='A', intf_count=1, max_queue_size=router_queue_size) object_L.append(router_a) #create a Link Layer to keep track of links between network nodes link_layer = link_1.LinkLayer() object_L.append(link_layer) #add all the links #client is output, router_a is input, 50 is largest size a packet can be to be transferred over a link link_layer.add_link(link_1.Link(client, 0, router_a, 0, 50)) link_layer.add_link(link_1.Link(router_a, 0, server, 0, 50)) #for part 2, change mtu to 30 #start all the objects thread_L = [] thread_L.append(threading.Thread(name=client.__str__(), target=client.run)) thread_L.append(threading.Thread(name=server.__str__(), target=server.run)) thread_L.append( threading.Thread(name=router_a.__str__(), target=router_a.run)) thread_L.append(threading.Thread(name="Network", target=link_layer.run)) for t in thread_L: t.start()
1: 3 } } # packet to host 2 through interface 1 for cost 3 router_b = network_1.Router(name='B', intf_cost_L=[1, 3], intf_capacity_L=[500, 100], rt_tbl_D=router_b_rt_tbl_D, max_queue_size=router_queue_size) object_L.append(router_b) #create a Link Layer to keep track of links between network nodes link_layer = link_1.LinkLayer() object_L.append(link_layer) #add all the links link_layer.add_link(link_1.Link(client, 0, router_a, 0)) link_layer.add_link(link_1.Link(router_a, 1, router_b, 0)) link_layer.add_link(link_1.Link(router_b, 1, server, 0)) #start all the objects thread_L = [] for obj in object_L: thread_L.append(threading.Thread(name=obj.__str__(), target=obj.run)) for t in thread_L: t.start() router_a.send_routes(1) #create some send events for i in range(5):
server = network_1.Host(2) object_L.append(server) router_a = network_1.Router(name='A', intf_count=1, max_queue_size=router_queue_size) object_L.append(router_a) #create a Link Layer to keep track of links between network nodes link_layer = link_1.LinkLayer() object_L.append(link_layer) #add all the links #link parameters: from_node, from_intf_num, to_node, to_intf_num, mtu/mtu_length # Link between client and a router link_layer.add_link(link_1.Link(client, 0, router_a, 0, mtu_length)) # Link between router and a client link_layer.add_link(link_1.Link(router_a, 0, server, 0, mtu_length)) #start all the objects thread_L = [] thread_L.append(threading.Thread(name=client.__str__(), target=client.run)) thread_L.append(threading.Thread(name=server.__str__(), target=server.run)) thread_L.append( threading.Thread(name=router_a.__str__(), target=router_a.run)) thread_L.append(threading.Thread(name="Network", target=link_layer.run)) for t in thread_L: t.start()
} } # packet to host 1 through interface 0 for cost 1 # router_d_rt_tbl_D = {1:{0:7,1:5},2:{0:7,1:5},3:{2:1}} router_d = network.Router(name='D', intf_cost_L=[1, 1, 1], intf_capacity_L=[500, 300, 20], rt_tbl_D=router_d_rt_tbl_D, max_queue_size=router_queue_size) object_L.append(router_d) #create a Link Layer to keep track of links between network nodes link_layer = link.LinkLayer() object_L.append(link_layer) #add all the links link_layer.add_link(link.Link(h1, 0, router_a, 0)) link_layer.add_link(link.Link(h2, 0, router_a, 1)) link_layer.add_link(link.Link(router_a, 2, router_b, 0)) link_layer.add_link(link.Link(router_a, 3, router_c, 0)) link_layer.add_link(link.Link(router_b, 1, router_d, 0)) link_layer.add_link(link.Link(router_c, 1, router_d, 1)) link_layer.add_link(link.Link(router_d, 2, h3, 0)) # #add all the links # link_layer.add_link(link.Link(h1, 0, router_a, 0)) # # link_layer.add_link(link.Link(h2, 0, router_a, 1)) # link_layer.add_link(link.Link(router_a, 1, router_b, 0))