def test_003_connect (self):
     """ Connect carrier_allocator to ofdm_serializer,
         make sure output==input """
     fft_len = 8
     n_syms = 10
     occupied_carriers = ((1, 2, 6, 7),)
     pilot_carriers = ((3,),(5,))
     pilot_symbols = ((1j,),(-1j,))
     tx_data = tuple([numpy.random.randint(0, 10) for x in range(4 * n_syms)])
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(tx_data))
     src = gr.vector_source_c(tx_data, False, 1, (tag,))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols,
                    tag_name)
     serializer = digital.ofdm_serializer_vcc(alloc)
     sink = gr.vector_sink_c()
     self.tb.connect(src, alloc, serializer, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), tx_data)
 def test_002_t (self):
     """
     same, but using negative carrier indices
     """
     fft_len = 6
     tx_symbols = (1, 2, 3)
     pilot_symbols = ((1j,),)
     occupied_carriers = ((-1, 1, 2),)
     pilot_carriers = ((3,),)
     expected_result = (1j, 0, 1, 0, 2, 3)
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(tx_symbols))
     src = blocks.vector_source_c(tx_symbols, False, 1, (tag,))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols, (),
                    tag_name)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, alloc, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
 def test_001_t2 (self):
     """
     pretty simple (same as before, but odd fft len)
     """
     fft_len = 5
     tx_symbols = (1, 2, 3)
     #             ^ this gets mapped to the DC carrier because occupied_carriers[0][0] == 0
     occupied_carriers = ((0, 1, 2),)
     pilot_carriers = ((-2,),)
     pilot_symbols = ((1j,),)
     expected_result = (1j, 0, 1, 2, 3)
     #                         ^ DC carrier
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(tx_symbols))
     src = blocks.vector_source_c(tx_symbols, False, 1, (tag,))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols, (),
                    tag_name)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, alloc, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
 def test_001_t (self):
     """
     pretty simple (the carrier allocation is not a practical OFDM configuration!)
     """
     fft_len = 6
     tx_symbols = (1, 2, 3)
     #             ^ this gets mapped to the DC carrier because occupied_carriers[0][0] == 0
     pilot_symbols = ((1j,),)
     occupied_carriers = ((0, 1, 2),)
     pilot_carriers = ((3,),)
     sync_word = (range(fft_len),)
     expected_result = tuple(sync_word[0] + [1j, 0, 0, 1, 2, 3])
     #                                                 ^ DC carrier
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(tx_symbols))
     src = blocks.vector_source_c(tx_symbols, False, 1, (tag,))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols, sync_word,
                    tag_name)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, alloc, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
 def test_001_t (self):
     """
     pretty simple
     """
     fft_len = 6
     tx_symbols = (1, 2, 3)
     pilot_symbols = ((1j,),)
     occupied_carriers = ((0, 1, 2),)
     pilot_carriers = ((3,),)
     expected_result = (1, 2, 3, 1j, 0, 0)
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(tx_symbols))
     src = gr.vector_source_c(tx_symbols, False, 1, (tag,))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols,
                    tag_name)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, alloc, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
 def test_004_connect (self):
     """
     Advanced test:
     - Allocator -> IFFT -> Frequency offset -> FFT -> Serializer
     - FFT does shift (moves DC to middle)
     - Make sure input == output
     - Frequency offset is -2 carriers
     """
     fft_len = 8
     n_syms = 1
     carr_offset = -2
     freq_offset = 1.0 / fft_len * carr_offset # Normalized frequency
     occupied_carriers = ((-2, -1, 1, 2),)
     pilot_carriers = ((-3,),(3,))
     pilot_symbols = ((1j,),(-1j,))
     tx_data = (1, 2, 3, 4)
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(tx_data))
     offsettag = gr.tag_t()
     offsettag.offset = 0
     offsettag.key = pmt.string_to_symbol("ofdm_sync_carr_offset")
     offsettag.value = pmt.from_long(carr_offset)
     src = blocks.vector_source_c(tx_data, False, 1, (tag, offsettag))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols, (),
                    tag_name)
     tx_ifft = fft.fft_vcc(fft_len, False, (1.0/fft_len,)*fft_len, True)
     oscillator = analog.sig_source_c(1.0, analog.GR_COS_WAVE, freq_offset, 1.0/fft_len)
     mixer = blocks.multiply_cc()
     rx_fft  = fft.fft_vcc(fft_len, True, (), True)
     sink2 = blocks.vector_sink_c(fft_len)
     self.tb.connect(rx_fft, sink2)
     serializer = digital.ofdm_serializer_vcc(
             alloc, "", 0, "ofdm_sync_carr_offset", True
     )
     sink = blocks.vector_sink_c()
     self.tb.connect(
             src, alloc, tx_ifft,
             blocks.vector_to_stream(gr.sizeof_gr_complex, fft_len),
             (mixer, 0),
             blocks.stream_to_vector(gr.sizeof_gr_complex, fft_len),
             rx_fft, serializer, sink
     )
     self.tb.connect(oscillator, (mixer, 1))
     self.tb.run ()
     self.assertComplexTuplesAlmostEqual(sink.data()[-len(occupied_carriers[0]):], tx_data, places=4)
 def test_004_connect (self):
     """
     Advanced test:
     - Allocator -> IFFT -> Frequency offset -> FFT -> Serializer
     - FFT does shift (moves DC to middle)
     - Make sure input == output
     - Frequency offset is -2 carriers
     """
     fft_len = 8
     n_syms = 2
     carr_offset = -2
     freq_offset = 2 * numpy.pi * carr_offset / fft_len # If the sampling rate == 1
     occupied_carriers = ((1, 2, -2, -1),)
     pilot_carriers = ((3,),(5,))
     pilot_symbols = ((1j,),(-1j,))
     tx_data = tuple([numpy.random.randint(0, 10) for x in range(4 * n_syms)])
     #tx_data = (1,) * occupied_carriers[0] * n_syms
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(tx_data))
     offsettag = gr.gr_tag_t()
     offsettag.offset = 0
     offsettag.key = pmt.pmt_string_to_symbol("ofdm_sync_carr_offset")
     offsettag.value = pmt.pmt_from_long(carr_offset)
     src = gr.vector_source_c(tx_data, False, 1, (tag, offsettag))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols,
                    tag_name)
     tx_ifft = fft.fft_vcc(fft_len, False, ())
     offset_sig = gr.sig_source_c(1.0, gr.GR_COS_WAVE, freq_offset, 1.0)
     mixer = gr.multiply_cc()
     rx_fft  = fft.fft_vcc(fft_len, True, (), True)
     serializer = digital.ofdm_serializer_vcc(alloc)
     sink = gr.vector_sink_c()
     self.tb.connect(
             src, alloc, tx_ifft,
             gr.vector_to_stream(gr.sizeof_gr_complex, fft_len),
             (mixer, 0),
             gr.stream_to_vector(gr.sizeof_gr_complex, fft_len),
             rx_fft, serializer, sink
     )
     self.tb.connect(offset_sig, (mixer, 1))
     self.tb.run ()
 def test_003_connect (self):
     """ Connect carrier_allocator to ofdm_serializer,
         make sure output==input """
     fft_len = 8
     n_syms = 1
     occupied_carriers = ((1, 2, 6, 7),)
     pilot_carriers = ((3,),(5,))
     pilot_symbols = ((1j,),(-1j,))
     #tx_data = tuple([numpy.random.randint(0, 10) for x in range(4 * n_syms)])
     tx_data = (1, 2, 3, 4)
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(tx_data))
     src = blocks.vector_source_c(tx_data, False, 1, (tag,))
     alloc = digital.ofdm_carrier_allocator_cvc(
             fft_len,
             occupied_carriers,
             pilot_carriers,
             pilot_symbols,
             (), # No sync word
             tag_name,
             True # Output is shifted (default)
     )
     serializer = digital.ofdm_serializer_vcc(
             alloc,
             "", # Len tag key
             0, # Symbols skipped
             "", # Carrier offset key
             True # Input is shifted (default)
     )
     sink = blocks.vector_sink_c()
     self.tb.connect(src, alloc, serializer, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), tx_data)
