Skip to content

Instantly share code, notes, and snippets.

@yoursunny
Last active October 11, 2015 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoursunny/22a7d53711b4e9bc198a to your computer and use it in GitHub Desktop.
Save yoursunny/22a7d53711b4e9bc198a to your computer and use it in GitHub Desktop.
NFD Face System design for LinkService http://redmine.named-data.net/issues/2222 and permanent face http://redmine.named-data.net/issues/2491
// TODO: decide which component is responsible for repairing a link failure in permanent face
// TODO: add details on internal structure of GenericLal
// -------- Face, Lal, Link --------
namespace nfd {
namespace face {
typedef uint64_t FaceId;
enum class FaceStatus {
DOWN,
UP
};
class Face
{
public:
Face(Lal& lal, Link& link);
public: // upper interface connected to forwarding
void
sendInterest(const Interest& interest);
void
sendData(const Data& interest);
void
sendNack(const Nack& interest);
Signal<Lal, Interest>& afterReceiveInterest;
Signal<Lal, Data>& afterReceiveData;
Signal<Lal, Nack>& afterReceiveNack;
public: // static properties
FaceId
getId() const; // from Face
FaceUri
getLocalUri() const; // from Link
FaceUri
getRemoteUri() const; // from Link
FacePersistency
getPersistency() const; // (undecided)
LinkType // point-to-point|multi-access
getLinkType() const; // from Link
public: // dynamic properties
FaceState
getState() const; // from Link
Signal<Link, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
FaceCounters
getCounters() const; // network layer packet counters from Lal, link layer packet and byte counters from Link
};
struct LinkPacket
{
Block packet;
NetworkAddress localAddr;
NetworkAddress remoteAddr;
};
class Link
{
public: // upper interface
void
send(const LinkPacket& packet); // increment counter and call .doSend
Signal<Link, LinkPacket> afterReceive;
private: // upper interface to be overridden by subclass
virtual void
doSend(const LinkPacket& packet) = 0;
protected: // upper interface to be invoked by subclass
void
receive(const LinkPacket& packet); // increment counter and signal afterReceive
public: // static properties
FaceUri
getLocalUri() const;
FaceUri
getRemoteUri() const;
LinkType
getLinkType() const;
public: // dynamic properties
FaceState
getState() const;
Signal<Link, FaceState/*old*/, FaceState/*new*/> afterStateChange;
LinkCounters
getCounters() const; // link layer packet and byte counters
protected:
void
changeState(FaceState newState);
};
class Lal
{
public:
void
setLink(Link& link);
public: // upper interface connected to forwarding
void
sendInterest(const Interest& interest); // increment counter and call .doSendInterest
void
sendData(const Data& interest);
void
sendNack(const Nack& interest);
Signal<Lal, Interest> afterReceiveInterest;
Signal<Lal, Data> afterReceiveData;
Signal<Lal, Nack> afterReceiveNack;
private: // upper interface to be overridden in subclass
virtual void
doSendInterest(const Interest& interest) = 0;
virtual void
doSendData(const Data& interest) = 0;
virtual void
doSendNack(const Nack& interest) = 0;
protected: // upper interface to be invoked in subclass
void
receiveInterest(const Interest& interest); // increment counter and signal afterReceiveInterest
void
receiveData(const Data& data);
void
receiveNack(const Nack& nack);
protected: // lower interface
bool
sendLinkPacket(const LinkPacket& packet);
private: // lower interface
virtual void
receiveLinkPacket(const LinkPacket& packet) = 0;
public: // dynamic properties
NetCounters
getCounters(); // network layer packet counters
};
} // namespace face
} // namespace nfd
// -------- generic LAL --------
namespace nfd {
namespace face {
namespace generic_lal {
class Options
{
bool enableFragmentation;
bool enableReassembly;
// send path and receive path should have separate options if it makes sense
time::nanoseconds reassemblyTimeout;
// (omitted)
};
class GenericLal : public face::Lal
{
public:
GenericLal(Options options);
const Options&
getOptions() const;
void
setOptions(const Options& options);
private: // send path entrypoint
virtual void
doSendInterest(const Interest& interest) override;
virtual void
doSendData(const Data& interest) override;
virtual void
doSendNack(const Nack& interest) override;
private: // receive path entrypoint
virtual void
receiveLinkPacket(const LinkPacket& packet) override;
};
} // namespace generic_lal
} // namespace face
} // namespace nfd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment