-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
216 lines (165 loc) · 7.39 KB
/
main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/ndnSIM-module.h"
#include "ns3/netanim-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/internet-module.h"
#include "ns3/csma-module.h"
#include "ns3/integer.h"
#include "ndnBlockchainApp.hpp"
#include "ipBlockchainApp.hpp"
namespace ns3 {
int
main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
int startTime = 0, endTime = 60;
AnnotatedTopologyReader topologyReader ("", 25);
topologyReader.SetFileName ("scratch/RF_BlockApp/topology/topology.txt");
topologyReader.Read ();
NodeContainer allNodes = topologyReader.GetNodes ();
cout << "Number of Nodes: " << allNodes.size () << endl;
bool ndn_flag = false;
// change this flag to run on udp
if (ndn_flag)
{
LogComponentEnable ("ndnBlockchainApp", LOG_LEVEL_DEBUG);
ndn::StackHelper ndnHelper;
ndnHelper.SetDefaultRoutes (true);
ndnHelper.setPolicy ("nfd::cs::lru");
ndnHelper.setCsSize (100);
ndnHelper.InstallAll ();
ndn::StrategyChoiceHelper::InstallAll ("/ndn.blockchain",
"/localhost/nfd/strategy/multicast");
ndn::GlobalRoutingHelper ndnRoutingHelper;
ndnRoutingHelper.InstallAll ();
ndn::AppHelper appHelper ("ndnBlockchainApp");
vector<Ptr<ndnBlockchainApp>> apps;
// for (auto& node : allNodes) {
// std::string nodeName = Names::FindName(node);
// if (nodeName[0] == 'r') continue;
// appHelper.SetAttribute("NodeName", StringValue(nodeName));
// appHelper.SetAttribute("cssz", IntegerValue(100));
// ApplicationContainer tempApps = appHelper.Install(node);
// // std::cout << apps.Get(1)->GetTypeId().GetName() << std::endl;
// apps.Add(tempApps.Get(0));
// std::string prefix = "/ndn.blockchain/" + nodeName;
// ndnRoutingHelper.AddOrigins(prefix, node);
// // cout << nodeName << endl;
// }
for (auto &node : allNodes)
{
std::string nodeName = Names::FindName (node);
Ptr<ndnBlockchainApp> app = CreateObject<ndnBlockchainApp> ();
app->SetStartTime (Seconds (startTime));
app->SetStopTime (Seconds (endTime));
app->SetAttribute ("NodeName", StringValue (nodeName));
app->SetAttribute ("cssz", IntegerValue (100));
apps.push_back (app);
if (nodeName[0] == 'r')
continue;
node->AddApplication (app);
std::string prefix = "/ndn.blockchain/" + nodeName;
ndnRoutingHelper.AddOrigins (prefix, node);
}
ndn::GlobalRoutingHelper::CalculateAllPossibleRoutes ();
Simulator::Stop (Seconds (endTime));
AnimationInterface anim ("scratch/RF_BlockApp/output/animation.xml");
// std::cout << "App name is: ";
// std::cout << allNodes.Get(108)->Get << std::endl;
// SCHEDULER START
// std::cout << "App: " << apps[108]->GetTypeId().GetName() << std::endl;
for (int i = 108; i <= 162; i++)
{
Simulator::Schedule (Seconds (2.0 + i * 0.035), &ndnBlockchainApp::sendInitRequest,
apps[i], std::string ("user-144"));
}
Simulator::Schedule (Seconds (10.000), &ndnBlockchainApp::NewTransaction, apps[108],
std::string ("user-145 Donald"));
Simulator::Schedule (Seconds (10.005), &ndnBlockchainApp::NewTransaction, apps[109],
std::string ("user-146 Clinton"));
Simulator::Schedule (Seconds (10.010), &ndnBlockchainApp::NewTransaction, apps[110],
std::string ("user-226 Russel"));
Simulator::Schedule (Seconds (10.015), &ndnBlockchainApp::NewTransaction, apps[111],
std::string ("user-157 Andrew"));
Simulator::Schedule (Seconds (10.020), &ndnBlockchainApp::NewTransaction, apps[112],
std::string ("user-197 Donald"));
Simulator::Schedule (Seconds (10.030), &ndnBlockchainApp::NewBlock, apps[91]);
Simulator::Schedule (Seconds (12.020), &ndnBlockchainApp::NewTransaction, apps[112],
std::string ("user-197 Donald"));
Simulator::Schedule (Seconds (13.000), &ndnBlockchainApp::NewTransaction, apps[108],
std::string ("user-145 Donald"));
Simulator::Schedule (Seconds (14.005), &ndnBlockchainApp::NewTransaction, apps[109],
std::string ("user-146 Clinton"));
Simulator::Schedule (Seconds (15.010), &ndnBlockchainApp::NewTransaction, apps[110],
std::string ("user-226 Russel"));
Simulator::Schedule (Seconds (20.500), &ndnBlockchainApp::NewBlock, apps[91]);
Simulator::Schedule (Seconds (50.000), &ndnBlockchainApp::ShowResults, apps[108]);
// SCHEDULER END
Simulator::Run ();
Simulator::Destroy ();
}
else
{
auto allLinks = topologyReader.GetLinks ();
InternetStackHelper internetHelper;
internetHelper.Install (allNodes);
topologyReader.AssignIpv4Addresses ("10.0.0.0");
vector<Ptr<ipBlockchainApp>> apps;
for (int i = 0; i < allNodes.size (); i++)
{
Ptr<Node> node = allNodes.Get (i);
std::string nodeName = Names::FindName (node);
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
Ipv4InterfaceAddress iaddr = ipv4->GetAddress (1, 0);
Ipv4Address ipAddr = iaddr.GetLocal ();
cout << i << " " << nodeName << " " << ipAddr << endl;
if (nodeName[0] == 'r')
continue;
Ptr<ipBlockchainApp> udp = CreateObject<ipBlockchainApp> ();
udp->SetStartTime (Seconds (startTime));
udp->SetStopTime (Seconds (endTime));
udp->SetAttribute ("NodeName", StringValue (nodeName));
stringstream ss;
ss << ipAddr;
string ipAddrStr;
ss >> ipAddrStr;
udp->SetAttribute ("m_thisAddress", StringValue (ipAddrStr));
allNodes.Get (i)->AddApplication (udp);
apps.push_back (udp);
}
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Packet::EnablePrinting ();
// Ptr<ipBlockchainApp> udp = CreateObject<ipBlockchainApp> ();
// udp->SetStartTime (Seconds (0));
// udp->SetStopTime (Seconds (20));
// Ptr<Ipv4> ipv4 = allNodes.Get (100)->GetObject<Ipv4> ();
// Ipv4InterfaceAddress iaddr = ipv4->GetAddress (1, 0);
// Ipv4Address ipAddr = iaddr.GetLocal ();
// stringstream ss;
// ss << ipAddr;
// string ipAddrStr;
// ss >> ipAddrStr;
// udp->SetAttribute ("m_thisAddress", StringValue (ipAddrStr));
// allNodes.Get (100)->AddApplication (udp);
// Ipv4Address destIp ("10.1.17.2");
Simulator::Schedule (Seconds (20), &ipBlockchainApp::NewTransaction, apps[108],
std::string ("user-145 Donald"));
// std::string hello = "hello1";
// Ptr<Packet> packet1 = Create<Packet> ((uint8_t *) hello.c_str (), hello.size () + 1);
// Simulator::Schedule (Seconds (20), &ipBlockchainApp::SendPacket, apps[100], packet1, destIp,
// 80);
Simulator::Run ();
Simulator::Destroy ();
}
return 0;
}
} // namespace ns3
int
main (int argc, char *argv[])
{
return ns3::main (argc, argv);
}