def test_l2_recvfrom (self): #addr = '' #frame_queue = Queue.Queue() #external_address_queue = Queue.Queue() # To use receive from, we go like this: # frame, external_address = LinkLayer.l2 node = Node.Node(1, 'localhost', 5555) node.SetMTU(1500) node.AddLink((2, 'localhost', 1)) node.AddLink((3, 'localhost', 1)) client_address, client_socket = LinkLayer.InitializeSocket(node) #print(client_address, client_socket.getsockname()) some_frame = LinkLayer.Frame() some_frame.SetPayload('This is a payload.') #node.PrintContents() #some_frame.PrintContents() LinkLayer.l2_sendto(client_socket, 'localhost', some_frame, node) #frame_queue.put(result) #external_address_queue.put(addr) #thread_id = thread.start_new_thread(LinkLayer.l2_recvfrom, (client_socket, node)) #frame = frame_queue.get() #external_address = external_address_queue.get() frame, external_address = LinkLayer.l2_recvfrom(client_socket, node) frame.PrintContents() #LinkLayer.l2_sendto(client_socket, 'localhost', some_frame, node) client_socket.close() pass
def test_l2_recvfrom (self): node = Node.Node(1, 'localhost', 5556) node.SetMTU(1500) node.AddLink((2, 'localhost', 1)) node.AddLink((3, 'localhost', 1)) client_address, client_socket = LinkLayer.InitializeSocket(node) some_frame = LinkLayer.Frame() some_frame.SetPayload('This is a payload.') LinkLayer.l2_sendto(client_socket, 'localhost', some_frame, node) frame, external_address = LinkLayer.l2_recvfrom(client_socket, node) client_socket.close() pass
def test_communications (self): #node = Node.Node(1, 'localhost', 5555) node = Node.Node(1, 'localhost', 5555, [(2, 'localhost', 1), (3, 'u-03.ecc.unr.edu', 1)], 1500, 0) routing_table = RoutingProtocol.DVRP(node) # YOU NEED THE \r\n IN HERE. segment = 'This is a payload.\r\n' #node.SetMTU(1500) #node.AddLink((1, 'localhost', 1)) # A link to itself... #node.AddLink((2, 'localhost', 1)) #node.AddLink((3, 'localhost', 1)) client_address, client_socket = LinkLayer.InitializeSocket(node) what_was_sent = TransportLayer.l4_sendto(client_socket, 2, 5555, routing_table, segment, node) #print(what_was_sent) # Receive it. length_of_buffer, received_frame, datagram_to_pass, external_address, received_segment = \ LinkLayer.l2_recvfrom(client_socket, node) print(received_segment)
def test_communications (self): node = Node.Node(1, 'localhost', 5555) routing_table = RoutingProtocol.DVRP(node) # YOU NEED THE \r\n IN HERE. segment = 'This is a payload.\r\n' node.SetMTU(1500) node.AddLink((1, 'localhost', 1)) # A link to itself... node.AddLink((2, 'localhost', 1)) node.AddLink((3, 'localhost', 1)) client_address, client_socket = LinkLayer.InitializeSocket(node) what_was_sent = NetworkLayer.l3_sendto(client_socket, 2, 5555, routing_table, segment, node) #print(what_was_sent) # Receive it. length_of_buffer, received_frame, datagram_to_pass, external_address, received_segment = \ LinkLayer.l2_recvfrom(client_socket, node) print(received_segment) received_segment.PrintContents()
def test_communications (self): #node = Node.Node(1, 'localhost', 5555) #node.SetMTU(1500) #node.AddLink((2, 'localhost', 1)) #node.AddLink((3, 'localhost', 1)) node = Node.ConfigInitialNetworkTopology(sys.argv[3], int(sys.argv[1])) client_address, client_socket = LinkLayer.InitializeSocket(node) datagram = NetworkLayer.Datagram() datagram.SetMTU(node.GetMTU()) itc_script = open('itc_test.txt') a_list = itc_script.readlines() itc_script.close() for entry in a_list: temp = entry.split(' ') if sys.argv[1] == temp[0]: datagram.SetSourcePort(int(temp[2])) if sys.argv[2] in temp[0]: datagram.SetDestPort(int(temp[2])) # YOU MUST PUT THE \r\n IN HERE OR IT WILL NOT WORK. #datagram.SetPayload('This is a payload.\r\n') inputs = [client_socket, sys.stdin] #print(what_was_sent.PrintContents()) go=1 while(go is 1): #sys.stdout.write(str(node.GetNID()) + '> ') inputready,outputready,exceptready = select.select(inputs,[],[]) for s in inputready: if s == client_socket: length_of_buffer, received_frame, datagram_to_pass, external_address, received_segment = LinkLayer.l2_recvfrom(client_socket, node) # added node as a parameter 04-06-2010. print(datagram_to_pass.GetPayload()) # received_segment.PrintContents() elif s == sys.stdin: payload = list(sys.stdin.readline()) payload.remove('\n') payload.append('\r') payload.append('\n') payload = ''.join(payload) if 'exit' in payload: print('exiting...') go=0 datagram.SetPayload(payload) hn = NetworkLayer.ResolveNID(int(sys.argv[2]), node) what_was_sent = LinkLayer.l2_sendto(client_socket, hn, datagram, node) #print(length_of_buffer) #received_frame.PrintContents() #if received_frame.GetLength() > 0: # pass # We need to deal with Layer 3 send here. #datagram_to_pass.PrintContents() #print(external_address) client_socket.close()