blob: acf4a5f04d15427362cb84c287be5d5ab29e9702 [file] [log] [blame]
Ilya Moiseenkoc9266042011-11-02 17:49:21 -07001/* -*- 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 Afanasyev176ed062011-11-15 23:49:22 -080025#include "ns3/point-to-point-grid.h"
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070026#include "ns3/ipv4-global-routing-helper.h"
27
28#include <iostream>
29#include <sstream>
30
31using namespace ns3;
32
33NS_LOG_COMPONENT_DEFINE ("CcnxGrid");
34
Alexander Afanasyev176ed062011-11-15 23:49:22 -080035uint32_t nGrid = 3;
36
37void PrintTime ()
38{
39 NS_LOG_INFO (Simulator::Now ());
40
41 Simulator::Schedule (Seconds (10.0), PrintTime);
42}
43
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070044int
45main (int argc, char *argv[])
46{
Alexander Afanasyev176ed062011-11-15 23:49:22 -080047 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
48 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("1ms"));
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -080049 Config::SetDefault ("ns3::CcnxConsumer::OffTime", StringValue ("100ms"));
Ilya Moiseenko82b8eea2011-11-02 23:08:47 -070050
Alexander Afanasyev176ed062011-11-15 23:49:22 -080051 Packet::EnableChecking();
52 Packet::EnablePrinting();
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070053
Alexander Afanasyev176ed062011-11-15 23:49:22 -080054 CommandLine cmd;
55 cmd.AddValue ("nGrid", "Number of grid nodes", nGrid);
56 cmd.Parse (argc, argv);
57
58 PointToPointHelper p2p;
59
60 InternetStackHelper stack;
61 Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
62 stack.SetRoutingHelper (ipv4RoutingHelper);
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070063
Alexander Afanasyev176ed062011-11-15 23:49:22 -080064 PointToPointGridHelper grid (nGrid, nGrid, p2p);
65 grid.BoundingBox(100,100,200,200);
66
67 // Install CCNx stack
68 NS_LOG_INFO ("Installing CCNx stack");
69 CcnxStackHelper ccnxHelper(Ccnx::NDN_FLOODING/*Ccnx::NDN_BESTROUTE*/);
70 ccnxHelper.InstallAll ();
71
72 // Install IP stack (necessary to populate FIB)
73 NS_LOG_INFO ("Installing IP stack");
74 grid.InstallStack (stack);
75 grid.AssignIpv4Addresses (
76 Ipv4AddressHelper("10.1.0.0", "255.255.255.0"),
77 Ipv4AddressHelper("10.2.0.0", "255.255.255.0")
78 );
79
80 Ptr<Node> producer = grid.GetNode (nGrid-1, nGrid-1);
81 NodeContainer consumerNodes;
82 consumerNodes.Add (grid.GetNode (0,0));
83
84 // Populate FIB based on IPv4 global routing controller
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -080085 // ccnxHelper.InstallFakeGlobalRoutes ();
86 // ccnxHelper.InstallRouteTo (producer);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080087
88 NS_LOG_INFO ("Installing Applications");
89 std::ostringstream prefix;
90 prefix << "/" << producer->GetId ();
91
92 CcnxConsumerHelper consumerHelper (prefix.str ());
93 ApplicationContainer consumers = consumerHelper.Install (consumerNodes);
94
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -080095 consumers.Start (Seconds (0.0));
96 consumers.Stop (Seconds (20.0));
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070097
Alexander Afanasyev176ed062011-11-15 23:49:22 -080098 CcnxProducerHelper producerHelper (prefix.str (),120);
99 ApplicationContainer producers = producerHelper.Install (producer);
100
101 producers.Start(Seconds(0.0));
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -0800102 producers.Stop(Seconds(20.0));
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800103
104 NS_LOG_INFO ("Outputing FIBs into [fibs.log]");
105 Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("fibs.log", std::ios::out);
106 for (NodeList::Iterator node = NodeList::Begin ();
107 node != NodeList::End ();
108 node++)
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700109 {
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800110 *routingStream->GetStream () << "Node " << (*node)->GetId () << "\n";
111
112 Ptr<CcnxFib> fib = (*node)->GetObject<CcnxFib> ();
113 NS_ASSERT_MSG (fib != 0, "Fire alarm");
114 *routingStream->GetStream () << *fib << "\n\n";
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700115 }
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700116
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800117 Simulator::Schedule (Seconds (10.0), PrintTime);
118
119 // NS_LOG_INFO ("FIB dump:\n" << *c.Get(0)->GetObject<CcnxFib> ());
120 // NS_LOG_INFO ("FIB dump:\n" << *c.Get(1)->GetObject<CcnxFib> ());
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700121
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -0800122 Simulator::Stop (Seconds (100));
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700123
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800124 NS_LOG_INFO ("Run Simulation.");
125 Simulator::Run ();
126 Simulator::Destroy ();
127 NS_LOG_INFO ("Done!");
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700128
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800129 return 0;
Alexander Afanasyev3ba44e52011-11-10 16:38:10 -0800130}