Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * This program is free software; you can redistribute it and/or modify | 3 * This program is free software; you can redistribute it and/or modify |
4 * it under the terms of the GNU General Public License version 2 as | 4 * it under the terms of the GNU General Public License version 2 as |
5 * published by the Free Software Foundation; | 5 * published by the Free Software Foundation; |
6 * | 6 * |
7 * This program is distributed in the hope that it will be useful, | 7 * This program is distributed in the hope that it will be useful, |
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 * GNU General Public License for more details. | 10 * GNU General Public License for more details. |
11 * | 11 * |
12 * You should have received a copy of the GNU General Public License | 12 * You should have received a copy of the GNU General Public License |
13 * along with this program; if not, write to the Free Software | 13 * along with this program; if not, write to the Free Software |
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
15 * | 15 * |
16 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it> | 16 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it> |
17 * Author: Valerio Sartini <valesar@gmail.com> | 17 * Author: Valerio Sartini <valesar@gmail.com> |
18 * | 18 * |
19 * This program conducts a simple experiment: It .... | 19 * This program conducts a simple experiment: It builds up a topology based on |
20 * [TODO] write some details | 20 * either Inet or Orbis trace files. A random node is then chosen, and all the |
21 * | 21 * other nodes will send a packet to it. The TTL is measured and reported as an histogram. |
22 * Use an Inet/Orbis generated web topology to build an ns-3 topology (plus an e xample | |
23 * of a simple echo application to test the structure). | |
24 * The type of topology reader used ("Orbis" or "Inet") and | |
25 * the input file name (InputFile: -> examplefile.txt) are set by command line | |
26 * | 22 * |
27 */ | 23 */ |
28 | 24 |
29 // #define NS3_LOG_ENABLE // Now defined by Makefile | 25 // #define NS3_LOG_ENABLE // Now defined by Makefile |
30 | 26 |
31 #include <ctime> | 27 #include <ctime> |
32 | 28 |
33 #include <sstream> | 29 #include <sstream> |
34 | 30 |
35 #include "ns3/core-module.h" | 31 #include "ns3/core-module.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
48 using namespace ns3; | 44 using namespace ns3; |
49 using namespace std; | 45 using namespace std; |
50 | 46 |
51 NS_LOG_COMPONENT_DEFINE ("TopologyCreationExperiment"); | 47 NS_LOG_COMPONENT_DEFINE ("TopologyCreationExperiment"); |
52 | 48 |
53 | 49 |
54 static list<unsigned int> data; | 50 static list<unsigned int> data; |
55 | 51 |
56 static void SinkRx (Ptr<const Packet> p, const Address &ad) | 52 static void SinkRx (Ptr<const Packet> p, const Address &ad) |
57 { | 53 { |
58 // std::cout << *p << std::endl; | |
59 Ipv4Header ipv4; | 54 Ipv4Header ipv4; |
60 p->PeekHeader (ipv4); | 55 p->PeekHeader (ipv4); |
61 // std::cout << " ttl=" << (unsigned)ipv4.GetTtl () << std::endl; | |
62 data.push_back ((unsigned)ipv4.GetTtl () ); | 56 data.push_back ((unsigned)ipv4.GetTtl () ); |
63 } | 57 } |
64 | 58 |
65 static void PingRtt (std::string context, Time rtt) | |
66 { | |
67 // std::cout << context << " " << rtt << std::endl; | |
68 } | |
69 | 59 |
70 // ---------------------------------------------------------------------- | 60 // ---------------------------------------------------------------------- |
71 // -- main | 61 // -- main |
72 // ---------------------------------------------- | 62 // ---------------------------------------------- |
73 int main (int argc, char *argv[]) | 63 int main (int argc, char *argv[]) |
74 { | 64 { |
75 | 65 |
76 string format ("Orbis"); | 66 string format ("Inet"); |
77 | 67 string input ("examples/topology-read/Inet_small_toposample.txt"); |
78 string experiment ("topology-test"); | |
79 string input; | |
80 | 68 |
81 // Set up command line parameters used to control the experiment. | 69 // Set up command line parameters used to control the experiment. |
82 CommandLine cmd; | 70 CommandLine cmd; |
83 cmd.AddValue ("format", "Format to use for data input [Orbis|Inet].", | 71 cmd.AddValue ("format", "Format to use for data input [Orbis|Inet].", |
84 format); | 72 format); |
85 cmd.AddValue ("input", "Name of the input file.", | 73 cmd.AddValue ("input", "Name of the input file.", |
86 input); | 74 input); |
87 cmd.Parse (argc, argv); | 75 cmd.Parse (argc, argv); |
88 | 76 |
89 if (format != "Orbis" && format != "Inet") | 77 if (format != "Orbis" && format != "Inet") |
90 { | 78 { |
91 NS_LOG_ERROR ("Unknown input format '" << format << "'"); | 79 NS_LOG_ERROR ("Unknown input format '" << format << "'"); |
92 return -1; | 80 return -1; |
93 } | 81 } |
94 | 82 |
95 // ------------------------------------------------------------ | 83 // ------------------------------------------------------------ |
96 // -- Read topology data. | 84 // -- Read topology data. |
97 // -------------------------------------------- | 85 // -------------------------------------------- |
98 | 86 |
99 // Pick a topology reader based in the requested format. | 87 // Pick a topology reader based in the requested format. |
100 | 88 |
101 Ptr<TopologyReaderInterface> inFile = 0; | 89 Ptr<TopologyReaderInterface> inFile = 0; |
102 | 90 |
103 NodeContainer nodes; | 91 NodeContainer nodes; |
104 map<string, TopologyNode > nodeMap; | 92 map<string, TopologyNode > nodeMap; |
105 list<TopologyLink> linksList; | 93 list<TopologyLink> linksList; |
106 | 94 int linkNumber; |
107 | 95 |
108 if (format == "Orbis") | 96 if (format == "Orbis") |
109 { | 97 { |
110 NS_LOG_INFO ("Reading Orbis formatted data input."); | 98 NS_LOG_INFO ("Reading Orbis formatted data input."); |
111 inFile = CreateObject<OrbisTopologyReader> (); | 99 inFile = CreateObject<OrbisTopologyReader> (); |
112 } | 100 } |
113 else if (format == "Inet") | 101 else if (format == "Inet") |
114 { | 102 { |
115 NS_LOG_INFO ("Reading Inet formatted data input."); | 103 NS_LOG_INFO ("Reading Inet formatted data input."); |
116 inFile = CreateObject<InetTopologyReader> (); | 104 inFile = CreateObject<InetTopologyReader> (); |
117 } | 105 } |
118 | 106 std::cout << "trying to read " << input << std::endl; |
Tommaso Pecorella
2010/02/22 00:12:04
This line is a refuso, already removed from code (
| |
119 if (inFile != 0) | 107 if (inFile != 0) |
120 { | 108 { |
121 inFile->SetTopoFileName (input); | 109 inFile->SetTopoFileName (input); |
122 inFile->Input ( nodes, nodeMap, linksList ); | 110 linkNumber = inFile->Input ( nodes, nodeMap, linksList ); |
123 } | 111 } |
124 | 112 |
125 if (nodes.GetN () == 0) | 113 if (linkNumber <= 0) |
126 { | |
127 NS_LOG_ERROR ("Problems reading the topology file. Failing."); | |
128 return -1; | |
129 } | |
130 ·· | |
131 // ------------------------------------------------------------ | |
132 // -- Bunch of debugging code. To be stripped out | |
133 // -------------------------------------------- | |
134 NS_LOG_INFO ("created " << nodes.GetN () << " nodes" ); | |
135 for (unsigned int i = 0; i < nodes.GetN (); i++ ) | |
136 { | 114 { |
137 NS_LOG_INFO ( "node " << i << " = " << nodes.Get (i) ); | 115 NS_LOG_ERROR ("Problems reading the topology file. Failing."); |
116 return -1; | |
138 } | 117 } |
139 | 118 |
140 NS_LOG_INFO ("created " << nodeMap.size () << " node names" ); | |
141 map<string, TopologyNode >::const_iterator itr; | |
142 for (itr = nodeMap.begin (); itr != nodeMap.end (); ++itr) | |
143 { | |
144 NS_LOG_INFO ( "Key: " << (*itr).first << " Value: " << (*itr).second.nodeP tr ); | |
145 } | |
146 | |
147 NS_LOG_INFO ("created " << linksList.size () << " links" ); | |
148 list<TopologyLink>::const_iterator itr2; | |
149 for (itr2 = linksList.begin (); itr2 != linksList.end (); ++itr2) | |
150 { | |
151 NS_LOG_INFO ( "from: " << (*itr2).from << " to: " << (*itr2).to ); | |
152 } | |
153 | |
154 | |
155 | |
156 // ------------------------------------------------------------ | 119 // ------------------------------------------------------------ |
157 // -- Create nodes and network stacks | 120 // -- Create nodes and network stacks |
158 // -------------------------------------------- | 121 // -------------------------------------------- |
159 NS_LOG_INFO ("creating internet stack"); | 122 NS_LOG_INFO ("creating internet stack"); |
160 InternetStackHelper stack; | 123 InternetStackHelper stack; |
161 | 124 |
162 // Setup NixVector Routing | 125 // Setup NixVector Routing |
163 Ipv4NixVectorHelper nixRouting; | 126 Ipv4NixVectorHelper nixRouting; |
164 Ipv4StaticRoutingHelper staticRouting; | 127 Ipv4StaticRoutingHelper staticRouting; |
165 | 128 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 { | 166 { |
204 ipic[i] = address.Assign (ndc[i]); | 167 ipic[i] = address.Assign (ndc[i]); |
205 address.NewNetwork (); | 168 address.NewNetwork (); |
206 } | 169 } |
207 | 170 |
208 | 171 |
209 uint32_t totalNodes = nodes.GetN (); | 172 uint32_t totalNodes = nodes.GetN (); |
210 UniformVariable unifRandom (0, totalNodes - 1); | 173 UniformVariable unifRandom (0, totalNodes - 1); |
211 | 174 |
212 unsigned int randomServerNumber = unifRandom.GetInteger (0, totalNodes - 1); | 175 unsigned int randomServerNumber = unifRandom.GetInteger (0, totalNodes - 1); |
213 // int randomServerNumber = 0; | |
214 unsigned int randomClientNumber = 0; | |
215 do | |
216 { | |
217 randomClientNumber = unifRandom.GetInteger (0, totalNodes - 1); | |
218 } | |
219 while (randomClientNumber == randomServerNumber ); | |
220 | 176 |
221 Ptr<Node> randomServerNode = nodes.Get (randomServerNumber); | 177 Ptr<Node> randomServerNode = nodes.Get (randomServerNumber); |
222 Ptr<Node> randomClientNode = nodes.Get (randomClientNumber); | |
223 | |
224 Ptr<Ipv4> ipv4Server = randomServerNode->GetObject<Ipv4> (); | 178 Ptr<Ipv4> ipv4Server = randomServerNode->GetObject<Ipv4> (); |
225 Ipv4InterfaceAddress iaddrServer = ipv4Server->GetAddress (1,0); | 179 Ipv4InterfaceAddress iaddrServer = ipv4Server->GetAddress (1,0); |
226 Ipv4Address ipv4AddrServer = iaddrServer.GetLocal (); | 180 Ipv4Address ipv4AddrServer = iaddrServer.GetLocal (); |
227 | 181 |
228 Ptr<Ipv4> ipv4Client = randomClientNode->GetObject<Ipv4> (); | |
229 Ipv4InterfaceAddress iaddrClient = ipv4Client->GetAddress (1,0); | |
230 Ipv4Address ipv4AddrClient = iaddrClient.GetLocal (); | |
231 | |
232 // ------------------------------------------------------------ | 182 // ------------------------------------------------------------ |
233 // -- Another bunch of debugging code. To be stripped out | 183 // -- Send around packets to check the ttl |
234 // -------------------------------------------- | |
235 int interfaceNumber = ipv4Server->GetNInterfaces (); | |
236 NS_LOG_INFO ("The server " << randomServerNumber << " - " << randomServerNode << " have " << interfaceNumber << " interfaces" ); | |
237 for ( int i = 0; i < interfaceNumber; i++ ) | |
238 { | |
239 int addressNumber = ipv4Server->GetNAddresses (i); | |
240 NS_LOG_INFO ("The interface " << i << " have " << addressNumber << " addre sses" ); | |
241 for ( int j = 0; j < addressNumber; j++ ) | |
242 { | |
243 NS_LOG_INFO ("The IP number of (interface, address) (" << i << "," << j << ") is " << ipv4Server->GetAddress (i,j).GetLocal () ); | |
244 } | |
245 } | |
246 | |
247 // Ipv4GlobalRoutingHelper uses too much memory for flat topologies | |
248 // Ipv4GlobalRoutingHelper::PopulateRoutingTables (); | |
249 | |
250 | |
251 /* | |
252 //------------------------------------------------------------ | |
253 //-- UDP Echo client / server | |
254 //-------------------------------------------- | |
255 // the sample application: just a client sending a packet to a server node and | |
256 // its echo. | |
257 NS_LOG_INFO ("creating echo server application"); | |
258 UdpEchoServerHelper echoServer (7); | |
259 | |
260 ApplicationContainer serverApps = echoServer.Install (randomServerNode); | |
261 serverApps.Start (Seconds (1.0)); | |
262 serverApps.Stop (Seconds (10.0)); | |
263 | |
264 UdpEchoClientHelper echoClient (ipv4AddrServer, 7); | |
265 echoClient.SetAttribute ("MaxPackets", UintegerValue (1)); | |
266 echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.))); | |
267 echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); | |
268 ApplicationContainer clientApps = echoClient.Install (randomClientNode); | |
269 clientApps.Start (Seconds (2.0)); | |
270 clientApps.Stop (Seconds (10.0)); | |
271 | |
272 | |
273 //------------------------------------------------------------ | |
274 //-- Ping application (from client to server) | |
275 //-------------------------------------------- | |
276 V4PingHelper ping = V4PingHelper (ipv4AddrServer); | |
277 ApplicationContainer pingApps = ping.Install (randomClientNode); | |
278 pingApps.Start (Seconds (11.0)); | |
279 pingApps.Stop (Seconds (20.0)); | |
280 */ | |
281 | |
282 // ------------------------------------------------------------ | |
283 // -- Some other packets to check the ttl | |
284 // -------------------------------------------- | 184 // -------------------------------------------- |
285 Config::SetDefault ("ns3::Ipv4RawSocketImpl::Protocol", StringValue ("2")); | 185 Config::SetDefault ("ns3::Ipv4RawSocketImpl::Protocol", StringValue ("2")); |
286 InetSocketAddress dst = InetSocketAddress ( ipv4AddrServer ); | 186 InetSocketAddress dst = InetSocketAddress ( ipv4AddrServer ); |
187 | |
287 OnOffHelper onoff = OnOffHelper ("ns3::Ipv4RawSocketFactory", dst); | 188 OnOffHelper onoff = OnOffHelper ("ns3::Ipv4RawSocketFactory", dst); |
288 onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0))); | 189 onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0))); |
289 onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0))); | 190 onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0))); |
290 onoff.SetAttribute ("DataRate", DataRateValue (DataRate (15000))); | 191 onoff.SetAttribute ("DataRate", DataRateValue (DataRate (15000))); |
291 onoff.SetAttribute ("PacketSize", UintegerValue (1200)); | 192 onoff.SetAttribute ("PacketSize", UintegerValue (1200)); |
292 | 193 |
293 NodeContainer clientNodes; | 194 NodeContainer clientNodes; |
294 // for( unsigned int i=0; i<10; i++ ) | |
295 for ( unsigned int i = 0; i < nodes.GetN (); i++ ) | 195 for ( unsigned int i = 0; i < nodes.GetN (); i++ ) |
296 { | 196 { |
297 if (i != randomServerNumber ) | 197 if (i != randomServerNumber ) |
298 { | 198 { |
299 Ptr<Node> clientNode = nodes.Get (i); | 199 Ptr<Node> clientNode = nodes.Get (i); |
300 clientNodes.Add (clientNode); | 200 clientNodes.Add (clientNode); |
301 } | 201 } |
302 } | 202 } |
303 // ApplicationContainer apps = onoff.Install (randomClientNode); | 203 |
304 ApplicationContainer apps = onoff.Install (clientNodes); | 204 ApplicationContainer apps = onoff.Install (clientNodes); |
305 apps.Start (Seconds (22.0)); | 205 apps.Start (Seconds (1.0)); |
306 apps.Stop (Seconds (23.0)); | 206 apps.Stop (Seconds (2.0)); |
307 | 207 |
308 // NS_LOG_INFO ("Create Sink."); | |
309 PacketSinkHelper sink = PacketSinkHelper ("ns3::Ipv4RawSocketFactory", dst); | 208 PacketSinkHelper sink = PacketSinkHelper ("ns3::Ipv4RawSocketFactory", dst); |
310 apps = sink.Install (randomServerNode); | 209 apps = sink.Install (randomServerNode); |
311 apps.Start (Seconds (21.0)); | 210 apps.Start (Seconds (0.0)); |
312 apps.Stop (Seconds (31.0)); | 211 apps.Stop (Seconds (3.0)); |
313 | 212 |
314 // then, print what the packet sink receives. | 213 // we trap the packet sink receiver to extract the TTL. |
315 Config::ConnectWithoutContext ("/NodeList/*/ApplicationList/*/$ns3::PacketSink /Rx", | 214 Config::ConnectWithoutContext ("/NodeList/*/ApplicationList/*/$ns3::PacketSink /Rx", |
316 MakeCallback (&SinkRx)); | 215 MakeCallback (&SinkRx)); |
317 | 216 |
318 // finally, print the ping rtts. | 217 // Packet::EnablePrinting (); |
Tommaso Pecorella
2010/02/22 00:12:04
This line is a refuso, already removed from code (
| |
319 Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::V4Ping/Rtt", | |
320 MakeCallback (&PingRtt)); | |
321 | |
322 Packet::EnablePrinting (); | |
323 | 218 |
324 // ------------------------------------------------------------ | 219 // ------------------------------------------------------------ |
325 // -- Run the simulation | 220 // -- Run the simulation |
326 // -------------------------------------------- | 221 // -------------------------------------------- |
327 NS_LOG_INFO ("Run Simulation."); | 222 NS_LOG_INFO ("Run Simulation."); |
328 Simulator::Run (); | 223 Simulator::Run (); |
329 Simulator::Destroy (); | 224 Simulator::Destroy (); |
330 | 225 |
331 unsigned int minTtl; | 226 unsigned int minTtl; |
332 unsigned int maxTtl; | 227 unsigned int maxTtl; |
(...skipping 17 matching lines...) Expand all Loading... | |
350 } | 245 } |
351 gsl_histogram_fprintf (stdout, h, "%g", "%g"); | 246 gsl_histogram_fprintf (stdout, h, "%g", "%g"); |
352 gsl_histogram_free (h); | 247 gsl_histogram_free (h); |
353 | 248 |
354 NS_LOG_INFO ("Done."); | 249 NS_LOG_INFO ("Done."); |
355 | 250 |
356 return 0; | 251 return 0; |
357 | 252 |
358 // end main | 253 // end main |
359 } | 254 } |
OLD | NEW |