blob: 46ea7408a258cebfb296a7153ee04c0a4ca4e0eb [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
88 AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
89 consumerHelper.SetPrefix(prefix);
90 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
91 consumerHelper.Install(consumerNodes);
92
93 AppHelper producerHelper("ns3::ndn::Producer");
94 producerHelper.SetPrefix(prefix);
95 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
96 producerHelper.Install(producer1);
97 producerHelper.Install(producer2);
98
99 // Install random-load-balancer forwarding strategy in
100 // node UCLA-HUB
101 StrategyChoiceHelper strategyChoiceHelper;
102 strategyChoiceHelper.Install<nfd::fw::RandomLoadBalancerStrategy>(Names::Find<Node>("UCLA-HUB"),
103 prefix);
104
105 // Add /prefix origins to ndn::GlobalRouter
106 ndnGlobalRoutingHelper.AddOrigins(prefix, producer1);
107 ndnGlobalRoutingHelper.AddOrigins(prefix, producer2);
108
109 // Calculate and install FIBs
110 GlobalRoutingHelper::CalculateRoutes();
111
112 Simulator::Stop(Seconds(1.0));
113
114 Simulator::Run();
115 Simulator::Destroy();
116
117 return 0;
118}