next up previous contents index
Next: 23.2 Other Configuration Mechanisms Up: 23.1 The Interface to Previous: Preference Assignment and Link Cost Assignment and Control

In the currently implemented route protocols, the metric of a route to a destination, at a node, is the cost to reach the destination from that node. It is possible to change the link costs at each of the links. The instance procedure []cost../ns-2/route-proto.tclSimulator::cost is invoked as $ns cost node1 node2 cost, and sets the cost of the link from node1 to node2 to cost.
        $ns cost $n1 $n2 10        # set cost of link \textbf{from} $n1 \textbf{to} $n2 to 10;
        $ns cost $n2 $n1  5        # set cost of link in reverse direction to 5;
        [$ns link $n1 $n2] cost?   # query cost of link from $n1 to $n2;
        [$ns link $n2 $n1] cost?   # query cost of link in reverse direction;
Notice that the procedure sets the cost along one direction only. Similarly, the procedure []cost?../ns-2/route-proto.tclLink::cost? returns the cost of traversing the specified unidirectional link. The default cost of a link is 1.