1 #ifndef NDNPH_FACE_PACKET_HANDLER_HPP
2 #define NDNPH_FACE_PACKET_HANDLER_HPP
4 #include "../port/clock/port.hpp"
25 if (m_face !=
nullptr) {
48 template<
typename Packet>
50 return m_face !=
nullptr && m_face->
send(region, packet, pi);
86 template<
typename Packet,
typename... PacketInfoModifier>
87 bool send(
Region& region,
const Packet& packet,
const PacketInfoModifier&... pim) {
103 template<
typename Packet,
typename... Arg,
104 typename =
typename std::enable_if<
105 !std::is_base_of<Region, typename std::decay<Packet>::type>::value>::type>
106 bool send(
const Packet& packet, Arg&&... arg) {
107 return send(regionOf(packet), packet, std::forward<Arg>(arg)...);
118 template<
typename... Arg>
121 return pi !=
nullptr &&
send(std::forward<Arg>(arg)..., *pi);
140 template<
typename Packet,
typename... Arg>
141 bool send(
const Packet& interest,
int timeout, Arg&&... arg) {
146 }
while (m_pitToken == 0);
151 template<
typename Packet>
152 bool send(
const Packet& interest) {
153 return send(interest, interest.getLifetime());
156 template<
typename Packet,
typename ArgFirst,
typename... Arg,
157 typename =
typename std::enable_if<!std::is_integral<ArgFirst>::value>::type>
158 bool send(
const Packet& interest, ArgFirst&& arg1, Arg&&... arg) {
159 return send(interest, interest.getLifetime(), std::forward<ArgFirst>(arg1),
160 std::forward<Arg>(arg)...);
173 return pi !=
nullptr && pi->
pitToken.
to4() == m_pitToken;
193 bool match(
const Data& data,
const Name& name,
bool canBePrefix =
true)
const {
197 interest.setName(name);
198 interest.setCanBePrefix(canBePrefix);
199 return match(data, interest);
214 uint32_t m_pitToken = 0;
249 template<
typename Packet,
typename PimFirst,
typename... PimRest>
251 const PimRest&... pimRest) {
253 return send(region, packet, pi, pimRest...);
257 Face* m_face =
nullptr;
265 #define NDNPH_FACE_PACKET_HANDLER_HPP_END
266 #include "face-impl.inc"
static bool generate(uint8_t *output, size_t count)
Data packet.
Definition: data.hpp:136
bool canSatisfy(const InterestT &interest, CanSatisfyOptions opts=CanSatisfyNone) const
Determine whether Data can satisfy Interest.
Definition: data.hpp:309
Network layer face.
Definition: face.hpp:12
const PacketInfo * getCurrentPacketInfo() const
Definition: face.hpp:84
bool removeHandler(PacketHandler &h)
Remove a packet handler.
bool addHandler(PacketHandler &h, int8_t prio=0)
Add a packet handler.
bool send(Region ®ion, const Packet &packet, PacketInfo pi)
Synchronously transmit a packet.
Interest packet.
Definition: interest.hpp:284
Nack packet.
Definition: nack.hpp:73
Name.
Definition: name.hpp:14
Helper to keep track an outgoing pending Interest.
Definition: packet-handler.hpp:125
bool expired() const
Determine if the pending Interest has expired / timed out.
Definition: packet-handler.hpp:208
bool match(const Data &data, const Name &name, bool canBePrefix=true) const
Check Interest-Data match.
Definition: packet-handler.hpp:193
bool match(const Data &data, const Interest &interest) const
Check Interest-Data match.
Definition: packet-handler.hpp:182
void expireNow()
Set expire time to now.
Definition: packet-handler.hpp:203
bool send(const Packet &interest, ArgFirst &&arg1, Arg &&... arg)
Definition: packet-handler.hpp:158
OutgoingPendingInterest(PacketHandler *ph)
Definition: packet-handler.hpp:127
bool matchPitToken() const
Compare PIT token of current incoming packet against last outgoing Interest.
Definition: packet-handler.hpp:171
bool send(const Packet &interest, int timeout, Arg &&... arg)
Send an Interest.
Definition: packet-handler.hpp:141
bool send(const Packet &interest)
Definition: packet-handler.hpp:152
Set EndpointId of PacketInfo.
Definition: packet-handler.hpp:54
WithEndpointId(uint64_t endpointId)
Definition: packet-handler.hpp:56
uint64_t endpointId
Definition: packet-handler.hpp:64
void operator()(PacketInfo &pi) const
Definition: packet-handler.hpp:59
Set PIT token of PacketInfo.
Definition: packet-handler.hpp:68
WithPitToken(const lp::PitToken &pitToken)
Definition: packet-handler.hpp:70
lp::PitToken pitToken
Definition: packet-handler.hpp:78
void operator()(PacketInfo &pi) const
Definition: packet-handler.hpp:73
Base class to receive packets from Face.
Definition: packet-handler.hpp:10
virtual bool processNack(Nack)
Override to receive Nack packets.
Definition: packet-handler.hpp:245
PacketHandler(Face &face, int8_t prio=0)
Construct and add handler to Face.
Definition: packet-handler.hpp:18
virtual bool processData(Data)
Override to receive Data packets.
Definition: packet-handler.hpp:236
bool send(const Packet &packet, Arg &&... arg)
Synchronously transmit a packet.
Definition: packet-handler.hpp:106
bool send(Region ®ion, const Packet &packet, PacketInfo pi={})
Synchronously transmit a packet.
Definition: packet-handler.hpp:49
Face::PacketInfo PacketInfo
Definition: packet-handler.hpp:12
Face * getFace() const
Definition: packet-handler.hpp:30
const PacketInfo * getCurrentPacketInfo() const
Retrieve information about current processing packet.
Definition: packet-handler.hpp:38
bool send(Region ®ion, const Packet &packet, const PacketInfoModifier &... pim)
Synchronously transmit a packet.
Definition: packet-handler.hpp:87
virtual bool processInterest(Interest)
Override to receive Interest packets.
Definition: packet-handler.hpp:227
virtual void loop()
Override to be invoked periodically.
Definition: packet-handler.hpp:220
virtual ~PacketHandler()
Remove handler from Face.
Definition: packet-handler.hpp:24
bool reply(Arg &&... arg)
Synchronously transmit a packet in reply to current processing packet.
Definition: packet-handler.hpp:119
PacketHandler()=default
Construct without adding to Face.
Region-based memory allocator thats owns memory of NDNph objects.
Definition: region.hpp:9
RefType create(Arg &&... arg)
Allocate and create an object, and return its reference.
Definition: region.hpp:90
Region with statically allocated memory.
Definition: region.hpp:143
PIT token field.
Definition: lp.hpp:35
static PitToken from4(uint32_t n)
Construct 4-octet PIT token from uint32.
Definition: lp.hpp:38
uint32_t to4() const
Interpret 4-octet PIT token as uint32.
Definition: lp.hpp:60
static bool isBefore(Time a, Time b)
Definition: ino.hpp:42
static Time now()
Definition: ino.hpp:21
static Time add(Time t, int ms)
Definition: ino.hpp:27
#define NDNPH_ASSERT(x)
Definition: common.hpp:30
lp::PitToken pitToken
Definition: face.hpp:16
uint64_t endpointId
Definition: face.hpp:15