[ndnSIM] Error linking N nodes in a loop using PointToPointHelprer

Ali Barma muhammadfb90 at gmail.com
Mon May 4 22:27:34 PDT 2020


Hi, please can you help solve my issue. The goal of my project is to create
a simple intelligent (with reinforcement learning) cache placement strategy
but for now i was trying to create a dynamic tree topology where i receive
the number of levels and children then further calculate the total number
of nodes, so i get problem when i try to link all the nodes in a loop with
PointTointHelper.
Please i really need someone to help as this is my final year project
thanks.

/*
 * projetFinal.cpp
 *
 *  Created on: Apr 25, 2020
 *      Author: elbee
 */
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/ndnSIM-module.h"
#include "ns3/csma-module.h"


using namespace std;

namespace ns3 {



int main(int argc, char* argv[])
{
Config::SetDefault("ns3::PointToPointNetDevice::DataRate",
StringValue("1Mbps"));
 Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
 Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));


 CommandLine cmd;
 cmd.Parse(argc, argv);

        string mon_fichier ="src/ndnSIM/examples/Configuration.txt";
// on ouvre le fichier en lecture
        int nbr_Nodes = 0, levels, children;
ifstream file(mon_fichier.c_str(), ios::in);
if (file){
file  >> levels >> children ;
                cout << levels << endl;
                cout << children << endl;
file.close();}
else {
cerr << "Can't open file !" << endl;
return 0;
}

int pow=1;
for (int i = 0; i <levels +1; i++){
pow *= children;
}
nbr_Nodes +=  (pow - 1 / (children -1));
cout << nbr_Nodes << endl;

NodeContainer nodes;
nodes.Create(nbr_Nodes);

PointToPointHelper p2p;
   //linking nodes to form a binary tree
for(int i = 0; i < nbr_Nodes; i++){
if(i == 0){
p2p.Install(nodes.Get(0), nodes.Get(1));
p2p.Install(nodes.Get(0), nodes.Get(2));

}
p2p.Install(nodes.Get(i), nodes.Get(2*i));
p2p.Install(nodes.Get(i), nodes.Get(2* i +1));
}

 ndn::StackHelper ndnHelper;
 ndnHelper.SetDefaultRoutes(true);
 ndnHelper.InstallAll();

 ndn::StrategyChoiceHelper::InstallAll("/prefix",
"/localhost/nfd/strategy/multicast");

   for (uint32_t i = 0; i != nbr_Nodes; ++i){
    ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
     consumerHelper.SetPrefix("/prefix");
     consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10
interests a second
     consumerHelper.Install(nodes.Get(i));
   }

   ndn::AppHelper producerHelper("ns3::ndn::Producer");
   producerHelper.SetPrefix("/prefix");
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
  producerHelper.Install(nodes.Get(0));



Simulator::Stop(Seconds(20.0));
Simulator::Run();
Simulator::Destroy();


    return 0;
}
} // namespace ns3

int
main(int argc, char* argv[])
{
  return ns3::main(argc, argv);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/ndnsim/attachments/20200505/8ed0dd5d/attachment.html>


More information about the ndnSIM mailing list