[ndnSIM] How to get nonce value from the reply object?

Alex Afanasyev alexander.afanasyev at ucla.edu
Sun Jul 28 15:40:22 PDT 2013


Hi!

With Data packet you can really put anything inside as part of the content.  There are many ways to do that, but in NS-3 the preferred method is to use a custom header.  It can be something like this:

class NonceHeader : public Header
{
public:
  static TypeId GetTypeId (void)
  {
    static TypeId tid = TypeId ("ns3::NonceHeader")
      .SetParent<Header> ()
      ;
    return tid;
  }

  NonceHeader ()
    : m_nonce (0)
  {
  }

  NonceHeader (uint32_t nonce)
    : m_nonce (nonce
  {
  }

  uint32_t
  GetNonce () const
  {
    return m_length;
  }

  virtual TypeId
  GetInstanceTypeId (void) const
  {
    return NonceHeader::GetTypeId ();
  }

  virtual void
  Print (std::ostream &os) const
  {
    os << m_nonce;
  }

  virtual uint32_t
  GetSerializedSize (void) const
  {
    return 4;
  }

  virtual void
  Serialize (Buffer::Iterator start) const
  {
    start.WriteU32 (m_nonce);
  }

  virtual uint32_t
  Deserialize (Buffer::Iterator start)
  {
    m_nonce = start.ReadU32 ();
    return 4;
  }

private:
  uint32_t m_nonce;
};

...

// in producer
void
OnInterest (Ptr<const Interest> interest)
{
  Ptr<Packet> content = Create<Packet> (m_virtualPayloadSize);
  // or just Ptr<Packet> content = Create<Packet> ();  if you don't need data packet to carry virtual payload
  NonceHeader hdr (intereset->GetNonce ());
  content->AddHeader (hdr);

  Ptr<ContentObject> data = Create<ContentObject> (content);

  // the rest is standard from apps/ndn-producer.cc
}

// in consumer
void
OnContentObject (Ptr<const ContentObject> data)
{
  NonceHeader hdr;
  data->GetPayload ()->PeekHeader (hdr);

  uint32_t echoedNonce = hdr->GetNonce ();
  // use it somehow
}
---
Alex

PS
My example uses API from version 0.5 of ndnSIM, which is a little bit different from the "old" one.

On Jul 28, 2013, at 7:01 AM, Prasertsak U. <gniliamg at gmail.com> wrote:

> For now, I solve my problem already, which workaround by signature field of ContentObject.
> 
> //  @Provider App.
> void OnInterest(...)
> {
>      ndn::ContentObjectHeader data;
>      ...
>      data.SetSignature(interest->GetNonce());
>      ...
> }
> 
> // @Consumer App.
> void OnContentObject (...)
> {
>      ...
>      uint32_t reply_nonce = contentObject->GetSignature();
>      ...
> }
> 
> Regards,
> Prasertsak U.
> 
> 
> On Sun, Jul 28, 2013 at 6:52 PM, Prasertsak U. <gniliamg at gmail.com> wrote:
> Dear All,
> 
> I'm trying to use nonce value from the reply step to map something in the buffer. 
> Unfortunately, I'm not found the way to get nonce value from the reply object in the method "OnContentObject". Anybody knows the way or some hints for mapping between request packet and the reply packet.  (I mean any headers or fields like a nonce of Interest packet)
> 
> Overview Diagram for mapping:
> (1) Create Interest Packet -----> (2) Keep sender nonce value -----> (3) waiting for reply 
> (4) Receive Reply content -----> (*5) Get nonce value from reply objects ------> 
> (6) mapping with the buffer in step-2 ----> etc.
>  
> 
> Thank you.
> 
> Regards,
> Prasertsak U.
> 
> Computing Department, Silpakorn University, Thailand.
> 
> 
> _______________________________________________
> ndnSIM mailing list
> ndnSIM at lists.cs.ucla.edu
> http://www.lists.cs.ucla.edu/mailman/listinfo/ndnsim

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/ndnsim/attachments/20130728/6f8c1fdd/attachment.html>


More information about the ndnSIM mailing list