blob: 53018a96a58135173edffa48ec1d428db3b336be [file] [log] [blame]
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2011 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
19 */
20
21#include <ctime>
22#include <sstream>
23
24#include "ns3/core-module.h"
25#include "ns3/network-module.h"
26#include "ns3/internet-module.h"
27#include "ns3/point-to-point-module.h"
28#include "ns3/applications-module.h"
29#include "ns3/ipv4-static-routing-helper.h"
30#include "ns3/ipv4-list-routing-helper.h"
31#include "ns3/annotated-topology-reader.h"
32#include <list>
33#include "ns3/visualizer-module.h"
34
35using namespace ns3;
36using namespace std;
37
38NS_LOG_COMPONENT_DEFINE ("AnnotatedTopologyReadingExample");
39
40int main (int argc, char *argv[])
41{
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -070042 GlobalValue::Bind ("SimulatorImplementationType", StringValue
43 ("ns3::VisualSimulatorImpl"));
44
45 string input ("/Users/iliamo/ns3-abstract-ndn/ns-3.11/src/NDNabstraction/examples/simpletopology.txt");
46
47 // Set up command line parameters used to control the experiment.
48 //CommandLine cmd;
49 //cmd.AddValue ("input", "Name of the input file.",
50 // input);
51 //cmd.Parse (argc, argv);
52
53
54 // ------------------------------------------------------------
55 // -- Read topology data.
56 // --------------------------------------------
Ilya Moiseenko7dd43be2011-08-18 18:57:12 -070057
58
59 Ptr<AnnotatedTopologyReader> reader = CreateObject<AnnotatedTopologyReader> ();
60 reader->SetFileName (input);
61
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -070062 NodeContainer nodes;
Ilya Moiseenko7dd43be2011-08-18 18:57:12 -070063 if (reader != 0)
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -070064 {
Ilya Moiseenko7dd43be2011-08-18 18:57:12 -070065 nodes = reader->Read ();
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -070066 }
67
Ilya Moiseenko7dd43be2011-08-18 18:57:12 -070068 if (reader->LinksSize () == 0)
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -070069 {
70 NS_LOG_ERROR ("Problems reading the topology file. Failing.");
71 return -1;
72 }
73
74 // ------------------------------------------------------------
75 // -- Create nodes and network stacks
76 // --------------------------------------------
77 NS_LOG_INFO ("creating internet stack");
78 InternetStackHelper stack;
79
80
81 //routing
82 Ipv4StaticRoutingHelper staticRouting;
83 Ipv4ListRoutingHelper listRH;
84 listRH.Add (staticRouting, 0);
85 stack.SetRoutingHelper (listRH); // has effect on the next Install ()
86 stack.Install (nodes);
87
88 NS_LOG_INFO ("creating ip4 addresses");
89 Ipv4AddressHelper address;
90 address.SetBase ("10.0.0.0", "255.255.255.252");
91
Ilya Moiseenko7dd43be2011-08-18 18:57:12 -070092 int totlinks = reader->LinksSize ();
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -070093
Ilya Moiseenko7dd43be2011-08-18 18:57:12 -070094
95 ///*** applying settings
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -070096 NS_LOG_INFO ("creating node containers");
97 NodeContainer* nc = new NodeContainer[totlinks];
98 TopologyReader::ConstLinksIterator iter;
99 int i = 0;
Ilya Moiseenko7dd43be2011-08-18 18:57:12 -0700100 for ( iter = reader->LinksBegin (); iter != reader->LinksEnd (); iter++, i++ )
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -0700101 {
102 nc[i] = NodeContainer (iter->GetFromNode (), iter->GetToNode ());
103 }
104
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -0700105 NetDeviceContainer* ndc = new NetDeviceContainer[totlinks];
Ilya Moiseenko7dd43be2011-08-18 18:57:12 -0700106 reader->ApplySettings(ndc,nc);
107 ///*** settings applied
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -0700108
Ilya Moiseenko7dd43be2011-08-18 18:57:12 -0700109
110
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -0700111
112 // it creates little subnets, one for each couple of nodes.
113 NS_LOG_INFO ("creating ipv4 interfaces");
114 Ipv4InterfaceContainer* ipic = new Ipv4InterfaceContainer[totlinks];
115 for (int i = 0; i < totlinks; i++)
116 {
117 ipic[i] = address.Assign (ndc[i]);
118 address.NewNetwork ();
119 }
120
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -0700121 // ------------------------------------------------------------
122 // -- Run the simulation
123 // --------------------------------------------
124 NS_LOG_INFO ("Run Simulation.");
125 Simulator::Stop (Seconds (20));
126 Simulator::Run ();
127 Simulator::Destroy ();
128
129 delete[] ipic;
130 delete[] ndc;
131 delete[] nc;
132
133 NS_LOG_INFO ("Done.");
134
135 return 0;
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -0700136}