7 The resource bound
7.1 Rationale
Consider the following PLAN program (found in rout_tests/ping_pong.plan):
svc print : 'a -> unit
svc getRB : void -> int
svc defaultRoute : host -> host * dev
fun ping_pong(pingHost, pongHost) =
(print("Current RB is "); print(getRB()); print("\n");
OnRemote (|ping_pong| (pongHost, pingHost),
pongHost, getRB (), defaultRoute))
A very simple program to write and run, but if this program were to
be left loose on the network (without any resource bound control), it
would keep shuttling between two hosts and eat up costly bandwidth.
7.2 Managing the resource bound
The concept of a resource bound is provided as a solution to this
problem. Each packet has associated with it a certain amount of
``resources''. The packet can only access this value through the getRB
service routine; it can specify the amount of resource bound it wants to
give out of its own bank to an outgoing packet through the third argument of
OnRemote and OnNeighbor.
Each hop that a packet traverses decreases its resource bound by
one. Additionally, whenever a packet causes a new packet to be sent
out into the network (through OnRemote or OnNeighbor) its resource
bound is decremented by the amount it allocated to the outgoing
packet.
If at any point the packet does not have enough resource bound left, either
to traverse the next hop or to give out to an outgoing packet, the NotEnoughRB exception is raised, which can either be handled by the program
or ignored; in the latter case a message is sent back to the source and
printed on the console. No further hops may be traversed, and no additional
packets may be sent when the resource bound reaches 0.
7.3 The two examples and resource bound
In the first example that we saw, there were no network primitives, no
packets going out. The resource bound was totally irrelevant in that
context.
In the second example, the program always gave all of its current resource
bound to an outgoing packet. Between the local and remote hosts, the packet
might traverse a number of hops, and the resource bound will be decremented
before each hop. The initial amount of resource bound given to the packet
must be enough to take it to the remote host and get it back. In the
example, we assumed that the packet would not take more than 30 hops on each
leg, so we gave it a total of 60 units of resource bound initially.