23 #include "ndn-cxx/impl/lp-field-tag.hpp" 30 #include <boost/asio/io_service.hpp> 42 if (m_receiveCallback) {
43 m_receiveCallback(block);
63 send(
const Block& wire)
override 69 send(
const Block& header,
const Block& payload)
override 73 encoder.appendByteArray(payload.
wire(), payload.
size());
75 this->send(encoder.block());
78 boost::asio::io_service&
85 Signal<Transport, Block> onSendBlock;
88 struct DummyClientFace::BroadcastLink
90 std::vector<DummyClientFace*> faces;
94 :
Error(
"Face has already been linked to another face")
100 , m_internalKeyChain(make_unique<KeyChain>())
101 , m_keyChain(*m_internalKeyChain)
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);
139 lp::Packet lpPacket(packet);
141 Buffer::const_iterator begin, end;
142 std::tie(begin, end) = lpPacket.get<lp::FragmentField>();
143 Block block(&*begin, std::distance(begin, end));
145 if (block.type() == tlv::Interest) {
146 shared_ptr<Interest> interest = make_shared<Interest>(block);
147 if (lpPacket.has<lp::NackField>()) {
148 shared_ptr<lp::Nack> nack = make_shared<lp::Nack>(std::move(*interest));
149 nack->setHeader(lpPacket.get<lp::NackField>());
150 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(*nack, lpPacket);
154 addTagFromField<lp::NextHopFaceIdTag, lp::NextHopFaceIdField>(*interest, lpPacket);
155 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(*interest, lpPacket);
156 onSendInterest(*interest);
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);
168 this->enablePacketLogging();
171 this->enableRegistrationReply();
175 enableBroadcastLink();
179 DummyClientFace::enableBroadcastLink()
182 if (m_bcastLink !=
nullptr) {
183 for (
auto otherFace : m_bcastLink->faces) {
184 if (otherFace != this) {
185 otherFace->receive(interest);
191 if (m_bcastLink !=
nullptr) {
192 for (
auto otherFace : m_bcastLink->faces) {
193 if (otherFace != this) {
194 otherFace->receive(data);
200 if (m_bcastLink !=
nullptr) {
201 for (
auto otherFace : m_bcastLink->faces) {
202 if (otherFace != this) {
203 otherFace->receive(nack);
211 DummyClientFace::enablePacketLogging()
225 DummyClientFace::enableRegistrationReply()
228 static const Name localhostRegistration(
"/localhost/nfd/rib");
241 resp.
setBody(params.wireEncode());
243 shared_ptr<Data> data = make_shared<Data>(interest.
getName());
257 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, interest);
258 addFieldFromTag<lp::NextHopFaceIdField, lp::NextHopFaceIdTag>(lpPacket, interest);
259 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, interest);
269 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, data);
270 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, data);
283 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, nack);
284 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, nack);
292 if (m_bcastLink !=
nullptr && other.m_bcastLink !=
nullptr) {
293 if (m_bcastLink != other.m_bcastLink) {
298 else if (m_bcastLink ==
nullptr && other.m_bcastLink !=
nullptr) {
299 m_bcastLink = other.m_bcastLink;
300 m_bcastLink->faces.push_back(
this);
302 else if (m_bcastLink !=
nullptr && other.m_bcastLink ==
nullptr) {
303 other.m_bcastLink = m_bcastLink;
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);
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);
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
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.
Signing parameters passed to KeyChain.
represents a Network Nack
options for DummyClientFace
size_t size() const
Return the size of the encoded wire, i.e.
size_t wireEncode(EncodingImpl< TAG > &encoder, bool wantUnsignedPortionOnly=false) const
Prepend wire encoding to encoder in NDN Packet Format v0.2.
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
Prepend wire encoding to encoder.
Signal< DummyClientFace, Data > onSendData
emits whenever a Data packet is sent
void unlink()
unlink the broadcast media if previously linked
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.
void linkTo(DummyClientFace &other)
link another DummyClientFace through a broadcast media
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)
Represents a name component.
ControlResponse & setBody(const Block &body)
void encode()
Encode sub-elements into TLV-VALUE.
const uint8_t * wire() const
Return a raw pointer to the beginning of the encoded wire.
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