How dnp3/opendnp3 works
Main Components
• Core DNP3 Library (C++ modules):
– The “cpp/lib” folder contains the primary source for the protocol stack implementation.
– This module includes many submodules such as:
▪ Channel layer (handling physical/serial/TCP/UDP communication, TLS support under “cpp/lib/src/channel” and “cpp/lib/src/channel/tls”)
▪ Transport layer (“cpp/lib/src/transport”)
▪ Application layer with classes for APDU building/parsing and measurement/event management (“cpp/lib/src/app”)
▪ Protocol-specific parts like link layer and master/outstation modules (“cpp/lib/src/master”, “cpp/lib/src/outstation”, “cpp/lib/src/link”)
• Examples:
– The “cpp/examples” directory contains demo applications for masters, outstations, UDP, TLS etc.
• Testing Infrastructure:
– “cpp/tests” is organized into multiple groups (unit tests, integration tests, ASIO tests, fuzz tests) indicating both component verification and protocol stress testing.
• Code Generation Tools:
– The “generation” folder (with subdirectories in Scala and pom.xml files) is used to automatically generate portions of the DNP3 protocol objects and enums.
• Language Bindings:
– The “dotnet” directory provides the CLR adapter and interface, along with example projects.
– The “java” directory contains the Java bindings (source, tests, JNI wrappers, code generation in Scala, and even adapter code in “java/cpp” for JNI support).
Relationships & Interactions
• The core C++ library forms the heart of the system. It is structured in a layered approach, where the physical or serial channels interact with the channel layer which, in turn, feeds the transport layer. This passes data to the application layer and then further bifurcates into master or outstation logic.
• The examples use the core library via APIs provided by different submodules (master, outstation), demonstrating typical use cases like handling multiple TCP sessions or simulating huge numbers of devices.
• The language bindings (for dotnet and java) wrap the core C++ library so that external clients can interact with it using managed languages. They essentially invoke or translate calls to the underlying protocol stack.
• The code generation components support the development process by generating enums, objects, and even source code structures used by both the core and the bindings.
• Testing components interact with all layers of the stack by simulating or emulating communication to validate protocol correctness and performance.
Architectural Patterns & Design Principles
• Layered Architecture – The stack is clearly divided into physical/channel, transport, and application layers.
• Separation of Concerns – C++ modules are factored into distinct subdirectories dedicated to roles like “master” and “outstation,” and even further into “link,” “channel,” “transport” etc.
• Extensibility – The presence of language bindings and code generation indicates that the design supports extensibility to other environments and customization via adapters.
• Testability – The file structure shows comprehensive tests covering unit, integration, and fuzz testing to verify each component’s robustness.
Final Elements
• Clear labels for each component (e.g., “C++ Core – Channel Layer”, “Transport Layer”, “Application Layer – Master/Outstation”, “.NET Binder”, “Java Binder”, “Code Generator”).
– For example, data flows from physical connectors to channel layer modules, then to a transport unit, then onward to master/outstation application logic.
• Additional notes for areas that might be more critical (like performance considerations in the channel and transport layers).