blob: 70295aac9e25abed630b760447f0e82c7c25b345 [file] [log] [blame]
akmhoqueba094742014-02-28 11:47:21 -06001#include "nlsr.hpp"
2#include "nlsr_slh.hpp"
3#include "security/nlsr_km.hpp"
4#include "utility/nlsr_tokenizer.hpp"
akmhoque05d5fcf2014-04-15 14:58:45 -05005#include "utility/nlsr_logger.hpp"
6
7#define THIS_FILE "nlsr_slh.cpp"
akmhoqueba094742014-02-28 11:47:21 -06008
9
10namespace nlsr
11{
akmhoque5a44dd42014-03-12 18:11:32 -050012 void
akmhoque05d5fcf2014-04-15 14:58:45 -050013 SyncLogicHandler::createSyncSocket(Nlsr& pnlsr )
akmhoque5a44dd42014-03-12 18:11:32 -050014 {
15 cout<<"Creating Sync socket ......"<<endl;
akmhoque05d5fcf2014-04-15 14:58:45 -050016 cout<<"Sync prefix: "<<m_syncPrefix.toUri()<<endl;
17 m_syncSocket=make_shared<SyncSocket>(m_syncPrefix, m_validator, m_syncFace,
akmhoque5a44dd42014-03-12 18:11:32 -050018 bind(&SyncLogicHandler::nsyncUpdateCallBack,this,
19 _1, _2,boost::ref(pnlsr)),
20 bind(&SyncLogicHandler::nsyncRemoveCallBack, this,
21 _1,boost::ref(pnlsr)));
22 }
akmhoqueba094742014-02-28 11:47:21 -060023
akmhoque5a44dd42014-03-12 18:11:32 -050024 void
25 SyncLogicHandler::nsyncUpdateCallBack(const vector<MissingDataInfo> &v,
26 SyncSocket *socket, Nlsr& pnlsr)
27 {
28 cout<<"nsyncUpdateCallBack called ...."<<endl;
29 int n = v.size();
30 for(int i=0; i < n; i++)
akmhoqueba094742014-02-28 11:47:21 -060031 {
akmhoque5a44dd42014-03-12 18:11:32 -050032 std::cout<<"Data Name: "<<v[i].prefix<<" Seq: "<<v[i].high.getSeq()<<endl;
33 processUpdateFromSync(v[i].prefix,v[i].high.getSeq(),pnlsr);
akmhoqueba094742014-02-28 11:47:21 -060034 }
akmhoque5a44dd42014-03-12 18:11:32 -050035 }
akmhoqueba094742014-02-28 11:47:21 -060036
akmhoque5a44dd42014-03-12 18:11:32 -050037 void
38 SyncLogicHandler::nsyncRemoveCallBack(const string& prefix, Nlsr& pnlsr)
39 {
40 cout<<"nsyncRemoveCallBack called ...."<<endl;
41 }
akmhoqueba094742014-02-28 11:47:21 -060042
akmhoque5a44dd42014-03-12 18:11:32 -050043 void
44 SyncLogicHandler::removeRouterFromSyncing(string& routerPrefix)
45 {
46 }
akmhoqueba094742014-02-28 11:47:21 -060047
akmhoque5a44dd42014-03-12 18:11:32 -050048 void
49 SyncLogicHandler::processUpdateFromSync(std::string updateName,
50 uint64_t seqNo, Nlsr& pnlsr)
51 {
52 nlsrTokenizer nt(updateName,"/");
53 string chkString("LSA");
54 if( nt.doesTokenExist(chkString) )
akmhoqueba094742014-02-28 11:47:21 -060055 {
akmhoque5a44dd42014-03-12 18:11:32 -050056 //process LSA Update here
57 string routerName=nt.getTokenString(nt.getTokenPosition(chkString)+1);
58 processRoutingUpdateFromSync(routerName, seqNo, pnlsr);
akmhoqueba094742014-02-28 11:47:21 -060059 }
akmhoque5a44dd42014-03-12 18:11:32 -050060 chkString="keys";
61 if( nt.doesTokenExist(chkString) )
62 {
63 //process keys update here
64 std::string certName=nt.getTokenString(0);
65 processKeysUpdateFromSync(certName,seqNo, pnlsr);
66 }
67 }
akmhoqueba094742014-02-28 11:47:21 -060068
akmhoque5a44dd42014-03-12 18:11:32 -050069 void
70 SyncLogicHandler::processRoutingUpdateFromSync(std::string routerName,
71 uint64_t seqNo, Nlsr& pnlsr)
72 {
73 if( routerName != pnlsr.getConfParameter().getRouterPrefix() )
akmhoqueba094742014-02-28 11:47:21 -060074 {
akmhoque5a44dd42014-03-12 18:11:32 -050075 SequencingManager sm(seqNo);
76 cout<<sm;
77 cout<<"Router Name: "<<routerName<<endl;
78 if ( pnlsr.getLsdb().isNameLsaNew(routerName+"/1",sm.getNameLsaSeq()))
79 {
80 cout<<"Updated Name LSA. Need to fetch it"<<endl;
81 string lsaPrefix=
82 pnlsr.getConfParameter().getChronosyncLsaPrefix() +
83 routerName + "/1/" +
84 boost::lexical_cast<std::string>(sm.getNameLsaSeq());
85 pnlsr.getIm().expressInterest(pnlsr, lsaPrefix, 3,
86 pnlsr.getConfParameter().getInterestResendTime());
87 }
88 if ( pnlsr.getLsdb().isAdjLsaNew(routerName+"/2",sm.getAdjLsaSeq()))
89 {
90 cout<<"Updated Adj LSA. Need to fetch it"<<endl;
91 string lsaPrefix=
92 pnlsr.getConfParameter().getChronosyncLsaPrefix() +
93 routerName + "/2/" +
94 boost::lexical_cast<std::string>(sm.getAdjLsaSeq());
95 pnlsr.getIm().expressInterest(pnlsr, lsaPrefix, 3,
96 pnlsr.getConfParameter().getInterestResendTime());
97 }
98 if ( pnlsr.getLsdb().isCorLsaNew(routerName+"/3",sm.getCorLsaSeq()))
99 {
100 cout<<"Updated Cor LSA. Need to fetch it"<<endl;
101 string lsaPrefix=
102 pnlsr.getConfParameter().getChronosyncLsaPrefix() +
103 routerName + "/3/" +
104 boost::lexical_cast<std::string>(sm.getCorLsaSeq());
105 pnlsr.getIm().expressInterest(pnlsr, lsaPrefix, 3,
106 pnlsr.getConfParameter().getInterestResendTime());
107 }
akmhoqueba094742014-02-28 11:47:21 -0600108 }
akmhoque5a44dd42014-03-12 18:11:32 -0500109 }
akmhoqueba094742014-02-28 11:47:21 -0600110
akmhoque5a44dd42014-03-12 18:11:32 -0500111 void
112 SyncLogicHandler::processKeysUpdateFromSync(std::string certName,
113 uint64_t seqNo, Nlsr& pnlsr)
114 {
115 cout<<"Cert Name: "<<certName<<std::endl;
116 if ( pnlsr.getKeyManager().isNewCertificate(certName,seqNo) )
akmhoqueba094742014-02-28 11:47:21 -0600117 {
akmhoque5a44dd42014-03-12 18:11:32 -0500118 string certNamePrefix=certName + "/" +
119 boost::lexical_cast<string>(seqNo);
120 pnlsr.getIm().expressInterest(pnlsr, certNamePrefix, 3,
121 pnlsr.getConfParameter().getInterestResendTime());
akmhoqueba094742014-02-28 11:47:21 -0600122 }
akmhoque5a44dd42014-03-12 18:11:32 -0500123 }
akmhoqueba094742014-02-28 11:47:21 -0600124
akmhoque5a44dd42014-03-12 18:11:32 -0500125 void
126 SyncLogicHandler::publishRoutingUpdate(SequencingManager& sm,
127 string updatePrefix)
128 {
129 sm.writeSeqNoToFile();
130 publishSyncUpdate(updatePrefix,sm.getCombinedSeqNo());
131 }
akmhoqueba094742014-02-28 11:47:21 -0600132
akmhoque5a44dd42014-03-12 18:11:32 -0500133 void
134 SyncLogicHandler::publishKeyUpdate(KeyManager& km)
135 {
akmhoque5a44dd42014-03-12 18:11:32 -0500136 publishSyncUpdate(km.getProcessCertName().toUri(),km.getCertSeqNo());
137 }
akmhoqueba094742014-02-28 11:47:21 -0600138
akmhoque5a44dd42014-03-12 18:11:32 -0500139 void
140 SyncLogicHandler::publishIdentityUpdate(string identityName)
141 {
142 publishSyncUpdate(identityName,0);
143 }
akmhoqueba094742014-02-28 11:47:21 -0600144
akmhoque5a44dd42014-03-12 18:11:32 -0500145 void
146 SyncLogicHandler::publishSyncUpdate(string updatePrefix, uint64_t seqNo)
147 {
148 cout<<"Publishing Sync Update ......"<<endl;
149 cout<<"Update in prefix: "<<updatePrefix<<endl;
150 cout<<"Seq No: "<<seqNo<<endl;
151 ndn::Name updateName(updatePrefix);
152 string data("NoData");
akmhoque05d5fcf2014-04-15 14:58:45 -0500153 m_syncSocket->publishData(updateName,0,data.c_str(),data.size(),1000,seqNo);
akmhoque5a44dd42014-03-12 18:11:32 -0500154 }
akmhoqueba094742014-02-28 11:47:21 -0600155
156}