blob: 51ec319ddd5268e18e45a273517a1ab2516755b4 [file] [log] [blame]
akmhoque53353462014-04-22 08:43:45 -05001#include "nlsr.hpp"
2#include "sync-logic-handler.hpp"
Yingdi Yu0c217822014-04-24 14:22:42 -07003// #include "security/key-manager.hpp"
akmhoque53353462014-04-22 08:43:45 -05004#include "utility/tokenizer.hpp"
5
6
7namespace nlsr {
8
9void
10SyncLogicHandler::createSyncSocket(Nlsr& pnlsr)
11{
12 std::cout << "Creating Sync socket ......" << std::endl;
13 std::cout << "Sync prefix: " << m_syncPrefix.toUri() << std::endl;
14 m_syncSocket = make_shared<Sync::SyncSocket>(m_syncPrefix, m_validator,
15 m_syncFace,
16 bind(&SyncLogicHandler::nsyncUpdateCallBack, this,
17 _1, _2, boost::ref(pnlsr)),
18 bind(&SyncLogicHandler::nsyncRemoveCallBack, this,
19 _1, boost::ref(pnlsr)));
20}
21
22void
23SyncLogicHandler::nsyncUpdateCallBack(const vector<Sync::MissingDataInfo>& v,
24 Sync::SyncSocket* socket, Nlsr& pnlsr)
25{
26 std::cout << "nsyncUpdateCallBack called ...." << std::endl;
27 int n = v.size();
28 for (int i = 0; i < n; i++)
29 {
30 std::cout << "Data Name: " << v[i].prefix << " Seq: " << v[i].high.getSeq() <<
31 endl;
32 processUpdateFromSync(v[i].prefix, v[i].high.getSeq(), pnlsr);
33 }
34}
35
36void
37SyncLogicHandler::nsyncRemoveCallBack(const string& prefix, Nlsr& pnlsr)
38{
39 std::cout << "nsyncRemoveCallBack called ...." << std::endl;
40}
41
42void
43SyncLogicHandler::removeRouterFromSyncing(string& routerPrefix)
44{
45}
46
47void
48SyncLogicHandler::processUpdateFromSync(std::string updateName,
49 uint64_t seqNo, Nlsr& pnlsr)
50{
51 Tokenizer nt(updateName, "/");
52 string chkString("LSA");
53 if (nt.doesTokenExist(chkString))
54 {
55 //process LSA Update here
56 string routerName = nt.getTokenString(nt.getTokenPosition(chkString) + 1);
57 processRoutingUpdateFromSync(routerName, seqNo, pnlsr);
58 }
59 chkString = "keys";
60 if (nt.doesTokenExist(chkString))
61 {
62 //process keys update here
63 std::string certName = nt.getTokenString(0);
Yingdi Yu0c217822014-04-24 14:22:42 -070064 // processKeysUpdateFromSync(certName, seqNo, pnlsr);
akmhoque53353462014-04-22 08:43:45 -050065 }
66}
67
68void
69SyncLogicHandler::processRoutingUpdateFromSync(std::string routerName,
70 uint64_t seqNo, Nlsr& pnlsr)
71{
72 if (routerName != pnlsr.getConfParameter().getRouterPrefix())
73 {
74 SequencingManager sm(seqNo);
75 std::cout << sm;
76 std::cout << "Router Name: " << routerName << endl;
77 if (pnlsr.getLsdb().isNameLsaNew(routerName + "/1", sm.getNameLsaSeq()))
78 {
79 std::cout << "Updated Name LSA. Need to fetch it" << std::endl;
80 string lsaPrefix =
81 pnlsr.getConfParameter().getChronosyncLsaPrefix() +
82 routerName + "/1/" +
83 boost::lexical_cast<std::string>(sm.getNameLsaSeq());
akmhoquec8a10f72014-04-25 18:42:55 -050084 pnlsr.getInterestManager().expressInterest(lsaPrefix, 3,
85 pnlsr.getConfParameter().getInterestResendTime());
akmhoque53353462014-04-22 08:43:45 -050086 }
87 if (pnlsr.getLsdb().isAdjLsaNew(routerName + "/2", sm.getAdjLsaSeq()))
88 {
89 std::cout << "Updated Adj LSA. Need to fetch it" << std::endl;
90 string lsaPrefix =
91 pnlsr.getConfParameter().getChronosyncLsaPrefix() +
92 routerName + "/2/" +
93 boost::lexical_cast<std::string>(sm.getAdjLsaSeq());
akmhoquec8a10f72014-04-25 18:42:55 -050094 pnlsr.getInterestManager().expressInterest(lsaPrefix, 3,
95 pnlsr.getConfParameter().getInterestResendTime());
akmhoque53353462014-04-22 08:43:45 -050096 }
akmhoqueb6450b12014-04-24 00:01:03 -050097 if (pnlsr.getLsdb().isCoordinateLsaNew(routerName + "/3", sm.getCorLsaSeq()))
akmhoque53353462014-04-22 08:43:45 -050098 {
99 std::cout << "Updated Cor LSA. Need to fetch it" << std::endl;
100 string lsaPrefix =
101 pnlsr.getConfParameter().getChronosyncLsaPrefix() +
102 routerName + "/3/" +
103 boost::lexical_cast<std::string>(sm.getCorLsaSeq());
akmhoquec8a10f72014-04-25 18:42:55 -0500104 pnlsr.getInterestManager().expressInterest(lsaPrefix, 3,
105 pnlsr.getConfParameter().getInterestResendTime());
akmhoque53353462014-04-22 08:43:45 -0500106 }
107 }
108}
109
Yingdi Yu0c217822014-04-24 14:22:42 -0700110// void
111// SyncLogicHandler::processKeysUpdateFromSync(std::string certName,
112// uint64_t seqNo, Nlsr& pnlsr)
113// {
114// std::cout << "Cert Name: " << certName << std::endl;
115// // if (pnlsr.getKeyManager().isNewCertificate(certName, seqNo))
116// {
117// string certNamePrefix = certName + "/" +
118// boost::lexical_cast<string>(seqNo);
119// pnlsr.getIm().expressInterest(certNamePrefix, 3,
120// pnlsr.getConfParameter().getInterestResendTime());
121// }
122// }
akmhoque53353462014-04-22 08:43:45 -0500123
124void
125SyncLogicHandler::publishRoutingUpdate(SequencingManager& sm,
126 string updatePrefix)
127{
128 sm.writeSeqNoToFile();
129 publishSyncUpdate(updatePrefix, sm.getCombinedSeqNo());
130}
131
Yingdi Yu0c217822014-04-24 14:22:42 -0700132// void
133// SyncLogicHandler::publishKeyUpdate(KeyManager& km)
134// {
135// publishSyncUpdate(km.getProcessCertName().toUri(), km.getCertSeqNo());
136// }
akmhoque53353462014-04-22 08:43:45 -0500137
138void
139SyncLogicHandler::publishIdentityUpdate(string identityName)
140{
141 publishSyncUpdate(identityName, 0);
142}
143
144void
145SyncLogicHandler::publishSyncUpdate(string updatePrefix, uint64_t seqNo)
146{
147 std::cout << "Publishing Sync Update ......" << std::endl;
148 std::cout << "Update in prefix: " << updatePrefix << std::endl;
149 std::cout << "Seq No: " << seqNo << std::endl;
150 ndn::Name updateName(updatePrefix);
151 string data("NoData");
152 m_syncSocket->publishData(updateName, 0, data.c_str(), data.size(), 1000,
153 seqNo);
154}
155
156}//namespace nlsr