|
ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
|
Layer: L4 Transport ยท Build flags: PC_ENABLE_DIFFSERV
DiffServ (RFC 2474) puts a 6-bit DSCP in the DS field of the IP header (the high 6 bits of the IPv4 TOS / IPv6 Traffic-Class byte). A QoS-aware switch, router, or Wi-Fi AP reads that class and prioritizes the packet - real-time / safety traffic marked Expedited Forwarding (EF, DSCP 46) jumps ahead of best-effort, and the Wi-Fi driver maps it into the top 802.11e WMM access categories.
With PC_ENABLE_DIFFSERV the transport writes the DSCP into the pcb's TOS field as each connection is accepted / connected, so nothing is added to the send hot path. Three levels of control, coarse to fine:
A DSCP of 0 means best-effort (no marking). Convenience code points are defined (PC_DSCP_EF 46, PC_DSCP_CS6 48, PC_DSCP_AF41 34, PC_DSCP_AF31 26); any 0-63 value is accepted - handy for arbitrarily tagging traffic in network testing, not just standards-defined classes.
This sketch marks every connection EF by default, and re-tags the GET /tag connection to CS6 to show the per-flow override.
Flash it, then read the DSCP straight off the wire from another machine on the LAN:
The marking applies from the connection's first data segment: the SYN-ACK stays best-effort because lwIP emits it before any app callback and ESP32 lwIP does not inherit the listen-pcb TOS (HW-tested). This was verified on an ESP32-P4 off the wire: the server default marked :80 responses tos 0xb8 (EF), a per-listener override marked :8080 responses tos 0x88 (AF41), and a per-connection re-tag marked /tag responses tos 0xc0 (CS6).
The complete sketch (DiffServ.ino):