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(3); // Connecting nodes using two links PointToPointHelper p2p; p2p.Install(nodes.Get(0), nodes.Get(1)); p2p.Install(nodes.Get(1), nodes.Get(2)); // Install NDN stack on all nodes StackHelper ndnHelper; ndnHelper.InstallAll(); // Installing global routing interface on all nodes ndn::GlobalRoutingHelper ndnGlobalRoutingHelper; ndnGlobalRoutingHelper.InstallAll(); // Installing applications // Consumer ndn::AppHelper consumerHelper("PingClientApp"); consumerHelper.SetAttribute("Prefix", StringValue("/ping")); consumerHelper.SetAttribute("nPings", StringValue("3")); consumerHelper.Install(nodes.Get(0)).Start(Seconds(2)); // Producer ndn::AppHelper producerHelper("PingServerApp"); producerHelper.SetAttribute("Prefix", StringValue("/ping")); producerHelper.SetAttribute("nMaxPings", StringValue("3")); producerHelper.Install(nodes.Get(2)).Start(Seconds(0.1)); ndnGlobalRoutingHelper.AddOrigins("/ping", nodes.Get(2)); // Calculate and install FIBs ndn::GlobalRoutingHelper::CalculateRoutes(); Simulator::Stop(Seconds(20.0)); Simulator::Run(); Simulator::Destroy(); return 0; }
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(3); // Connecting nodes using two links PointToPointHelper p2p; p2p.Install(nodes.Get(0), nodes.Get(1)); p2p.Install(nodes.Get(1), nodes.Get(2)); // Install NDN stack on all nodes StackHelper ndnHelper; ndnHelper.SetDefaultRoutes(true); ndnHelper.InstallAll(); // Installing applications // Consumer auto consumer = CreateObject<ApiApp<PingClient>>(); nodes.Get(0)->AddApplication(consumer); // consumer->SetStopTime(Seconds(15.0)); auto producer = CreateObject<ApiApp<PingServer>>(); nodes.Get(2)->AddApplication(producer); // producer->SetStartTime(Seconds(0.5)); Simulator::Stop(Seconds(20.0)); Simulator::Run(); Simulator::Destroy(); return 0; }
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("10")); // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.Parse(argc, argv); // Creating 3x3 topology PointToPointHelper p2p; PointToPointGridHelper grid(3, 3, p2p); grid.BoundingBox(100, 100, 200, 200); // Install NDN stack on all nodes StackHelper ndnHelper; ndnHelper.InstallAll(); // Installing global routing interface on all nodes GlobalRoutingHelper ndnGlobalRoutingHelper; ndnGlobalRoutingHelper.InstallAll(); // Getting containers for the consumer/producer Ptr<Node> producer = grid.GetNode(2, 2); NodeContainer consumerNodes; consumerNodes.Add(grid.GetNode(0, 0)); // Install NDN applications std::string prefix = "/prefix"; // Install different forwarding strategies for (int row = 0; row < 3; row++) { for (int column = 0; column < 3; column++) { if (row < 2) StrategyChoiceHelper::Install(grid.GetNode(row, column), "/prefix", "/localhost/nfd/strategy/best-route"); else StrategyChoiceHelper::Install(grid.GetNode(row, column), "/prefix", "/localhost/nfd/strategy/multicast"); } } AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); consumerHelper.SetPrefix(prefix); consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second consumerHelper.Install(consumerNodes); AppHelper producerHelper("ns3::ndn::Producer"); producerHelper.SetPrefix(prefix); producerHelper.SetAttribute("PayloadSize", StringValue("1024")); producerHelper.Install(producer); // Add /prefix origins to ndn::GlobalRouter ndnGlobalRoutingHelper.AddOrigins(prefix, producer); // Calculate and install FIBs GlobalRoutingHelper::CalculateRoutes(); Simulator::Stop(Seconds(20.0)); Simulator::Run(); Simulator::Destroy(); return 0; }