title: Ping via linux routing table not working [OR] how is this expected?
body: <h2>Long question in short:</h2>
  <blockquote>
  <p>Ping over <code>r1-r4-r2</code> path works using <code>10.0.1.*</code> or <code>10.0.2.*</code> IP addresses, but fails if we alter the path to <code>r1-r3-r2</code> using <code>1.0.0.*</code> or <code>1.0.1.*</code> IP addresses for the exactly same packets (except for the fact that packets' <code>src</code> and <code>dst</code> IP fields are changed from <code>10.*</code> to <code>1.*</code> and vice-versa at <code>s1</code> and <code>s2</code> respectively). Why?</p>
  </blockquote>
  <hr />
  <h2>Question in detail:</h2>
  <p>I have a small topology as below</p>
  <pre><code> h1 -- s1 -- r1 -- r4 -- r2 -- s2 -- h2
                \         /
                 \       /
                  \     /
                    r3
  </code></pre>
  <p>The <code>s</code>'s are OpenvSwitch instances while <code>r</code>'s are Ubuntu 16 Linux machines.</p>
  <p>IP Addresses are:</p>
  <pre><code>h1-eth0 - 10.0.1.10/24
  s1      - 10.0.1.50/24
  h2-eth0 - 10.0.2.10/24
  s2      - 10.0.2.50/24
  r1-eth0 - 10.0.1.1/24
  r1-eth1 - 10.0.11.2/24
  r1-eth2 - 10.0.12.2/24
  r2-eth0 - 10.0.2.1/24
  r2-eth1 - 10.0.13.1/24
  r2-eth2 - 10.0.5.1/24
  r3-eth0 - 10.0.12.1/24
  r3-eth1 - 10.0.5.2/24
  r4-eth0 - 10.0.11.1/24
  r4-eth1 - 10.0.13.2/24
  </code></pre>
  <p>As you can see, there are two similar paths between r1 and r2. I add the following static entries.</p>
  <p><strong>r1</strong></p>
  <p><code>sudo ip route add 10.0.2.0/24 via 10.0.11.1</code></p>
  <p><strong>r2</strong></p>
  <p><code>sudo ip route add 10.0.1.0/24 via 10.0.13.2</code></p>
  <p><strong>r4</strong></p>
  <pre><code>sudo ip route add 10.0.1.0/24 via 10.0.11.2
  sudo ip route add 10.0.2.0/24 via 10.0.13.1
  </code></pre>
  <p>The ping between h1 and h2 works as expected. Now, since the switches are OVS (and thus are OpenFlow-enabled) I install entries in s1 to <em>map the destination IPs to a different subnet</em>.</p>
  <blockquote>
  <p>i.e. the IP 10.0.1.10 would be mapped to 1.0.0.10 while the IP 10.0.2.10 would be mapped to 1.0.1.10 when such a packet is received at s1, while the destination IPs would be mapped back to original at s2.</p>
  </blockquote>
  <p>(I have checked that these entries are indeed correct and are working as expected. Also I have added this entry only to match ICMP packets). Similar procedure would be done when ping reply is sent by h1.</p>
  <p>Along with these, I install static routes in the routers to route these IPs.</p>
  <p><strong>r1</strong></p>
  <pre><code>sudo ip route add 1.0.0.0/24 via 10.0.1.50
  sudo ip route add 1.0.1.0/24 via 10.0.12.1
  </code></pre>
  <p><strong>r2</strong></p>
  <pre><code>sudo ip route add 1.0.0.0/24 via 10.0.5.2
  sudo ip route add 1.0.1.0/24 via 10.0.2.50
  </code></pre>
  <p><strong>r3</strong></p>
  <pre><code>sudo ip route add 1.0.0.0/24 via 10.0.12.2
  sudo ip route add 1.0.1.0/24 via 10.0.5.1
  </code></pre>
  <p>Now if I ping h1 from h2, the packet starts with destination IP 10.0.1.10, which is mapped to 1.0.0.10 at s2, r2 routes this and sends it to r3, r3 routes it and sends to r1. <strong>But r1, even after receiving the packet at one interface and having the matching entry in the Linux routing table does not route and forward packet.</strong></p>
  <p>Even <code>ip route get</code> outputs the correct port to which the packet should be forwarded. There are no firewall entries in <code>ip tables</code> as well.</p>
  <hr />
  <h3>Some additional information:</h3>
  <ul>
  <li><p>If I change the newly added routing entries to use the original path
  of <code>r1-r4-r2</code> (i.e., we route on this path with mapped ip's) , it behaves as expected and the ping works as expected.</p>
  </li>
  <li><p>Alternatively, if I change the old routing entries for 10.0.2.0/24 in r1 and<br />
  10.0.1.0/24 in r2 (which now ideally don't even have to be matched by the new
  packets as their Destination IPs are in 1.0.0.* range or 1.0.1.* only) to use
  the new path <code>r1-r3-r4</code> along with this mapped-IP packets, the ping between
  r2 and r1 works as  expected.</p>
  </li>
  </ul>
  <h3>Details that may be required:</h3>
  <p>The final routing tables are as follows:</p>
  <p><strong>r1</strong></p>
  <pre><code>Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
  0.0.0.0         10.0.11.1       0.0.0.0         UG    0      0        0 eth1
  1.0.0.0         10.0.1.10       255.255.255.0   UG    0      0        0 eth0
  1.0.1.0         10.0.12.1       255.255.255.0   UG    0      0        0 eth2
  10.0.1.0        0.0.0.0         255.255.255.0   U     1      0        0 eth0
  10.0.2.0        10.0.11.1       255.255.255.0   UG    0      0        0 eth1
  10.0.11.0       0.0.0.0         255.255.255.0   U     1      0        0 eth1
  10.0.12.0       0.0.0.0         255.255.255.0   U     1      0        0 eth2
  </code></pre>
  <p><strong>r2</strong></p>
  <pre><code>Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
  0.0.0.0         10.0.13.2       0.0.0.0         UG    0      0        0 eth1
  1.0.0.0         10.0.5.2        255.255.255.0   UG    0      0        0 eth1
  1.0.1.0         10.0.2.50       255.255.255.0   UG    0      0        0 eth0
  10.0.1.0        10.0.13.2       255.255.255.0   UG    0      0        0 eth1
  10.0.2.0        0.0.0.0         255.255.255.0   U     1      0        0 eth0
  10.0.5.0        0.0.0.0         255.255.255.0   U     1      0        0 eth2
  10.0.13.0       0.0.0.0         255.255.255.0   U     1      0        0 eth1
  </code></pre>
  <p><strong>r3</strong></p>
  <pre><code>Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
  0.0.0.0         10.0.5.1        0.0.0.0         UG    0      0        0 eth1
  1.0.0.0         10.0.12.2       255.255.255.0   UG    0      0        0 eth0
  1.0.1.0         10.0.5.1        255.255.255.0   UG    0      0        0 eth1
  10.0.1.0        10.0.12.2       255.255.255.0   UG    0      0        0 eth0
  10.0.2.0        10.0.5.1        255.255.255.0   U     1      0       0 eth1
  10.0.5.0        0.0.0.0         255.255.255.0   U     1      0        0 eth1
  10.0.12.0       0.0.0.0         255.255.255.0   U     1      0        0 eth0
  </code></pre>
  <p><strong>r4</strong></p>
  <pre><code>Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
  0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 eth4
  1.0.0.0         10.0.11.2       255.255.255.0   UG    0      0        0 eth0
  1.0.1.0         10.0.13.1       255.255.255.0   UG    0      0        0 eth1
  10.0.1.0        10.0.11.2       255.255.255.0   UG    0      0        0 eth0
  10.0.2.0        10.0.13.1       255.255.255.0   UG    0      0        0 eth1
  10.0.11.0       0.0.0.0         255.255.255.0   U     1      0        0 eth0
  10.0.13.0       0.0.0.0         255.255.255.0   U     1      0        0 eth1
  192.168.0.0     0.0.0.0         255.255.255.0   U     1      0        0 eth4
  </code></pre>
  <p>Note: 192.168.0.* is a subnet connected to outside Internet.</p>
  <p><strong>What do you think is the problem ? I am completely baffled looking at this problem.</strong></p>