-
Notifications
You must be signed in to change notification settings - Fork 18
/
fat-tree.cc
288 lines (238 loc) · 8.95 KB
/
fat-tree.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
// Network topology
//
// _l9__ _l10__
// / \ / \
// / /\ \
// / / \ \
// / / \ \
// l5 l6 l7 l8
// |\ /| |\ /|
// | \ / | | \ / |
// | \ / | | \ / |
// | /\ | | /\ |
// |_/ \__| |_/ \__|
// l1 l2 l3 l4
// | | | |
// c1 c2 c3 c4
//*/
// - all links are point-to-point links with indicated one-way BW/delay
// - CBR/UDP flows from n0 to n3, and n3 to n1
// - FTP/TCP flow from n0 to n3, starting at time 1.2 to 1.35 sec.
// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec.
// (i.e., DataRate of 448,000 bps)
// - DropTail queues
// - Tracing of queues and packet receptions to file "simple-global-routing.tr"
//
#include <iostream>
#include <fstream>
#include <string>
#include <cassert>
#include "ns3/olsr-helper.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/flow-monitor-helper.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/csma-module.h"
using namespace ns3;
using namespace std;
void printRoutingTable (Ptr<Node> node)
{
Ipv4StaticRoutingHelper helper;
Ptr<Ipv4> stack = node -> GetObject<Ipv4>();
Ptr<Ipv4StaticRouting> staticrouting = helper.GetStaticRouting(stack);
uint32_t numroutes=staticrouting->GetNRoutes();
Ipv4RoutingTableEntry entry;
std::cout << "Routing table for device: " << Names::FindName(node) <<"\n";
std::cout << "Destination\tMask\t\tGateway\t\tIface\n";
for (uint32_t i =0 ; i<numroutes;i++) {
entry =staticrouting->GetRoute(i);
std::cout << entry.GetDestNetwork() << "\t" << entry.GetDestNetworkMask() << "\t" << entry.GetGateway() << "\t\t" << entry.GetInterface() << "\n";
}
return;
}
NS_LOG_COMPONENT_DEFINE ("SimpleGlobalRoutingExample");
int
main(int argc, char *argv[])
{
// Users may find it convenient to turn on explicit debugging
// for selected modules; the below line suggets how to do this
#if 0
LogComponentEnable ("SimpleGlobalRoutingExample", LOG_LEVEL_INFO);
#endif
// Set up some default values for the simulation. Use the
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue(210));
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
// DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
// Allow the user to override any of the default and the above
// DafaultValue::Bind ()s at run-time, via command-line arguments
CommandLine cmd;
// OlsrHelper olsr;
Ipv4StaticRoutingHelper staticRouting;
Ipv4ListRoutingHelper listRouting;
Ipv4ListRoutingHelper list;
//list.Add (listRouting, 0);
//list.Add (olsr, 10);
bool enableFlowMonitor = false;
cmd.AddValue("EnableMonitor", "Enable Flow Monitor", enableFlowMonitor);
cmd.Parse(argc, argv);
NS_LOG_INFO ("Create Nodes");
NodeContainer c1,c2,c3,c4;
NodeContainer l1,l2,l3,l4,l5,l6,l7,l8,l9,l10;
c1.Create(1);
c2.Create(1);
c3.Create(1);
c4.Create(1);
l1.Create(1);
l2.Create(1);
l3.Create(1);
l4.Create(1);
l5.Create(1);
l6.Create(1);
l7.Create(1);
l8.Create(1);
l9.Create(1);
l10.Create(1);
NodeContainer n1 = NodeContainer (c1,l1);
NodeContainer n2 = NodeContainer (c2,l2);
NodeContainer n3 = NodeContainer (c3,l3);
NodeContainer n4 = NodeContainer (c4,l4);
NodeContainer n51 = NodeContainer (l5,l1);
NodeContainer n52 = NodeContainer (l5,l2);
NodeContainer n61 = NodeContainer (l6,l1);
NodeContainer n62 = NodeContainer (l6,l2);
NodeContainer n71 = NodeContainer (l7,l3);
NodeContainer n72 = NodeContainer (l7,l4);
NodeContainer n81 = NodeContainer (l8,l3);
NodeContainer n82 = NodeContainer (l8,l4);
NodeContainer n91 = NodeContainer (l9,l5);
NodeContainer n92 = NodeContainer (l9,l7);
NodeContainer nx = NodeContainer (l10,l6);
NodeContainer ny = NodeContainer (l10,l8);
InternetStackHelper internet;
//internet.SetRoutingHelper (list);
internet.Install (c1);
internet.Install (c2);
internet.Install (c3);
internet.Install (c4);
internet.Install (l1);
internet.Install (l2);
internet.Install (l3);
internet.Install (l4);
internet.Install (l5);
internet.Install (l6);
internet.Install (l7);
internet.Install (l8);
internet.Install (l9);
internet.Install (l10);
NS_LOG_INFO ("Create Channels");
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate",DataRateValue (DataRate ("2Mbps")));
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
csma.SetDeviceAttribute ("Mtu", UintegerValue (1400));
NetDeviceContainer d1 = csma.Install (n1 );
NetDeviceContainer d2 = csma.Install (n2 );
NetDeviceContainer d3 = csma.Install (n3 );
NetDeviceContainer d4 = csma.Install (n4 );
PointToPointHelper p2p;
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
NetDeviceContainer d51 = p2p.Install(n51);
NetDeviceContainer d52 = p2p.Install(n52);
NetDeviceContainer d61 = p2p.Install(n61);
NetDeviceContainer d62 = p2p.Install(n62);
NetDeviceContainer d71 = p2p.Install(n71);
NetDeviceContainer d72 = p2p.Install(n72);
NetDeviceContainer d81 = p2p.Install(n81);
NetDeviceContainer d82 = p2p.Install(n82);
NetDeviceContainer d91 = p2p.Install(n91);
NetDeviceContainer d92 = p2p.Install(n92);
NetDeviceContainer dx = p2p.Install(nx);
NetDeviceContainer dy = p2p.Install(ny);
cout << "Control after point-to-point" << endl;
/*p2p.SetDeviceAttribute ("DataRate", StringValue ("15Mbps"));
p2p.SetChannelAttribute ("Delay", StringValue ("5ms"));
NetDeviceContainer d3d2 = p2p.Install (n3n2);*/
// Later we add IP Addresses
NS_LOG_INFO ("Assign IP Addresses.");
Ipv4AddressHelper ipv4;
ipv4.SetBase("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer i1 = ipv4.Assign(d1);
ipv4.SetBase("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer i2 = ipv4.Assign(d2);
ipv4.SetBase("10.1.3.0", "255.255.255.0");
Ipv4InterfaceContainer i3 = ipv4.Assign(d3);
ipv4.SetBase("10.1.4.0", "255.255.255.0");
Ipv4InterfaceContainer i4 = ipv4.Assign(d4);
ipv4.SetBase("10.1.5.0", "255.255.255.0");
Ipv4InterfaceContainer i51 = ipv4.Assign(d51);
ipv4.SetBase("10.1.6.0", "255.255.255.0");
Ipv4InterfaceContainer i52 = ipv4.Assign(d52);
ipv4.SetBase("10.1.7.0", "255.255.255.0");
Ipv4InterfaceContainer i61 = ipv4.Assign(d61);
ipv4.SetBase("10.1.8.0", "255.255.255.0");
Ipv4InterfaceContainer i62 = ipv4.Assign(d62);
ipv4.SetBase("10.1.9.0", "255.255.255.0");
Ipv4InterfaceContainer i71 = ipv4.Assign(d71);
ipv4.SetBase("10.1.10.0", "255.255.255.0");
Ipv4InterfaceContainer i72 = ipv4.Assign(d72);
ipv4.SetBase("10.1.11.0", "255.255.255.0");
Ipv4InterfaceContainer i81 = ipv4.Assign(d81);
ipv4.SetBase("10.1.12.0", "255.255.255.0");
Ipv4InterfaceContainer i82 = ipv4.Assign(d82);
ipv4.SetBase("10.1.13.0", "255.255.255.0");
Ipv4InterfaceContainer i91 = ipv4.Assign(d91);
ipv4.SetBase("10.1.14.0", "255.255.255.0");
Ipv4InterfaceContainer i92 = ipv4.Assign(d92);
ipv4.SetBase("10.1.15.0", "255.255.255.0");
Ipv4InterfaceContainer ix = ipv4.Assign(dx);
ipv4.SetBase("10.1.16.0", "255.255.255.0");
Ipv4InterfaceContainer iy = ipv4.Assign(dy);
cout << " Address assigned " << endl;
// Create router nodes, initialize routing database and set up the routing
// tables in the nodes.
//
// Ipv4GlobalRouting::RandomEcmpRouting:m_randomEcmpRouting (true);
// Ipv4GlobalRouting::RandomEcmpRouting (true);
Ipv4GlobalRoutingHelper::PopulateRoutingTables();
cout << "Routing is done " << endl;
// printRoutingTable(l1.Get(0));
// printRoutingTable(l2.Get(0));
// printRoutingTable(l3.Get(0));
//
// Create one udpServer applications on node one.
//
uint16_t port = 4000;
UdpServerHelper server (port);
ApplicationContainer apps = server.Install (c1.Get (0));
apps.Start (Seconds (1.0));
apps.Stop (Seconds (10.0));
//
// Create one UdpClient application to send UDP datagrams from node zero to
// node one.
//
uint32_t MaxPacketSize = 1024;
Time interPacketInterval = Seconds (0.05);
uint32_t maxPacketCount = 320;
UdpClientHelper client (i1.GetAddress (0), port);
client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
client.SetAttribute ("Interval", TimeValue (interPacketInterval));
client.SetAttribute ("PacketSize", UintegerValue (MaxPacketSize));
apps = client.Install (NodeContainer (c4.Get (0)));
apps.Start (Seconds (2.0));
apps.Stop (Seconds (10.0));
csma.EnablePcap ("server", d1, false);
csma.EnablePcap ("client", d4, false);
//
// Now, do the actual simulation.
//
NS_LOG_INFO ("Run Simulation.");
Simulator::Stop (Seconds (20.0));
Simulator::Run ();
Simulator::Destroy ();
NS_LOG_INFO ("Done.");
//
}