##
#
# Comparison of algorithms.
#
# Copyright 2007-2008, Freie Universitaet Berlin. All rights reserved.
# Please refer to the COPYING file for detailed licensing information.
#
# Author: Georg Wittenburg
#
# $Id: algcmp.tcl 2686 2008-06-26 10:30:01Z wittenbu $
#
##



source common/config.tcl

# Number of mobile nodes.
set val(nn)	200

# Size of topography (m).
set val(x)	3000
set val(y)	3000

# Simulation duration and expetected time of completion (s).
set simulation_duration	7200.0



source common/header.tcl

# Create, initialize and connect nodes, agents and applications.
for {set i 0} {$i < $val(nn)} {incr i} {
	set node_($i) [$ns_ node]
	$node_($i) random-motion 0		;# Disable random motion
	$god_ new_node $node_($i)
	$ns_ initial_node_pos $node_($i) 10

	set agent_($i) [new Agent/MessagePassing]
	set application_($i) [new Application/C]
	$node_($i) attach $agent_($i)
	$application_($i) attach-agent $agent_($i)
	$application_($i) seed heuristic 0	;# Enable heuristic random seed in application
	$application_($i) PLACEMENT_set_algorithm none
#	$application_($i) PLACEMENT_set_algorithm linkpull_migration
#	$application_($i) PLACEMENT_set_algorithm peerpull_migration
#	$application_($i) PLACEMENT_set_algorithm tree-topology_migration
#	$application_($i) PLACEMENT_set_algorithm simple_heuristic
	$ns_ at [$rng_ uniform $start_phase_begin $start_phase_end] "$application_($i) start"
	$ns_ at [$rng_ uniform $stop_phase_begin $stop_phase_end] "$application_($i) stop"
	$ns_ at $finalize_phase_begin "$application_($i) finalize"
}

# Place nodes by ID in the four quadrants.
for {set i 0} {$i < 50} {incr i} {
	$node_($i) set X_ [$rng_ uniform 0 1500]
	$node_($i) set Y_ [$rng_ uniform 0 1500]
	$node_($i) set Z_ 0
}
for {set i 50} {$i < 100} {incr i} {
	$node_($i) set X_ [$rng_ uniform 1500 3000]
	$node_($i) set Y_ [$rng_ uniform 0 1500]
	$node_($i) set Z_ 0
}
for {set i 100} {$i < 150} {incr i} {
	$node_($i) set X_ [$rng_ uniform 0 1500]
	$node_($i) set Y_ [$rng_ uniform 1500 3000]
	$node_($i) set Z_ 0
}
for {set i 150} {$i < 200} {incr i} {
	$node_($i) set X_ [$rng_ uniform 1500 3000]
	$node_($i) set Y_ [$rng_ uniform 1500 3000]
	$node_($i) set Z_ 0
}



# Service requests per node per second.
set request_frequency %%request_frequency%%

# Number of times the active region is to shift during the simulation.
set active_region_shifts %%active_region_shifts%%

# Start service "srv_A" on node #0.
$ns_ at $simulation_begin "$application_(0) SERVICE_create_service srv_A 4096"

set active_phase_duration [expr $simulatio_duration / ($active_region_shifts + 1)]
set current_start_node 0
for {set phase 0} {$phase <= $active_region_shifts} {incr phase} {
	set current_phase_begin [expr ($active_phase_duration * $phase) + $simulation_begin]
	set current_phase_end [expr $current_phase_begin + $active_phase_duration]
	for {set t $current_phase_begin} {$t < $current_phase_end} {set t [expr $t + (1.0 / $request_frequency)]} {
		for {set node $current_start_node} {$node < [expr $current_start_node + 50]} {incr node} {
			$ns_ at [$rng_ uniform $t [expr $t + (1.0 / $request_frequency)]] "$application_($node) SERVICE_request_data srv_A 0x0000 1024"
		}
	}
	set current_start_node [expr ($current_start_node + 50) % 200]
}

# Start simulation.
puts "Starting Simulation..."
$ns_ run
