NS_ASSERT failed, cond="uid <= m_information.size() && uid != 0", msg="The uid 0 for this TypeId is invalid"

I'm trying to recreate a mesh network with multicast in ns3 but this problem keeps happening and I'm not sure how to resolve it. Can anyone help me.

NS_ASSERT failed, cond="uid <= m_information.size() && uid != 0", msg="The uid 0 for this TypeId is invalid", +0.000000000s -1 file=/home/mpais/ns-allinone-3.42/ns-3.42/src/core/model/type-id.cc, line=460 NS_FATAL, terminating terminate called without an active exception

#include "ns3/core-module.h"
#include "ns3/internet-module.h"
#include "ns3/ipv4-address.h"
#include "ns3/ipv4-list-routing-helper.h"
#include "ns3/ipv4-static-routing-helper.h"
#include "ns3/mesh-module.h"
#include "ns3/network-module.h"
#include "ns3/udp-client-server-helper.h"
#include "ns3/wifi-module.h"
#include "ns3/udp-socket-factory.h"


using namespace ns3;

void
SendMulticastPacket(Ptr<Socket> socket, uint32_t packetSize)
{
    Ptr<Packet> packet = Create<Packet>(packetSize);
    socket->Send(packet);
    Simulator::Schedule(Seconds(1.0), &SendMulticastPacket, socket, packetSize);
}

int
main(int argc, char* argv[])
{
    CommandLine cmd;
    cmd.Parse(argc, argv);

    NodeContainer meshNodes;
    meshNodes.Create(6); // Create 6 mesh nodes 

    // Install Wi-Fi, Mesh, and Internet stacks

    WifiHelper wifi;
    YansWifiPhyHelper wifiPhy;
    MeshHelper mesh;
    InternetStackHelper internet;
    mesh.SetStackInstaller("ns3::Dot11sStack");
    NetDeviceContainer meshDevices = mesh.Install(wifiPhy, meshNodes);
    internet.Install(meshNodes);

    // Assign IP addresses
    Ipv4AddressHelper address;
    address.SetBase("10.1.1.0", "255.255.255.0");
    Ipv4InterfaceContainer interfaces = address.Assign(meshDevices);

    // Create a multicast group
    Ipv4Address multicastGroup = Ipv4Address("225.1.2.3"); // Multicast group address

    // Configure multicast routing
    std::vector<uint32_t> outputInterfaces;
    outputInterfaces.push_back(0); // Assuming interface 0 for all nodes
    Ipv4StaticRoutingHelper multicastRoutingHelper;
    Ptr<Ipv4StaticRouting> multicastRouting;
    for (uint32_t i = 0; i < meshNodes.GetN(); ++i)
    {
        Ptr<Node> node = meshNodes.Get(i);
        multicastRouting = multicastRoutingHelper.GetStaticRouting(node->GetObject<Ipv4>());
        multicastRouting->AddMulticastRoute(interfaces.GetAddress(i, 0),
                                            multicastGroup,
                                            i,
                                            outputInterfaces);
    }

    // Set up a multicast receiver on the first node
    TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");

    Ptr<Socket> recvSink = Socket::CreateSocket(meshNodes.Get(0), tid);
    InetSocketAddress local = InetSocketAddress(multicastGroup, 8080);
    recvSink->Bind(local);

    // Set up a multicast sender on the second node
    Ptr<Socket> source = Socket::CreateSocket(meshNodes.Get(1), tid);
    InetSocketAddress remote = InetSocketAddress(multicastGroup, 8080);
    source->SetAllowBroadcast(true);
    source->Connect(remote);

    // Schedule the periodic sending of multicast packets
    uint32_t packetSize = 1024; // Example packet size
    Simulator::ScheduleWithContext(source->GetNode()->GetId(),
                                   Seconds(1.0),
                                   &SendMulticastPacket,
                                   source,
                                   packetSize);

    // Run the simulation
    Simulator::Stop(Seconds(10.0));
    Simulator::Run();
    Simulator::Destroy();

    return 0;
}

I've already revised my code and found nothing wrong, plus this is my first time working with ns3 so I'm not sure what to look for.

Upvotes: 0

Views: 55

Answers (0)

Related Questions