Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ add_library(ariec61850_core
src/mms/data_codec.cpp
src/mms/pdu.cpp
src/mms/services.cpp
src/mms/dynamic_data_set.cpp
src/mms/invoke_router.cpp
src/mms/reporting.cpp
src/mms/association_runtime.cpp
Expand Down Expand Up @@ -176,6 +177,13 @@ if(ARIEC61850_BUILD_TESTS)
ariec61850_apply_sanitizers(ariec61850_mms_services_tests)
add_test(NAME ariec61850_mms_services_tests COMMAND ariec61850_mms_services_tests)

add_executable(ariec61850_dynamic_data_set_tests tests/test_dynamic_data_set.cpp)
target_link_libraries(ariec61850_dynamic_data_set_tests PRIVATE ARIEC61850::core)
target_compile_features(ariec61850_dynamic_data_set_tests PRIVATE cxx_std_20)
ariec61850_apply_warnings(ariec61850_dynamic_data_set_tests)
ariec61850_apply_sanitizers(ariec61850_dynamic_data_set_tests)
add_test(NAME ariec61850_dynamic_data_set_tests COMMAND ariec61850_dynamic_data_set_tests)

add_executable(ariec61850_reporting_tests tests/test_reporting.cpp)
target_link_libraries(ariec61850_reporting_tests PRIVATE ARIEC61850::core)
target_compile_features(ariec61850_reporting_tests PRIVATE cxx_std_20)
Expand Down
71 changes: 71 additions & 0 deletions DYNAMIC_DATASET_PROFILE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Dynamic DataSet Profile

## Scope

This profile ports the ARIEC61850 dynamic DataSet lifecycle to the C++ stack without coupling it to IEC 61850 control sequencing.

Implemented MMS services:

- `DefineNamedVariableList` — service choice `[11]`
- `DeleteNamedVariableList` — service choice `[13]`
- `GetNamedVariableListAttributes` verification through the existing DataSet-directory codec

The codec is symmetric: request and response encode/decode are available so the same wire model can be reused by a future MMS server dispatcher.

## Reference and member rules

Dynamic DataSets use domain-specific IEC 61850 references:

`LD/LN.DataSetName`

The operational runtime also accepts `LD/DataSetName` and normalizes it to `LD/LLN0.DataSetName`, matching the C# oracle behavior.

Members are ordered domain-specific MMS named variables. Duplicate members are rejected. Member ordering is treated as semantic because IEC 61850 report values are mapped to DataSet members by index.

## Safe create lifecycle

`MmsDynamicDataSetRuntime::create()` requires an already associated `MmsAssociationRuntime` and performs:

1. validate the DataSet identity and bounded member list;
2. send exactly one `DefineNamedVariableList` request;
3. require a matching successful confirmed response;
4. by default, issue `GetNamedVariableListAttributes` for the new DataSet;
5. require exact member count, content, and ordering;
6. record local ownership only after the create path succeeds.

If verification fails after a successful Define, the runtime attempts one best-effort Delete rollback and then propagates the original failure. It does not retry creation automatically.

The operational default is 64 members. Callers can raise the limit explicitly up to the bounded codec maximum after validating target-IED payload and resource limits.

## Safe delete lifecycle

Deletion is default-deny for DataSets the runtime did not create.

`owned_only` is the default policy. `explicit_override` must be selected deliberately to delete an unowned DataSet. This prevents a reporting client from accidentally deleting a static or another client's DataSet merely because the reference is known.

No network operation is performed from a destructor. Cleanup is always explicit so shutdown and association-loss behavior remain observable.

## C# parity evidence

The dedicated C++ test target includes the ARIEC61850 C# oracle vectors for:

- successful `DefineNamedVariableList` response: `A10502010A8B00`;
- successful `DeleteNamedVariableList` matched/deleted response: `A10B02010BAD06800101810101`;
- Define request service/member shape;
- Delete request service/list-name shape.

The tests also round-trip both request types, reject empty/duplicate/invalid definitions, verify invoke-ID correlation, and require an active association before any mutation.

## Acceptance boundary

Hosted CI can establish deterministic wire parity, parser/encoder safety, portability, and integration with the existing association runtime. It cannot establish physical IED mutation interoperability.

Before claiming live Dynamic DataSet interoperability, retain evidence from a non-operational lab IED showing:

1. `DefineNamedVariableList` accepted for a small DataSet;
2. immediate `GetNamedVariableListAttributes` returns the exact requested ordered members;
3. an available RCB can bind to that DataSet and report values map by the verified indexes;
4. `DeleteNamedVariableList` reports the expected matched/deleted counts after RCB disable/unbind;
5. reconnect and failure cases do not cause an unrelated/static DataSet to be deleted.

Smart Control is intentionally outside this profile and may progress independently.
154 changes: 154 additions & 0 deletions include/ariec61850/mms/dynamic_data_set.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once

#include "ariec61850/mms/association_runtime.hpp"
#include "ariec61850/mms/reporting.hpp"

#include <cstddef>
#include <cstdint>
#include <optional>
#include <set>
#include <span>
#include <stdexcept>
#include <stop_token>
#include <string>
#include <vector>

namespace ar::iec61850::mms {

class MmsDynamicDataSetError final : public std::runtime_error {
public:
using std::runtime_error::runtime_error;
};

struct MmsDefineNamedVariableListRequest final {
std::uint32_t invoke_id{};
MmsObjectName data_set_name;
std::vector<MmsObjectName> members;

friend bool operator==(const MmsDefineNamedVariableListRequest&,
const MmsDefineNamedVariableListRequest&) = default;
};

struct MmsDefineNamedVariableListResponse final {
std::uint32_t invoke_id{};

friend bool operator==(const MmsDefineNamedVariableListResponse&,
const MmsDefineNamedVariableListResponse&) = default;
};

struct MmsDeleteNamedVariableListRequest final {
std::uint32_t invoke_id{};
MmsObjectName data_set_name;

friend bool operator==(const MmsDeleteNamedVariableListRequest&,
const MmsDeleteNamedVariableListRequest&) = default;
};

struct MmsDeleteNamedVariableListResponse final {
std::uint32_t invoke_id{};
std::optional<std::uint32_t> number_matched;
std::optional<std::uint32_t> number_deleted;

[[nodiscard]] bool deleted() const noexcept {
return number_deleted.value_or(0U) > 0U;
}

friend bool operator==(const MmsDeleteNamedVariableListResponse&,
const MmsDeleteNamedVariableListResponse&) = default;
};

class MmsNamedVariableListCodec final {
public:
static constexpr std::int32_t define_service_tag = 11;
static constexpr std::int32_t delete_service_tag = 13;
static constexpr std::size_t maximum_members = 65'536U;

[[nodiscard]] static std::vector<std::uint8_t> encode_define_request_pdu(
const MmsDefineNamedVariableListRequest& request);
[[nodiscard]] static std::vector<std::uint8_t> encode_define_request_p_data(
const MmsDefineNamedVariableListRequest& request,
std::uint32_t presentation_context_id = 3U);
[[nodiscard]] static MmsDefineNamedVariableListRequest decode_define_request(
std::span<const std::uint8_t> presentation_or_mms_payload);

[[nodiscard]] static std::vector<std::uint8_t> encode_define_response_pdu(
const MmsDefineNamedVariableListResponse& response);
[[nodiscard]] static std::vector<std::uint8_t> encode_define_response_p_data(
const MmsDefineNamedVariableListResponse& response,
std::uint32_t presentation_context_id = 3U);
[[nodiscard]] static MmsDefineNamedVariableListResponse decode_define_response(
std::span<const std::uint8_t> presentation_or_mms_payload,
std::optional<std::uint32_t> expected_invoke_id = std::nullopt);

[[nodiscard]] static std::vector<std::uint8_t> encode_delete_request_pdu(
const MmsDeleteNamedVariableListRequest& request);
[[nodiscard]] static std::vector<std::uint8_t> encode_delete_request_p_data(
const MmsDeleteNamedVariableListRequest& request,
std::uint32_t presentation_context_id = 3U);
[[nodiscard]] static MmsDeleteNamedVariableListRequest decode_delete_request(
std::span<const std::uint8_t> presentation_or_mms_payload);

[[nodiscard]] static std::vector<std::uint8_t> encode_delete_response_pdu(
const MmsDeleteNamedVariableListResponse& response);
[[nodiscard]] static std::vector<std::uint8_t> encode_delete_response_p_data(
const MmsDeleteNamedVariableListResponse& response,
std::uint32_t presentation_context_id = 3U);
[[nodiscard]] static MmsDeleteNamedVariableListResponse decode_delete_response(
std::span<const std::uint8_t> presentation_or_mms_payload,
std::optional<std::uint32_t> expected_invoke_id = std::nullopt);
};

struct MmsDynamicDataSetOptions final {
// Dynamic report DataSets are safest when intentionally small. The wire codec
// supports the full bounded MMS list size, while this operational default can
// be raised explicitly by a caller that has verified the target IED limits.
std::size_t maximum_members{64U};
bool verify_after_create{true};
};

struct MmsDynamicDataSetCreateResult final {
std::string data_set_reference;
MmsDefineNamedVariableListResponse define_response;
std::optional<MmsDataSetDirectoryResponse> verified_directory;
};

enum class MmsDynamicDataSetDeletePolicy : std::uint8_t {
owned_only,
explicit_override,
};

class MmsDynamicDataSetRuntime final {
public:
explicit MmsDynamicDataSetRuntime(
MmsAssociationRuntime& association,
MmsDynamicDataSetOptions options = {});

[[nodiscard]] MmsDynamicDataSetCreateResult create(
const std::string& data_set_reference,
std::span<const MmsObjectName> members,
std::stop_token stop_token = {});

[[nodiscard]] MmsDeleteNamedVariableListResponse remove(
const std::string& data_set_reference,
MmsDynamicDataSetDeletePolicy policy = MmsDynamicDataSetDeletePolicy::owned_only,
std::stop_token stop_token = {});

[[nodiscard]] bool owns(const std::string& data_set_reference) const;
[[nodiscard]] std::vector<std::string> owned_data_sets() const;

private:
[[nodiscard]] std::string normalize_reference(const std::string& reference) const;
[[nodiscard]] MmsDeleteNamedVariableListResponse remove_impl(
const std::string& normalized_reference,
std::stop_token stop_token);
[[nodiscard]] MmsDataSetDirectoryResponse verify(
const MmsObjectName& data_set_name,
std::stop_token stop_token);

MmsAssociationRuntime& association_;
MmsDynamicDataSetOptions options_{};
std::set<std::string, std::less<>> owned_data_sets_;
};

} // namespace ar::iec61850::mms
Loading
Loading