Skip to content

Packet Types

At a high level, NDN defines two distinct types of packets:

  • Interest packets are used to request data from the network. The most important component of an Interest packet is the name of the data being requested. An Interest may contain additional parameters such as a lifetime or hop limit, which are referred to as selectors.
  • Data packets carry the actual data being requested, along with the name of the Data and a cryptographic signature. On receiving an Interest packet, nodes in the network may respond with a Data matching the name in the Interest.

How are NDN packets used?

Interest and Data packets are used in a request-response fashion. An NDN application sends an Interest packet to request data from the network, and receives a single Data packet in response.

The following example illustrates the basic structure of Interest and Data packets.

classDiagram
  Interest <|-- Data
  class Interest{
    Name = /edu/ucla/cs/118/notes
    Lifetime = 5000 ms
  }
  class Data{
    Name = /edu/ucla/cs/118/notes
    Content = "Hello, NDN!"
    Signature = 3046022100e773b
  }

CanBePrefix Interest Selector

In this example, the name of the Interest and Data packets is an exact match. If the CanBePrefix selector is specified on the Interest, the name of a matching Data packet may be longer than the name of the Interest packet, as long as it has the name of the Interest as a prefix.

Data Signing

It is important to note that a Data packet is required to carry a signature to be considered valid.

TLV Encoding

On the wire, NDN packets are represented using the Type-Length-Value (NDN TLV1) encoding scheme. TLV is a highly efficient binary encoding scheme that supports variable length fields and nested structures.

Each field in the packet is encoded as a TLV element, which consists of a type, length, and value. The type and length fields are encoded as variable length integers, and the value field is encoded as a sequence of bytes (which in turn may be another TLV block). Interest and Data packets themselves are also encoded as TLV elements.

The following example illustrates the TLV encoding of the Interest and Data packets shown above. The type of the block is specified first (in red, hover for numeric), followed by the length (in blue) and the value.

Encoding of Names

NDN names are hierarchical and are encoded as a list of components. Each component is treated as an opaque binary value by the network, and may contain any sequence of bytes with no restrictions. For readability, names may be represented using the NDN URI Scheme using slashes as delimiters between components.

Packet Format Specification

The formal specification for Interest and Data packets and TLV encoding can be accessed here.

Library Functions

This section describes how to encode Interest and Data packets using some of the NDN client libraries. The next page will describe how to use the libraries to send and receive the packets.

#include <ndn-cxx/face.hpp>

int main(int argc, char** argv)
{
    // Create an NDN Name from a URI string
    ndn::Name name("/edu/ucla/cs/118/notes");

    // Create an Interest packet with this name
    ndn::Interest interest(name);

    // Set the Interest packet's InterestLifetime to 5 seconds
    interest.setInterestLifetime(ndn::time::seconds(5));

    // Create a Data packet with the same name
    ndn::Data data(name);

    // Set the Data packet's content to "Hello, NDN!"
    data.setContent(ndn::make_span(reinterpret_cast<const uint8_t*>("Hello, NDN!"), 11));
}
import ndn.encoding as enc
import ndn.security as sec

#  Create an Interest packet with its NDN name from a URI string
interest_wire = enc.make_interest(
    enc.Name.from_str('/edu/ucla/cs/118/notes'),
    # Set the Interest packet's InterestLifetime to 5 seconds
    enc.InterestParam(lifetime=5000),
)
print(interest_wire.hex())
# In python-ndn you do not have to encode the Interest manually.
# NDNApp's express function provides a more flexible API to send an Interest directly.

# Create a SHA256 digest signer
digest_signer = sec.DigestSha256Signer()
# Create a Data packet with the same name
data_wire = enc.make_data(
    # String can be directly used as Name in most cases
    name='/edu/ucla/cs/118/notes',
    # Set the Interest packet's FreshnessPeriod to 10 seconds
    meta_info=enc.MetaInfo(freshness_period=10000),
    # Set the Data packet's content to "Hello, NDN!"
    content=b'Hello, NDN!',
    signer=digest_signer
)
print(data_wire.hex())
import { Name, Interest, Data } from '@ndn/packet';
import { toUtf8 } from '@ndn/util';

// Create an NDN name from a URI string
const name = new Name('/edu/ucla/cs/118/notes');

// Create an Interest packet with this name
const interest = new Interest(name);

// Set the Interest packet's InterestLifetime to 5 seconds
interest.lifetime = 5000;

// Create a Data packet with the same name
const data = new Data(name);

// Set the Data packet's content to "Hello, NDN!"
data.content = toUtf8('Hello, NDN!');

  1. Ma, X. et al. 2022. A type-theoretic model on NDN-TLV encoding. Proceedings of the 9th ACM conference on information-centric networking (New York, NY, USA, 2022), 91–102.