##
#
# Test script.
#
# Copyright 2007-2008, Freie Universitaet Berlin. All rights reserved.
# Please refer to the COPYING file for detailed licensing information.
#
# Author: Georg Wittenburg
#
# $Id: test.tcl 2688 2008-06-26 11:59:33Z wittenbu $
#
##



source common/config.tcl

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

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

# Simulation duration and expetected time of completion (s).
set simulation_duration	3600.0		;# 1 hour



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) set X_ [$rng_ uniform 0 $val(x)]
	$node_($i) set Y_ [$rng_ uniform 0 $val(y)]
	$node_($i) set Z_ 0
	$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"
}



# Location factor (0.0 -> worst; 1.0 -> best).
set location_factor 1.0

# Service requests per node per second.
set request_frequency 0.01

# Active node ratio (0.0 -> all nodes quiet; 1.0 -> all nodes active).
set activity_factor 1.0

# Place node #0 relative to the middle of the simulation area.
$node_(0) set X_ [expr $val(x) / 2 * $location_factor]
$node_(0) set Y_ [expr $val(y) / 2 * $location_factor]

# Place node #1 in the middle of the simulation area.
#$node_(1) set X_ [expr $val(x) / 2]
#$node_(1) set Y_ [expr $val(y) / 2]

# Construct network graphs with node #0 as coordinator.
#$ns_ at $simulation_begin "$application_(15) GRAPHS_construct"

# Start service "srv_A" on node #0.
#$ns_ at $simulation_begin "$application_(0) SERVICE_create_service srv_A 4096"
#$ns_ at [expr $simulation_begin + 5] "$application_(0) SERVICE_is_local_service srv_A"

# Send a NOP to node #1.
#$ns_ at $simulation_begin "$application_(0) ICMP_send_nop 1"

# Broadcast a NOP to all nodes in the network.
$ns_ at $simulation_begin "$application_(0) ICMP_send_nop"

# Broadcast an echo request to all nodes in the one-hop neighborhood.
#$ns_ at $simulation_begin "$application_(0) ICMP_send_local_echo_request"

# Broadcast an echo request to all nodes in the network.
#$ns_ at $simulation_begin "$application_(0) ICMP_send_echo_request"

# Broadcast an echo request from all nodes to all nodes in the network.
#for {set i 0} {$i < $val(nn)} {incr i} {
#	$ns_ at [$rng_ uniform $simulation_begin $simulation_end] "$application_($i) ICMP_send_local_echo_request"
#	$ns_ at [$rng_ uniform $simulation_begin $simulation_end] "$application_($i) ICMP_send_echo_request"
#}

# Have node #1 locate service "srv_A"
#$ns_ at $simulation_begin "$application_(1) SLP_locate_service srv_A 1"

# Have all nodes in the network locate the service "srv_A".
#for {set i 1} {$i < $val(nn)} {incr i} {
#	$ns_ at [$rng_ uniform $simulation_begin $simulation_end] "$application_($i) SLP_locate_service srv_A 1"
#}

# Request some data from of "srv_A".
#$ns_ at $simulation_begin "$application_(1) SERVICE_request_data srv_A 0x0000 1024"

# Have all nodes in the network request data of "srv_A".
#for {set t $simulation_begin} {$t < [expr $simulation_end]} {set t [expr $t + (1.0 / $request_frequency)]} {
#	for {set i 0} {$i < [expr $val(nn) * $activity_factor]} {incr i} {
#		$ns_ at [$rng_ uniform $t [expr $t + (1.0 / $request_frequency)]] "$application_($i) SERVICE_request_data srv_A 0x0000 1024"
#	}
#}

# Update some data of "srv_A".
#$ns_ at $simulation_begin "$application_(1) SERVICE_update_data srv_A 0x0000 1024"

# Have all nodes in the network update data of "srv_A".
#for {set t $simulation_begin} {$t < [expr $simulation_end]} {set t [expr $t + (1.0 / $request_frequency)]} {
#	for {set i 0} {$i < $val(nn)} {incr i} {
#		$ns_ at [$rng_ uniform $t [expr $t + (1.0 / $request_frequency)]] "$application_($i) SERVICE_update_data srv_A 0x0000 1024"
#	}
#}

# Request a stream of "srv_A".
#$ns_ at $simulation_begin "$application_(1) SERVICE_request_stream srv_A 0x0000 1024 10.0 30.0"

# Have all nodes in the network request a stream of "srv_A".
#for {set i 0} {$i < $val(nn)} {incr i} {
#	$ns_ at [$rng_ uniform $simulation_begin [expr $simulation_begin + (1.0 / $request_frequency)]] "$application_($i) SERVICE_request_stream srv_A 0x0000 1024 10.0 [expr $simulation_duration - (1.0 / $request_frequency)]"
#}

# Replicate service "srv_A" from node #0 on node #1.
#$ns_ at [expr $simulation_begin + ($simulation_duration / 2)] "$application_(0) SERVICE_replicate_service srv_A 1"

# Migrate service "srv_A" from node #0 to node #1.
#$ns_ at [expr $simulation_begin + ($simulation_duration / 2)] "$application_(0) SERVICE_migrate_service srv_A 1"

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