Example #9
0
 def __init__(self, fft_len=_def_fft_len, cp_len=_def_cp_len,
              packet_length_tag_key=_def_packet_length_tag_key,
              occupied_carriers=_def_occupied_carriers,
              pilot_carriers=_def_pilot_carriers,
              pilot_symbols=_def_pilot_symbols,
              bps_header=1,
              bps_payload=1,
              sync_word1=None,
              sync_word2=None,
              rolloff=0,
              debug_log=False,
              scramble_bits=False
              ):
     gr.hier_block2.__init__(self, "ofdm_tx",
                 gr.io_signature(1, 1, gr.sizeof_char),
                 gr.io_signature(1, 1, gr.sizeof_gr_complex))
     ### Param init / sanity check ########################################
     self.fft_len           = fft_len
     self.cp_len            = cp_len
     self.packet_length_tag_key = packet_length_tag_key
     self.occupied_carriers = occupied_carriers
     self.pilot_carriers    = pilot_carriers
     self.pilot_symbols     = pilot_symbols
     self.bps_header        = bps_header
     self.bps_payload       = bps_payload
     self.sync_word1 = sync_word1
     if sync_word1 is None:
         self.sync_word1 = _make_sync_word1(fft_len, occupied_carriers, pilot_carriers)
     else:
         if len(sync_word1) != self.fft_len:
             raise ValueError("Length of sync sequence(s) must be FFT length.")
     self.sync_words = [self.sync_word1,]
     if sync_word2 is None:
         self.sync_word2 = _make_sync_word2(fft_len, occupied_carriers, pilot_carriers)
     else:
         self.sync_word2 = sync_word2
     if len(self.sync_word2):
         if len(self.sync_word2) != fft_len:
             raise ValueError("Length of sync sequence(s) must be FFT length.")
         self.sync_word2 = list(self.sync_word2)
         self.sync_words.append(self.sync_word2)
     if scramble_bits:
         self.scramble_seed = 0x7f
     else:
         self.scramble_seed = 0x00 # We deactivate the scrambler by init'ing it with zeros
     ### Header modulation ################################################
     crc = digital.crc32_bb(False, self.packet_length_tag_key)
     header_constellation  = _get_constellation(bps_header)
     header_mod = digital.chunks_to_symbols_bc(header_constellation.points())
     formatter_object = digital.packet_header_ofdm(
         occupied_carriers=occupied_carriers, n_syms=1,
         bits_per_header_sym=self.bps_header,
         bits_per_payload_sym=self.bps_payload,
         scramble_header=scramble_bits
     )
     header_gen = digital.packet_headergenerator_bb(formatter_object.base(), self.packet_length_tag_key)
     header_payload_mux = blocks.tagged_stream_mux(
             itemsize=gr.sizeof_gr_complex*1,
             lengthtagname=self.packet_length_tag_key,
             tag_preserve_head_pos=1 # Head tags on the payload stream stay on the head
     )
     self.connect(
             self,
             crc,
             header_gen,
             header_mod,
             (header_payload_mux, 0)
     )
     if debug_log:
         self.connect(header_gen, blocks.file_sink(1, 'tx-hdr.dat'))
     ### Payload modulation ###############################################
     payload_constellation = _get_constellation(bps_payload)
     payload_mod = digital.chunks_to_symbols_bc(payload_constellation.points())
     payload_scrambler = digital.additive_scrambler_bb(
         0x8a,
         self.scramble_seed,
         7,
         0, # Don't reset after fixed length (let the reset tag do that)
         bits_per_byte=8, # This is before unpacking
         reset_tag_key=self.packet_length_tag_key
     )
     payload_unpack = blocks.repack_bits_bb(
         8, # Unpack 8 bits per byte
         bps_payload,
         self.packet_length_tag_key
     )
     self.connect(
         crc,
         payload_scrambler,
         payload_unpack,
         payload_mod,
         (header_payload_mux, 1)
     )
     ### Create OFDM frame ################################################
     allocator = digital.ofdm_carrier_allocator_cvc(
         self.fft_len,
         occupied_carriers=self.occupied_carriers,
         pilot_carriers=self.pilot_carriers,
         pilot_symbols=self.pilot_symbols,
         sync_words=self.sync_words,
         len_tag_key=self.packet_length_tag_key
     )
     ffter = fft.fft_vcc(
             self.fft_len,
             False, # Inverse FFT
             (), # No window
             True # Shift
     )
     cyclic_prefixer = digital.ofdm_cyclic_prefixer(
         self.fft_len,
         self.fft_len+self.cp_len,
         rolloff,
         self.packet_length_tag_key
     )
     self.connect(header_payload_mux, allocator, ffter, cyclic_prefixer, self)
     if debug_log:
         self.connect(allocator,       blocks.file_sink(gr.sizeof_gr_complex * fft_len, 'tx-post-allocator.dat'))
         self.connect(cyclic_prefixer, blocks.file_sink(gr.sizeof_gr_complex,           'tx-signal.dat'))
