Difference between revisions of "HLAExample"

From Nsnam
Jump to: navigation, search
m (Running)
m (Object Model file)
Line 42: Line 42:
  
 
= Object Model file =
 
= Object Model file =
 +
 +
The [http://code.nsnam.org/muditraajgupta/ns-3-dev-hla/file/528951a6288c/codeRev/src/hla/examples/SimpleSharedObjectExample.fed SimpleSharedObjectExample.fed] was used for this tutorial. Please make sure you list all objects that you are using and their attributes in the .fed file in similar order. It is used by the RTI. Please note that you have to include these three lines at the beginning. This is because the Portico FED parser want it to be like this.
 +
 +
<pre>
 +
(FED
 +
(Federation Portico-Test)
 +
(FEDversion v1.3)
 +
</pre>
  
 
= Running =
 
= Running =

Revision as of 10:52, 20 August 2012

Before Getting Started

The tutorial will talk about using hla model for ns-3 to make ns-3 participate in distributed simulation with other federates through a Run Time infrastructure. The code for the tutorial can be found in .cc and .fed files. We will be referring to the ns-3 hla model Wiki, it has mostly model related explanation, only few sub-sections are required for the tutorial. Information about HLA and RTI. on Wikipedia.

If you want to know more about the source code of the hla model, please read the design and see the diagram here and here. Also reading this would be useful. The code can be found here.

The tutorial will assume that you have a working copy on ns-3 with hla which can be obtained here and familiarity with writing and running ns-3 scripts. Please download and install the required packages listed here as set the mentioned environment variables.

Description

The objective here is to make a simple ns-3 script that publishes and subscribes to an object PingPong with attributes Msg and MsgType. Before we could start with this we need to send an initialisation message. Let us first look as what variable we have at our disposal, let's look at the initialisation variables and common terms:

  • Seconds : Number of Times time advance request is expected.
  • SyncPhase : The string that is used by federates for synchronisation in RTI.
  • Fomfile : Name of the file that has the object model
  • FederationName : Name of the federation (Should be same in all federates)
  • FederateName : Name of the federate (ns3)
  • RtiTimeResolution : What time steps are required by the model (Default is 1.0)
  • Object Name : Name of the Object you are sharing
  • Object Attributes : A property of the shared object
  • Object Handle : Unique federate wide identifier for an object
  • Attribute Handle : Unique federate wide identifier for the attribute
  • Attribute Value : Value the attributes presently (RTI Time) posses

Initilisation

The above variables are used for initialisation. Ns-3 will create a federation <FederationName> or join the same if already created by other federates. It will register in the federation as federate <FederateName> and with a synchronisation phrase <SyncPhrase> and RTI will use the object model in <FomFileName>. The simulation will run for <Seconds>*<RtiTimeResolution> seconds and will advance in <RtiTimeResolutionSteps>. Hla model will take care of these events.

Objects

Now lets look at how the objects are created and published. After defining the object model in .fed file you have to create an object and attributes. You can create any number of objects (the helper uses a dynamic memory allocation) and add any number of attributes (again dynamic). You have to specify the name of the object and the number of attributes it will have. Once you create an object you are object handle is issued. This can used in future for listing all attributes of the object and accessing object name. Similarly, attributes can be added to object by specifying Attribute Name and Object Handle and it will return a similar Attribute Handle. All Objects are to be published and subscribed with the RTI. All events are taken care by the hla model

Synchronisation and Update

Whenever a time advance is required the hla model is designed to send it to the RTI and whenever the Time Advance Grant is approved it is handled by the hla model. For this functionality you have use a RTI simulator implementation. Whenever a value is changed in the RTI the hla model automatically updates the value in ns3, so the value of the shared object's attribute attribute value you are using is the one which is known to all federates and is in the federation. Again handled by the hla model.

More low-level implementation details of the hla model can be found here

ns-3 script

The source code of the script can be found here. Functions from the src/hla/helper will be used here. It is good to have this file open along side in another tab. It has doxygen and thus you can easily figure out the API calls, we will referring to it.

Object Model file

The SimpleSharedObjectExample.fed was used for this tutorial. Please make sure you list all objects that you are using and their attributes in the .fed file in similar order. It is used by the RTI. Please note that you have to include these three lines at the beginning. This is because the Portico FED parser want it to be like this.

(FED
(Federation Portico-Test)
(FEDversion v1.3)

Running

Once you have created your .cc and .fed file you can easily run the simulation according to instructions here. So, as it is clear from the section, we will look deeper into the three commands:

$ ./hla.sh --clean
$ Cleaning log files and jar 

It will clear all your files that are generated using your java code. This will include .class files and .jar files. It will also clear all log files. These log files are created by the Run Time Interface, in this case portico. The files can be found in $build/src/hla/model/ns3Federate. It will log the following message

Next is,

$ ./hla.sh --build
$ Building HLA interfaces

It will compile hla module code written in java and will save it in $build/src/hla/model/ns3Federate. Make sure you build ns-3 first by using ./waf, before building hla. To run a specific simulation you can use.

$ ./hla.sh --run scratch/SimpleSharedObjectExample

Make sure you copied your .fed to $ns/scratch and also you are using the .fed file name in the --run command. Also please follow the sequence in which you start the two shells as given in the Wiki Instructions

Testing