1

I am wondering why tc command does not work as expected. I set the command like the following

tc qdisc add dev eno0 root handle 1:0 tbf rate 50mbit burst 25kb limit 250kb

where I'm expecting outbound communication is simulated over 50Mbps bandwidth. Now, I'm trying to let two processes communicate with each other on a same machine using local ip address (say, 192.168.0.4) associated with eno0.

In order to know the affect of the tc command. I used iperf command on two processes A and B.

At process A, I ran iperf -s.

At process B, I ran iperf -c 192.168.0.4.

However, the observed bandwidth rate is approximately 300Mbit/sec. (Not around 50Mbit/sec!). The machine is located under the router that can process 1Gbps at most. And, the LAN cable is capable to deal with enough bandwidth rate.

When I tried to do the same thing using two different machines under the same router where the role of process A is on another machine while the role of process B is on the machine having IP address 192.168.0.4, observed bandwidth is around 50Mbit/s.

How can I get 50Mbps simulation on the same machine?? Is it impossible to do that? Thank you very much!

user9414424
  • 171
  • 1
  • 4

1 Answers1

0

The same machine routes traffic from itself to itself locally, using the lo interface. It will not emit any packet on the wire (eno0) for this traffic. You could use the same rule, but on the lo interface instead, but more tweaking is needed: for example the default MTU of 65536 changes the tbf behaviour (found in logs: sch_tbf: burst 25600 is lower than device lo mtu (65550) !):

# ip link set lo mtu 1500
# tc qdisc add dev lo root handle 1:0 tbf rate 50mbit burst 25kb limit 250kb

Anyway there would be slight differences. For example, lo is a layer 3 interface and thus doesn't have Ethernet overhead, which will alter results.

You can use instead network namespaces to do more isolated simulation, example:

# ip netns add host1
# ip netns add host2
# ip -n host1 link add dev eno0 type veth peer netns host2 name eno0
# ip -n host1 link set lo up; ip -n host2 link set lo up
# ip -n host1 link set eno0 up; ip -n host2 link set eno0 up
# ip -n host1 address add 192.168.0.4/24 dev eno0
# ip -n host2 address add 192.168.0.5/24 dev eno0

# tc -n host2 qdisc add dev eno0 root handle 1:0 tbf rate 50mbit burst 25kb limit 250kb

Term1:

# ip netns exec host1 iperf -s

Term2:

# ip netns exec host2 iperf -c 192.168.0.4

If your goal is to involve actual external hardware, it's probably possible using macvlan interfaces in VEPA mode instead of veth interfaces, still in network namespaces. This probably requires configuration on the external switch (or router) too, and don't do IP collisions.

A.B
  • 11,090
  • 2
  • 24
  • 45