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);
108 , m_keyChain(keyChain)
110 this->construct(options);
115 , m_internalKeyChain(make_unique<
KeyChain>())
116 , m_keyChain(*m_internalKeyChain)
118 this->construct(options);
123 , m_keyChain(keyChain)
125 this->construct(options);
134 DummyClientFace::construct(
const Options& options)
136 static_pointer_cast<Transport>(getTransport())->onSendBlock.connect([
this] (
const Block& blockFromDaemon) {
137 Block packet(blockFromDaemon);
141 Buffer::const_iterator begin, end;
143 Block block(&*begin, std::distance(begin, end));
146 shared_ptr<Interest> interest = make_shared<Interest>(block);
148 shared_ptr<lp::Nack> nack = make_shared<lp::Nack>(std::move(*interest));
150 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(*nack, lpPacket);
154 addTagFromField<lp::NextHopFaceIdTag, lp::NextHopFaceIdField>(*interest, lpPacket);
155 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(*interest, lpPacket);
160 shared_ptr<Data> data = make_shared<Data>(block);
161 addTagFromField<lp::CachePolicyTag, lp::CachePolicyField>(*data, lpPacket);
162 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(*data, lpPacket);
167 if (options.enablePacketLogging)
168 this->enablePacketLogging();
170 if (options.enableRegistrationReply)
171 this->enableRegistrationReply();
175 enableBroadcastLink();
179 DummyClientFace::enableBroadcastLink()
184 if (otherFace != this) {
185 otherFace->receive(interest);
190 this->onSendData.connect([
this] (
const Data& data) {
191 if (m_bcastLink !=
nullptr) {
192 for (
auto otherFace : m_bcastLink->faces) {
193 if (otherFace != this) {
194 otherFace->receive(data);
199 this->onSendNack.connect([
this] (
const lp::Nack& nack) {
200 if (m_bcastLink !=
nullptr) {
201 for (
auto otherFace : m_bcastLink->faces) {
202 if (otherFace != this) {
203 otherFace->receive(nack);
211 DummyClientFace::enablePacketLogging()
213 onSendInterest.connect([
this] (
const Interest& interest) {
214 this->sentInterests.push_back(interest);
216 onSendData.connect([
this] (
const Data& data) {
217 this->sentData.push_back(data);
219 onSendNack.connect([
this] (
const lp::Nack& nack) {
220 this->sentNacks.push_back(nack);
225 DummyClientFace::enableRegistrationReply()
227 onSendInterest.connect([
this] (
const Interest& interest) {
228 static const Name localhostRegistration(
"/localhost/nfd/rib");
229 if (!localhostRegistration.isPrefixOf(interest.getName()))
241 resp.
setBody(params.wireEncode());
243 shared_ptr<Data> data = make_shared<Data>(interest.getName());
246 m_keyChain.sign(*data, security::SigningInfo(security::SigningInfo::SIGNER_TYPE_SHA256));
248 this->getIoService().post([
this, data] { this->receive(*data); });
257 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, interest);
258 addFieldFromTag<lp::NextHopFaceIdField, lp::NextHopFaceIdTag>(lpPacket, interest);
259 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, interest);
261 static_pointer_cast<Transport>(getTransport())->receive(lpPacket.wireEncode());
265 DummyClientFace::receive(
const Data& data)
269 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, data);
270 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, data);
272 static_pointer_cast<Transport>(getTransport())->receive(lpPacket.wireEncode());
283 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, nack);
284 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, nack);
286 static_pointer_cast<Transport>(getTransport())->receive(lpPacket.
wireEncode());
292 if (m_bcastLink !=
nullptr && other.
m_bcastLink !=
nullptr) {
298 else if (m_bcastLink ==
nullptr && other.
m_bcastLink !=
nullptr) {
300 m_bcastLink->faces.push_back(
this);
302 else if (m_bcastLink !=
nullptr && other.
m_bcastLink ==
nullptr) {
304 m_bcastLink->faces.push_back(&other);
307 m_bcastLink = other.
m_bcastLink = make_shared<BroadcastLink>();
308 m_bcastLink->faces.push_back(
this);
309 m_bcastLink->faces.push_back(&other);
314 DummyClientFace::unlink()
316 if (m_bcastLink ==
nullptr) {
320 auto it = std::find(m_bcastLink->faces.begin(), m_bcastLink->faces.end(),
this);
321 BOOST_ASSERT(it != m_bcastLink->faces.end());
322 m_bcastLink->faces.erase(it);
324 if (m_bcastLink->faces.size() == 1) {
325 m_bcastLink->faces[0]->m_bcastLink =
nullptr;
326 m_bcastLink->faces.clear();
328 m_bcastLink =
nullptr;
332 DummyClientFace::doProcessEvents(time::milliseconds timeout,
bool keepThread)
334 if (m_processEventsOverride !=
nullptr) {
335 m_processEventsOverride(timeout);
338 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.
Signal< DummyClientFace, Interest > onSendInterest
emits whenever an Interest is sent
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
Nack & setHeader(const NackHeader &header)
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
std::function< void(time::milliseconds)> m_processEventsOverride
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.
Signal< DummyClientFace, lp::Nack > onSendNack
emits whenever a Nack is sent
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
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.
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.
Block wireEncode() const
encode packet into wire format
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