##
#
# Evaluate the impact of service placement by statically moving the position
# of a single server under different load conditions.
#
# Copyright 2007-2008, Freie Universitaet Berlin. All rights reserved.
# Please refer to the COPYING file for detailed licensing information.
#
# Author: Georg Wittenburg
#
# $Id: impact.tcl 2686 2008-06-26 10:30:01Z wittenbu $
#
##



source common/config.tcl

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

# Size of topography (m).
set val(x)	%%area_x%%
set val(y)	1000

# Simulation duration and expetected time of completion (s).
set simulation_duration	3600.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) 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
	$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 %%location_factor%%

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

# 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]

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

# 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"
	}
}

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