diff --git a/simulations/interference/.gitignore b/simulations/interference/.gitignore new file mode 100644 index 0000000..fbca225 --- /dev/null +++ b/simulations/interference/.gitignore @@ -0,0 +1 @@ +results/ diff --git a/simulations/interference/Makefile b/simulations/interference/Makefile new file mode 100644 index 0000000..dd843da --- /dev/null +++ b/simulations/interference/Makefile @@ -0,0 +1,25 @@ +SHELL=/bin/bash +MESSAGES=100 + +PCAPFILES=$(shell python -c 'import itertools; import numpy as np; print(" ".join(["results/sim_%d_%.1f_%s_.pcap" % x for x in itertools.product(range(20), np.arange(0,12,0.5), ["ofdm", "noise"])]))') + +all: pdr.pdf + +pdr.pdf: plot.py results/all.csv + python ./plot.py + +results/all.csv: $(PCAPFILES) + ./parse.sh + +%.pcap: sim.py + mkdir -p results + export GR_CONF_DEFAULT_MAX_MESSAGES=2000 + @echo $@ + $(eval REPETITION=$(shell python -c "print \"$@\".split(\"_\")[1]")) + $(eval SNR=$(shell python -c "print \"$@\".split(\"_\")[2]")) + $(eval INTERFERENCE=$(shell python -c "print \"$@\".split(\"_\")[3]")) + @echo REPETITION=$(REPETITION) + @echo SNR=$(SNR) + @echo INTERFERENCE=$(INTERFERENCE) + ./sim.py --repetition=$(REPETITION) --snr=$(SNR) --messages=$(MESSAGES) --interference=$(INTERFERENCE) + diff --git a/simulations/interference/parse.sh b/simulations/interference/parse.sh new file mode 100755 index 0000000..63e285e --- /dev/null +++ b/simulations/interference/parse.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +files=`ls results/*.pcap` +outfile=results/all.csv +rm -f ${outfile} + +echo "repetition;interference;snr;received" +echo "repetition;interference;snr;received" > ${outfile} + +for f in ${files} +do + repetition=`python -c "print \"${f}\".split(\"_\")[1]"` + snr=`python -c "print \"${f}\".split(\"_\")[2]"` + interference=`python -c "print \"${f}\".split(\"_\")[3]"` + echo "file ${f} repetition ${repetition} interference ${interference} snr ${snr}" + rcvd=`tshark -r ${f} -Y "wlan.sa == 23:23:23:23:23:23" | wc -l | tr -d " "` + echo "${repetition};${interference};${snr};${rcvd}" + echo "${repetition};${interference};${snr};${rcvd}" >> ${outfile} +done diff --git a/simulations/interference/pdr.pdf b/simulations/interference/pdr.pdf new file mode 100644 index 0000000..48dc5a5 Binary files /dev/null and b/simulations/interference/pdr.pdf differ diff --git a/simulations/interference/plot.py b/simulations/interference/plot.py new file mode 100644 index 0000000..fb70725 --- /dev/null +++ b/simulations/interference/plot.py @@ -0,0 +1,13 @@ +import numpy as np +import pandas as pd +import matplotlib as mpl +import matplotlib.pyplot as plt + +pdr = pd.read_csv('./results/all.csv', sep=';') + +a = pdr.groupby(['interference', 'snr']) + +b = a.agg({'received': np.mean}).reset_index() +c = b.pivot(index='snr', columns='interference', values='received') +c.plot() +plt.savefig('pdr.pdf') diff --git a/simulations/interference/sim.grc b/simulations/interference/sim.grc new file mode 100644 index 0000000..931e8b9 --- /dev/null +++ b/simulations/interference/sim.grc @@ -0,0 +1,2067 @@ + + + + Sat Feb 1 18:28:19 2014 + + options + + author + + + + window_size + 1280, 1024 + + + category + Custom + + + comment + + + + description + + + + _enabled + True + + + _coordinate + (7, 4) + + + _rotation + 0 + + + generate_options + no_gui + + + hier_block_src_path + .: + + + id + sim + + + max_nouts + 0 + + + qt_qss_theme + + + + realtime_scheduling + + + + run_command + {python} -u {filename} + + + run_options + run + + + run + True + + + sizing_mode + fixed + + + thread_safe_setters + 1 + + + title + + + + placement + (0,0) + + + + variable + + comment + + + + _enabled + True + + + _coordinate + (8, 244) + + + _rotation + 0 + + + id + filename + + + value + "results/sim_%d_%.1f_%s_.pcap" % (repetition, snr, interference) + + + + variable + + comment + + + + _enabled + True + + + _coordinate + (8, 85) + + + _rotation + 0 + + + id + out_buf_size + + + value + 960000 + + + + variable + + comment + + + + _enabled + True + + + _coordinate + (840, 4) + + + _rotation + 0 + + + id + sync_length + + + value + 320 + + + + variable + + comment + + + + _enabled + True + + + _coordinate + (944, 4) + + + _rotation + 0 + + + id + window_size + + + value + 48 + + + + analog_noise_source_x + + amp + 1 + + + alias + + + + comment + + + + affinity + + + + _enabled + 1 + + + _coordinate + (24, 820) + + + _rotation + 0 + + + id + analog_noise_source_x_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + noise_type + analog.GR_GAUSSIAN + + + type + complex + + + seed + repetition+12312 + + + + analog_noise_source_x + + amp + 1 + + + alias + + + + comment + + + + affinity + + + + _enabled + 1 + + + _coordinate + (1124, 808) + + + _rotation + 90 + + + id + analog_noise_source_x_0_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + noise_type + analog.GR_GAUSSIAN + + + type + complex + + + seed + repetition+1 + + + + blocks_add_xx + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (1048, 392) + + + _rotation + 90 + + + id + blocks_add_xx_0 + + + type + complex + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + num_inputs + 4 + + + vlen + 1 + + + + blocks_add_xx + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (184, 768) + + + _rotation + 0 + + + id + blocks_add_xx_1 + + + type + complex + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + num_inputs + 2 + + + vlen + 1 + + + + blocks_file_sink + + append + False + + + alias + + + + comment + + + + affinity + + + + _enabled + 1 + + + file + filename + + + _coordinate + (200, 252) + + + _rotation + 180 + + + id + blocks_file_sink_0 + + + type + byte + + + unbuffered + True + + + vlen + 1 + + + + blocks_multiply_const_vxx + + alias + + + + comment + + + + const + (10**(snr/10.0))**.5 + + + affinity + + + + _enabled + True + + + _coordinate + (696, 452) + + + _rotation + 0 + + + id + blocks_multiply_const_vxx_0 + + + type + complex + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + vlen + 1 + + + + blocks_multiply_const_vxx + + alias + + + + comment + + + + const + 1 if interference == "ofdm" else 0 + + + affinity + + + + _enabled + 1 + + + _coordinate + (1076, 496) + + + _rotation + 90 + + + id + blocks_multiply_const_vxx_1 + + + type + complex + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + vlen + 1 + + + + blocks_multiply_const_vxx + + alias + + + + comment + + + + const + 0.00001 + + + affinity + + + + _enabled + True + + + _coordinate + (1140, 648) + + + _rotation + 90 + + + id + blocks_multiply_const_vxx_1_0 + + + type + complex + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + vlen + 1 + + + + blocks_multiply_const_vxx + + alias + + + + comment + + + + const + 1 if interference == "noise" else 0 + + + affinity + + + + _enabled + 1 + + + _coordinate + (968, 836) + + + _rotation + 0 + + + id + blocks_multiply_const_vxx_1_1 + + + type + complex + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + vlen + 1 + + + + blocks_multiply_const_vxx + + alias + + + + comment + + + + const + 0 + + + affinity + + + + _enabled + True + + + _coordinate + (344, 564) + + + _rotation + 0 + + + id + blocks_multiply_const_vxx_2 + + + type + complex + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + vlen + 1 + + + + blocks_skiphead + + alias + + + + comment + + + + affinity + + + + _enabled + 1 + + + _coordinate + (872, 452) + + + _rotation + 0 + + + id + blocks_skiphead_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + num_items + 2400 + repetition * 4 + + + type + complex + + + vlen + 1 + + + + blocks_stream_to_tagged_stream + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (224, 828) + + + _rotation + 0 + + + id + blocks_stream_to_tagged_stream_0 + + + len_tag_key + "packet_len" + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + packet_len + ieee802_11.payload_to_samples(ieee802_11.mac_payload_to_payload(size), encoding) + + + type + complex + + + vlen + 1 + + + + parameter + + alias + + + + comment + + + + _enabled + 1 + + + _coordinate + (752, 4) + + + _rotation + 0 + + + id + encoding + + + label + + + + short_id + + + + hide + none + + + type + intx + + + value + 2 + + + + foo_packet_pad2 + + alias + + + + comment + + + + affinity + + + + debug + False + + + delay_sec + 0.001 + + + delay + False + + + _enabled + 1 + + + _coordinate + (480, 424) + + + _rotation + 0 + + + id + foo_packet_pad2_0 + + + maxoutbuf + 0 + + + minoutbuf + out_buf_size + + + pad_front + 4000 + + + pad_tail + 5000 + + + + foo_packet_pad2 + + alias + + + + comment + + + + affinity + + + + debug + False + + + delay_sec + 0.001 + + + delay + False + + + _enabled + 1 + + + _coordinate + (704, 648) + + + _rotation + 0 + + + id + foo_packet_pad2_0_0 + + + maxoutbuf + 0 + + + minoutbuf + out_buf_size + + + pad_front + 4000 + + + pad_tail + 5000 + + + + foo_packet_pad2 + + alias + + + + comment + + + + affinity + + + + debug + False + + + delay_sec + 0.001 + + + delay + False + + + _enabled + 1 + + + _coordinate + (472, 808) + + + _rotation + 0 + + + id + foo_packet_pad2_0_0_0 + + + maxoutbuf + 0 + + + minoutbuf + out_buf_size + + + pad_front + 4000 + + + pad_tail + 5000 + + + + foo_random_periodic_msg_source + + alias + + + + comment + + + + affinity + + + + debug + False + + + _enabled + True + + + _coordinate + (272, 112) + + + _rotation + 0 + + + id + foo_random_periodic_msg_source_0 + + + maxoutbuf + 0 + + + msg_len + ieee802_11.mac_payload_to_payload(size) + + + minoutbuf + 0 + + + num + messages + + + interval + interval + + + quit + True + + + seed + repetition+4242 + + + + foo_random_periodic_msg_source + + alias + + + + comment + + + + affinity + + + + debug + False + + + _enabled + 1 + + + _coordinate + (8, 616) + + + _rotation + 0 + + + id + foo_random_periodic_msg_source_0_0 + + + maxoutbuf + 0 + + + msg_len + ieee802_11.mac_payload_to_payload(size) + + + minoutbuf + 0 + + + num + messages + + + interval + interval + + + quit + True + + + seed + repetition+123 + + + + foo_wireshark_connector + + alias + + + + comment + + + + affinity + + + + debug + False + + + _enabled + 1 + + + _coordinate + (400, 260) + + + _rotation + 180 + + + id + foo_wireshark_connector_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + tech + 127 + + + + ieee802_11_mac + + bss_mac + [0xff, 0xff, 0xff, 0xff, 0xff, 0xff] + + + alias + + + + comment + + + + affinity + + + + dst_mac + [0x42, 0x42, 0x42, 0x42, 0x42, 0x42] + + + _enabled + True + + + _coordinate + (600, 148) + + + _rotation + 0 + + + id + ieee802_11_mac_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + src_mac + [0x23, 0x23, 0x23, 0x23, 0x23, 0x23] + + + + ieee802_11_mac + + bss_mac + [0x56, 0x56, 0x56, 0x56, 0x56, 0x56] + + + alias + + + + comment + + + + affinity + + + + dst_mac + [0x34, 0x34, 0x34, 0x34, 0x34, 0x34] + + + _enabled + 1 + + + _coordinate + (296, 652) + + + _rotation + 0 + + + id + ieee802_11_mac_0_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + src_mac + [0x12, 0x12, 0x12, 0x12, 0x12, 0x12] + + + + import + + alias + + + + comment + + + + _enabled + True + + + _coordinate + (8, 148) + + + _rotation + 0 + + + id + import_0 + + + import + import math + + + + import + + alias + + + + comment + + + + _enabled + True + + + _coordinate + (8, 196) + + + _rotation + 0 + + + id + import_0_0 + + + import + import random + + + + parameter + + alias + + + + comment + + + + _enabled + True + + + _coordinate + (472, 4) + + + _rotation + 0 + + + id + interference + + + label + + + + short_id + + + + hide + none + + + type + str + + + value + "ofdm" + + + + parameter + + alias + + + + comment + + + + _enabled + True + + + _coordinate + (576, 4) + + + _rotation + 0 + + + id + interval + + + label + + + + short_id + + + + hide + none + + + type + eng_float + + + value + 50 + + + + parameter + + alias + + + + comment + + + + _enabled + True + + + _coordinate + (384, 4) + + + _rotation + 0 + + + id + messages + + + label + + + + short_id + + + + hide + none + + + type + intx + + + value + 50 + + + + pfb_arb_resampler_xxx + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (856, 656) + + + _rotation + 0 + + + id + pfb_arb_resampler_xxx_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + nfilts + 32 + + + rrate + 1 + 15e-6 + + + samp_delay + 0 + + + atten + 100 + + + taps + + + + type + ccf + + + + pfb_arb_resampler_xxx + + alias + + + + comment + + + + affinity + + + + _enabled + 1 + + + _coordinate + (672, 816) + + + _rotation + 0 + + + id + pfb_arb_resampler_xxx_0_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + nfilts + 32 + + + rrate + 1 + 15e-6 + + + samp_delay + 0 + + + atten + 100 + + + taps + + + + type + ccf + + + + parameter + + alias + + + + comment + + + + _enabled + True + + + _coordinate + (208, 4) + + + _rotation + 0 + + + id + repetition + + + label + + + + short_id + + + + hide + none + + + type + intx + + + value + 23 + + + + parameter + + alias + + + + comment + + + + _enabled + True + + + _coordinate + (664, 4) + + + _rotation + 0 + + + id + size + + + label + + + + short_id + + + + hide + none + + + type + intx + + + value + 546 + + + + parameter + + alias + + + + comment + + + + _enabled + True + + + _coordinate + (296, 4) + + + _rotation + 0 + + + id + snr + + + label + + + + short_id + + + + hide + none + + + type + eng_float + + + value + 20 + + + + wifi_phy_hier + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (800, 272) + + + _rotation + 180 + + + id + wifi_phy_hier_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + bandwidth + 10e6 + + + chan_est + ieee802_11.LS + + + encoding + encoding + + + frequency + 5.89e9 + + + sensitivity + 0.56 + + + + wifi_phy_hier + + alias + + + + comment + + + + affinity + + + + _enabled + 1 + + + _coordinate + (520, 640) + + + _rotation + 0 + + + id + wifi_phy_hier_0_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + bandwidth + 10e6 + + + chan_est + ieee802_11.LS + + + encoding + encoding + + + frequency + 5.89e9 + + + sensitivity + 0.56 + + + + analog_noise_source_x_0 + blocks_add_xx_1 + 0 + 1 + + + analog_noise_source_x_0_0 + blocks_multiply_const_vxx_1_0 + 0 + 0 + + + blocks_add_xx_0 + wifi_phy_hier_0 + 0 + 0 + + + blocks_add_xx_1 + blocks_stream_to_tagged_stream_0 + 0 + 0 + + + blocks_multiply_const_vxx_0 + blocks_skiphead_0 + 0 + 0 + + + blocks_multiply_const_vxx_1 + blocks_add_xx_0 + 0 + 1 + + + blocks_multiply_const_vxx_1_0 + blocks_add_xx_0 + 0 + 3 + + + blocks_multiply_const_vxx_1_1 + blocks_add_xx_0 + 0 + 2 + + + blocks_multiply_const_vxx_2 + blocks_add_xx_1 + 0 + 0 + + + blocks_multiply_const_vxx_2 + wifi_phy_hier_0_0 + 0 + 0 + + + blocks_skiphead_0 + blocks_add_xx_0 + 0 + 0 + + + blocks_stream_to_tagged_stream_0 + foo_packet_pad2_0_0_0 + 0 + 0 + + + foo_packet_pad2_0 + blocks_multiply_const_vxx_0 + 0 + 0 + + + foo_packet_pad2_0_0 + pfb_arb_resampler_xxx_0 + 0 + 0 + + + foo_packet_pad2_0_0_0 + pfb_arb_resampler_xxx_0_0 + 0 + 0 + + + foo_random_periodic_msg_source_0 + ieee802_11_mac_0 + out + app in + + + foo_random_periodic_msg_source_0_0 + ieee802_11_mac_0_0 + out + app in + + + foo_wireshark_connector_0 + blocks_file_sink_0 + 0 + 0 + + + ieee802_11_mac_0 + wifi_phy_hier_0 + phy out + mac_in + + + ieee802_11_mac_0_0 + wifi_phy_hier_0_0 + phy out + mac_in + + + pfb_arb_resampler_xxx_0 + blocks_multiply_const_vxx_1 + 0 + 0 + + + pfb_arb_resampler_xxx_0_0 + blocks_multiply_const_vxx_1_1 + 0 + 0 + + + wifi_phy_hier_0 + foo_wireshark_connector_0 + mac_out + in + + + wifi_phy_hier_0 + blocks_multiply_const_vxx_2 + 0 + 0 + + + wifi_phy_hier_0 + foo_packet_pad2_0 + 0 + 0 + + + wifi_phy_hier_0_0 + foo_packet_pad2_0_0 + 0 + 0 + + diff --git a/simulations/interference/sim.py b/simulations/interference/sim.py new file mode 100755 index 0000000..37391b1 --- /dev/null +++ b/simulations/interference/sim.py @@ -0,0 +1,270 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- +################################################## +# GNU Radio Python Flow Graph +# Title: Sim +# Generated: Thu Oct 12 12:33:05 2017 +################################################## +import threading + + +import os +import sys +sys.path.append(os.environ.get('GRC_HIER_PATH', os.path.expanduser('~/.grc_gnuradio'))) + +from argparse import ArgumentParser +from gnuradio import analog +from gnuradio import blocks +from gnuradio import eng_notation +from gnuradio import gr +from gnuradio.eng_arg import eng_float, intx +from gnuradio.filter import firdes +from gnuradio.filter import pfb +from wifi_phy_hier import wifi_phy_hier # grc-generated hier_block +import foo +import ieee802_11 +import math +import pmt +import random + + +class sim(gr.top_block): + + def __init__(self, encoding=2, interference="ofdm", interval=50, messages=50, repetition=23, size=546, snr=20): + gr.top_block.__init__(self, "Sim") + + self._lock = threading.RLock() + + ################################################## + # Parameters + ################################################## + self.encoding = encoding + self.interference = interference + self.interval = interval + self.messages = messages + self.repetition = repetition + self.size = size + self.snr = snr + + ################################################## + # Variables + ################################################## + self.window_size = window_size = 48 + self.sync_length = sync_length = 320 + self.out_buf_size = out_buf_size = 960000 + self.filename = filename = "results/sim_%d_%.1f_%s_.pcap" % (repetition, snr, interference) + + ################################################## + # Blocks + ################################################## + self.wifi_phy_hier_0_0 = wifi_phy_hier( + bandwidth=10e6, + chan_est=ieee802_11.LS, + encoding=encoding, + frequency=5.89e9, + sensitivity=0.56, + ) + self.wifi_phy_hier_0 = wifi_phy_hier( + bandwidth=10e6, + chan_est=ieee802_11.LS, + encoding=encoding, + frequency=5.89e9, + sensitivity=0.56, + ) + self.pfb_arb_resampler_xxx_0_0 = pfb.arb_resampler_ccf( + 1 + 15e-6, + taps=None, + flt_size=32) + self.pfb_arb_resampler_xxx_0_0.declare_sample_delay(0) + + self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_ccf( + 1 + 15e-6, + taps=None, + flt_size=32) + self.pfb_arb_resampler_xxx_0.declare_sample_delay(0) + + self.ieee802_11_mac_0_0 = ieee802_11.mac(([0x12, 0x12, 0x12, 0x12, 0x12, 0x12]), ([0x34, 0x34, 0x34, 0x34, 0x34, 0x34]), ([0x56, 0x56, 0x56, 0x56, 0x56, 0x56])) + self.ieee802_11_mac_0 = ieee802_11.mac(([0x23, 0x23, 0x23, 0x23, 0x23, 0x23]), ([0x42, 0x42, 0x42, 0x42, 0x42, 0x42]), ([0xff, 0xff, 0xff, 0xff, 0xff, 0xff])) + self.foo_wireshark_connector_0 = foo.wireshark_connector(127, False) + self.foo_random_periodic_msg_source_0_0 = foo.random_periodic_msg_source(ieee802_11.mac_payload_to_payload(size), interval, messages, True, False, repetition+123) + self.foo_random_periodic_msg_source_0 = foo.random_periodic_msg_source(ieee802_11.mac_payload_to_payload(size), interval, messages, True, False, repetition+4242) + self.foo_packet_pad2_0_0_0 = foo.packet_pad2(False, False, 0.001, 4000, 5000) + (self.foo_packet_pad2_0_0_0).set_min_output_buffer(960000) + self.foo_packet_pad2_0_0 = foo.packet_pad2(False, False, 0.001, 4000, 5000) + (self.foo_packet_pad2_0_0).set_min_output_buffer(960000) + self.foo_packet_pad2_0 = foo.packet_pad2(False, False, 0.001, 4000, 5000) + (self.foo_packet_pad2_0).set_min_output_buffer(960000) + self.blocks_stream_to_tagged_stream_0 = blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, ieee802_11.payload_to_samples(ieee802_11.mac_payload_to_payload(size), encoding), "packet_len") + self.blocks_skiphead_0 = blocks.skiphead(gr.sizeof_gr_complex*1, 2400 + repetition * 4) + self.blocks_multiply_const_vxx_2 = blocks.multiply_const_vcc((0, )) + self.blocks_multiply_const_vxx_1_1 = blocks.multiply_const_vcc((1 if interference == "noise" else 0, )) + self.blocks_multiply_const_vxx_1_0 = blocks.multiply_const_vcc((0.00001, )) + self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vcc((1 if interference == "ofdm" else 0, )) + self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc(((10**(snr/10.0))**.5, )) + self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, filename, False) + self.blocks_file_sink_0.set_unbuffered(True) + self.blocks_add_xx_1 = blocks.add_vcc(1) + self.blocks_add_xx_0 = blocks.add_vcc(1) + self.analog_noise_source_x_0_0 = analog.noise_source_c(analog.GR_GAUSSIAN, 1, repetition+1) + self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, 1, repetition+12312) + + + + ################################################## + # Connections + ################################################## + self.msg_connect((self.foo_random_periodic_msg_source_0, 'out'), (self.ieee802_11_mac_0, 'app in')) + self.msg_connect((self.foo_random_periodic_msg_source_0_0, 'out'), (self.ieee802_11_mac_0_0, 'app in')) + self.msg_connect((self.ieee802_11_mac_0, 'phy out'), (self.wifi_phy_hier_0, 'mac_in')) + self.msg_connect((self.ieee802_11_mac_0_0, 'phy out'), (self.wifi_phy_hier_0_0, 'mac_in')) + self.msg_connect((self.wifi_phy_hier_0, 'mac_out'), (self.foo_wireshark_connector_0, 'in')) + self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_1, 1)) + self.connect((self.analog_noise_source_x_0_0, 0), (self.blocks_multiply_const_vxx_1_0, 0)) + self.connect((self.blocks_add_xx_0, 0), (self.wifi_phy_hier_0, 0)) + self.connect((self.blocks_add_xx_1, 0), (self.blocks_stream_to_tagged_stream_0, 0)) + self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_skiphead_0, 0)) + self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_add_xx_0, 1)) + self.connect((self.blocks_multiply_const_vxx_1_0, 0), (self.blocks_add_xx_0, 3)) + self.connect((self.blocks_multiply_const_vxx_1_1, 0), (self.blocks_add_xx_0, 2)) + self.connect((self.blocks_multiply_const_vxx_2, 0), (self.blocks_add_xx_1, 0)) + self.connect((self.blocks_multiply_const_vxx_2, 0), (self.wifi_phy_hier_0_0, 0)) + self.connect((self.blocks_skiphead_0, 0), (self.blocks_add_xx_0, 0)) + self.connect((self.blocks_stream_to_tagged_stream_0, 0), (self.foo_packet_pad2_0_0_0, 0)) + self.connect((self.foo_packet_pad2_0, 0), (self.blocks_multiply_const_vxx_0, 0)) + self.connect((self.foo_packet_pad2_0_0, 0), (self.pfb_arb_resampler_xxx_0, 0)) + self.connect((self.foo_packet_pad2_0_0_0, 0), (self.pfb_arb_resampler_xxx_0_0, 0)) + self.connect((self.foo_wireshark_connector_0, 0), (self.blocks_file_sink_0, 0)) + self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.blocks_multiply_const_vxx_1, 0)) + self.connect((self.pfb_arb_resampler_xxx_0_0, 0), (self.blocks_multiply_const_vxx_1_1, 0)) + self.connect((self.wifi_phy_hier_0, 0), (self.blocks_multiply_const_vxx_2, 0)) + self.connect((self.wifi_phy_hier_0, 0), (self.foo_packet_pad2_0, 0)) + self.connect((self.wifi_phy_hier_0_0, 0), (self.foo_packet_pad2_0_0, 0)) + + def get_encoding(self): + return self.encoding + + def set_encoding(self, encoding): + with self._lock: + self.encoding = encoding + self.wifi_phy_hier_0_0.set_encoding(self.encoding) + self.wifi_phy_hier_0.set_encoding(self.encoding) + self.blocks_stream_to_tagged_stream_0.set_packet_len(ieee802_11.payload_to_samples(ieee802_11.mac_payload_to_payload(self.size), self.encoding)) + self.blocks_stream_to_tagged_stream_0.set_packet_len_pmt(ieee802_11.payload_to_samples(ieee802_11.mac_payload_to_payload(self.size), self.encoding)) + + def get_interference(self): + return self.interference + + def set_interference(self, interference): + with self._lock: + self.interference = interference + self.set_filename("results/sim_%d_%.1f_%s_.pcap" % (self.repetition, self.snr, self.interference)) + self.blocks_multiply_const_vxx_1_1.set_k((1 if self.interference == "noise" else 0, )) + self.blocks_multiply_const_vxx_1.set_k((1 if self.interference == "ofdm" else 0, )) + + def get_interval(self): + return self.interval + + def set_interval(self, interval): + with self._lock: + self.interval = interval + + def get_messages(self): + return self.messages + + def set_messages(self, messages): + with self._lock: + self.messages = messages + + def get_repetition(self): + return self.repetition + + def set_repetition(self, repetition): + with self._lock: + self.repetition = repetition + self.set_filename("results/sim_%d_%.1f_%s_.pcap" % (self.repetition, self.snr, self.interference)) + + def get_size(self): + return self.size + + def set_size(self, size): + with self._lock: + self.size = size + self.blocks_stream_to_tagged_stream_0.set_packet_len(ieee802_11.payload_to_samples(ieee802_11.mac_payload_to_payload(self.size), self.encoding)) + self.blocks_stream_to_tagged_stream_0.set_packet_len_pmt(ieee802_11.payload_to_samples(ieee802_11.mac_payload_to_payload(self.size), self.encoding)) + + def get_snr(self): + return self.snr + + def set_snr(self, snr): + with self._lock: + self.snr = snr + self.set_filename("results/sim_%d_%.1f_%s_.pcap" % (self.repetition, self.snr, self.interference)) + self.blocks_multiply_const_vxx_0.set_k(((10**(self.snr/10.0))**.5, )) + + def get_window_size(self): + return self.window_size + + def set_window_size(self, window_size): + with self._lock: + self.window_size = window_size + + def get_sync_length(self): + return self.sync_length + + def set_sync_length(self, sync_length): + with self._lock: + self.sync_length = sync_length + + def get_out_buf_size(self): + return self.out_buf_size + + def set_out_buf_size(self, out_buf_size): + with self._lock: + self.out_buf_size = out_buf_size + + def get_filename(self): + return self.filename + + def set_filename(self, filename): + with self._lock: + self.filename = filename + self.blocks_file_sink_0.open(self.filename) + + +def argument_parser(): + parser = ArgumentParser() + parser.add_argument( + "--encoding", dest="encoding", type=intx, default=2, + help="Set encoding [default=%(default)r]") + parser.add_argument( + "--interference", dest="interference", type=str, default="ofdm", + help="Set interference [default=%(default)r]") + parser.add_argument( + "--interval", dest="interval", type=eng_float, default=eng_notation.num_to_str(50), + help="Set interval [default=%(default)r]") + parser.add_argument( + "--messages", dest="messages", type=intx, default=50, + help="Set messages [default=%(default)r]") + parser.add_argument( + "--repetition", dest="repetition", type=intx, default=23, + help="Set repetition [default=%(default)r]") + parser.add_argument( + "--size", dest="size", type=intx, default=546, + help="Set size [default=%(default)r]") + parser.add_argument( + "--snr", dest="snr", type=eng_float, default=eng_notation.num_to_str(20), + help="Set snr [default=%(default)r]") + return parser + + +def main(top_block_cls=sim, options=None): + if options is None: + options = argument_parser().parse_args() + + tb = top_block_cls(encoding=options.encoding, interference=options.interference, interval=options.interval, messages=options.messages, repetition=options.repetition, size=options.size, snr=options.snr) + tb.start() + tb.wait() + + +if __name__ == '__main__': + main()