1.. _module-pw_router: 2 3--------- 4pw_router 5--------- 6The ``pw_router`` module provides transport-agnostic classes for routing packets 7over network links. 8 9Common router interfaces 10======================== 11 12PacketParser 13------------ 14To work with arbitrary packet formats, routers require a common interface for 15extracting relevant packet data, such as the destination. This interface is 16``pw::router::PacketParser``, defined in ``pw_router/packet_parser.h``, which 17must be implemented for the packet framing format used by the network. 18 19Egress 20------ 21The Egress class is a virtual interface for sending packet data over a network 22link. Egress implementations provide a single ``SendPacket`` function, which 23takes the raw packet data and transmits it. 24 25Some common egress implementations are provided upstream in Pigweed. 26 27StaticRouter 28============ 29``pw::router::StaticRouter`` is a router with a static table of address to 30egress mappings. Routes in a static router never change; packets with the same 31address are always sent through the same egress. If links are unavailable, 32packets will be dropped. 33 34Static routers are suitable for basic networks with persistent links. 35 36Usage example 37------------- 38 39.. code-block:: c++ 40 41 namespace { 42 43 // Define packet parser and egresses. 44 HdlcFrameParser hdlc_parser; 45 UartEgress uart_egress; 46 BluetoothEgress ble_egress; 47 48 // Define the routing table. 49 constexpr pw::router::StaticRouter::Route routes[] = {{1, uart_egress}, 50 {7, ble_egress}}; 51 pw::router::StaticRouter router(hdlc_parser, routes); 52 53 } // namespace 54 55 void ProcessPacket(pw::ConstByteSpan packet) { 56 router.RoutePacket(packet); 57 } 58 59.. TODO(frolv): Re-enable this when the size report builds. 60.. Size report 61.. ----------- 62.. The following size report shows the cost of a ``StaticRouter`` with a simple 63.. ``PacketParser`` implementation and a single route using an ``EgressFunction``. 64 65.. .. include:: static_router_size 66