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" |
| 25 | #include <ns3/point-to-point-grid.h> |
| 26 | #include "ns3/ipv4-global-routing-helper.h" |
| 27 | |
| 28 | #include <iostream> |
| 29 | #include <sstream> |
| 30 | |
Alexander Afanasyev | 3ba44e5 | 2011-11-10 16:38:10 -0800 | [diff] [blame^] | 31 | // #include "ns3/visualizer-module.h" |
Ilya Moiseenko | 82b8eea | 2011-11-02 23:08:47 -0700 | [diff] [blame] | 32 | #include "ns3/ccnx.h" |
| 33 | |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 34 | using namespace ns3; |
| 35 | |
| 36 | NS_LOG_COMPONENT_DEFINE ("CcnxGrid"); |
| 37 | |
| 38 | int |
| 39 | main (int argc, char *argv[]) |
| 40 | { |
Alexander Afanasyev | 3ba44e5 | 2011-11-10 16:38:10 -0800 | [diff] [blame^] | 41 | // GlobalValue::Bind ("SimulatorImplementationType", StringValue |
| 42 | // ("ns3::VisualSimulatorImpl")); |
Ilya Moiseenko | 82b8eea | 2011-11-02 23:08:47 -0700 | [diff] [blame] | 43 | |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 44 | uint32_t n = 3; |
| 45 | |
Ilya Moiseenko | 82b8eea | 2011-11-02 23:08:47 -0700 | [diff] [blame] | 46 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps")); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 47 | Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("1ms")); |
| 48 | |
| 49 | Packet::EnableChecking(); |
| 50 | Packet::EnablePrinting(); |
| 51 | CommandLine cmd; |
| 52 | cmd.Parse (argc, argv); |
| 53 | |
| 54 | PointToPointHelper p2p; |
| 55 | InternetStackHelper stack; |
| 56 | |
| 57 | Ipv4GlobalRoutingHelper ipv4RoutingHelper; |
| 58 | // Ptr<Ipv4RoutingHelper> ipv4RoutingHelper = stack.GetRoutingHelper (); |
| 59 | stack.SetRoutingHelper (ipv4RoutingHelper); |
| 60 | |
| 61 | PointToPointGridHelper grid (n, n, p2p); |
Ilya Moiseenko | 82b8eea | 2011-11-02 23:08:47 -0700 | [diff] [blame] | 62 | grid.BoundingBox(100,100,200,200); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 63 | grid.InstallStack (stack); |
| 64 | |
| 65 | // // Create router nodes, initialize routing database and set up the routing |
| 66 | // // tables in the nodes. |
| 67 | Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
| 68 | |
| 69 | grid.AssignIpv4Addresses ( |
| 70 | Ipv4AddressHelper("10.1.0.0", "255.255.255.0"), |
| 71 | Ipv4AddressHelper("10.2.0.0", "255.255.255.0") |
| 72 | ); |
| 73 | |
| 74 | NS_LOG_INFO ("Installing NDN stack"); |
| 75 | NodeContainer c; |
| 76 | |
| 77 | for(uint32_t i=0; i<n; i++) |
| 78 | { |
| 79 | for(uint32_t j=0; j<n; j++) |
| 80 | { |
| 81 | NS_LOG_INFO ("Adding node i="<<i << " j=" << j); |
| 82 | c.Add(grid.GetNode(i,j)); |
| 83 | |
| 84 | int nodeCount = i*n+j+1; |
| 85 | std::stringstream ss; |
| 86 | ss<<nodeCount; |
| 87 | Names::Add (ss.str(), c.Get (c.GetN()-1)); |
| 88 | NS_LOG_INFO("Eventual name is " << ss.str()); |
| 89 | } |
| 90 | } |
Ilya Moiseenko | 82b8eea | 2011-11-02 23:08:47 -0700 | [diff] [blame] | 91 | CcnxStackHelper ccnx(Ccnx::NDN_BESTROUTE); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 92 | Ptr<CcnxFaceContainer> cf = ccnx.Install (c); |
| 93 | |
| 94 | NS_LOG_INFO ("Installing Applications"); |
| 95 | CcnxConsumerHelper helper ("/3"); |
Ilya Moiseenko | 82b8eea | 2011-11-02 23:08:47 -0700 | [diff] [blame] | 96 | ApplicationContainer app = helper.Install (grid.GetNode (0,0)); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 97 | app.Start (Seconds (1.0)); |
Ilya Moiseenko | 82b8eea | 2011-11-02 23:08:47 -0700 | [diff] [blame] | 98 | app.Stop (Seconds (1000.05)); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 99 | |
| 100 | CcnxProducerHelper helper2 ("/3",120); |
Ilya Moiseenko | 82b8eea | 2011-11-02 23:08:47 -0700 | [diff] [blame] | 101 | ApplicationContainer app2 = helper2.Install(grid.GetNode (2,2)); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 102 | app2.Start(Seconds(0.0)); |
Ilya Moiseenko | 82b8eea | 2011-11-02 23:08:47 -0700 | [diff] [blame] | 103 | app2.Stop(Seconds(1500.0)); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * \brief Add forwarding entry in FIB |
| 107 | * |
| 108 | * \param node Node |
| 109 | * \param prefix Routing prefix |
| 110 | * \param face Face index |
| 111 | * \param metric Routing metric |
| 112 | */ |
| 113 | |
| 114 | //2x2 works |
| 115 | /*ccnx.AddRoute ("1", "/3", 0, 1); |
| 116 | ccnx.AddRoute ("1", "/3", 1, 1); |
| 117 | |
| 118 | ccnx.AddRoute ("2", "/3", 1, 1); |
| 119 | ccnx.AddRoute ("3", "/3", 1, 1); |
| 120 | */ |
| 121 | |
| 122 | //3x3 |
| 123 | |
| 124 | ccnx.AddRoute ("1", "/3", 0, 1); |
| 125 | ccnx.AddRoute ("1", "/3", 1, 1); |
| 126 | |
| 127 | ccnx.AddRoute ("2", "/3", 1, 1); |
| 128 | |
| 129 | ccnx.AddRoute ("3", "/3", 1, 1); |
| 130 | |
| 131 | ccnx.AddRoute ("4", "/3", 2, 1); |
| 132 | |
| 133 | ccnx.AddRoute ("6", "/3", 2, 1); |
| 134 | |
| 135 | ccnx.AddRoute ("7", "/3", 1, 1); |
| 136 | |
| 137 | ccnx.AddRoute ("8", "/3", 1, 1); |
| 138 | |
| 139 | |
| 140 | NS_LOG_INFO ("FIB dump:\n" << *c.Get(0)->GetObject<CcnxFib> ()); |
| 141 | NS_LOG_INFO ("FIB dump:\n" << *c.Get(1)->GetObject<CcnxFib> ()); |
| 142 | |
| 143 | |
| 144 | |
Ilya Moiseenko | 82b8eea | 2011-11-02 23:08:47 -0700 | [diff] [blame] | 145 | Simulator::Stop (Seconds (2000)); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 146 | |
| 147 | NS_LOG_INFO ("Run Simulation."); |
| 148 | Simulator::Run (); |
| 149 | Simulator::Destroy (); |
| 150 | NS_LOG_INFO ("Done."); |
| 151 | |
| 152 | return 0; |
| 153 | |
Alexander Afanasyev | 3ba44e5 | 2011-11-10 16:38:10 -0800 | [diff] [blame^] | 154 | } |