blob: 68622246fad12d6c628ed485480da8070b5a3cbc [file] [log] [blame]
akmhoque298385a2014-02-13 14:13:09 -06001#ifndef NLSR_LSDB_HPP
2#define NLSR_LSDB_HPP
3
4#include <utility>
5#include "nlsr_lsa.hpp"
6
akmhoque1fd8c1e2014-02-19 19:41:49 -06007namespace nlsr
8{
akmhoqueb1710aa2014-02-19 17:13:36 -06009
akmhoque1fd8c1e2014-02-19 19:41:49 -060010 using namespace std;
akmhoque298385a2014-02-13 14:13:09 -060011
akmhoque1fd8c1e2014-02-19 19:41:49 -060012 class Nlsr;
akmhoque298385a2014-02-13 14:13:09 -060013
akmhoque1fd8c1e2014-02-19 19:41:49 -060014 class Lsdb
15 {
16 public:
17 Lsdb()
18 : lsaRefreshTime(0)
19 {
20 }
akmhoque298385a2014-02-13 14:13:09 -060021
akmhoque298385a2014-02-13 14:13:09 -060022
akmhoque1fd8c1e2014-02-19 19:41:49 -060023 bool doesLsaExist(string key, int lsType);
24 // function related to Name LSDB
25 bool buildAndInstallOwnNameLsa(Nlsr& pnlsr);
26 std::pair<NameLsa&, bool> getNameLsa(string key);
27 bool installNameLsa(Nlsr& pnlsr, NameLsa &nlsa);
28 bool removeNameLsa(Nlsr& pnlsr, string& key);
akmhoque2bb198e2014-02-28 11:46:27 -060029 bool isNameLsaNew(string key, uint64_t seqNo);
akmhoque1fd8c1e2014-02-19 19:41:49 -060030 void printNameLsdb(); //debugging
akmhoque298385a2014-02-13 14:13:09 -060031
akmhoque1fd8c1e2014-02-19 19:41:49 -060032 //function related to Cor LSDB
33 bool buildAndInstallOwnCorLsa(Nlsr& pnlsr);
34 std::pair<CorLsa&, bool> getCorLsa(string key);
35 bool installCorLsa(Nlsr& pnlsr, CorLsa &clsa);
36 bool removeCorLsa(Nlsr& pnlsr, string& key);
akmhoque2bb198e2014-02-28 11:46:27 -060037 bool isCorLsaNew(string key, uint64_t seqNo);
akmhoque1fd8c1e2014-02-19 19:41:49 -060038 void printCorLsdb(); //debugging
akmhoque298385a2014-02-13 14:13:09 -060039
akmhoque1fd8c1e2014-02-19 19:41:49 -060040 //function related to Adj LSDB
41 void scheduledAdjLsaBuild(Nlsr& pnlsr);
42 bool buildAndInstallOwnAdjLsa(Nlsr& pnlsr);
43 bool removeAdjLsa(Nlsr& pnlsr, string& key);
akmhoque2bb198e2014-02-28 11:46:27 -060044 bool isAdjLsaNew(string key, uint64_t seqNo);
akmhoque1fd8c1e2014-02-19 19:41:49 -060045 bool installAdjLsa(Nlsr& pnlsr, AdjLsa &alsa);
46 std::pair<AdjLsa& , bool> getAdjLsa(string key);
47 std::list<AdjLsa>& getAdjLsdb();
48 void printAdjLsdb();
akmhoque298385a2014-02-13 14:13:09 -060049
akmhoque1fd8c1e2014-02-19 19:41:49 -060050 //void scheduleRefreshLsdb(Nlsr& pnlsr, int interval);
51 void setLsaRefreshTime(int lrt);
52 void setThisRouterPrefix(string trp);
akmhoque85d88332014-02-17 21:11:21 -060053
akmhoque1fd8c1e2014-02-19 19:41:49 -060054 private:
55 bool addNameLsa(NameLsa &nlsa);
56 bool doesNameLsaExist(string key);
akmhoque298385a2014-02-13 14:13:09 -060057
akmhoque85d88332014-02-17 21:11:21 -060058
akmhoque1fd8c1e2014-02-19 19:41:49 -060059 bool addCorLsa(CorLsa& clsa);
60 bool doesCorLsaExist(string key);
akmhoque298385a2014-02-13 14:13:09 -060061
akmhoque1fd8c1e2014-02-19 19:41:49 -060062 bool addAdjLsa(AdjLsa &alsa);
63 bool doesAdjLsaExist(string key);
akmhoque298385a2014-02-13 14:13:09 -060064
akmhoque1fd8c1e2014-02-19 19:41:49 -060065 ndn::EventId
66 scheduleNameLsaExpiration(Nlsr& pnlsr, string key, int seqNo, int expTime);
67 void exprireOrRefreshNameLsa(Nlsr& pnlsr, string lsaKey, int seqNo);
68 ndn::EventId
69 scheduleAdjLsaExpiration(Nlsr& pnlsr, string key, int seqNo, int expTime);
70 void exprireOrRefreshAdjLsa(Nlsr& pnlsr, string lsaKey, int seqNo);
71 ndn::EventId
72 scheduleCorLsaExpiration(Nlsr& pnlsr, string key, int seqNo, int expTime);
73 void exprireOrRefreshCorLsa(Nlsr& pnlsr, string lsaKey, int seqNo);
74
75
76 private:
77 void cancelScheduleLsaExpiringEvent(Nlsr& pnlsr, EventId eid);
78
79 std::list<NameLsa> nameLsdb;
80 std::list<AdjLsa> adjLsdb;
81 std::list<CorLsa> corLsdb;
82
83 int lsaRefreshTime;
84 string thisRouterPrefix;
85
86 };
akmhoque298385a2014-02-13 14:13:09 -060087
akmhoqueb1710aa2014-02-19 17:13:36 -060088}//namespace nlsr
89
akmhoque298385a2014-02-13 14:13:09 -060090#endif