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