NDNSIM Mesh network simulation

133 views
Skip to first unread message

Nazmus Saqib

unread,
Apr 8, 2019, 3:55:55 AM4/8/19
to ns-3-users
#include <iostream>
#include <sstream>
#include <fstream>
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/internet-module.h"
#include "ns3/mesh-module.h"
#include "ns3/mesh-helper.h"
#include "ns3/ndnSIM-module.h"

using namespace std;
namespace ns3 {

NS_LOG_COMPONENT_DEFINE("ndn.WifiExample");

//void CourseChange (std::string context, Ptr<const MobilityModel> model)
//{
// Vector position = model->GetPosition ();
// Vector velocity = model->GetVelocity();
// NS_LOG_UNCOND (context << " x = " << position.x << ", y = " << position.y << ", velocityX = " << velocity.x << ", velocityY = " << velocity.y);
//}

//
// DISCLAIMER:  Note that this is an extremely simple example, containing just 2 wifi nodes
// communicating directly over AdHoc channel.
//

// Ptr<ndn::NetDeviceFace>
// MyNetDeviceFaceCallback (Ptr<Node> node, Ptr<ndn::L3Protocol> ndn, Ptr<NetDevice> device)
// {
//   // NS_LOG_DEBUG ("Create custom network device " << node->GetId ());
//   Ptr<ndn::NetDeviceFace> face = CreateObject<ndn::MyNetDeviceFace> (node, device);
//   ndn->AddFace (face);
//   return face;
// }

int
main(int argc, char* argv[])
{

  // disable fragmentation
  Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue("2200"));
  Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("2200"));
  Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode",
                     StringValue("OfdmRate24Mbps"));

  CommandLine cmd;
  cmd.Parse(argc, argv);
  std::string m_stack = "ns3::Dot11sStack";
  //////////////////////
  //////////////////////
  //////////////////////

  NodeContainer nodes;
  nodes.Create(2);

  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
  wifiPhy.SetChannel (wifiChannel.Create ());



  MeshHelper myMesh;
  myMesh.Default();
  myMesh.SetStackInstaller (m_stack.c_str());
  myMesh.SetSpreadInterfaceChannels (MeshHelper::SPREAD_CHANNELS);
  NetDeviceContainer meshDevices;
  meshDevices = myMesh.Install (wifiPhy, nodes);

//  WifiHelper wifi;
//  // wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
//  wifi.SetStandard(WIFI_PHY_STANDARD_80211a);
//  wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode",
//                               StringValue("OfdmRate24Mbps"));
//
//  YansWifiChannelHelper wifiChannel; // = YansWifiChannelHelper::Default ();
//  wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
//  wifiChannel.AddPropagationLoss("ns3::ThreeLogDistancePropagationLossModel");
//  wifiChannel.AddPropagationLoss("ns3::NakagamiPropagationLossModel");
//
//  // YansWifiPhy wifiPhy = YansWifiPhy::Default();
//  YansWifiPhyHelper wifiPhyHelper = YansWifiPhyHelper::Default();
//  wifiPhyHelper.SetChannel(wifiChannel.Create());
//  wifiPhyHelper.Set("TxPowerStart", DoubleValue(5));
//  wifiPhyHelper.Set("TxPowerEnd", DoubleValue(5));
//
//  WifiMacHelper wifiMacHelper;
//  wifiMacHelper.SetType("ns3::AdhocWifiMac");


  Ptr<UniformRandomVariable> randomizer = CreateObject<UniformRandomVariable>();
  randomizer->SetAttribute("Min", DoubleValue(10));
  randomizer->SetAttribute("Max", DoubleValue(100));




  MobilityHelper mobility;

  //  mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizer),
//                                "Y", PointerValue(randomizer), "Z", PointerValue(randomizer));
//
//  mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");


    mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                                   "MinX", DoubleValue (0.0),
                                   "MinY", DoubleValue (0.0),
                                   "DeltaX", DoubleValue (5),
                                   "DeltaY", DoubleValue (5),
                                   "GridWidth", UintegerValue (40),
                                   "LayoutType", StringValue ("RowFirst"));
    mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");



//  mobility.SetPositionAllocator ("ns3::RandomRectanglePositionAllocator");
//
//
//
//  mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
//                                 "Mode", StringValue ("Time"),
//                                 "Time", StringValue ("2s"),
//                                 "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"),
//                                 "Bounds", StringValue ("0|200|0|200"));


  ////////////////
  // 1. Install Wifi
  //NetDeviceContainer wifiNetDevices = wifi.Install(wifiPhyHelper, wifiMacHelper, nodes);

  // 2. Install Mobility model
  mobility.Install(nodes);

  // 3. Install NDN stack
  NS_LOG_INFO("Installing NDN stack");
  ndn::StackHelper ndnHelper;
  // ndnHelper.AddNetDeviceFaceCreateCallback (WifiNetDevice::GetTypeId (), MakeCallback
  // (MyNetDeviceFaceCallback));
  ndnHelper.SetOldContentStore("ns3::ndn::cs::Lru", "MaxSize", "1000");
  ndnHelper.SetDefaultRoutes(true);
  ndnHelper.Install(nodes);

  // Set BestRoute strategy
  ndn::StrategyChoiceHelper::Install(nodes, "/", "/localhost/nfd/strategy/best-route");

  // 4. Set up applications
  NS_LOG_INFO("Installing Applications");

  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
  consumerHelper.SetPrefix("/test/prefix");
  consumerHelper.SetAttribute("Frequency", DoubleValue(10.0));
  consumerHelper.Install(nodes.Get(0));

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

  ////////////////

  Simulator::Stop(Seconds(30.0));

//
//  for (int i = 0; i < 2; i++){
//
//   std::ostringstream oss;
//   oss << "/NodeList/" << nodes.Get (i)->GetId () << "/$ns3::MobilityModel/CourseChange";
//   Config::Connect (oss.str(), MakeCallback(&CourseChange));
//  }

  Simulator::Run();
  Simulator::Destroy();

  return 0;
}

} // namespace ns3

int
main(int argc, char* argv[])
{
  return ns3::main(argc, argv);
}

Hi, I am quite new in NS-3 and i am trying to implement simple NDN  client-server in a mesh network for my thesis. I tried to use MeshHelper class of NS 3 for this purpose. But whenever I try to run my code, an error is shown. I can't understand what am I doing wrong here? Please help.

I have attached my code and also the error here.
Error.png

Rob Kers

unread,
Apr 9, 2019, 3:32:49 AM4/9/19
to ns-3-users
Hi!

Welcome to NS3! 
Check the last line before the SIGIOT. It indicates that an assert failed. This assert is a check, if the check fails the program halts. The assert is at the indicated line (line 458) at file src/core/model/type-id.cc. In this case, the condition " uid <= m_information.size() && uid != 0". Not sure what the uid is, but i guess some kind of identifier that is set wrongly. You could check that.

I'm not familiar with the NDN mesh libs, so not sure how to construct these, but your simulation setup looks okay at a first glance.
If you can, setup a debugger (I'm using DBG in Eclipse) to see step through your code and explorer what goes wrong.

Cheers!
Rob
Reply all
Reply to author
Forward
0 new messages