Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -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 "ns3/core-module.h" |
| 22 | #include "ns3/network-module.h" |
| 23 | #include "ns3/point-to-point-module.h" |
| 24 | #include "ns3/NDNabstraction-module.h" |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 25 | #include "ns3/point-to-point-grid.h" |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 26 | #include "ns3/ipv4-global-routing-helper.h" |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 27 | #include "ns3/netanim-module.h" |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 28 | |
| 29 | #include <iostream> |
| 30 | #include <sstream> |
| 31 | |
| 32 | using namespace ns3; |
| 33 | |
| 34 | NS_LOG_COMPONENT_DEFINE ("CcnxGrid"); |
| 35 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 36 | uint32_t nGrid = 3; |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 37 | Time finishTime = Seconds (20.0); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 38 | |
| 39 | void PrintTime () |
| 40 | { |
| 41 | NS_LOG_INFO (Simulator::Now ()); |
| 42 | |
| 43 | Simulator::Schedule (Seconds (10.0), PrintTime); |
| 44 | } |
| 45 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 46 | void PrintFIBs () |
| 47 | { |
| 48 | NS_LOG_INFO ("Outputing FIBs into [fibs.log]"); |
| 49 | Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("fibs.log", std::ios::out); |
| 50 | for (NodeList::Iterator node = NodeList::Begin (); |
| 51 | node != NodeList::End (); |
| 52 | node++) |
| 53 | { |
| 54 | *routingStream->GetStream () << "Node " << (*node)->GetId () << "\n"; |
| 55 | |
| 56 | Ptr<CcnxFib> fib = (*node)->GetObject<CcnxFib> (); |
| 57 | NS_ASSERT_MSG (fib != 0, "Fire alarm"); |
| 58 | *routingStream->GetStream () << *fib << "\n\n"; |
| 59 | } |
| 60 | } |
| 61 | |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 62 | int |
| 63 | main (int argc, char *argv[]) |
| 64 | { |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 65 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps")); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 66 | Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms")); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 67 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20")); |
Ilya Moiseenko | 82b8eea | 2011-11-02 23:08:47 -0700 | [diff] [blame] | 68 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 69 | Packet::EnableChecking(); |
| 70 | Packet::EnablePrinting(); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 71 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 72 | std::string animationFile = ""; |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 73 | std::string strategy = "ns3::CcnxFloodingStrategy"; |
| 74 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 75 | CommandLine cmd; |
| 76 | cmd.AddValue ("nGrid", "Number of grid nodes", nGrid); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 77 | cmd.AddValue ("finish", "Finish time", finishTime); |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 78 | cmd.AddValue ("netanim", "NetAnim filename", animationFile); |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 79 | cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 80 | cmd.Parse (argc, argv); |
| 81 | |
| 82 | PointToPointHelper p2p; |
| 83 | |
| 84 | InternetStackHelper stack; |
| 85 | Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 86 | stack.SetRoutingHelper (ipv4RoutingHelper); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 87 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 88 | PointToPointGridHelper grid (nGrid, nGrid, p2p); |
| 89 | grid.BoundingBox(100,100,200,200); |
| 90 | |
| 91 | // Install CCNx stack |
| 92 | NS_LOG_INFO ("Installing CCNx stack"); |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 93 | CcnxStackHelper ccnxHelper; |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 94 | ccnxHelper.SetForwardingStrategy (strategy); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 95 | ccnxHelper.EnableLimits (true, Seconds(0.1)); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 96 | ccnxHelper.InstallAll (); |
| 97 | |
| 98 | // Install IP stack (necessary to populate FIB) |
| 99 | NS_LOG_INFO ("Installing IP stack"); |
| 100 | grid.InstallStack (stack); |
| 101 | grid.AssignIpv4Addresses ( |
| 102 | Ipv4AddressHelper("10.1.0.0", "255.255.255.0"), |
| 103 | Ipv4AddressHelper("10.2.0.0", "255.255.255.0") |
| 104 | ); |
| 105 | |
| 106 | Ptr<Node> producer = grid.GetNode (nGrid-1, nGrid-1); |
| 107 | NodeContainer consumerNodes; |
| 108 | consumerNodes.Add (grid.GetNode (0,0)); |
| 109 | |
| 110 | // Populate FIB based on IPv4 global routing controller |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 111 | ccnxHelper.InstallFakeGlobalRoutes (); |
| 112 | ccnxHelper.InstallRouteTo (producer); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 113 | |
| 114 | NS_LOG_INFO ("Installing Applications"); |
| 115 | std::ostringstream prefix; |
| 116 | prefix << "/" << producer->GetId (); |
| 117 | |
Alexander Afanasyev | e1a065d | 2012-01-10 15:55:14 -0800 | [diff] [blame] | 118 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumerCbr"); |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 119 | consumerHelper.SetPrefix (prefix.str ()); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 120 | consumerHelper.SetAttribute ("MeanRate", StringValue ("1Mbps")); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 121 | ApplicationContainer consumers = consumerHelper.Install (consumerNodes); |
| 122 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 123 | // consumers.Start (Seconds (0.0)); |
| 124 | // consumers.Stop (finishTime); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 125 | |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 126 | CcnxAppHelper producerHelper ("ns3::CcnxProducer"); |
| 127 | producerHelper.SetPrefix (prefix.str ()); |
| 128 | producerHelper.SetAttribute ("PayloadSize", StringValue("1024")); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 129 | ApplicationContainer producers = producerHelper.Install (producer); |
| 130 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 131 | // producers.Start(Seconds(0.0)); |
| 132 | // producers.Stop(finishTime); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 133 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 134 | Simulator::Schedule (Seconds (1.0), PrintFIBs); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 135 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 136 | Simulator::Schedule (Seconds (10.0), PrintTime); |
| 137 | |
| 138 | // NS_LOG_INFO ("FIB dump:\n" << *c.Get(0)->GetObject<CcnxFib> ()); |
| 139 | // NS_LOG_INFO ("FIB dump:\n" << *c.Get(1)->GetObject<CcnxFib> ()); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 140 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 141 | Simulator::Stop (finishTime); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 142 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 143 | AnimationInterface *anim = 0; |
| 144 | if (animationFile != "") |
| 145 | { |
| 146 | anim = new AnimationInterface (animationFile); |
| 147 | anim->SetMobilityPollInterval (Seconds (1)); |
| 148 | } |
| 149 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 150 | NS_LOG_INFO ("Run Simulation."); |
| 151 | Simulator::Run (); |
| 152 | Simulator::Destroy (); |
| 153 | NS_LOG_INFO ("Done!"); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 154 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 155 | if (anim != 0) |
| 156 | delete anim; |
| 157 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 158 | return 0; |
Alexander Afanasyev | 3ba44e5 | 2011-11-10 16:38:10 -0800 | [diff] [blame] | 159 | } |