I want to write a P4 program which performs some header modifications. I want my P4 switch to change (Source IP, Source Port) of the arrived packet into its own IP address and a psudo Port number and relay the packet towards its ultimate destination.
When the response arrives, I want the switch to modify the destination IP & Port from its own IP and psudo Port to the original IP & Port.
This program needs the switch to have a valid IP address but I don’t know how to define IP for the switch in either P4 program or mininet.
There is an example to illustrate the logic of my P4 switch:
assume IP address of the switch is '15.15.15.15'
. packet comes from ('20.20.20.20', 20000)
to ('30.30.30.30', 80)
. The switch must change it to ('15.15.15.15', some free port say 35000)
–> ('30.30.30.30', 80)
and writes the mapping (org Src IP,org Src Port) -> (Switch IP, Psudo Port)
somewhere (probably in one of its tables).
When the response arrives, its source is ('30.30.30.30', 80)
and its destination is ('15.15.15.15', 35000)
. The switch must change the destination into ('20.20.20.20', 20000)
and send it the the original source.
Please provide me some help to define IP for the switch or do this functionality in an alternative way.