See distance vector routing algorithm.