Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 1 | /* -*- 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> |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame^] | 33 | //#include "ns3/visualizer-module.h" |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 34 | |
| 35 | using namespace ns3; |
| 36 | using namespace std; |
| 37 | |
| 38 | NS_LOG_COMPONENT_DEFINE ("AnnotatedTopologyReadingExample"); |
| 39 | |
| 40 | int main (int argc, char *argv[]) |
| 41 | { |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 42 | 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 Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 57 | |
| 58 | |
| 59 | Ptr<AnnotatedTopologyReader> reader = CreateObject<AnnotatedTopologyReader> (); |
| 60 | reader->SetFileName (input); |
| 61 | |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 62 | NodeContainer nodes; |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 63 | if (reader != 0) |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 64 | { |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 65 | nodes = reader->Read (); |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 68 | if (reader->LinksSize () == 0) |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 69 | { |
| 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 Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 92 | int totlinks = reader->LinksSize (); |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 93 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 94 | |
| 95 | ///*** applying settings |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 96 | NS_LOG_INFO ("creating node containers"); |
| 97 | NodeContainer* nc = new NodeContainer[totlinks]; |
| 98 | TopologyReader::ConstLinksIterator iter; |
| 99 | int i = 0; |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 100 | for ( iter = reader->LinksBegin (); iter != reader->LinksEnd (); iter++, i++ ) |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 101 | { |
| 102 | nc[i] = NodeContainer (iter->GetFromNode (), iter->GetToNode ()); |
| 103 | } |
| 104 | |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 105 | NetDeviceContainer* ndc = new NetDeviceContainer[totlinks]; |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 106 | reader->ApplySettings(ndc,nc); |
| 107 | ///*** settings applied |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 108 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 109 | |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame^] | 110 | |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 111 | |
| 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 Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 121 | // ------------------------------------------------------------ |
| 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 Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 136 | } |