router algorithm