Ejemplo n.º 1
0
def test_cell_comparison(fixture_cell_comparison_test_type):
    cell_attributes = {
        'slot_offset': 1,
        'channel_offset': 2,
        'options': [d.CELLOPTION_TX],
        'mac_addr': None,
        'link_type': d.LINKTYPE_NORMAL
    }
    cell_1 = tsch.Cell(**cell_attributes)

    if fixture_cell_comparison_test_type == 'no_diff':
        # do nothing
        pass
    elif fixture_cell_comparison_test_type == 'slot_offset':
        cell_attributes['slot_offset'] += 1
    elif fixture_cell_comparison_test_type == 'channel_offset':
        cell_attributes['channel_offset'] += 1
    elif fixture_cell_comparison_test_type == 'cell_options':
        cell_attributes['options'] = [d.CELLOPTION_RX]
    elif fixture_cell_comparison_test_type == 'mac_addr':
        cell_attributes['mac_addr'] = 'dummy_mac_addr'
    elif fixture_cell_comparison_test_type == 'link_type':
        cell_attributes['link_type'] = d.LINKTYPE_ADVERTISING
    else:
        raise NotImplementedError()

    cell_2 = tsch.Cell(**cell_attributes)

    if fixture_cell_comparison_test_type == 'no_diff':
        assert cell_1 == cell_2
    else:
        assert cell_1 != cell_2
Ejemplo n.º 2
0
def test_advertising_link(sim_engine):
    # EB should be sent only on links having ADVERTISING on
    sim_engine = sim_engine(
        diff_config={
            'exec_numMotes': 1,
            'sf_class': 'SFNone',
            'tsch_slotframeLength': 2,
            'tsch_probBcast_ebProb': 1.0,
        })
    root = sim_engine.motes[0]
    # disable DIO so that there will be no traffic except for EBs.
    root.rpl.trickle_timer.stop()

    slotframe = root.tsch.get_slotframe(0)

    # make sure we have one cell
    assert len(slotframe.get_busy_slots()) == 1
    cells = slotframe.get_cells_by_mac_addr(None)
    assert len(cells) == 1

    # the link-type of the minimal cell should be ADVERTISING
    minimal_cell = cells[0]
    assert minimal_cell.slot_offset == 0
    assert minimal_cell.channel_offset == 0
    assert (sorted(minimal_cell.options) == sorted(
        [d.CELLOPTION_RX, d.CELLOPTION_TX, d.CELLOPTION_SHARED]))
    assert minimal_cell.mac_addr == None
    assert minimal_cell.link_type == d.LINKTYPE_ADVERTISING

    # add one cell whose link-type is NORMAL at slotoffset 1
    normal_cell = tsch.Cell(slot_offset=1,
                            channel_offset=1,
                            options=minimal_cell.options,
                            mac_addr=None,
                            link_type=d.LINKTYPE_NORMAL)
    assert normal_cell.link_type == d.LINKTYPE_NORMAL
    slotframe.add(normal_cell)

    # run the simulation; we should have EBs only on the minimal cells
    u.run_until_end(sim_engine)

    tx_logs = u.read_log_file(filter=[SimLog.LOG_TSCH_TXDONE['type']])
    assert len(tx_logs) > 0
    for tx_log in tx_logs:
        assert tx_log['slot_offset'] != normal_cell.slot_offset