Example #10
0
 def __init__(self, fft_len=_def_fft_len, cp_len=_def_cp_len,
              packet_length_tag_key=_def_packet_length_tag_key,
              occupied_carriers=_def_occupied_carriers,
              pilot_carriers=_def_pilot_carriers,
              pilot_symbols=_def_pilot_symbols,
              bps_header=1,
              bps_payload=1,
              sync_word1=None,
              sync_word2=None,
              rolloff=0,
              debug_log=False
              ):
     gr.hier_block2.__init__(self, "ofdm_tx",
                 gr.io_signature(1, 1, gr.sizeof_char),
                 gr.io_signature(1, 1, gr.sizeof_gr_complex))
     ### Param init / sanity check ########################################
     self.fft_len           = fft_len
     self.cp_len            = cp_len
     self.packet_length_tag_key = packet_length_tag_key
     self.occupied_carriers = occupied_carriers
     self.pilot_carriers    = pilot_carriers
     self.pilot_symbols     = pilot_symbols
     self.bps_header        = bps_header
     self.bps_payload       = bps_payload
     n_sync_words = 1
     self.sync_word1 = sync_word1
     if sync_word1 is None:
         self.sync_word1 = _make_sync_word1(fft_len, occupied_carriers, pilot_carriers)
     else:
         if len(sync_word1) != self.fft_len:
             raise ValueError("Length of sync sequence(s) must be FFT length.")
     self.sync_words = [self.sync_word1,]
     self.sync_word2 = ()
     if sync_word2 is None:
         self.sync_word2 = _make_sync_word2(fft_len, occupied_carriers, pilot_carriers)
     if len(self.sync_word2):
         if len(self.sync_word2) != fft_len:
             raise ValueError("Length of sync sequence(s) must be FFT length.")
         self.sync_word2 = list(self.sync_word2)
         n_sync_words = 2
         self.sync_words.append(self.sync_word2)
     ### Header modulation ################################################
     crc = digital.crc32_bb(False, self.packet_length_tag_key)
     header_constellation  = _get_constellation(bps_header)
     header_mod = digital.chunks_to_symbols_bc(header_constellation.points())
     formatter_object = digital.packet_header_ofdm(
         occupied_carriers=occupied_carriers, n_syms=1,
         bits_per_header_sym=self.bps_header,
         bits_per_payload_sym=self.bps_payload
     )
     header_gen = digital.packet_headergenerator_bb(formatter_object.base(), self.packet_length_tag_key)
     header_payload_mux = blocks.tagged_stream_mux(gr.sizeof_gr_complex*1, self.packet_length_tag_key)
     self.connect(self, crc, header_gen, header_mod, (header_payload_mux, 0))
     if debug_log:
         self.connect(header_gen, blocks.file_sink(1, 'tx-hdr.dat'))
     ### Payload modulation ###############################################
     payload_constellation = _get_constellation(bps_payload)
     payload_mod = digital.chunks_to_symbols_bc(payload_constellation.points())
     self.connect(
         crc,
         blocks.repack_bits_bb(
             8, # Unpack 8 bits per byte
             bps_payload,
             self.packet_length_tag_key
         ),
         payload_mod,
         (header_payload_mux, 1)
     )
     ### Create OFDM frame ################################################
     allocator = digital.ofdm_carrier_allocator_cvc(
         self.fft_len,
         occupied_carriers=self.occupied_carriers,
         pilot_carriers=self.pilot_carriers,
         pilot_symbols=self.pilot_symbols,
         sync_words=self.sync_words,
         len_tag_key=self.packet_length_tag_key
     )
     ffter = fft.fft_vcc(
             self.fft_len,
             False, # Inverse FFT
             (), # No window
             True # Shift
     )
     cyclic_prefixer = digital.ofdm_cyclic_prefixer(
         self.fft_len,
         self.fft_len+self.cp_len,
         rolloff,
         self.packet_length_tag_key
     )
     self.connect(header_payload_mux, allocator, ffter, cyclic_prefixer, self)
     if debug_log:
         self.connect(allocator,         blocks.file_sink(8*64, 'tx-post-allocator.dat'))
         self.connect(cyclic_prefixer,   blocks.file_sink(8,    'tx-signal.dat'))
