Skip to content

Instantly share code, notes, and snippets.

@adriantunez
Created May 9, 2014 16:20
Show Gist options
  • Save adriantunez/84d63d014be391d32aae to your computer and use it in GitHub Desktop.
Save adriantunez/84d63d014be391d32aae to your computer and use it in GitHub Desktop.
Required patch to be eligible in any NS-3 project
--- a/scratch/testapp-sim.cc 2014-05-09 18:14:55.890791594 +0100
+++ b/scratch/testapp-sim.cc 2014-05-09 18:13:48.714789659 +0100
@@ -12,14 +12,13 @@
NodeContainer nodes;
nodes.Create (1);
- /*
- * XXX:
- * Add TestApplication to the above created
- * node. Then schedule TestApplication to be
- * started and stopped at the 1st and 2nd
- * second of simulation time respectively.
- *
- * */
+ // LogComponentEnable ("TestApplication", LOG_LEVEL_ALL);
+ Ptr<TestApplication> app = CreateObject<TestApplication> ();
+ Ptr<Node> node = DynamicCast<Node> (nodes.Get(0));
+
+ node->AddApplication (app);
+ app->SetStartTime (Seconds (1.0));
+ app->SetStopTime (Seconds (2.0));
Simulator::Run ();
Simulator::Destroy ();
--- a/src/applications/model/testapp.h 2014-05-09 18:14:55.890791594 +0100
+++ b/src/applications/model/testapp.h 2014-05-09 18:12:07.826787660 +0100
@@ -15,11 +15,8 @@
virtual ~TestApplication ();
private:
-/*
- * XXX: ADD TWO METHODS HERE
- *
- *
- */
+ virtual void StartApplication (void);
+ virtual void StopApplication (void);
};
}
--- a/src/applications/model/testapp.cc 2014-05-09 18:14:55.890791594 +0100
+++ b/src/applications/model/testapp.cc 2014-05-09 18:12:16.978790445 +0100
@@ -1,4 +1,5 @@
#include "ns3/log.h"
+#include "ns3/simulator.h"
#include "testapp.h"
NS_LOG_COMPONENT_DEFINE ("TestApplication");
@@ -26,10 +27,20 @@
NS_LOG_FUNCTION (this);
}
-/*
- *
- * XXX: IMPLEMENT TWO METHODS HERE
- *
- * */
+void
+TestApplication::StartApplication (void)
+{
+ NS_LOG_FUNCTION(this);
+ NS_LOG_LOGIC("Application started at second " << Simulator::Now().GetSeconds());
+ std::cout << "Hello World!" << std::endl;
+}
+
+void
+TestApplication::StopApplication (void)
+{
+ NS_LOG_FUNCTION(this);
+ NS_LOG_LOGIC("Application stopped at second " << Simulator::Now().GetSeconds());
+ std::cout << "Goodbye World!" << std::endl;
+}
} // namespace ns3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment