algorithm for ns2