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 | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 33 | #include "ns3/visualizer-module.h" |
| 34 | #include "ns3/ccnx.h" |
| 35 | #include "ns3/ipv4-global-routing-helper.h" |
| 36 | #include "ns3/NDNabstraction-module.h" |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 37 | |
| 38 | using namespace ns3; |
| 39 | using namespace std; |
| 40 | |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 41 | NS_LOG_COMPONENT_DEFINE ("AnnotatedTopologyExample"); |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 42 | |
| 43 | int main (int argc, char *argv[]) |
| 44 | { |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 45 | GlobalValue::Bind ("SimulatorImplementationType", StringValue |
| 46 | ("ns3::VisualSimulatorImpl")); |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 47 | Packet::EnableChecking(); |
| 48 | Packet::EnablePrinting(); |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 49 | string input ("/Users/iliamo/ns3-abstract-ndn/ns-3.11/src/NDNabstraction/examples/simpletopology.txt"); |
| 50 | |
| 51 | // Set up command line parameters used to control the experiment. |
| 52 | //CommandLine cmd; |
| 53 | //cmd.AddValue ("input", "Name of the input file.", |
| 54 | // input); |
| 55 | //cmd.Parse (argc, argv); |
| 56 | |
| 57 | |
| 58 | // ------------------------------------------------------------ |
| 59 | // -- Read topology data. |
| 60 | // -------------------------------------------- |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 61 | |
| 62 | |
| 63 | Ptr<AnnotatedTopologyReader> reader = CreateObject<AnnotatedTopologyReader> (); |
| 64 | reader->SetFileName (input); |
| 65 | |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 66 | NodeContainer nodes; |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 67 | if (reader != 0) |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 68 | { |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 69 | nodes = reader->Read (); |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 72 | if (reader->LinksSize () == 0) |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 73 | { |
| 74 | NS_LOG_ERROR ("Problems reading the topology file. Failing."); |
| 75 | return -1; |
| 76 | } |
| 77 | |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 78 | |
| 79 | for(uint32_t j=0; j<nodes.GetN(); j++) |
| 80 | { |
| 81 | uint32_t name = j+1; |
| 82 | std::stringstream ss; |
| 83 | ss<<name; |
| 84 | Names::Add (ss.str(), nodes.Get (j)); |
| 85 | NS_LOG_INFO("Name = " << ss.str()); |
| 86 | } |
| 87 | |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 88 | // ------------------------------------------------------------ |
| 89 | // -- Create nodes and network stacks |
| 90 | // -------------------------------------------- |
| 91 | NS_LOG_INFO ("creating internet stack"); |
| 92 | InternetStackHelper stack; |
| 93 | |
| 94 | |
| 95 | //routing |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 96 | //Ipv4StaticRoutingHelper staticRouting; |
| 97 | //Ipv4ListRoutingHelper listRH; |
| 98 | //listRH.Add (staticRouting, 0); |
| 99 | //stack.SetRoutingHelper (listRH); // has effect on the next Install () |
| 100 | //stack.Install (nodes); |
| 101 | |
| 102 | Ipv4GlobalRoutingHelper ipv4RoutingHelper; |
| 103 | // Ptr<Ipv4RoutingHelper> ipv4RoutingHelper = stack.GetRoutingHelper (); |
| 104 | stack.SetRoutingHelper (ipv4RoutingHelper); |
| 105 | stack.Install(nodes); |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 106 | |
| 107 | NS_LOG_INFO ("creating ip4 addresses"); |
| 108 | Ipv4AddressHelper address; |
| 109 | address.SetBase ("10.0.0.0", "255.255.255.252"); |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 110 | |
| 111 | // // Create router nodes, initialize routing database and set up the routing |
| 112 | // // tables in the nodes. |
| 113 | Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
| 114 | |
| 115 | /*grid.AssignIpv4Addresses ( |
| 116 | Ipv4AddressHelper("10.1.0.0", "255.255.255.0"), |
| 117 | Ipv4AddressHelper("10.2.0.0", "255.255.255.0") |
| 118 | ); |
| 119 | */ |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 120 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 121 | int totlinks = reader->LinksSize (); |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 122 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 123 | |
| 124 | ///*** applying settings |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 125 | NS_LOG_INFO ("creating node containers"); |
| 126 | NodeContainer* nc = new NodeContainer[totlinks]; |
| 127 | TopologyReader::ConstLinksIterator iter; |
| 128 | int i = 0; |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 129 | for ( iter = reader->LinksBegin (); iter != reader->LinksEnd (); iter++, i++ ) |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 130 | { |
| 131 | nc[i] = NodeContainer (iter->GetFromNode (), iter->GetToNode ()); |
| 132 | } |
| 133 | |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 134 | NetDeviceContainer* ndc = new NetDeviceContainer[totlinks]; |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 135 | reader->ApplySettings(ndc,nc); |
| 136 | ///*** settings applied |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 137 | |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 138 | NS_LOG_INFO("installing ccnx stack"); |
| 139 | CcnxStackHelper ccnx(Ccnx::NDN_FLOODING); |
| 140 | Ptr<CcnxFaceContainer> cf = ccnx.Install (nodes); |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 141 | |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 142 | NS_LOG_INFO ("Installing Applications"); |
| 143 | CcnxConsumerHelper helper ("/3"); |
| 144 | ApplicationContainer app = helper.Install (nodes.Get(1)); |
| 145 | app.Start (Seconds (1.0)); |
| 146 | app.Stop (Seconds (1000.05)); |
| 147 | |
| 148 | /*CcnxConsumerHelper helper2 ("/4"); |
| 149 | ApplicationContainer app2 = helper2.Install(c.Get(5)); |
| 150 | app2.Start (Seconds (1.0)); |
| 151 | app2.Stop (Seconds (1000.05)); |
| 152 | */ |
| 153 | CcnxProducerHelper helper3 ("/3",120); |
| 154 | ApplicationContainer app3 = helper3.Install(nodes.Get(6)); |
| 155 | app3.Start(Seconds(0.0)); |
| 156 | app3.Stop(Seconds(1500.0)); |
| 157 | /* |
| 158 | CcnxProducerHelper helper4 ("/4",150); |
| 159 | ApplicationContainer app4 = helper4.Install(c.Get(0)); |
| 160 | app4.Start(Seconds(0.0)); |
| 161 | app4.Stop(Seconds(1500.0)); |
| 162 | */ |
| 163 | |
| 164 | NS_LOG_INFO("Routes"); |
| 165 | ccnx.AddRoute("1","/3",0,1); |
| 166 | ccnx.AddRoute("3","/3",1,1); |
| 167 | ccnx.AddRoute("3","/3",2,2); |
| 168 | /*ccnx.AddRoute("4","/3",1,1); |
| 169 | ccnx.AddRoute("5","/3",2,1); |
| 170 | */ |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 171 | |
| 172 | // it creates little subnets, one for each couple of nodes. |
| 173 | NS_LOG_INFO ("creating ipv4 interfaces"); |
| 174 | Ipv4InterfaceContainer* ipic = new Ipv4InterfaceContainer[totlinks]; |
| 175 | for (int i = 0; i < totlinks; i++) |
| 176 | { |
| 177 | ipic[i] = address.Assign (ndc[i]); |
| 178 | address.NewNetwork (); |
| 179 | } |
| 180 | |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 181 | // ------------------------------------------------------------ |
| 182 | // -- Run the simulation |
| 183 | // -------------------------------------------- |
| 184 | NS_LOG_INFO ("Run Simulation."); |
| 185 | Simulator::Stop (Seconds (20)); |
| 186 | Simulator::Run (); |
| 187 | Simulator::Destroy (); |
| 188 | |
| 189 | delete[] ipic; |
| 190 | delete[] ndc; |
| 191 | delete[] nc; |
| 192 | |
| 193 | NS_LOG_INFO ("Done."); |
| 194 | |
| 195 | return 0; |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 196 | } |