I have published a very simple example of a P4 program, plus a controller written in Python, that demonstrates the switch sending PacketIn messages to the controller, where the controller reacts to those messages by adding new table entries into the switch.
The P4 code is written to run with the v1model architecture, and has been tested on the BMv2 software switch (aka behavioral-model).
You can find it, and instructions for running it, here: p4-guide/flowcache at master · jafingerhut/p4-guide · GitHub