23 #include "../detail/lp-field-tag.hpp" 24 #include "../lp/packet.hpp" 25 #include "../lp/tags.hpp" 26 #include "../mgmt/nfd/controller.hpp" 27 #include "../mgmt/nfd/control-response.hpp" 28 #include "../transport/transport.hpp" 30 #include <boost/asio/io_service.hpp> 42 if (m_receiveCallback) {
63 send(
const Block& wire)
override 69 send(
const Block& header,
const Block& payload)
override 71 EncodingBuffer encoder(header.size() + payload.size(), header.size() + payload.size());
73 encoder.appendByteArray(payload.wire(), payload.size());
75 this->send(encoder.block());
78 boost::asio::io_service&
85 Signal<Transport, Block> onSendBlock;
90 , m_internalKeyChain(new KeyChain)
91 , m_keyChain(*m_internalKeyChain)
93 this->construct(options);
99 , m_keyChain(keyChain)
101 this->construct(options);
107 , m_internalKeyChain(new KeyChain)
108 , m_keyChain(*m_internalKeyChain)
110 this->construct(options);
116 , m_keyChain(keyChain)
118 this->construct(options);
122 DummyClientFace::construct(
const Options& options)
124 static_pointer_cast<Transport>(
getTransport())->onSendBlock.connect([
this] (
const Block& blockFromDaemon) {
125 Block packet(blockFromDaemon);
127 lp::Packet lpPacket(packet);
129 Buffer::const_iterator begin, end;
130 std::tie(begin, end) = lpPacket.get<lp::FragmentField>();
131 Block block(&*begin, std::distance(begin, end));
133 if (block.type() == tlv::Interest) {
134 shared_ptr<Interest> interest = make_shared<Interest>(block);
135 if (lpPacket.has<lp::NackField>()) {
136 shared_ptr<lp::Nack> nack = make_shared<lp::Nack>(std::move(*interest));
137 nack->setHeader(lpPacket.get<lp::NackField>());
138 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(*nack, lpPacket);
142 addTagFromField<lp::NextHopFaceIdTag, lp::NextHopFaceIdField>(*interest, lpPacket);
143 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(*interest, lpPacket);
144 onSendInterest(*interest);
148 shared_ptr<Data> data = make_shared<Data>(block);
149 addTagFromField<lp::CachePolicyTag, lp::CachePolicyField>(*data, lpPacket);
150 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(*data, lpPacket);
156 this->enablePacketLogging();
159 this->enableRegistrationReply();
165 DummyClientFace::enablePacketLogging()
179 DummyClientFace::enableRegistrationReply()
182 static const Name localhostRegistration(
"/localhost/nfd/rib");
195 resp.
setBody(params.wireEncode());
197 shared_ptr<Data> data = make_shared<Data>(interest.
getName());
211 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, interest);
212 addFieldFromTag<lp::NextHopFaceIdField, lp::NextHopFaceIdTag>(lpPacket, interest);
213 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, interest);
223 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, data);
224 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, data);
237 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, nack);
238 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, nack);
244 DummyClientFace::doProcessEvents(time::milliseconds timeout,
bool keepThread)
246 if (m_processEventsOverride !=
nullptr) {
247 m_processEventsOverride(timeout);
bool enableRegistrationReply
if true, prefix registration command will be automatically replied with a successful response ...
ControlParameters & setFaceId(uint64_t faceId)
std::vector< lp::Nack > sentNacks
Nacks sent out of this DummyClientFace.
const Name & getName() const
Copyright (c) 2013-2017 Regents of the University of California.
virtual void doProcessEvents(time::milliseconds timeout, bool keepThread)
const NackHeader & getHeader() const
Signal< DummyClientFace, Interest > onSendInterest
emits whenever an Interest is sent
represents parameters in a ControlCommand request or response
std::vector< Interest > sentInterests
Interests sent out of this DummyClientFace.
Packet & add(const typename FIELD::ValueType &value)
add a FIELD with value
const Interest & getInterest() const
Represents a TLV element of NDN packet format.
represents an Interest packet
use sha256 digest, no signer needs to be specified
const Block & wireEncode() const
std::vector< Data > sentData
Data sent out of this DummyClientFace.
ReceiveCallback m_receiveCallback
Signing parameters passed to KeyChain.
represents a Network Nack
options for DummyClientFace
size_t wireEncode(EncodingImpl< TAG > &encoder, bool wantUnsignedPortionOnly=false) const
Fast encoding or block size estimation.
DummyClientFace(const Options &options=Options())
Create a dummy face with internal IO service.
Signal< DummyClientFace, lp::Nack > onSendNack
emits whenever a Nack is sent
Block blockFromValue() const
shared_ptr< Transport > getTransport()
Provide a communication channel with local or remote NDN forwarder.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
boost::asio::io_service * m_ioService
Signal< DummyClientFace, Data > onSendData
emits whenever a Data packet is sent
Represents an absolute name.
void receive(const Interest &interest)
cause the Face to receive an interest
bool isPrefixOf(const Name &other) const
Check if this name is a prefix of another name.
provides TLV-block delivery service
boost::asio::io_service & getIoService()
size_t appendByteArray(const uint8_t *array, size_t length)
Append a byte array array of length length.
a client-side face for unit testing
ControlParameters & setCost(uint64_t cost)
Component holds a read-only name component value.
ControlResponse & setBody(const Block &body)
ControlParameters & setOrigin(RouteOrigin origin)
Represents a Data packet.
const Component & get(ssize_t i) const
Get the component at the given index.
ControlResponse & setCode(uint32_t code)
EncodingImpl< EncoderTag > EncodingBuffer
bool enablePacketLogging
if true, packets sent out of DummyClientFace will be appended to a container
std::function< void(time::milliseconds)> processEventsOverride
if not empty, face.processEvents() will be overridden by this function