23 #include "../lp/packet.hpp"
24 #include "../lp/tags.hpp"
25 #include "../mgmt/nfd/controller.hpp"
26 #include "../mgmt/nfd/control-response.hpp"
27 #include "../transport/transport.hpp"
29 #include <boost/asio/io_service.hpp>
72 encoder.appendByteArray(payload.
wire(), payload.
size());
74 this->
send(encoder.block());
77 boost::asio::io_service&
89 , m_internalKeyChain(new KeyChain)
90 , m_keyChain(*m_internalKeyChain)
92 this->construct(options);
98 , m_keyChain(keyChain)
100 this->construct(options);
106 , m_internalKeyChain(new KeyChain)
107 , m_keyChain(*m_internalKeyChain)
109 this->construct(options);
115 , m_keyChain(keyChain)
117 this->construct(options);
121 DummyClientFace::construct(
const Options& options)
124 Block packet(blockFromDaemon);
126 lp::Packet lpPacket(packet);
128 Buffer::const_iterator begin, end;
129 std::tie(begin, end) = lpPacket.get<lp::FragmentField>();
130 Block block(&*begin, std::distance(begin, end));
132 if (block.type() == tlv::Interest) {
133 shared_ptr<Interest> interest = make_shared<Interest>(block);
134 if (lpPacket.has<lp::NackField>()) {
135 shared_ptr<lp::Nack> nack = make_shared<lp::Nack>(std::move(*interest));
136 nack->setHeader(lpPacket.get<lp::NackField>());
137 if (lpPacket.has<lp::NextHopFaceIdField>()) {
138 nack->setTag(make_shared<lp::NextHopFaceIdTag>(lpPacket.get<lp::NextHopFaceIdField>()));
143 if (lpPacket.has<lp::NextHopFaceIdField>()) {
144 interest->setTag(make_shared<lp::NextHopFaceIdTag>(lpPacket.get<lp::NextHopFaceIdField>()));
146 onSendInterest(*interest);
150 shared_ptr<Data> data = make_shared<Data>(block);
160 if (options.enablePacketLogging)
161 this->enablePacketLogging();
163 if (options.enableRegistrationReply)
164 this->enableRegistrationReply();
166 m_processEventsOverride = options.processEventsOverride;
170 DummyClientFace::enablePacketLogging()
172 onSendInterest.connect([
this] (
const Interest& interest) {
173 this->sentInterests.push_back(interest);
175 onSendData.connect([
this] (
const Data& data) {
176 this->sentData.push_back(data);
178 onSendNack.connect([
this] (
const lp::Nack& nack) {
179 this->sentNacks.push_back(nack);
184 DummyClientFace::enableRegistrationReply()
186 onSendInterest.connect([
this] (
const Interest& interest) {
187 static const Name localhostRegistration(
"/localhost/nfd/rib");
188 if (!localhostRegistration.isPrefixOf(interest.getName()))
194 if (interest.getName().get(3) == name::Component(
"register")) {
200 resp.
setBody(params.wireEncode());
202 shared_ptr<Data> data = make_shared<Data>(interest.getName());
203 data->setContent(resp.wireEncode());
207 this->getIoService().post([
this, data] { this->receive(*data); });
211 template<
typename Packet>
213 DummyClientFace::receive(
const Packet& packet)
217 shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag =
218 static_cast<const TagHost&
>(packet).getTag<lp::IncomingFaceIdTag>();
219 if (incomingFaceIdTag !=
nullptr) {
223 shared_ptr<lp::NextHopFaceIdTag> nextHopFaceIdTag =
224 static_cast<const TagHost&
>(packet).getTag<lp::NextHopFaceIdTag>();
225 if (nextHopFaceIdTag !=
nullptr) {
228 static_pointer_cast<
Transport>(getTransport())->receive(lpPacket.wireEncode());
232 DummyClientFace::receive<Interest>(
const Interest& packet);
235 DummyClientFace::receive<Data>(
const Data& packet);
239 DummyClientFace::receive<lp::Nack>(
const lp::Nack& nack)
243 Block interest = nack.getInterest().wireEncode();
247 if (incomingFaceIdTag !=
nullptr) {
255 DummyClientFace::doProcessEvents(
const time::milliseconds& timeout,
bool keepThread)
257 if (m_processEventsOverride !=
nullptr) {
258 m_processEventsOverride(timeout);
size_t wireEncode(EncodingImpl< TAG > &encoder) const
append packet to encoder
Copyright (c) 2013-2016 Regents of the University of California.
virtual void pause() override
pause the transport
Base class to store tag information (e.g., inside Interest and Data packets)
Packet & add(const typename FIELD::ValueType &value)
add a FIELD with value
void receive(Block block) const
Class representing a wire element of NDN-TLV packet format.
represents an Interest packet
use sha256 digest, no signer needs to be specified
ReceiveCallback m_receiveCallback
virtual void send(const Block &header, const Block &payload) override
send two memory blocks through the transport
virtual void doProcessEvents(const time::milliseconds &timeout, bool keepThread)
virtual void send(const Block &wire) override
send a TLV block through the transport
boost::asio::io_service & getIoService()
represents a Network Nack
options for DummyClientFace
provides a tag type for simple types
virtual void close() override
Close the connection.
ndn::mgmt::ControlResponse ControlResponse
EncodingImpl< EncoderTag > EncodingBuffer
DummyClientFace(const Options &options=Options())
Create a dummy face with internal IO service.
shared_ptr< Transport > getTransport()
Provide a communication channel with local or remote NDN forwarder.
boost::asio::io_service * m_ioService
Signal< DummyClientFace, Data > onSendData
emits whenever a Data packet is sent
provides TLV-block delivery service
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
ControlResponse & setBody(const Block &body)
void encode()
Encode subblocks into wire buffer.
const uint8_t * wire() const
ControlResponse & setCode(uint32_t code)
virtual void resume() override
resume the transport
Signal< Transport, Block > onSendBlock
virtual void connect(boost::asio::io_service &ioService, const ReceiveCallback &receiveCallback)
asynchronously open the connection