Example #11
0
 def __init__(self, fft_len=_def_fft_len, cp_len=_def_cp_len,
              frame_length_tag_key=_def_frame_length_tag_key,
              occupied_carriers=_def_occupied_carriers,
              pilot_carriers=_def_pilot_carriers,
              pilot_symbols=_def_pilot_symbols,
              bps_header=1,
              bps_payload=1,
              sync_word1=None,
              sync_word2=None,
              rolloff=0
              ):
     gr.hier_block2.__init__(self, "ofdm_tx",
                 gr.io_signature(1, 1, gr.sizeof_char),
                 gr.io_signature(1, 1, gr.sizeof_gr_complex))
     self.fft_len           = fft_len
     self.cp_len            = cp_len
     self.frame_length_tag_key    = frame_length_tag_key
     self.occupied_carriers = occupied_carriers
     self.pilot_carriers    = pilot_carriers
     self.pilot_symbols     = pilot_symbols
     self.bps_header        = bps_header
     self.bps_payload       = bps_payload
     n_sync_words = 1
     header_constellation  = _get_constellation(bps_header)
     header_mod = digital.chunks_to_symbols_bc(header_constellation.points())
     self.sync_word1 = sync_word1
     if sync_word1 is None:
         self.sync_word1 = _make_sync_word(fft_len, occupied_carriers, header_constellation)
     else:
         if len(sync_word1) != self.fft_len:
             raise ValueError("Length of sync sequence(s) must be FFT length.")
     total_sync_word = self.sync_word1
     self.sync_word2 = ()
     if sync_word2 is not None:
         if len(sync_word2) != fft_len:
             raise ValueError("Length of sync sequence(s) must be FFT length.")
         self.sync_word2 = sync_word2
         n_sync_words = 2
         total_sync_word = sync_word1 + sync_word2
     crc = digital.crc32_bb(False, self.frame_length_tag_key)
     formatter_object = digital.packet_header_ofdm(
         occupied_carriers, 1, "", "", "",
         bps_header
     )
     header_gen = digital.packet_headergenerator_bb(formatter_object.base())
     header_payload_mux = blocks.tagged_stream_mux(gr.sizeof_gr_complex*1, self.frame_length_tag_key)
     self.connect(self, crc, header_gen, header_mod, (header_payload_mux, 0))
     payload_constellation = _get_constellation(bps_payload)
     payload_mod = digital.chunks_to_symbols_bc(payload_constellation.points())
     self.connect(
         crc,
         blocks.repack_bits_bb(8, bps_payload, frame_length_tag_key),
         payload_mod,
         (header_payload_mux, 1)
     )
     self.connect(payload_mod, gr.tag_debug(gr.sizeof_gr_complex, "pmod"))
     sync_word_gen = gr.vector_source_c(
         total_sync_word, True, self.fft_len,
         tagged_streams.make_lengthtags((n_sync_words,), (0,), self.frame_length_tag_key)
     )
     allocator = digital.ofdm_carrier_allocator_cvc(
         self.fft_len,
         occupied_carriers=self.occupied_carriers,
         pilot_carriers=self.pilot_carriers,
         pilot_symbols=self.pilot_symbols,
         len_tag_key=self.frame_length_tag_key
     )
     syncword_data_mux  = blocks.tagged_stream_mux(gr.sizeof_gr_complex*self.fft_len, self.frame_length_tag_key)
     self.connect(sync_word_gen, (syncword_data_mux, 0))
     self.connect(header_payload_mux, allocator, (syncword_data_mux, 1))
     ffter = fft.fft_vcc(self.fft_len, False, (), False)
     cyclic_prefixer = digital.ofdm_cyclic_prefixer(
         self.fft_len,
         self.fft_len+self.cp_len,
         rolloff,
         self.frame_length_tag_key
     )
     self.connect(syncword_data_mux, ffter, cyclic_prefixer, self)
 def test_003_t (self):
     """
     more advanced:
     - 6 symbols per carrier
     - 2 pilots per carrier
     - have enough data for nearly 3 OFDM symbols
     - send that twice
     - add some random tags
     - don't shift
     """
     tx_symbols = range(1, 16); # 15 symbols
     pilot_symbols = ((1j, 2j), (3j, 4j))
     occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),)
     pilot_carriers = ((2, 13), (3, 12))
     expected_result = (0, 1,  1j,  2,  3, 0, 0, 0, 0, 0, 0, 4,  5,  2j, 6,  0,
                        0, 7,  8,  3j,  9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12, 0,
                        0, 13, 1j, 14, 15, 0, 0, 0, 0, 0, 0, 0,  0,  2j, 0,  0)
     fft_len = 16
     tag_name = "len"
     tag1 = gr.tag_t()
     tag1.offset = 0
     tag1.key = pmt.string_to_symbol(tag_name)
     tag1.value = pmt.from_long(len(tx_symbols))
     tag2 = gr.tag_t()
     tag2.offset = len(tx_symbols)
     tag2.key = pmt.string_to_symbol(tag_name)
     tag2.value = pmt.from_long(len(tx_symbols))
     testtag1 = gr.tag_t()
     testtag1.offset = 0
     testtag1.key = pmt.string_to_symbol('tag1')
     testtag1.value = pmt.from_long(0)
     testtag2 = gr.tag_t()
     testtag2.offset = 7 # On the 2nd OFDM symbol
     testtag2.key = pmt.string_to_symbol('tag2')
     testtag2.value = pmt.from_long(0)
     testtag3 = gr.tag_t()
     testtag3.offset = len(tx_symbols)+1 # First OFDM symbol of packet 2
     testtag3.key = pmt.string_to_symbol('tag3')
     testtag3.value = pmt.from_long(0)
     testtag4 = gr.tag_t()
     testtag4.offset = 2*len(tx_symbols)-1 # Last OFDM symbol of packet 2
     testtag4.key = pmt.string_to_symbol('tag4')
     testtag4.value = pmt.from_long(0)
     src = blocks.vector_source_c(tx_symbols * 2, False, 1, 
                                  (tag1, tag2, testtag1, testtag2, testtag3, testtag4))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols, (),
                    tag_name,
                    False)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, alloc, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result * 2)
     tags_found = {'tag1': False, 'tag2': False, 'tag3': False, 'tag4': False}
     correct_offsets = {'tag1': 0, 'tag2': 1, 'tag3': 3, 'tag4': 5}
     for tag in sink.tags():
         key = pmt.symbol_to_string(tag.key)
         if key in tags_found.keys():
             tags_found[key] = True
             self.assertEqual(correct_offsets[key], tag.offset)
         if key == tag_name:
             self.assertTrue(tag.offset == 0 or tag.offset == 3)
             self.assertTrue(pmt.to_long(tag.value) == 3)
     self.assertTrue(all(tags_found.values()))