How danikf/tik4net works
1. This repository is a multi-project .NET library centered on talking to MikroTik RouterOS devices. The architecture splits into a low-level protocol layer, a higher-level object mapper layer, test doubles, and several sample/tooling applications.
2. The core transport/protocol subsystem lives in tik4net. It defines the connection and command abstractions (ITikConnection, ITikCommand, sentence interfaces) plus concrete API protocol handling under tik4net/Api. This layer is responsible for opening the RouterOS API session, sending commands, parsing replies, handling async command execution/cancellation, and surfacing connection/command exceptions.
3. tik4net/Api is the wire-protocol boundary. The files here model MikroTik API sentence types such as done/re/trap/fatal, command parameters, tag sequencing, and sentence lists. This is the point where raw protocol messages are encoded/decoded before higher layers see them.
4. Discovery support is separate from the main API session path. The tik4net/Mndp folder contains MNDP helpers and binary parsing utilities for MikroTik network discovery, enabling a device-discovery flow distinct from authenticated API control.
5. tik4net.objects is the high-level O/R mapper layer built on top of tik4net. It introduces entity annotations and metadata (TikEntityAttribute, TikPropertyAttribute, TikEntityMetadataCache) and extension methods that translate between typed C# objects and RouterOS command/list operations.
6. The object model is organized by RouterOS domain area: Interface, Ip, Ppp, Queue, Routing/BGP, System, Tool, User, Wireguard, and CapsMan. Each entity file represents a concrete RouterOS resource and is intended to support CRUD-like operations through the mapper.
7. The mapper layer also contains reusable infrastructure for entity access and batching: property accessors, list merge behavior, command/connection extensions, and asynchronous loading context. These pieces form the bridge from typed entities to low-level API calls, so they are the main boundary between business-level model code and protocol code.
8. tik4net.testing provides fake implementations of commands, connections, parameters, and sentences. This is a test seam that lets unit tests exercise the object mapper and command code without requiring a live RouterOS device.
9. tik4net.tests is the integration/unit test suite for both the low-level API and the typed entity layer. The test names show coverage across connection behavior, CRUD, BGP, interfaces, firewall, hotspot, DNS, PPP, tool commands, MNDP discovery, and async/torch scenarios. This suite is the main consumer validating the end-to-end contract against RouterOS.
10. The tik4net.examples project is a usage sample library, not an application service. It demonstrates how consumers are expected to open a connection, issue commands, read lists, and save typed entities using the two-tier API.
11. There are two console front ends: tik4net.console and tik4net.coreconsole. These are thin executable wrappers around the library, likely used for manual experimentation and cross-runtime validation. The presence of both suggests support for older .NET Framework style and newer .NET Core style runtimes.
12. The tik4net.torch project is a focused executable around the RouterOS torch/traffic-monitoring capability. It likely exercises the tool-command subsystem and serves as a specialized sample or diagnostic utility.
13. The Tools directory contains semi-automatic code-generation utilities. tik4net.entitygenerator is a Windows Forms generator that parses/assembles typed entity classes, while tik4net.entityWikiImporter appears to import entity definitions from wiki content. These tools feed the tik4net.objects model layer by generating or updating entity code.
14. At the repo level, the main dependency flow is: tools and samples consume the library; tests consume both real and fake implementations; tik4net.objects depends on tik4net; and tik4net is the foundational protocol/runtime boundary. The architectural diagram should show tik4net as the base, tik4net.objects as the higher-level abstraction, and the executables/tools/tests as consumers around them.
Main entry points: tik4net.objects tik4net.objects · tik4net tik4net · Api API layer · tik4net.tests tik4net.tests
Components 18
Core protocol
Low-level RouterOS API and discovery runtime.
- tik4net · Foundational connection, command, sentence, error, and MNDP discovery APIs.
tik4net - API layer · RouterOS API sentence encoding/decoding and connection session handling.
tik4net/Api - Commands · Command and parameter representations plus command execution flow.
tik4net/Api/ApiCommand.cs - Sentences · done/re/trap/fatal sentence models and sentence list/tag sequencing.
tik4net/Api/ApiSentence.cs - MNDP · Binary parsing helpers and MikroTik network discovery support.
tik4net/Mndp
Object mapper
Typed entity layer built on top of the core protocol.
- tik4net.objects · Typed RouterOS object model and mapping extensions over the core API.
tik4net.objects - Metadata · Entity attributes, metadata cache, and property accessors for object mapping.
tik4net.objects/TikEntityMetadata.cs - Entity ops · Connection and command extensions for CRUD-style entity access and batching.
tik4net.objects/TikEntityObjectsExtensions.cs - Async load · Asynchronous loading coordination for entity retrieval.
tik4net.objects/AsyncLoadingContext.cs - Entity models · Typed RouterOS resources spanning interfaces, IP, PPP, routing, system, tools, users, wireguard, and capsman.
tik4net.objects/Interface/Interface.cs
Test support
Fakes and test suite validating protocol and mapping behavior.
- tik4net.tests · Integration and unit coverage for API, mapper, MNDP, and tool scenarios.
tik4net.tests - tik4net.testing · Fake connections, commands, parameters, and sentences for isolated tests.
tik4net.testing
Samples and tools
Console samples and code-generation utilities.
- Examples · Usage examples for low-level commands and typed entity persistence.
tik4net.examples - Console app · Legacy console front end for manual experimentation.
tik4net.console - Core console · Modern console front end for cross-runtime validation.
tik4net.coreconsole - Torch tool · Focused executable around RouterOS torch and traffic monitoring.
tik4net.torch - Entity generator · WinForms tool for generating and updating typed entity classes.
Tools/tik4net.entitygenerator - Wiki importer · WinForms utility for importing entity definitions from wiki content.
Tools/tik4net.entityWikiImporter
Connections 22
- tik4net → API layer: contains · Core library exposes the API protocol boundary.
- API layer → Commands: defines · Command and parameter abstractions live in the API layer.
- API layer → Sentences: defines · Protocol sentence models and sequencing are part of the wire layer.
- tik4net → MNDP: contains · Discovery support is shipped alongside the core runtime.
- tik4net.objects → Metadata: uses · Object mapping relies on entity metadata and property accessors.
- tik4net.objects → Entity ops: uses · Typed object operations are exposed through mapper extensions.
- tik4net.objects → Async load: coordinates · Entity loading uses async orchestration support.
- tik4net.objects → Entity models: contains · Domain-specific RouterOS entities are organized under the object layer.
- tik4net.objects → tik4net: depends on · Mapper builds on the low-level connection and command abstractions.
- Entity models → Metadata: annotated by · Entities are described using mapping attributes and cached metadata.
- Entity ops → API layer: invokes · High-level operations translate to protocol commands and sentence handling.
- tik4net.testing → tik4net: fakes · Test doubles stand in for the core protocol interfaces.
- tik4net.tests → tik4net: validates · Test suite exercises the low-level API and discovery flows.
- tik4net.tests → tik4net.objects: validates · Tests cover typed entity mapping and CRUD behavior.
- tik4net.tests → tik4net.testing: uses · Integration-style tests rely on fake implementations for isolation.
- Examples → tik4net: consumes · Samples demonstrate direct use of the protocol API.
- Examples → tik4net.objects: consumes · Samples also demonstrate typed entity access.
- Console app → tik4net: wraps · Legacy console is a thin executable over the library.
- Core console → tik4net: wraps · Core console is a thin executable over the library.
- Torch tool → tik4net.objects: uses · Torch executable likely exercises the tool-command and mapping layers.
- Entity generator → tik4net.objects: generates · Entity generator feeds the typed model layer.
- Wiki importer → tik4net.objects: updates · Wiki importer helps create or refresh entity definitions.