ndn::util::DummyClientFace Class Reference

A client-side face for unit testing. More...

#include <ndn-cxx/util/dummy-client-face.hpp>

+ Inheritance diagram for ndn::util::DummyClientFace:
+ Collaboration diagram for ndn::util::DummyClientFace:

Classes

class  AlreadyLinkedError
 
class  Options
 Options for DummyClientFace. More...
 

Public Member Functions

 DummyClientFace (boost::asio::io_service &ioService, const Options &options=Options())
 Create a dummy face with the provided IO service. More...
 
 DummyClientFace (boost::asio::io_service &ioService, KeyChain &keyChain, const Options &options=Options())
 Create a dummy face with the provided IO service and the specified KeyChain. More...
 
 DummyClientFace (const Options &options=Options())
 Create a dummy face with internal IO service. More...
 
 DummyClientFace (KeyChain &keyChain, const Options &options=Options())
 Create a dummy face with internal IO service and the specified KeyChain. More...
 
 ~DummyClientFace () override
 
PendingInterestHandle expressInterest (const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
 Express an Interest. More...
 
boost::asio::io_service & getIoService ()
 Returns a reference to the io_service used by this face. More...
 
size_t getNPendingInterests () const
 Get number of pending Interests. More...
 
void linkTo (DummyClientFace &other)
 Link another DummyClientFace through a broadcast media. More...
 
void processEvents (time::milliseconds timeout=time::milliseconds::zero(), bool keepThread=false)
 Process any data to receive or call timeout callbacks. More...
 
void put (Data data)
 Publish a Data packet. More...
 
void put (lp::Nack nack)
 Send a Network Nack. More...
 
void receive (const Data &data)
 Cause the Face to receive a Data packet. More...
 
void receive (const Interest &interest)
 Cause the Face to receive an Interest packet. More...
 
void receive (const lp::Nack &nack)
 Cause the Face to receive a Nack packet. More...
 
RegisteredPrefixHandle registerPrefix (const Name &prefix, const RegisterPrefixSuccessCallback &onSuccess, const RegisterPrefixFailureCallback &onFailure, const security::SigningInfo &signingInfo=security::SigningInfo(), uint64_t flags=nfd::ROUTE_FLAG_CHILD_INHERIT)
 Register prefix with the connected NDN forwarder. More...
 
void removeAllPendingInterests ()
 Cancel all previously expressed Interests. More...
 
InterestFilterHandle setInterestFilter (const InterestFilter &filter, const InterestCallback &onInterest)
 Set an InterestFilter to dispatch matching incoming Interests to onInterest callback. More...
 
RegisteredPrefixHandle setInterestFilter (const InterestFilter &filter, const InterestCallback &onInterest, const RegisterPrefixFailureCallback &onFailure, const security::SigningInfo &signingInfo=security::SigningInfo(), uint64_t flags=nfd::ROUTE_FLAG_CHILD_INHERIT)
 Set InterestFilter to dispatch incoming matching interest to onInterest callback and register the filtered prefix with the connected NDN forwarder. More...
 
RegisteredPrefixHandle setInterestFilter (const InterestFilter &filter, const InterestCallback &onInterest, const RegisterPrefixSuccessCallback &onSuccess, const RegisterPrefixFailureCallback &onFailure, const security::SigningInfo &signingInfo=security::SigningInfo(), uint64_t flags=nfd::ROUTE_FLAG_CHILD_INHERIT)
 Set InterestFilter to dispatch incoming matching interest to onInterest callback and register the filtered prefix with the connected NDN forwarder. More...
 
void shutdown ()
 Shutdown face operations. More...
 
void unlink ()
 Unlink the broadcast media if previously linked. More...
 

Public Attributes

Signal< DummyClientFace, DataonSendData
 Emits whenever a Data packet is sent. More...
 
Signal< DummyClientFace, InterestonSendInterest
 Emits whenever an Interest is sent. More...
 
Signal< DummyClientFace, lp::NackonSendNack
 Emits whenever a Nack is sent. More...
 
std::vector< DatasentData
 Data sent out of this DummyClientFace. More...
 
std::vector< InterestsentInterests
 Interests sent out of this DummyClientFace. More...
 
std::vector< lp::NacksentNacks
 Nacks sent out of this DummyClientFace. More...
 

Protected Member Functions

shared_ptr< Transport > getTransport () const
 Returns the underlying transport. More...
 

Detailed Description

A client-side face for unit testing.

Definition at line 34 of file dummy-client-face.hpp.

Constructor & Destructor Documentation

◆ DummyClientFace() [1/4]

ndn::util::DummyClientFace::DummyClientFace ( const Options options = Options())
explicit

Create a dummy face with internal IO service.

Definition at line 82 of file dummy-client-face.cpp.

◆ DummyClientFace() [2/4]

ndn::util::DummyClientFace::DummyClientFace ( KeyChain &  keyChain,
const Options options = Options() 
)
explicit

Create a dummy face with internal IO service and the specified KeyChain.

Definition at line 90 of file dummy-client-face.cpp.

◆ DummyClientFace() [3/4]

ndn::util::DummyClientFace::DummyClientFace ( boost::asio::io_service &  ioService,
const Options options = Options() 
)
explicit

Create a dummy face with the provided IO service.

Definition at line 97 of file dummy-client-face.cpp.

◆ DummyClientFace() [4/4]

ndn::util::DummyClientFace::DummyClientFace ( boost::asio::io_service &  ioService,
KeyChain &  keyChain,
const Options options = Options() 
)

Create a dummy face with the provided IO service and the specified KeyChain.

Definition at line 105 of file dummy-client-face.cpp.

◆ ~DummyClientFace()

ndn::util::DummyClientFace::~DummyClientFace ( )
override

Definition at line 112 of file dummy-client-face.cpp.

Member Function Documentation

◆ expressInterest()

PendingInterestHandle ndn::Face::expressInterest ( const Interest interest,
const DataCallback afterSatisfied,
const NackCallback afterNacked,
const TimeoutCallback afterTimeout 
)
inherited

Express an Interest.

Parameters
interestthe Interest; a copy will be made, so that the caller is not required to maintain the argument unchanged
afterSatisfiedfunction to be invoked if Data is returned
afterNackedfunction to be invoked if Network NACK is returned
afterTimeoutfunction to be invoked if neither Data nor Network NACK is returned within InterestLifetime
Exceptions
OversizedPacketErrorencoded Interest size exceeds MAX_NDN_PACKET_SIZE
Returns
A handle for canceling the pending Interest.

Definition at line 164 of file face.cpp.

◆ getIoService()

boost::asio::io_service& ndn::Face::getIoService ( )
inlineinherited

Returns a reference to the io_service used by this face.

Definition at line 423 of file face.hpp.

◆ getNPendingInterests()

size_t ndn::Face::getNPendingInterests ( ) const
inherited

Get number of pending Interests.

Definition at line 190 of file face.cpp.

◆ getTransport()

shared_ptr<Transport> ndn::Face::getTransport ( ) const
inlineprotectedinherited

Returns the underlying transport.

Definition at line 433 of file face.hpp.

◆ linkTo()

void ndn::util::DummyClientFace::linkTo ( DummyClientFace other)

Link another DummyClientFace through a broadcast media.

Definition at line 275 of file dummy-client-face.cpp.

◆ processEvents()

void ndn::Face::processEvents ( time::milliseconds  timeout = time::milliseconds::zero(),
bool  keepThread = false 
)
inlineinherited

Process any data to receive or call timeout callbacks.

This call will block forever (with the default timeout of 0) to process I/O on the face. To exit cleanly on a producer, clear any Interest filters and wait for processEvents() to return. To exit after an error, one can call shutdown(). In consumer applications, processEvents() will return when all expressed Interests have been satisfied, Nacked, or timed out. To terminate earlier, a consumer application should cancel all previously expressed and still-pending Interests.

If a positive timeout is specified, then processEvents() will exit after this timeout, provided it is not stopped earlier with shutdown() or when all active events finish. processEvents() can be called repeatedly, if desired.

If a negative timeout is specified, then processEvents will not block and will process only pending events.

Parameters
timeoutmaximum time to block the thread
keepThreadKeep thread in a blocked state (in event processing), even when there are no outstanding events (e.g., no Interest/Data is expected). If timeout is zero and this parameter is true, the only way to stop processEvents() is to call shutdown().
Note
This may throw an exception for reading data or in the callback for processing the data. If you call this from an main event loop, you may want to catch and log/disregard all exceptions.
Exceptions
OversizedPacketErrorencoded packet size exceeds MAX_NDN_PACKET_SIZE

Definition at line 397 of file face.hpp.

◆ put() [1/2]

void ndn::Face::put ( Data  data)
inherited

Publish a Data packet.

Parameters
datathe Data; a copy will be made, so that the caller is not required to maintain the argument unchanged

This method can be called to satisfy incoming Interests, or to add Data packet into the cache of the local NDN forwarder if forwarder is configured to accept unsolicited Data.

Exceptions
OversizedPacketErrorencoded Data size exceeds MAX_NDN_PACKET_SIZE

Definition at line 196 of file face.cpp.

◆ put() [2/2]

void ndn::Face::put ( lp::Nack  nack)
inherited

Send a Network Nack.

Parameters
nackthe Nack; a copy will be made, so that the caller is not required to maintain the argument unchanged
Exceptions
OversizedPacketErrorencoded Nack size exceeds MAX_NDN_PACKET_SIZE

Definition at line 204 of file face.cpp.

◆ receive() [1/3]

void ndn::util::DummyClientFace::receive ( const Data data)

Cause the Face to receive a Data packet.

Definition at line 250 of file dummy-client-face.cpp.

◆ receive() [2/3]

void ndn::util::DummyClientFace::receive ( const Interest interest)

Cause the Face to receive an Interest packet.

Definition at line 238 of file dummy-client-face.cpp.

◆ receive() [3/3]

void ndn::util::DummyClientFace::receive ( const lp::Nack nack)

Cause the Face to receive a Nack packet.

Definition at line 261 of file dummy-client-face.cpp.

◆ registerPrefix()

RegisteredPrefixHandle ndn::Face::registerPrefix ( const Name prefix,
const RegisterPrefixSuccessCallback onSuccess,
const RegisterPrefixFailureCallback onFailure,
const security::SigningInfo signingInfo = security::SigningInfo(),
uint64_t  flags = nfd::ROUTE_FLAG_CHILD_INHERIT 
)
inherited

Register prefix with the connected NDN forwarder.

This method only modifies forwarder's RIB and does not associate any onInterest callbacks. Use setInterestFilter method to dispatch incoming Interests to the right callbacks.

Parameters
prefixA prefix to register with the connected NDN forwarder
onSuccessA callback to be called when prefixRegister command succeeds
onFailureA callback to be called when prefixRegister command fails
signingInfoSigning parameters. When omitted, a default parameters used in the signature will be used.
flagsPrefix registration flags
Returns
A handle for unregistering the prefix.
See also
nfd::RouteFlags

Definition at line 246 of file face.cpp.

◆ removeAllPendingInterests()

void ndn::Face::removeAllPendingInterests ( )
inherited

Cancel all previously expressed Interests.

Definition at line 182 of file face.cpp.

◆ setInterestFilter() [1/3]

InterestFilterHandle ndn::Face::setInterestFilter ( const InterestFilter filter,
const InterestCallback onInterest 
)
inherited

Set an InterestFilter to dispatch matching incoming Interests to onInterest callback.

Parameters
filterInterest filter
onInterestA callback to be called when a matching interest is received

This method modifies library's FIB only, and does not register the prefix with the forwarder. It will always succeed. To register a prefix with the forwarder, use registerPrefix() or one of the other two setInterestFilter() overloads.

Returns
A handle for unsetting the Interest filter.

Definition at line 234 of file face.cpp.

◆ setInterestFilter() [2/3]

RegisteredPrefixHandle ndn::Face::setInterestFilter ( const InterestFilter filter,
const InterestCallback onInterest,
const RegisterPrefixFailureCallback onFailure,
const security::SigningInfo signingInfo = security::SigningInfo(),
uint64_t  flags = nfd::ROUTE_FLAG_CHILD_INHERIT 
)
inherited

Set InterestFilter to dispatch incoming matching interest to onInterest callback and register the filtered prefix with the connected NDN forwarder.

This version of setInterestFilter combines setInterestFilter and registerPrefix operations and is intended to be used when only one filter for the same prefix needed to be set. When multiple names sharing the same prefix should be dispatched to different callbacks, use one registerPrefix call, followed (in onSuccess callback) by a series of setInterestFilter calls.

Parameters
filterInterest filter (prefix part will be registered with the forwarder)
onInterestA callback to be called when a matching interest is received
onFailureA callback to be called when prefixRegister command fails
signingInfoSigning parameters. When omitted, a default parameters used in the signature will be used.
flagsPrefix registration flags
Returns
A handle for unregistering the prefix and unsetting the Interest filter.

Definition at line 212 of file face.cpp.

◆ setInterestFilter() [3/3]

RegisteredPrefixHandle ndn::Face::setInterestFilter ( const InterestFilter filter,
const InterestCallback onInterest,
const RegisterPrefixSuccessCallback onSuccess,
const RegisterPrefixFailureCallback onFailure,
const security::SigningInfo signingInfo = security::SigningInfo(),
uint64_t  flags = nfd::ROUTE_FLAG_CHILD_INHERIT 
)
inherited

Set InterestFilter to dispatch incoming matching interest to onInterest callback and register the filtered prefix with the connected NDN forwarder.

This version of setInterestFilter combines setInterestFilter and registerPrefix operations and is intended to be used when only one filter for the same prefix needed to be set. When multiple names sharing the same prefix should be dispatched to different callbacks, use one registerPrefix call, followed (in onSuccess callback) by a series of setInterestFilter calls.

Parameters
filterInterest filter (prefix part will be registered with the forwarder)
onInterestA callback to be called when a matching interest is received
onSuccessA callback to be called when prefixRegister command succeeds
onFailureA callback to be called when prefixRegister command fails
signingInfoSigning parameters. When omitted, a default parameters used in the signature will be used.
flagsPrefix registration flags
Returns
A handle for unregistering the prefix and unsetting the Interest filter.

Definition at line 220 of file face.cpp.

◆ shutdown()

void ndn::Face::shutdown ( )
inherited

Shutdown face operations.

This method cancels all pending operations and closes the connection to the NDN forwarder.

Note that this method does not stop the io_service if it is shared between multiple Faces or with other IO objects (e.g., Scheduler).

Warning
Calling this method may cause outgoing packets to be lost. Producers that shut down immediately after sending a Data packet should instead clear all Interest filters to shut down cleanly.
See also
processEvents()

Definition at line 291 of file face.cpp.

◆ unlink()

void ndn::util::DummyClientFace::unlink ( )

Unlink the broadcast media if previously linked.

Definition at line 299 of file dummy-client-face.cpp.

Member Data Documentation

◆ onSendData

Signal<DummyClientFace, Data> ndn::util::DummyClientFace::onSendData

Emits whenever a Data packet is sent.

After .put, .processEvents must be called before this signal would be emitted.

Definition at line 185 of file dummy-client-face.hpp.

◆ onSendInterest

Signal<DummyClientFace, Interest> ndn::util::DummyClientFace::onSendInterest

Emits whenever an Interest is sent.

After .expressInterest, .processEvents must be called before this signal would be emitted.

Definition at line 179 of file dummy-client-face.hpp.

◆ onSendNack

Signal<DummyClientFace, lp::Nack> ndn::util::DummyClientFace::onSendNack

Emits whenever a Nack is sent.

After .put, .processEvents must be called before this signal would be emitted.

Definition at line 191 of file dummy-client-face.hpp.

◆ sentData

std::vector<Data> ndn::util::DummyClientFace::sentData

Data sent out of this DummyClientFace.

Sent Data are appended to this container if options.enablePacketLogger is true. User of this class is responsible for cleaning up the container, if necessary. After .put, .processEvents must be called before the Data would show up here.

Definition at line 165 of file dummy-client-face.hpp.

◆ sentInterests

std::vector<Interest> ndn::util::DummyClientFace::sentInterests

Interests sent out of this DummyClientFace.

Sent Interests are appended to this container if options.enablePacketLogger is true. User of this class is responsible for cleaning up the container, if necessary. After .expressInterest, .processEvents must be called before the Interest would show up here.

Definition at line 157 of file dummy-client-face.hpp.

◆ sentNacks

std::vector<lp::Nack> ndn::util::DummyClientFace::sentNacks

Nacks sent out of this DummyClientFace.

Sent Nacks are appended to this container if options.enablePacketLogger is true. User of this class is responsible for cleaning up the container, if necessary. After .put, .processEvents must be called before the NACK would show up here.

Definition at line 173 of file dummy-client-face.hpp.