blob: 29772f72da7f31685023048fe0044ab23e82ed70 [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
Alexander Afanasyev59314802012-11-26 14:56:04 -080027using namespace ns3;
28
29/**
30 * This scenario simulates a tree topology (using topology reader module)
31 *
32 * /------\ /------\ /------\ /------\
33 * |leaf-1| |leaf-2| |leaf-3| |leaf-4|
34 * \------/ \------/ \------/ \------/
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080035 * ^ ^ ^ ^
Alexander Afanasyev59314802012-11-26 14:56:04 -080036 * | | | |
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080037 * \ / \ /
Alexander Afanasyev59314802012-11-26 14:56:04 -080038 * \ / \ / 10Mbps / 1ms
39 * \ / \ /
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080040 * | | | |
41 * v v v v
Alexander Afanasyev59314802012-11-26 14:56:04 -080042 * /-------\ /-------\
43 * | rtr-1 | | rtr-2 |
44 * \-------/ \-------/
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045 * ^ ^
Alexander Afanasyev59314802012-11-26 14:56:04 -080046 * | |
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047 * \ / 10 Mpbs / 1ms
48 * +--------+ +--------+
49 * | |
Alexander Afanasyev59314802012-11-26 14:56:04 -080050 * v v
51 * /--------\
52 * | root |
53 * \--------/
54 *
55 *
56 * To run scenario and see what is happening, use the following command:
57 *
58 * ./waf --run=ndn-tree-tracers
59 */
60
61int
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062main(int argc, char* argv[])
Alexander Afanasyev59314802012-11-26 14:56:04 -080063{
64 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 cmd.Parse(argc, argv);
Alexander Afanasyev59314802012-11-26 14:56:04 -080066
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067 AnnotatedTopologyReader topologyReader("", 1);
68 topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-tree.txt");
69 topologyReader.Read();
Alexander Afanasyev59314802012-11-26 14:56:04 -080070
71 // Install CCNx stack on all nodes
72 ndn::StackHelper ccnxHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080073 ccnxHelper.SetForwardingStrategy("ns3::ndn::fw::BestRoute");
74 ccnxHelper.InstallAll();
Alexander Afanasyev59314802012-11-26 14:56:04 -080075
76 // Installing global routing interface on all nodes
77 ndn::GlobalRoutingHelper ccnxGlobalRoutingHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080078 ccnxGlobalRoutingHelper.InstallAll();
Alexander Afanasyev59314802012-11-26 14:56:04 -080079
80 // Getting containers for the consumer/producer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081 Ptr<Node> consumers[4] = {Names::Find<Node>("leaf-1"), Names::Find<Node>("leaf-2"),
82 Names::Find<Node>("leaf-3"), Names::Find<Node>("leaf-4")};
83 Ptr<Node> producer = Names::Find<Node>("root");
Alexander Afanasyev59314802012-11-26 14:56:04 -080084
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080085 for (int i = 0; i < 4; i++) {
86 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
87 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
Alexander Afanasyev59314802012-11-26 14:56:04 -080088
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080089 // Each consumer will express unique interests /root/<leaf-name>/<seq-no>
90 consumerHelper.SetPrefix("/root/" + Names::FindName(consumers[i]));
91 consumerHelper.Install(consumers[i]);
92 }
93
94 ndn::AppHelper producerHelper("ns3::ndn::Producer");
95 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
Alexander Afanasyev59314802012-11-26 14:56:04 -080096
97 // Register /root prefix with global routing controller and
98 // install producer that will satisfy Interests in /root namespace
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080099 ccnxGlobalRoutingHelper.AddOrigins("/root", producer);
100 producerHelper.SetPrefix("/root");
101 producerHelper.Install(producer);
Alexander Afanasyev59314802012-11-26 14:56:04 -0800102
103 // Calculate and install FIBs
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800104 ccnxGlobalRoutingHelper.CalculateRoutes();
Alexander Afanasyev59314802012-11-26 14:56:04 -0800105
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800106 Simulator::Stop(Seconds(20.0));
Alexander Afanasyev59314802012-11-26 14:56:04 -0800107
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800108 ndn::L3AggregateTracer::InstallAll("aggregate-trace.txt", Seconds(0.5));
109 ndn::L3RateTracer::InstallAll("rate-trace.txt", Seconds(0.5));
110
111 Simulator::Run();
112 Simulator::Destroy();
Alexander Afanasyev59314802012-11-26 14:56:04 -0800113
114 return 0;
115}