In this paper the variation principles from theoretical physics is considered that would describe the process of routing in computer networks. The total traffic which is currently served on all hops of the route has been chosen as the quantity to minimize. Universal metric function has been found for dynamic routing taking into account the packet loss effect. An attempt to derive the metric of the most popular dynamic routing protocols such as RIP, OSPF, EIGRP from universal metric was made.