24 #include "wire-ccnb.h" 
   27 #include "ns3/unused.h" 
   28 #include "ns3/packet.h" 
   30 #include "ccnb-parser/visitors/name-visitor.h" 
   31 #include "ccnb-parser/visitors/non-negative-integer-visitor.h" 
   32 #include "ccnb-parser/visitors/timestamp-visitor.h" 
   33 #include "ccnb-parser/visitors/uint32t-blob-visitor.h" 
   35 #include "ccnb-parser/syntax-tree/block.h" 
   36 #include "ccnb-parser/syntax-tree/dtag.h" 
   38 #include <boost/foreach.hpp> 
   40 NS_LOG_COMPONENT_DEFINE (
"ndn.wire.Ccnb.Interest");
 
   47 NS_OBJECT_ENSURE_REGISTERED (Interest);
 
   50 Interest::GetTypeId (
void)
 
   52   static TypeId tid = TypeId (
"ns3::ndn::Interest::Ccnb")
 
   55     .AddConstructor<Interest> ()
 
   61 Interest::GetInstanceTypeId (
void)
 const 
   67   : m_interest (Create<ndn::Interest> ())
 
   71 Interest::Interest (Ptr<ndn::Interest> interest)
 
   72   : m_interest (interest)
 
   77 Interest::GetInterest ()
 
   83 Interest::ToWire (Ptr<const ndn::Interest> interest)
 
   85   Ptr<const Packet> p = interest->GetWire ();
 
   88       Ptr<Packet> packet = Create<Packet> (*interest->GetPayload ());
 
   89       Interest wireEncoding (ConstCast<ndn::Interest> (interest));
 
   90       packet->AddHeader (wireEncoding);
 
   91       interest->SetWire (packet);
 
  100 Interest::FromWire (Ptr<Packet> packet)
 
  102   Ptr<ndn::Interest> interest = Create<ndn::Interest> ();
 
  103   Ptr<Packet> wire = packet->Copy ();
 
  105   Interest wireEncoding (interest);
 
  106   packet->RemoveHeader (wireEncoding);
 
  108   interest->SetPayload (packet);
 
  109   interest->SetWire (wire);
 
  115 Interest::Serialize (Buffer::Iterator start)
 const 
  153   if (m_interest->GetScope() >= 0)
 
  159   if (!m_interest->GetInterestLifetime().IsZero())
 
  165   if (m_interest->GetNonce()>0)
 
  167       uint32_t nonce = m_interest->GetNonce();
 
  171   if (m_interest->GetNack ()>0)
 
  181 Interest::GetSerializedSize ()
 const 
  220   if (m_interest->GetScope() >= 0)
 
  226   if (!m_interest->GetInterestLifetime().IsZero())
 
  232   if (m_interest->GetNonce()>0)
 
  236   if (m_interest->GetNack ()>0)
 
  270     case CcnbParser::CCN_DTAG_Interest:
 
  271       NS_LOG_DEBUG (
"Interest");
 
  274       BOOST_FOREACH (Ptr<CcnbParser::Block> block, n.
m_nestedTags)
 
  276           block->accept (*
this, param);
 
  279     case CcnbParser::CCN_DTAG_Name:
 
  281         NS_LOG_DEBUG (
"Name");
 
  284         Ptr<Name> name = Create<Name> ();
 
  285         n.
accept (nameVisitor, GetPointer (name));
 
  343     case CcnbParser::CCN_DTAG_Scope: 
 
  344       NS_LOG_DEBUG (
"Scope");
 
  348                boost::any_cast<uint32_t> (
 
  350                                                                            nonNegativeIntegerVisitor
 
  353     case CcnbParser::CCN_DTAG_InterestLifetime:
 
  354       NS_LOG_DEBUG (
"InterestLifetime");
 
  359                boost::any_cast<Time> (
 
  364     case CcnbParser::CCN_DTAG_Nonce:
 
  365       NS_LOG_DEBUG (
"Nonce");
 
  370                boost::any_cast<uint32_t> (
 
  377     case CcnbParser::CCN_DTAG_Nack:
 
  378       NS_LOG_DEBUG (
"Nack");
 
  383                boost::any_cast<uint32_t> (
 
  384                                           (*n.
m_nestedTags.begin())->accept(nonNegativeIntegerVisitor)));
 
  391 Interest::Deserialize (Buffer::Iterator start)
 
  395   Buffer::Iterator i = start;
 
  397   root->accept (interestVisitor, GetPointer (m_interest));
 
  399   return i.GetDistanceFrom (start);
 
  403 Interest::Print (std::ostream &os)
 const 
  405   os << 
"I: " << m_interest->GetName ();
 
Depth-first visitor that takes one argument and returns nothing. 
 
void SetScope(int8_t scope)
Set Scope Scope limits where the Interest may propagate. 
 
static size_t EstimateBlockHeader(size_t value)
Estimate size of the CCNB block header. 
 
static size_t EstimateNumber(uint32_t number)
Estimate size of the number in CCNB encoding. 
 
std::list< Ptr< Block > > m_nestedTags
List of nested tags. 
 
static size_t SerializeName(Buffer::Iterator &start, const Name &name)
Append Name in CCNB encoding. 
 
Exception thrown if there is a parsing error. 
 
static size_t EstimateTimestampBlob(const Time &time)
Estimate size of a binary timestamp as a BLOB using CCNB enconding. 
 
virtual void visit(CcnbParser::Dtag &n, boost::any param)
Method accepting DTAG block. 
 
Class to represent DTAG ccnb-encoded node. 
 
static size_t AppendTimestampBlob(Buffer::Iterator &start, const Time &time)
Append a binary timestamp as a BLOB using the ccn binary Timestamp representation (12-bit fraction)...
 
static size_t AppendBlockHeader(Buffer::Iterator &start, size_t value, uint32_t block_type)
Append CCNB block header. 
 
static size_t EstimateTaggedBlob(uint32_t dtag, size_t size)
Estimate size of a tagged BLOB in CCNB enconding. 
 
void SetNack(uint8_t nackType)
Mark the Interest as a Negative Acknowledgement Three types of NACKs are supported. 
 
static size_t AppendNumber(Buffer::Iterator &start, uint32_t number)
Add number in CCNB encoding. 
 
void SetInterestLifetime(Time time)
Set InterestLifetime InterestLifetime indicates the (approximate) time remaining before the interest ...
 
uint32_t m_dtag
Dictionary code for DTAG. 
 
Visitor to obtain fill CcnxName object with name components. 
 
Visitor to obtain non-negative integer value from UDATA block. 
 
static size_t AppendTaggedBlob(Buffer::Iterator &start, uint32_t dtag, const uint8_t *data, size_t size)
Append a tagged BLOB. 
 
static size_t AppendCloser(Buffer::Iterator &start)
Append CCNB closer tag (estimated size is 1) 
 
static Ptr< Block > ParseBlock(Buffer::Iterator &start, bool dontParseBlock=false)
Parsing stream (recursively) and creating a parsed BLOCK object. 
 
Visitor to obtain timestamp value from BLOB block. 
 
static size_t SerializedSizeName(const Name &name)
Estimate size of Name in CCNB encoding. 
 
Visitor to obtain nonce value from BLOB block. 
 
NDN Interest (wire formats are defined in wire) 
 
virtual void accept(VoidNoArguVisitor &v)
Accept visitor void(*)() 
 
void SetName(Ptr< Name > name)
Set interest name. 
 
void SetNonce(uint32_t nonce)
Set Nonce Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicat...