Exemple #1
0
	mac_rx_options = copy.copy(options)
	mac_rx_options.mac_address = 1
	mac_rx_options.ip_address = "10.0.0.1"
	mac_tx_options = copy.copy(options)
	mac_tx_options.mac_address = 2
	mac_tx_options.ip_address = "10.0.0.2"

	# Create 2 nodes and connect them via software channels
	tb = gr.top_block()
	mac_rx = cs_mac(mac_rx_options, True)
	mac_tx = cs_mac(mac_tx_options, True)
	tb.connect(mac_tx, software_channel(options), mac_rx)
	tb.connect(mac_rx, software_channel(options), mac_tx)

	# Spawn TUN wrappers
	tun_tx = tun_mac_wrapper(mac_tx_options, mac_tx)
	tun_rx = tun_mac_wrapper(mac_rx_options, mac_rx)
	tun_tx.start()
	tun_rx.start()

	# Let everything run
	tb.start()
	try:
		raw_input()
	except KeyboardInterrupt:
		pass

	# Cleanup
	tb.stop()
	mac_tx.stop()
	mac_rx.stop()
	cs_mac.add_options(parser, expert_grp)
	usrp_rx.add_options(parser, expert_grp)
	usrp_tx.add_options(parser, expert_grp)
	tun_mac_wrapper.add_options(parser, expert_grp)
	(options, args) = parser.parse_args()

	# Set MAC address that matches IP address
	options.mac_address = struct.unpack('!I',socket.inet_aton(options.ip_address))[0]

	# Create MAC and connect to USRP
	tb = gr.top_block()
	mac = cs_mac(options)
	tb.connect(usrp_rx(options), mac, usrp_tx(options))

	# Spawn thread
	tun_wrapper = tun_mac_wrapper(options, mac)
	tun_wrapper.start()

	# Let everything run
	tb.start()
	try:
		raw_input()
	except KeyboardInterrupt:
		pass

	# Cleanup
	tb.stop()
	mac.stop()
	tun_wrapper.stop()

	# Wait for completion