blob: 8db76ce3e17eb43b6997a407efaff49361e5e42f [file] [log] [blame]
Spyridon Mastorakis77b63662014-11-25 19:22:51 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
4 *
5 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
7 *
8 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
20// ndn-load-balancer.cpp
21
22#include "ns3/core-module.h"
23#include "ns3/network-module.h"
24#include "ns3/ndnSIM-module.h"
25
26#include "ndn-load-balancer/random-load-balancer-strategy.hpp"
27
28using namespace ns3;
29
30/**
31 * This scenario simulates a load balancer topology (using topology reader module)
32 *
33 * ( ) ----- ( ) ---- (consumer)
34 * |
35 * ------ ( ) -----
36 * | |
37 * (producer) ---- (producer)
38 *
39 * All links are 1Mbps with propagation 10ms delay.
40 *
41 * FIB is populated using NdnGlobalRoutingHelper.
42 *
43 * Consumer requests data from the two producers with frequency 10 interests per
44 * second (interests contain constantly increasing sequence number).
45 *
46 * For every received interest, a load balancing operation is performed
47 * (based on a custom forwarding strategy) and the selected producer
48 * replies with a data packet, containing 1024 bytes of virtual payload.
49 *
50 * To run scenario and see what is happening, use the following command:
51 *
52 * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-load-balancer
53 */
54
55using ns3::ndn::StackHelper;
56using ns3::ndn::AppHelper;
57using ns3::ndn::GlobalRoutingHelper;
58using ns3::ndn::StrategyChoiceHelper;
59using ns3::AnnotatedTopologyReader;
60
61int
62main(int argc, char* argv[])
63{
64 CommandLine cmd;
65 cmd.Parse(argc, argv);
66
67 AnnotatedTopologyReader topologyReader("", 25);
68 topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-load-balancer.txt");
69 topologyReader.Read();
70
71 // Install NDN stack on all nodes
72 StackHelper ndnHelper;
73 ndnHelper.InstallAll();
74
75 // Installing global routing interface on all nodes
76 GlobalRoutingHelper ndnGlobalRoutingHelper;
77 ndnGlobalRoutingHelper.InstallAll();
78
79 // Getting containers for the consumer/producer
80 Ptr<Node> producer1 = Names::Find<Node>("UCLA-1");
81 Ptr<Node> producer2 = Names::Find<Node>("UCLA-2");
82 NodeContainer consumerNodes;
83 consumerNodes.Add(Names::Find<Node>("CSU-1"));
84
85 // Install NDN applications
86 std::string prefix = "/ucla/hello";
87
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080088 // Install random-load-balancer forwarding strategy in
89 // node UCLA-HUB
90 StrategyChoiceHelper::Install<nfd::fw::RandomLoadBalancerStrategy>(Names::Find<Node>("UCLA-HUB"),
91 prefix);
92
Spyridon Mastorakis77b63662014-11-25 19:22:51 -080093 AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
94 consumerHelper.SetPrefix(prefix);
95 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
96 consumerHelper.Install(consumerNodes);
97
98 AppHelper producerHelper("ns3::ndn::Producer");
99 producerHelper.SetPrefix(prefix);
100 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
101 producerHelper.Install(producer1);
102 producerHelper.Install(producer2);
103
Spyridon Mastorakis77b63662014-11-25 19:22:51 -0800104 // Add /prefix origins to ndn::GlobalRouter
105 ndnGlobalRoutingHelper.AddOrigins(prefix, producer1);
106 ndnGlobalRoutingHelper.AddOrigins(prefix, producer2);
107
108 // Calculate and install FIBs
109 GlobalRoutingHelper::CalculateRoutes();
110
111 Simulator::Stop(Seconds(1.0));
112
113 Simulator::Run();
114 Simulator::Destroy();
115
116 return 0;
117}