示例#1
0
def main (argv):

	# global variables
	global node

	#check for proper input
 	if len(sys.argv) != 3:
		PrintUsage()

    # good input, start program
	else:
		run = 1

  	# initialize node object in physical layer
  	node = Physical.InitializeTopology(sys.argv[1], sys.argv[2])

  	# wait for node to propagate
  	time.sleep(2)

	#start listen threads
	Link.start_listener(node)

	# begin loop
	while(run == 1):

		# clear screen
		os.system('clear')

		# print menu
		menu()

		# prompt for input
		message = raw_input("Enter your selection: ")

		# start new service
		if (message == '1'):
			P = raw_input("Enter the maximum number of connections this service point will accept: ")
			start_service(P)

		# stop service
		if (message == '2'):
			S = raw_input("Enter the Service ID of the node you wish to stop service with: ")
			stop_service(S)

		# list service points
		if (message == '3'):
			list_service_points()

		# connect to node x
		if (message == '4'):
			Y = raw_input("Enter the node you would like to connect to: ")
			S = raw_input("Enter the SID of the node: ")
			#connect(Y, S)
			thread.start_new_thread(connect, (Y,S))

		# close connection with node x
		if (message == '5'):
			C = raw_input("Enter the CID of the connection you would like to close: ")
			close(C)

		# download from node x
		if (message == '6'):
			C = raw_input("Enter the CID of the peer from whom you would like to download: ")
			F = raw_input("Enter the name of the file you would like to download: ")
			thread.start_new_thread(download, (C,F))

		# set garbler probability
		if (message == '7'):
			L = raw_input("Set the probability of packet loss (1-100): ")
			C = raw_input("Set the probability of packet corruption (1-100): ")
			set_garbler(L, C)

		# display next hop data
		if (message == '8'):
			route_table(node)

		# down link to node x
		if (message == '9'):
			N = raw_input("Enter the node with whom you would like to down a link: ")
			link_down(N)

		# up link to node x
		if (message == '10'):
			N = raw_input("Enter the node with whom you would like to up a link: ")
			link_up(N)

		# for testing, send simple text message
		if (message == "11"):
			dest_nid = raw_input("Enter NID of target: ")
			text = raw_input("Enter Text Message: ")
			string = {}
			string['code'] = '10'
			string['message'] = text
			data = json.dumps(string)
			Transport.l4_sendto(node, dest_nid, data)

		# for testing node at physical layer
		if (message == "12"):
			node.PrintStatus()

		# exit program
		if (message == '13') or (message == 'Exit') or (message == 'exit'):
			run = 0
示例#2
0
def main (argv):

	#check for proper input
 	if len(sys.argv) != 3:
		PrintUsage()

    # good input, start program
	else:
		run = 1

  	# initialize node object in physical layer
  	node = Physical.InitializeTopology(sys.argv[1], sys.argv[2])

	#start listen threads
	Link.start_listener(node)


	# begin loop
	while(run == 1):

		# clear screen
		os.system('clear')

		# prompt for input
		message = raw_input("Enter A Command, or 'menu' to see all options: ")

		# for testing node at physical layer
		if (message == "PrintStatus"):
			node.PrintStatus()

		# for testing, send simple text message
		if (message == "send message"):
			dest_nid = raw_input("Enter NID of target: ")
			data = raw_input("Enter Message: ")
			Transport.l4_sendto(node, dest_nid, data)

		# print menu to screen
		if (message == "MENU") or (message == "Menu") or (message == "menu"):
			menu()

		# start new service
		if (message == '1'):
			P = raw_input("Enter the maximum number of connections this service point will accept: ")
			start_service(P)

		# stop service
		if (message == '2'):
			S = raw_input("Enter the Service ID of the node you wish to stop service with: ")
			stop_service(S)

		# connect to node x
		if (message == '3'):
			Y = raw_input("Enter the node you would like to connect to: ")
			S = raw_input("Enter the SID of the node: ")
			W = raw_input("Enter a value between 1-5 to set the window for packets in flight")
			connect(Y, S, W)

		# close connection with node x
		if (message == '4'):
			C = raw_input("Enter the CID of the connection you would like to close: ")
			close(C)

		# download from node x
		if (message == '5'):
			C = raw_input("Enter the CID of the peer from whom you would like to download: ")
			F = raw_input("Enter the name of the file you would like to download")
			download(C, F)

		# set garbler probability
		if (message == '6'):
			L = raw_input("Set the probability of packet loss (1-100): ")
			C = raw_input("Set the probability of packet corruption (1-100): ")
			set_garbler(L, C)

		# display next hop data
		if (message == '7'):
			route_table(node)

		# down link to node x
		if (message == '8'):
			N = raw_input("Enter the node with whom you would like to down a link: ")
			link_down(node, N)

		# up link to node x
		if (message == '9'):
			N = raw_input("Enter the node with whom you would like to up a link: ")
			link_up(node, N)

		# exit program
		if (message == 'Exit') or (message == 'Exit') or (message == 'exit'):
			run = 0