Advanced Simulator Configuration

In this example we'll see some of the more advanced configuration features of the EmStar simulator, including how to create node-specific configurations, or configurations that vary over time.

Creating Default Node Configurations, and Overriding the Defaults

We saw in the basic simulator introduction how to create a simple simulation in which every node was randomly placed in an area of 20 square meters. The important part of the simulator configuration is the following block:
# The default for all nodes is for them to be at a random position in
# the field, power on, and using ../emrun/test/deptab as their emrun tab
node default {
        position = (random(0, 20), random(0, 20));
        power = on;

        # "emruntab" is the emrun config file that you want the nodes
        #to run.
        emruntab = ../link/examples/ping/pingtab;
}
This piece of the simconfig is called a node block. Although the basic simconfig example had only a single node block, a simconfig can have any number of node blocks. Node blocks that appear later in the file have precedence over earlier blocks.

Every node block starts with a node specifier, which can be one of four types:

All of these types of node blocks can be used in combination to create complex configurations. Later node blocks take precedence over earlier ones. So, for example, consider the following simulator configuration:
num-nodes = 10;
field-size = (100, 100);

node default {
        position = (random(0, 100), random(0, 100));
        power = on;
        emruntab = ../some-path/emrun-configuration-file;
}

# Nodes 6 through 10 are special: they are randomly placed near the
# center of the 100m field instead of uniformly scattered
node 6-10 {
        position = (random(40, 60), random(40, 60));
}

# We also pick one random node to go exactly in the center
node random(1, 10) {
        position = (50, 50);
	emruntab = ../special-software
}
In this configuration, the default for all 10 nodes is to be placed randomly in the 100-meter field, powered on, and using a standard emrun configuration file. We then override nodes 6 through 10 to be placed randomly within a smaller area between 40 and 60 meters. Finally, we pick one random node to be placed at exactly (50, 50), and use a different emrun configuration file.

Node blocks can override all or only some of the directives in earlier blocks. Note that in this example, the node block for nodes 6-10 left the standard emruntab intact, while the randomly-picked node overrode the default emruntab. Both of the later node blocks retained the default "power=on".

We can test the configuration using "emsim -t configfile", and the output looks something like this:

Node On/Off   Position (m)      EmRun Configuration   
---- ------ ----------------  ------------------------
  1    On   ( 32.87,  67.81)  ../some-path/emrun-configuration-file
  2    On   ( 50.00,  50.00)  ../special-software
  3    On   ( 62.60,  63.80)  ../some-path/emrun-configuration-file
  4    On   ( 94.16,  28.86)  ../some-path/emrun-configuration-file
  5    On   ( 80.75,  57.29)  ../some-path/emrun-configuration-file
  6    On   ( 50.63,  49.76)  ../some-path/emrun-configuration-file
  7    On   ( 57.85,  55.20)  ../some-path/emrun-configuration-file
  8    On   ( 53.40,  51.75)  ../some-path/emrun-configuration-file
  9    On   ( 46.49,  56.17)  ../some-path/emrun-configuration-file
 10    On   ( 44.02,  42.63)  ../some-path/emrun-configuration-file
Sure enough, nodes 6 through 10 all lie within the range of 40 to 60 meters. And, in this case, node 2 was randomly picked as the node to go be placed at (50, 50) and run the special software. If we run "emsim -t configfile" again, we'll see different random numbers picked:
Node On/Off   Position (m)      EmRun Configuration   
---- ------ ----------------  ------------------------
  1    On   ( 57.17,  67.40)  ../some-path/emrun-configuration-file
  2    On   (  3.93,  70.10)  ../some-path/emrun-configuration-file
  3    On   ( 84.82,  53.10)  ../some-path/emrun-configuration-file
  4    On   (  1.81,  88.91)  ../some-path/emrun-configuration-file
  5    On   ( 86.71,  65.85)  ../some-path/emrun-configuration-file
  6    On   ( 47.25,  44.11)  ../some-path/emrun-configuration-file
  7    On   ( 50.00,  50.00)  ../special-software
  8    On   ( 45.33,  54.38)  ../some-path/emrun-configuration-file
  9    On   ( 44.72,  58.01)  ../some-path/emrun-configuration-file
 10    On   ( 43.82,  55.23)  ../some-path/emrun-configuration-file
In this case, node 7 was picked to go in the center.

Time Blocks

The simulator allows time-varying configurations to be specified using time blocks. A time block is a group of node blocks, just as were described above, but that are applied some time after the simulation has started.

