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;
88 struct DummyClientFace::BroadcastLink
90 std::vector<DummyClientFace*> faces;
94 :
Error(
"Face has already been linked to another face")
100 , m_internalKeyChain(new KeyChain)
101 , m_keyChain(*m_internalKeyChain)
103 this->construct(options);
109 , m_keyChain(keyChain)
111 this->construct(options);
117 , m_internalKeyChain(new KeyChain)
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);
171 this->enablePacketLogging();
174 this->enableRegistrationReply();
178 enableBroadcastLink();
182 DummyClientFace::enableBroadcastLink()
185 if (m_bcastLink !=
nullptr) {
186 for (
auto otherFace : m_bcastLink->faces) {
187 if (otherFace != this) {
188 otherFace->receive(interest);
194 if (m_bcastLink !=
nullptr) {
195 for (
auto otherFace : m_bcastLink->faces) {
196 if (otherFace != this) {
197 otherFace->receive(data);
203 if (m_bcastLink !=
nullptr) {
204 for (
auto otherFace : m_bcastLink->faces) {
205 if (otherFace != this) {
206 otherFace->receive(nack);
214 DummyClientFace::enablePacketLogging()
228 DummyClientFace::enableRegistrationReply()
231 static const Name localhostRegistration(
"/localhost/nfd/rib");
244 resp.
setBody(params.wireEncode());
246 shared_ptr<Data> data = make_shared<Data>(interest.
getName());
260 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, interest);
261 addFieldFromTag<lp::NextHopFaceIdField, lp::NextHopFaceIdTag>(lpPacket, interest);
262 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, interest);
272 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, data);
273 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, data);
286 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, nack);
287 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, nack);
295 if (m_bcastLink !=
nullptr && other.m_bcastLink !=
nullptr) {
296 if (m_bcastLink != other.m_bcastLink) {
301 else if (m_bcastLink ==
nullptr && other.m_bcastLink !=
nullptr) {
302 m_bcastLink = other.m_bcastLink;
303 m_bcastLink->faces.push_back(
this);
305 else if (m_bcastLink !=
nullptr && other.m_bcastLink ==
nullptr) {
306 other.m_bcastLink = m_bcastLink;
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);
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);
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
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)
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