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 | { |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 44 | // Packet::EnableChecking(); |
| 45 | // Packet::EnablePrinting(); |
| 46 | string input ("./src/NDNabstraction/examples/simpletopology.txt"); |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 47 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 48 | // Time finishTime; |
| 49 | // string animationFile; |
| 50 | string strategy = "ns3::CcnxFloodingStrategy"; |
| 51 | CommandLine cmd; |
| 52 | // cmd.AddValue ("finish", "Finish time", finishTime); |
| 53 | // cmd.AddValue ("netanim", "NetAnim filename", animationFile); |
| 54 | cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy); |
| 55 | cmd.Parse (argc, argv); |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 56 | |
| 57 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 58 | // ------------------------------------------------------------ |
| 59 | // -- Read topology data. |
| 60 | // -------------------------------------------- |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 61 | AnnotatedTopologyReader reader; |
| 62 | reader.SetFileName (input); |
| 63 | |
| 64 | NodeContainer nodes = reader.Read (); |
| 65 | |
| 66 | if (reader.LinksSize () == 0) |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 67 | { |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 68 | NS_LOG_ERROR ("Problems reading the topology file. Failing."); |
| 69 | return -1; |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 70 | } |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 71 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 72 | // ------------------------------------------------------------ |
| 73 | // -- Create nodes and network stacks |
| 74 | // -------------------------------------------- |
| 75 | NS_LOG_INFO ("creating internet stack"); |
| 76 | InternetStackHelper stack; |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 77 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 78 | Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 79 | stack.SetRoutingHelper (ipv4RoutingHelper); |
| 80 | stack.Install(nodes); |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 81 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 82 | NS_LOG_INFO ("Assigning IPv4 addresses"); |
| 83 | reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0")); // will assign metrics |
| 84 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 85 | Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 86 | |
| 87 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 88 | NS_LOG_INFO("installing ccnx stack"); |
| 89 | CcnxStackHelper ccnx; |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 90 | ccnx.SetForwardingStrategy (strategy); |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 91 | ccnx.EnableLimits (false); |
| 92 | |
| 93 | Ptr<CcnxFaceContainer> cf = ccnx.Install (nodes); |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 94 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 95 | NS_LOG_INFO ("Installing Applications"); |
Alexander Afanasyev | e1a065d | 2012-01-10 15:55:14 -0800 | [diff] [blame] | 96 | CcnxAppHelper helper ("ns3::CcnxConsumerCbr"); |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 97 | helper.SetPrefix ("/3"); |
| 98 | ApplicationContainer app = helper.Install ("1"); |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 99 | app.Start (Seconds (1.0)); |
| 100 | app.Stop (Seconds (1000.05)); |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 101 | |
| 102 | CcnxAppHelper helper2 ("ns3::CcnxProducer"); |
| 103 | helper2.SetPrefix ("/3"); |
| 104 | helper2.SetAttribute ("PayloadSize", StringValue("1024")); |
| 105 | ApplicationContainer app2 = helper2.Install("3"); |
| 106 | |
| 107 | app2.Start(Seconds(0.0)); |
| 108 | app2.Stop(Seconds(1500.0)); |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 109 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 110 | // ------------------------------------------------------------ |
| 111 | // -- Run the simulation |
| 112 | // -------------------------------------------- |
| 113 | NS_LOG_INFO ("Run Simulation."); |
| 114 | Simulator::Stop (Seconds (20)); |
| 115 | Simulator::Run (); |
| 116 | Simulator::Destroy (); |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 117 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 118 | NS_LOG_INFO ("Done."); |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 119 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 120 | return 0; |
Ilya Moiseenko | f9a4fb4 | 2011-08-17 10:56:29 -0700 | [diff] [blame] | 121 | } |