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