blob: 28a021bdf7242e80d9e814fc426949603414dfdd [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"));
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -080066 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080067 Config::SetDefault ("ns3::CcnxConsumer::OffTime", StringValue ("1s"));
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -080068 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
Ilya Moiseenko82b8eea2011-11-02 23:08:47 -070069
Alexander Afanasyev176ed062011-11-15 23:49:22 -080070 Packet::EnableChecking();
71 Packet::EnablePrinting();
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070072
Alexander Afanasyev9d313d42011-11-25 13:36:15 -080073 std::string animationFile = "";
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080074 std::string strategy = "ns3::CcnxFloodingStrategy";
75
Alexander Afanasyev176ed062011-11-15 23:49:22 -080076 CommandLine cmd;
77 cmd.AddValue ("nGrid", "Number of grid nodes", nGrid);
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080078 cmd.AddValue ("finish", "Finish time", finishTime);
Alexander Afanasyev9d313d42011-11-25 13:36:15 -080079 cmd.AddValue ("netanim", "NetAnim filename", animationFile);
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080080 cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080081 cmd.Parse (argc, argv);
82
83 PointToPointHelper p2p;
84
85 InternetStackHelper stack;
86 Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
87 stack.SetRoutingHelper (ipv4RoutingHelper);
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070088
Alexander Afanasyev176ed062011-11-15 23:49:22 -080089 PointToPointGridHelper grid (nGrid, nGrid, p2p);
90 grid.BoundingBox(100,100,200,200);
91
92 // Install CCNx stack
93 NS_LOG_INFO ("Installing CCNx stack");
Alexander Afanasyev11453142011-11-25 16:13:33 -080094 CcnxStackHelper ccnxHelper;
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080095 ccnxHelper.SetForwardingStrategy (strategy);
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -080096 ccnxHelper.EnableLimits (true, Seconds(0.1));
Alexander Afanasyev176ed062011-11-15 23:49:22 -080097 ccnxHelper.InstallAll ();
98
99 // Install IP stack (necessary to populate FIB)
100 NS_LOG_INFO ("Installing IP stack");
101 grid.InstallStack (stack);
102 grid.AssignIpv4Addresses (
103 Ipv4AddressHelper("10.1.0.0", "255.255.255.0"),
104 Ipv4AddressHelper("10.2.0.0", "255.255.255.0")
105 );
106
107 Ptr<Node> producer = grid.GetNode (nGrid-1, nGrid-1);
108 NodeContainer consumerNodes;
109 consumerNodes.Add (grid.GetNode (0,0));
110
111 // Populate FIB based on IPv4 global routing controller
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800112 ccnxHelper.InstallFakeGlobalRoutes ();
113 ccnxHelper.InstallRouteTo (producer);
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800114
115 NS_LOG_INFO ("Installing Applications");
116 std::ostringstream prefix;
117 prefix << "/" << producer->GetId ();
118
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800119 CcnxAppHelper consumerHelper ("ns3::CcnxConsumer");
120 consumerHelper.SetPrefix (prefix.str ());
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800121 ApplicationContainer consumers = consumerHelper.Install (consumerNodes);
122
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800123 // consumers.Start (Seconds (0.0));
124 // consumers.Stop (finishTime);
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700125
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800126 CcnxAppHelper producerHelper ("ns3::CcnxProducer");
127 producerHelper.SetPrefix (prefix.str ());
128 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800129 ApplicationContainer producers = producerHelper.Install (producer);
130
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800131 // producers.Start(Seconds(0.0));
132 // producers.Stop(finishTime);
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800133
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800134 Simulator::Schedule (Seconds (1.0), PrintFIBs);
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700135
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800136 Simulator::Schedule (Seconds (10.0), PrintTime);
137
138 // NS_LOG_INFO ("FIB dump:\n" << *c.Get(0)->GetObject<CcnxFib> ());
139 // NS_LOG_INFO ("FIB dump:\n" << *c.Get(1)->GetObject<CcnxFib> ());
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700140
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800141 Simulator::Stop (finishTime);
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700142
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800143 AnimationInterface *anim = 0;
144 if (animationFile != "")
145 {
146 anim = new AnimationInterface (animationFile);
147 anim->SetMobilityPollInterval (Seconds (1));
148 }
149
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800150 NS_LOG_INFO ("Run Simulation.");
151 Simulator::Run ();
152 Simulator::Destroy ();
153 NS_LOG_INFO ("Done!");
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700154
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800155 if (anim != 0)
156 delete anim;
157
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800158 return 0;
Alexander Afanasyev3ba44e52011-11-10 16:38:10 -0800159}