blob: f5e9a5ec4c36063a38d6b12c4c7763f6c2e8fe13 [file] [log] [blame]
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -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// ndn-congestion-topo-plugin.cc
21#include "ns3/core-module.h"
22#include "ns3/network-module.h"
23#include "ns3/ndnSIM-module.h"
24
25using namespace ns3;
26
27/**
28 * This scenario simulates a grid topology (using topology reader module)
29 *
30 * /------\ /------\
31 * | Src1 |<--+ +-->| Dst1 |
32 * \------/ \ / \------/
33 * \ /
34 * +-->/------\ "bottleneck" /------\<-+
35 * | Rtr1 |<===============>| Rtr2 |
36 * +-->\------/ \------/<-+
37 * / \
38 * /------\ / \ /------\
39 * | Src2 |<--+ +-->| Dst2 |
40 * \------/ \------/
41 *
42 * To run scenario and see what is happening, use the following command:
43 *
44 * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-topo-plugin
45 */
46
47int
48main (int argc, char *argv[])
49{
50 CommandLine cmd;
51 cmd.Parse (argc, argv);
52
53 AnnotatedTopologyReader topologyReader ("", 25);
54 topologyReader.SetFileName ("src/ndnSIM/examples/topology/topo-grid-3x3.txt");
55 topologyReader.Read ();
56
57 // Install CCNx stack on all nodes
58 ndn::StackHelper ccnxHelper;
59 ccnxHelper.InstallAll ();
60
61 // Installing global routing interface on all nodes
62 ndn::GlobalRoutingHelper ccnxGlobalRoutingHelper;
63 ccnxGlobalRoutingHelper.InstallAll ();
64
65 // Getting containers for the consumer/producer
66 Ptr<Node> consumer1 = Names::Find<Node> ("Src1");
67 Ptr<Node> consumer2 = Names::Find<Node> ("Src2");
68
69 Ptr<Node> producer1 = Names::Find<Node> ("Dst1");
70 Ptr<Node> producer2 = Names::Find<Node> ("Dst2");
71
72 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
73 consumerHelper.SetAttribute ("Frequency", StringValue ("100")); // 100 interests a second
74
75 // on the first consumer node install a Consumer application
76 // that will express interests in /dst1 namespace
77 consumerHelper.SetPrefix ("/dst1");
78 consumerHelper.Install (consumer1);
79
80 // on the second consumer node install a Consumer application
81 // that will express interests in /dst2 namespace
82 consumerHelper.SetPrefix ("/dst2");
83 consumerHelper.Install (consumer2);
84
85 ndn::AppHelper producerHelper ("ns3::ndn::Producer");
86 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
87
88 // Register /dst1 prefix with global routing controller and
89 // install producer that will satisfy Interests in /dst1 namespace
90 ccnxGlobalRoutingHelper.AddOrigins ("/dst1", producer1);
91 producerHelper.SetPrefix ("/dst1");
92 producerHelper.Install (producer1);
93
94 // Register /dst2 prefix with global routing controller and
95 // install producer that will satisfy Interests in /dst2 namespace
96 ccnxGlobalRoutingHelper.AddOrigins ("/dst2", producer2);
97 producerHelper.SetPrefix ("/dst2");
98 producerHelper.Install (producer2);
99
100 // Calculate and install FIBs
101 ccnxGlobalRoutingHelper.CalculateRoutes ();
102
103 Simulator::Stop (Seconds (20.0));
104
105 Simulator::Run ();
106 Simulator::Destroy ();
107
108 return 0;
109}