--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/codeRev/src/hla/test/SystemIntegration/dummyFederate.java Sat Aug 18 16:05:34 2012 -0400
@@ -0,0 +1,401 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2012 Mudit Raj Gupta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Authors: Mudit Raj Gupta <mudit.raaj.gupta@gmail.com>
+ *
+ */
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+
+import hla.rti.AttributeHandleSet;
+import hla.rti.FederatesCurrentlyJoined;
+import hla.rti.FederationExecutionAlreadyExists;
+import hla.rti.FederationExecutionDoesNotExist;
+import hla.rti.LogicalTime;
+import hla.rti.LogicalTimeInterval;
+import hla.rti.RTIambassador;
+import hla.rti.RTIexception;
+import hla.rti.ResignAction;
+import hla.rti.SuppliedAttributes;
+import hla.rti.SuppliedParameters;
+import hla.rti.jlc.EncodingHelpers;
+import hla.rti.jlc.RtiFactoryFactory;
+
+import org.portico.impl.hla13.types.DoubleTime;
+import org.portico.impl.hla13.types.DoubleTimeInterval;
+
+
+public class dummyFederate
+{
+ //setting iterations
+ public static final int ITERATIONS = 20;
+ public static final String READY_TO_RUN = "ReadyToRun";
+
+ //communicating with other classes
+ private RTIambassador rtiamb;
+ private dummyFederateAmbassador fedamb;
+
+ int glo=0;
+
+ //simple logging function
+ private void log( String message )
+ {
+ System.out.println( "dummy : " + message );
+ }
+
+ //Wait for user to reply
+ private void waitForUser()
+ {
+ log( " >>>>>>>>>> Press Enter to Continue <<<<<<<<<<" );
+ BufferedReader reader = new BufferedReader( new InputStreamReader(System.in) );
+ try
+ {
+ reader.readLine();
+ }
+ catch( Exception e )
+ {
+ log( "Error while waiting for user input: " + e.getMessage() );
+ e.printStackTrace();
+ }
+ }
+
+
+ private LogicalTime convertTime( double time )
+ {
+ // PORTICO SPECIFIC!!
+ return new DoubleTime( time );
+ }
+
+ private LogicalTimeInterval convertInterval( double time )
+ {
+ // PORTICO SPECIFIC!!
+ return new DoubleTimeInterval( time );
+ }
+
+ // This is the main simulation loop. It can be thought of as the main method of
+ // the federate.
+
+ public void runFederate( String federateName ) throws RTIexception
+ {
+ // create the RTIambassador
+
+ rtiamb = RtiFactoryFactory.getRtiFactory().createRtiAmbassador();
+
+ // create the federation
+ // create
+ // NOTE: some other federate may have already created the federation,
+ // in that case, we'll just try and join it
+
+ try
+ {
+ File fom = new File( "testfom.fed" );
+ rtiamb.createFederationExecution( "ExampleFederation",
+ fom.toURI().toURL() );
+ log( "Created Federation" );
+ }
+ catch( FederationExecutionAlreadyExists exists )
+ {
+ log( "Didn't create federation, it already existed" );
+ }
+ catch( MalformedURLException urle )
+ {
+ log( "Exception processing fom: " + urle.getMessage() );
+ urle.printStackTrace();
+ return;
+ }
+
+ // join the federation
+ // create the federate ambassador and join the federation
+log("Going To create a Federate Object");
+ fedamb = new dummyFederateAmbassador();
+log("ObjectCreated");
+ rtiamb.joinFederationExecution( federateName, "ExampleFederation", fedamb );
+ log( "Joined Federation as " + federateName );
+
+ // announce the sync point
+ // announce a sync point to get everyone on the same page. if the point
+ // has already been registered, we'll get a callback saying it failed,
+ // but we don't care about that, as long as someone registered it
+log("Registering Sync Point");
+ rtiamb.registerFederationSynchronizationPoint( READY_TO_RUN, null );
+log("Registed Sync Point");
+ // wait until the point is announced
+
+ while( fedamb.isAnnounced == false )
+ {
+ rtiamb.tick();
+ }
+
+ // WAIT FOR USER TO KICK US OFF
+ // So that there is time to add other federates, we will wait until the
+ // user hits enter before proceeding. That was, you have time to start
+ // other federates.
+
+ waitForUser();
+
+ // achieve the point and wait for synchronization
+ // tell the RTI we are ready to move past the sync point and then wait
+ // until the federation has synchronized on
+
+ rtiamb.synchronizationPointAchieved( READY_TO_RUN );
+ log( "Achieved sync point: " +READY_TO_RUN+ ", waiting for federation..." );
+ while( fedamb.isReadyToRun == false )
+ {
+ rtiamb.tick();
+ }
+
+ // enable time policies
+ // in this section we enable/disable all time policies
+ // note that this step is optional!
+
+ enableTimePolicy();
+ log( "Time Policy Enabled" );
+
+ // publish and subscribe //
+ // in this section we tell the RTI of all the data we are going to
+ // produce, and all the data we want to know about
+
+ publishAndSubscribe();
+ log( "Published and Subscribed" );
+
+ //register an object to update
+
+ int objectHandle = registerObject();
+ log( "Registered Object, handle=" + objectHandle );
+
+ // do the main simulation loop
+ // here is where we do the meat of our work. in each iteration, we will
+ // update the attribute values of the object we registered, and will
+ // send an interaction.
+
+ for( int i = 0; i < ITERATIONS; i++ )
+ {
+ //update the attribute values of the instance //
+ glo++;
+ updateAttributeValues( objectHandle, i );
+
+ //request a time advance and wait until we get it
+ advanceTime( 1.0 );
+ log( "Time Advanced to " + fedamb.federateTime );
+ }
+
+ // delete the object we created
+
+ deleteObject( objectHandle );
+ log( "Deleted Object, handle=" + objectHandle );
+
+ // resign from the federation
+
+ rtiamb.resignFederationExecution( ResignAction.NO_ACTION );
+ log( "Resigned from Federation" );
+
+ // try and destroy the federation
+ // NOTE: we won't die if we can't do this because other federates
+ // remain. in that case we'll leave it for them to clean up
+
+ try
+ {
+ rtiamb.destroyFederationExecution( "ExampleFederation" );
+ log( "Destroyed Federation" );
+ }
+ catch( FederationExecutionDoesNotExist dne )
+ {
+ log( "No need to destroy federation, it doesn't exist" );
+ }
+ catch( FederatesCurrentlyJoined fcj )
+ {
+ log( "Didn't destroy federation, federates still joined" );
+ }
+ }
+
+ // This method will attempt to enable the various time related properties for
+ // the federate
+
+ private void enableTimePolicy() throws RTIexception
+ {
+
+ LogicalTime currentTime = convertTime( fedamb.federateTime );
+ LogicalTimeInterval lookahead = convertInterval( fedamb.federateLookahead );
+
+ // enable time regulation
+
+ this.rtiamb.enableTimeRegulation( currentTime, lookahead );
+
+ // tick until we get the callback
+
+ while( fedamb.isRegulating == false )
+ {
+ rtiamb.tick();
+ }
+
+ // enable time constrained
+
+ this.rtiamb.enableTimeConstrained();
+
+ // tick until we get the callback
+
+ while( fedamb.isConstrained == false )
+ {
+ rtiamb.tick();
+ }
+ }
+
+ // This method will inform the RTI about the types of data that the federate will
+ // be creating, and the types of data we are interested in hearing about as other
+ // federates produce it.
+
+ private void publishAndSubscribe() throws RTIexception
+ {
+ // publish all attributes of ObjectRoot.PingPong
+ // before we can register instance of the object class ObjectRoot.PingPong and
+ // update the values of the various attributes, we need to tell the RTI
+ // that we intend to publish this information
+
+ // get all the handle information for the attributes of ObjectRoot.PingPong
+
+ int classHandle = rtiamb.getObjectClassHandle( "ObjectRoot.PingPong" );
+ int MsgTypeHandle = rtiamb.getAttributeHandle( "MsgType", classHandle );
+ int MsgHandle = rtiamb.getAttributeHandle( "Msg", classHandle );
+
+ AttributeHandleSet attributes =
+ RtiFactoryFactory.getRtiFactory().createAttributeHandleSet();
+ attributes.add( MsgTypeHandle );
+ attributes.add( MsgHandle );
+
+ // do the actual publication
+ rtiamb.publishObjectClass( classHandle, attributes );
+
+ // subscribe to all attributes of ObjectRoot.PingPong
+ // we also want to hear about the same sort of information as it is
+ // created and altered in other federates, so we need to subscribe to it
+
+ rtiamb.subscribeObjectClassAttributes( classHandle, attributes );
+
+
+ }
+
+ //This method will register an instance of the class ObjectRoot.PingPong and will
+ // return the federation-wide unique handle for that instance. Later in the
+ // simulation, we will update the attribute values for this instance
+
+ private int registerObject() throws RTIexception
+ {
+ int classHandle = rtiamb.getObjectClassHandle( "ObjectRoot.PingPong" );
+ return rtiamb.registerObjectInstance( classHandle );
+ }
+
+ // This method will update all the values of the given object instance.
+
+ private void updateAttributeValues( int objectHandle, int i ) throws RTIexception
+ {
+
+ // create the necessary container and values
+ // create the collection to store the values in, as you can see
+ // this is quite a lot of work
+ SuppliedAttributes attributes =
+ RtiFactoryFactory.getRtiFactory().createSuppliedAttributes();
+ byte[] MsgTypeValue,MsgValue;
+ // generate the new values
+ // we use EncodingHelpers to make things nice friendly for both Java and C++
+
+ if(i%2==0)
+ {
+ MsgTypeValue = EncodingHelpers.encodeString("ping" );
+ MsgValue = EncodingHelpers.encodeString("Client: Hello!!!");
+ }
+ else
+ {
+ MsgTypeValue = EncodingHelpers.encodeString("pong" );
+ MsgValue = EncodingHelpers.encodeString("Server: Hello!!!");
+ }
+ int classHandle = rtiamb.getObjectClass( objectHandle );
+ int MsgTypeHandle = rtiamb.getAttributeHandle( "MsgType", classHandle );
+ int MsgHandle = rtiamb.getAttributeHandle( "Msg", classHandle );
+
+ // put the values into the collection
+ attributes.add( MsgTypeHandle, MsgTypeValue );
+ attributes.add( MsgHandle, MsgValue );
+
+ System.out.println(EncodingHelpers.decodeString(attributes.getValue(0)));
+
+ // do the actual update
+ rtiamb.updateAttributeValues( objectHandle,attributes, generateTag() );
+
+ }
+
+
+ // This method will request a time advance to the current time, plus the given
+ // timestep. It will then wait until a notification of the time advance grant
+ // has been received.
+
+ private void advanceTime( double timestep ) throws RTIexception
+ {
+ // request the advance
+ fedamb.isAdvancing = true;
+ LogicalTime newTime = convertTime( fedamb.federateTime + timestep );
+ rtiamb.timeAdvanceRequest( newTime );
+
+ // wait for the time advance to be granted.
+ while( fedamb.isAdvancing )
+ {
+ rtiamb.tick();
+ }
+ }
+
+ //This method will attempt to delete the object instance of the given
+ // handle. We can only delete objects we created, or for which we own the
+ // privilegeToDelete attribute.
+
+ private void deleteObject( int handle ) throws RTIexception
+ {
+ rtiamb.deleteObjectInstance( handle, generateTag() );
+ }
+
+
+
+ private byte[] generateTag()
+ {
+ if(glo%2==0)
+ return (EncodingHelpers.encodeString("ping"));
+ else
+ return (EncodingHelpers.encodeString("pong"));
+ }
+
+ public static void main( String[] args )
+ {
+ // get a federate name
+ String federateName = "dummy";
+ if( args.length != 0 )
+ {
+ federateName = args[0];
+ }
+
+ try
+ {
+ // run the example federate
+ new dummyFederate().runFederate( federateName );
+ }
+ catch( RTIexception rtie )
+ {
+ // an exception occurred, just log the information and exit
+ rtie.printStackTrace();
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/codeRev/src/hla/test/SystemIntegration/dummyFederateAmbassador.java Sat Aug 18 16:05:34 2012 -0400
@@ -0,0 +1,249 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2012 Mudit Raj Gupta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * This class handles all the callbacks for the ns3Federate. On each callback, it will
+ * just create a string describing the event and add that string to a list of events that have
+ * happened. At the end of processing, the contents of this list can be printed so we can see
+ * exactly what events happened in what order.
+ *
+ * Authors: Mudit Raj Gupta <mudit.raaj.gupta@gmail.com>
+ *
+ */
+
+import hla.rti.ArrayIndexOutOfBounds;
+import hla.rti.EventRetractionHandle;
+import hla.rti.LogicalTime;
+import hla.rti.ReceivedInteraction;
+import hla.rti.ReflectedAttributes;
+import hla.rti.jlc.EncodingHelpers;
+import hla.rti.jlc.NullFederateAmbassador;
+
+import org.portico.impl.hla13.types.DoubleTime;
+
+/**
+ * This class handles all incoming callbacks from the RTI regarding a particular
+ * Federate. It will log information about any callbacks it
+ * receives, thus demonstrating how to deal with the provided callback information.
+ */
+public class dummyFederateAmbassador extends NullFederateAmbassador
+{
+ // these variables are accessible in the package
+ protected double federateTime = 0.0;
+ protected double federateLookahead = 1.0;
+
+ protected boolean isRegulating = false;
+ protected boolean isConstrained = false;
+ protected boolean isAdvancing = false;
+
+ protected boolean isAnnounced = false;
+ protected boolean isReadyToRun = false;
+
+ public dummyFederateAmbassador()
+ {
+ log("In constructor");
+ }
+
+
+ private double convertTime( LogicalTime logicalTime )
+ {
+ // PORTICO SPECIFIC!!
+ return ((DoubleTime)logicalTime).getTime();
+ }
+
+ private void log( String message )
+ {
+ System.out.println( "FederateAmbassador: " + message );
+ }
+
+
+ public void synchronizationPointRegistrationFailed( String label )
+ {
+ log( "Failed to register sync point: " + label );
+ }
+
+ public void synchronizationPointRegistrationSucceeded( String label )
+ {
+ log( "Successfully registered sync point: " + label );
+ }
+
+ public void announceSynchronizationPoint( String label, byte[] tag )
+ {
+ log( "Synchronization point announced: " + label );
+ if( label.equals(dummyFederate.READY_TO_RUN) )
+ this.isAnnounced = true;
+ }
+
+ public void federationSynchronized( String label )
+ {
+ log( "Federation Synchronized: " + label );
+ if( label.equals(dummyFederate.READY_TO_RUN) )
+ this.isReadyToRun = true;
+ }
+
+ /**
+ * The RTI has informed us that time regulation is now enabled.
+ */
+ public void timeRegulationEnabled( LogicalTime theFederateTime )
+ {
+ this.federateTime = convertTime( theFederateTime );
+ this.isRegulating = true;
+ }
+
+ public void timeConstrainedEnabled( LogicalTime theFederateTime )
+ {
+ this.federateTime = convertTime( theFederateTime );
+ this.isConstrained = true;
+ }
+
+ public void timeAdvanceGrant( LogicalTime theTime )
+ {
+ this.federateTime = convertTime( theTime );
+ this.isAdvancing = false;
+ }
+
+ public void discoverObjectInstance( int theObject,
+ int theObjectClass,
+ String objectName )
+ {
+ log( "Discoverd Object: handle=" + theObject + ", classHandle=" +
+ theObjectClass + ", name=" + objectName );
+ }
+
+ public void reflectAttributeValues( int theObject,
+ ReflectedAttributes theAttributes,
+ byte[] tag )
+ {
+ // just pass it on to the other method for printing purposes
+ // passing null as the time will let the other method know it
+ // it from us, not from the RTI
+ reflectAttributeValues( theObject, theAttributes, tag, null, null );
+ }
+
+ public void reflectAttributeValues( int theObject,
+ ReflectedAttributes theAttributes,
+ byte[] tag,
+ LogicalTime theTime,
+ EventRetractionHandle retractionHandle )
+ {
+ StringBuilder builder = new StringBuilder( "Reflection for object:" );
+ System.out.print("test");
+ // print the handle
+ builder.append( " handle=" + theObject );
+ // print the tag
+ builder.append( ", tag=" + EncodingHelpers.decodeString(tag) );
+ // print the time (if we have it) we'll get null if we are just receiving
+ // a forwarded call from the other reflect callback above
+ if( theTime != null )
+ {
+ builder.append( ", time=" + convertTime(theTime) );
+ }
+
+ // print the attribute information
+ builder.append( ", attributeCount=" + theAttributes.size() );
+ builder.append( "\n" );
+ for( int i = 0; i < theAttributes.size(); i++ )
+ {
+ try
+ {
+ // print the attibute handle
+ builder.append( "\tattributeHandle=" );
+ builder.append( theAttributes.getAttributeHandle(i) );
+ // print the attribute value
+ builder.append( ", attributeValue=" );
+ builder.append(
+ EncodingHelpers.decodeString(theAttributes.getValue(i)) );
+ builder.append( "\n" );
+ }
+ catch( ArrayIndexOutOfBounds aioob )
+ {
+ // won't happen
+ }
+ }
+
+ log( builder.toString() );
+ }
+
+ public void receiveInteraction( int interactionClass,
+ ReceivedInteraction theInteraction,
+ byte[] tag )
+ {
+ // just pass it on to the other method for printing purposes
+ // passing null as the time will let the other method know it
+ // it from us, not from the RTI
+ receiveInteraction( interactionClass, theInteraction, tag, null, null );
+ }
+
+ public void receiveInteraction( int interactionClass,
+ ReceivedInteraction theInteraction,
+ byte[] tag,
+ LogicalTime theTime,
+ EventRetractionHandle eventRetractionHandle )
+ {
+ StringBuilder builder = new StringBuilder( "Interaction Received:" );
+
+ // print the handle
+ builder.append( " handle=" + interactionClass );
+ // print the tag
+ builder.append( ", tag=" + EncodingHelpers.decodeString(tag) );
+ // print the time (if we have it) we'll get null if we are just receiving
+ // a forwarded call from the other reflect callback above
+ if( theTime != null )
+ {
+ builder.append( ", time=" + convertTime(theTime) );
+ }
+
+ // print the parameer information
+ builder.append( ", parameterCount=" + theInteraction.size() );
+ builder.append( "\n" );
+ for( int i = 0; i < theInteraction.size(); i++ )
+ {
+ try
+ {
+ // print the parameter handle
+ builder.append( "\tparamHandle=" );
+ builder.append( theInteraction.getParameterHandle(i) );
+ // print the parameter value
+ builder.append( ", paramValue=" );
+ builder.append(
+ EncodingHelpers.decodeString(theInteraction.getValue(i)) );
+ builder.append( "\n" );
+ }
+ catch( ArrayIndexOutOfBounds aioob )
+ {
+ // won't happen
+ }
+ }
+
+ log( builder.toString() );
+ }
+
+ public void removeObjectInstance( int theObject, byte[] userSuppliedTag )
+ {
+ log( "Object Removed: handle=" + theObject );
+ }
+
+ public void removeObjectInstance( int theObject,
+ byte[] userSuppliedTag,
+ LogicalTime theTime,
+ EventRetractionHandle retractionHandle )
+ {
+ log( "Object Removed: handle=" + theObject );
+ }
+
+
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/codeRev/src/hla/test/SystemIntegration/linux.sh Sat Aug 18 16:05:34 2012 -0400
@@ -0,0 +1,85 @@
+#!/bin/bash
+
+USAGE="usage: linux.sh [compile] [clean] [execute [federate-name]]"
+
+################################
+# check command line arguments #
+################################
+if [ $# = 0 ]
+then
+ echo $USAGE
+ exit;
+fi
+
+######################
+# test for JAVA_HOME #
+######################
+JAVA=java
+if [ "$JAVA_HOME" = "" ]
+then
+ echo WARNING Your JAVA_HOME environment variable is not set!
+ #exit;
+else
+ JAVA=$JAVA_HOME/bin/java
+fi
+
+#####################
+# test for RTI_HOME #
+#####################
+if [ "$RTI_HOME" = "" ]
+then
+ RTI_HOME=$PWD
+ export RTI_HOME
+fi
+
+
+######################
+# test for JAR_HOME #
+######################
+if [ "$JAR_HOME" = "" ]
+then
+ echo WARNING Your JAR_HOME environment variable is not set, assuming ns3 directory, please move portico jar to ns3 directory
+ echo or try setting JAR_HOME to portico.jar
+ #exit;
+ cd ../../../../../
+ JAR_HOME=$PWD
+ cd src/hla/test/SystemIntegration/dummy
+fi
+
+
+############################################
+### (target) clean #########################
+############################################
+if [ $1 = "clean" ]
+then
+ echo "deleting dummyFederate jar file and left over logs"
+ rm *.class
+ rm dummy.jar
+ rm -Rf logs
+ exit;
+fi
+
+############################################
+### (target) compile #######################
+############################################
+if [ $1 = "compile" ]
+then
+
+ echo "compiling dummyFederate"
+ javac -cp ./:$JAR_HOME/portico.jar *.java
+ jar -cf dummy.jar *.class
+ exit;
+fi
+
+############################################
+### (target) execute #######################
+############################################
+if [ $1 = "execute" ]
+then
+ shift;
+ java -cp ./dummy.jar:$JAR_HOME/portico.jar dummyFederate $*
+ exit;
+fi
+
+echo $USAGE
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/codeRev/src/hla/test/SystemIntegration/testfom.fed Sat Aug 18 16:05:34 2012 -0400
@@ -0,0 +1,50 @@
+;; A comment in the test file, just to show I'm cool ;;
+(FED
+ (Federation Portico-Test)
+ (FEDversion v1.3)
+ (spaces
+ (space TestSpace
+ (dimension TestDimension)
+ )
+ (space OtherSpace
+ (dimension OtherDimension)
+ )
+ )
+ (objects
+ (class ObjectRoot
+ (attribute privilegeToDelete reliable timestamp)
+ (class RTIprivate)
+ (class PingPong
+ (attribute MsgType reliable timestamp TestSpace) ;; more comments!
+ (attribute Msg reliable timestamp TestSpace)
+ (attribute ac reliable timestamp TestSpace)
+ (class B
+ (attribute ba reliable timestamp TestSpace)
+ (attribute bb reliable timestamp TestSpace)
+ (attribute bc reliable timestamp TestSpace)
+ )
+ )
+ )
+ )
+ (interactions
+ (class InteractionRoot reliable timestamp
+ (class RTIprivate reliable timestamp)
+ (class X reliable timestamp TestSpace
+ (parameter xa)
+ (parameter xb)
+ (parameter xc)
+ (class Y reliable timestamp ;; note the absence of any space definition
+ (parameter ya)
+ (parameter yb)
+ (parameter yc)
+ (class Z reliable timestamp TestSpace
+ (parameter za)
+ (parameter zb)
+ (parameter zc)
+ )
+ )
+ )
+ )
+ )
+)
+
Binary file codeRev/src/hla/test/dummy/dummy.jar has changed
--- a/codeRev/src/hla/test/dummy/linux.sh Sat Aug 18 15:29:15 2012 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-#!/bin/bash
-
-USAGE="usage: linux.sh [compile] [clean] [execute [federate-name]]"
-
-################################
-# check command line arguments #
-################################
-if [ $# = 0 ]
-then
- echo $USAGE
- exit;
-fi
-
-######################
-# test for JAVA_HOME #
-######################
-JAVA=java
-if [ "$JAVA_HOME" = "" ]
-then
- echo WARNING Your JAVA_HOME environment variable is not set!
- #exit;
-else
- JAVA=$JAVA_HOME/bin/java
-fi
-
-#####################
-# test for RTI_HOME #
-#####################
-if [ "$RTI_HOME" = "" ]
-then
- cd ../../
- cd RTI
- RTI_HOME=$PWD
- export RTI_HOME
- cd ..
- cd test/dummy
- echo WARNING Your RTI_HOME environment variable is not set, assuming $RTI_HOME
-fi
-
-############################################
-### (target) clean #########################
-############################################
-if [ $1 = "clean" ]
-then
- echo "deleting dummyFederate jar file and left over logs"
- rm src/*.class
- rm dummy.jar
- rm -Rf logs
- exit;
-fi
-
-############################################
-### (target) compile #######################
-############################################
-if [ $1 = "compile" ]
-then
- echo "compiling dummyFederate"
- cd src
- javac -cp ./:$RTI_HOME/lib/portico.jar *.java
- jar -cf ../dummy.jar *.class
- cd ../
- exit;
-fi
-
-############################################
-### (target) execute #######################
-############################################
-if [ $1 = "execute" ]
-then
- shift;
- java -cp ./dummy.jar:$RTI_HOME/lib/portico.jar dummyFederate $*
- exit;
-fi
-
-echo $USAGE
-
--- a/codeRev/src/hla/test/dummy/src/dummyFederate.java Sat Aug 18 15:29:15 2012 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,400 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2012 Mudit Raj Gupta
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Authors: Mudit Raj Gupta <mudit.raaj.gupta@gmail.com>
- *
- */
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.InputStreamReader;
-import java.net.MalformedURLException;
-
-import hla.rti.AttributeHandleSet;
-import hla.rti.FederatesCurrentlyJoined;
-import hla.rti.FederationExecutionAlreadyExists;
-import hla.rti.FederationExecutionDoesNotExist;
-import hla.rti.LogicalTime;
-import hla.rti.LogicalTimeInterval;
-import hla.rti.RTIambassador;
-import hla.rti.RTIexception;
-import hla.rti.ResignAction;
-import hla.rti.SuppliedAttributes;
-import hla.rti.SuppliedParameters;
-import hla.rti.jlc.EncodingHelpers;
-import hla.rti.jlc.RtiFactoryFactory;
-
-import org.portico.impl.hla13.types.DoubleTime;
-import org.portico.impl.hla13.types.DoubleTimeInterval;
-
-
-public class dummyFederate
-{
- //setting iterations
- public static final int ITERATIONS = 20;
- public static final String READY_TO_RUN = "ReadyToRun";
-
- //communicating with other classes
- private RTIambassador rtiamb;
- private dummyFederateAmbassador fedamb;
-
- int glo=0;
-
- //simple logging function
- private void log( String message )
- {
- System.out.println( "dummy : " + message );
- }
-
- //Wait for user to reply
- private void waitForUser()
- {
- log( " >>>>>>>>>> Press Enter to Continue <<<<<<<<<<" );
- BufferedReader reader = new BufferedReader( new InputStreamReader(System.in) );
- try
- {
- reader.readLine();
- }
- catch( Exception e )
- {
- log( "Error while waiting for user input: " + e.getMessage() );
- e.printStackTrace();
- }
- }
-
-
- private LogicalTime convertTime( double time )
- {
- // PORTICO SPECIFIC!!
- return new DoubleTime( time );
- }
-
- private LogicalTimeInterval convertInterval( double time )
- {
- // PORTICO SPECIFIC!!
- return new DoubleTimeInterval( time );
- }
-
- // This is the main simulation loop. It can be thought of as the main method of
- // the federate.
-
- public void runFederate( String federateName ) throws RTIexception
- {
- // create the RTIambassador
-
- rtiamb = RtiFactoryFactory.getRtiFactory().createRtiAmbassador();
-
- // create the federation
- // create
- // NOTE: some other federate may have already created the federation,
- // in that case, we'll just try and join it
-
- try
- {
- File fom = new File( "testfom.fed" );
- rtiamb.createFederationExecution( "ExampleFederation",
- fom.toURI().toURL() );
- log( "Created Federation" );
- }
- catch( FederationExecutionAlreadyExists exists )
- {
- log( "Didn't create federation, it already existed" );
- }
- catch( MalformedURLException urle )
- {
- log( "Exception processing fom: " + urle.getMessage() );
- urle.printStackTrace();
- return;
- }
-
- // join the federation
- // create the federate ambassador and join the federation
-
- fedamb = new dummyFederateAmbassador();
- rtiamb.joinFederationExecution( federateName, "ExampleFederation", fedamb );
- log( "Joined Federation as " + federateName );
-
- // announce the sync point
- // announce a sync point to get everyone on the same page. if the point
- // has already been registered, we'll get a callback saying it failed,
- // but we don't care about that, as long as someone registered it
-
- rtiamb.registerFederationSynchronizationPoint( READY_TO_RUN, null );
-
- // wait until the point is announced
-
- while( fedamb.isAnnounced == false )
- {
- rtiamb.tick();
- }
-
- // WAIT FOR USER TO KICK US OFF
- // So that there is time to add other federates, we will wait until the
- // user hits enter before proceeding. That was, you have time to start
- // other federates.
-
- waitForUser();
-
- // achieve the point and wait for synchronization
- // tell the RTI we are ready to move past the sync point and then wait
- // until the federation has synchronized on
-
- rtiamb.synchronizationPointAchieved( READY_TO_RUN );
- log( "Achieved sync point: " +READY_TO_RUN+ ", waiting for federation..." );
- while( fedamb.isReadyToRun == false )
- {
- rtiamb.tick();
- }
-
- // enable time policies
- // in this section we enable/disable all time policies
- // note that this step is optional!
-
- enableTimePolicy();
- log( "Time Policy Enabled" );
-
- // publish and subscribe //
- // in this section we tell the RTI of all the data we are going to
- // produce, and all the data we want to know about
-
- publishAndSubscribe();
- log( "Published and Subscribed" );
-
- //register an object to update
-
- int objectHandle = registerObject();
- log( "Registered Object, handle=" + objectHandle );
-
- // do the main simulation loop
- // here is where we do the meat of our work. in each iteration, we will
- // update the attribute values of the object we registered, and will
- // send an interaction.
-
- for( int i = 0; i < ITERATIONS; i++ )
- {
- //update the attribute values of the instance //
- glo++;
- updateAttributeValues( objectHandle, i );
-
- //request a time advance and wait until we get it
- advanceTime( 1.0 );
- log( "Time Advanced to " + fedamb.federateTime );
- }
-
- // delete the object we created
-
- deleteObject( objectHandle );
- log( "Deleted Object, handle=" + objectHandle );
-
- // resign from the federation
-
- rtiamb.resignFederationExecution( ResignAction.NO_ACTION );
- log( "Resigned from Federation" );
-
- // try and destroy the federation
- // NOTE: we won't die if we can't do this because other federates
- // remain. in that case we'll leave it for them to clean up
-
- try
- {
- rtiamb.destroyFederationExecution( "ExampleFederation" );
- log( "Destroyed Federation" );
- }
- catch( FederationExecutionDoesNotExist dne )
- {
- log( "No need to destroy federation, it doesn't exist" );
- }
- catch( FederatesCurrentlyJoined fcj )
- {
- log( "Didn't destroy federation, federates still joined" );
- }
- }
-
- // This method will attempt to enable the various time related properties for
- // the federate
-
- private void enableTimePolicy() throws RTIexception
- {
-
- LogicalTime currentTime = convertTime( fedamb.federateTime );
- LogicalTimeInterval lookahead = convertInterval( fedamb.federateLookahead );
-
- // enable time regulation
-
- this.rtiamb.enableTimeRegulation( currentTime, lookahead );
-
- // tick until we get the callback
-
- while( fedamb.isRegulating == false )
- {
- rtiamb.tick();
- }
-
- // enable time constrained
-
- this.rtiamb.enableTimeConstrained();
-
- // tick until we get the callback
-
- while( fedamb.isConstrained == false )
- {
- rtiamb.tick();
- }
- }
-
- // This method will inform the RTI about the types of data that the federate will
- // be creating, and the types of data we are interested in hearing about as other
- // federates produce it.
-
- private void publishAndSubscribe() throws RTIexception
- {
- // publish all attributes of ObjectRoot.PingPong
- // before we can register instance of the object class ObjectRoot.PingPong and
- // update the values of the various attributes, we need to tell the RTI
- // that we intend to publish this information
-
- // get all the handle information for the attributes of ObjectRoot.PingPong
-
- int classHandle = rtiamb.getObjectClassHandle( "ObjectRoot.PingPong" );
- int MsgTypeHandle = rtiamb.getAttributeHandle( "MsgType", classHandle );
- int MsgHandle = rtiamb.getAttributeHandle( "Msg", classHandle );
-
- AttributeHandleSet attributes =
- RtiFactoryFactory.getRtiFactory().createAttributeHandleSet();
- attributes.add( MsgTypeHandle );
- attributes.add( MsgHandle );
-
- // do the actual publication
- rtiamb.publishObjectClass( classHandle, attributes );
-
- // subscribe to all attributes of ObjectRoot.PingPong
- // we also want to hear about the same sort of information as it is
- // created and altered in other federates, so we need to subscribe to it
-
- rtiamb.subscribeObjectClassAttributes( classHandle, attributes );
-
-
- }
-
- //This method will register an instance of the class ObjectRoot.PingPong and will
- // return the federation-wide unique handle for that instance. Later in the
- // simulation, we will update the attribute values for this instance
-
- private int registerObject() throws RTIexception
- {
- int classHandle = rtiamb.getObjectClassHandle( "ObjectRoot.PingPong" );
- return rtiamb.registerObjectInstance( classHandle );
- }
-
- // This method will update all the values of the given object instance.
-
- private void updateAttributeValues( int objectHandle, int i ) throws RTIexception
- {
-
- // create the necessary container and values
- // create the collection to store the values in, as you can see
- // this is quite a lot of work
- SuppliedAttributes attributes =
- RtiFactoryFactory.getRtiFactory().createSuppliedAttributes();
- byte[] MsgTypeValue,MsgValue;
- // generate the new values
- // we use EncodingHelpers to make things nice friendly for both Java and C++
-
- if(i%2==0)
- {
- MsgTypeValue = EncodingHelpers.encodeString("ping" );
- MsgValue = EncodingHelpers.encodeString("Client: Hello!!!");
- }
- else
- {
- MsgTypeValue = EncodingHelpers.encodeString("pong" );
- MsgValue = EncodingHelpers.encodeString("Server: Hello!!!");
- }
- int classHandle = rtiamb.getObjectClass( objectHandle );
- int MsgTypeHandle = rtiamb.getAttributeHandle( "MsgType", classHandle );
- int MsgHandle = rtiamb.getAttributeHandle( "Msg", classHandle );
-
- // put the values into the collection
- attributes.add( MsgTypeHandle, MsgTypeValue );
- attributes.add( MsgHandle, MsgValue );
-
- System.out.println(EncodingHelpers.decodeString(attributes.getValue(0)));
-
- // do the actual update
- rtiamb.updateAttributeValues( objectHandle,attributes, generateTag() );
-
- }
-
-
- // This method will request a time advance to the current time, plus the given
- // timestep. It will then wait until a notification of the time advance grant
- // has been received.
-
- private void advanceTime( double timestep ) throws RTIexception
- {
- // request the advance
- fedamb.isAdvancing = true;
- LogicalTime newTime = convertTime( fedamb.federateTime + timestep );
- rtiamb.timeAdvanceRequest( newTime );
-
- // wait for the time advance to be granted.
- while( fedamb.isAdvancing )
- {
- rtiamb.tick();
- }
- }
-
- //This method will attempt to delete the object instance of the given
- // handle. We can only delete objects we created, or for which we own the
- // privilegeToDelete attribute.
-
- private void deleteObject( int handle ) throws RTIexception
- {
- rtiamb.deleteObjectInstance( handle, generateTag() );
- }
-
-
-
- private byte[] generateTag()
- {
- if(glo%2==0)
- return (EncodingHelpers.encodeString("ping"));
- else
- return (EncodingHelpers.encodeString("pong"));
- }
-
- public static void main( String[] args )
- {
- // get a federate name
- String federateName = "dummy";
- if( args.length != 0 )
- {
- federateName = args[0];
- }
-
- try
- {
- // run the example federate
- new dummyFederate().runFederate( federateName );
- }
- catch( RTIexception rtie )
- {
- // an exception occurred, just log the information and exit
- rtie.printStackTrace();
- }
- }
-}
--- a/codeRev/src/hla/test/dummy/src/dummyFederateAmbassador.java Sat Aug 18 15:29:15 2012 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,248 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2012 Mudit Raj Gupta
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * This class handles all the callbacks for the ns3Federate. On each callback, it will
- * just create a string describing the event and add that string to a list of events that have
- * happened. At the end of processing, the contents of this list can be printed so we can see
- * exactly what events happened in what order.
- *
- * Authors: Mudit Raj Gupta <mudit.raaj.gupta@gmail.com>
- *
- */
-
-import hla.rti.ArrayIndexOutOfBounds;
-import hla.rti.EventRetractionHandle;
-import hla.rti.LogicalTime;
-import hla.rti.ReceivedInteraction;
-import hla.rti.ReflectedAttributes;
-import hla.rti.jlc.EncodingHelpers;
-import hla.rti.jlc.NullFederateAmbassador;
-
-import org.portico.impl.hla13.types.DoubleTime;
-
-/**
- * This class handles all incoming callbacks from the RTI regarding a particular
- * Federate. It will log information about any callbacks it
- * receives, thus demonstrating how to deal with the provided callback information.
- */
-public class dummyFederateAmbassador extends NullFederateAmbassador
-{
- // these variables are accessible in the package
- protected double federateTime = 0.0;
- protected double federateLookahead = 1.0;
-
- protected boolean isRegulating = false;
- protected boolean isConstrained = false;
- protected boolean isAdvancing = false;
-
- protected boolean isAnnounced = false;
- protected boolean isReadyToRun = false;
-
- public dummyFederateAmbassador()
- {
- }
-
-
- private double convertTime( LogicalTime logicalTime )
- {
- // PORTICO SPECIFIC!!
- return ((DoubleTime)logicalTime).getTime();
- }
-
- private void log( String message )
- {
- System.out.println( "FederateAmbassador: " + message );
- }
-
-
- public void synchronizationPointRegistrationFailed( String label )
- {
- log( "Failed to register sync point: " + label );
- }
-
- public void synchronizationPointRegistrationSucceeded( String label )
- {
- log( "Successfully registered sync point: " + label );
- }
-
- public void announceSynchronizationPoint( String label, byte[] tag )
- {
- log( "Synchronization point announced: " + label );
- if( label.equals(dummyFederate.READY_TO_RUN) )
- this.isAnnounced = true;
- }
-
- public void federationSynchronized( String label )
- {
- log( "Federation Synchronized: " + label );
- if( label.equals(dummyFederate.READY_TO_RUN) )
- this.isReadyToRun = true;
- }
-
- /**
- * The RTI has informed us that time regulation is now enabled.
- */
- public void timeRegulationEnabled( LogicalTime theFederateTime )
- {
- this.federateTime = convertTime( theFederateTime );
- this.isRegulating = true;
- }
-
- public void timeConstrainedEnabled( LogicalTime theFederateTime )
- {
- this.federateTime = convertTime( theFederateTime );
- this.isConstrained = true;
- }
-
- public void timeAdvanceGrant( LogicalTime theTime )
- {
- this.federateTime = convertTime( theTime );
- this.isAdvancing = false;
- }
-
- public void discoverObjectInstance( int theObject,
- int theObjectClass,
- String objectName )
- {
- log( "Discoverd Object: handle=" + theObject + ", classHandle=" +
- theObjectClass + ", name=" + objectName );
- }
-
- public void reflectAttributeValues( int theObject,
- ReflectedAttributes theAttributes,
- byte[] tag )
- {
- // just pass it on to the other method for printing purposes
- // passing null as the time will let the other method know it
- // it from us, not from the RTI
- reflectAttributeValues( theObject, theAttributes, tag, null, null );
- }
-
- public void reflectAttributeValues( int theObject,
- ReflectedAttributes theAttributes,
- byte[] tag,
- LogicalTime theTime,
- EventRetractionHandle retractionHandle )
- {
- StringBuilder builder = new StringBuilder( "Reflection for object:" );
- System.out.print("test");
- // print the handle
- builder.append( " handle=" + theObject );
- // print the tag
- builder.append( ", tag=" + EncodingHelpers.decodeString(tag) );
- // print the time (if we have it) we'll get null if we are just receiving
- // a forwarded call from the other reflect callback above
- if( theTime != null )
- {
- builder.append( ", time=" + convertTime(theTime) );
- }
-
- // print the attribute information
- builder.append( ", attributeCount=" + theAttributes.size() );
- builder.append( "\n" );
- for( int i = 0; i < theAttributes.size(); i++ )
- {
- try
- {
- // print the attibute handle
- builder.append( "\tattributeHandle=" );
- builder.append( theAttributes.getAttributeHandle(i) );
- // print the attribute value
- builder.append( ", attributeValue=" );
- builder.append(
- EncodingHelpers.decodeString(theAttributes.getValue(i)) );
- builder.append( "\n" );
- }
- catch( ArrayIndexOutOfBounds aioob )
- {
- // won't happen
- }
- }
-
- log( builder.toString() );
- }
-
- public void receiveInteraction( int interactionClass,
- ReceivedInteraction theInteraction,
- byte[] tag )
- {
- // just pass it on to the other method for printing purposes
- // passing null as the time will let the other method know it
- // it from us, not from the RTI
- receiveInteraction( interactionClass, theInteraction, tag, null, null );
- }
-
- public void receiveInteraction( int interactionClass,
- ReceivedInteraction theInteraction,
- byte[] tag,
- LogicalTime theTime,
- EventRetractionHandle eventRetractionHandle )
- {
- StringBuilder builder = new StringBuilder( "Interaction Received:" );
-
- // print the handle
- builder.append( " handle=" + interactionClass );
- // print the tag
- builder.append( ", tag=" + EncodingHelpers.decodeString(tag) );
- // print the time (if we have it) we'll get null if we are just receiving
- // a forwarded call from the other reflect callback above
- if( theTime != null )
- {
- builder.append( ", time=" + convertTime(theTime) );
- }
-
- // print the parameer information
- builder.append( ", parameterCount=" + theInteraction.size() );
- builder.append( "\n" );
- for( int i = 0; i < theInteraction.size(); i++ )
- {
- try
- {
- // print the parameter handle
- builder.append( "\tparamHandle=" );
- builder.append( theInteraction.getParameterHandle(i) );
- // print the parameter value
- builder.append( ", paramValue=" );
- builder.append(
- EncodingHelpers.decodeString(theInteraction.getValue(i)) );
- builder.append( "\n" );
- }
- catch( ArrayIndexOutOfBounds aioob )
- {
- // won't happen
- }
- }
-
- log( builder.toString() );
- }
-
- public void removeObjectInstance( int theObject, byte[] userSuppliedTag )
- {
- log( "Object Removed: handle=" + theObject );
- }
-
- public void removeObjectInstance( int theObject,
- byte[] userSuppliedTag,
- LogicalTime theTime,
- EventRetractionHandle retractionHandle )
- {
- log( "Object Removed: handle=" + theObject );
- }
-
-
-
-}
--- a/codeRev/src/hla/test/dummy/testfom.fed Sat Aug 18 15:29:15 2012 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-;; A comment in the test file, just to show I'm cool ;;
-(FED
- (Federation Portico-Test)
- (FEDversion v1.3)
- (spaces
- (space TestSpace
- (dimension TestDimension)
- )
- (space OtherSpace
- (dimension OtherDimension)
- )
- )
- (objects
- (class ObjectRoot
- (attribute privilegeToDelete reliable timestamp)
- (class RTIprivate)
- (class PingPong
- (attribute MsgType reliable timestamp TestSpace) ;; more comments!
- (attribute Msg reliable timestamp TestSpace)
- (attribute ac reliable timestamp TestSpace)
- (class B
- (attribute ba reliable timestamp TestSpace)
- (attribute bb reliable timestamp TestSpace)
- (attribute bc reliable timestamp TestSpace)
- )
- )
- )
- )
- (interactions
- (class InteractionRoot reliable timestamp
- (class RTIprivate reliable timestamp)
- (class X reliable timestamp TestSpace
- (parameter xa)
- (parameter xb)
- (parameter xc)
- (class Y reliable timestamp ;; note the absence of any space definition
- (parameter ya)
- (parameter yb)
- (parameter yc)
- (class Z reliable timestamp TestSpace
- (parameter za)
- (parameter zb)
- (parameter zc)
- )
- )
- )
- )
- )
-)
-