Ccnx-interest-sender, not complete yet
diff --git a/apps/ccnx-interest-sender.cc b/apps/ccnx-interest-sender.cc
new file mode 100644
index 0000000..f7b7ac0
--- /dev/null
+++ b/apps/ccnx-interest-sender.cc
@@ -0,0 +1,164 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+#include "ccnx-interest-sender.h"
+
+NS_LOG_COMPONENT_DEFINE ("CcnxInterestSender");
+
+namespace ns3
+{    
+
+NS_OBJECT_ENSURE_REGISTERED (CcnxInterestSender);
+
+TypeId
+CcnxInterestSender::GetTypeId (void)
+{
+    static TypeId tid = TypeId ("ns3::CcnxInterestSender")
+    .SetParent<Application> ()
+    .AddConstructor<CcnxInterestSender> ()
+    .AddAttribute ("OffTime", "Time interval between packets",
+                   TimeValue (Seconds (0.1)),
+                   MakeTimeAccessor (&CcnxInterestSender::m_offTime),
+                   MakeTimeChecker ())
+    /*.AddAttribute ("NameComponents","CcnxName of the Interest (use Name::Components)",
+                   Name::ComponentsValue(Name::Components()),
+                   Name::MakeComponentsAccessor(&CcnxInterestSender::m_interestName),
+                   Name::MakeComponentsChecker())*/
+    .AddAttribute ("NameComponents","CcnxName of the Interest (use Name::Components)",
+                   PointerValue (CreateObject<Name::Components> ()),
+                   MakePointerAccessor (&CcnxInterestSender::m_interestName),
+                   MakePointerChecker<Name::Components> ())
+    .AddAttribute ("LifeTime", "LifeTime fo interest packet",
+                   TimeValue (Seconds (4.0)),
+                   MakeTimeAccessor (&CcnxInterestSender::m_interestLifeTime),
+                   MakeTimeChecker ())
+    .AddAttribute ("MinSuffixComponents", "MinSuffixComponents",
+                   IntegerValue(-1),
+                   MakeIntegerAccessor(&CcnxInterestSender::m_minSuffixComponents),
+                   MakeIntegerChecker<int32_t>())
+    .AddAttribute ("MaxSuffixComponents", "MaxSuffixComponents",
+                   IntegerValue(-1),
+                   MakeIntegerAccessor(&CcnxInterestSender::m_maxSuffixComponents),
+                   MakeIntegerChecker<int32_t>())
+    .AddAttribute ("ChildSelector", "ChildSelector",
+                   BooleanValue(false),
+                   MakeBooleanAccessor(&CcnxInterestSender::m_childSelector),
+                   MakeBooleanChecker())
+    /*.AddAttribute ("Exclude","only simple name matching is supported (use Name::Components)",
+                   Name::ComponentsValue(Name::Components()),
+                   Name::MakeComponentsAccessor(&CcnxInterestSender::m_exclude),
+                   Name::MakeComponentsChecker())*/
+    .AddAttribute ("Exclude", "only simple name matching is supported (use Name::Components)",
+                   PointerValue (CreateObject<Name::Components> ()),
+                   MakePointerAccessor (&CcnxInterestSender::m_exclude),
+                   MakePointerChecker<Name::Components> ())
+    .AddAttribute ("Initial Nonce", "If 0 then nonce is not used",
+                   UintegerValue(1),
+                   MakeUintegerAccessor(&CcnxInterestSender::m_initialNonce),
+                   MakeUintegerChecker<uint32_t>())
+    ;
+    /*
+    .AddAttribute ("NoiseModel",
+                   "A pointer to the model of the channel ambient noise.",
+                   PointerValue (CreateObject<UanNoiseModelDefault> ()),
+                   MakePointerAccessor (&UanChannel::m_noise),
+                   MakePointerChecker<UanNoiseModel> ())*/
+    return tid;
+}
+    
+CcnxInterestSender::CcnxInterestSender ()
+{
+    NS_LOG_FUNCTION_NOARGS ();
+}
+    
+CcnxInterestSender::~CcnxInterestSender()
+{
+    NS_LOG_FUNCTION_NOARGS ();
+}
+    
+void
+CcnxInterestSender::DoDispose (void)
+{
+    NS_LOG_FUNCTION_NOARGS ();
+        
+    Application::DoDispose ();
+}
+    
+// Application Methods
+void 
+CcnxInterestSender::StartApplication () // Called at time specified by Start
+{
+    NS_LOG_FUNCTION_NOARGS ();
+    ScheduleNextTx();
+}
+    
+void 
+CcnxInterestSender::StopApplication () // Called at time specified by Stop
+{
+    NS_LOG_FUNCTION_NOARGS ();
+    
+    CancelEvents ();
+}
+    
+void 
+CcnxInterestSender::CancelEvents ()
+{
+    NS_LOG_FUNCTION_NOARGS ();
+        
+    Simulator::Cancel (m_sendEvent);
+}
+
+void 
+CcnxInterestSender::ScheduleNextTx ()
+{
+    NS_LOG_FUNCTION_NOARGS ();
+        
+    Time nextTime = Seconds(m_offTime); //send now
+    m_sendEvent = Simulator::Schedule (nextTime, &CcnxInterestSender::SendPacket, this);
+}
+    
+void
+CcnxInterestSender::SendPacket ()
+{
+    NS_LOG_FUNCTION_NOARGS ();
+    NS_LOG_INFO ("Sending Interest at " << Simulator::Now ());
+    
+    uint32_t randomNonce = UniformVariable().GetInteger(1, std::numeric_limits<uint32_t>::max ());
+    CcnxInterestHeader interestHeader;
+    interestHeader.SetNonce(randomNonce);
+    //const Ptr<Name::Components> name = Create<Name::Components>(m_interestName);
+    interestHeader.SetName(m_interestName);
+    interestHeader.SetInterestLifetime(m_interestLifeTime);
+    interestHeader.SetChildSelector(m_childSelector);
+    //const Ptr<Name::Components> exclude = Create<Name::Components>(m_exclude);
+    interestHeader.SetExclude(m_exclude);
+    interestHeader.SetMaxSuffixComponents(m_maxSuffixComponents);
+    interestHeader.SetMinSuffixComponents(m_minSuffixComponents);
+    
+    Ptr<Packet> packet = Create<Packet> ();
+    packet->AddHeader (interestHeader);
+    
+    m_face->Send(packet);
+    
+    ScheduleNextTx();
+}
+
+    
+}
diff --git a/apps/ccnx-interest-sender.h b/apps/ccnx-interest-sender.h
new file mode 100644
index 0000000..0a9d2b5
--- /dev/null
+++ b/apps/ccnx-interest-sender.h
@@ -0,0 +1,104 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+#include "ns3/application.h"
+#include "ns3/log.h"
+#include "ns3/random-variable.h"
+#include "ns3/nstime.h"
+#include "ns3/event-id.h"
+#include "ns3/ptr.h"
+#include "ns3/simulator.h"
+#include "ns3/ccnx-interest-header.h"
+#include "ns3/ccnx-local-face.h"
+#include "ns3/name-components.h"
+#include "ns3/packet.h"
+#include "ns3/boolean.h"
+#include "ns3/integer.h"
+#include "ns3/uinteger.h"
+#include "ns3/random-variable.h"
+#include <limits> 
+#include "ns3/pointer.h"
+
+namespace ns3 
+{
+    
+class Socket;
+    
+class CcnxInterestSender: public Application
+{
+public: 
+    static TypeId GetTypeId (void);
+        
+    CcnxInterestSender ();
+        
+    virtual ~CcnxInterestSender ();
+        
+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;
+    Ptr<Name::Components> m_interestName;
+    Time m_interestLifeTime;
+    int32_t m_minSuffixComponents;
+    int32_t m_maxSuffixComponents;
+    bool m_childSelector;
+    Ptr<Name::Components> m_exclude;
+    uint32_t m_initialNonce;
+    
+    //EventId         m_startStopEvent;     // Event id for next start or stop event
+    EventId         m_sendEvent;    // Eventid of pending "send packet" event
+    TypeId          m_tid;
+    Ptr<CcnxLocalFace> m_face;
+        
+    //helpers
+    void CancelEvents ();
+        
+    void Construct (Ptr<Node> n,
+                    std::string tid,
+                    const Time& offtime,
+                    Ptr<Name::Components> nameComponents,
+                    const Time& lifetime,
+                    const int32_t& minSuffixComponents,
+                    const int32_t& maxSuffixComponents,
+                    const bool childSelector,
+                    Ptr<Name::Components> exclude,
+                    const uint32_t& initialNonce
+                    );
+    
+    // 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>);
+        
+};
+}
diff --git a/model/name-components.h b/model/name-components.h
index 95d2347..097152e 100644
--- a/model/name-components.h
+++ b/model/name-components.h
@@ -22,15 +22,19 @@
 #define _NDN_NAME_COMPONENTS_H_
 
 #include "ns3/simple-ref-count.h"
+#include "ns3/attribute.h"
+#include "ns3/attribute-helper.h"
 
 #include <string>
 #include <algorithm>
 #include <list>
+#include "ns3/object.h"
 
 namespace ns3 {
 namespace Name {
 
-class Components : public SimpleRefCount<Components>
+class Components : public Object
+
 {
 public:
   Components ();
@@ -100,6 +104,14 @@
                                        prefix.m_prefix.begin (), prefix.m_prefix.end ());
 }
 
+    
+/**
+* \class ns3::ComponentsValue
+* \brief hold objects of type ns3::Name::Components
+*/
+ATTRIBUTE_VALUE_DEFINE (Components);
+ATTRIBUTE_ACCESSOR_DEFINE (Components);
+ATTRIBUTE_CHECKER_DEFINE (Components);
 } // Namespace Name
 } // namespace ns3