blob: 24bfec362abb8ca495b56b66b868794b91b9fcd5 [file] [log] [blame]
#ifndef NLSR_LSDB_HPP
#define NLSR_LSDB_HPP
#include <utility>
#include "nlsr_lsa.hpp"
namespace nlsr
{
using namespace std;
class Nlsr;
class Lsdb
{
public:
Lsdb()
: lsaRefreshTime(0)
{
}
bool doesLsaExist(string key, int lsType);
// function related to Name LSDB
bool buildAndInstallOwnNameLsa(Nlsr& pnlsr);
std::pair<NameLsa&, bool> getNameLsa(string key);
bool installNameLsa(Nlsr& pnlsr, NameLsa &nlsa);
bool removeNameLsa(Nlsr& pnlsr, string& key);
bool isNameLsaNew(string key, uint64_t seqNo);
void printNameLsdb(); //debugging
//function related to Cor LSDB
bool buildAndInstallOwnCorLsa(Nlsr& pnlsr);
std::pair<CorLsa&, bool> getCorLsa(string key);
bool installCorLsa(Nlsr& pnlsr, CorLsa &clsa);
bool removeCorLsa(Nlsr& pnlsr, string& key);
bool isCorLsaNew(string key, uint64_t seqNo);
void printCorLsdb(); //debugging
//function related to Adj LSDB
void scheduledAdjLsaBuild(Nlsr& pnlsr);
bool buildAndInstallOwnAdjLsa(Nlsr& pnlsr);
bool removeAdjLsa(Nlsr& pnlsr, string& key);
bool isAdjLsaNew(string key, uint64_t seqNo);
bool installAdjLsa(Nlsr& pnlsr, AdjLsa &alsa);
std::pair<AdjLsa& , bool> getAdjLsa(string key);
std::list<AdjLsa>& getAdjLsdb();
void printAdjLsdb();
//void scheduleRefreshLsdb(Nlsr& pnlsr, int interval);
void setLsaRefreshTime(int lrt);
void setThisRouterPrefix(string trp);
private:
bool addNameLsa(NameLsa &nlsa);
bool doesNameLsaExist(string key);
bool addCorLsa(CorLsa& clsa);
bool doesCorLsaExist(string key);
bool addAdjLsa(AdjLsa &alsa);
bool doesAdjLsaExist(string key);
ndn::EventId
scheduleNameLsaExpiration(Nlsr& pnlsr, string key, int seqNo, int expTime);
void exprireOrRefreshNameLsa(Nlsr& pnlsr, string lsaKey, int seqNo);
ndn::EventId
scheduleAdjLsaExpiration(Nlsr& pnlsr, string key, int seqNo, int expTime);
void exprireOrRefreshAdjLsa(Nlsr& pnlsr, string lsaKey, int seqNo);
ndn::EventId
scheduleCorLsaExpiration(Nlsr& pnlsr, string key, int seqNo, int expTime);
void exprireOrRefreshCorLsa(Nlsr& pnlsr, string lsaKey, int seqNo);
private:
void cancelScheduleLsaExpiringEvent(Nlsr& pnlsr, EventId eid);
std::list<NameLsa> nameLsdb;
std::list<AdjLsa> adjLsdb;
std::list<CorLsa> corLsdb;
int lsaRefreshTime;
string thisRouterPrefix;
};
}//namespace nlsr
#endif