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" |
| 27 | |
| 28 | #include <iostream> |
| 29 | #include <sstream> |
| 30 | |
| 31 | using namespace ns3; |
| 32 | |
| 33 | NS_LOG_COMPONENT_DEFINE ("CcnxGrid"); |
| 34 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 35 | uint32_t nGrid = 3; |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 36 | Time finishTime = Seconds (20.0); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 37 | |
| 38 | void PrintTime () |
| 39 | { |
| 40 | NS_LOG_INFO (Simulator::Now ()); |
| 41 | |
| 42 | Simulator::Schedule (Seconds (10.0), PrintTime); |
| 43 | } |
| 44 | |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 45 | int |
| 46 | main (int argc, char *argv[]) |
| 47 | { |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 48 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps")); |
| 49 | Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("1ms")); |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 50 | Config::SetDefault ("ns3::CcnxConsumer::OffTime", StringValue ("1s")); |
Ilya Moiseenko | 82b8eea | 2011-11-02 23:08:47 -0700 | [diff] [blame] | 51 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 52 | Packet::EnableChecking(); |
| 53 | Packet::EnablePrinting(); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 54 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 55 | CommandLine cmd; |
| 56 | cmd.AddValue ("nGrid", "Number of grid nodes", nGrid); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 57 | cmd.AddValue ("finish", "Finish time", finishTime); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 58 | cmd.Parse (argc, argv); |
| 59 | |
| 60 | PointToPointHelper p2p; |
| 61 | |
| 62 | InternetStackHelper stack; |
| 63 | Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 64 | stack.SetRoutingHelper (ipv4RoutingHelper); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 65 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 66 | PointToPointGridHelper grid (nGrid, nGrid, p2p); |
| 67 | grid.BoundingBox(100,100,200,200); |
| 68 | |
| 69 | // Install CCNx stack |
| 70 | NS_LOG_INFO ("Installing CCNx stack"); |
| 71 | CcnxStackHelper ccnxHelper(Ccnx::NDN_FLOODING/*Ccnx::NDN_BESTROUTE*/); |
| 72 | ccnxHelper.InstallAll (); |
| 73 | |
| 74 | // Install IP stack (necessary to populate FIB) |
| 75 | NS_LOG_INFO ("Installing IP stack"); |
| 76 | grid.InstallStack (stack); |
| 77 | grid.AssignIpv4Addresses ( |
| 78 | Ipv4AddressHelper("10.1.0.0", "255.255.255.0"), |
| 79 | Ipv4AddressHelper("10.2.0.0", "255.255.255.0") |
| 80 | ); |
| 81 | |
| 82 | Ptr<Node> producer = grid.GetNode (nGrid-1, nGrid-1); |
| 83 | NodeContainer consumerNodes; |
| 84 | consumerNodes.Add (grid.GetNode (0,0)); |
| 85 | |
| 86 | // Populate FIB based on IPv4 global routing controller |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 87 | ccnxHelper.InstallFakeGlobalRoutes (); |
| 88 | ccnxHelper.InstallRouteTo (producer); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 89 | |
| 90 | NS_LOG_INFO ("Installing Applications"); |
| 91 | std::ostringstream prefix; |
| 92 | prefix << "/" << producer->GetId (); |
| 93 | |
| 94 | CcnxConsumerHelper consumerHelper (prefix.str ()); |
| 95 | ApplicationContainer consumers = consumerHelper.Install (consumerNodes); |
| 96 | |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 97 | consumers.Start (Seconds (0.0)); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 98 | consumers.Stop (finishTime); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 99 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 100 | CcnxProducerHelper producerHelper (prefix.str (),120); |
| 101 | ApplicationContainer producers = producerHelper.Install (producer); |
| 102 | |
| 103 | producers.Start(Seconds(0.0)); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 104 | producers.Stop(finishTime); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 105 | |
| 106 | NS_LOG_INFO ("Outputing FIBs into [fibs.log]"); |
| 107 | Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("fibs.log", std::ios::out); |
| 108 | for (NodeList::Iterator node = NodeList::Begin (); |
| 109 | node != NodeList::End (); |
| 110 | node++) |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 111 | { |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 112 | *routingStream->GetStream () << "Node " << (*node)->GetId () << "\n"; |
| 113 | |
| 114 | Ptr<CcnxFib> fib = (*node)->GetObject<CcnxFib> (); |
| 115 | NS_ASSERT_MSG (fib != 0, "Fire alarm"); |
| 116 | *routingStream->GetStream () << *fib << "\n\n"; |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 117 | } |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 118 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 119 | Simulator::Schedule (Seconds (10.0), PrintTime); |
| 120 | |
| 121 | // NS_LOG_INFO ("FIB dump:\n" << *c.Get(0)->GetObject<CcnxFib> ()); |
| 122 | // NS_LOG_INFO ("FIB dump:\n" << *c.Get(1)->GetObject<CcnxFib> ()); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 123 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 124 | Simulator::Stop (finishTime); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 125 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 126 | NS_LOG_INFO ("Run Simulation."); |
| 127 | Simulator::Run (); |
| 128 | Simulator::Destroy (); |
| 129 | NS_LOG_INFO ("Done!"); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 130 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 131 | return 0; |
Alexander Afanasyev | 3ba44e5 | 2011-11-10 16:38:10 -0800 | [diff] [blame] | 132 | } |