# Small Exemplar Network Stack

**URL:** <https://forum.opencyphal.org/t/small-exemplar-network-stack/2383>\
**Category:** LibUDPard\
**Created:** [May 14, 2025, 6:01pm UTC](https://forum.opencyphal.org/t/small-exemplar-network-stack/2383 "2025-05-14T18:01:01Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![erik.rainey](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/erik.rainey/32/20_2.png) [@erik.rainey](https://forum.opencyphal.org/u/erik.rainey)\
**Post date:** [May 14, 2025, 6:01pm UTC](https://forum.opencyphal.org/t/small-exemplar-network-stack/2383/1 "2025-05-14T18:01:01Z")

</div>

For customers who do not have an appropriately capable ethernet/IP multicast stack, we want to provide a minimal solution which enables the use of libudpard on platforms which at least have an ethernet driver which can send and receive frames along with some other minor requirements.

This small IP stack would be required to only support, per Cyphal specification, UDP multicast (and Ethernet Multicast) and IGMP in order to get a functional implementation with 1 network interface. These may have consequences that more features are needed to bring the stack up but for now this seems like the minimal set.

Since the library would pair with lidudpard, it would also be in “C” although I would prefer C23 or C17 or eariler.

Other features under discussion to aid customers:

- ARP request/response
- ICMP echo/response
- unicast support in UDP
- IPv6 support for UDP

Additionally T1S support in the future may cause some necessary changes but I can’t forsee what that may be right now.

An API discussion or feature discussion is welcome.

I’m not in favor of a socket API as these deeply embedded projects without an existing stack don’t need that abstraction. I would prefer something simple, with APIs to register intent to listen/transmit to a specific multicast addresses and port, as well as either a callback/RunOnce or an active call to Receive. The IGMP packets could be automatic w/ time-outs or explicit via the “intent” API.

Thoughts?

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [May 14, 2025, 6:32pm UTC](https://forum.opencyphal.org/t/small-exemplar-network-stack/2383/2 "2025-05-14T18:32:51Z")

</div>

That sounds good. I don’t have any inputs on API yet.

No objections to C17; it seems well-supported already as far as I can tell. C23 notably [lacks support from IAR](https://www.iar.com/embedded-development-tools/iar-embedded-workbench) at the moment, but it may change quickly so not sure if that’s a deal breaker.

---

<div class="post-metadata">

**Author:** ![erik.rainey](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/erik.rainey/32/20_2.png) [@erik.rainey](https://forum.opencyphal.org/u/erik.rainey)\
**Post date:** [May 14, 2025, 9:00pm UTC](https://forum.opencyphal.org/t/small-exemplar-network-stack/2383/3 "2025-05-14T21:00:10Z")

</div>

It is available in GCC-15, which just recently released.

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [May 14, 2025, 9:16pm UTC](https://forum.opencyphal.org/t/small-exemplar-network-stack/2383/4 "2025-05-14T21:16:40Z")

</div>

Do we know when it’s going to be supported in IAR?

---

<div class="post-metadata">

**Author:** ![erik.rainey](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/erik.rainey/32/20_2.png) [@erik.rainey](https://forum.opencyphal.org/u/erik.rainey)\
**Post date:** [May 14, 2025, 9:19pm UTC](https://forum.opencyphal.org/t/small-exemplar-network-stack/2383/5 "2025-05-14T21:19:18Z")

</div>

Some initial thoughts on API

- `Status Initialize(Context, ExternalContext Dependencies)` - then depedencies are a bunch of function pointers in a structure back to customer APIs which can provide. External context here is whatever the Ethernet driver needs.
  - `Frame* Acquire(ExternalContext)`;
  - `void Release(ExternalContext, Frame*);`
  - `Status Receive(ExternalContext, Frame*);`
  - `Status Transmit(ExternalContext, Frame*);`
  - utility functions like `print` or a monotonic timestamp, no assumed external functions, except `memset` and `memcpy`, even those could be supplied.

- `Deinitialize(Context);`
- `Status PrepareListen(Context, multicast_ip);`
- `Status PrepareTransmit(Context, multicast_ip);`
- Either a direct call or an indirect callback
  - `Status ReceiveUdp(Context, Metadata*, cspan);`
  - `Status RunOnce(Context, Callback);`

- `Status TransmitUdp(Context, Metadata *, cspan);`

---

<div class="post-metadata">

**Author:** ![erik.rainey](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/erik.rainey/32/20_2.png) [@erik.rainey](https://forum.opencyphal.org/u/erik.rainey)\
**Post date:** [May 14, 2025, 9:22pm UTC](https://forum.opencyphal.org/t/small-exemplar-network-stack/2383/6 "2025-05-14T21:22:03Z")

</div>

[https://en.cppreference.com/w/c/compiler\_support/23](https://en.cppreference.com/w/c/compiler_support/23)

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [May 14, 2025, 9:31pm UTC](https://forum.opencyphal.org/t/small-exemplar-network-stack/2383/7 "2025-05-14T21:31:51Z")

</div>

IAR is not mentioned there

---

<div class="post-metadata">

**Author:** ![erik.rainey](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/erik.rainey/32/20_2.png) [@erik.rainey](https://forum.opencyphal.org/u/erik.rainey)\
**Post date:** [May 14, 2025, 9:51pm UTC](https://forum.opencyphal.org/t/small-exemplar-network-stack/2383/8 "2025-05-14T21:51:53Z")

</div>

Hmm, do they not support any C specifications? I keep getting 404 pages on many google links.

[https://www.iar.com/knowledge/learn/programming/exploring-c-and-cpp/#:~:text=C11%20is%20a%20superset%20of,low%20level%20drivers%20in%20C](https://www.iar.com/knowledge/learn/programming/exploring-c-and-cpp/#:~:text=C11%20is%20a%20superset%20of,low%20level%20drivers%20in%20C).

[https://www.iar.com/knowledge/learn/programming/exploring-c-and-cpp/](https://www.iar.com/knowledge/learn/programming/exploring-c-and-cpp/)

They claim at least C18 (which I guess is the ISO version?)

[https://netstorage.iar.com/SuppDB/Public/UPDINFO/013857/arm/doc/infocenter/readme.ENU.html](https://netstorage.iar.com/SuppDB/Public/UPDINFO/013857/arm/doc/infocenter/readme.ENU.html)

Wikipedia Page is a bit old [IAR Systems - Wikipedia](https://en.wikipedia.org/wiki/IAR_Systems)

---

<div class="post-metadata">

**Author:** ![erik.rainey](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/erik.rainey/32/20_2.png) [@erik.rainey](https://forum.opencyphal.org/u/erik.rainey)\
**Post date:** [May 16, 2025, 3:37pm UTC](https://forum.opencyphal.org/t/small-exemplar-network-stack/2383/9 "2025-05-16T15:37:08Z")

</div>

I was thinking about consequences of not supporting unicast yet is that we may not need an IP address, except that we do need to put an address into the source field of any outgoing packet. So I think we’ll need to have that at least properly supported as a normal endpoint in the network from the beginning.

---

<div class="post-metadata">

**Author:** ![erik.rainey](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/erik.rainey/32/20_2.png) [@erik.rainey](https://forum.opencyphal.org/u/erik.rainey)\
**Post date:** [May 17, 2025, 1:41am UTC](https://forum.opencyphal.org/t/small-exemplar-network-stack/2383/10 "2025-05-17T01:41:08Z")

</div>

And now the hardest part, the name, in four parts; common name, namespacing prefix,MACRO prefix and variable prefix

- Micro IP, MicroIpFunctionName, MICRO\_IP\_DEFINE, micro\_ip\_var
- Nano IP, NanoIpFunctionName, NANO\_IP\_DEFINE, nano\_ip\_var
- Cyphal IP, CyphalIpFunctionName, CYPHAL\_IP\_DEFINE, cyphal\_ip\_var
- Cilia IP, CiliaIpFunctionName, CILIA\_IP\_DEFINE, cilia\_ip\_var
- Cilium IP, CiliumIpFunctionName, CILIUM\_IP\_DEFINE, cilium\_ip\_var
- Hypha IP, HyphaIpFunctionName, HYPHA\_IP\_DEFINE, hypha\_ip\_var

I’m partial to Hypha now

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [May 17, 2025, 9:23am UTC](https://forum.opencyphal.org/t/small-exemplar-network-stack/2383/11 "2025-05-17T09:23:13Z")

</div>

Hypha sounds fine to me

---

<div class="post-metadata">

**Author:** ![erik.rainey](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/erik.rainey/32/20_2.png) [@erik.rainey](https://forum.opencyphal.org/u/erik.rainey)\
**Post date:** [June 11, 2025, 3:42pm UTC](https://forum.opencyphal.org/t/small-exemplar-network-stack/2383/12 "2025-06-11T15:42:43Z")

</div>

I’m close to posting an initial revision for review which should have:

- Ethernet, IPv4, UDP and IGMP support
- Unity Unit Tests, CMake build.
- Lots of AI assisted doxygen comments (so the style is oddly inconsistent)

It does not have:

- ICMP or ARP (but has some defines for them and TODOs)
- Integration testing on any specific platform
