Merge remote-tracking branch 'git.irl/master'
diff --git a/helper/ndn_stupidinterestgenerator_helper.cc b/helper/ndn_stupidinterestgenerator_helper.cc
new file mode 100644
index 0000000..982f283
--- /dev/null
+++ b/helper/ndn_stupidinterestgenerator_helper.cc
@@ -0,0 +1,65 @@
+//
+// ndn_stupidinterestgenerator_helper.cpp
+// Abstraction
+//
+// Created by Ilya Moiseenko on 05.08.11.
+// Copyright 2011 UCLA. All rights reserved.
+//
+
+#include "ndn_stupidinterestgenerator_helper.h"
+#include "ns3/inet-socket-address.h"
+#include "ns3/packet-socket-address.h"
+#include "ns3/string.h"
+#include "ns3/names.h"
+
+
+namespace ns3 {
+
+ StupidInterestGeneratorHelper::StupidInterestGeneratorHelper (std::string protocol, Address address)
+ {
+ m_factory.SetTypeId ("ns3::StupidInterestGenerator");
+ m_factory.Set ("Protocol", StringValue (protocol));
+ m_factory.Set ("Remote", AddressValue (address));
+ }
+
+ void
+ StupidInterestGeneratorHelper::SetAttribute (std::string name, const AttributeValue &value)
+ {
+ m_factory.Set (name, value);
+ }
+
+ ApplicationContainer
+ StupidInterestGeneratorHelper::Install (Ptr<Node> node) const
+ {
+ return ApplicationContainer (InstallPriv (node));
+ }
+
+ ApplicationContainer
+ StupidInterestGeneratorHelper::Install (std::string nodeName) const
+ {
+ Ptr<Node> node = Names::Find<Node> (nodeName);
+ return ApplicationContainer (InstallPriv (node));
+ }
+
+ ApplicationContainer
+ StupidInterestGeneratorHelper::Install (NodeContainer c) const
+ {
+ ApplicationContainer apps;
+ for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
+ {
+ apps.Add (InstallPriv (*i));
+ }
+
+ return apps;
+ }
+
+ Ptr<Application>
+ StupidInterestGeneratorHelper::InstallPriv (Ptr<Node> node) const
+ {
+ Ptr<Application> app = m_factory.Create<Application> ();
+ node->AddApplication (app);
+
+ return app;
+ }
+
+} // namespace ns3
diff --git a/helper/ndn_stupidinterestgenerator_helper.h b/helper/ndn_stupidinterestgenerator_helper.h
new file mode 100644
index 0000000..4f9f6bb
--- /dev/null
+++ b/helper/ndn_stupidinterestgenerator_helper.h
@@ -0,0 +1,86 @@
+//
+// ndn_stupidinterestgenerator_helper.h
+// Abstraction
+//
+// Created by Ilya Moiseenko on 05.08.11.
+// Copyright 2011 UCLA. All rights reserved.
+//
+
+#include "ns3/object-factory.h"
+#include "ns3/ipv4-address.h"
+#include "ns3/node-container.h"
+#include "ns3/application-container.h"
+
+namespace ns3 {
+
+ /**
+ * \brief A helper to make it easier to instantiate an ns3::OnOffApplication
+ * on a set of nodes.
+ */
+ class StupidInterestGeneratorHelper
+ {
+ public:
+ /**
+ * Create an OnOffHelper to make it easier to work with OnOffApplications
+ *
+ * \param protocol the name of the protocol to use to send traffic
+ * by the applications. This string identifies the socket
+ * factory type used to create sockets for the applications.
+ * A typical value would be ns3::UdpSocketFactory.
+ * \param address the address of the remote node to send traffic
+ * to.
+ */
+ StupidInterestGeneratorHelper (std::string protocol, Address address);
+
+ /**
+ * Helper function used to set the underlying application attributes.
+ *
+ * \param name the name of the application attribute to set
+ * \param value the value of the application attribute to set
+ */
+ void SetAttribute (std::string name, const AttributeValue &value);
+
+ /**
+ * Install an ns3::OnOffApplication on each node of the input container
+ * configured with all the attributes set with SetAttribute.
+ *
+ * \param c NodeContainer of the set of nodes on which an OnOffApplication
+ * will be installed.
+ * \returns Container of Ptr to the applications installed.
+ */
+ ApplicationContainer Install (NodeContainer c) const;
+
+ /**
+ * Install an ns3::OnOffApplication on the node configured with all the
+ * attributes set with SetAttribute.
+ *
+ * \param node The node on which an OnOffApplication will be installed.
+ * \returns Container of Ptr to the applications installed.
+ */
+ ApplicationContainer Install (Ptr<Node> node) const;
+
+ /**
+ * Install an ns3::OnOffApplication on the node configured with all the
+ * attributes set with SetAttribute.
+ *
+ * \param nodeName The node on which an OnOffApplication will be installed.
+ * \returns Container of Ptr to the applications installed.
+ */
+ ApplicationContainer Install (std::string nodeName) const;
+
+ private:
+ /**
+ * \internal
+ * Install an ns3::OnOffApplication on the node configured with all the
+ * attributes set with SetAttribute.
+ *
+ * \param node The node on which an OnOffApplication will be installed.
+ * \returns Ptr to the application installed.
+ */
+ Ptr<Application> InstallPriv (Ptr<Node> node) const;
+ std::string m_protocol;
+ Address m_remote;
+ ObjectFactory m_factory;
+ };
+
+} // namespace ns3
diff --git a/model/ndn_contentpacket.cc b/model/ndn_contentpacket.cc
index 599d175..60b4963 100644
--- a/model/ndn_contentpacket.cc
+++ b/model/ndn_contentpacket.cc
@@ -24,7 +24,8 @@
{
namespace NDNabstraction
{
- ContentPacket::ContentPacket(const struct ccn_charbuf *Name,const void *data,size_t size):Packet()
+ ContentPacket::ContentPacket(const struct ccn_charbuf *Name,const void *data,size_t size)
+ : Packet()
{
ccn_charbuf *output = ccn_charbuf_create();
int result = ccn_encode_ContentObject(output,Name,data,size);
diff --git a/model/ndn_stupidinterestgenerator.cc b/model/ndn_stupidinterestgenerator.cc
new file mode 100644
index 0000000..629d48f
--- /dev/null
+++ b/model/ndn_stupidinterestgenerator.cc
@@ -0,0 +1,177 @@
+//
+// ndn_stupidinterestgenerator.cpp
+// Abstraction
+//
+// Created by Ilya Moiseenko on 05.08.11.
+// Copyright 2011 UCLA. All rights reserved.
+//
+
+#include "ndn_stupidinterestgenerator.h"
+#include "ns3/socket.h"
+#include "ns3/socket-factory.h"
+#include "ns3/simulator.h"
+#include "ndn_interestpacket.h"
+#include "ndn_namebuilder.h"
+
+NS_LOG_COMPONENT_DEFINE ("StupidInterestGenerator");
+
+namespace ns3
+{
+//namespace NDNabstraction
+//{
+ using namespace NDNabstraction;
+
+ NS_OBJECT_ENSURE_REGISTERED (StupidInterestGenerator);
+
+ TypeId
+ StupidInterestGenerator::GetTypeId (void)
+ {
+ static TypeId tid = TypeId ("ns3::StupidInterestGenerator")
+ .SetParent<Application> ()
+ .AddConstructor<StupidInterestGenerator> ()
+ .AddAttribute ("Remote", "The address of the destination",
+ AddressValue (),
+ MakeAddressAccessor (&StupidInterestGenerator::m_peer),
+ MakeAddressChecker ())
+ .AddAttribute ("OffTime", "Time interval between packets",
+ TimeValue (Seconds (0.1)),
+ MakeTimeAccessor (&StupidInterestGenerator::m_offTime),
+ MakeTimeChecker ())
+ .AddAttribute ("Protocol", "The type of protocol to use.",
+ TypeIdValue (UdpSocketFactory::GetTypeId ()),
+ MakeTypeIdAccessor (&StupidInterestGenerator::m_tid),
+ MakeTypeIdChecker ())
+ ;
+ return tid;
+ }
+
+ StupidInterestGenerator::StupidInterestGenerator ()
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+ m_socket = 0;
+ //m_connected = false;
+ //m_residualBits = 0;
+ //m_lastStartTime = Seconds (0);
+ //m_totBytes = 0;
+ }
+
+ StupidInterestGenerator::~StupidInterestGenerator()
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+ }
+
+ void
+ StupidInterestGenerator::DoDispose (void)
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+
+ m_socket = 0;
+ // chain up
+ Application::DoDispose ();
+ }
+
+ // Application Methods
+ void StupidInterestGenerator::StartApplication () // Called at time specified by Start
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+
+ // Create the socket if not already
+ if (!m_socket)
+ {
+ m_socket = Socket::CreateSocket (GetNode (), m_tid);
+ m_socket->Bind ();
+ m_socket->Connect (m_peer);
+ m_socket->SetAllowBroadcast (true);
+ m_socket->ShutdownRecv ();
+ }
+ // Insure no pending event
+ CancelEvents ();
+ // If we are not yet connected, there is nothing to do here
+ // The ConnectionComplete upcall will start timers at that time
+ //if (!m_connected) return;
+ ScheduleStartEvent ();
+ }
+
+ void StupidInterestGenerator::StopApplication () // Called at time specified by Stop
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+
+ CancelEvents ();
+ if(m_socket != 0)
+ {
+ m_socket->Close ();
+ }
+ else
+ {
+ NS_LOG_WARN ("OnOffApplication found null socket to close in StopApplication");
+ }
+ }
+
+ void StupidInterestGenerator::CancelEvents ()
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+
+ Simulator::Cancel (m_sendEvent);
+ Simulator::Cancel (m_startStopEvent);
+ }
+
+ void StupidInterestGenerator::ScheduleStartEvent ()
+ { // Schedules the event to start sending data (switch to the "On" state)
+ NS_LOG_FUNCTION_NOARGS ();
+
+ Time offInterval = Seconds (m_offTime);
+ NS_LOG_LOGIC ("start at " << offInterval);
+ m_startStopEvent = Simulator::Schedule (offInterval, &StupidInterestGenerator::StartSending, this);
+ }
+
+ // Event handlers
+ void StupidInterestGenerator::StartSending ()
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+ //m_lastStartTime = Simulator::Now ();
+ ScheduleNextTx (); // Schedule the send packet event
+ //ScheduleStopEvent ();
+ }
+
+ void StupidInterestGenerator::StopSending ()
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+ CancelEvents ();
+
+ ScheduleStartEvent ();
+ }
+
+ // Private helpers
+ void StupidInterestGenerator::ScheduleNextTx ()
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+
+
+ Time nextTime = Seconds(0.); //send now
+ m_sendEvent = Simulator::Schedule (nextTime,
+ &StupidInterestGenerator::SendPacket, this);
+ }
+
+
+ void StupidInterestGenerator::SendPacket ()
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_LOGIC ("sending packet at " << Simulator::Now ());
+ NS_ASSERT (m_sendEvent.IsExpired ());
+
+ NameBuilder name;
+ name.AddComponent("prefix1");
+ name.AddComponent("prefix2");
+ name.AddComponent("filename");
+ ccn_charbuf *output = name.GetName();
+ Ptr<InterestPacket> packet = Create<InterestPacket>(output->buf,(uint32_t)output->length);
+ packet->AddTimeout(4000);
+ UniformVariable var;
+ packet->AddNonce(var.GetInteger(1,10000));
+ m_socket->Send(packet);
+
+ ScheduleStartEvent();
+ }
+
+//}
+}
\ No newline at end of file
diff --git a/model/ndn_stupidinterestgenerator.h b/model/ndn_stupidinterestgenerator.h
new file mode 100644
index 0000000..6407d32
--- /dev/null
+++ b/model/ndn_stupidinterestgenerator.h
@@ -0,0 +1,78 @@
+//
+// ndn_stupidinterestgenerator.h
+// Abstraction
+//
+// Created by Ilya Moiseenko on 05.08.11.
+// Copyright 2011 UCLA. All rights reserved.
+//
+
+#include "ns3/application.h"
+#include "ns3/log.h"
+#include "ns3/address.h"
+#include "ns3/random-variable.h"
+#include "ns3/nstime.h"
+#include "ns3/event-id.h"
+#include "ns3/ptr.h"
+#include "ccn_ccn.h"
+#include "ns3/udp-socket-factory.h"
+
+namespace ns3
+{
+
+
+//namespace NDNabstraction
+//{
+ class Socket; //dynamic linking works in a somehow strange way
+
+ class StupidInterestGenerator: public Application
+ {
+ public:
+ static TypeId GetTypeId (void);
+
+ StupidInterestGenerator ();
+
+ virtual ~StupidInterestGenerator();
+
+
+ protected:
+ virtual void DoDispose (void);
+ private:
+ // inherited from Application base class.
+ virtual void StartApplication (void); // Called at time specified by Start
+ virtual void StopApplication (void); // Called at time specified by Stop
+
+ //Time m_onTime;
+ Time m_offTime;
+
+ Address m_peer; // Peer address
+ Ptr<Socket> m_socket;
+ EventId m_startStopEvent; // Event id for next start or stop event
+ EventId m_sendEvent; // Eventid of pending "send packet" event
+ TypeId m_tid;
+
+ //helpers
+ void CancelEvents ();
+
+ void Construct (Ptr<Node> n,
+ const Address &remote,
+ std::string tid,
+ const RandomVariable& ontime,
+ const RandomVariable& offtime,
+ uint32_t size);
+
+ // Event handlers
+ void StartSending ();
+ void StopSending ();
+ void SendPacket ();
+
+ private:
+ void ScheduleNextTx ();
+ void ScheduleStartEvent ();
+ void ScheduleStopEvent ();
+ void ConnectionSucceeded (Ptr<Socket>);
+ void ConnectionFailed (Ptr<Socket>);
+ void Ignore (Ptr<Socket>);
+
+ };
+//}
+}
\ No newline at end of file
diff --git a/wscript b/wscript
index 00d5c32..1747f46 100644
--- a/wscript
+++ b/wscript
@@ -18,7 +18,9 @@
'model/ndn_timeoutheader.cc',
'model/ndn_nonceheader.cc',
'model/ndn_namebuilder.cc',
+ 'model/ndn_stupidinterestgenerator.cc',
'helper/ndnabstraction-helper.cc',
+ 'helper/ndn_stupidinterestgenerator_helper.cc',
]
module_test = bld.create_ns3_module_test_library('NDNabstraction')
@@ -42,7 +44,9 @@
'model/ndn_timeoutheader.h',
'model/ndn_nonceheader.h',
'model/ndn_namebuilder.h',
+ 'model/ndn_stupidinterestgenerator.h',
'helper/ndnabstraction-helper.h',
+ 'helper/ndn_stupidinterestgenerator_helper.h',
]