blob: ac291481a886adfbc3f84eb71ff008ef6675099d [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"
5
6
7namespace nlsr
8{
9 void
10 SyncLogicHandler::createSyncSocket(Nlsr &pnlsr )
11 {
12 cout<<"Creating Sync socket ......"<<endl;
13 cout<<"Sync prefix: "<<syncPrefix.toUri()<<endl;
14 syncSocket=make_shared<SyncSocket>(syncPrefix, validator, syncFace,
15 bind(&SyncLogicHandler::nsyncUpdateCallBack,this,
16 _1, _2,boost::ref(pnlsr)),
17 bind(&SyncLogicHandler::nsyncRemoveCallBack, this,
18 _1,boost::ref(pnlsr)));
19 }
20
21 void
22 SyncLogicHandler::nsyncUpdateCallBack(const vector<MissingDataInfo> &v,
23 SyncSocket *socket, Nlsr& pnlsr)
24 {
25 cout<<"nsyncUpdateCallBack called ...."<<endl;
26 int n = v.size();
27 for(int i=0; i < n; i++)
28 {
29 std::cout<<"Data Name: "<<v[i].prefix<<" Seq: "<<v[i].high.getSeq()<<endl;
30 processUpdateFromSync(v[i].prefix,v[i].high.getSeq(),pnlsr);
31 }
32 }
33
34 void
35 SyncLogicHandler::nsyncRemoveCallBack(const string& prefix, Nlsr& pnlsr)
36 {
37 cout<<"nsyncRemoveCallBack called ...."<<endl;
38 }
39
40 void
41 SyncLogicHandler::removeRouterFromSyncing(string& routerPrefix)
42 {
43 }
44
45 void
46 SyncLogicHandler::processUpdateFromSync(std::string updateName,
47 uint64_t seqNo, Nlsr& pnlsr)
48 {
49 nlsrTokenizer nt(updateName,"/");
50 string chkString("LSA");
51 if( nt.doesTokenExist(chkString) )
52 {
53 //process LSA Update here
54 string routerName=nt.getTokenString(nt.getTokenPosition(chkString)+1);
55 processRoutingUpdateFromSync(routerName, seqNo, pnlsr);
56 }
57 chkString="keys";
58 if( nt.doesTokenExist(chkString) )
59 {
60 //process keys update here
61 processKeysUpdateFromSync(updateName,seqNo, pnlsr);
62 }
63 }
64
65 void
66 SyncLogicHandler::processRoutingUpdateFromSync(std::string routerName,
67 uint64_t seqNo, Nlsr& pnlsr)
68 {
69 if( routerName != pnlsr.getConfParameter().getRouterPrefix() )
70 {
71 SequencingManager sm(seqNo);
72 cout<<sm;
73 cout<<"Router Name: "<<routerName<<endl;
74 if ( pnlsr.getLsdb().isNameLsaNew(routerName+"/1",sm.getNameLsaSeq()))
75 {
76 cout<<"Updated Name LSA. Need to fetch it"<<endl;
77 string lsaPrefix=
78 pnlsr.getConfParameter().getChronosyncLsaPrefix() +
79 routerName + "/1/" +
80 boost::lexical_cast<std::string>(sm.getNameLsaSeq());
81 pnlsr.getIm().expressInterest(pnlsr, lsaPrefix, 3,
82 pnlsr.getConfParameter().getInterestResendTime());
83 }
84 if ( pnlsr.getLsdb().isAdjLsaNew(routerName+"/2",sm.getAdjLsaSeq()))
85 {
86 cout<<"Updated Adj LSA. Need to fetch it"<<endl;
87 string lsaPrefix=
88 pnlsr.getConfParameter().getChronosyncLsaPrefix() +
89 routerName + "/2/" +
90 boost::lexical_cast<std::string>(sm.getAdjLsaSeq());
91 pnlsr.getIm().expressInterest(pnlsr, lsaPrefix, 3,
92 pnlsr.getConfParameter().getInterestResendTime());
93 }
94 if ( pnlsr.getLsdb().isCorLsaNew(routerName+"/3",sm.getCorLsaSeq()))
95 {
96 cout<<"Updated Cor LSA. Need to fetch it"<<endl;
97 string lsaPrefix=
98 pnlsr.getConfParameter().getChronosyncLsaPrefix() +
99 routerName + "/3/" +
100 boost::lexical_cast<std::string>(sm.getCorLsaSeq());
101 pnlsr.getIm().expressInterest(pnlsr, lsaPrefix, 3,
102 pnlsr.getConfParameter().getInterestResendTime());
103 }
104 }
105 }
106
107 void
108 SyncLogicHandler::processKeysUpdateFromSync(std::string certName,
109 uint64_t seqNo, Nlsr& pnlsr)
110 {
111 string certNamePrefix=certName + "/" + boost::lexical_cast<string>(seqNo);
112 pnlsr.getIm().expressInterest(pnlsr, certNamePrefix, 3,
113 pnlsr.getConfParameter().getInterestResendTime());
114 }
115
116 void
117 SyncLogicHandler::publishRoutingUpdate(SequencingManager& sm,
118 string updatePrefix)
119 {
120 sm.writeSeqNoToFile();
121 publishSyncUpdate(updatePrefix,sm.getCombinedSeqNo());
122 }
123
124 void
125 SyncLogicHandler::publishKeyUpdate(KeyManager& km)
126 {
127 publishSyncUpdate(km.getRouterCertName().toUri(),km.getCertSeqNo());
128 }
129
130 void
131 SyncLogicHandler::publishIdentityUpdate(string identityName)
132 {
133 publishSyncUpdate(identityName,0);
134 }
135
136 void
137 SyncLogicHandler::publishSyncUpdate(string updatePrefix, uint64_t seqNo)
138 {
139 cout<<"Publishing Sync Update ......"<<endl;
140 cout<<"Update in prefix: "<<updatePrefix<<endl;
141 cout<<"Seq No: "<<seqNo<<endl;
142 ndn::Name updateName(updatePrefix);
143 string data("NoData");
144 syncSocket->publishData(updateName,0,data.c_str(),data.size(),1000,seqNo);
145 }
146
147}