for s in config.sections(): # Skip sections not describing nodes if not s.startswith(CFG_NODE_PREFIX): continue name = s[len(CFG_NODE_PREFIX):] mac_options = copy.copy(options) # Assign unique MAC address mac_options.mac_address = node_addr node_addr += 1 # Allow custom transmit power per-node if config.has_option(s, "tx-amplitude"): mac_options.tx_amplitude = config.getint(s, "tx-amplitude") # Construct MAC object for the node mac = cs_mac(mac_options, True) # Construct block for adding all incoming signals. Block # is directly connected to node receiver input_add = gr.add_cc() tb.connect(input_add, mac) # Construct noise generator and add to input signals noise_voltage = mac_options.noise_amplitude if config.has_option(s, "noise-amplitude"): noise_voltage = config.getint(s, "noise-amplitude") noise_src = gr.noise_source_c(gr.GR_GAUSSIAN, noise_voltage, mac_options.noise_seed) tb.connect(noise_src, (input_add, 0)) # Add packet receiver thread mac_receiver = pkt_listener(mac_options, mac)
if __name__ == '__main__': # Initialize logging logging.basicConfig(format="%(asctime)-15s %(name)-30s %(message)s", level=logging.DEBUG) # Handle command-line options parser = OptionParser(option_class=eng_option, conflict_handler="resolve") expert_grp = parser.add_option_group("Expert") cs_mac.add_options(parser, expert_grp) usrp_rx.add_options(parser, expert_grp) usrp_tx.add_options(parser, expert_grp) pkt_listener.add_options(parser, expert_grp) (options, args) = parser.parse_args() # 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 to listen for packets pkt_thread = pkt_listener(options, mac) pkt_thread.start() # Let everything run tb.start() try: raw_input() except KeyboardInterrupt: pass # Cleanup tb.stop()
cs_mac.add_options(parser, expert_grp) tun_mac_wrapper.add_options(parser, expert_grp) software_channel.add_options(parser, expert_grp) (options, args) = parser.parse_args() # Override node addresses 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: