NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
ndn::util::SegmentFetcher Class Reference

Utility class to fetch latest version of the segmented data. More...

#include <segment-fetcher.hpp>

Inheritance diagram for ndn::util::SegmentFetcher:
Collaboration diagram for ndn::util::SegmentFetcher:

Public Types

enum  ErrorCode { INTEREST_TIMEOUT = 1, DATA_HAS_NO_SEGMENT = 2, SEGMENT_VERIFICATION_FAIL = 3 }
 Error codes that can be passed to ErrorCallback. More...
 
typedef function< void(const ConstBufferPtr &data)> CompleteCallback
 
typedef function< bool(const Data &data)> VerifySegment
 
typedef function< void(uint32_t code, const std::string &msg)> ErrorCallback
 

Static Public Member Functions

static void fetch (Face &face, const Interest &baseInterest, const VerifySegment &verifySegment, const CompleteCallback &completeCallback, const ErrorCallback &errorCallback)
 Initiate segment fetching. More...
 

Detailed Description

Utility class to fetch latest version of the segmented data.

SegmentFetcher assumes that the data is named /<prefix>/<version>/<segment>, where:

  • <prefix> is the specified prefix,
  • <version> is an unknown version that needs to be discovered, and
  • <segment> is a segment number (number of segments is unknown and is controlled by FinalBlockId field in at least the last Data packet

The following logic is implemented in SegmentFetcher:

  1. Express first interest to discover version:

Interest: /<prefix>?ChildSelector=1&MustBeFresh=yes

  1. Infer the latest version of Data: <version> = Data.getName().get(-2)
  2. If segment number in the retrieved packet == 0, go to step 5.
  3. Send Interest for segment 0:

Interest: /<prefix>/<version>/<segment=0>

  1. Keep sending Interests for the next segment while the retrieved Data does not have FinalBlockId or FinalBlockId != Data.getName().get(-1).

Interest: /<prefix>/<version>/<segment=(N+1))>

  1. Fire onCompletion callback with memory block that combines content part from all segmented objects.

If an error occurs during the fetching process, an error callback is fired with a proper error code. The following errors are possible:

  • INTEREST_TIMEOUT: if any of the Interests times out
  • DATA_HAS_NO_SEGMENT: if any of the retrieved Data packets don't have segment as a last component of the name (not counting implicit digest)
  • SEGMENT_VERIFICATION_FAIL: if any retrieved segment fails user-provided validation

In order to validate individual segments, an VerifySegment callback needs to be specified. If the callback returns false, fetching process is aborted with SEGMENT_VERIFICATION_FAIL. If data validation is not required, provided DontVerifySegment() functor can be used.

Examples:

void
onComplete(const ConstBufferPtr& data)
{
  ...
}

void
onError(uint32_t errorCode, const std::string& errorMsg)
{
  ...
}

...
SegmentFetcher::fetch(face, Interest("/data/prefix", time::seconds(1000)),
                      DontVerifySegment(),
                      bind(&onComplete, this, _1),
                      bind(&onError, this, _1, _2));

Definition at line 112 of file segment-fetcher.hpp.

Member Typedef Documentation

typedef function<void (const ConstBufferPtr& data)> ndn::util::SegmentFetcher::CompleteCallback

Definition at line 115 of file segment-fetcher.hpp.

typedef function<bool (const Data& data)> ndn::util::SegmentFetcher::VerifySegment

Definition at line 116 of file segment-fetcher.hpp.

typedef function<void (uint32_t code, const std::string& msg)> ndn::util::SegmentFetcher::ErrorCallback

Definition at line 117 of file segment-fetcher.hpp.

Member Enumeration Documentation

Error codes that can be passed to ErrorCallback.

Enumerator
INTEREST_TIMEOUT 
DATA_HAS_NO_SEGMENT 
SEGMENT_VERIFICATION_FAIL 

Definition at line 122 of file segment-fetcher.hpp.

Member Function Documentation

void ndn::util::SegmentFetcher::fetch ( Face face,
const Interest baseInterest,
const VerifySegment verifySegment,
const CompleteCallback completeCallback,
const ErrorCallback errorCallback 
)
static

Initiate segment fetching.

Parameters
faceReference to the Face that should be used to fetch data
baseInterestAn Interest for the initial segment of requested data. This interest may include custom InterestLifetime and selectors that will propagate to all subsequent Interests. The only exception is that the initial Interest will be forced to include "ChildSelector=1" and "MustBeFresh=true" selectors, which will be turned off in subsequent Interests.
verifySegmentFunctor to be called when Data segment is received. If functor return false, fetching will be aborted with SEGMENT_VERIFICATION_FAIL error
completeCallbackCallback to be fired when all segments are fetched
errorCallbackCallback to be fired when an error occurs (
See also
Errors)

Definition at line 42 of file segment-fetcher.cpp.

References ndn::Name::appendSegment(), ndn::name::Component::empty(), ndn::Name::get(), ndn::Data::getContent(), ndn::MetaInfo::getFinalBlockId(), ndn::Data::getMetaInfo(), ndn::Data::getName(), ndn::Name::getPrefix(), ndn::Interest::refreshNonce(), ndn::Interest::setChildSelector(), ndn::Interest::setMustBeFresh(), ndn::Interest::setName(), ndn::name::Component::toSegment(), ndn::Block::value(), and ndn::Block::value_size().


The documentation for this class was generated from the following files: