Nauman (recluze) on computing, philosophy and more ...
Agent Mobility With JADE and JIPMS
A friend and I have been working on Java Agent DEvelopment Framework (JADE) for a while now. The idea is to enhance security mechanisms in the open source agent-deployment platform. The first step we decided to address was the actual mobility of an agent from one platform (in the sense of a dedicated machine running the JADE middleware) to another one. Turned out that it was much harder than one would imagine — especially given the fact that these agents are supposed to be mobile. Anyway, after around two months of part-time efforts, we got the agent working. Since the whole ordeal involved a lot of missing documentation and bad support, I decided to document the process through this tutorial. So, here it is. Read on to see how you can create an agent on one platform, migrate it to another platform, have it do some computation there and come back to the source.
First, you’re going to need two machines running Ubuntu. (We used Ubuntu 11.10 oneric for this.) If you only have one machine, you can install VirtualBox, setup a Ubuntu instance in a VM and connect it to the host through a virtual interface. I prefer using two adapters, first one set to a NAT setting and another one set to Host-only setting. This way, I get Internet connectivity in the guest as well as host-to-guest simple addressing.
We’re going to use JADE 3.6 along with the JADE Inter-platform Mobility Service (JIPMS) 1.2 for our needs. Download JADE and JIPMS. I used jade-binary package and extracted it in /home/documents/jade. I also extracted the JIPMS and moved the file migration.jar from its lib folder to the lib folder of jade binary. This makes it easier for us to change the classpath later on. We’ll need these files on both machines.
Now we need to setup the machines. Here are the details of the setup on each machine:
IP: 192.168.56.1 (set by VirtualBox automatically)
You can get the IP addresses of each machine through the ifconfig command. Edit /etc/hosts to insert the other machine’s address. My hosts file on slave1 looks like this:
You will need to use a little common sense about the line breaks and spaces here. I’ve formatted the command for highest readability. (Note the escaped ‘;’ in the services param and the use of full colon instead of the semi-colon in the classpath. This is only required on *nix platforms.) Three switches are important here: platform-id, host and services. First two are self-explanatory. Third tells the IPMS to start the services that take care of the agent migration. We also need to enable the acceptance of foreign agents but I’m sure you already knew that from all the mailing list searches.
IP: 192.168.56.101 (set by VirtualBox automatically)****
Also,addallthejadeandmobilityjarstothebuildpathoftheproject.I'mnotsurewhichonesareneededheresoyouwillhavetofigurethatoutonyourown.**Caveats:**1.Ifyougetthiserror:`Destinationslave2:1099/JADEdoesnotexistordoesnotsupportmobility`,itmostprobablymeansthatyou(a)youdon'thaveIPMSrunning,(b)youdidn'tputthe-servicesswitchproperly(c)there'safirewallblockingyourport7778or(d)yourhostnamesaremessedup.Inanycase,thewholeinstructionsaboveshouldworkforyou.2.Youwillmostprobablyneedtochangeyour/etc/hostsfileandcommentoutthelinethatsays'127.0.0.1localhost'.ItcausesJADEtostarttheams@slaveNserviceashttp://localhost:7778/acc instead of http://slaveN:7778/acc and that means a lot of missed ACL messages and a lot of headaches. You usually get the dreaded `getContainerID() failed to find agent ams@slave1` error because of this. Do this for both the host and the guest. Make sure your JADE GUI looks like the following: [!(http://www.csrdu.org/nauman/wp-content/uploads/2011/12/rma_jade_slave.png)](http://www.csrdu.org/nauman/wp-content/uploads/2011/12/rma_jade_slave.png)3.Finally,ifyouneeddetailedlogging,youcancreatetheloggingconfigfilebythenameoflogging.propertiesgivenbelowandpassthe`-Djava.util.logging.config.file=logging.properties`parameterwhenstartingJADE.Thiswillgivemuchfiner-grainedlogs.Thisisstandardlog4jsyntax.[sourcecode]handlers=java.util.logging.FileHandler,java.util.logging.ConsoleHandler.level=INFOjade.domain.mobility.level=ALL#---ConsoleHandler---java.util.logging.ConsoleHandler.level=ALLjava.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter#---FileHandler---java.util.logging.FileHandler.level=ALLjava.util.logging.FileHandler.pattern=%h/java%u.logjava.util.logging.FileHandler.limit=50000java.util.logging.FileHandler.count=1java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter