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> 73 encoder.appendByteArray(payload.
wire(), payload.
size());
75 this->
send(encoder.block());
78 boost::asio::io_service&
90 std::vector<DummyClientFace*>
faces;
94 :
Error(
"Face has already been linked to another face")
103 this->construct(options);
109 , m_keyChain(keyChain)
111 this->construct(options);
118 , m_keyChain(*m_internalKeyChain)
120 this->construct(options);
126 , m_keyChain(keyChain)
128 this->construct(options);
137 DummyClientFace::construct(
const Options& options)
139 static_pointer_cast<
Transport>(getTransport())->onSendBlock.
connect([
this] (
const Block& blockFromDaemon) {
140 Block packet(blockFromDaemon);
142 lp::Packet lpPacket(packet);
144 Buffer::const_iterator begin, end;
145 std::tie(begin, end) = lpPacket.get<lp::FragmentField>();
146 Block block(&*begin, std::distance(begin, end));
148 if (block.type() == tlv::Interest) {
149 shared_ptr<Interest> interest = make_shared<Interest>(block);
150 if (lpPacket.has<lp::NackField>()) {
151 shared_ptr<lp::Nack> nack = make_shared<lp::Nack>(std::move(*interest));
152 nack->setHeader(lpPacket.get<lp::NackField>());
153 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(*nack, lpPacket);
157 addTagFromField<lp::NextHopFaceIdTag, lp::NextHopFaceIdField>(*interest, lpPacket);
158 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(*interest, lpPacket);
159 onSendInterest(*interest);
163 shared_ptr<Data> data = make_shared<Data>(block);
164 addTagFromField<lp::CachePolicyTag, lp::CachePolicyField>(*data, lpPacket);
165 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(*data, lpPacket);
170 if (options.enablePacketLogging)
171 this->enablePacketLogging();
173 if (options.enableRegistrationReply)
174 this->enableRegistrationReply();
176 m_processEventsOverride = options.processEventsOverride;
178 enableBroadcastLink();
182 DummyClientFace::enableBroadcastLink()
184 this->onSendInterest.connect([
this] (
const Interest& interest) {
185 if (m_bcastLink !=
nullptr) {
186 for (
auto otherFace : m_bcastLink->faces) {
187 if (otherFace != this) {
188 otherFace->receive(interest);
193 this->onSendData.connect([
this] (
const Data& data) {
194 if (m_bcastLink !=
nullptr) {
195 for (
auto otherFace : m_bcastLink->faces) {
196 if (otherFace != this) {
197 otherFace->receive(data);
202 this->onSendNack.connect([
this] (
const lp::Nack& nack) {
203 if (m_bcastLink !=
nullptr) {
204 for (
auto otherFace : m_bcastLink->faces) {
205 if (otherFace != this) {
206 otherFace->receive(nack);
214 DummyClientFace::enablePacketLogging()
216 onSendInterest.connect([
this] (
const Interest& interest) {
217 this->sentInterests.push_back(interest);
219 onSendData.connect([
this] (
const Data& data) {
220 this->sentData.push_back(data);
222 onSendNack.connect([
this] (
const lp::Nack& nack) {
223 this->sentNacks.push_back(nack);
228 DummyClientFace::enableRegistrationReply()
230 onSendInterest.connect([
this] (
const Interest& interest) {
231 static const Name localhostRegistration(
"/localhost/nfd/rib");
232 if (!localhostRegistration.isPrefixOf(interest.getName()))
244 resp.
setBody(params.wireEncode());
246 shared_ptr<Data> data = make_shared<Data>(interest.getName());
249 m_keyChain.sign(*data, security::SigningInfo(security::SigningInfo::SIGNER_TYPE_SHA256));
251 this->getIoService().post([
this, data] { this->receive(*data); });
260 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, interest);
261 addFieldFromTag<lp::NextHopFaceIdField, lp::NextHopFaceIdTag>(lpPacket, interest);
262 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, interest);
264 static_pointer_cast<
Transport>(getTransport())->receive(lpPacket.wireEncode());
268 DummyClientFace::receive(
const Data& data)
272 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, data);
273 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, data);
275 static_pointer_cast<
Transport>(getTransport())->receive(lpPacket.wireEncode());
286 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, nack);
287 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, nack);
289 static_pointer_cast<
Transport>(getTransport())->receive(lpPacket.wireEncode());
295 if (m_bcastLink !=
nullptr && other.
m_bcastLink !=
nullptr) {
301 else if (m_bcastLink ==
nullptr && other.
m_bcastLink !=
nullptr) {
303 m_bcastLink->faces.push_back(
this);
305 else if (m_bcastLink !=
nullptr && other.
m_bcastLink ==
nullptr) {
307 m_bcastLink->faces.push_back(&other);
310 m_bcastLink = other.
m_bcastLink = make_shared<BroadcastLink>();
311 m_bcastLink->faces.push_back(
this);
312 m_bcastLink->faces.push_back(&other);
317 DummyClientFace::unlink()
319 if (m_bcastLink ==
nullptr) {
323 auto it = std::find(m_bcastLink->faces.begin(), m_bcastLink->faces.end(),
this);
324 BOOST_ASSERT(it != m_bcastLink->faces.end());
325 m_bcastLink->faces.erase(it);
327 if (m_bcastLink->faces.size() == 1) {
328 m_bcastLink->faces[0]->m_bcastLink =
nullptr;
329 m_bcastLink->faces.clear();
331 m_bcastLink =
nullptr;
335 DummyClientFace::doProcessEvents(time::milliseconds timeout,
bool keepThread)
337 if (m_processEventsOverride !=
nullptr) {
338 m_processEventsOverride(timeout);
341 this->Face::doProcessEvents(timeout, keepThread);
ControlParameters & setFaceId(uint64_t faceId)
Copyright (c) 2011-2015 Regents of the University of California.
The interface of signing key management.
represents parameters in a ControlCommand request or response
void resume() override
resume the transport
Packet & add(const typename FIELD::ValueType &value)
add a FIELD with value
std::vector< DummyClientFace * > faces
const uint8_t * wire() const
Get pointer to encoded wire.
Represents a TLV element of NDN packet format.
Represents an Interest packet.
const Block & wireEncode() const
const NackHeader & getHeader() const
ReceiveCallback m_receiveCallback
provides a lightweight signal / event system
boost::asio::io_service & getIoService()
represents a Network Nack
options for DummyClientFace
void pause() override
pause the transport
size_t size() const
Get size of encoded wire, including Type-Length-Value.
DummyClientFace(const Options &options=Options())
Create a dummy face with internal IO service.
Provide a communication channel with local or remote NDN forwarder.
Signal< DummyClientFace, Data > onSendData
emits whenever a Data packet is sent
void unlink()
unlink the broadcast media if previously linked
virtual void connect(const ReceiveCallback &receiveCallback)
asynchronously open the connection
shared_ptr< BroadcastLink > m_bcastLink
provides TLV-block delivery service
size_t appendByteArray(const uint8_t *array, size_t length)
Append a byte array array of length length.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Prepend wire encoding to encoder in NDN Packet Format v0.2.
a client-side face for unit testing
ControlParameters & setCost(uint64_t cost)
Represents a name component.
ControlResponse & setBody(const Block &body)
void send(const Block &wire) override
send a TLV block through the transport
void encode()
Encode sub elements into TLV-VALUE.
size_t wireEncode(EncodingImpl< TAG > &encoder, bool wantUnsignedPortionOnly=false) const
Prepend wire encoding to encoder in NDN Packet Format v0.2.
ControlParameters & setOrigin(RouteOrigin origin)
void close() override
Close the connection.
Represents a Data packet.
void send(const Block &header, const Block &payload) override
send two memory blocks through the transport
std::unique_ptr< KeyChain > m_internalKeyChain
ControlResponse & setCode(uint32_t code)
EncodingImpl< EncoderTag > EncodingBuffer
Signal< Transport, Block > onSendBlock
const Interest & getInterest() const
void receive(Block block) const