for n_dst in nodes.keys(): (dst_mac, dst_input, dummy) = nodes[n_dst] # Use global options as a base link_options = copy.copy(options) link_options.noise_amplitude = 0 # Gather channel options from config file s = CFG_LINK_PREFIX + n_src + ":" + n_dst if config.has_option(s, "freq-offset"): link_options.freq_offset = config.getint(s, "freq-offset") if config.has_option(s, "timing-ratio"): link_options.timing_ratio = config.getint(s, "timing-ratio") # Construct software channel and connect the nodes tb.connect(src_mac, software_channel(link_options), (dst_input, inputidx[n_dst])) inputidx[n_dst] = inputidx[n_dst] + 1 # Construct flows: section names of form 'flow:[src]:[dst]' flow_srcs = [] for s in config.sections(): # Skip sections not describing flows if not s.startswith(CFG_FLOW_PREFIX): continue name = s[len(CFG_FLOW_PREFIX):] # Extract source and destination node names endpoints = name.split(":") if len(endpoints) != 2: raise SystemExit("Must specify exactly 2 flow endpoints") (src, dst) = (endpoints[0], endpoints[1])
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: pass