# This is an example 'emruntab' that runs the UDP link driver and the
# ping daemon. Run it from the obj.i686-linux directory.
udpd {
type = daemon;
cmd = "link/udpd";
no-sim; # the simulator provides its own link-layer driver
}
pingd {
type = daemon;
waitfor = udpd;
cmd = "link/examples/pingd";
}
The emrun configuration specifies what the software stack is supposed
to look like, whether you're running in the simulator or in
reality. (Recall from the previous lesson that if you wanted to run
ping "for real", you'd just log into a few machines, and run "emrun
pingtab", where pingtab is the file above. Then, one one machine,
you'd type "ping" to run ping.)
Now, this time, we want to try running the ping daemon on a whole bunch of simulated nodes. We still need the emrun configuration file that describes what a single instance of the system stack is supposed to look like. But, in addition, we need a second configuration file for the simulator itself. This describes, for example, how many simulated nodes we want, and where they are geographically so that the channel model can determine which transmissions reach which receivers. And, a very important element of the simulator configuration is that it specifies a emrun configuration as part of the description of the simulated node.
In other words: when you are running in "reality", you run emrun directly, and give it the name of your emrun configuration file. When you are using the simulator, you give it the name a simulator configuration file. Part of that simulator configuration specifies an emrun configuration file. The simulator then runs n copies of emrun for you, using the emrun configuration file that you specified.
In the emstar/link/examples/ping directory is a file called ping-simconfig, which is a simulator specification for running ping. It looks like this:
# Allow number of nodes to be specified at the command-line as the
# first argument
num-nodes = $1;
# Physical size of the simulated field is 20 square meters
field-size = (20, 20);
# 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 ../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;
}
Note that you can use $1, $2, $3 etc, in a config file, and then
provide substitutions as command-line arguments when you run the
program. So, when using this configuration file, you'd pass an
argument to emsim. For exampling, typing "emrun/emsim
../link/examples/ping/ping-simconfig 10", the 10 gets substituted into
the config file in place of $1.
The "-m circle" argument to the mote sim component means we are using a trivial "8 meter deterministic circle" channel model. (Right now, Alberto Cerpa is working on a 2nd channel model empirically derived from his ASCENT experiments.) The "position = " declaration puts each mote in a random location within a 20m by 20m square. You can enumerate positions for nodes, as we'll see in the advanced lesson, but in this simplest example we just let the simulator pick the position of everything. The "emruntab" argument tells the simulator that each of the simulated nodes should be running the same pingd configuration as we used in real life.
GAMA:/home/jelson/projects/emstar/obj.i686-linux(5067) emrun/emsim -t ../link/examples/ping/ping-simconfig 10 Tue Feb 18 20:54:58.382: emrun/emsim: starting (simulator component) Simulator Configuration State 0 Valid from beginning of simulation to end of simulation *** ACTIVE NOW *** Node On/Off Position (m) EmRun Configuration ---- ------ ---------------- ------------------------ 1 On ( 18.82, 13.31) ../link/examples/ping/pingtab 2 On ( 11.51, 11.31) ../link/examples/ping/pingtab 3 On ( 16.63, 8.07) ../link/examples/ping/pingtab 4 On ( 8.88, 8.04) ../link/examples/ping/pingtab 5 On ( 19.76, 5.10) ../link/examples/ping/pingtab 6 On ( 15.30, 17.50) ../link/examples/ping/pingtab 7 On ( 10.77, 5.41) ../link/examples/ping/pingtab 8 On ( 1.82, 18.63) ../link/examples/ping/pingtab 9 On ( 11.61, 6.14) ../link/examples/ping/pingtab 10 On ( 0.39, 10.16) ../link/examples/ping/pingtab ****As expected, each node has a random position between 0 and 20 meters in both the X and Y dimensions. Of course, if we run the same command again, different random numbers will be picked.
setenv SIM_GROUP 5
emrun/emsim ../link/examples/ping/ping-simconfig 10
The SIM_GROUP environment variable can be set to any number, and is
used to separate your simulation from simulations that other users
might also be running on the computer at the time. If you're using
bash, you'll have a different syntax for setting environment
variables, e.g. "export SIM_GROUP=5". If you pick a group ID that
someone else is using, the simulator will refuse to run and tell you
to pick a different group ID.
In the following examples, we will assume that you picked group 5. Substitute your actual group ID (i.e. what you set SIM_GROUP to be) when trying this for yourself.
After running the commands above, you should see output that looks something like this example:
GAMA:/home/jelson/projects/emstar/obj.i686-linux(5062) emrun/emsim ../link/examples/ping/ping-simconfig 10 Tue Feb 18 20:47:33.421: emrun/emsim: starting (simulator component) Tue Feb 18 20:47:33.425: main: 10-node simulation starting (loglevel NOTICE) Tue Feb 18 20:47:33.425: sim-component-0 launched, pid 2397 Tue Feb 18 20:47:33.428: libchannel_config: using circle channel model Tue Feb 18 20:47:33.430: motesim_new_config: now simulating 10 motes Tue Feb 18 20:47:33.933: simulator state 0 (t=0) now current Tue Feb 18 20:47:33.933: node 1 powering ON Tue Feb 18 20:47:33.933: node 2 powering ON Tue Feb 18 20:47:33.933: node 3 powering ON Tue Feb 18 20:47:33.933: node 4 powering ON Tue Feb 18 20:47:33.933: node 5 powering ON Tue Feb 18 20:47:33.933: node 6 powering ON Tue Feb 18 20:47:33.933: node 7 powering ON Tue Feb 18 20:47:33.933: node 8 powering ON Tue Feb 18 20:47:33.933: node 9 powering ON Tue Feb 18 20:47:33.933: node 10 powering ON Tue Feb 18 20:47:33.933: sim-node-1 launched, pid 2398 Tue Feb 18 20:47:33.933: sim-node-2 launched, pid 2399 Tue Feb 18 20:47:33.934: sim-node-3 launched, pid 2400 Tue Feb 18 20:47:33.935: sim-node-4 launched, pid 2401 Tue Feb 18 20:47:33.935: sim-node-5 launched, pid 2402 Tue Feb 18 20:47:33.935: sim-node-6 launched, pid 2403 Tue Feb 18 20:47:33.936: sim-node-7 launched, pid 2404 Tue Feb 18 20:47:33.941: sim-node-8 launched, pid 2405 Tue Feb 18 20:47:33.941: sim-node-9 launched, pid 2406 Tue Feb 18 20:47:33.942: sim-node-10 launched, pid 2407After this bootup, you'll see the log messages being emitted by the user programs that are running as part of the simulation.
To stop the simulation, press Control-C.
For example, if we type "cat /dev/sim/group5/config", we can see the random positions that were picked for each node, as shown below. As we'll see in the advanced configuration lesson, it's possible to have these positions vary over time; the "ACTIVE NOW" indicator shows which configuration is current.
GAMA:/home/jelson/projects/emstar/obj.i686-linux(5051) cat /dev/sim/group5/config Simulator Configuration State 0 Valid from beginning of simulation to end of simulation *** ACTIVE NOW *** Node On/Off Position (m) EmRun Configuration ---- ------ ---------------- ------------------------ 1 On ( 14.83, 15.52) ../link/examples/ping/pingtab 2 On ( 5.17, 6.99) ../link/examples/ping/pingtab 3 On ( 8.92, 15.80) ../link/examples/ping/pingtab 4 On ( 19.66, 2.65) ../link/examples/ping/pingtab 5 On ( 5.59, 18.28) ../link/examples/ping/pingtab 6 On ( 4.21, 6.27) ../link/examples/ping/pingtab 7 On ( 14.18, 2.45) ../link/examples/ping/pingtab 8 On ( 8.22, 14.26) ../link/examples/ping/pingtab 9 On ( 4.67, 0.37) ../link/examples/ping/pingtab 10 On ( 14.61, 18.55) ../link/examples/ping/pingtab ****The information seen (above) by checking /dev/sim/group5/config is the same as we saw above, when running emsim in its "configuration test" mode. However, if a simulator configuration has random number picks, the /dev/sim/group5/config version gives the actual random values that were picked for the simulation currently running.
We can also check to make sure all the simulated "nodes" are running, by checking /dev/sim/group5/status. This is similar to the emrun status output we saw in the previous lesson.
GAMA:/home/jelson/projects/emstar/obj.i686-linux(5052) cat /dev/sim/group5/status Process Name Type Current Status Command ------------ -------- -------------- ------- sim-component-0 daemon pid 2277 sim/sim_mote -o NOTICE -m circle sim-node-1 daemon pid 2278 emrun/emrun -o NOTICE ../link/examples/ping/pingtab sim-node-2 daemon pid 2279 emrun/emrun -o NOTICE ../link/examples/ping/pingtab sim-node-3 daemon pid 2280 emrun/emrun -o NOTICE ../link/examples/ping/pingtab sim-node-4 daemon pid 2281 emrun/emrun -o NOTICE ../link/examples/ping/pingtab sim-node-5 daemon pid 2282 emrun/emrun -o NOTICE ../link/examples/ping/pingtab sim-node-6 daemon pid 2283 emrun/emrun -o NOTICE ../link/examples/ping/pingtab sim-node-7 daemon pid 2284 emrun/emrun -o NOTICE ../link/examples/ping/pingtab sim-node-8 daemon pid 2285 emrun/emrun -o NOTICE ../link/examples/ping/pingtab sim-node-9 daemon pid 2286 emrun/emrun -o NOTICE ../link/examples/ping/pingtab sim-node-10 daemon pid 2287 emrun/emrun -o NOTICE ../link/examples/ping/pingtab
It's also possible to check on the status of individual simulated nodes. All device files that would normally be under /dev on a regular node are moved into /dev/sim/groupXX/nodeYY when the node is being simulated, where XX is the group ID and YY is the node ID. For example, the "/dev/emrun/status" file that we'd normally see when running a non-simulated emrun is available as /dev/sim/group5/node4/emrun/status. This path indicates we are looking at a simulated emrun status, running on node 4 of a simulation in group 5. We can see this below:
GAMA:/home/jelson/projects/emstar/obj.i686-linux(5054) cat /dev/sim/group5/node4/emrun/status Process Name Type Current Status Command ------------ -------- -------------- ------- udpd dead not simulated link/udpd pingd daemon pid 2289 link/examples/pingdThis is the normal emrun status output, but in a different place -- under /dev/sim. There are 10 copies of /dev/emrun/status, one for each simulated node: /dev/sim/group5/node1/emrun/status, /dev/sim/group5/node2/emrun/status, etc. Note that UDPd, which is part of the normal non-simulated configuration, is disabled when running as part of the simulator, since the channel simulator takes the place of all the link-layer device drives. This happened because we put the "no-sim" into the emrun configuration file. Normally, almost all daemons are simulated; only the lowest level device drivers, such as UDPd, are not simulated.
Finally, we can interactively run a "ping" program on one of our simulated nodes. When running interactive commands from the command-line, it's first necessary to tell ping two important pieces of information:
GAMA:/home/jelson/projects/emstar/obj.i686-linux(5056) setenv SIM_GROUP 5 GAMA:/home/jelson/projects/emstar/obj.i686-linux(5057) setenv SIM_ID 3 GAMA:/home/jelson/projects/emstar/obj.i686-linux(5058) link/examples/ping Tue Feb 18 20:42:53.082: link/examples/ping: starting SIMULATED node id 3 Tue Feb 18 20:42:53.083: running, using /dev/sim/group5/node3/link/0/data Tue Feb 18 20:42:53.083: ping_send: broadcast ping seqno 1 Tue Feb 18 20:42:53.436: ping_receiver: got reply 1 from node 1, iface 66.11.0.1, rtt 352.54 ms Tue Feb 18 20:42:53.436: ping_receiver: got reply 2 from node 5, iface 93.26.0.5, rtt 352.57 ms Tue Feb 18 20:42:53.436: ping_receiver: got reply 3 from node 8, iface 228.78.0.8, rtt 352.56 ms Tue Feb 18 20:42:53.436: ping_receiver: got reply 4 from node 10, iface 188.174.0.10, rtt 352.58 ms Tue Feb 18 20:42:54.095: ping_send: broadcast ping seqno 2 Tue Feb 18 20:42:54.456: ping_receiver: got reply 5 from node 1, iface 66.11.0.1, rtt 360.03 ms Tue Feb 18 20:42:54.456: ping_receiver: got reply 6 from node 5, iface 93.26.0.5, rtt 360.06 ms Tue Feb 18 20:42:54.456: ping_receiver: got reply 7 from node 8, iface 228.78.0.8, rtt 360.10 ms Tue Feb 18 20:42:54.456: ping_receiver: got reply 8 from node 10, iface 188.174.0.10, rtt 360.10 msIn this case, we received replies from nodes 1, 5, 8, and 10, which happen to be the nodes that fell within 8 meters of node 3 during this run of the simulator. If you run the simulator again, new random positions will be picked for each node, and the results will be different.
To stop the simulation, simply press Control-C.