[ndnSIM] about Interest & Data

Samira Moosavi moosavi.itsu at yahoo.com
Mon Aug 31 00:37:53 PDT 2015



Dear all
I want to work with ndnSIM. Now I would be appreciate if any one could explain about code of Interest and Data for me?
code of Interest::

#include "ndn-interest.h"

#include "ns3/log.h"
#include "ns3/unused.h"
#include "ns3/packet.h"

NS_LOG_COMPONENT_DEFINE ("ndn.Interest");

namespace ns3 {
namespace ndn {

Interest::Interest (Ptr<Packet> payload/* = Create<Packet> ()*/)
  : m_name ()
  , m_scope (0xFF)
  , m_interestLifetime (Seconds (0))
  , m_nonce (0)
  , m_nackType (NORMAL_INTEREST)
  , m_exclude (0)
  , m_payload (payload)
  , m_wire (0)
{
  if (m_payload == 0) // just in case
    {
      m_payload = Create<Packet> ();
    }
}

Interest::Interest (const Interest &interest)
  : m_name             (Create<Name> (interest.GetName ()))
  , m_scope            (interest.m_scope)
  , m_interestLifetime (interest.m_interestLifetime)
  , m_nonce            (interest.m_nonce)
  , m_nackType         (interest.m_nackType)
  , m_exclude          (interest.m_exclude ? Create<Exclude> (*interest.GetExclude ()) : 0)
  , m_payload          (interest.GetPayload ()->Copy ())
  , m_wire             (0)
{
  NS_LOG_FUNCTION ("correct copy constructor");
}

void
Interest::SetName (Ptr<Name> name)
{
  m_name = name;
  m_wire = 0;
}

void
Interest::SetName (const Name &name)
{
  m_name = Create<Name> (name);
  m_wire = 0;
}

const Name&
Interest::GetName () const
{
  if (m_name==0) throw InterestException();
  return *m_name;
}

Ptr<const Name>
Interest::GetNamePtr () const
{
  return m_name;
}

void
Interest::SetScope (int8_t scope)
{
  m_scope = scope;
  m_wire = 0;
}

int8_t
Interest::GetScope () const
{
  return m_scope;
}

void
Interest::SetInterestLifetime (Time lifetime)
{
  m_interestLifetime = lifetime;
  m_wire = 0;
}

Time
Interest::GetInterestLifetime () const
{
  return m_interestLifetime;
}

void
Interest::SetNonce (uint32_t nonce)
{
  m_nonce = nonce;
  m_wire = 0;
}

uint32_t
Interest::GetNonce () const
{
  return m_nonce;
}

void
Interest::SetNack (uint8_t nackType)
{
  m_nackType = nackType;
  m_wire = 0;
}

uint8_t
Interest::GetNack () const
{
  return m_nackType;
}

void
Interest::SetExclude (Ptr<Exclude> exclude)
{
  m_exclude = exclude;
  m_wire = 0;
}

Ptr<const Exclude>
Interest::GetExclude () const
{
  return m_exclude;
}

void
Interest::SetPayload (Ptr<Packet> payload)
{
  m_payload = payload;
  m_wire = 0;
}

Ptr<const Packet>
Interest::GetPayload () const
{
  return m_payload;
}

void
Interest::Print (std::ostream &os) const
{
  os << "I: " << GetName ();
  
  return;
  os << "<Interest>\n  <Name>" << GetName () << "</Name>\n";
  if (GetNack ()>0)
    {
      os << "  <NACK>";
      switch (GetNack ())
        {
        case NACK_LOOP:
          os << "loop";
          break;
        case NACK_CONGESTION:
          os << "congestion";
          break;
        default:
          os << "unknown";
          break;
        }
      os << "</NACK>\n";
    }
  os << "  <Scope>" << GetScope () << "</Scope>\n";
  if ( !GetInterestLifetime ().IsZero() )
    os << "  <InterestLifetime>" << GetInterestLifetime () << "</InterestLifetime>\n";
  if (GetNonce ()>0)
    os << "  <Nonce>" << GetNonce () << "</Nonce>\n";
  os << "</Interest>";
}

} // namespace ndn
} // namespace ns3

code of Data::

#include "ndn-data.h"

#include "ns3/log.h"

#include <boost/foreach.hpp>

NS_LOG_COMPONENT_DEFINE ("ndn.Data");

namespace ns3 {
namespace ndn {

Data::Data (Ptr<Packet> payload/* = Create<Packet> ()*/)
  : m_name (Create<Name> ())
  , m_signature (0)
  , m_payload (payload)
  , m_keyLocator (0)
  , m_wire (0)
{
  if (m_payload == 0) // just in case
    {
      m_payload = Create<Packet> ();
    }
}

Data::Data (const Data &other)
  : m_name (Create<Name> (other.GetName ()))
  , m_freshness (other.GetFreshness ())
  , m_timestamp (other.GetTimestamp ())
  , m_signature (other.GetSignature ())
  , m_payload (other.GetPayload ()->Copy ())
  , m_wire (0)
{
  if (other.GetKeyLocator ())
    {
      m_keyLocator = Create<Name> (*other.GetKeyLocator ());
    }
}

void
Data::SetName (Ptr<Name> name)
{
  m_name = name;
  m_wire = 0;
}

void
Data::SetName (const Name &name)
{
  m_name = Create<Name> (name);
  m_wire = 0;
}

const Name&
Data::GetName () const
{
  if (m_name==0) throw DataException();
  return *m_name;
}

Ptr<const Name>
Data::GetNamePtr () const
{
  return m_name;
}


void
Data::SetTimestamp (const Time &timestamp)
{
  m_timestamp = timestamp;
  m_wire = 0;
}

Time
Data::GetTimestamp () const
{
  return m_timestamp;
}
    
void
Data::SetFreshness (const Time &freshness)
{
  m_freshness = freshness;
  m_wire = 0;
}


Time
Data::GetFreshness () const
{
  return m_freshness;
}

void
Data::SetSignature (uint32_t signature)
{
  m_signature = signature;
  m_wire = 0;
}

uint32_t
Data::GetSignature () const
{
  return m_signature;
}

void
Data::SetKeyLocator (Ptr<Name> keyLocator)
{
  m_keyLocator = keyLocator;
}

Ptr<const Name>
Data::GetKeyLocator () const
{
  return m_keyLocator;
}

void
Data::Print (std::ostream &os) const
{
  os << "D: " << GetName ();
  // os << "<Data><Name>" << GetName () << "</Name><Content>";
}

void
Data::SetPayload (Ptr<Packet> payload)
{
  m_payload = payload;
  m_wire = 0;
}

Ptr<const Packet>
Data::GetPayload () const
{
  return m_payload;
}

} // namespace ndn
} // namespace ns3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/ndnsim/attachments/20150831/f33f1d5b/attachment.html>


More information about the ndnSIM mailing list