Next: Run this program
Up: Moving on
Previous: The Ping program
The OnRemote primitive is one of the two primitives provided in
the language for specifying computation at a node across the
network. It takes four arguments:
- What
-
The first argument specifies what to execute at the remote
node. It must be of the form of a function call. Note that
the arguments to the function call will be evaluated on
the machine invoking OnRemote, while the function will
be evaluated on the remote machine.
- Where
-
The second argument specifies where to execute the packet next
at. Note that the packet will go through (possibly) many other
active nodes in the process of getting to the specified host,
but it will not be executed at any intermediate nodes.
- How much
-
The third argument specifies how much of the current packet's
resources to give to the outgoing packet.
- How to
-
The fourth argument specifies which routing function to use to
get to the remote host.
The other network primitive provided is OnNeighbor. It requires
that the second argument be on the same (AN virtual) link-layer as the
current host, and hence does not require the fourth argument.
The program consists of just one function definition. This function, called
``ping'', takes three arguments and returns a unit result. The first two
arguments are of type host, and mean the source and
destination
of the packet for a particular leg of its journey. The third argument is a
boolean value which specifies whether the packet is outgoing or otherwise.
The body of the function is divided into three cases by the 'if
.. then .. else' constructs.
- If the packet is outgoing and it has reached its destination, it is
time to turn back. The program then uses the OnRemote primitive. It
specifies that the next execution should be at the original
source. The function to be executed is ping itself, but with the
source and destination switched (since this leg of the journey goes
from the destination to the source), apart from outgoing being set
to false. It also gives all of its current resources to the outgoing
packet, and specifies ``defaultRoute'' as the routing function to
use to get to the source.
- If the packet is incoming and it has reached its destination,
it has reached the remote host and made its way back to
the original source - the packet then just prints a message.
- If none of the above cases were true, the packet is still on
the source and about to begin the first leg of the
journey. The OnRemote call sends it on its way.
Next: Run this program
Up: Moving on
Previous: The Ping program
Michael Hicks
Mon Nov 24 10:50:43 EST 1997