The time may be specified as any combination of hours, minutes and seconds, using "h" to indicate hours, "m" for minutes, and "s" for seconds. For example:

The following simple simconfig demonstrates a time block:

num-nodes = 10;
field-size = (100, 100);

node default {
        position = (random(0, 100), random(0, 100));
        power = on;
        emruntab = ../some-path/emrun-configuration-file;
}

time 30s {
        node 10 {
                position = (random(0, 100), random(0, 100));

        }
}
This configuration starts out the same as the earlier examples: all nodes are placed in a random location in our 100x100 meter field. However, 30 seconds after the simulation starts, node 10 moves to a different random location.

Using "emsim -t" we can see what the simulator might do if it were run using this simconfig:


Simulator Configuration State 0
Valid from beginning of simulation to t=30  *** ACTIVE NOW ***

Node On/Off   Position (m)      EmRun Configuration   
---- ------ ----------------  ------------------------
  1    On   (  2.98,  80.46)  ../some-path/emrun-configuration-file
  2    On   ( 95.88,  70.25)  ../some-path/emrun-configuration-file
  3    On   (  7.08,   3.42)  ../some-path/emrun-configuration-file
  4    On   ( 44.97,  76.29)  ../some-path/emrun-configuration-file
  5    On   ( 91.90,  53.21)  ../some-path/emrun-configuration-file
  6    On   ( 52.60,  65.48)  ../some-path/emrun-configuration-file
  7    On   ( 49.75,  53.02)  ../some-path/emrun-configuration-file
  8    On   ( 21.48,  17.68)  ../some-path/emrun-configuration-file
  9    On   ( 13.15,   7.57)  ../some-path/emrun-configuration-file
 10    On   ( 67.24,  88.75)  ../some-path/emrun-configuration-file

****

Simulator Configuration State 1
Valid from t=30 to end of simulation

Node On/Off   Position (m)      EmRun Configuration   
---- ------ ----------------  ------------------------
  1    On   (  2.98,  80.46)  ../some-path/emrun-configuration-file
  2    On   ( 95.88,  70.25)  ../some-path/emrun-configuration-file
  3    On   (  7.08,   3.42)  ../some-path/emrun-configuration-file
  4    On   ( 44.97,  76.29)  ../some-path/emrun-configuration-file
  5    On   ( 91.90,  53.21)  ../some-path/emrun-configuration-file
  6    On   ( 52.60,  65.48)  ../some-path/emrun-configuration-file
  7    On   ( 49.75,  53.02)  ../some-path/emrun-configuration-file
  8    On   ( 21.48,  17.68)  ../some-path/emrun-configuration-file
  9    On   ( 13.15,   7.57)  ../some-path/emrun-configuration-file
 10    On   ( 48.68,  61.52)  ../some-path/emrun-configuration-file

