5.2 Probabilistic Routing in VR Protocol
6.1.2 Migration Engine
The Migration Engine of the UbiMASS agent middleware is responsible for com- plete and correct process of the agent migration. One of the key features is that the agent can decide on its own which current values of variables it needs to take to the destination host. In this manner, the agent can trigger an entry point in order to continue to work where it stopped at the previous host.
The process of the migration is shown in Figure 6.3 and described as follows: 1. Before starting the migration the agent can send current values of integer
and string variables to the agent middleware using two functions set init- data(int id, int data) and set init data(int id, char data[]). Because the agent itself will receive this list of tuples, there are no further specifications necessary. The agent knows how to handle the data on the destination node.
2. Using start migration() the agent initiates migration and lets the middle- ware to perform the required steps.
3. Agent middleware initiates the migration. Actually, it is a weak migration, because only the program code and data of the agent is transferred, but not
58 Mobility in WSN Agent Middleware Migration Engine Agent Host 1 Agent
set_init_data(id, data) start_migration() Agent Middleware Migration Engine Agent Host 2 Agent MIGRATION demand_init_data() get_init_data(id) send_init() send_data()Figure 6.3: Agent migration in UbiMASS
its status. The agent starts from the beginning at each time. The agent and its memory address that is known from the initial loading is forwarded to the communication level. On the destination host, the agent is loaded and started using the ELF loader described in the previous section.
4. In order to receive the last values of its variables the agent calls at the begin- ning the middleware function demand init data(). This turns the migration into a strong migration, because the agent can now continue to work with its previous status.
5. The destination host requests the list of variables by sending an INIT to the source host.
6. The source host packs all tuples into a char array and sends it to the requesting host. Figure 6.4 gives an example of the char array.
4 UbiMASS ein mobiles Agentensystem für Sensornetze
2. Mit start_migration() initiiert der Agent nun die Migration und lässt den
weiteren Ablauf von der Middleware durchführen.
3. Die Agenten-Middleware beginnt nun mit der Agenten-Migration. Im Prin-
zip handelt es sich hierbei immer um eine schwache Migration, d.h. nur
der Programmcode und die Daten des Agenten werden übertragen, nicht
aber sein Zustand die Ausführung soll also beim Zielhost von Anfang an
starten. Zur Übertragung wird der Agent, dessen Adresse im Speicher ja
vom Laden noch bekannt ist, an die Kommunikationsschicht übergeben. In
kleine Pakete aufgeteilt startet nun der Broadcast-Transfer zum Zielrech-
ner (Agentenhost 2), um dort wieder zusammengesetzt zu werden. Nach
der Ankunft wird die Lademethode des ELF-Loaders aufgerufen (wie in
Abschnitt 4.1.1 beschrieben) und die Ausführung des Agenten startet.
4. Zur Anforderung der Variablenbelegungen ruft der Agent auf Agenten-
host 2 gleich zu Beginn die Methode demand_init_data() der Agenten-
Middleware auf. Damit wird auch gekennzeichnet, dass es sich nicht um
eine schwache Migration handelt, sondern dass der Zustand durch die Va-
riablenbelegung übergeben werden soll.
5. Das Agentensystem des Zielrechners fordert nun über die Funknachricht
INIT den Agentenhost 1 dazu auf, die Variablenbelegungen zu versenden.
6. Nach erfolgreichem Erhalt der INIT -Nachricht verpackt Agentenhost 1 die
Belegung der Variablen in einem Char-Array, um dieses dann an den Ziel-
rechner zu senden. Die Systematik ist anhand eines Beispiels (Tabelle 4.3)
recht einfach zu erklären:
i 32 3 s 4 t e s t ...
Tabelle 4.3: Senden der Variablenbelegung bei einer Migration
Die erste Stelle gibt immer den Typ (i für Integer, s für String) der Variable
an. Falls es sich um einen Integer handelt, wie am Anfang des Beispiels, so
folgt in den nächsten beiden Feldern der Wert. Da ein Integer zum Speichern
16 Bit benötigt, der Char-Array aber nur 8 Bit pro Feld speichern kann, ist
eine Zerlegung nötig. Die vorderen 8 Bit des Integers werden nach rechts
geshiftet und separat gespeichert. Für den Wert im Beispiel ergibt sich also
(3 8) + 32 = 768 + 32 = 800. Gleich darauf folgt die nächste Variable,
hier vom Typ String. Dabei wird nach der Typbeschreibung ein Feld für
die Angabe der String-Länge verwendet (im Beispiel: Länge 4). Diese Zahl
an Felder wird nun durchlaufen und die gefundenen Char-Werte zu einem
String konkateniert. In der derzeitigen Version von UbiMASS ist die String-
Länge allerdings auf 255 Zeichen beschränkt.
40
Figure 6.4: Example: sending of variable values
At the beginning of each variable the type is specified by an i for integer and s for a string. Because integer variables require 16 bits two chars are used to deliver one integer right-shifting the first bits by 8. The value in the example can be calculated by (3 << 8) + 32 = 768 + 32 = 800. After the string type, length of the string is indicated. After successful transfer of the
6.1 UbiMASS Architecture 59
message, agent host can delete the agent process and deallocate memory space or agent can remain, if cloning of agents is desired.
7. After waiting for the variable value to receive the agent can access values using middleware functions get init data(int id) and get init string(int id). Because the agent knows in which order it has put the variables, it also knows which variable matches its id.
The Migration Engine works as a fundamental component of the overall agent system. For this work our goal was to develop and to evaluate the basic func- tionality.