Exemplo n.º 1
0
 def test_correct_num_of_entries(cb_ref, ttl, dat_set, go_id, t, st_num,
                                 sq_num, go_test, conf_rev, nds_com,
                                 num_entries, all_data):
     pdu = ProtocolDataUnit(cb_ref, ttl, dat_set, go_id, t, st_num, sq_num,
                            go_test, conf_rev, nds_com, num_entries,
                            all_data)
     assert pdu.number_of_data_set_entries.value == pdu.all_data.number_of_data_set_entries
Exemplo n.º 2
0
 def test_wrong_num_of_entries(cb_ref, ttl, dat_set, go_id, t, st_num,
                               sq_num, go_test, conf_rev, nds_com,
                               all_data):
     with raises(ValueError):
         ProtocolDataUnit(cb_ref, ttl, dat_set, go_id, t, st_num, sq_num,
                          go_test, conf_rev, nds_com,
                          NumberOfDataSetEntries(2), all_data)
Exemplo n.º 3
0
    def __init__(self,
                 destination: bytes = b'\x01\x0c\xcd\x01\x00\x00',
                 source: bytes = b'\x00\x00\x00\x00\x00\x00',
                 virtual_lan: bool = True,
                 vlan_priority: int = 4,
                 vlan_id: int = 0,
                 app_id: int = 1,
                 goose_control_block_reference:
                 str = 'IED_CFG/LLN0$GO$ControlBlockReference',
                 time_allowed_to_live: int = 1000,
                 data_set: str = 'IED_CFG/LLN0$DataSet',
                 goose_identifier: str = 'IED',
                 goose_timestamp: float = 0.0,
                 status_number: int = 1,
                 sequence_number: int = 0,
                 test: bool = False,
                 configuration_revision: int = 1,
                 needs_commissioning: bool = False,
                 number_of_data_set_entries: Optional[int] = None,
                 all_data: Optional[Union[AllData, Tuple[Base, ...]]] = None):
        self.destination = destination
        self.source = source
        if virtual_lan:
            self._ether_type = VLAN_ETHER_TYPE
            # TODO add vlan property if, and only if, vlan set to True
            self._virtual_lan = VirtualLAN(GOOSE_ETHER_TYPE, vlan_priority,
                                           vlan_id)
        else:
            self._ether_type = GOOSE_ETHER_TYPE
            self._virtual_lan = None
        self._set_app_id(app_id)
        self._length = None  # 2 bytes
        self._reserved = b'\x00\x00\x00\x00'

        goose_control_block_reference = GooseControlBlockReference(
            goose_control_block_reference)
        time_allowed_to_live = TimeAllowedToLive(time_allowed_to_live)
        data_set = DataSet(data_set)
        goose_identifier = GooseIdentifier(goose_identifier)
        goose_timestamp = GooseTimestamp(goose_timestamp)
        status_number = StatusNumber(status_number)
        sequence_number = SequenceNumber(sequence_number)
        test = GooseTest(test)
        configuration_revision = ConfigurationRevision(configuration_revision)
        needs_commissioning = NeedsCommissioning(needs_commissioning)
        if number_of_data_set_entries is not None:
            number_of_data_set_entries = NumberOfDataSetEntries(
                number_of_data_set_entries)
        if all_data:
            if not isinstance(all_data, AllData):
                all_data = AllData(*all_data)
        else:
            all_data = AllData()

        self._pdu = ProtocolDataUnit(
            goose_control_block_reference, time_allowed_to_live, data_set,
            goose_identifier, goose_timestamp, status_number, sequence_number,
            test, configuration_revision, needs_commissioning,
            number_of_data_set_entries, all_data)
Exemplo n.º 4
0
 def test_all_data_change_no_iter_sq(cb_ref, ttl, dat_set, go_id, t, st_num,
                                     sq_num, go_test, conf_rev, nds_com,
                                     num_entries, all_data):
     pdu = ProtocolDataUnit(cb_ref, ttl, dat_set, go_id, t, st_num, sq_num,
                            go_test, conf_rev, nds_com, num_entries,
                            all_data)
     pdu.all_data[0].value = False
     assert pdu.sequence_number.value == 0
Exemplo n.º 5
0
 def test_all_data_change_next_st(cb_ref, ttl, dat_set, go_id, t, st_num,
                                  sq_num, go_test, conf_rev, nds_com,
                                  num_entries, all_data):
     pdu = ProtocolDataUnit(cb_ref, ttl, dat_set, go_id, t, st_num, sq_num,
                            go_test, conf_rev, nds_com, num_entries,
                            all_data)
     iter_pdu = iter(pdu)
     iter_pdu.all_data[0].value = False
     assert next(pdu).status_number.value == 2
Exemplo n.º 6
0
 def test_all_data_change_no_iter_error(cb_ref, ttl, dat_set, go_id, t,
                                        st_num, sq_num, go_test, conf_rev,
                                        nds_com, num_entries, all_data):
     pdu = ProtocolDataUnit(cb_ref, ttl, dat_set, go_id, t, st_num, sq_num,
                            go_test, conf_rev, nds_com, num_entries,
                            all_data)
     with raises(TypeError) as info:
         next(pdu)
     assert str(info.value) == "'ProtocolDataUnit' object is not iterable"
Exemplo n.º 7
0
 def pdu(self, cb_ref, ttl, dat_set, go_id, t, st_num, sq_num, go_test,
         conf_rev, nds_com):
     return ProtocolDataUnit(cb_ref, ttl, dat_set, go_id, t, st_num, sq_num,
                             go_test, conf_rev, nds_com)
Exemplo n.º 8
0
 def test_error_all_data(cb_ref, ttl, dat_set, go_id, t, st_num, sq_num,
                         go_test, conf_rev, nds_com, num_entries):
     with raises(TypeError):
         ProtocolDataUnit(cb_ref, ttl, dat_set, go_id, t, st_num, sq_num,
                          go_test, conf_rev, nds_com, num_entries, 1)