Thursday 2 August 2012

A little trick :P

Synchronising ns-3 according to the RTI clock was quite a hectic job, we initially started by assuming we have to write a new scheduler for the job then we looked into writing a new simulator for getting our worked done. Probably this was the correct design choice and we looked into various implementation.

Finally, we managed to trick ns-3 into thinking that Read time is nothing but the RTI time by creating a new simulator "RtiSimulator" similar to Real Time Simulator Implementation. The synchroniser implementation tweaked from wall clock synchroniser helped in doing the trick.

Now, in the present code, ns-3 advances according to the RTI clock and when ns-3 has nothing to do, it sends a time-advance request to the RTI and once all federates have send such requests for time equal to or less than the ns-3 Time Advance Request, RTI grants the request and time advances in ns-3.

What I understood an HLA to be

I suppose it's fair say that there is quite inadequate literature on HLA. I have been talking to people and reading about HLA in bits and pieces. The federates can basically chit-chat with each other by two means :

1. Publishing and Subscribing Objects

2. Sending and Receiving Interactions

Let us consider a case where two federates communicate by publishing and subscribing objects. Let us consider two federates ns3 and dummy, the process of having multiple federates running though a RTI can be summarised as below:

1. Both federates publish and subscribe object through the RTI.

2. Whenever one federate changes any attributes of the object, a callback is send by the RTI to the federate and also the changed attributes.

3. RTI only grants a time advance request when all federates have finished their simulation till the present time.

This is how the entire federation works.
  

Run Time Interface Dilemma

An RTI or Run Time Infrastructure is required in order to implement HLA. RTI can be considered as the middleware between different federates. It offers various services to the federates like time management, object sharing and interactions.

There are various RTIs available but few open source. We analysed two RTIs for our project (tried CERTI only when we faced a few problems with portico :P) :

1. portico 

portico is a well written and has a C++ and a JAVA API. The source is in JAVA and the C++ API is using JNI (Java Native Interface). The project is well documented and ample of examples for both C++ and JAVA. Although there is a very - very small team :P supporting the project and seems to have issues with some operating systems. Running a federation is comparatively easier  with scripts for running them and not many variables to set.

http://www.porticoproject.org/index.php?title=Main_Page

2. CERTI

CERTI on the other hand is written in C++ and has a great C++ API. A JAVA API also exits. It seems good for the job but I didn't find the example very basic/self-explanatory (Billard). Another issue is number of variables one has to set, although it seems that using CERTI it will be quite easier to run the federates on different mmachines as compared to portico.

http://savannah.nongnu.org/projects/certi/

At present the code uses a portico federate.