Added examples, scripts and cleaned code
authormuditraajgupta
Sat, 18 Aug 2012 14:56:20 -0400
changeset 7 34c7b09eeb00
parent 6 d5e3d57fec79
child 8 d3922187cb51
Added examples, scripts and cleaned code
codeRev/hla.sh
codeRev/src/hla/examples/SimpleSharedObjectExample.fed
codeRev/src/hla/examples/example-plus-rti-listen.cc
codeRev/src/hla/examples/first.cc
codeRev/src/hla/examples/hla-example-one.cc
codeRev/src/hla/examples/simple-shared-object-example.cc
codeRev/src/hla/examples/waf
codeRev/src/hla/examples/wscript
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/codeRev/hla.sh	Sat Aug 18 14:56:20 2012 -0400
@@ -0,0 +1,102 @@
+#!/bin/bash
+
+USAGE="usage: linux.sh [--build] [--clean] [--run [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 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;
+else
+        JAR_HOME=$PWD
+fi
+
+
+
+#####################
+# test for RTI_HOME #
+#####################
+if [ "$RTI_HOME" = "" ]
+then
+	RTI_HOME=$PWD
+	export RTI_HOME
+fi
+
+############################################
+### (target) clean #########################
+############################################
+
+if [ $1 = "--clean" ]
+then
+	echo "Cleaning log files and jar"
+	cd build/src/hla/model
+        rm -rf ns3Federate
+	cd $RTI_HOME
+	rm -Rf src/hla/model/logs
+	exit;
+fi
+
+############################################
+### (target) compile #######################
+############################################
+
+if [ $1 = "--build" ]
+then
+	echo "Building HLA interfaces"
+	cd src/hla/model
+	javac -cp ./:$JAR_HOME/portico.jar *.java
+        cd $RTI_HOME/build/src/hla/model
+        mkdir ns3Federate
+        cd $RTI_HOME
+        cp src/hla/model/j.class $RTI_HOME/build/src/hla/model/ns3Federate
+        rm src/hla/model/j.class
+        cp src/hla/model/ns3Federate.class $RTI_HOME/build/src/hla/model/ns3Federate
+        rm src/hla/model/ns3Federate.class
+        cp src/hla/model/ns3FedAmb.class $RTI_HOME/build/src/hla/model/ns3Federate
+        rm src/hla/model/ns3FedAmb.class
+        jar -cf build/src/hla/model/ns3Federate/ns3Federate.jar build/src/hla/model/ns3Federate/*.class
+	cd $RTI_HOME
+	exit;
+fi
+
+############################################
+### (target) execute #######################
+###########################################logs#
+
+#if [ $1 = "execute" ]
+#then
+	shift;
+        fom=$1".fed"
+        cp $fom $RTI_HOME/build/src/hla/model/ns3Federate
+        cd $RTI_HOME
+        cd build/src/hla/model/ns3Federate
+        java -cp .:ns3Federate.jar:$JAR_HOME/portico.jar ns3Federate $*
+	exit;
+#fi
+
+echo $USAGE
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/codeRev/src/hla/examples/SimpleSharedObjectExample.fed	Sat Aug 18 14:56:20 2012 -0400
@@ -0,0 +1,15 @@
+(FED
+  (Federation Portico-Test)
+  (FEDversion v1.3)
+  (objects 
+    (class ObjectRoot 
+      (attribute privilegeToDelete reliable timestamp)
+      (class RTIprivate)
+      (class PingPong
+        (attribute MsgType reliable timestamp)
+        (attribute Msg reliable timestamp)
+      )
+    )
+  )
+)
+
--- a/codeRev/src/hla/examples/example-plus-rti-listen.cc	Sun Aug 12 08:30:21 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,142 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * 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
- */
-
-#include "ns3/core-module.h"
-#include "ns3/network-module.h"
-#include "ns3/internet-module.h"
-#include "ns3/point-to-point-module.h"
-#include "ns3/applications-module.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h> 
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
-
-void 
-readFed();
-
-int
-main (int argc, char *argv[])
-{
-  readFed();
-  NS_LOG_UNCOND("Hello World!!!");  
-      
-  LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
-  LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
-
-  NodeContainer nodes;
-  nodes.Create (2);
-
-  PointToPointHelper pointToPoint;
-  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
-  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
-
-  NetDeviceContainer devices;
-  devices = pointToPoint.Install (nodes);
-
-  InternetStackHelper stack;
-  stack.Install (nodes);
-
-  Ipv4AddressHelper address;
-  address.SetBase ("10.1.1.0", "255.255.255.0");
-
-  Ipv4InterfaceContainer interfaces = address.Assign (devices);
-
-  UdpEchoServerHelper echoServer (9);
-
-  ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
-  serverApps.Start (Seconds (1.0));
-  serverApps.Stop (Seconds (10.0));
-
-  UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
-  echoClient.SetAttribute ("MaxPackets", UintegerValue (5));
-  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
-  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
-
-  ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
-  clientApps.Start (Seconds (2.0));
-  clientApps.Stop (Seconds (10.0));
-
-  Simulator::Run ();
-  Simulator::Destroy ();
-  return 0;
-}
-/*void error(const char *msg)
-{
-    perror(msg);
-    exit(1);
-}*/
-
-void readFed()
-{
-
-     int sockfd, newsockfd, portno;
-     socklen_t clilen;
-     char buffer[256];
-     struct sockaddr_in serv_addr, cli_addr;
-     int n,count=0;
-     sockfd = socket(AF_INET, SOCK_STREAM, 0);
-     if (sockfd < 0)
-  NS_LOG_UNCOND("Hello World!!!");   
-        //error("ERROR opening socket");
-     bzero((char *) &serv_addr, sizeof(serv_addr));
-     portno = 2201;
-     serv_addr.sin_family = AF_INET;
-     serv_addr.sin_addr.s_addr = INADDR_ANY;
-     serv_addr.sin_port = htons(portno);
-     if (bind(sockfd, (struct sockaddr *) &serv_addr,
-              sizeof(serv_addr)) < 0)
-  NS_LOG_UNCOND("Hello World!!!");   
-              //error("ERROR on binding");
-     listen(sockfd,5);
-
-
-  clilen = sizeof(cli_addr);
-     newsockfd = accept(sockfd, 
-                 (struct sockaddr *) &cli_addr, 
-                 &clilen);
-     if (newsockfd < 0) 
-          //error("ERROR on accept");
-  NS_LOG_UNCOND("Hello World!!!");  
-
-     while(count<21)
-     {
-       count++;
-       //bzero(buffer,256);
-//n = write(newsockfd,"^***",1);
- //    if (n < 0) error("ERROR writing to socket");
-	n=read(newsockfd,buffer,256);
-   if(n>0);
-       		//printf("%s\n",buffer);
-  NS_LOG_UNCOND("Hello World/th!!!");  
-       if (n < 0)  NS_LOG_UNCOND("Hello World!!!");   //error("ERROR reading from socket");
- 
-       //if(strcmp(buffer,"*****")==0);
-	//	break;
-     }
-    
-     close(newsockfd);
-     close(sockfd);
- //    printf("%d",count);     
-//return 0; 
-}
--- a/codeRev/src/hla/examples/first.cc	Sun Aug 12 08:30:21 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +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
- *
- * Author: Mudit Raj Gupta <mudit.raaj.gupta@gmail.com>
- */
-
-#include "ns3/log.h"
-#include "ns3/link_to_rti.h"
-
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h> 
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <pthread.h>
-
-#include "ns3/core-module.h"
-#include "ns3/network-module.h"
-#include "ns3/internet-module.h"
-#include "ns3/point-to-point-module.h"
-#include "ns3/applications-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
-//socket related variables
-int
-main (int argc, char *argv[])
-
-{
-  LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
-  LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
-link_to_rti o;
-o.connectToRTI();
-//NS_LOG_UNCOND("jjj");
-GlobalValue::Bind ("SimulatorImplementationType", 
-                     StringValue ("ns3::RtiSimulatorImpl"));
-  //NS_LOG_UNCOND("jjj");
-  NodeContainer nodes;
-  nodes.Create (2);
-
-  PointToPointHelper pointToPoint;
-  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
-  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
-
-  NetDeviceContainer devices;
-  devices = pointToPoint.Install (nodes);
-
-  InternetStackHelper stack;
-  stack.Install (nodes);
-
-  Ipv4AddressHelper address;
-  address.SetBase ("10.1.1.0", "255.255.255.0");
-
-  Ipv4InterfaceContainer interfaces = address.Assign (devices);
-
-  UdpEchoServerHelper echoServer (9);
-//NS_LOG_UNCOND("jjj");
-  ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
-  serverApps.Start (Seconds (1.0));
-  serverApps.Stop (Seconds (10.0));
-
-  UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
-  echoClient.SetAttribute ("MaxPackets", UintegerValue (6));
-  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
-  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
-
-  ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
-  clientApps.Start (Seconds (2.0));
-  clientApps.Stop (Seconds (10.0));
-//NS_LOG_UNCOND("jkl");
-  Simulator::Stop (Seconds (11.0)); 
-  Simulator::Run ();
-  Simulator::Destroy ();
-pthread_exit(NULL);
-  return 0;
-}
--- a/codeRev/src/hla/examples/hla-example-one.cc	Sun Aug 12 08:30:21 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-#include "ns3/hla-interface.h"
-#include "ns3/core-module.h"
-#include <iostream>
-
-using namespace std;
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("HlaExampleOne");
-
-int main()
-{/*
-  //Create an object to communicate with RTI
-  HlaHelper ns3Fed;
-
-  //Create an object of HlaInterface to be shared over RTI with other Federates
-  HlaInterface SharedObject;
-  
-  //Add a name to this object
-  SharedObject.SetName("PingPong");
-
-  //Add some attributes to be seen and modified by other federates
-  SharedObject.AddAttribute("MsgType","5Mbps");
-  SharedObject.AddAttribute("Msg","2ms");
-
-  //Send a request to RTI to start simulation
-  ns3Fed.Start();
-
-  //Change Simulator to RtiSimulaorImpl
-  GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RtiSimulatorImpl"));
-  
-  //similar to examples/tutorial/first.cc
-  NodeContainer nodes;
-  nodes.Create (2);
-
-  PointToPointHelper pointToPoint;
-  
-  //Setting DataRate and Delay according to external Federate
-  pointToPoint.SetDeviceAttribute ("DataRate", StringValue (SharedObject.GetAttribute(msg)));
-  pointToPoint.SetChannelAttribute ("Delay", StringValue (SharedObject.GetAttribute(msgType)));
-
-  NetDeviceContainer devices;
-  devices = pointToPoint.Install (nodes);
-
-  InternetStackHelper stack;
-  stack.Install (nodes);
-
-  Ipv4AddressHelper address;
-  address.SetBase ("10.1.1.0", "255.255.255.0");
-
-  Ipv4InterfaceContainer interfaces = address.Assign (devices);
-
-  UdpEchoServerHelper echoServer (9);
-
-  ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
-  serverApps.Start (Seconds (1.0));
-  serverApps.Stop (Seconds (10.0));
-
-  UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
-  echoClient.SetAttribute ("MaxPackets", UintegerValue (6));
-  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
-  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
-
-  ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
-  clientApps.Start (Seconds (2.0));
-  clientApps.Stop (Seconds (10.0));
-
-  Simulator::Stop (Seconds (11.0)); 
-  Simulator::Run ();
-  Simulator::Destroy ();
-  
-  pthread_exit(NULL);
- */ 
-  return 0;
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/codeRev/src/hla/examples/simple-shared-object-example.cc	Sat Aug 18 14:56:20 2012 -0400
@@ -0,0 +1,56 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * 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
+ */
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/internet-module.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/applications-module.h"
+
+#include "ns3/hla-helper.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("SimpleSharedObjectExample");
+
+int
+main (int argc, char *argv[])
+{
+  GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RtiSimulatorImpl"));
+  HlaHelper hla;
+  
+  int ObjectHandle;
+  ObjectHandle = hla.CreateSharedObject("PingPong","2");
+  
+  int AttributeHandle1, AttributeHandle2;
+  AttributeHandle1 = hla.AddAttributeToSharedObject("MsgType",ObjectHandle);
+  AttributeHandle2 = hla.AddAttributeToSharedObject("Msg",ObjectHandle);
+    
+  hla.Start();
+  
+  NS_LOG_UNCOND(ObjectHandle);
+  NS_LOG_UNCOND(AttributeHandle1);
+  NS_LOG_UNCOND(AttributeHandle2);
+  
+  Simulator::Stop (Seconds (10.0));
+  Simulator::Run ();
+  Simulator::Destroy ();
+  return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/codeRev/src/hla/examples/waf	Sat Aug 18 14:56:20 2012 -0400
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/codeRev/src/hla/examples/wscript	Sat Aug 18 14:56:20 2012 -0400
@@ -0,0 +1,14 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+    obj = bld.create_ns3_program('simple-shared-object-example',
+                                 ['core', 'hla'])
+    obj.source = 'simple-shared-object-example.cc'
+
+  #  obj = bld.create_ns3_program('third-distributed',
+  #                              ['point-to-point', 'internet', 'mobility', 'wifi', 'csma', 'applications'])
+  #  obj.source = 'third-distributed.cc'
+
+  #  obj = bld.create_ns3_program('nms-p2p-nix-distributed',
+  #                               ['point-to-point', 'internet', 'nix-vector-routing', 'applications'])
+  #  obj.source = 'nms-p2p-nix-distributed.cc'