blob: e60e9624be21ef275c2c2923893a9bcdeaf9b9a8 [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"
Alexander Afanasyev9d313d42011-11-25 13:36:15 -080027#include "ns3/netanim-module.h"
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070028
29#include <iostream>
30#include <sstream>
31
32using namespace ns3;
33
34NS_LOG_COMPONENT_DEFINE ("CcnxGrid");
35
Alexander Afanasyev176ed062011-11-15 23:49:22 -080036uint32_t nGrid = 3;
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080037Time finishTime = Seconds (20.0);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080038
39void PrintTime ()
40{
41 NS_LOG_INFO (Simulator::Now ());
42
43 Simulator::Schedule (Seconds (10.0), PrintTime);
44}
45
Alexander Afanasyev9d313d42011-11-25 13:36:15 -080046void PrintFIBs ()
47{
48 NS_LOG_INFO ("Outputing FIBs into [fibs.log]");
49 Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("fibs.log", std::ios::out);
50 for (NodeList::Iterator node = NodeList::Begin ();
51 node != NodeList::End ();
52 node++)
53 {
54 *routingStream->GetStream () << "Node " << (*node)->GetId () << "\n";
55
56 Ptr<CcnxFib> fib = (*node)->GetObject<CcnxFib> ();
57 NS_ASSERT_MSG (fib != 0, "Fire alarm");
58 *routingStream->GetStream () << *fib << "\n\n";
59 }
60}
61
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070062int
63main (int argc, char *argv[])
64{
Alexander Afanasyev176ed062011-11-15 23:49:22 -080065 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
66 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("1ms"));
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080067 Config::SetDefault ("ns3::CcnxConsumer::OffTime", StringValue ("1s"));
Ilya Moiseenko82b8eea2011-11-02 23:08:47 -070068
Alexander Afanasyev176ed062011-11-15 23:49:22 -080069 Packet::EnableChecking();
70 Packet::EnablePrinting();
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070071
Alexander Afanasyev9d313d42011-11-25 13:36:15 -080072 std::string animationFile = "";
Alexander Afanasyev176ed062011-11-15 23:49:22 -080073 CommandLine cmd;
74 cmd.AddValue ("nGrid", "Number of grid nodes", nGrid);
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080075 cmd.AddValue ("finish", "Finish time", finishTime);
Alexander Afanasyev9d313d42011-11-25 13:36:15 -080076 cmd.AddValue ("netanim", "NetAnim filename", animationFile);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080077 cmd.Parse (argc, argv);
Alexander Afanasyev9d313d42011-11-25 13:36:15 -080078
Alexander Afanasyev176ed062011-11-15 23:49:22 -080079 PointToPointHelper p2p;
80
81 InternetStackHelper stack;
82 Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
83 stack.SetRoutingHelper (ipv4RoutingHelper);
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070084
Alexander Afanasyev176ed062011-11-15 23:49:22 -080085 PointToPointGridHelper grid (nGrid, nGrid, p2p);
86 grid.BoundingBox(100,100,200,200);
87
88 // Install CCNx stack
89 NS_LOG_INFO ("Installing CCNx stack");
90 CcnxStackHelper ccnxHelper(Ccnx::NDN_FLOODING/*Ccnx::NDN_BESTROUTE*/);
91 ccnxHelper.InstallAll ();
92
93 // Install IP stack (necessary to populate FIB)
94 NS_LOG_INFO ("Installing IP stack");
95 grid.InstallStack (stack);
96 grid.AssignIpv4Addresses (
97 Ipv4AddressHelper("10.1.0.0", "255.255.255.0"),
98 Ipv4AddressHelper("10.2.0.0", "255.255.255.0")
99 );
100
101 Ptr<Node> producer = grid.GetNode (nGrid-1, nGrid-1);
102 NodeContainer consumerNodes;
103 consumerNodes.Add (grid.GetNode (0,0));
104
105 // Populate FIB based on IPv4 global routing controller
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800106 ccnxHelper.InstallFakeGlobalRoutes ();
107 ccnxHelper.InstallRouteTo (producer);
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800108
109 NS_LOG_INFO ("Installing Applications");
110 std::ostringstream prefix;
111 prefix << "/" << producer->GetId ();
112
113 CcnxConsumerHelper consumerHelper (prefix.str ());
114 ApplicationContainer consumers = consumerHelper.Install (consumerNodes);
115
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800116 // consumers.Start (Seconds (0.0));
117 // consumers.Stop (finishTime);
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700118
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800119 CcnxProducerHelper producerHelper (prefix.str (),120);
120 ApplicationContainer producers = producerHelper.Install (producer);
121
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800122 // producers.Start(Seconds(0.0));
123 // producers.Stop(finishTime);
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800124
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800125 Simulator::Schedule (Seconds (1.0), PrintFIBs);
126
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800127 Simulator::Schedule (Seconds (10.0), PrintTime);
128
129 // NS_LOG_INFO ("FIB dump:\n" << *c.Get(0)->GetObject<CcnxFib> ());
130 // NS_LOG_INFO ("FIB dump:\n" << *c.Get(1)->GetObject<CcnxFib> ());
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700131
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800132 Simulator::Stop (finishTime);
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800133
134 AnimationInterface *anim = 0;
135 if (animationFile != "")
136 {
137 anim = new AnimationInterface (animationFile);
138 anim->SetMobilityPollInterval (Seconds (1));
139 }
140
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800141 NS_LOG_INFO ("Run Simulation.");
142 Simulator::Run ();
143 Simulator::Destroy ();
144 NS_LOG_INFO ("Done!");
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800145
146 if (anim != 0)
147 delete anim;
148
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800149 return 0;
Alexander Afanasyev3ba44e52011-11-10 16:38:10 -0800150}