[Ndn-interest] Replacing virtual payload into realtime file transmission
Arif Hussain Magsi
ahmagsi at sau.edu.pk
Mon Dec 4 00:54:02 PST 2023
Dear all,
I am trying to replace and exchange a virtual payload to a real-time file in a simple ndnSIM scenario. Following is my code, where a consumer requests a CSV file and the producer responds with the required payload from the example directory. However, I faced an error in it. Can anyone help me in this connection, please?
Code:
/#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/ndnSIM-module.h"
#include <fstream>
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<Packet>::MaxSize", StringValue("20p"));
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
ndn::StackHelper ndnHelper;
ndnHelper.SetDefaultRoutes(true);
ndnHelper.InstallAll();
// Choosing forwarding strategy
ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/multicast");
// Installing applications
// Consumer
ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
// Consumer will request /reputation.csv
consumerHelper.SetPrefix("/reputation.csv");
consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second
auto apps = consumerHelper.Install(nodes.Get(0)); // first node
apps.Stop(Seconds(10.0)); // stop the consumer app at 10 seconds mark
// Producer
ndn::AppHelper producerHelper("ns3::ndn::Producer");
// Producer will reply to requests for /reputation.csv
producerHelper.SetPrefix("/reputation.csv");
// Read reputation.csv from local storage
std::ifstream inputFile("ndnSIM/ns-3/src/ndnSIM/examples/reputation.csv");
std::string fileContent((std::istreambuf_iterator<char>(inputFile)),
std::istreambuf_iterator<char>());
producerHelper.SetAttribute("Payload", StringValue(fileContent));
producerHelper.Install(nodes.Get(2)); // last node
Simulator::Stop(Seconds(20.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
} // namespace ns3
int
main(int argc, char* argv[])
{
return ns3::main(argc, argv);
BR,
Magsi, Arif Hussain
____________________
ahmagsi at sau.edu.pk
Whatsapp. +92-302-3483433
Wechat. +86-15600225390
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/ndn-interest/attachments/20231204/f7f26eb0/attachment.html>
More information about the Ndn-interest
mailing list