Hello, I want to implement simple fec encoding and decoding operations (using only xor operations) on p4 switch. Suppose host1 is sending packets to host2, then sw1 performs fec encoding and sw2 performs fec decoding, and 3 original packets will generate 1 redundant packet(pkt1 ⊕ pkt2 ⊕ pkt3). Since the connection between sw1 and sw2 goes through wide area network, so the packets may arrive out of order.
If pkt1 is lost, and the order of packets received by sw2 is pkt2, pkt3, and the redundant packet, then sw2 doesn’t need to generate new packet, since the recovered pkt1 can be sent as the payload of the redundant packet. But if the order of the packets received by sw2 is the redundant packet, pkt2 and pkt3, then sw2 seems to generate a new packet when receive pkt3, since the redundant packet can only be stored in register.
My biggest question is that I don’t know how to make p4 switch generate a new packet and any help would be greatly appreciated, thanks a lot!
First, I will mention quickly that the options for implementing what you hope to do could be very significantly affected by which P4 target device you use. For example, I am not aware of an existing ASIC implementation of a P4-programmable device that allows you to store the payloads of received packets in a random access storage area, without sending those packets to a controller (which would significantly restrict the bandwidth possible), but if someone created such an ASIC, or implemented such features in an FPGA with a P4 compiler targeting it, a feature like that could make your job significantly easier.
For the rest of this message, I will restrict myself to the published capabilities of P4-programmable devices using the v1model architecture, or Tofino’s TNA architecture. As you mention, storing packet payload data in a P4 register array is possible, although it tends to be limited in Tofino to reading or writing somewhere in the range of 256 to 512 bytes of packet data in a single pass, as is done in the P4 code of this project: GitHub - p4lang/p4app-switchML: Switch ML Application
There are several ways to send out more packets than you receive, e.g. multicast and mirroring/cloning. So at sw1 you could have some logic that stores packet payload data, forwarding pkt1 and pkt2 normally, while recording their payload data, and when the 3rd packet arrives, record its data as well, forward pkt3, and then create a mirror of the packet that is sent to a recirculation port. After the mirror copy is recirculated, you can modify its payload to contain (pkt1 + pkt2 + pkt3), then forward that packet.