21 #include "ndn-api-face.h" 
   22 #include "detail/pending-interests-container.h" 
   23 #include "detail/registered-prefix-container.h" 
   25 #include <ns3/random-variable.h> 
   27 #include <ns3/ndn-l3-protocol.h> 
   28 #include <ns3/ndn-interest.h> 
   29 #include <ns3/ndn-data.h> 
   30 #include <ns3/ndn-face.h> 
   31 #include <ns3/ndn-fib.h> 
   33 #include <ns3/packet.h> 
   37 using namespace boost;
 
   40 NS_LOG_COMPONENT_DEFINE (
"ndn.ApiFace");
 
   45 using namespace detail;
 
   51     : m_rand (0, std::numeric_limits<uint32_t>::max ())
 
   55   ns3::UniformVariable m_rand; 
 
   62 ApiFace::ApiFace (Ptr<Node> node)
 
   66   NS_LOG_FUNCTION (
this << boost::cref (*
this));
 
   68   NS_ASSERT_MSG (
GetNode ()->GetObject<L3Protocol> () != 0,
 
   69                  "NDN stack should be installed on the node " << 
GetNode ());
 
   78   NS_LOG_FUNCTION (
this << boost::cref (*
this));
 
   86   NS_LOG_FUNCTION (
this << boost::cref (*
this));
 
   95   m_this->m_pendingInterests.clear ();
 
   96   m_this->m_expectedInterests.clear ();
 
  104                           TimeoutCallback onTimeout)
 
  106   NS_LOG_INFO (
">> I " << interest->GetName ());
 
  108   if (interest->GetNonce () == 0)
 
  110       interest->SetNonce (m_this->m_rand.GetValue ());
 
  114   bool needToActuallyExpressInterest = 
false;
 
  115   PendingInterestContainer::iterator entry = m_this->m_pendingInterests.
find_exact (interest->GetName ());
 
  116   if (entry == m_this->m_pendingInterests.end ())
 
  118       pair<PendingInterestContainer::iterator, bool> status =
 
  119         m_this->m_pendingInterests.insert (interest->GetName (), Create <PendingInterestEntry> (interest));
 
  121       entry = status.first;
 
  123       needToActuallyExpressInterest = 
true;
 
  125   entry->payload ()->AddCallbacks (onData, onTimeout);
 
  127   if (needToActuallyExpressInterest)
 
  136   NS_LOG_DEBUG (
"== setInterestFilter " << *prefix << 
" (" << 
GetNode ()->
GetId () << 
")");
 
  138   RegisteredPrefixContainer::iterator entry = m_this->m_expectedInterests.
find_exact (*prefix);
 
  139   if (entry == m_this->m_expectedInterests.end ())
 
  141       pair<RegisteredPrefixContainer::iterator, bool> status =
 
  142         m_this->m_expectedInterests.insert (*prefix, Create < RegisteredPrefixEntry > (prefix));
 
  144       entry = status.first;
 
  147   entry->payload ()->AddCallback (onInterest);
 
  151   Ptr<ndn::fib::Entry> fibEntry = fib->
Add (prefix, 
this, 0);
 
  152   fibEntry->UpdateStatus (
this, ndn::fib::FaceMetric::NDN_FIB_GREEN);
 
  158   RegisteredPrefixContainer::iterator entry = m_this->m_expectedInterests.
find_exact (*prefix);
 
  159   if (entry == m_this->m_expectedInterests.end ())
 
  162   entry->payload ()->ClearCallback ();
 
  163   m_this->m_expectedInterests.erase (entry);
 
  169   NS_LOG_INFO (
">> D " << data->GetName ());
 
  182   NS_LOG_FUNCTION (
this << interest);
 
  184   NS_LOG_DEBUG (
"<< I " << interest->GetName ());
 
  192   RegisteredPrefixContainer::iterator entry = m_this->m_expectedInterests.
longest_prefix_match (interest->GetName ());
 
  193   if (entry == m_this->m_expectedInterests.end ())
 
  198   if (!entry->payload ()->m_callback.IsNull ())
 
  199     entry->payload ()->m_callback (entry->payload ()->GetPrefix (), interest);
 
  207   NS_LOG_DEBUG (
"<< D " << data->GetName ());
 
  215   PendingInterestContainer::iterator entry = m_this->m_pendingInterests.
longest_prefix_match (data->GetName ());
 
  216   if (entry == m_this->m_pendingInterests.end ())
 
  221   while (entry != m_this->m_pendingInterests.end ())
 
  223       entry->payload ()->ProcessOnData (entry->payload ()->GetInterest (), data);
 
  224       m_this->m_pendingInterests.erase (entry);
 
  228   m_this->m_pendingInterests.erase (entry);
 
  236   os << 
"dev=ApiFace(" << 
GetId () << 
")";
 
void SetUp(bool up=true)
These are face states and may be distinct from actual lower-layer device states, such as found in rea...
 
void ExpressInterest(Ptr< Interest > interest, DataCallback onData, TimeoutCallback onTimeout)
Express Interest. 
 
virtual Ptr< fib::Entry > Add(const Name &prefix, Ptr< Face > face, int32_t metric)=0
Add or update FIB entry. 
 
virtual bool ReceiveInterest(Ptr< Interest > interest)
Receive interest from application or another node and forward it up to the NDN stack. 
 
uint32_t GetId() const 
Get face Id. 
 
Implementation network-layer of NDN stack. 
 
Virtual class defining NDN face. 
 
iterator longest_prefix_match(const FullKey &key)
Find a node that has the longest common prefix with key (FIB/PIT lookup) 
 
virtual bool SendData(Ptr< const Data > data)
Send out Dat packet through the face. 
 
void ClearInterestFilter(Ptr< const Name > prefix)
clear Interest filter 
 
virtual bool SendInterest(Ptr< const Interest > interest)
Send out interest through the face. 
 
void SetFlags(uint32_t flags)
Set face flags. 
 
Class implementing FIB functionality. 
 
void Put(Ptr< Data > data)
Publish data. 
 
Ptr< Node > GetNode() const 
Get node to which this face is associated. 
 
virtual bool ReceiveData(Ptr< Data > data)
Receive Data packet from application or another node and forward it up to the NDN stack...
 
bool IsUp() const 
Returns true if this face is enabled, false otherwise. 
 
virtual void Shutdown()
Shutdown the API face. 
 
void SetInterestFilter(Ptr< const Name > prefix, InterestCallback onInterest)
set Interest filter (specify what interest you want to receive) 
 
virtual std::ostream & Print(std::ostream &os) const 
Print information about the face into the stream. 
 
iterator find_exact(const FullKey &key)
Find a node that has the exact match with the key.