Help needed Basic Error

151 views
Skip to first unread message

Dev Gupta

unread,
Jul 1, 2023, 7:02:14 AM7/1/23
to ns-3-users
The error I am having will be basic and simple so if you dont want to waste your time please avoid this
Thank you.



Here is the error 
gdb) run
Starting program: /home/dev/ns-allinone-3.34/ns-3.34/build/scratch/our
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
assert failed. cond="uid <= m_information.size () && uid != 0", +0.000000000s -1 file=../src/core/model/type-id.cc, line=462
terminate called without an active exception

Program received signal SIGABRT, Aborted.
__pthread_kill_implementation (no_tid=0, signo=6, threadid=140737347917632) at ./nptl/pthread_kill.c:44
44 ./nptl/pthread_kill.c: No such file or directory.
(gdb)


#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/wifi-module.h"
#include "ns3/internet-module.h"
#include "ns3/udp-echo-helper.h"


using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("AdhocExample");

// Define global variables to capture sent/received packets
uint32_t totalTx = 0;
uint32_t successfulTx = 0;

void TxCallback (Ptr<const Packet> p) {
  totalTx++;
}

void RxCallback (Ptr<const Packet> p) {
  successfulTx++;
}

int main (int argc, char *argv[])
{
  double totalTime = 10.0;
  uint32_t nodeCount = 20;
  uint32_t eavesdropperCount = 5;
  uint32_t packetSize = 1024;

  NodeContainer nodes;
  nodes.Create (nodeCount);

  NodeContainer bsNodes;
  bsNodes.Create (2);

  NodeContainer eavesdropper;
  eavesdropper.Create (eavesdropperCount);

  // Set up the wifi channel, wifi devices, and mac
  YansWifiChannelHelper channel;
  YansWifiPhyHelper wifiPhy;
  wifiPhy.SetChannel (channel.Create ());

  WifiMacHelper wifiMac;
  wifiMac.SetType ("ns3::AdhocWifiMac");

  WifiHelper wifi;
  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager");

  Ptr<RateErrorModel> em = CreateObject<RateErrorModel> ();
  em->SetAttribute ("ErrorRate", DoubleValue (0.1)); // Assuming a 10% chance that a packet will be intercepted by an eavesdropper

  NetDeviceContainer devices;
  devices = wifi.Install (wifiPhy, wifiMac, nodes);
  devices.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (em)); // Applying error model to first device only for example

  NetDeviceContainer bsDevices;
  bsDevices = wifi.Install (wifiPhy, wifiMac, bsNodes);

  NetDeviceContainer eavesdropperDevices;
  eavesdropperDevices = wifi.Install (wifiPhy, wifiMac, eavesdropper);

  // Set up the network stack and assign IP addresses
  InternetStackHelper internet;
  internet.Install (nodes);
  internet.Install (bsNodes);
  internet.Install (eavesdropper);

  Ipv4AddressHelper ipv4;
  ipv4.SetBase ("10.0.0.0", "255.255.255.0");
  Ipv4InterfaceContainer i = ipv4.Assign (devices);
  ipv4.Assign (bsDevices);
  ipv4.Assign (eavesdropperDevices);

  // Set up mobility models
  MobilityHelper mobility;
  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
 
  for (uint32_t i = 0; i < nodeCount; i++)
    {
      positionAlloc->Add (Vector (i*20.0, i*20.0, 0.0));
    }

  mobility.SetPositionAllocator (positionAlloc);
  mobility.SetMobilityModel ("ns3::RandomWaypointMobilityModel",
                             "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=5.0]"),
                             "Pause", StringValue ("ns3::ConstantRandomVariable[Constant=0.2]"),
                             "PositionAllocator", PointerValue (positionAlloc));
  mobility.Install (nodes);

  // Install applications
  UdpEchoServerHelper echoServer (9);
  ApplicationContainer serverApps = echoServer.Install (nodes.Get (0));
  serverApps.Start (Seconds (1.0));
  serverApps.Stop (Seconds (totalTime));

  UdpEchoClientHelper echoClient (i.GetAddress (0), 9);
  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
  echoClient.SetAttribute ("PacketSize", UintegerValue (packetSize));

  ApplicationContainer clientApps = echoClient.Install (nodes.Get (1));
  clientApps.Start (Seconds (2.0));
  clientApps.Stop (Seconds (totalTime));

  Simulator::Stop (Seconds (totalTime));

  // Enable tracing
  wifiPhy.EnablePcap ("AdhocExample", devices);
  AsciiTraceHelper ascii;
  wifiPhy.EnableAsciiAll (ascii.CreateFileStream ("AdhocExample.tr"));

  // Run the simulation
  Simulator::Run ();

  // Print out the sent/received packet counts
  std::cout << "Total Tx: " << totalTx << ", Successful Tx: " << successfulTx << std::endl;

  Simulator::Destroy ();
  return 0;
}
 
Reply all
Reply to author
Forward
0 new messages