implementation of distance vector algorithm