****
In this case, there are now two simulation states: 0 and 1. As the status output indicates, State 0 is active from t=0 to t=30; State 1 is active from t=30 to the end of the simulation. The two configurations are identical except that node 10 has changed its position. (Existing radio propagation models only support "instantaneous" mobility models, i.e. the node instantly zaps from its old location to its new one. However, it's possible to write a simulator component that supports continuous mobility, if needed.)

An interesting use of timeblocks is to specify "power=off". This actually causes the node to "die" -- that is, the simulator will shut down the simulated node when the time arrives. For example, consider this more complex example, in emstar/emrun/examples/sim-syntax-example:

# 10 node simulation (nodes are numbered from 1-10)
num-nodes = 10;

# Physical size of the simulated field is 100m^2
field-size = (100, 100);

# We want to simulate having MoteNIC available
sim-component = "sim/sim_mote -m circle";

# The default for all nodes is for them to be at a random position in
# the field, power on, and using "../some-path/emrun-configuration-file"
# as their emrun configuration file.
node default {
        position = (random(0, 100), random(0, 100));
        power = on;
        emruntab = ../some-path/emrun-configuration-file;
}


# Nodes 6 through 10 are special: they run different software.
node 6-10 {
        emruntab = ../some-path/special-config-file;
}

# Node 10 is very special: in addition to running the "special-config",
# it also is in the center of the field.
node 10 {
        position = (50, 50);
}

# We'd also like to put a random node in a random place within a 1m by
# 1m square in the center of the field, and have it run different
# software.  Note that since this comes after the special-config line,
# it overrides it.
node random(1, 10) {
        emruntab = center-square-softare;
        position = (random(49, 50), random(49, 50));
}


###### Time Blocks (changes to the simulator configuration over time) #######


# 10 seconds into the simulation, shutdown nodes 3-6
time 10 {
        node 3-6 {
                power=off;
        }
}

# 20 seconds into the simulation, shut down a random node and move
# node 1 to a new location
time 20 {
        node 1 {
	        position = (4, 4);
	}

        node random(1, 10) {
                power = off;
        }
}

# 2 minutes into the simulation, turn node 5 back on.
time 2m {
        node 5 { power=on; }
}
And, here is the resulting schedule:

Simulator Configuration State 0
Valid from beginning of simulation to t=10  *** ACTIVE NOW ***

Node On/Off   Position (m)      EmRun Configuration   
---- ------ ----------------  ------------------------
  1    On   ( 83.94,  95.73)  ../some-path/emrun-configuration-file
  2    On   ( 18.40,  84.42)  ../some-path/emrun-configuration-file
  3    On   ( 62.69,  75.52)  ../some-path/emrun-configuration-file
  4    On   ( 35.04,   9.70)  ../some-path/emrun-configuration-file
  5    On   ( 68.35,  59.64)  ../some-path/emrun-configuration-file
  6    On   ( 49.62,  49.89)  center-square-softare
  7    On   ( 33.69,  54.49)  ../some-path/special-config-file
  8    On   ( 38.51,  51.26)  ../some-path/special-config-file
  9    On   ( 45.54,  75.96)  ../some-path/special-config-file
 10    On   ( 50.00,  50.00)  ../some-path/special-config-file

****

Simulator Configuration State 1
Valid from t=10 to t=20

Node On/Off   Position (m)      EmRun Configuration   
---- ------ ----------------  ------------------------
  1    On   ( 83.94,  95.73)  ../some-path/emrun-configuration-file
  2    On   ( 18.40,  84.42)  ../some-path/emrun-configuration-file
  3   Off   ( 62.69,  75.52)  ../some-path/emrun-configuration-file
  4   Off   ( 35.04,   9.70)  ../some-path/emrun-configuration-file
  5   Off   ( 68.35,  59.64)  ../some-path/emrun-configuration-file
  6   Off   ( 49.62,  49.89)  center-square-softare
  7    On   ( 33.69,  54.49)  ../some-path/special-config-file
  8    On   ( 38.51,  51.26)  ../some-path/special-config-file
  9    On   ( 45.54,  75.96)  ../some-path/special-config-file
 10    On   ( 50.00,  50.00)  ../some-path/special-config-file

****

Simulator Configuration State 2
Valid from t=20 to t=120

Node On/Off   Position (m)      EmRun Configuration   
---- ------ ----------------  ------------------------
  1    On   (  4.00,   4.00)  ../some-path/emrun-configuration-file
  2    On   ( 18.40,  84.42)  ../some-path/emrun-configuration-file
  3   Off   ( 62.69,  75.52)  ../some-path/emrun-configuration-file
  4   Off   ( 35.04,   9.70)  ../some-path/emrun-configuration-file
  5   Off   ( 68.35,  59.64)  ../some-path/emrun-configuration-file
  6   Off   ( 49.62,  49.89)  center-square-softare
  7   Off   ( 33.69,  54.49)  ../some-path/special-config-file
  8    On   ( 38.51,  51.26)  ../some-path/special-config-file
  9    On   ( 45.54,  75.96)  ../some-path/special-config-file
 10    On   ( 50.00,  50.00)  ../some-path/special-config-file

****

Simulator Configuration State 3
Valid from t=120 to end of simulation

Node On/Off   Position (m)      EmRun Configuration   
---- ------ ----------------  ------------------------
  1    On   (  4.00,   4.00)  ../some-path/emrun-configuration-file
  2    On   ( 18.40,  84.42)  ../some-path/emrun-configuration-file
  3   Off   ( 62.69,  75.52)  ../some-path/emrun-configuration-file
  4   Off   ( 35.04,   9.70)  ../some-path/emrun-configuration-file
  5    On   ( 68.35,  59.64)  ../some-path/emrun-configuration-file
  6   Off   ( 49.62,  49.89)  center-square-softare
  7   Off   ( 33.69,  54.49)  ../some-path/special-config-file
  8    On   ( 38.51,  51.26)  ../some-path/special-config-file
  9    On   ( 45.54,  75.96)  ../some-path/special-config-file
 10    On   ( 50.00,  50.00)  ../some-path/special-config-file

****

Simconfigs can have any number of time blocks. Each time block can have any number of node blocks, and each node block can have any number of simulation directives.



Last modified by jelson, 18 February 2003