Route Selection

Hi

I have a ROS that connected to 4 routers that advertise dgw via OSPF, my route table looks something like[admin@ybortr1] > /ip route pr # DST-ADDRESS PREF-SRC GATEWAY DISTANCE
0 ADo 0.0.0.0/0 10.31.17.3 110
10.31.18.3
10.31.18.2
10.31.17.2


Which gateway is ROS going to use ?? is it round robin or . I always thought it was lowest ip address, but I have been doing some tests and its not ..

You’re describing Equal Cost Multipath (ECMP). You have one route entry with multiple gateway addresses:

[admin@MikroTik] /ip route> print 
 #      DST-ADDRESS        PREF-SRC        GATEWAY            DISTANCE
 0 A S  0.0.0.0/0                          192.168.3.1               1
                                           192.168.2.1       
 1 ADC  192.168.2.0/24     192.168.2.2     ether2                    0
 2 ADC  192.168.3.0/24     192.168.3.2     ether1                    0

You can, instead, have multiple route entries covering the same destination prefix, in which case only one route at a time can be “active”. The active route is chosen first based on the distance metric, and if there is a tie with distance, then the manual states that route selection is undefined/arbitrary, and not based on the “lowest” gateway IP number:

[admin@MikroTik] /ip route> print 
 #      DST-ADDRESS        PREF-SRC        GATEWAY            DISTANCE
 0 A S  0.0.0.0/0                          192.168.3.1               1
 1   S  0.0.0.0/0                          192.168.2.1               1
 2 ADC  192.168.2.0/24     192.168.2.2     ether2                    0
 3 ADC  192.168.3.0/24     192.168.3.2     ether1                    0

With ECMP routes, my understanding is that in Linux, selection of gateway for any given flow or session is based on a hash of the source and destination IPs in the packets, not a round-robin algorithm. So traffic from one particular IP address to one particular IP address should tend to have an affinity for a particular gateway.

– Nathan

ECMP is what I have, the routes come from OSPF

Thanks for the info. I was tracking down an asymmetrical routing issue

you are right on affinity .. AFAIK.. this is the effect of route cache, already matched routes are reused on similar connections

it’s unclear to me which mechanism is behind the “hash or round robin like” on the first match

Thanks