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&
90 , m_keyChain(*m_internalKeyChain)
92 this->construct(options);
98 , m_keyChain(keyChain)
100 this->construct(options);
107 , m_keyChain(*m_internalKeyChain)
109 this->construct(options);
115 , m_keyChain(keyChain)
117 this->construct(options);
121 DummyClientFace::construct(
const Options& options)
123 static_pointer_cast<
Transport>(getTransport())->onSendBlock.
connect([
this] (
const Block& blockFromDaemon) {
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>()));
140 if (lpPacket.has<lp::CongestionMarkField>()) {
141 nack->setTag(make_shared<lp::CongestionMarkTag>(lpPacket.get<lp::CongestionMarkField>()));
146 if (lpPacket.has<lp::NextHopFaceIdField>()) {
147 interest->setTag(make_shared<lp::NextHopFaceIdTag>(lpPacket.get<lp::NextHopFaceIdField>()));
149 if (lpPacket.has<lp::CongestionMarkField>()) {
150 interest->setTag(make_shared<lp::CongestionMarkTag>(lpPacket.get<lp::CongestionMarkField>()));
152 onSendInterest(*interest);
156 shared_ptr<Data> data = make_shared<Data>(block);
170 this->enablePacketLogging();
173 this->enableRegistrationReply();
179 DummyClientFace::enablePacketLogging()
193 DummyClientFace::enableRegistrationReply()
196 static const Name localhostRegistration(
"/localhost/nfd/rib");
209 resp.
setBody(params.wireEncode());
211 shared_ptr<Data> data = make_shared<Data>(interest.
getName());
220 template<
typename Packet,
typename Field,
typename Tag>
224 shared_ptr<Tag> tag =
static_cast<const TagHost&
>(packet).getTag<Tag>();
225 if (tag !=
nullptr) {
226 lpPacket.
add<Field>(*tag);
230 template<
typename Packet>
236 addFieldFromTag<Packet, lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, packet);
237 addFieldFromTag<Packet, lp::NextHopFaceIdField, lp::NextHopFaceIdTag>(lpPacket, packet);
238 addFieldFromTag<Packet, lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, packet);
240 static_pointer_cast<
Transport>(getTransport())->
receive(lpPacket.wireEncode());
244 DummyClientFace::receive<Interest>(
const Interest& packet);
247 DummyClientFace::receive<Data>(
const Data& packet);
251 DummyClientFace::receive<lp::Nack>(
const lp::Nack& nack)
255 Block interest = nack.getInterest().wireEncode();
258 addFieldFromTag<lp::Nack, lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, nack);
259 addFieldFromTag<lp::Nack, lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, nack);
261 static_pointer_cast<
Transport>(getTransport())->
receive(lpPacket.wireEncode());
265 DummyClientFace::doProcessEvents(
const time::milliseconds& timeout,
bool keepThread)
267 if (m_processEventsOverride !=
nullptr) {
268 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.
Copyright (c) 2011-2015 Regents of the University of California.
static void addFieldFromTag(lp::Packet &lpPacket, const Packet &packet)
Signal< DummyClientFace, Interest > onSendInterest
emits whenever an Interest is sent
represents parameters in a ControlCommand request or response
virtual void pause() override
pause the transport
const Component & get(ssize_t i) const
Get the component at the given index.
Base class to store tag information (e.g., inside Interest and Data packets)
std::vector< Interest > sentInterests
Interests sent out of this DummyClientFace.
Packet & add(const typename FIELD::ValueType &value)
add a FIELD with value
The packet signing interface.
const uint8_t * wire() const
Class representing a wire element of NDN-TLV packet format.
represents an Interest packet
const Block & wireEncode() const
use sha256 digest, no signer needs to be specified
std::vector< Data > sentData
Data sent out of this DummyClientFace.
void sign(Data &data, const SigningInfo ¶ms=DEFAULT_SIGNING_INFO)
Sign data according to the supplied signing information.
ReceiveCallback m_receiveCallback
provides a lightweight signal / event system
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
Signing parameters passed to KeyChain.
boost::asio::io_service & getIoService()
represents a Network Nack
options for DummyClientFace
virtual void close() override
Close the connection.
EncodingImpl< EncoderTag > EncodingBuffer
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.
boost::asio::io_service * m_ioService
Signal< DummyClientFace, Data > onSendData
emits whenever a Data packet is sent
Name abstraction to represent an absolute name.
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
provides TLV-block delivery service
boost::asio::io_service & getIoService()
Return nullptr (cannot use IoService in simulations), preserved for API compatibility.
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)
void encode()
Encode subblocks into wire buffer.
Block blockFromValue() const
ControlParameters & setOrigin(uint64_t origin)
void receive(const Packet &packet)
cause the Face to receive a packet
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
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
const Name & getName() const
void receive(Block block) const