|
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
/**
|
|
* Copyright (c) 2011-2015 Regents of the University of California.
|
|
*
|
|
* This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
|
|
* contributors.
|
|
*
|
|
* ndnSIM is free software: you can redistribute it and/or modify it under the terms
|
|
* of the GNU General Public License as published by the Free Software Foundation,
|
|
* either version 3 of the License, or (at your option) any later version.
|
|
*
|
|
* ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
|
**/
|
|
|
|
// ndn-simple.cpp
|
|
|
|
#include "ns3/core-module.h"
|
|
#include "ns3/network-module.h"
|
|
#include "ns3/point-to-point-module.h"
|
|
#include "ns3/ndnSIM-module.h"
|
|
|
|
namespace ns3 {
|
|
|
|
|
|
int
|
|
main(int argc, char* argv[])
|
|
{
|
|
// setting default parameters for PointToPoint links and channels
|
|
Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
|
|
Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
|
|
Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
|
|
|
|
// Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
|
|
CommandLine cmd;
|
|
cmd.Parse(argc, argv);
|
|
|
|
// Creating nodes
|
|
NodeContainer nodes;
|
|
nodes.Create(13);
|
|
|
|
// Connecting nodes using two links
|
|
PointToPointHelper p2p;
|
|
p2p.Install(nodes.Get(0), nodes.Get(1));
|
|
p2p.Install(nodes.Get(1), nodes.Get(2));
|
|
p2p.Install(nodes.Get(1), nodes.Get(3));
|
|
p2p.Install(nodes.Get(1), nodes.Get(4));
|
|
p2p.Install(nodes.Get(1), nodes.Get(5));
|
|
p2p.Install(nodes.Get(1), nodes.Get(6));
|
|
p2p.Install(nodes.Get(1), nodes.Get(7));
|
|
p2p.Install(nodes.Get(1), nodes.Get(8));
|
|
p2p.Install(nodes.Get(1), nodes.Get(9));
|
|
p2p.Install(nodes.Get(0), nodes.Get(12));
|
|
p2p.Install(nodes.Get(0), nodes.Get(11));
|
|
|
|
// Install NDN stack on all nodes
|
|
ndn::StackHelper ndnHelper;
|
|
ndnHelper.SetDefaultRoutes(true);
|
|
ndnHelper.InstallAll();
|
|
|
|
// Choosing forwarding strategy
|
|
ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/best-route");
|
|
|
|
// Installing global routing interface on all nodes
|
|
ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
|
|
ndnGlobalRoutingHelper.InstallAll();
|
|
|
|
// Installing applications
|
|
|
|
// Consumer
|
|
ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
|
|
// Consumer will request /prefix/0, /prefix/1, ...
|
|
consumerHelper.SetPrefix("/prefix");
|
|
consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second
|
|
consumerHelper.Install(nodes.Get(0)); // first node
|
|
|
|
// Producer
|
|
ndn::AppHelper producerHelper("ns3::ndn::Producer");
|
|
// Producer will reply to all requests starting with /prefix
|
|
producerHelper.SetPrefix("/prefix");
|
|
producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
|
|
producerHelper.Install(nodes.Get(2)); // last node
|
|
|
|
// Add /prefix origins to ndn::GlobalRouter
|
|
ndnGlobalRoutingHelper.AddOrigins("/prefix", nodes.Get(2));
|
|
|
|
// Calculate and install FIBs
|
|
ndn::GlobalRoutingHelper::CalculateAllPossibleRoutes();
|
|
//ndn::GlobalRoutingHelper::CalculateRoutes();
|
|
|
|
Simulator::Stop(Seconds(20.0));
|
|
|
|
Simulator::Run();
|
|
Simulator::Destroy();
|
|
|
|
return 0;
|
|
}
|
|
|
|
} // namespace ns3
|
|
|
|
int
|
|
main(int argc, char* argv[])
|
|
{
|
|
return ns3::main(argc, argv);
|
|
}
|