Generalized p4 code