# Create a new simulation environment set ns [new Simulator] # Enable OLSR routing $ns olsr # Create nodes set node(0) [$ns node] set node(1) [$ns node] set node(2) [$ns node] set node(3) [$ns node] # Create a wireless channel set channel [new Channel/WirelessChannel] # Create a propagation loss model set loss [new Propagation/TwoRayGround] # Create a wireless physical layer set phy [new Phy/WirelessPhy] # Create a wireless MAC layer set mac [new Mac/802_11] # Create a wireless device set dev [new NetDeviceContainer] $dev Create $phy $mac # Install the device on the nodes $dev Install $node(0) $channel $dev Install $node(1) $channel $dev Install $node(2) $channel $dev Install $node(3) $channel # Set up the mobility model set mobility [new MobilityModel/RandomWalk] $mobility SetAttribute("Bounds", "0|200|0|200|0|0") # Install the mobility model on the nodes $ns initial_node_pos $node(0) 50 100 0 $ns initial_node_pos $node(1) 150 100 0 $ns initial_node_pos $node(2) 100 50 0 $ns initial_node_pos $node(3) 100 150 0 # Set up OLSR routing set olsr [new Agent/OLSR] $olsr SetDebugLevel(2) # Install OLSR on the nodes $ns attach-agent $node(0) $olsr $ns attach-agent $node(1) $olsr $ns attach-agent $node(2) $olsr $ns attach-agent $node(3) $olsr # Create a UDP traffic source and sink set udp [new Agent/UDP] $ns attach-agent $node(0) $udp set null [new Agent/Null] $ns attach-agent $node(3) $null set sink [new Agent/UDP] $ns attach-agent $node(3) $sink # Create a traffic model set traffic [new Application/Traffic/Constant] $traffic attach-agent $udp $traffic SetType(1) $traffic SetPacketSize(1024) $traffic SetRate(1Mbps) $traffic SetMaxBytes(1000000) # Connect the traffic source and sink $ns connect $udp $sink # Create a trace file for mobility set tracefile [open "olsr-mobility.tr" w] $mobility set_tracefile $tracefile # Schedule events $ns at 0.0 "$mobility resume" $ns at 5.0 "$traffic start" $ns at 20.0 "$traffic stop" $ns at 25.0 "finish" # Define the 'finish' procedure proc finish {} { global ns tracefile $ns flush-trace close $tracefile exec nam olsr-mobility.nam & exit 0 } # Run the simulation $ns run