How can i set next hop of nodes in NS2?

357 views Asked by At

I have a sensor field with dimension 200*200. I choose nearest node to center of field as a cluster head. My goal is that data of sensors forward to cluster head and cluster head forward data to sink node. I want cluster head become next hop of any sensor nodes (apart from sink node) in field. How do i do that? Thanks

1

There are 1 answers

0
wolfhammer On

I don't know ns2 but if there is a forwarding command then it should be just a matter of looping the nodes and running the forward command. Here's some pseudo code.

set head_x 7
set head_y 8

# get node at head_y head_x as head_node
# tell head to forward to sinc node

for {set y 0} {$y < 200} {incr y} {

    for {set x 0} {$x < 200} {incr x} {

        if {$x != $head_x && $y != $head_y} {
            # tell node $y $x to forward to $head_node
        }

    }
}