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