I have Ubuntu 16.04 LTS with hwe kernel 4.13.0-39-generic. I configure the veth pair in the default network namespace as follows:
$ sudo ip link add h1-eth0 type veth peer name h2-eth0
$ sudo ip link set dev h1-eth0 up
$ sudo ip link set dev h2-eth0 up
$ sudo ip addr add 10.0.0.1/24 dev h1-eth0
$ sudo ip addr add 10.0.0.2/24 dev h2-eth0
Here is the settings which I get after the above configuration:
$ ifconfig
...
h1-eth0 Link encap:Ethernet HWaddr ea:ee:1e:bb:66:55
inet addr:10.0.0.1 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
...
h2-eth0 Link encap:Ethernet HWaddr ba:aa:99:77:ff:78
inet addr:10.0.0.2 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
...
$ ip route show
10.0.0.0/24 dev h1-eth0 proto kernel scope link src 10.0.0.1
10.0.0.0/24 dev h2-eth0 proto kernel scope link src 10.0.0.2
...
Now I can ping one interface from another as following:
$ ping -I 10.0.0.1 -c1 10.0.0.2
PING 10.0.0.2 (10.0.0.2) from 10.0.0.1 : 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=0.046 ms
--- 10.0.0.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.046/0.046/0.046/0.000 ms
But the first problem is that ping fails when I try to ping using the name of the interface, rather than the ip address:
$ ping -I h1-eth0 -c1 10.0.0.2
PING 10.0.0.2 (10.0.0.2) from 10.0.0.1 h1-eth0: 56(84) bytes of data.
From 10.0.0.1 icmp_seq=1 Destination Host Unreachable
--- 10.0.0.2 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
How can this be a problem if h1-eth0 has ip address 10.0.0.1?
The second problem is, I believe, related. I configure the interfaces as following:
$ sudo tc qdisc add dev h1-eth0 root netem delay 60ms
$ sudo tc qdisc add dev h2-eth0 root netem delay 60ms
$ tc qdisc show
qdisc netem 8006: dev h2-eth0 root refcnt 2 limit 1000 delay 60.0ms
qdisc netem 8005: dev h1-eth0 root refcnt 2 limit 1000 delay 60.0ms
Now I ping again with the delay:
$ ping -I 10.0.0.1 -c4 10.0.0.2
PING 10.0.0.2 (10.0.0.2) from 10.0.0.1 : 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=0.033 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.034 ms
64 bytes from 10.0.0.2: icmp_seq=3 ttl=64 time=0.059 ms
64 bytes from 10.0.0.2: icmp_seq=4 ttl=64 time=0.027 ms
--- 10.0.0.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3063ms
rtt min/avg/max/mdev = 0.027/0.038/0.059/0.013 ms
And it can be seen that the rtt is not expected 60ms*2=120ms. So it looks like tc qdisc netem does not work for my interfaces.
So overall, I see that my configuration is somehow broken.