blob: b76869ace5cf7d48a9026aa82c4684f6899beec8 [file] [log] [blame]
Alexander Afanasyev59314802012-11-26 14:56:04 -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-tracers.cc
22
23#include "ns3/core-module.h"
24#include "ns3/network-module.h"
25#include "ns3/ndnSIM-module.h"
26
27// for ndn::L3AggregateTracer
28#include <ns3/ndnSIM/utils/tracers/ndn-l3-aggregate-tracer.h>
29
30// for ndn::L3RateTracer
31#include <ns3/ndnSIM/utils/tracers/ndn-l3-rate-tracer.h>
32
33using namespace ns3;
34
35/**
36 * This scenario simulates a tree topology (using topology reader module)
37 *
38 * /------\ /------\ /------\ /------\
39 * |leaf-1| |leaf-2| |leaf-3| |leaf-4|
40 * \------/ \------/ \------/ \------/
41 * ^ ^ ^ ^
42 * | | | |
43 * \ / \ /
44 * \ / \ / 10Mbps / 1ms
45 * \ / \ /
46 * | | | |
47 * v v v v
48 * /-------\ /-------\
49 * | rtr-1 | | rtr-2 |
50 * \-------/ \-------/
51 * ^ ^
52 * | |
53 * \ / 10 Mpbs / 1ms
54 * +--------+ +--------+
55 * | |
56 * v v
57 * /--------\
58 * | root |
59 * \--------/
60 *
61 *
62 * To run scenario and see what is happening, use the following command:
63 *
64 * ./waf --run=ndn-tree-tracers
65 */
66
67int
68main (int argc, char *argv[])
69{
70 CommandLine cmd;
71 cmd.Parse (argc, argv);
72
73 AnnotatedTopologyReader topologyReader ("", 1);
74 topologyReader.SetFileName ("src/ndnSIM/examples/topologies/topo-tree.txt");
75 topologyReader.Read ();
76
77 // Install CCNx stack on all nodes
78 ndn::StackHelper ccnxHelper;
79 ccnxHelper.SetForwardingStrategy ("ns3::ndn::fw::BestRoute");
80 ccnxHelper.InstallAll ();
81
82 // Installing global routing interface on all nodes
83 ndn::GlobalRoutingHelper ccnxGlobalRoutingHelper;
84 ccnxGlobalRoutingHelper.InstallAll ();
85
86 // Getting containers for the consumer/producer
87 Ptr<Node> consumers[4] = { Names::Find<Node> ("leaf-1"), Names::Find<Node> ("leaf-2"),
88 Names::Find<Node> ("leaf-3"), Names::Find<Node> ("leaf-4") };
89 Ptr<Node> producer = Names::Find<Node> ("root");
90
91 for (int i = 0; i < 4; i++)
92 {
93 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
94 consumerHelper.SetAttribute ("Frequency", StringValue ("100")); // 100 interests a second
95
96 // Each consumer will express unique interests /root/<leaf-name>/<seq-no>
97 consumerHelper.SetPrefix ("/root/" + Names::FindName (consumers[i]));
98 consumerHelper.Install (consumers[i]);
99 }
100
101 ndn::AppHelper producerHelper ("ns3::ndn::Producer");
102 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
103
104 // Register /root prefix with global routing controller and
105 // install producer that will satisfy Interests in /root namespace
106 ccnxGlobalRoutingHelper.AddOrigins ("/root", producer);
107 producerHelper.SetPrefix ("/root");
108 producerHelper.Install (producer);
109
110 // Calculate and install FIBs
111 ccnxGlobalRoutingHelper.CalculateRoutes ();
112
113 Simulator::Stop (Seconds (20.0));
114
115 boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<ndn::L3AggregateTracer> > >
116 aggTracers = ndn::L3AggregateTracer::InstallAll ("aggregate-trace.txt", Seconds (0.5));
117
118 boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<ndn::L3RateTracer> > >
119 rateTracers = ndn::L3RateTracer::InstallAll ("rate-trace.txt", Seconds (0.5));
120
121 Simulator::Run ();
122 Simulator::Destroy ();
123
124 return 0;
125}