How to assign IP address to P4 Switches?
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.
Regarding the part of of your question about needing the switch to have a valid IP address, such things are typically done by having one or more tables where the entries have actions where one of the parameters is an IP address. The control plane code is responsible for installing appropriate entries with any desired IP addresses into those tables. Then the P4 program will not have any IP addresses hard-coded into it, but reads them when executing the action with those IP addresses as parameters.
Feel free to ask questions like this on P4 Zulip at https://p4lang.zulipchat.com, where there are a larger number of active readers and participants than you are likely to find on Github issues on this repository.
No follow-up for a while, so closing this issue. Feel free to re-open it if you believe you have related concerns, or just create a new issue.