I'm implementing some kind of router which has multiple internet connections, based on current throughput of those connections it would forward packets/frames using faster connection.
In order to test my implementation I have to have some actual packets to route. In order to generate some traffic I implemented IP packet fragmentation. I almost found myself implementing TCP reliable connection to generate some traffic. I tried to look for a way to generate some traffic and thought I would open socket connection from IP A on local machine to IP B on remote host. I would send some data on that connection so I wouldn't have to bother with packet generation.
And here is the problem, I must intercept those packets in order to route them in my router. I initially thought I would create some rule to forward every packet to IP B back to localhost, I would open raw socket on localhost and filter out all packets with destination IP B. I tried to make iptables rule: sudo iptables -t nat -A OUTPUT -d some_ip -j DNAT --to-destination 127.0.0.1 but as I found out it was changing destination IP address of packet, and I just wanted to intercept original packet in order to route it.
Do you have any idea how to generate some traffic that I could capture or how to configure iptables to forward packets going to specified IP back to host but preserving original destination IP address?
Clarification: The program I'm developing is distributed system, think of it as of few Raspberry Pis of which one is actual process routing packets and the rest are relays with dedicated internet connections, the router process chooses best relay to forward the packets. The processes across the system communicate via MPI communicator, the whole thing is implemented using MPI. So in a sense it's kind of software-router if that makes sense.