blob: 496b9d573ce4a5427bfa28d2762a31652677de14 [file] [log] [blame]
Alexander Afanasyevf4a03592012-12-10 16:12:34 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011-2012 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 */
20
21// ndn-tree-cs-tracers.cc
22
23#include "ns3/core-module.h"
24#include "ns3/network-module.h"
25#include "ns3/ndnSIM-module.h"
26
Alexander Afanasyevb1d6b032013-01-18 14:11:11 -080027// for ndn::CsTracer
28#include <ns3/ndnSIM/utils/tracers/ndn-cs-tracer.h>
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080029
30using namespace ns3;
31
32/**
33 * This scenario simulates a tree topology (using topology reader module)
34 *
35 * /------\ /------\ /------\ /------\
36 * |leaf-1| |leaf-2| |leaf-3| |leaf-4|
37 * \------/ \------/ \------/ \------/
38 * ^ ^ ^ ^
39 * | | | |
40 * \ / \ /
41 * \ / \ / 10Mbps / 1ms
42 * \ / \ /
43 * | | | |
44 * v v v v
45 * /-------\ /-------\
46 * | rtr-1 | | rtr-2 |
47 * \-------/ \-------/
48 * ^ ^
49 * | |
50 * \ / 10 Mpbs / 1ms
51 * +--------+ +--------+
52 * | |
53 * v v
54 * /--------\
55 * | root |
56 * \--------/
57 *
58 *
59 * To run scenario and see what is happening, use the following command:
60 *
61 * ./waf --run=ndn-tree-cs-tracers
62 */
63
64int
65main (int argc, char *argv[])
66{
67 CommandLine cmd;
68 cmd.Parse (argc, argv);
69
70 AnnotatedTopologyReader topologyReader ("", 1);
71 topologyReader.SetFileName ("src/ndnSIM/examples/topologies/topo-tree.txt");
72 topologyReader.Read ();
73
74 // Install CCNx stack on all nodes
75 ndn::StackHelper ndnHelper;
76 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::BestRoute");
77 ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Lru", "MaxSize", "100"); // default ContentStore parameters
78 ndnHelper.InstallAll ();
79
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080080 // Installing global routing interface on all nodes
81 ndn::GlobalRoutingHelper ccnxGlobalRoutingHelper;
82 ccnxGlobalRoutingHelper.InstallAll ();
83
84 // Getting containers for the consumer/producer
85 Ptr<Node> consumers[4] = { Names::Find<Node> ("leaf-1"), Names::Find<Node> ("leaf-2"),
86 Names::Find<Node> ("leaf-3"), Names::Find<Node> ("leaf-4") };
87 Ptr<Node> producer = Names::Find<Node> ("root");
88
89 for (int i = 0; i < 4; i++)
90 {
91 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
92 consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 100 interests a second
93
94 // Each consumer will express the same data /root/<seq-no>
95 consumerHelper.SetPrefix ("/root");
96 ApplicationContainer app = consumerHelper.Install (consumers[i]);
97 app.Start (Seconds (0.01 * i));
98 }
99
100 ndn::AppHelper producerHelper ("ns3::ndn::Producer");
101 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
102
103 // Register /root prefix with global routing controller and
104 // install producer that will satisfy Interests in /root namespace
105 ccnxGlobalRoutingHelper.AddOrigins ("/root", producer);
106 producerHelper.SetPrefix ("/root");
107 producerHelper.Install (producer);
108
109 // Calculate and install FIBs
110 ccnxGlobalRoutingHelper.CalculateRoutes ();
111
112 Simulator::Stop (Seconds (20.0));
113
Alexander Afanasyevb1d6b032013-01-18 14:11:11 -0800114 boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<ndn::CsTracer> > >
115 aggTracers = ndn::CsTracer::InstallAll ("cs-trace.txt", Seconds (1));
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800116
117 Simulator::Run ();
118 Simulator::Destroy ();
119
120 return 0;
121}